vcl/inc/fontsubset.hxx | 5 vcl/inc/sft.hxx | 6 - vcl/source/fontsubset/cff.cxx | 19 +-- vcl/source/fontsubset/fontsubset.cxx | 2 vcl/source/fontsubset/sft.cxx | 182 ++++++++++++++++++++++------------- vcl/unx/generic/print/glyphset.cxx | 20 +-- 6 files changed, 142 insertions(+), 92 deletions(-)
New commits: commit a0e674851896d2d8e869474db067b7698293c02a Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Thu Sep 22 20:41:33 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Sep 24 16:19:17 2022 +0200 use faster TempFile for font subset writing by not asking for the name or URL, we stay on the happy path, which is faster on Windows Change-Id: Ia333ab251fc0fc4129ad0610412c5c509914a58e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140453 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/vcl/inc/fontsubset.hxx b/vcl/inc/fontsubset.hxx index fef6603cd2fd..cb4cb34dd979 100644 --- a/vcl/inc/fontsubset.hxx +++ b/vcl/inc/fontsubset.hxx @@ -29,6 +29,7 @@ #include "glyphid.hxx" namespace vcl { class TrueTypeFont; } ///< SFT's idea of a TTF font +class SvStream; enum class FontType { NO_FONT = 0, @@ -57,7 +58,7 @@ public: void LoadFont( vcl::TrueTypeFont* pSftTrueTypeFont ); bool CreateFontSubset( FontType nOutFontTypeMask, - FILE* pOutFile, const char* pOutFontName, + SvStream* pOutFile, const char* pOutFontName, const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncodedIds, int nReqGlyphCount); @@ -79,7 +80,7 @@ private: // subset-request details FontType mnReqFontTypeMask; ///< allowed subset-target font types - FILE* mpOutFile; + SvStream* mpOutFile; const char* mpReqFontName; const sal_GlyphId* mpReqGlyphIds; const sal_uInt8* mpReqEncodedIds; diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx index 05f62de655ec..3b72df3826a8 100644 --- a/vcl/inc/sft.hxx +++ b/vcl/inc/sft.hxx @@ -52,6 +52,8 @@ #include "font/PhysicalFontFace.hxx" +class SvStream; + namespace vcl { @@ -582,7 +584,7 @@ class TrueTypeFace; * @ingroup sft * */ - SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname, sal_uInt16 const *glyphArray, sal_uInt8 *encoding, int nGlyphs, int wmode); + SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, SvStream *outf, const char *fname, sal_uInt16 const *glyphArray, sal_uInt8 *encoding, int nGlyphs, int wmode); /** * Generates a new TrueType font and dumps it to <b>outf</b> file. @@ -644,7 +646,7 @@ class TrueTypeFace; * */ SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont *ttf, - FILE *outf, + SvStream *outf, const char *psname, sal_uInt16 const *glyphArray, sal_uInt8 *encoding, diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx index f22ab23f6e12..8d8700308bed 100644 --- a/vcl/source/fontsubset/cff.cxx +++ b/vcl/source/fontsubset/cff.cxx @@ -27,6 +27,7 @@ #include <o3tl/safeint.hxx> #include <strhelper.hxx> #include <sal/log.hxx> +#include <tools/stream.hxx> typedef sal_uInt8 U8; typedef sal_uInt16 U16; @@ -1610,7 +1611,7 @@ namespace { class Type1Emitter { public: - explicit Type1Emitter( FILE* pOutFile, bool bPfbSubset); + explicit Type1Emitter( SvStream* pOutFile, bool bPfbSubset); ~Type1Emitter(); void setSubsetName( const char* ); @@ -1622,7 +1623,7 @@ public: void updateLen( int nTellPos, size_t nLength); void emitValVector( const char* pLineHead, const char* pLineTail, const std::vector<ValType>&); private: - FILE* mpFileOut; + SvStream* mpFileOut; char maBuffer[MAX_T1OPS_SIZE]; // TODO: dynamic allocation unsigned mnEECryptR; public: @@ -1635,7 +1636,7 @@ public: } -Type1Emitter::Type1Emitter( FILE* pOutFile, bool bPfbSubset) +Type1Emitter::Type1Emitter( SvStream* pOutFile, bool bPfbSubset) : mpFileOut( pOutFile) , maBuffer{} , mnEECryptR( 55665) // default eexec seed, TODO: mnEECryptSeed @@ -1663,7 +1664,7 @@ void Type1Emitter::setSubsetName( const char* pSubsetName) int Type1Emitter::tellPos() const { - int nTellPos = ftell( mpFileOut); + int nTellPos = mpFileOut->Tell(); return nTellPos; } @@ -1675,18 +1676,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 = ftell(mpFileOut); + const tools::Long nCurrPos = mpFileOut->Tell(); if (nCurrPos < 0) return; - if (fseek( mpFileOut, nTellPos, SEEK_SET) != 0) + if (mpFileOut->Seek(nTellPos) != static_cast<sal_uInt64>(nTellPos)) return; - fwrite(cData, 1, sizeof(cData), mpFileOut); - (void)fseek(mpFileOut, nCurrPos, SEEK_SET); + mpFileOut->WriteBytes(cData, sizeof(cData)); + mpFileOut->Seek(nCurrPos); } inline size_t Type1Emitter::emitRawData(const char* pData, size_t nLength) const { - return fwrite( pData, 1, nLength, mpFileOut); + return mpFileOut->WriteBytes( pData, nLength ); } inline void Type1Emitter::emitAllRaw() diff --git a/vcl/source/fontsubset/fontsubset.cxx b/vcl/source/fontsubset/fontsubset.cxx index 3b016a9b0dce..72b634b786f0 100644 --- a/vcl/source/fontsubset/fontsubset.cxx +++ b/vcl/source/fontsubset/fontsubset.cxx @@ -67,7 +67,7 @@ void FontSubsetInfo::LoadFont( vcl::TrueTypeFont* pSftTTFont ) bool FontSubsetInfo::CreateFontSubset( FontType nReqFontTypeMask, - FILE* pOutFile, const char* pReqFontName, + SvStream* pOutFile, const char* pReqFontName, const sal_GlyphId* pReqGlyphIds, const sal_uInt8* pReqEncodedIds, int nReqGlyphCount) { // prepare request details needed by all underlying subsetters diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index ee346b833836..5c9cc85201e3 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -114,7 +114,7 @@ constexpr int HFORMAT_LINELEN = 64; class HexFmt { public: - HexFmt(FILE *outf) : o(outf) {} + HexFmt(SvStream *outf) : o(outf) {} ~HexFmt() { Flush(); @@ -125,7 +125,7 @@ public: void BlockWrite(const void *ptr, sal_uInt32 size); private: - FILE *o; + SvStream *o; char buffer[HFORMAT_LINELEN]; size_t bufpos = 0; int total = 0; @@ -219,7 +219,7 @@ bool HexFmt::Flush() { bool bRet = true; if (bufpos) { - size_t nWritten = fwrite(buffer, 1, bufpos, o); + size_t nWritten = o->WriteBytes(buffer, bufpos); bRet = nWritten == bufpos; bufpos = 0; } @@ -228,13 +228,13 @@ bool HexFmt::Flush() void HexFmt::OpenString() { - fputs("<\n", o); + o->WriteCharPtr("<\n"); } void HexFmt::CloseString() { Flush(); - fputs("00\n>\n", o); + o->WriteCharPtr("00\n>\n"); } void HexFmt::BlockWrite(const void *ptr, sal_uInt32 size) @@ -252,7 +252,7 @@ void HexFmt::BlockWrite(const void *ptr, sal_uInt32 size) buffer[bufpos++] = toHex(Ch & 0xF); if (bufpos == HFORMAT_LINELEN) { Flush(); - fputc('\n', o); + o->WriteCharPtr("\n"); } } @@ -1576,7 +1576,7 @@ int GetTTGlyphComponents(AbstractTrueTypeFont *ttf, sal_uInt32 glyphID, std::vec return n; } -SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname, +SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, SvStream *outf, const char *fname, sal_uInt16 const *glyphArray, sal_uInt8 *encoding, int nGlyphs, int wmode) { @@ -1639,13 +1639,21 @@ SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname if (!glyphArray) return SFErrCodes::BadArg; if (!fname) fname = ttf->psname.getStr(); - fprintf(outf, h01, GetInt16(table, 0), GetUInt16(table, 2), GetInt16(table, 4), GetUInt16(table, 6)); - fprintf(outf, h02, modname, modver, modextra); - fprintf(outf, h09, ttf->psname.getStr()); + constexpr int bufmax = 256; + char buf[bufmax]; - fprintf(outf, "%s", h10); - fprintf(outf, h11, fname); -/* fprintf(outf, h12, 4000000); */ + snprintf(buf, bufmax, h01, GetInt16(table, 0), GetUInt16(table, 2), GetInt16(table, 4), GetUInt16(table, 6)); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, h02, modname, modver, modextra); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, h09, ttf->psname.getStr()); + outf->WriteCharPtr(buf); + + snprintf(buf, bufmax, "%s", h10); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, h11, fname); + outf->WriteCharPtr(buf); +/* snprintf(buf, bufmax, h12, 4000000); */ /* XUID generation: * 103 0 0 C1 C2 C3 C4 @@ -1657,21 +1665,30 @@ SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname * All CRC-32 numbers are presented as hexadecimal numbers */ - fprintf(outf, h17, rtl_crc32(0, ttf->ptr, ttf->fsize), nGlyphs, rtl_crc32(0, glyphArray, nGlyphs * 2), rtl_crc32(0, encoding, nGlyphs)); - fprintf(outf, "%s", h13); - fprintf(outf, h14, XUnits(UPEm, GetInt16(table, 36)), XUnits(UPEm, GetInt16(table, 38)), XUnits(UPEm, GetInt16(table, 40)), XUnits(UPEm, GetInt16(table, 42))); - fprintf(outf, "%s", h15); + snprintf(buf, bufmax, h17, rtl_crc32(0, ttf->ptr, ttf->fsize), nGlyphs, rtl_crc32(0, glyphArray, nGlyphs * 2), rtl_crc32(0, encoding, nGlyphs)); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "%s", h13); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, h14, XUnits(UPEm, GetInt16(table, 36)), XUnits(UPEm, GetInt16(table, 38)), XUnits(UPEm, GetInt16(table, 40)), XUnits(UPEm, GetInt16(table, 42))); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "%s", h15); + outf->WriteCharPtr(buf); for (i = 0; i < nGlyphs; i++) { - fprintf(outf, h16, encoding[i], i); + snprintf(buf, bufmax, h16, encoding[i], i); + outf->WriteCharPtr(buf); } - fprintf(outf, h30, nGlyphs+1); - fprintf(outf, "%s", h31); - fprintf(outf, "%s", h32); + snprintf(buf, bufmax, h30, nGlyphs+1); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "%s", h31); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "%s", h32); + outf->WriteCharPtr(buf); for (i = 0; i < nGlyphs; i++) { - fprintf(outf, h33, i); + snprintf(buf, bufmax, h33, i); + outf->WriteCharPtr(buf); int r = GetTTGlyphOutline(ttf, glyphArray[i] < ttf->glyphCount() ? glyphArray[i] : 0, pa, &metrics, nullptr); if (r > 0) { @@ -1683,47 +1700,60 @@ SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname continue; } } - fprintf(outf, "\t%d %d %d %d %d %d setcachedevice\n", + snprintf(buf, bufmax, "\t%d %d %d %d %d %d setcachedevice\n", wmode == 0 ? XUnits(UPEm, metrics.aw) : 0, wmode == 0 ? 0 : -XUnits(UPEm, metrics.ah), XUnits(UPEm, metrics.xMin), XUnits(UPEm, metrics.yMin), XUnits(UPEm, metrics.xMax), XUnits(UPEm, metrics.yMax)); + outf->WriteCharPtr(buf); for (j = 0; j < n; j++) { switch (path[j].type) { case PS_MOVETO: - fprintf(outf, "\t%d %d moveto\n", XUnits(UPEm, path[j].x1), XUnits(UPEm, path[j].y1)); + snprintf(buf, bufmax, "\t%d %d moveto\n", XUnits(UPEm, path[j].x1), XUnits(UPEm, path[j].y1)); + outf->WriteCharPtr(buf); break; case PS_LINETO: - fprintf(outf, "\t%d %d lineto\n", XUnits(UPEm, path[j].x1), XUnits(UPEm, path[j].y1)); + snprintf(buf, bufmax, "\t%d %d lineto\n", XUnits(UPEm, path[j].x1), XUnits(UPEm, path[j].y1)); + outf->WriteCharPtr(buf); break; case PS_CURVETO: - fprintf(outf, "\t%d %d %d %d %d %d curveto\n", XUnits(UPEm, path[j].x1), XUnits(UPEm, path[j].y1), XUnits(UPEm, path[j].x2), XUnits(UPEm, path[j].y2), XUnits(UPEm, path[j].x3), XUnits(UPEm, path[j].y3)); + snprintf(buf, bufmax, "\t%d %d %d %d %d %d curveto\n", XUnits(UPEm, path[j].x1), XUnits(UPEm, path[j].y1), XUnits(UPEm, path[j].x2), XUnits(UPEm, path[j].y2), XUnits(UPEm, path[j].x3), XUnits(UPEm, path[j].y3)); + outf->WriteCharPtr(buf); break; case PS_CLOSEPATH: - fprintf(outf, "\tclosepath\n"); + snprintf(buf, bufmax, "\tclosepath\n"); + outf->WriteCharPtr(buf); break; case PS_NOOP: break; } } - if (n > 0) fprintf(outf, "\tfill\n"); /* if glyph is not a whitespace character */ + if (n > 0) + { + snprintf(buf, bufmax, "\tfill\n"); /* if glyph is not a whitespace character */ + outf->WriteCharPtr(buf); + } - fprintf(outf, "%s", h34); + snprintf(buf, bufmax, "%s", h34); + outf->WriteCharPtr(buf); path.reset(); } - fprintf(outf, "%s", h35); + snprintf(buf, bufmax, "%s", h35); + outf->WriteCharPtr(buf); - fprintf(outf, "%s", h40); - fprintf(outf, h41, fname); + snprintf(buf, bufmax, "%s", h40); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, h41, fname); + outf->WriteCharPtr(buf); return SFErrCodes::Ok; } @@ -1902,21 +1932,16 @@ bool CreateCFFfontSubset(const unsigned char* pFontBytes, int nByteLength, FontSubsetInfo& rInfo) { utl::TempFile aTempFile; - const OString aToFile(OUStringToOString(aTempFile.GetFileName(), osl_getThreadTextEncoding())); - - FILE* pOutFile = fopen(aToFile.getStr(), "wb"); - if (!pOutFile) - return false; + SvStream* pStream = aTempFile.GetStream(StreamMode::READWRITE); rInfo.LoadFont(FontType::CFF_FONT, pFontBytes, nByteLength); - bool bRet = rInfo.CreateFontSubset(FontType::TYPE1_PFB, pOutFile, rPSName.toUtf8().getStr(), + bool bRet = rInfo.CreateFontSubset(FontType::TYPE1_PFB, pStream, rPSName.toUtf8().getStr(), pGlyphIds, pEncoding, nGlyphCount); - fclose(pOutFile); if (bRet) { - SvStream* pStream = aTempFile.GetStream(StreamMode::READ); rOutBuffer.resize(pStream->TellEnd()); + pStream->Seek(0); auto nRead = pStream->ReadBytes(rOutBuffer.data(), rOutBuffer.size()); if (nRead != rOutBuffer.size()) { @@ -1978,7 +2003,7 @@ GlyphOffsets::GlyphOffsets(sal_uInt8 *sfntP, sal_uInt32 sfntLen) } } -static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) +static void DumpSfnts(SvStream *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) { if (sfntLen < 12) { @@ -2007,7 +2032,7 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) std::unique_ptr<sal_uInt32[]> offs(new sal_uInt32[numTables]); - fputs("/sfnts [", outf); + outf->WriteCharPtr("/sfnts ["); h.OpenString(); h.BlockWrite(sfntP, 12); /* stream out the Offset Table */ h.BlockWrite(sfntP+12, 16 * numTables); /* stream out the Table Directory */ @@ -2076,11 +2101,11 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) h.BlockWrite(pad, (4 - (len & 3)) & 3); } h.CloseString(); - fputs("] def\n", outf); + outf->WriteCharPtr("] def\n"); } SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont *ttf, - FILE *outf, + SvStream *outf, const char *psname, sal_uInt16 const *glyphArray, sal_uInt8 *encoding, @@ -2152,37 +2177,62 @@ SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont *ttf, return res; } - fprintf(outf, "%%!PS-TrueTypeFont-%d.%d-%d.%d\n", static_cast<int>(ver), static_cast<int>(ver & 0xFF), static_cast<int>(rev>>16), static_cast<int>(rev & 0xFFFF)); - fprintf(outf, "%%%%Creator: %s %s %s\n", modname, modver, modextra); - fprintf(outf, "%%- Font subset generated from a source font file: '%s'\n", ttf->fileName().data()); - fprintf(outf, "%%- Original font name: %s\n", ttf->psname.getStr()); - fprintf(outf, "%%- Original font family: %s\n", ttf->family.getStr()); - fprintf(outf, "%%- Original font sub-family: %s\n", ttf->subfamily.getStr()); - fprintf(outf, "11 dict begin\n"); - fprintf(outf, "/FontName (%s) cvn def\n", psname); - fprintf(outf, "/PaintType 0 def\n"); - fprintf(outf, "/FontMatrix [1 0 0 1 0 0] def\n"); - fprintf(outf, "/FontBBox [%d %d %d %d] def\n", XUnits(UPEm, GetInt16(headP, HEAD_xMin_offset)), XUnits(UPEm, GetInt16(headP, HEAD_yMin_offset)), XUnits(UPEm, GetInt16(headP, HEAD_xMax_offset)), XUnits(UPEm, GetInt16(headP, HEAD_yMax_offset))); - fprintf(outf, "/FontType 42 def\n"); - fprintf(outf, "/Encoding 256 array def\n"); - fprintf(outf, " 0 1 255 {Encoding exch /.notdef put} for\n"); + constexpr int bufmax = 256; + char buf[bufmax]; + + snprintf(buf, bufmax, "%%!PS-TrueTypeFont-%d.%d-%d.%d\n", static_cast<int>(ver), static_cast<int>(ver & 0xFF), static_cast<int>(rev>>16), static_cast<int>(rev & 0xFFFF)); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "%%%%Creator: %s %s %s\n", modname, modver, modextra); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "%%- Font subset generated from a source font file: '%s'\n", ttf->fileName().data()); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "%%- Original font name: %s\n", ttf->psname.getStr()); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "%%- Original font family: %s\n", ttf->family.getStr()); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "%%- Original font sub-family: %s\n", ttf->subfamily.getStr()); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "11 dict begin\n"); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "/FontName (%s) cvn def\n", psname); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "/PaintType 0 def\n"); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "/FontMatrix [1 0 0 1 0 0] def\n"); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "/FontBBox [%d %d %d %d] def\n", XUnits(UPEm, GetInt16(headP, HEAD_xMin_offset)), XUnits(UPEm, GetInt16(headP, HEAD_yMin_offset)), XUnits(UPEm, GetInt16(headP, HEAD_xMax_offset)), XUnits(UPEm, GetInt16(headP, HEAD_yMax_offset))); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "/FontType 42 def\n"); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "/Encoding 256 array def\n"); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, " 0 1 255 {Encoding exch /.notdef put} for\n"); + outf->WriteCharPtr(buf); for (i = 1; i<nGlyphs; i++) { - fprintf(outf, "Encoding %d /glyph%u put\n", encoding[i], gID[i]); + snprintf(buf, bufmax, "Encoding %d /glyph%u put\n", encoding[i], gID[i]); + outf->WriteCharPtr(buf); } - fprintf(outf, "/XUID [103 0 1 16#%08X %u 16#%08X 16#%08X] def\n", static_cast<unsigned int>(rtl_crc32(0, ttf->ptr, ttf->fsize)), static_cast<unsigned int>(nGlyphs), static_cast<unsigned int>(rtl_crc32(0, glyphArray, nGlyphs * 2)), static_cast<unsigned int>(rtl_crc32(0, encoding, nGlyphs))); + snprintf(buf, bufmax, "/XUID [103 0 1 16#%08X %u 16#%08X 16#%08X] def\n", static_cast<unsigned int>(rtl_crc32(0, ttf->ptr, ttf->fsize)), static_cast<unsigned int>(nGlyphs), static_cast<unsigned int>(rtl_crc32(0, glyphArray, nGlyphs * 2)), static_cast<unsigned int>(rtl_crc32(0, encoding, nGlyphs))); + outf->WriteCharPtr(buf); DumpSfnts(outf, aOutBuffer.data(), aOutBuffer.size()); /* dump charstrings */ - fprintf(outf, "/CharStrings %d dict dup begin\n", nGlyphs); - fprintf(outf, "/.notdef 0 def\n"); - for (i = 1; i < nGlyfCount; ++i) { - fprintf(outf,"/glyph%d %d def\n", i, i); + snprintf(buf, bufmax, "/CharStrings %d dict dup begin\n", nGlyphs); + outf->WriteCharPtr(buf); + snprintf(buf, bufmax, "/.notdef 0 def\n"); + outf->WriteCharPtr(buf); + for (i = 1; i < nGlyfCount; i++) { + snprintf(buf, bufmax, "/glyph%d %d def\n", i, i); + outf->WriteCharPtr(buf); } - fprintf(outf, "end readonly def\n"); + snprintf(buf, bufmax, "end readonly def\n"); + outf->WriteCharPtr(buf); + + snprintf(buf, bufmax, "FontName currentdict end definefont pop\n"); + outf->WriteCharPtr(buf); - fprintf(outf, "FontName currentdict end definefont pop\n"); return SFErrCodes::Ok; } diff --git a/vcl/unx/generic/print/glyphset.cxx b/vcl/unx/generic/print/glyphset.cxx index 6b0475a62bc3..201ccb0fec33 100644 --- a/vcl/unx/generic/print/glyphset.cxx +++ b/vcl/unx/generic/print/glyphset.cxx @@ -193,7 +193,7 @@ struct EncEntry } -static void CreatePSUploadableFont( TrueTypeFont* pSrcFont, FILE* pTmpFile, +static void CreatePSUploadableFont( TrueTypeFont* pSrcFont, SvStream* pTmpFile, const char* pGlyphSetName, int nGlyphCount, /*const*/ const sal_uInt16* pRequestedGlyphs, /*const*/ const unsigned char* pEncoding, bool bAllowType42 ) @@ -240,10 +240,7 @@ GlyphSet::PSUploadFont (osl::File& rOutFile, PrinterGfx &rGfx, bool bAllowType42 return; utl::TempFile aTmpFile; - aTmpFile.EnableKillingFile(); - FILE* pTmpFile = fopen(OUStringToOString(aTmpFile.GetFileName(), osl_getThreadTextEncoding()).getStr(), "w+b"); - if (pTmpFile == nullptr) - return; + SvStream* pTmpFile = aTmpFile.GetStream(StreamMode::READWRITE); // encoding vector maps character encoding to the ordinal number // of the glyph in the output file @@ -271,31 +268,30 @@ GlyphSet::PSUploadFont (osl::File& rOutFile, PrinterGfx &rGfx, bool bAllowType42 // create the current subset OString aGlyphSetName = GetGlyphSetName(nGlyphSetID); - fprintf( pTmpFile, "%%%%BeginResource: font %s\n", aGlyphSetName.getStr() ); + pTmpFile->WriteOString( OStringConcatenation(OString::Concat("%%BeginResource: font ")+ aGlyphSetName + "\n") ); CreatePSUploadableFont( pTTFont, pTmpFile, aGlyphSetName.getStr(), glyph.size(), pTTGlyphMapping, pEncoding, bAllowType42 ); - fprintf( pTmpFile, "%%%%EndResource\n" ); + pTmpFile->WriteOString("%%EndResource\n" ); rSuppliedFonts.push_back( aGlyphSetName ); ++nGlyphSetID; } // copy the file into the page header - rewind(pTmpFile); - fflush(pTmpFile); + pTmpFile->Seek(0); + pTmpFile->Flush(); unsigned char pBuffer[0x2000]; sal_uInt64 nIn; sal_uInt64 nOut; do { - nIn = fread(pBuffer, 1, sizeof(pBuffer), pTmpFile); + nIn = pTmpFile->ReadBytes(pBuffer, sizeof(pBuffer)); rOutFile.write (pBuffer, nIn, nOut); } - while ((nIn == nOut) && !feof(pTmpFile)); + while ((nIn == nOut) && !pTmpFile->eof()); // cleanup CloseTTFont (pTTFont); - fclose (pTmpFile); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */