vcl/inc/fontsubset.hxx | 10 +-- vcl/source/fontsubset/cff.cxx | 105 +++++++------------------------------- vcl/source/pdf/pdfwriter_impl.cxx | 4 - 3 files changed, 27 insertions(+), 92 deletions(-)
New commits: commit 6a3c3d1a41a27995e90ff473e823b5e80e314c91 Author: Khaled Hosny <[email protected]> AuthorDate: Tue Feb 17 23:48:21 2026 +0200 Commit: Khaled Hosny <[email protected]> CommitDate: Fri Feb 20 22:30:28 2026 +0100 FontSubsetInfo is always filled by time we reach emitAsType1() We can remove fallback code. Change-Id: Ic8bdcddc44099807c2b09703eaf3e243c3f1c64d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199585 Tested-by: Jenkins Reviewed-by: Khaled Hosny <[email protected]> diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx index 9b5caa1cadf0..39377645e172 100644 --- a/vcl/source/fontsubset/cff.cxx +++ b/vcl/source/fontsubset/cff.cxx @@ -674,7 +674,6 @@ struct CffGlobal int mnFontDictBase; int mnFDAryCount; - std::vector<ValType> maFontBBox; std::vector<ValType> maFontMatrix; }; @@ -938,14 +937,14 @@ void CffSubsetterContext::readDictOp() } break; case 'a': { // array switch( nOpId) { - case 5: maFontBBox.clear(); break; // "FontBBox" + case 5: break; // "FontBBox" case 907: maFontMatrix.clear(); break; // "FontMatrix" default: break; // TODO: reset other arrays? } for( int i = 0; i < size(); ++i ) { ValType nVal = getVal(i); switch( nOpId) { - case 5: maFontBBox.push_back( nVal); break; // "FontBBox" + case 5: break; // "FontBBox" case 907: maFontMatrix.push_back( nVal); break; // "FontMatrix" default: break; // TODO: handle more array dictops? } @@ -2296,14 +2295,11 @@ void CffSubsetterContext::emitAsType1( Type1Emitter& rEmitter, fYFactor = 1000.0F * maFontMatrix[3]; } - auto aFontBBox = maFontBBox; - if (rFSInfo.m_bFilled) - aFontBBox = { - rFSInfo.m_aFontBBox.Left() / fXFactor, rFSInfo.m_aFontBBox.Top() / fYFactor, - rFSInfo.m_aFontBBox.Right() / fXFactor, (rFSInfo.m_aFontBBox.Bottom() + 1) / fYFactor - }; - else if (aFontBBox.size() != 4) - aFontBBox = { 0, 0, 999, 999 }; // emit default FontBBox if needed + auto aFontBBox = { + rFSInfo.m_aFontBBox.Left() / fXFactor, rFSInfo.m_aFontBBox.Top() / fYFactor, + rFSInfo.m_aFontBBox.Right() / fXFactor, (rFSInfo.m_aFontBBox.Bottom() + 1) / fYFactor + }; + rEmitter.emitValVector( "/FontBBox {", "}readonly def ", aFontBBox); // emit FONTINFO into TOPDICT rEmitter.maBuffer.append( @@ -2506,20 +2502,6 @@ void CffSubsetterContext::emitAsType1( Type1Emitter& rEmitter, // note: the rest of VCL expects the details below to be scaled like for an emUnits==1000 font rFSInfo.m_nFontType = FontType::TYPE1_PFB; - - if (rFSInfo.m_bFilled) - return; - - rFSInfo.m_aFontBBox = { Point(static_cast<sal_Int32>(aFontBBox[0] * fXFactor), - static_cast<sal_Int32>(aFontBBox[1] * fYFactor)), - Point(static_cast<sal_Int32>(aFontBBox[2] * fXFactor), - static_cast<sal_Int32>(aFontBBox[3] * fYFactor)) }; - // PDF-Spec says the values below mean the ink bounds! - // TODO: use better approximations for these ink bounds - rFSInfo.m_nAscent = +rFSInfo.m_aFontBBox.Bottom(); // for capital letters - rFSInfo.m_nDescent = -rFSInfo.m_aFontBBox.Top(); // for all letters - rFSInfo.m_nCapHeight = rFSInfo.m_nAscent; // for top-flat capital letters - } namespace vcl commit 112975f031231a42612f4d08cda8b1ca7f39607c Author: Khaled Hosny <[email protected]> AuthorDate: Tue Feb 17 23:25:27 2026 +0200 Commit: Khaled Hosny <[email protected]> CommitDate: Fri Feb 20 22:30:20 2026 +0100 Remove code for creating Type 1 PFA subset fonts We never request such a subset format. Change-Id: Ia1176df67ab6b6894394bc1edee11ddbe0adacb7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199584 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> Reviewed-by: Khaled Hosny <[email protected]> diff --git a/vcl/inc/fontsubset.hxx b/vcl/inc/fontsubset.hxx index ed3e1ce7e980..c09327433c66 100644 --- a/vcl/inc/fontsubset.hxx +++ b/vcl/inc/fontsubset.hxx @@ -32,14 +32,12 @@ enum class FontType { NO_FONT = 0, SFNT_TTF = 1<<1, ///< SFNT container with TrueType glyphs SFNT_CFF = 1<<2, ///< SFNT container with CFF-container - TYPE1_PFA = 1<<3, ///< PSType1 Postscript Font Ascii - TYPE1_PFB = 1<<4, ///< PSType1 Postscript Font Binary - CFF_FONT = 1<<5, ///< CFF-container with PSType2 glyphs - ANY_SFNT = SFNT_TTF | SFNT_CFF, - ANY_TYPE1 = TYPE1_PFA | TYPE1_PFB + TYPE1_PFB = 1<<3, ///< PSType1 Postscript Font Binary + CFF_FONT = 1<<4, ///< CFF-container with PSType2 glyphs + ANY_SFNT = SFNT_TTF | SFNT_CFF }; namespace o3tl { - template<> struct typed_flags<FontType> : is_typed_flags<FontType, (1<<8)-1> {}; + template<> struct typed_flags<FontType> : is_typed_flags<FontType, 0x1e> {}; } class VCL_DLLPUBLIC FontSubsetInfo final diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx index 6a7196e1cf74..9b5caa1cadf0 100644 --- a/vcl/source/fontsubset/cff.cxx +++ b/vcl/source/fontsubset/cff.cxx @@ -2105,12 +2105,11 @@ namespace { class Type1Emitter { public: - explicit Type1Emitter( SvStream* pOutFile, bool bPfbSubset); + explicit Type1Emitter( SvStream* pOutFile); ~Type1Emitter(); size_t emitRawData( const char* pData, size_t nLength) const; void emitAllRaw(); - void emitAllHex(); void emitAllCrypted(); int tellPos() const; void updateLen( int nTellPos, size_t nLength); @@ -2120,18 +2119,13 @@ private: unsigned mnEECryptR; public: OStringBuffer maBuffer; - - bool mbPfbSubset; - int mnHexLineCol; }; } -Type1Emitter::Type1Emitter( SvStream* pOutFile, bool bPfbSubset) +Type1Emitter::Type1Emitter( SvStream* pOutFile) : mpFileOut( pOutFile) , mnEECryptR( 55665) // default eexec seed, TODO: mnEECryptSeed -, mbPfbSubset( bPfbSubset) -, mnHexLineCol( 0) { } @@ -2178,31 +2172,6 @@ inline void Type1Emitter::emitAllRaw() maBuffer.setLength(0); } -inline void Type1Emitter::emitAllHex() -{ - auto const end = maBuffer.getStr() + maBuffer.getLength(); - for( const char* p = maBuffer.getStr(); p < end;) { - // convert binary chunk to hex - char aHexBuf[0x4000]; - char* pOut = aHexBuf; - while( (p < end) && (pOut < aHexBuf+sizeof(aHexBuf)-4)) { - // convert each byte to hex - char cNibble = (static_cast<unsigned char>(*p) >> 4) & 0x0F; - cNibble += (cNibble < 10) ? '0' : 'A'-10; - *(pOut++) = cNibble; - cNibble = *(p++) & 0x0F; - cNibble += (cNibble < 10) ? '0' : 'A'-10; - *(pOut++) = cNibble; - // limit the line length - if( (++mnHexLineCol & 0x3F) == 0) - *(pOut++) = ' '; - } - // writeout hex-converted chunk - emitRawData( aHexBuf, pOut-aHexBuf); - } - // reset the raw buffer - maBuffer.setLength(0); -} void Type1Emitter::emitAllCrypted() { @@ -2213,10 +2182,7 @@ void Type1Emitter::emitAllCrypted() } // emit the t1crypt result - if( mbPfbSubset) - emitAllRaw(); - else - emitAllHex(); + emitAllRaw(); } // #i110387# quick-and-dirty double->ascii conversion @@ -2304,10 +2270,8 @@ void CffSubsetterContext::emitAsType1( Type1Emitter& rEmitter, ++nUniqueId; // create a PFB+Type1 header - if( rEmitter.mbPfbSubset ) { - static const char aPfbHeader[] = "\x80\x01\x00\x00\x00\x00"; - rEmitter.emitRawData( aPfbHeader, sizeof(aPfbHeader)-1); - } + static const char aPfbHeader[] = "\x80\x01\x00\x00\x00\x00"; + rEmitter.emitRawData( aPfbHeader, sizeof(aPfbHeader)-1); rEmitter.maBuffer.append( "%!FontType1-1.0: " + OString::Concat(aSubsetName) + " 001.003 "); @@ -2364,14 +2328,12 @@ void CffSubsetterContext::emitAsType1( Type1Emitter& rEmitter, // emit PFB header rEmitter.emitAllRaw(); - if( rEmitter.mbPfbSubset) { - // update PFB header segment - const int nPfbHeaderLen = rEmitter.tellPos() - 6; - rEmitter.updateLen( 2, nPfbHeaderLen); + // update PFB header segment + const int nPfbHeaderLen = rEmitter.tellPos() - 6; + rEmitter.updateLen( 2, nPfbHeaderLen); - // prepare start of eexec segment - rEmitter.emitRawData( "\x80\x02\x00\x00\x00\x00", 6); // segment start - } + // prepare start of eexec segment + rEmitter.emitRawData( "\x80\x02\x00\x00\x00\x00", 6); // segment start const int nEExecSegTell = rEmitter.tellPos(); // which always starts with a privdict @@ -2522,10 +2484,8 @@ void CffSubsetterContext::emitAsType1( Type1Emitter& rEmitter, rEmitter.emitAllCrypted(); // mark stop of eexec encryption - if( rEmitter.mbPfbSubset) { - const int nEExecLen = rEmitter.tellPos() - nEExecSegTell; - rEmitter.updateLen( nEExecSegTell-4, nEExecLen); - } + const int nEExecLen = rEmitter.tellPos() - nEExecSegTell; + rEmitter.updateLen( nEExecSegTell-4, nEExecLen); // create PFB footer static const char aPfxFooter[] = "\x80\x01\x14\x02\x00\x00 " // TODO: check segment len @@ -2539,16 +2499,13 @@ void CffSubsetterContext::emitAsType1( Type1Emitter& rEmitter, "0000000000000000000000000000000000000000000000000000000000000000 " "cleartomark " "\x80\x03"; - if( rEmitter.mbPfbSubset) - rEmitter.emitRawData( aPfxFooter, sizeof(aPfxFooter)-1); - else - rEmitter.emitRawData( aPfxFooter+6, sizeof(aPfxFooter)-9); + rEmitter.emitRawData( aPfxFooter, sizeof(aPfxFooter)-1); // provide details to the subset requesters, TODO: move into own method? // note: Top and Bottom are flipped between Type1 and VCL // note: the rest of VCL expects the details below to be scaled like for an emUnits==1000 font - rFSInfo.m_nFontType = rEmitter.mbPfbSubset ? FontType::TYPE1_PFB : FontType::TYPE1_PFA; + rFSInfo.m_nFontType = FontType::TYPE1_PFB; if (rFSInfo.m_bFilled) return; @@ -2581,7 +2538,7 @@ bool CreateCFFfontSubset(const unsigned char* pFontBytes, int nByteLength, // emit Type1 subset from the CFF input // TODO: also support CFF->CFF subsetting (when PDF-export and PS-printing need it) - Type1Emitter aType1Emitter(pStream, true); + Type1Emitter aType1Emitter(pStream); aCff.emitAsType1(aType1Emitter, pGlyphIds, pEncoding, nGlyphCount, rInfo); rOutBuffer.resize(pStream->TellEnd()); diff --git a/vcl/source/pdf/pdfwriter_impl.cxx b/vcl/source/pdf/pdfwriter_impl.cxx index 0305bf5c1403..4442f15fbba4 100644 --- a/vcl/source/pdf/pdfwriter_impl.cxx +++ b/vcl/source/pdf/pdfwriter_impl.cxx @@ -2033,9 +2033,7 @@ sal_Int32 PDFWriterImpl::emitFontDescriptor( const vcl::font::PhysicalFontFace* case FontType::CFF_FONT: aLine.append( "3" ); break; - case FontType::TYPE1_PFA: case FontType::TYPE1_PFB: - case FontType::ANY_TYPE1: break; default: OSL_FAIL( "unknown fonttype in PDF font descriptor" ); @@ -2196,7 +2194,7 @@ bool PDFWriterImpl::emitFonts() if ( !updateObject( nFontObject ) ) return false; aLine.setLength( 0 ); aLine.append( OString::number(nFontObject) + " 0 obj " ); - aLine.append( (aSubsetInfo.m_nFontType & (FontType::ANY_TYPE1 | FontType::CFF_FONT)) ? + aLine.append( (aSubsetInfo.m_nFontType & (FontType::TYPE1_PFB | FontType::CFF_FONT)) ? "<</Type/Font/Subtype/Type1/BaseFont/" : "<</Type/Font/Subtype/TrueType/BaseFont/" ); appendSubsetName( s_subset.m_nFontID, aSubsetInfo.m_aPSName, aLine );
