vcl/source/fontsubset/cff.cxx | 45 ++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 19 deletions(-)
New commits: commit 6907cbd0f8e198a0f1810b1a07f552a47c9da660 Author: Thorsten Behrens <thorsten.behr...@cib.de> AuthorDate: Thu Mar 14 00:36:37 2019 +0100 Commit: Thorsten Behrens <thorsten.behr...@cib.de> CommitDate: Sat Mar 16 23:41:33 2019 +0100 tdf#113448 fix type1 font subsetter This fixes verapdf A-1 validation error '6.2.11.5-1 glyph width in dict and font file inconsistent' Previous code was writing hard-coded '1000' as glyph width for any type1 font subsetting - since actual type2 width info only became available during subsequent convertOneTypeOp() parsing. Catch was, that loop sometimes already modifies the output buffer (whenever glyph path info was given), so we fix that by first padding out 5 bytes for the width (size of integers are sadly variable), then parsing Type2 glyph code, and in the end putting in the actual width value we then know. Can't put hsbw type1 op last, since standard requires that to be first (and can only be given _once_)... Could be re-done nicer by buffering Type2 glyph data, then writing it. Left as an exercise for the reader. Change-Id: I64ffaa32ded2f0a7c06311d1e0426cf358308a0a Reviewed-on: https://gerrit.libreoffice.org/69293 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx index a311104dca9b..57824367d366 100644 --- a/vcl/source/fontsubset/cff.cxx +++ b/vcl/source/fontsubset/cff.cxx @@ -1099,16 +1099,34 @@ int CffSubsetterContext::convert2Type1Ops( CffLocal* pCffLocal, const U8* const mpReadEnd = pT2Ops + nT2Len; // prepend "hsbw" or "sbw" // TODO: only emit hsbw when charwidth is known - // TODO: remove charwidth from T2 stack - writeType1Val( 0); // TODO: aSubsetterContext.getLeftSideBearing(); - writeType1Val( 1000/*###getCharWidth()###*/); - writeTypeOp( TYPE1OP::HSBW); + writeType1Val(0); // TODO: aSubsetterContext.getLeftSideBearing(); + U8* pCharWidthPtr=mpWritePtr; // need to overwrite that later + // pad out 5 bytes for the char width with default val 1000 (to be + // filled with the actual value below) + *(mpWritePtr++) = 255; + *(mpWritePtr++) = static_cast<U8>(0); + *(mpWritePtr++) = static_cast<U8>(0); + *(mpWritePtr++) = static_cast<U8>(250); + *(mpWritePtr++) = static_cast<U8>(124); + writeTypeOp(TYPE1OP::HSBW); mbNeedClose = false; mbIgnoreHints = false; mnHintSize=mnHorzHintSize=mnStackIdx=0; maCharWidth=-1;//####### mnCntrMask = 0; while( mpReadPtr < mpReadEnd) convertOneTypeOp(); + if( maCharWidth != -1 ) + { + // overwrite earlier charWidth value, which we only now have + // parsed out of mpReadPtr buffer (by way of + // convertOneTypeOp()s above) + const int nInt = static_cast<int>(maCharWidth); + *(pCharWidthPtr++) = 255; + *(pCharWidthPtr++) = static_cast<U8>(nInt >> 24); + *(pCharWidthPtr++) = static_cast<U8>(nInt >> 16); + *(pCharWidthPtr++) = static_cast<U8>(nInt >> 8); + *(pCharWidthPtr++) = static_cast<U8>(nInt); + } const int nType1Len = mpWritePtr - pT1Ops; commit b4d5e95b3c9454ead87dd2333799dcae41ac7970 Author: Thorsten Behrens <thorsten.behr...@cib.de> AuthorDate: Wed Mar 13 19:16:52 2019 +0100 Commit: Thorsten Behrens <thorsten.behr...@cib.de> CommitDate: Sat Mar 16 23:41:22 2019 +0100 vcl: cleanup font subsetter from ancient TODOs Change-Id: I8e6b6747f2b6c60523c8dc0878c08da39fe1da5b Reviewed-on: https://gerrit.libreoffice.org/69292 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx index 79c344d8fbfb..a311104dca9b 100644 --- a/vcl/source/fontsubset/cff.cxx +++ b/vcl/source/fontsubset/cff.cxx @@ -377,11 +377,10 @@ inline int CffSubsetterContext::popInt() inline void CffSubsetterContext::updateWidth( bool bUseFirstVal) { -#if 1 // TODO: is this still needed? // the first value is not a hint but the charwidth if( hasCharWidth()) return; -#endif + if( bUseFirstVal) { maCharWidth = mpCffLocal->maNominalWidth + mnValStack[0]; // remove bottom stack entry @@ -1084,21 +1083,18 @@ int CffSubsetterContext::convert2Type1Ops( CffLocal* pCffLocal, const U8* const // prepare the charstring conversion mpWritePtr = pT1Ops; -#if 1 // TODO: update caller U8 aType1Ops[ MAX_T1OPS_SIZE]; if( !pT1Ops) mpWritePtr = aType1Ops; *const_cast<U8**>(&pT1Ops) = mpWritePtr; -#else - assert( pT1Ops); -#endif // prepend random seed for T1crypt *(mpWritePtr++) = 0x48; *(mpWritePtr++) = 0x44; *(mpWritePtr++) = 0x55; *(mpWritePtr++) = ' '; -#if 1 // convert the Type2 charstring to Type1 + + // convert the Type2 charstring to Type1 mpReadPtr = pT2Ops; mpReadEnd = pT2Ops + nT2Len; // prepend "hsbw" or "sbw" @@ -1113,14 +1109,7 @@ int CffSubsetterContext::convert2Type1Ops( CffLocal* pCffLocal, const U8* const mnCntrMask = 0; while( mpReadPtr < mpReadEnd) convertOneTypeOp(); -// if( bActivePath) -// writeTypeOp( TYPE1OP::CLOSEPATH); -// if( bSubRoutine) -// writeTypeOp( TYPE1OP::RETURN); -#else // useful for manually encoding charstrings - mpWritePtr = pT1Ops; - mpWritePtr += sprintf( (char*)mpWritePtr, "OOo_\x8b\x8c\x0c\x10\x0b"); -#endif + const int nType1Len = mpWritePtr - pT1Ops; // encrypt the Type1 charstring _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits