vcl/inc/sft.hxx | 13 +++--------- vcl/source/fontsubset/cff.cxx | 43 +++++++++++++----------------------------- vcl/source/fontsubset/sft.cxx | 26 ++++++++----------------- 3 files changed, 27 insertions(+), 55 deletions(-)
New commits: commit 479e50132d41ebba840f69b766d82564cea3291c Author: Khaled Hosny <[email protected]> AuthorDate: Wed Feb 18 00:15:43 2026 +0200 Commit: Khaled Hosny <[email protected]> CommitDate: Fri Feb 20 22:30:47 2026 +0100 OpenTTFontFile/OpenTTFontBuffer is never called with charmap Change-Id: Iefa7c140b9442a8f559807d3913da3f83c9c523d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199587 Reviewed-by: Khaled Hosny <[email protected]> Tested-by: Jenkins diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx index 1ff10a985846..537e3a9a0ce5 100644 --- a/vcl/inc/sft.hxx +++ b/vcl/inc/sft.hxx @@ -44,7 +44,6 @@ #include <tools/fontenum.hxx> #include <vcl/dllapi.h> #include <vcl/fontcapabilities.hxx> -#include <vcl/fontcharmap.hxx> #include <i18nlangtag/lang.h> #include "glyphid.hxx" @@ -430,12 +429,11 @@ class TrueTypeFont; * @param facenum - logical font number within a TTC file. This value is ignored * for TrueType fonts * @param ttf - returns the opened TrueTypeFont - * @param xCharMap - optional parsed character map * @return value of SFErrCodes enum * @ingroup sft */ SFErrCodes VCL_DLLPUBLIC OpenTTFontBuffer(const void* pBuffer, sal_uInt32 nLen, sal_uInt32 facenum, - TrueTypeFont** ttf, const FontCharMapRef xCharMap = nullptr); + TrueTypeFont** ttf); #if !defined(_WIN32) || defined(DO_USE_TTF_ON_WIN32) /** * TrueTypeFont constructor. @@ -445,12 +443,10 @@ class TrueTypeFont; * @param facenum - logical font number within a TTC file. This value is ignored * for TrueType fonts * @param ttf - returns the opened TrueTypeFont - * @param xCharMap - optional parsed character map * @return value of SFErrCodes enum * @ingroup sft */ - SFErrCodes VCL_DLLPUBLIC OpenTTFontFile(const char *fname, sal_uInt32 facenum, TrueTypeFont** ttf, - const FontCharMapRef xCharMap = nullptr); + SFErrCodes VCL_DLLPUBLIC OpenTTFontFile(const char *fname, sal_uInt32 facenum, TrueTypeFont** ttf); #endif bool VCL_DLLPUBLIC getTTCoverage( @@ -530,14 +526,13 @@ class UNLESS_MERGELIBS(VCL_DLLPUBLIC) AbstractTrueTypeFont sal_uInt32 m_nVertMetrics; /* if not 0 => font has vertical metrics information */ sal_uInt32 m_nUnitsPerEm; std::vector<sal_uInt32> m_aGlyphOffsets; - FontCharMapRef m_xCharMap; bool m_bMicrosoftSymbolEncoded; protected: SFErrCodes indexGlyphData(); public: - AbstractTrueTypeFont(const char* fileName = nullptr, const FontCharMapRef xCharMap = nullptr); + AbstractTrueTypeFont(const char* fileName = nullptr); virtual ~AbstractTrueTypeFont(); SFErrCodes initialize(); @@ -576,7 +571,7 @@ public: sal_uInt8 *ptr; sal_uInt32 ntables; - TrueTypeFont(const char* pFileName = nullptr, const FontCharMapRef xCharMap = nullptr); + TrueTypeFont(const char* pFileName = nullptr); ~TrueTypeFont() override; SFErrCodes open(sal_uInt32 facenum); diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index 68f3e4a49dbf..af5b4772b3bd 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -346,8 +346,7 @@ int CountTTCFonts(const char* fname) } #if !defined(_WIN32) || defined(DO_USE_TTF_ON_WIN32) -SFErrCodes OpenTTFontFile(const char* fname, sal_uInt32 facenum, TrueTypeFont** ttf, - const FontCharMapRef xCharMap) +SFErrCodes OpenTTFontFile(const char* fname, sal_uInt32 facenum, TrueTypeFont** ttf) { SFErrCodes ret; int fd = -1; @@ -355,7 +354,7 @@ SFErrCodes OpenTTFontFile(const char* fname, sal_uInt32 facenum, TrueTypeFont** if (!fname || !*fname) return SFErrCodes::BadFile; - *ttf = new TrueTypeFont(fname, xCharMap); + *ttf = new TrueTypeFont(fname); if( ! *ttf ) return SFErrCodes::Memory; @@ -416,10 +415,9 @@ cleanup: } #endif -SFErrCodes OpenTTFontBuffer(const void* pBuffer, sal_uInt32 nLen, sal_uInt32 facenum, TrueTypeFont** ttf, - const FontCharMapRef xCharMap) +SFErrCodes OpenTTFontBuffer(const void* pBuffer, sal_uInt32 nLen, sal_uInt32 facenum, TrueTypeFont** ttf) { - *ttf = new TrueTypeFont(nullptr, xCharMap); + *ttf = new TrueTypeFont(nullptr); if( *ttf == nullptr ) return SFErrCodes::Memory; @@ -448,12 +446,11 @@ bool withinBounds(sal_uInt32 tdoffset, sal_uInt32 moreoffset, sal_uInt32 len, sa } } -AbstractTrueTypeFont::AbstractTrueTypeFont(const char* pFileName, const FontCharMapRef xCharMap) +AbstractTrueTypeFont::AbstractTrueTypeFont(const char* pFileName) : m_nGlyphs(0xFFFFFFFF) , m_nHorzMetrics(0) , m_nVertMetrics(0) , m_nUnitsPerEm(0) - , m_xCharMap(xCharMap) , m_bMicrosoftSymbolEncoded(false) { if (pFileName) @@ -464,8 +461,8 @@ AbstractTrueTypeFont::~AbstractTrueTypeFont() { } -TrueTypeFont::TrueTypeFont(const char* pFileName, const FontCharMapRef xCharMap) - : AbstractTrueTypeFont(pFileName, xCharMap) +TrueTypeFont::TrueTypeFont(const char* pFileName) + : AbstractTrueTypeFont(pFileName) , fsize(-1) , mmhandle(0) , ptr(nullptr) @@ -554,13 +551,8 @@ SFErrCodes AbstractTrueTypeFont::indexGlyphData() table = this->table(O_vhea, table_size); m_nVertMetrics = (table && table_size >= 36) ? GetUInt16(table, 34) : 0; - if (!m_xCharMap.is()) - { - table = this->table(O_cmap, table_size); - m_bMicrosoftSymbolEncoded = HasMicrosoftSymbolCmap(table, table_size); - } - else - m_bMicrosoftSymbolEncoded = m_xCharMap->isMicrosoftSymbolMap(); + table = this->table(O_cmap, table_size); + m_bMicrosoftSymbolEncoded = HasMicrosoftSymbolCmap(table, table_size); return SFErrCodes::Ok; } commit a059cba6e304b389ecd78d5760acef25b77ea21d Author: Khaled Hosny <[email protected]> AuthorDate: Tue Feb 17 23:55:42 2026 +0200 Commit: Khaled Hosny <[email protected]> CommitDate: Fri Feb 20 22:30:37 2026 +0100 Use SvMemoryStream in Type1Emitter instead of creating a temp file Change-Id: I70af1a1fa754a1cd6ef75cf506fc747122687891 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199586 Tested-by: Jenkins Reviewed-by: Khaled Hosny <[email protected]> diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx index 39377645e172..07abeca6eb7b 100644 --- a/vcl/source/fontsubset/cff.cxx +++ b/vcl/source/fontsubset/cff.cxx @@ -35,7 +35,6 @@ #include <strhelper.hxx> #include <sal/log.hxx> #include <tools/stream.hxx> -#include <unotools/tempfile.hxx> typedef sal_uInt8 U8; typedef sal_uInt16 U16; @@ -2104,8 +2103,7 @@ namespace { class Type1Emitter { public: - explicit Type1Emitter( SvStream* pOutFile); - ~Type1Emitter(); + explicit Type1Emitter( SvMemoryStream& rStream); size_t emitRawData( const char* pData, size_t nLength) const; void emitAllRaw(); @@ -2114,7 +2112,7 @@ public: void updateLen( int nTellPos, size_t nLength); void emitValVector( const char* pLineHead, const char* pLineTail, const std::vector<ValType>&); private: - SvStream* mpFileOut; + SvMemoryStream& mrStream; unsigned mnEECryptR; public: OStringBuffer maBuffer; @@ -2122,22 +2120,16 @@ public: } -Type1Emitter::Type1Emitter( SvStream* pOutFile) -: mpFileOut( pOutFile) +Type1Emitter::Type1Emitter( SvMemoryStream& rStream) +: mrStream( rStream) , mnEECryptR( 55665) // default eexec seed, TODO: mnEECryptSeed { } -Type1Emitter::~Type1Emitter() -{ - if( !mpFileOut) - return; - mpFileOut = nullptr; -} int Type1Emitter::tellPos() const { - int nTellPos = mpFileOut->Tell(); + int nTellPos = mrStream.Tell(); return nTellPos; } @@ -2149,18 +2141,18 @@ void Type1Emitter::updateLen( int nTellPos, size_t nLength) cData[1] = static_cast<U8>(nLength >> 8); cData[2] = static_cast<U8>(nLength >> 16); cData[3] = static_cast<U8>(nLength >> 24); - const tools::Long nCurrPos = mpFileOut->Tell(); + const tools::Long nCurrPos = mrStream.Tell(); if (nCurrPos < 0) return; - if (mpFileOut->Seek(nTellPos) != static_cast<sal_uInt64>(nTellPos)) + if (mrStream.Seek(nTellPos) != static_cast<sal_uInt64>(nTellPos)) return; - mpFileOut->WriteBytes(cData, sizeof(cData)); - mpFileOut->Seek(nCurrPos); + mrStream.WriteBytes(cData, sizeof(cData)); + mrStream.Seek(nCurrPos); } inline size_t Type1Emitter::emitRawData(const char* pData, size_t nLength) const { - return mpFileOut->WriteBytes( pData, nLength ); + return mrStream.WriteBytes( pData, nLength ); } inline void Type1Emitter::emitAllRaw() @@ -2515,22 +2507,15 @@ bool CreateCFFfontSubset(const unsigned char* pFontBytes, int nByteLength, if (!bRC) return bRC; - utl::TempFileFast aTempFile; - SvStream* pStream = aTempFile.GetStream(StreamMode::READWRITE); + SvMemoryStream aStream; // emit Type1 subset from the CFF input // TODO: also support CFF->CFF subsetting (when PDF-export and PS-printing need it) - Type1Emitter aType1Emitter(pStream); + Type1Emitter aType1Emitter(aStream); aCff.emitAsType1(aType1Emitter, pGlyphIds, pEncoding, nGlyphCount, rInfo); - rOutBuffer.resize(pStream->TellEnd()); - pStream->Seek(0); - auto nRead = pStream->ReadBytes(rOutBuffer.data(), rOutBuffer.size()); - if (nRead != rOutBuffer.size()) - { - rOutBuffer.clear(); - return false; - } + rOutBuffer.assign(static_cast<const sal_uInt8*>(aStream.GetData()), + static_cast<const sal_uInt8*>(aStream.GetData()) + aStream.Tell()); return true; }
