Blame SOURCES/ghostscript-strange-fonts.patch

c9d7fc
diff -up ghostscript-9.07/Resource/Init/gs_ttf.ps.strange-fonts ghostscript-9.07/Resource/Init/gs_ttf.ps
c9d7fc
--- ghostscript-9.07/Resource/Init/gs_ttf.ps.strange-fonts	2013-02-14 07:58:16.000000000 +0000
c9d7fc
+++ ghostscript-9.07/Resource/Init/gs_ttf.ps	2013-06-18 16:09:49.904150294 +0100
c9d7fc
@@ -41,21 +41,17 @@
c9d7fc
 % Closes the file in either case.
c9d7fc
 /.findnonttfontvalue /.findfontvalue load def
c9d7fc
 /.findfontvalue {
c9d7fc
-  1 index read {
c9d7fc
-    2 index 1 index unread
c9d7fc
-    % beginning with binary 0 or 't' (TrueType), or 'O' (OpenType)
c9d7fc
-    dup 0 eq 1 index (O) 0 get eq or exch (t) 0 get eq or {
c9d7fc
+  1 index .is_ttf_or_otf {
c9d7fc
                 % If this is a font at all, it's a TrueType font.
c9d7fc
       dup /FontType eq {
c9d7fc
         pop closefile 42 //true
c9d7fc
       } {
c9d7fc
         dup /FontName eq { pop .findttfontname } { pop closefile //false } ifelse
c9d7fc
       } ifelse
c9d7fc
-    } {
c9d7fc
+  } {
c9d7fc
                 % Not a TrueType font.
c9d7fc
       .findnonttfontvalue
c9d7fc
-    } ifelse
c9d7fc
-  } { pop closefile //false } ifelse
c9d7fc
+  } ifelse
c9d7fc
 } bind def
c9d7fc
 
c9d7fc
 % <file> .findttfontname <fname> true
c9d7fc
@@ -65,7 +61,9 @@
c9d7fc
   //true 0 .loadttfonttables
c9d7fc
   tabdict /name .knownget {
c9d7fc
     dup 8 getu32 f exch setfileposition
c9d7fc
-    12 getu32 string f exch readstring pop
c9d7fc
+    12 getu32
c9d7fc
+    dup 65535 gt { pop 65535 } if % protect against extremely large name
c9d7fc
+    string f exch readstring pop
c9d7fc
     dup
c9d7fc
     6 findname not {
c9d7fc
       4 findname	% Try FullName
c9d7fc
@@ -82,6 +80,7 @@
c9d7fc
 % Load a font file that might be a TrueType font.
c9d7fc
 
c9d7fc
 /tt_tag_dict << <00010000> 0 (true) 0 (typ1) 0 (ttcf) 0 >> readonly def
c9d7fc
+/ttf_otf_tag_dict << <00010000> 0 (true) 0 (typ1) 0 (ttcf) 0 (OTTO) 0>> readonly def
c9d7fc
 
c9d7fc
 % <file> .loadfontfile -
c9d7fc
 /.loadnonttfontfile /.loadfontfile load def
c9d7fc
@@ -95,7 +94,13 @@
c9d7fc
   } ifelse
c9d7fc
 } bind def
c9d7fc
 
c9d7fc
+% <file> .istruetypefont <bool>
c9d7fc
+/.is_ttf_or_otf {
c9d7fc
+    dup 0 setfileposition (1234) .peekstring { //ttf_otf_tag_dict exch known } { //false } ifelse
c9d7fc
+} bind def
c9d7fc
+
c9d7fc
 currentdict /tt_tag_dict .undef
c9d7fc
+currentdict /ttf_otf_tag_dict .undef
c9d7fc
 
c9d7fc
 % ---------------- Automatic Type 42 generation ---------------- %
c9d7fc