summaryrefslogtreecommitdiff
path: root/gs
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2009-07-28 16:20:51 +0000
committerKen Sharp <ken.sharp@artifex.com>2009-07-28 16:20:51 +0000
commit346797ab8b52ee71f2f5417747d7a0f8dbb10e96 (patch)
tree04cedf2955a7cb851fa7e1b3a6365f3036d73346 /gs
parentd44f38bedfd50a7210ef6a50fb955b3a8a94d07c (diff)
downloadghostpdl-346797ab8b52ee71f2f5417747d7a0f8dbb10e96.tar.gz
Fix (pdfwrite): Excessive redefinitions of CIDFonts causing memory exhaustion
Details: bug #690642: "conversion to PDF aborts after 800 pages" When instantiating a CIDFont with TrueType outlines, the TrueType interpretation code tries to name the font using the name table from the TrueType font. If there is no name table (as is the case for CIDFonts with TT outlines) it instead uses the XUID as the name. The XUID is incremented on every use, this means that each time the font is instantiated (up to once per page when the job is PDF) we create a new CIDFont with a new name. pdfwrite is unable to determine that these are all in fact the same original font, and creates many fonts in the output file, eventually leading to memory exhaustion. This change creates a new key in the current dictionary '/PDFCIDFontName', while processing a CIDFont with TrueType outlines for a PDF file, which is the same as the CIDFont BaseFont name. Since PDF can only have one descendant font per CIDFont this should not cause name collisions. To avoid interference with PostScript the key is removed from the current dictionary after use. In the TrueType interpreter, if we are handling a CIDRFont then after loading the TT tables we check to see if /PDFCIDFontName is defined. If it is we use it to replace the /FontName and /CIFontName values. This means we only ever create the font with a single name, which avoids the confusion with pdfwrite. With this change pdfwrite only emits a single font and, usefully, it has the same name as the font in the original PDF file. Expected Differences None git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@9897 a1074d23-0009-0410-80fe-cf8c14f379e6
Diffstat (limited to 'gs')
-rw-r--r--gs/Resource/Init/gs_ttf.ps9
-rw-r--r--gs/Resource/Init/pdf_font.ps3
2 files changed, 12 insertions, 0 deletions
diff --git a/gs/Resource/Init/gs_ttf.ps b/gs/Resource/Init/gs_ttf.ps
index da0dab6b6..0e9a2c87b 100644
--- a/gs/Resource/Init/gs_ttf.ps
+++ b/gs/Resource/Init/gs_ttf.ps
@@ -1605,6 +1605,15 @@ currentdict /postalias undef
% CIDFontType2 fonts don't have a cmap: they are indexed by CID.
mark
.ttkeys
+ /PDFCIDFontName where { % Only set if called by the PDF interpreter.
+ pop % Remove the dictionary where it is defined.
+ /fontname PDFCIDFontName def % Use the substitute name, not the name from the name
+ % table or manufactured from XUID.
+ .dicttomark dup % convert keys to dict and copy dict
+ /FontName fontname put % replace any definition of /FontName
+ mark exch % put a mark on stack
+ {} forall % read keys from dict back onto stack
+ } if
.definettcidfont
} bind def
diff --git a/gs/Resource/Init/pdf_font.ps b/gs/Resource/Init/pdf_font.ps
index 04c002515..217ccbb6f 100644
--- a/gs/Resource/Init/pdf_font.ps
+++ b/gs/Resource/Init/pdf_font.ps
@@ -1006,8 +1006,11 @@ currentdict /eexec_pdf_param_dict .undef
true resolvestream readfontfilter
% Stack: filepos fontres stream
1 index /Subtype get /CIDFontType2 eq {
+ 1 index /BaseFont get % Use the BaseFont name for the font. Otherwise we
+ /PDFCIDFontName exch def % would use the name table, or a manufactured name.
.loadttcidfont
% Stack: filepos fontres cidfont
+ currentdict /PDFCIDFontName undef % Remove the name to avoid interference.
} {
% filepos fontres stream
1 index /FontDescriptor oget % filepos fontres stream fd