% Copyright (C) 1995, 2000 Aladdin Enterprises. All rights reserved.
%
% This software is provided AS-IS with no warranty, either express or
% implied.
%
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
%
% For more information about licensing, please refer to
% http://www.ghostscript.com/licensing/. For information on
% commercial licensing, go to http://www.artifex.com/licensing/ or
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA 94903, U.S.A., +1(415)492-9861.
% $Id: gs_cmap.ps 8954 2008-08-08 04:22:38Z ray $
% ProcSet for implementing CMap resources.
% When this is run, systemdict is still writable.
% NOTE: Rearranged fonts are not implemented yet.
[
/CMERGE_DEBUG
/USE_CIDCHAR_AS_RANGE
] {dup where {pop pop} { currentdict exch //false def pop } ifelse} forall
% ---------------- Public operators ---------------- %
/.rewriteTempMapsNotDef {
%
% Before building .CodeMapData from .TempMaps,
% we need to replace dst type codes in the notdef map with the value 3,
% which corresponds to CODE_VALUE_NOTDEF, see gxfcmap.h .
%
CMAPDEBUG { (rewriting TempMapsNotDef\n) print flush } if
.TempMaps 2 get
dup length 0 gt {
0 get
CMAPDEBUG { (...original...\n) print flush } if
1 5 2 index length 1 sub {
{ 1 index exch get 2 3 put } stopped
{ CMAPDEBUG { (cannot rewrite\n) print flush } if }
{ CMAPDEBUG { (rewrite\n) print flush } if } ifelse
} for
} if
pop
CMAPDEBUG { (...FINISHED...\n) print } if
} bind def
/.composefontdict { % composefont
10 dict begin
/CMap 2 index dup type /dicttype ne { /CMap findresource } if def
/FDepVector 1 index cvlit def % temporarily
/Encoding [ 0 1 FDepVector length 1 sub { } for ] def
/FontInfo 1 dict def % for .processToUnicode in pdf_font.ps .
/FDepVector [ 0 1 FDepVector length 1 sub {
% Stack: name cmap[name] fonts /FDepVector [ fonts... i
FDepVector 1 index get
dup type /dicttype ne {
dup /CIDFont resourcestatus {
pop pop /CIDFont
} {
/Font
} ifelse findresource
} if
exch CMap /FontMatrices get dup length 2 index gt {
exch get dup //null eq { pop } { makefont } ifelse
} {
pop pop
} ifelse
} for ] readonly def
/FMapType 9 def
/FontMatrix matrix def
/FontName 3 index def
CMap /WMode .knownget { /WMode exch def } if
/FontType 0 def
pop pop currentdict end
} bind odef
% composefont doesn't appear in CMap files -- it's documented in
% the "PostScript Language Reference Manual Supplement".
/composefont { % composefont
.composefontdict /Font defineresource
} bind def
% ---------------- CMap operators ---------------- %
40 dict begin
% Our internal .CodeMapData structure closely mirrors the structures
% defined in gxfcmap.h (q.v.). () indicate a string, [] indicate an array,
% ? indicates a Boolean, # indicates an integer, {} for grouping.
% [[[(first) (last) ...]+] % code space ranges
% [[(prefix) (key_size,?is_range,value_type,value_size) (keys...)
% {(values...) | [value ...]} #font_index ]+] % code mappings
% ...]
% <> % notdef mappings
% ]
% FontMatrices is the array of matrices defined by begin/endusematrix.
% All of the arrays and strings are read-only after they have been built.
%
% Note that the code in zfcmap.c that constructs the C structures from
% the PostScript structures has intimate knowledge of the above format.
% ****** NOTE: The code currently only handles "well-behaved" CMaps:
% - CID values only (no bfchars), 16-bit
% - Entries (both code space and map) must be sorted
% - Only the last byte must vary in each map range, except for
% the identity mapping
% ------ Font-level operators ------ %
/begincmap { % - begincmap -
/.CodeMapData [[[]] [[]] [[]]] def
/FontMatrices [] def
/.FontIndex 0 def
/.TempMaps [20 dict 50 dict 50 dict] def
/CodeMap //null def % for .buildcmap
} bind def
/endcmap { % - endcmap -
.rewriteTempMapsNotDef
CMAPDEBUG {
2 (*** undefined charmap ***)
1 (*** defined charmap ***)
0 (*** code space ranges ***)
3 { =
.TempMaps exch get
0 1 2 index length 1 sub {
dup == (\t) print
1 index exch get ==
} for
pop
} repeat
} if
/.CodeMapData dup load [ exch
.TempMaps aload pop begin begin begin
{
[ exch aload pop
0 1 currentdict length 1 sub {
currentdict exch get
} for
]
end
} forall
] .endmap def
CMAPDEBUG {
(*** Content of .CodeMapData ***) =
0 .CodeMapData { exch dup == 1 add exch (\t) print == } forall
pop
} if
currentdict /.TempMaps undef
/FontMatrices FontMatrices .endmap def
} bind def
/.endmap { %