diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2020-09-13 15:01:22 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2020-09-15 06:43:42 +0200 |
commit | bdde33ea94b77f50ca58b82bed86d6fcde77749c (patch) | |
tree | 3f605a937a3f239a21f588c967ebe543f5d6cd65 /vcl/quartz/salgdicommon.cxx | |
parent | 5ebc5f9df6972ac3d9ce7ed6a1504c48535c0881 (diff) |
WIN OSX Qt5 unify CreateFontSubset code
This is basically just some refactoring. Most interestingly the
MacOS used to work with 257 glyphs. I couldn't find any
explaination for the 256 glyph limit. Sadly the PrintFontManager
is out of scope. That needs more inspection.
Change-Id: Ibfa0e905f5efeb7d4a609884d64b4ed2615a9d3d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102688
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Tested-by: Jenkins
Diffstat (limited to 'vcl/quartz/salgdicommon.cxx')
-rw-r--r-- | vcl/quartz/salgdicommon.cxx | 123 |
1 files changed, 14 insertions, 109 deletions
diff --git a/vcl/quartz/salgdicommon.cxx b/vcl/quartz/salgdicommon.cxx index c72e8ee5cabd..3f2ec10bbd30 100644 --- a/vcl/quartz/salgdicommon.cxx +++ b/vcl/quartz/salgdicommon.cxx @@ -145,7 +145,7 @@ static void AddPolyPolygonToPath( CGMutablePathRef xPath, bool AquaSalGraphics::CreateFontSubset( const OUString& rToFile, const PhysicalFontFace* pFontData, const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncoding, - sal_Int32* pGlyphWidths, int nGlyphCount, + sal_Int32* pGlyphWidths, const int nGlyphCount, FontSubsetInfo& rInfo ) { // TODO: move more of the functionality here into the generic subsetter code @@ -153,36 +153,21 @@ bool AquaSalGraphics::CreateFontSubset( const OUString& rToFile, // prepare the requested file name for writing the font-subset file OUString aSysPath; if( osl_File_E_None != osl_getSystemPathFromFileURL( rToFile.pData, &aSysPath.pData ) ) - { return false; - } // get the raw-bytes from the font to be subset std::vector<unsigned char> aBuffer; bool bCffOnly = false; if( !GetRawFontData( pFontData, aBuffer, &bCffOnly ) ) - { return false; - } const OString aToFile( OUStringToOString( aSysPath, osl_getThreadTextEncoding())); // handle CFF-subsetting - if( bCffOnly ) - { - // provide the raw-CFF data to the subsetter - ByteCount nCffLen = aBuffer.size(); - rInfo.LoadFont( FontType::CFF_FONT, aBuffer.data(), nCffLen ); - - // NOTE: assuming that all glyphids requested on Aqua are fully translated - - // make the subsetter provide the requested subset - FILE* pOutFile = fopen( aToFile.getStr(), "wb" ); - bool bRC = rInfo.CreateFontSubset( FontType::TYPE1_PFB, pOutFile, nullptr, - pGlyphIds, pEncoding, nGlyphCount, pGlyphWidths ); - fclose( pOutFile ); - return bRC; - } + // NOTE: assuming that all glyphids requested on Aqua are fully translated + if (bCffOnly) + return SalGraphics::CreateCFFfontSubset(aBuffer.data(), aBuffer.size(), aToFile, pGlyphIds, + pEncoding, pGlyphWidths, nGlyphCount, rInfo); // TODO: modernize psprint's horrible fontsubset C-API // this probably only makes sense after the switch to another SCM @@ -190,102 +175,22 @@ bool AquaSalGraphics::CreateFontSubset( const OUString& rToFile, // prepare data for psprint's font subsetter TrueTypeFont* pSftFont = nullptr; - SFErrCodes nRC = ::OpenTTFontBuffer( static_cast<void*>(aBuffer.data()), aBuffer.size(), 0, &pSftFont); - if( nRC != SFErrCodes::Ok ) - { + if (::OpenTTFontBuffer( static_cast<void*>(aBuffer.data()), aBuffer.size(), 0, &pSftFont) + != SFErrCodes::Ok) return false; - } + // get details about the subsetted font TTGlobalFontInfo aTTInfo; ::GetTTGlobalFontInfo( pSftFont, &aTTInfo ); - rInfo.m_nFontType = FontType::SFNT_TTF; - rInfo.m_aPSName = OUString( aTTInfo.psname, std::strlen(aTTInfo.psname), - RTL_TEXTENCODING_UTF8 ); - rInfo.m_aFontBBox = tools::Rectangle( Point( aTTInfo.xMin, aTTInfo.yMin ), - Point( aTTInfo.xMax, aTTInfo.yMax ) ); - rInfo.m_nCapHeight = aTTInfo.yMax; // Well ... - rInfo.m_nAscent = aTTInfo.winAscent; - rInfo.m_nDescent = aTTInfo.winDescent; - // mac fonts usually do not have an OS2-table - // => get valid ascent/descent values from other tables - if( !rInfo.m_nAscent ) - { - rInfo.m_nAscent = +aTTInfo.typoAscender; - } - if( !rInfo.m_nAscent ) - { - rInfo.m_nAscent = +aTTInfo.ascender; - } - if( !rInfo.m_nDescent ) - { - rInfo.m_nDescent = +aTTInfo.typoDescender; - } - if( !rInfo.m_nDescent ) - { - rInfo.m_nDescent = -aTTInfo.descender; - } - - // subset glyphs and get their properties - // take care that subset fonts require the NotDef glyph in pos 0 - int nOrigCount = nGlyphCount; - sal_uInt16 aShortIDs[ 257 ]; - sal_uInt8 aTempEncs[ 257 ]; - int nNotDef = -1; - - assert( (nGlyphCount <= 256 && "too many glyphs for subsetting" )); - - for( int i = 0; i < nGlyphCount; ++i ) - { - aTempEncs[i] = pEncoding[i]; - - sal_GlyphId aGlyphId(pGlyphIds[i]); - aShortIDs[i] = static_cast<sal_uInt16>( aGlyphId ); - if( !aGlyphId && nNotDef < 0 ) - { - nNotDef = i; // first NotDef glyph found - } - } - - if( nNotDef != 0 ) - { - // add fake NotDef glyph if needed - if( nNotDef < 0 ) - { - nNotDef = nGlyphCount++; - } - // NotDef glyph must be in pos 0 => swap glyphids - aShortIDs[ nNotDef ] = aShortIDs[0]; - aTempEncs[ nNotDef ] = aTempEncs[0]; - aShortIDs[0] = 0; - aTempEncs[0] = 0; - } - - // TODO: where to get bVertical? - const bool bVertical = false; - - // fill the pGlyphWidths array - // while making sure that the NotDef glyph is at index==0 - std::unique_ptr<sal_uInt16[]> pGlyphMetrics = ::GetTTSimpleGlyphMetrics( pSftFont, aShortIDs, - nGlyphCount, bVertical ); - if( !pGlyphMetrics ) - { - return false; - } - - sal_uInt16 nNotDefAdv = pGlyphMetrics[0]; - pGlyphMetrics[0] = pGlyphMetrics[nNotDef]; - pGlyphMetrics[nNotDef] = nNotDefAdv; - for( int i = 0; i < nOrigCount; ++i ) - { - pGlyphWidths[i] = pGlyphMetrics[i]; - } - pGlyphMetrics.reset(); + OUString aPSName(aTTInfo.psname, std::strlen(aTTInfo.psname), RTL_TEXTENCODING_UTF8); + FillFontSubsetInfo(aTTInfo, aPSName, rInfo); // write subset into destination file - nRC = ::CreateTTFromTTGlyphs( pSftFont, aToFile.getStr(), aShortIDs, - aTempEncs, nGlyphCount ); + bool bRet + = SalGraphics::CreateTTFfontSubset(*pSftFont, aToFile, false /* use FontSelectPattern? */, + pGlyphIds, pEncoding, pGlyphWidths, nGlyphCount); ::CloseTTFont(pSftFont); - return (nRC == SFErrCodes::Ok); + return bRet; } static void alignLinePoint( const SalPoint* i_pIn, float& o_fX, float& o_fY ) |