[gs-cvs] rev 7129 - trunk/gs/lib
leonardo at ghostscript.com
leonardo at ghostscript.com
Thu Oct 26 15:14:02 PDT 2006
Author: leonardo
Date: 2006-10-26 15:14:01 -0700 (Thu, 26 Oct 2006)
New Revision: 7129
Modified:
trunk/gs/lib/gs_ttf.ps
trunk/gs/lib/pdf_font.ps
Log:
Fix (TT font reader) : Obtain Unicode codes from Encoding glyph names of a special format.
DETAILS :
Bug 688946 "Problem reading PDF file with Arabic font".
We think we observe an undocumented Adobe feature.
This patch has no strong theoretic foundation.
It is created empirically.
An embedded True Type font has no some glyph names in its 'post' table,
but they present in Encoding Differences.
The glyph names look as uniXXXX where XXXX is 4 hexadecimal digits.
The corresponding character codes can't be translated into
glyph indices neither with AdobeGlyphList, nor with 'post',
nor by the identity or another simple mapping to Unicode.
We conclude that Adobe recognizes such names and
obtains Unicode codes from them, and then translates
them with 'cmap'. We think it is only possible correct method for
the supplied test case. This patch implements it.
1. Passed Encoding as prebuilt_encoding for symbolic fonts (pdf_font.ps).
2. When a symbolic font has an Unicode 'cmap',
account glyph names from its Encoding (the change to .pdfcharkeys in gs_ttf.ps)
while composing CharStrings.
3. Modified .addglyph with conversion of uniXXXX names into Unicode codes.
4. The new mapping is allowed only with cmap 3.1.
Debugged with Bug688467.ps .
EXPECTED DIFFERENCES :
None.
Modified: trunk/gs/lib/gs_ttf.ps
===================================================================
--- trunk/gs/lib/gs_ttf.ps 2006-10-26 08:26:31 UTC (rev 7128)
+++ trunk/gs/lib/gs_ttf.ps 2006-10-26 22:14:01 UTC (rev 7129)
@@ -1572,20 +1572,63 @@
.defineencoding
} bind exec
+/.hexdigits (0123456789ABCDEF) def
+
+/.is_hex_digit { % <int> .is_hex_digit <bool>
+ dup 48 ge exch
+ dup 57 le exch
+ dup 65 ge exch
+ 70 le and
+ 3 1 roll
+ and or
+} bind def
+
+/.popfex { pop //false exit } bind def
+/.pop3ex { pop pop pop exit } bind def
+
/.addglyph { % <dict> <name> <glyph#> .addglyph -
- dup cmapencoding length lt {
- cmapencoding exch get dup 0 ne {
- 3 copy pop known {
- pop pop pop
- } {
- put
- } ifelse
- } {
- pop pop pop
- } ifelse
+ 1 index .namestring % d n g s
+ dup length 7 eq {
+ % Bug688467.ps doesn't work if the uniXXXX mapping is allowed with any cmap.
+ % Allow it with cmap 3.1 only.
+ currentdict /.allow_uniXXXX_glyph_names .knownget not { //false } if
+ } { //false
+ } ifelse % d n g s b
+ {
+ % An undocumented Adobe feature (not sure) :
+ % if the name is uniXXXX, obtain Unicode code from it.
+ % See bug 688946.
+ TTFDEBUG { (Try uniXXXX:) print dup print } if
+ { dup 0 get 117 ne //.popfex if % u
+ dup 1 get 110 ne //.popfex if % n
+ dup 2 get 105 ne //.popfex if % i
+ dup 3 get //.is_hex_digit exec not //.popfex if
+ dup 4 get //.is_hex_digit exec not //.popfex if
+ dup 5 get //.is_hex_digit exec not //.popfex if
+ dup 6 get //.is_hex_digit exec not //.popfex if
+ dup 3 1 getinterval .hexdigits exch search pop length exch pop exch pop 12 bitshift exch
+ dup 4 1 getinterval .hexdigits exch search pop length exch pop exch pop 8 bitshift exch
+ dup 5 1 getinterval .hexdigits exch search pop length exch pop exch pop 4 bitshift exch
+ dup 6 1 getinterval .hexdigits exch search pop length exch pop exch pop exch pop
+ add add add
+ dup cmapencoding length ge //.popfex if
+ cmapencoding exch get
+ dup 0 eq //.popfex if
+ TTFDEBUG { ( index=) print dup =string cvs print } if
+ exch pop
+ put //true exit
+ } loop
+ TTFDEBUG { ()= } if
} {
- pop pop pop
+ pop //false
} ifelse
+ not { % d n g
+ { dup cmapencoding length ge //.pop3ex if
+ cmapencoding exch get dup 0 eq //.pop3ex if
+ 3 copy pop known //.pop3ex if
+ put exit
+ } loop
+ } if
} bind def
% <subcmap> <chartoglyphmap> .pdfmapchars /CharStrings <charstrings>
@@ -1624,7 +1667,6 @@
/.pdfcharkeys {
% The following algorithms are per the PDF Reference, Second Edition
% (PDF 1.3 reference manual).
-
is_symbolic {
<00030001> .findcmap {
%
@@ -1677,6 +1719,7 @@
% Try to map Unicode to SymbolEncoding
<00030001> .findcmap {
TTFDEBUG { (Using cmap 3.1) = } if
+ /.allow_uniXXXX_glyph_names //true def
AdobeGlyphList .pdfmapchars
/Encoding /SymbolEncoding .findencoding
} {
@@ -1711,12 +1754,20 @@
} ifelse
} {
<00030001> .findcmap {
- TTFDEBUG { (Using cmap 3.1 for non-symbolic.) = } if
- AdobeGlyphList .pdfmapchars
- /Encoding /WinAnsiEncoding .findencoding
- % WinAnsiEncoding is just a stub here.
- % It will be replaced with one from font resource,
- % because PDF spec requires it.
+ prebuilt_encoding null ne {
+ TTFDEBUG { (Using cmap 3.1 with prebuilt_encoding for non-symbolic.) = } if
+ /.allow_uniXXXX_glyph_names //true def
+ prebuilt_encoding .invert_encoding .pdfmapchars
+ /Encoding prebuilt_encoding
+ } {
+ % Likely this branch is now obsolete.
+ TTFDEBUG { (Using cmap 3.1 for non-symbolic.) = } if
+ AdobeGlyphList .pdfmapchars
+ /Encoding /WinAnsiEncoding .findencoding
+ % WinAnsiEncoding is just a stub here.
+ % It will be replaced with one from font resource,
+ % because PDF spec requires it.
+ } ifelse
} {
<00010000> .findcmap {
TTFDEBUG { (Using cmap 1.0 for non-symbolic.) = } if
Modified: trunk/gs/lib/pdf_font.ps
===================================================================
--- trunk/gs/lib/pdf_font.ps 2006-10-26 08:26:31 UTC (rev 7128)
+++ trunk/gs/lib/pdf_font.ps 2006-10-26 22:14:01 UTC (rev 7129)
@@ -856,11 +856,11 @@
/Flags get 4 and 0 ne % filepos fontres stream is_symbolic
dup {
2 index null exch getencoding % filepos fontres stream is_symbolic Encoding
- dup 4 index exch % filepos fontres stream is_symbolic Encoding fontres Encoding
- /prebuilt_encoding exch put % filepos fontres stream is_symbolic Encoding
} {
- null
+ 2 index StandardEncoding exch getencoding
} ifelse
+ dup 4 index exch % filepos fontres stream is_symbolic Encoding fontres Encoding
+ /prebuilt_encoding exch put % filepos fontres stream is_symbolic Encoding
.loadpdfttfont
} ifelse
exch pop
More information about the gs-cvs
mailing list