Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 144769 | Differences between
and this patch

Collapse All | Expand All

(-)addons/opvp/opvp_common.h (-23 / +19 lines)
Lines 33-52 Link Here
33
#define _PDAPI_VERSION_MINOR_	2
33
#define _PDAPI_VERSION_MINOR_	2
34
34
35
/* Return Values */
35
/* Return Values */
36
#define	OPVP_OK			0	/* ¥¨¥é¡¼¤Ï -1 */
36
#define	OPVP_OK			0	/* error is -1 */
37
37
38
/* Error Codes */
38
/* Error Codes */
39
#define	OPVP_FATALERROR		-101	/* ¥é¥¤¥Ö¥é¥êÆâ¤ÇÉüµìÉÔ²Äǽ¤Ê¥¨¥é¡¼¤¬ */
39
#define	OPVP_FATALERROR		-101	/* unrecoverable error occurred within the */
40
					/* ȯÀ¸¤·¤¿ */
40
									/* library */
41
#define	OPVP_BADREQUEST		-102	/* ´Ø¿ô¤ò¸Æ¤ó¤Ç¤Ï¤¤¤±¤Ê¤¤¤È¤³¤í¤Ç¡¢ */
41
#define	OPVP_BADREQUEST		-102	/* invalid function parameters */
42
					/* ¸Æ¤ó¤Ç¤·¤Þ¤Ã¤¿ */
42
#define	OPVP_BADCONTEXT		-103	/* bad parameter precontext */
43
#define	OPVP_BADCONTEXT		-103	/* ¥Ñ¥é¥á¡¼¥¿¤Î¥×¥ê¥³¥ó¥Æ¥­¥¹¥È¤¬ÉÔÀµ */
43
#define	OPVP_NOTSUPPORTED	-104	/* printer or driver request not supported */
44
#define	OPVP_NOTSUPPORTED	-104	/* ¥Ñ¥é¥á¡¼¥¿¤ÎÁȤ߹ç¤ï¤»¤Ë¤è¤ê¡¢ */
44
#define	OPVP_JOBCANCELED	-105	/* job cancelled */
45
					/* ¥É¥é¥¤¥Ð¤â¤·¤¯¤Ï¥×¥ê¥ó¥¿¤¬ */
45
#define	OPVP_PARAMERROR		-106	/* illegal parameter combination */
46
					/* °·¤¨¤Ê¤¤¥ê¥¯¥¨¥¹¥È¤¬¹Ô¤Ê¤ï¤ì¤¿ */
47
#define	OPVP_JOBCANCELED	-105	/* ²¿¤é¤«¤ÎÍ×°ø¤Ë¤è¤ê¡¢¥¸¥ç¥Ö¤ò */
48
					/* ¥­¥ã¥ó¥»¥ë¤·¤Æ¤¤¤ë */
49
#define	OPVP_PARAMERROR		-106	/* ¥Ñ¥é¥á¡¼¥¿¤ÎÁȤ߹ç¤ï¤»¤¬ÉÔÀµ */
50
46
51
/* Info params */
47
/* Info params */
52
#define	OPVP_INFO_PREFIX	"updf:"
48
#define	OPVP_INFO_PREFIX	"updf:"
Lines 80-92 Link Here
80
} OPVP_Point;
76
} OPVP_Point;
81
77
82
typedef	struct	_OPVP_Rectangle {
78
typedef	struct	_OPVP_Rectangle {
83
	OPVP_Point	p0;		/* ³«»ÏÅÀ */
79
	OPVP_Point	p0;		/* start point */
84
	OPVP_Point	p1;		/* ½ªÎ»ÅÀ */
80
	OPVP_Point	p1;		/* end point */
85
} OPVP_Rectangle;
81
} OPVP_Rectangle;
86
82
87
typedef	struct	_OPVP_RoundRectangle {
83
typedef	struct	_OPVP_RoundRectangle {
88
	OPVP_Point	p0;		/* ³«»ÏÅÀ */
84
	OPVP_Point	p0;		/* start point */
89
	OPVP_Point	p1;		/* ½ªÎ»ÅÀ */
85
	OPVP_Point	p1;		/* end point */
90
	OPVP_Fix	xellipse;
86
	OPVP_Fix	xellipse;
91
	OPVP_Fix	yellipse;
87
	OPVP_Fix	yellipse;
92
} OPVP_RoundRectangle;
88
} OPVP_RoundRectangle;
Lines 192-204 Link Here
192
} OPVP_Brush;
188
} OPVP_Brush;
193
189
194
/* Misc. Flags */
190
/* Misc. Flags */
195
#define	OPVP_Arc		0	/* ±ß¸Ì */
191
#define	OPVP_Arc		0	/* circular arc */
196
#define	OPVP_Chord		1	/* µÝ·Á */
192
#define	OPVP_Chord		1	/* arch */
197
#define	OPVP_Pie		2	/* Àð·Á */
193
#define	OPVP_Pie		2	/* pie section */
198
#define	OPVP_Clockwise		0	/* »þ·×Êý¸þ */
194
#define	OPVP_Clockwise		0	/* clockwise */
199
#define	OPVP_Counterclockwise	1	/* È¿»þ·×Êý¸þ */
195
#define	OPVP_Counterclockwise	1	/* counter-clockwise */
200
#define	OPVP_PathClose		0	/* Close path upon LinePath */
196
#define	OPVP_PathClose		0	/* Close path when using LinePath */
201
#define	OPVP_PathOpen		1	/* Do not close path upon LinePath */
197
#define	OPVP_PathOpen		1	/* Do not close path when using LinePath */
202
198
203
/* CTM */
199
/* CTM */
204
typedef	struct	_OPVP_CTM {
200
typedef	struct	_OPVP_CTM {
(-)lib/cjkv/baseutil.ps (+569 lines)
Line 0 Link Here
1
%!
2
%
3
% Developed by AXE,Inc., BBR Inc. and Turbolinux Inc.
4
%   under the technical advice by suzuki toshiya (Hiroshima University)
5
% For questions, please send mail to espgs8-cjk@printing-japan.org
6
%
7
% (C) Copyright 2006 Center of the International Cooperation for
8
%     Computerization
9
%
10
%
11
% Based on gs-cjk patches
12
% Copyright (C) 2001-2003 gs-cjk project:
13
%   Taiji Yamada, Masatake Yamato, Hideyuki Suzuki and suzuki toshiya.
14
%   Enhancements by Akira Tagoh and Taiji Yamada, 2005.
15
%   All rights reserved.
16
%
17
%
18
% Based on GNU Ghostscript 7.07 and 8.15
19
% Copyright (C) 1996-2003 artofcode LLC.  All rights reserved.
20
%
21
% This software is provided AS-IS with no warranty, either express or
22
% implied.
23
%
24
%
25
% This program is free software;  you can redistribute it and/or
26
% modify it under the terms of the GNU General Public License as
27
% published by the Free Software Foundation; either version 2 of
28
% the License, or (at your option) any later version.
29
%
30
% This program is distributed in the hope that it will be useful,
31
% but WITHOUT ANY WARRANTY; without even the implied warranty of
32
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
33
% See the GNU General Public License for more details.
34
%
35
% You should have received a copy of the GNU General Public License
36
% along with this program; if not, write to the Free Software Foundation,
37
% Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38
%
39
40
[
41
   /CJKV_DEBUG_BASE
42
] {dup where {pop pop} { currentdict exch false def pop } ifelse} forall
43
44
/_cjkv_ttcmap_tmp 10 dict def
45
46
/_cjkv_base_util 50 dict dup begin
47
48
  /.cjkv_newdicttomark { % <mark> <k1> <v1> ... <kn> <vn> <extra_space> .cjkv_newdicttomark <dict>
49
    CJKV_DEBUG_BASE { (--- .cjkv_newdicttomark start\n) print flush  } if
50
    counttomark 1 sub 2 idiv add dict   % <mark> <k1> <v1> ... <kn> <vn> <dict>
51
    CJKV_DEBUG_BASE { (--- scratch dict making finished\n) print flush  } if
52
    counttomark 1 sub 2 idiv {
53
      dup                               % <mark> <k1> <v1> ... <kn> <vn> <dict> <dict>
54
      4 2 roll                          % <mark> <k1> <v1> ... <dict> <dict> <kn> <vn>
55
      dup type /stringtype eq { dup length string copy } if
56
      dup type /arraytype  eq {
57
        dup length array exch dup length 0 exch 1 exch 1 sub {
58
          1 index 1 index get dup type /stringtype eq {
59
            dup length string copy
60
          } if
61
          [ exch ]
62
          3 index 3 1 roll putinterval
63
        } for
64
        pop
65
      } if
66
      dup type /dicttype   eq {
67
        dup length dict exch
68
        [ 1 index { pop } forall ] {
69
          1 index 1 index get dup type /stringtype eq {
70
            dup length string copy
71
          } if
72
          3 index 3 1 roll put
73
        } forall
74
        pop
75
      } if
76
      put                               % <mark> <k1> <v1> ... <dict>
77
      CJKV_DEBUG_BASE { (--- copy ok\n) print flush  } if
78
    } repeat                            % <mark> <dict>
79
    exch pop                            % <dict>
80
    CJKV_DEBUG_BASE { (--- .cjkv_newdicttomark ok\n) print flush  } if
81
  } bind def
82
83
  /orgXUID AladdinEnterprisesXUID def
84
  /maxstring 32000 def    % half the maximum length of a PostScript string,
85
                          % must be a multiple of 4 (for hmtx / loca / vmtx)
86
  
87
88
  /.cjkv_xuidstring <80000000> def
89
90
  /.cjkv_curxuid {              % - curxuid <int>
91
    0 .cjkv_xuidstring { exch 8 bitshift exch add } forall
92
  } bind def
93
94
  /.cjkv_nextxuid {             % - nextxuid -
95
    3 -1 0 {
96
      .cjkv_xuidstring 1 index 2 copy get dup 255 ne {
97
        1 add put pop exit
98
      } if pop 0 put pop
99
    } for
100
  } bind def
101
  
102
  % <string> <index> .cjkv_getu16 <integer>
103
  /.cjkv_getu16 {
104
    2 copy get 8 bitshift 3 1 roll 1 add get add
105
  } bind def
106
  
107
  % <string> <index> .cjkv_gets16 <integer>
108
  /.cjkv_gets16 {
109
    .cjkv_getu16 16#8000 xor 16#8000 sub
110
  } bind def
111
  
112
  % <string> <index> .cjkv_getu32 <integer>
113
  /.cjkv_getu32 {
114
    2 copy .cjkv_getu16 16 bitshift 3 1 roll 2 add .cjkv_getu16 add
115
  } bind def
116
  
117
  % <string> <index> .cjkv_gets32 <integer>
118
  /.cjkv_gets32 {
119
    2 copy .cjkv_gets16 16 bitshift 3 1 roll 2 add .cjkv_getu16 add
120
  } bind def
121
  
122
  % <string> <index> <integer> .cjkv_putu16 -
123
  /.cjkv_putu16 {
124
    3 copy -8 bitshift put
125
    exch 1 add exch 16#ff and put
126
  } bind def
127
  
128
  % <string> <index> <integer> .cjkv_putu32 -
129
  /.cjkv_putu32 {
130
    3 copy -16 bitshift .cjkv_putu16
131
    exch 2 add exch 16#ffff and .cjkv_putu16
132
  } bind def
133
134
  /.cjkv_biglength { % <str>|<array of str> .biglength <integer>
135
    dup type /arraytype eq { 0 exch { length add } forall } { length } ifelse
136
  } bind def
137
  
138
  /.cjkv_concats { % [str ...] concats str
139
    () exch dup length 1 sub -1 0 {
140
      1 index exch get dup type /stringtype ne { dup length string cvs } if
141
      3 -1 roll exch dup length 2 index length add string
142
      dup dup 4 2 roll copy length 4 -1 roll putinterval exch
143
    } for pop
144
  } bind def
145
  
146
  % <str>|<array of str> <index> <count> .cjkv_biggetinterval <str>|<array of str>
147
  /.cjkv_biggetinterval {
148
    currentglobal 4 1 roll
149
    false setglobal
150
    5 dict begin
151
    2 index type /arraytype eq {
152
      /c exch def
153
      /i exch def
154
      [ exch {
155
        dup length /l exch def
156
        i c add l gt {
157
          i l lt {
158
            i l i sub getinterval
159
            /c i c add l sub def
160
            /i 0 def
161
          } {
162
            pop
163
            /i i l sub def
164
          } ifelse
165
        } {
166
          i c getinterval exit
167
        } ifelse
168
      } forall
169
      counttomark array dup length 1 sub -1 0 { 1 index exch 3 index put exch pop } for exch pop
170
      dup .cjkv_biglength 65535 le { .cjkv_concats } if
171
    } { getinterval } ifelse
172
    end
173
    exch setglobal
174
  } bind def
175
  
176
  % <str>|<array of str> <index> .cjkv_biggetu16 <integer>
177
  /.cjkv_biggetu16 {
178
    2 .cjkv_biggetinterval 0 .cjkv_getu16
179
  } bind def
180
  
181
  % <str>|<array of str> <index> .cjkv_biggetu32 <integer>
182
  /.cjkv_biggetu32 {
183
    4 .cjkv_biggetinterval 0 .cjkv_getu32
184
  } bind def
185
  
186
  % <string> .cjkv_strtoint <integer>
187
  /.cjkv_strtoint {
188
    0 exch { exch 8 bitshift add } forall
189
  } bind def
190
  
191
  % <nametable> <nameid> findname <string> true
192
  % <nametable> <nameid> findname false
193
  /.cjkv_findname {
194
    CJKV_DEBUG_BASE { (findname: ) print dup =only  } if
195
    false 3 1 roll 0 1 3 index 2 .cjkv_getu16 1 sub {
196
                  % Stack: false table id index
197
      12 mul 6 add 2 index exch 12 getinterval
198
      dup 6 .cjkv_getu16 2 index eq {
199
                  % We found the name we want.
200
        exch pop
201
                  % Stack: false table record
202
        dup 10 .cjkv_getu16 2 index 4 .cjkv_getu16 add
203
        1 index 8 .cjkv_getu16 4 -1 roll 3 1 roll getinterval exch
204
                  % Stack: false string record
205
                  % Check for 8- vs. 16-bit characters.
206
        .cjkv_is2byte { .cjkv_string2to1 } if true null 4 -1 roll exit
207
      } if pop
208
    } for pop pop
209
    CJKV_DEBUG_BASE {
210
      dup { ( = ) print 1 index == } { ( not found) = } ifelse
211
    } if
212
  } bind def
213
  
214
  % <namerecord> .cjkv_is2byte <bool>
215
  /.cjkv_is2byte {
216
    dup 0 .cjkv_getu16 {
217
      { pop true }                % Apple Unicode
218
      { pop false }               % Macintosh Script manager
219
      { 1 .cjkv_getu16 1 eq }           % ISO
220
      { 1 .cjkv_getu16 1 eq }           % Microsoft
221
    } exch get exec
222
  } bind def
223
  
224
  % <string2> string2to1 <string>
225
  /.cjkv_string2to1 {
226
    dup length 2 idiv string dup
227
    0 1 3 index length 1 sub {
228
      3 index 1 index 2 mul 1 add get put dup
229
    } for pop exch pop
230
  } bind def
231
  
232
233
  % <array> <lt-proc> .cjkv_sort <array>
234
  /.cjkv_sort {
235
    1 index length 1 sub -1 1 {
236
      2 index exch 2 copy get 3 copy      % arr proc arr i arr[i] arr i arr[i]
237
      0 1 3 index 1 sub {
238
        3 index 1 index get       % arr proc arr i arr[i] arr imax amax j arr[j]
239
        2 index 1 index 10 index exec {   % ... amax < arr[j]
240
          4 2 roll
241
        } if pop pop
242
      } for                       % arr proc arr i arr[i] arr imax amax
243
      4 -1 roll exch 4 1 roll put put
244
    } for pop
245
  } def
246
  
247
  
248
  % <array|string> <index> <count> .cjkv_safegetinterval <subarray|substring>
249
  /.cjkv_safegetinterval {
250
    exch 2 index length .min exch
251
    2 index length 2 index sub .min
252
    getinterval
253
  } bind def
254
  
255
  % <array> <index> <obj> .cjkv_safeput -
256
  /.cjkv_safeput {
257
    2 index length 2 index gt { put } { pop pop pop } ifelse
258
  } bind def
259
  
260
  % Each procedure in this dictionary is called as follows:
261
  %       <encodingtable> proc <glypharray>
262
  /_cjkv_cmapformats mark
263
    0 {		% Apple standard 1-to-1 mapping.
264
      6 256 getinterval { } forall 256 packedarray
265
    } bind
266
    2 {		% Apple 16bit CJK (ShiftJIS etc)
267
  
268
      % /sHK_sz		subHeaderKey_size	% 1 * uint16
269
      % /sH_sz		subHeader_size		% 4 * uint16
270
      % /sH_len		subHeader_length
271
      % /cmapf2_tblen	total table length
272
      % /cmapf2_lang	language code (not used)
273
      % /sHKs		subHeaderKeys
274
  
275
      /sHK_sz 2 def
276
      /sH_sz 8 def
277
      dup 2 .cjkv_getu16 /cmapf2_tblen exch def
278
  
279
      CJKV_DEBUG_BASE {
280
         (format2 table length: 0x) print
281
         cmapf2_tblen 16 10 string cvrs print
282
         (=) print
283
         cmapf2_tblen == flush
284
      } if
285
      dup 4 .cjkv_getu16 /cmapf2_lang exch def
286
  
287
      CJKV_DEBUG_BASE {
288
         (format2 lang code: 0x) print
289
         cmapf2_lang 16 10 string cvrs == flush
290
      } if
291
      dup 6 256 sHK_sz mul getinterval /sHKs exch def
292
      CJKV_DEBUG_BASE {
293
         (format2 subHeaderKeys: ) print
294
         sHKs == flush
295
         (scan subHeaderKeys\n) print flush
296
      } if
297
  
298
      0		% initialization value for /sH_len
299
      0 1 255 {
300
         CJKV_DEBUG_BASE {
301
            (hi byte ) =only
302
            dup 16 10 string cvrs =only
303
            (-> subHeader #) print
304
            flush
305
         } if
306
         sHKs exch
307
         2 mul .cjkv_getu16
308
         CJKV_DEBUG_BASE {
309
            dup 16 10 string cvrs =only
310
            ( ) print dup == flush
311
         } if
312
         1 index	% get current max
313
         1 index	% get current subHeaderKey
314
         lt {exch} if pop
315
      } for
316
      /sH_len exch def
317
  
318
      CJKV_DEBUG_BASE {
319
        (format2 subHeader length: ) print
320
        sH_len ==
321
        flush
322
      } if
323
      dup 6 256 sHK_sz mul add
324
      cmapf2_tblen 1 index sub getinterval
325
      /sH_gIA exch def
326
      CJKV_DEBUG_BASE {
327
         (format2 subHeaders + GID array: ) print
328
         sH_gIA ==
329
      } if
330
  
331
      /cmapf2_glyph_array 65535 array def
332
  
333
      /.cmapf2_putGID {
334
          /cmapf2_ch cmapf2_ch_hi 8 bitshift cmapf2_ch_lo add def
335
          CJKV_DEBUG_BASE {
336
              (code: ) =only cmapf2_ch 16 4 string cvrs =only
337
              ( -> ) =only
338
          } if
339
          firstCode cmapf2_ch_lo le
340
          cmapf2_ch_lo firstCode entryCount add lt
341
          and { % true: j is inside
342
              sH_offset idRangeOffset add		% offset to gI
343
              cmapf2_ch_lo firstCode sub 2 mul	% rel. pos. in range
344
              add 6 add				% offset in sH_gIA
345
              sH_gIA exch .cjkv_getu16
346
              dup 0 gt { % 
347
                  CJKV_DEBUG_BASE {
348
                      dup 16 8 string cvrs =only
349
                      (+) =only idDelta 16 8 string cvrs =only
350
                  } if
351
                  idDelta add
352
                  CJKV_DEBUG_BASE {
353
                      (=) =only dup 16 8 string cvrs == flush
354
                  } if
355
                  cmapf2_glyph_array exch cmapf2_ch exch put
356
              } {
357
                  CJKV_DEBUG_BASE {(specified 0: 0\n) print flush} if
358
                  pop
359
                  % cmapf2_glyph_array cmapf2_ch 0 put
360
              } ifelse
361
          } {   % false: j is outside
362
              CJKV_DEBUG_BASE {(outside of range: 0\n) print flush} if
363
              % cmapf2_glyph_array cmapf2_ch 0 put
364
          } ifelse
365
      } def
366
  
367
      16#00 1 16#ff { % hi_byte scan
368
          /cmapf2_ch_hi exch def
369
          sHKs cmapf2_ch_hi sHK_sz mul .cjkv_getu16
370
          CJKV_DEBUG_BASE {
371
              (subHeader_offset = idx * 8 = ) print
372
              dup ==
373
          } if
374
          /sH_offset exch def
375
          sH_gIA sH_offset sH_sz getinterval
376
              dup 0 .cjkv_getu16 /firstCode exch def
377
              dup 2 .cjkv_getu16 /entryCount exch def
378
              dup 4 .cjkv_gets16 /idDelta exch def
379
              dup 6 .cjkv_getu16 /idRangeOffset exch def
380
          pop
381
          CJKV_DEBUG_BASE {
382
             (idRangeOffset: ) print idRangeOffset 16 8 string cvrs ==
383
          } if
384
          sH_offset 0 eq {
385
             /cmapf2_ch_lo cmapf2_ch_hi def
386
             /cmapf2_ch_hi 0 def
387
             .cmapf2_putGID
388
          } {
389
             16#00 1 16#ff { % lo_byte scan
390
                 /cmapf2_ch_lo exch def
391
                 .cmapf2_putGID
392
             } for
393
          } ifelse
394
       } for
395
       pop
396
       0 1 cmapf2_glyph_array length 1 sub { % rewrite null -> 0.
397
          % CJKV_DEBUG_BASE { (rewriting null: ) print dup == flush } if
398
          dup cmapf2_glyph_array exch get
399
          null eq { cmapf2_glyph_array exch 0 put } {pop} ifelse 
400
       } for
401
       CJKV_DEBUG_BASE { (rewriting finished\n) print flush } if
402
       cmapf2_glyph_array
403
       CJKV_DEBUG_BASE {
404
         16#0000 16#0010 16#fff0 {
405
            16#0000 16#0001 16#000f {
406
               1 index add dup 16#ffff lt {
407
                 2 index exch get =only
408
                 ( ) =only
409
               } { pop } ifelse
410
            } for
411
            pop
412
            (\n) print flush
413
         } for
414
       } if
415
    } bind
416
    4 {		% Microsoft/Adobe segmented mapping.
417
      /etab exch _cjkv_ttcmap_tmp 3 1 roll put
418
      /nseg2 _cjkv_ttcmap_tmp /etab get 6 .cjkv_biggetu16 def
419
      14 /endc _cjkv_ttcmap_tmp /etab get 2 index nseg2 .cjkv_biggetinterval _cjkv_ttcmap_tmp 3 1 roll put
420
  		% The Apple TrueType documentation omits the 2-byte
421
  		% 'reserved pad' that follows the endCount vector!
422
      2 add
423
      nseg2 add /startc _cjkv_ttcmap_tmp /etab get 2 index nseg2 .cjkv_biggetinterval _cjkv_ttcmap_tmp 3 1 roll put
424
      nseg2 add /iddelta _cjkv_ttcmap_tmp /etab get 2 index nseg2 .cjkv_biggetinterval _cjkv_ttcmap_tmp 3 1 roll put
425
      nseg2 add /idroff _cjkv_ttcmap_tmp /etab get 2 index nseg2 .cjkv_biggetinterval  _cjkv_ttcmap_tmp 3 1 roll put
426
  		% The following hack allows us to properly handle
427
  		% idiosyncratic fonts that start at 0xf000:
428
      pop
429
      /firstcode _cjkv_ttcmap_tmp /startc get 0 .cjkv_getu16 16#ff00 and dup 16#f000 ne { pop 0 } if def
430
      _cjkv_ttcmap_tmp /putglyph {
431
        glyphs code 3 -1 roll put /code code 1 add def
432
      } bind put
433
  		% Do a first pass to compute the size of the glyphs array.
434
      /numcodes 0 def /glyphs 0 0 2 nseg2 3 sub {
435
  		% Stack: /glyphs numglyphs i2
436
        /i2 exch def
437
        /scode _cjkv_ttcmap_tmp /startc get i2 .cjkv_biggetu16 def
438
        /ecode _cjkv_ttcmap_tmp /endc get i2 .cjkv_biggetu16 def
439
        numcodes scode firstcode sub
440
  		% Hack for fonts that have only 0x0000 and 0xf000 ranges
441
        %dup 16#e000 ge { 255 and } if
442
        % the previous line is obstructive to CJK fonts, so it was removed
443
        exch sub 0 .max ecode scode sub 1 add add
444
        exch 1 index add exch
445
        numcodes add /numcodes exch def
446
      } for array def
447
  		% Now fill in the array.
448
      /numcodes 0 def /code 0 def
449
      0 2 nseg2 3 sub {
450
        /i2 exch def
451
        /scode _cjkv_ttcmap_tmp /startc get i2 .cjkv_getu16 def
452
        /ecode _cjkv_ttcmap_tmp /endc get i2 .cjkv_getu16 def
453
        numcodes scode firstcode sub
454
  		% Hack for fonts that have only 0x0000 and 0xf000 ranges
455
        %dup 16#e000 ge { 255 and } if
456
        % the previous line is obstructive to CJK fonts, so it was removed
457
        exch sub 0 .max dup { 0 _cjkv_ttcmap_tmp /putglyph get exec } repeat
458
        ecode scode sub 1 add add numcodes add /numcodes exch def
459
        /delta _cjkv_ttcmap_tmp /iddelta get i2 .cjkv_gets16 def
460
        CJKV_DEBUG_BASE {
461
  	(scode=) print scode =only
462
  	( ecode=) print ecode =only
463
  	( delta=) print delta =only
464
  	( droff=) print _cjkv_ttcmap_tmp /idroff get i2 .cjkv_biggetu16 =
465
        } if
466
        _cjkv_ttcmap_tmp /idroff get i2 .cjkv_biggetu16 dup 0 eq {
467
  	pop scode delta add 65535 and 1 ecode delta add 65535 and
468
  	{ _cjkv_ttcmap_tmp /putglyph get exec } for
469
        } {	% The +2 is for the 'reserved pad'.
470
          /gloff exch 14 nseg2 3 mul add 2 add i2 add add def
471
          0 1 ecode scode sub {
472
  	  2 mul gloff add _cjkv_ttcmap_tmp /etab get exch .cjkv_biggetu16
473
  	  dup 0 ne { delta add 65535 and } if _cjkv_ttcmap_tmp /putglyph get exec
474
  	} for
475
        } ifelse
476
      } for glyphs /glyphs null def	% for GC
477
    } bind
478
    6 {		% Single interval lookup.
479
      dup 6 .cjkv_getu16 /firstcode exch def dup 8 .cjkv_getu16 /ng exch def
480
      firstcode ng add array
481
  		% Stack: tab array
482
  		% Fill elements 0 .. firstcode-1 with 0
483
      0 1 firstcode 1 sub { 2 copy 0 put pop } for
484
      dup firstcode ng getinterval
485
  		% Stack: tab array subarray
486
  		% Fill elements firstcode .. firstcode+nvalue-1 with glyph values
487
      0 1 ng 1 sub {
488
        dup 2 mul 10 add 4 index exch .cjkv_getu16 3 copy put pop pop
489
      } for pop exch pop
490
    } bind
491
  .dicttomark readonly def                % _cjkv_cmapformats
492
  
493
  % <cmaptab> _cjkv_cmaparray <glypharray>
494
  /_cjkv_cmaparray {
495
    dup 0 .cjkv_biggetu16
496
  
497
    _cjkv_cmapformats exch .knownget {
498
      CJKV_DEBUG_BASE {
499
        (cmap: format ) print 1 index 0 .cjkv_biggetu16 = flush
500
      } if exec
501
    } {
502
      (Can't handle format ) print 0 .cjkv_biggetu16 = flush
503
      0 1 255 { } for 256 packedarray
504
    } ifelse
505
    CJKV_DEBUG_BASE {
506
      (cmap: length=) print dup length = dup ==
507
    } if
508
  } bind def
509
  
510
  % Each procedure in this dictionary is called as follows:
511
  %	<file> <length> -proc- <string|array_of_strings>
512
  % Note that each table must have an even length, because of a strange
513
  % Adobe requirement that each sfnts entry have even length.
514
  /_cjkv_readtables mark
515
  	% Ordinary tables
516
    (head) { .cjkv_readtable }
517
    (hhea) { .cjkv_readtable }
518
    (maxp) { .cjkv_readtable }
519
    (name) { .cjkv_readtable }
520
    (OS/2) { .cjkv_readtable }
521
    (vhea) { .cjkv_readtable }
522
  	% Big tables
523
    (cmap) { .cjkv_readbigtable }
524
    (glyf) { .cjkv_readbigtable }
525
    (loca) { .cjkv_readbigtable }
526
    (hmtx) { .cjkv_readbigtable }
527
    (vmtx) { .cjkv_readbigtable }
528
    (post) { .cjkv_readbigtable }
529
  	% Tables only needed for embedding in PDF files
530
    (cvt ) { .cjkv_readtable }
531
    (fpgm) { .cjkv_readtable }
532
    (prep) { .cjkv_readtable }
533
    (GSUB) { .cjkv_readtable }
534
  .dicttomark
535
  % Normally there would be a 'readonly' here, but the ttf2pf utility wants
536
  % to include the 'kern' table as well, so we leave the readtables dictionary
537
  % writable.
538
  def                % readtables
539
540
  % Read a table as a single string.
541
  % <file> <length> .readtable <string>
542
  /.cjkv_readtable {
543
    dup dup 1 and add string
544
                  % Stack: f len str
545
    dup 0 4 -1 roll getinterval
546
                  % Stack: f str str1
547
          % Because of the absurd PostScript specification that gives an
548
          % error for reading into an empty string, we have to check for
549
          % this explicitly here.
550
    3 -1 roll exch
551
    dup () ne { readstring } if pop pop
552
  } bind def
553
  
554
  % Read a big table (one that may exceed 64K).
555
  % <file> <length> .readbigtable <string[s]>
556
  /.cjkv_readbigtable {
557
    dup 65400 lt {
558
      .cjkv_readtable
559
    } {
560
      currentuserparams /VMReclaim get -2 vmreclaim
561
      [ 4 2 roll {
562
                  % Stack: mark ... f left
563
        dup maxstring le { exit } if
564
        1 index maxstring string readstring pop 3 1 roll maxstring sub
565
      } loop .cjkv_readtable ]
566
      exch vmreclaim
567
    } ifelse
568
  } bind def
569
end readonly def % /_cjkv_base_util
(-)lib/cjkv/cjkcidcm.ps (+455 lines)
Line 0 Link Here
1
%!
2
%
3
% Developed by AXE,Inc., BBR Inc. and Turbolinux Inc.
4
%   under the technical advice by suzuki toshiya (Hiroshima University)
5
% For questions, please send mail to espgs8-cjk@printing-japan.org
6
%
7
% (C) Copyright 2006 Center of the International Cooperation for
8
%     Computerization
9
%
10
%
11
% Based on gs-cjk patches
12
% Copyright (C) 2001-2003 gs-cjk project:
13
%   Taiji Yamada, Masatake Yamato, Hideyuki Suzuki and suzuki toshiya.
14
%   All rights reserved.
15
%
16
%
17
% Based on GNU Ghostscript 7.07 and 8.15
18
% Copyright (C) 1996-2003 artofcode LLC.  All rights reserved.
19
%
20
% This software is provided AS-IS with no warranty, either express or
21
% implied.
22
%
23
%
24
% This program is free software;  you can redistribute it and/or
25
% modify it under the terms of the GNU General Public License as
26
% published by the Free Software Foundation; either version 2 of
27
% the License, or (at your option) any later version.
28
%
29
% This program is distributed in the hope that it will be useful,
30
% but WITHOUT ANY WARRANTY; without even the implied warranty of
31
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
32
% See the GNU General Public License for more details.
33
%
34
% You should have received a copy of the GNU General Public License
35
% along with this program; if not, write to the Free Software Foundation,
36
% Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37
%
38
39
true setglobal
40
41
[
42
   /CJKV_DEBUG_CIDCM
43
   /NOCIDFONTMAP
44
] {dup where {pop pop} { currentdict exch false def pop } ifelse} forall
45
46
% -------------------------------------------------------------------------------
47
% taken from gs7.05/lib/gs_cidcm.ps
48
49
25 dict begin
50
51
  /.prs_dict currentdict def
52
  /.prs_empty 0 dict readonly def
53
  /enable_cache true def
54
  /path_buffer 8192 string def
55
  /name_buffer 1024 string def
56
  /minus (-) 0 get def             % character code constant for '-'
57
  /period (.) 0 get def            % character code constant for '.'
58
  /CMap 10 dict def                % CSI cache for CMaps
59
  /CIDFont 10 dict def             % CSI cache for CIDFonts
60
  /enable_cache true def           % set false to disable cache
61
  /.prsFile 0 def                   % file to prescan
62
  /.prsResult 0 def                 % result of prescan
63
  /.prsDictCount 0 def              % save the dictionary stack depth
64
65
66
  /.cjkv_StopIfCSIDefined {   % - StopIfCSIDefined -
67
    CJKV_DEBUG_CIDCM { (.cjkv_StopIfCSIDefined\n) print flush } if
68
  
69
    % Check if the dictionary stack contains a dictionary containing /CIDSystemInfo.
70
    % The search is limited to the top .prsDictCount dictionaries in the stack.
71
    % If so, retrieve the CSI, and execute stop to terminate the pre-scanning of the file.
72
    % Otherwise, do nothing, so the pre-scanning continues.
73
  
74
    countdictstack //.prs_dict /.prsDictCount get sub dup {
75
      currentdict /CIDSystemInfo .knownget {
76
        //.prs_dict exch /.prsResult exch put
77
        stop
78
      } if
79
      currentdict exch end
80
    } repeat {
81
      begin
82
    } repeat
83
  } bind def
84
  
85
  /.cjkv_PrescanFile {     % - PrescanFile -
86
    CJKV_DEBUG_CIDCM { (.cjkv_PrescanFile\n) print flush } if
87
    { //.prs_dict /.prsFile get token {
88
        dup type                          % token type
89
        dup /nametype eq exch /operatortype eq or {
90
          dup xcheck {
91
            exec
92
            //.cjkv_StopIfCSIDefined exec
93
          } if
94
        } if
95
      } {
96
        stop
97
      } ifelse
98
    } loop
99
  } bind odef
100
  
101
  /.cjkv_GetCIDSystemInfoFromFile { % <file> GetCIDSystemInfoFromFile <CSI>
102
    CJKV_DEBUG_CIDCM { (.cjkv_GetCIDSystemInfoFromFile\n) print flush } if
103
    //.prs_dict begin
104
    /.prsFile exch def
105
    /.prsResult //.prs_empty def
106
    /.prsDictCount countdictstack def
107
    { //.cjkv_PrescanFile } stopped pop
108
    //.prs_dict /.prsResult get
109
    end
110
  } bind def
111
112
113
  /.cjkv_GetCIDSystemInfo {     % <InstName> <CatName> GetCIDSystemInfo <CSI>
114
    CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo: ) print 1 index =only ( in ) print dup == flush } if
115
    2 copy resourcestatus {
116
      CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo: resource status OK\n) print } if
117
      pop 2 lt {
118
        CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo: resource status < 2\n) print } if
119
        findresource /CIDSystemInfo .knownget not { //.prs_empty } if
120
      } {
121
        CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo: resource status >= 2\n) print } if
122
        dup //.prs_dict exch get dup 3 index known //enable_cache and {
123
          CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo: resource cached\n) print } if
124
          exch pop exch get
125
        } {
126
          CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo: resource not-cached\n) print } if
127
          3 1 roll /Category findresource begin dup //path_buffer ResourceFileName
128
          end currentglobal exch true setglobal mark exch {
129
            CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo->.cjkv_GetCIDSystemInfoFromFile\n) print } if
130
            (r) file //.cjkv_GetCIDSystemInfoFromFile exec
131
          } stopped
132
          {
133
            cleartomark 1 index dup
134
            CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo->.CIDFontmapKnownget START\n) print } if
135
            /CIDFont /Category findresource /.cjkv_CIDFontmapKnownget get exec
136
            CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo->.CIDFontmapKnownget EXECED\n) print } if
137
            {
138
              CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo [knownget OK]\n) print } if
139
              true setglobal 1 index 3 1 roll
140
              CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo->.cjkv_CIDFontmapRunHandler\n) print } if
141
              /CIDFont /Category findresource /.cjkv_CIDFontmapRunHandler get exec
142
              CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo<-.cjkv_CIDFontmapRunHandler\n) print } if
143
              /CIDFont findresource /CIDSystemInfo get
144
            } {
145
              CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo [knownget FAILED]\n) print } if
146
              pop //.prs_empty
147
            } ifelse
148
          } {
149
            CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo [not stopped]\n) print } if
150
            exch pop
151
          } ifelse
152
          exch setglobal dup 4 1 roll put
153
        } ifelse
154
      } ifelse
155
    } {
156
      CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo: resource status FAILED\n) print } if
157
      pop pop //.prs_empty
158
    } ifelse
159
    CJKV_DEBUG_CIDCM { (*** .cjkv_GetCIDSystemInfo finished\n) print flush } if
160
  } bind def
161
162
  /GetCIDSystemInfo {
163
    .cjkv_GetCIDSystemInfo
164
  } bind def
165
166
  % -------------------------------------------------------------------------------
167
  /orig_font_resourcestatus /Generic /Category findresource /ResourceStatus get bind def
168
  /orig_font_resourceforall /Generic /Category findresource /ResourceForAll get bind def
169
  /orig_font_findresource   /Font    /Category findresource /FindResource   get bind def
170
171
  /BindAux {   % <proc> BindAux <proc>
172
    0 exec
173
  } bind def
174
  
175
  /EnumerateFontNames {
176
    end
177
    {
178
      0 1 2 {
179
        en_local_dict exch /status exch put
180
        Fonts {
181
          en_local_dict /status get eq {
182
            scr cvs
183
            proc exec
184
          } {
185
            pop
186
          } ifelse
187
        } forall
188
      } for
189
    } stopped
190
    Category begin
191
    { stop } if
192
  } bind def
193
  
194
  /Bind {
195
    dup length array copy
196
    dup length 1 sub -1 0 {
197
      2 copy get
198
      dup dup type /arraytype eq exch xcheck and {
199
        //BindAux exec
200
        2 index 3 1 roll put
201
      } {
202
        dup dup type /nametype eq exch xcheck and {
203
          currentdict exch .knownget {
204
            2 index 3 1 roll put
205
          } {
206
            pop
207
          } ifelse
208
        } {
209
          pop pop
210
        } ifelse
211
      } ifelse
212
    } for
213
    cvx
214
  } bind def
215
  
216
  //BindAux 0 //Bind put
217
218
  CJKV_DEBUG_CIDCM { (*** Font Enumurator utility definition OK\n) print flush } if
219
220
  % ---------------------------------------------------------------------------------
221
222
  /.cjkv_ComposeName {
223
    CJKV_DEBUG_CIDCM { (*** .cjkv_ComposeName\n) print flush } if
224
    dup dup 5 2 roll 3 2 roll exch cvs length dup 4 -1 roll exch //minus put 1 add dup
225
    3 index dup length 2 index sub 3 2 roll exch getinterval 3 2 roll exch cvs length
226
    add 0 exch getinterval
227
  } bind def
228
229
  /.cjkv_IsCompatibleCSI {
230
    CJKV_DEBUG_CIDCM { (*** .cjkv_IsCompatibleCSI\n) print flush } if
231
    exch
232
    { dup type /arraytype eq {
233
        dup length 1 ne { pop pop false exit } if
234
        0 get
235
      } if
236
      dup type /dicttype ne { pop pop false exit } if
237
      exch
238
      dup type /dicttype ne { pop pop false exit } if
239
      true
240
      [/Registry /Ordering] {
241
        2 index 1 index .knownget not { 1234567 } if
242
        exch
243
        4 index exch .knownget not { 7654321 } if
244
        eq and
245
      } forall
246
      exch pop exch pop
247
      exit
248
    } loop
249
  } bind def
250
251
  /.cjkv_IsComposedOK {
252
    CJKV_DEBUG_CIDCM { (*** .cjkv_IsComposedOK ENTER with: ) print 1 index =only ( ) print dup == flush } if
253
    exch
254
    /CIDFont
255
    CJKV_DEBUG_CIDCM { (*** .cjkv_IsComposedOK->.cjkv_GetCIDSystemInfo for CIDFont:) print 1 index == flush } if
256
    .cjkv_GetCIDSystemInfo
257
    CJKV_DEBUG_CIDCM { (*** .cjkv_IsComposedOK<-.cjkv_GetCIDSystemInfo\n) print flush } if
258
    dup type /dicttype eq {
259
      dup length 0 ne {
260
        exch /CMap
261
        CJKV_DEBUG_CIDCM { (*** .cjkv_IsComposedOK->.cjkv_GetCIDSystemInfo for CMap:) print 1 index == flush } if
262
        .cjkv_GetCIDSystemInfo
263
        CJKV_DEBUG_CIDCM { (*** .cjkv_IsComposedOK<-.cjkv_GetCIDSystemInfo\n) print flush } if
264
        CJKV_DEBUG_CIDCM { (*** .cjkv_IsComposedOK->.cjkv_IsCompatibleCSI\n) print flush } if
265
        .cjkv_IsCompatibleCSI
266
        CJKV_DEBUG_CIDCM { (*** .cjkv_IsComposedOK<-.cjkv_IsCompatibleCSI\n) print flush } if
267
      } {
268
        pop pop false
269
      } ifelse
270
    } {
271
      pop pop false
272
    } ifelse
273
    CJKV_DEBUG_CIDCM { (*** .cjkv_IsComposedOK EXIT with ) print dup == flush } if
274
  } bind def
275
  
276
  /.cjkv_IsComposedFont {
277
    CJKV_DEBUG_CIDCM { (*** .cjkv_IsComposedFont START: ) print 3 index =only ( ) print 2 index =only ( ) print 1 index =only ( ) print dup ==  flush } if
278
    dup type /stringtype ne {
279
      //name_buffer cvs
280
    } if
281
    {
282
      dup length 2 sub -1 1 {
283
        2 copy get dup //minus eq exch //period eq or {
284
          2 copy 2 copy
285
          2 copy get //minus eq {
286
            2 copy 1 sub get //minus eq {
287
              1 sub
288
            } if
289
          } if
290
          0 exch getinterval cvn 3 1 roll 1 add dup 5 index length exch sub getinterval cvn
291
          2 copy
292
          CJKV_DEBUG_CIDCM { (*** .cjkv_IsComposedFont->.cjkv_IsComposedOK\n) print flush } if
293
          .cjkv_IsComposedOK {
294
            4 2 roll pop pop stop
295
          } if
296
          pop pop pop
297
        } {
298
          pop
299
        } ifelse
300
      } for
301
      pop
302
    } stopped
303
    CJKV_DEBUG_CIDCM { (*** .cjkv_IsComposedFont END:\n) print pstack (--bottom--\n) print flush } if
304
  } bind def
305
306
  CJKV_DEBUG_CIDCM { (*** CIDFont-CMap font utility definition OK\n) print flush } if
307
308
  % -------------------------------------------------------------------------------
309
310
  /.cjkv_ResourceStatus {  % <InstName> ResourceStatus <nStatus> <nSize> true
311
    	                   % <InstName> ResourceStatus false
312
    CJKV_DEBUG_CIDCM { (*** .cjkv_ResourceStatus start\n) print pstack (  ---bottom--\n) print flush } if
313
    dup
314
    CJKV_DEBUG_CIDCM { (*** .cjkv_ResourceStatus->orig_font_resourcestatus [for precomposed CIDFont-CMap resource]\n) print flush } if
315
    orig_font_resourcestatus {
316
      CJKV_DEBUG_CIDCM { (*** .cjkv_ResourceStatus->orig_font_resourcestatus OK, exit\n) print flush } if
317
      3 2 roll pop true
318
    } {
319
      CJKV_DEBUG_CIDCM { (*** .cjkv_ResourceStatus->orig_font_resourcestatus FAILED, check uncomposed composite font\n) print flush } if
320
      CJKV_DEBUG_CIDCM { (*** .cjkv_ResourceStatus->.cjkv_IsComposedFont\n) print flush } if
321
      .cjkv_IsComposedFont {
322
        CJKV_DEBUG_CIDCM { (*** looks composite font, check CMap\n) print flush } if
323
        /CMap CJKV_DEBUG_CIDCM { (---top---\n) print pstack (---bottom---\n) print flush } if resourcestatus {
324
          CJKV_DEBUG_CIDCM { (*** CMap OK, check CIDFont\n) print flush } if
325
          exch pop exch /CIDFont resourcestatus {
326
            CJKV_DEBUG_CIDCM { (*** exist, finally check status/size\n) print flush } if
327
            exch pop dup 0 ge {
328
              CJKV_DEBUG_CIDCM { (*** check status/size OK\n) print flush } if
329
              exch dup 0 ge {
330
                add
331
              } {
332
                exch pop
333
              } ifelse
334
            } {
335
              CJKV_DEBUG_CIDCM { (*** check status/size FAILED\n) print flush } if
336
              pop
337
            } ifelse
338
            2 exch true
339
          } {
340
            CJKV_DEBUG_CIDCM { (*** inexist CIDFont\n) print flush } if
341
            pop pop pop false
342
          } ifelse
343
        } {
344
          CJKV_DEBUG_CIDCM { (*** inexist CMap\n) print flush } if
345
          pop pop pop false
346
        } ifelse
347
      } {
348
        CJKV_DEBUG_CIDCM { (*** not composite font\n) print flush } if
349
        false
350
      } ifelse
351
    } ifelse
352
    CJKV_DEBUG_CIDCM { (*** .cjkv_ResourceStatus finished\n) print pstack (  ---bottom--\n) print flush } if
353
  } bind def
354
355
  /ResourceStatus {
356
    CJKV_DEBUG_CIDCM { (*** STUB: ResourceStatus\n) print flush } if
357
    .cjkv_ResourceStatus
358
  } bind def
359
360
  % -------------------------------------------------------------------------------
361
  
362
  /.cjkv_ResourceForAll { % <template> <proc> <scratch> ResourceForAll -
363
    CJKV_DEBUG_CIDCM { (*** .cjkv_ResourceForAll\n) print flush } if
364
    currentglobal false setglobal
365
    20 dict 20 dict 20 dict
366
    4 -1 roll setglobal
367
    5 index [ 2 index {exch cvn dup put} aload pop ] cvx 5 index orig_font_resourceforall
368
    (*)     [ 3 index {exch cvn dup put} aload pop ] cvx 5 index /CMap resourceforall
369
    (*)     [ 4 index {exch cvn dup put} aload pop ] cvx 5 index /CIDFont resourceforall
370
    dup {
371
      //.cjkv_ResourceStatus exec {
372
        pop 2 index 3 1 roll put
373
      } {
374
        pop
375
      } ifelse
376
    } forall
377
  
378
    3 2 roll  {
379
      3 index {
380
        3 1 roll 6 index .cjkv_ComposeName dup 8 index .stringmatch {
381
          cvn dup 4 index exch known {
382
            pop pop
383
          } {
384
            2 index 4 2 roll .cjkv_IsComposedOK {
385
              exch 2 index exch 2 put
386
            } {
387
              exch pop
388
            } ifelse
389
          } ifelse
390
        } {
391
          pop pop
392
        } ifelse
393
        dup
394
      } forall
395
      pop pop
396
    } forall
397
    exch pop
398
  
399
    currentdict
400
    6 dict begin % the temporary dictionary
401
      /Category exch def
402
      /Fonts exch def
403
      /scr exch def
404
      /proc exch def
405
      /en_local_dict currentdict def
406
      //EnumerateFontNames //Bind exec
407
      /status 0 def
408
    end
409
    exch pop
410
  
411
    exec
412
    CJKV_DEBUG_CIDCM { (*** .cjkv_ResourceForAll finished\n) print flush } if
413
  } bind def
414
415
  /ResourceForAll {
416
    CJKV_DEBUG_CIDCM { (*** STUB: ResourceStatus\n) print flush } if
417
    .cjkv_ResourceForAll
418
  } bind def
419
420
  CJKV_DEBUG_CIDCM { (*** ResourceForAll definition OK\n) print flush } if
421
422
  % -------------------------------------------------------------------------------
423
424
  /.cjkv_FindResource {
425
    CJKV_DEBUG_CIDCM { (*** .cjkv_FindResource\n) print flush } if
426
    dup //.cjkv_ResourceStatus exec {
427
      pop pop
428
      CJKV_DEBUG_CIDCM { (*** .cjkv_FindResource->orig_font_findresource #1\n) print flush } if
429
      orig_font_findresource
430
    } {
431
      dup
432
        CJKV_DEBUG_CIDCM { (*** .cjkv_FindResource->.cjkv_IsComposedFont\n) print flush } if
433
        //.cjkv_IsComposedFont exec {
434
        exch [ exch ] composefont
435
      } {
436
        CJKV_DEBUG_CIDCM { (*** .cjkv_FindResource->orig_font_findresource #2\n) print flush } if
437
        orig_font_findresource
438
      } ifelse
439
    } ifelse
440
    CJKV_DEBUG_CIDCM { (*** .cjkv_FindResource finished\n) print flush } if
441
  } bind def
442
 
443
  /FindResource {
444
    CJKV_DEBUG_CIDCM { (*** STUB: FindResource\n) print flush } if
445
    .cjkv_FindResource
446
  } bind def
447
448
  % -------------------------------------------------------------------------------
449
450
currentdict end
451
% /Generic /Category findresource dup length 25 add dict .copydict copy
452
/Font /Category findresource dup length 25 add dict .copydict copy
453
/Font exch /Category
454
defineresource pop
455
false setglobal
(-)lib/cjkv/cjkfnmap.ps (+389 lines)
Line 0 Link Here
1
%!
2
%
3
% Developed by AXE,Inc., BBR Inc. and Turbolinux Inc.
4
%   under the technical advice by suzuki toshiya (Hiroshima University)
5
% For questions, please send mail to espgs8-cjk@printing-japan.org
6
%
7
% (C) Copyright 2006 Center of the International Cooperation for
8
%     Computerization
9
%
10
%
11
% Based on gs-cjk patches
12
% Copyright (C) 2001-2003 gs-cjk project:
13
%   Masatake Yamato, suzuki toshiya, Hideyuki Suzuki and Taiji Yamada.
14
%   All rights reserved.
15
%
16
%
17
% Based on GNU Ghostscript 7.07 and 8.15
18
% Copyright (C) 1996-2003 artofcode LLC.  All rights reserved.
19
%
20
% This software is provided AS-IS with no warranty, either express or
21
% implied.
22
%
23
%
24
% This program is free software;  you can redistribute it and/or
25
% modify it under the terms of the GNU General Public License as
26
% published by the Free Software Foundation; either version 2 of
27
% the License, or (at your option) any later version.
28
%
29
% This program is distributed in the hope that it will be useful,
30
% but WITHOUT ANY WARRANTY; without even the implied warranty of
31
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
32
% See the GNU General Public License for more details.
33
%
34
% You should have received a copy of the GNU General Public License
35
% along with this program; if not, write to the Free Software Foundation,
36
% Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37
%
38
39
40
true setglobal
41
42
[
43
   /CJKV_DEBUG_FNMAP
44
   /NOCIDFONTMAP
45
] {dup where {pop pop} { currentdict exch false def pop } ifelse} forall
46
47
48
50 dict begin
49
50
/.cjkv_filenamedirseparator (/) def
51
/_cjkv_defaultcidfontmap (CIDFnmap) def
52
53
% -------------------------------------------------------------------------------
54
% taken from gs7.05/lib/gs_cidfn.ps
55
56
% Define the name of the CID font map file.
57
userdict /_cjkv_CIDFontmap 10 dict put
58
59
% <dict> <file> .readCIDFontmap <dict>
60
% Code from gs_fonts.ps::.readFontmap
61
  /.cjkv_readCIDFontmap {
62
    CJKV_DEBUG_FNMAP { (.cjkv_readCIDFontmap\n) print flush } if
63
    { dup token not { closefile exit } if
64
      dup (\032) eq { pop closefile exit } if
65
      1 index token not
66
       { (CIDFontmap entry for ) print dup =only
67
         ( has no associated file or alias name!  Giving up.) = flush
68
         {.cjkv_readCIDFontmap} 0 get 1 .quit
69
       } if
70
      dup type dup /stringtype eq exch /nametype eq or not
71
       { (CIDFontmap entry for ) print 1 index =only
72
         ( has an invalid file or alias name!  Giving up.) = flush
73
         {.cjkv_readCIDFontmap} 0 get 1 .quit
74
       } if
75
                % stack: dict file cidfontname filename|aliasname
76
      1 index type /stringtype eq
77
      1 index type /nametype eq and 1 index xcheck and
78
      1 index /run eq 2 index /.runlibfile eq or and {
79
                % This is an inclusion entry.
80
        pop findlibfile { exch pop } { file } ifelse
81
        2 index exch .cjkv_readCIDFontmap pop
82
      } {
83
        exch dup type /stringtype eq {cvn} if exch
84
       { 2 index token not
85
          { (CIDFontmap entry for ) print 1 index =only
86
            ( ends prematurely!  Giving up.) = flush
87
            {.cjkv_readCIDFontmap} 0 get 1 .quit
88
          } if
89
         dup /; eq { pop 3 index 3 1 roll .growput exit } if
90
         1 index type /nametype eq {
91
           (CIDFontmap entry for ) print 2 index =only
92
           (defines an alias! Giving up.) = flush
93
           {.cjkv_readCIDFontmap} 0 get 1 .quit
94
         } if
95
         exch [ exch 3 -1 roll
96
         dup type /integertype eq {
97
           4 index token not
98
           { (CIDFontmap entry for ) print 3 index =only
99
             ( ends prematurely!  Giving up.) = flush
100
             {.cjkv_readCIDFontmap} 0 get 1 .quit
101
           } if
102
         } if
103
         dup /; eq not 1 index type /nametype eq and {
104
           counttomark 2 eq {4} {5} ifelse index token not
105
           { (CIDFontmap entry for ) print
106
             counttomark 2 eq {3} {4} ifelse index =only
107
             ( ends prematurely!  Giving up.) = flush
108
             {.cjkv_readCIDFontmap} 0 get 1 .quit
109
           } if
110
         } if
111
         dup /; eq {
112
             pop ]
113
             3 index 3 1 roll .growput exit
114
         } if
115
         pop
116
       } loop
117
      } ifelse
118
    } loop
119
  } bind def
120
121
% <file> .cjkv_loadCIDFontmap -
122
  /.cjkv_loadCIDFontmap {
123
    CJKV_DEBUG_FNMAP { (.cjkv_loadCIDFontmap\n) print flush } if
124
    userdict /_cjkv_CIDFontmap get exch
125
    .cjkv_readCIDFontmap pop
126
  } bind def
127
128
% Code from .loadinitialfonts
129
  /.cjkv_loadinitialcidfonts {
130
    CJKV_DEBUG_FNMAP { (.cjkv_loadinitialcidfonts\n) print flush } if
131
    NOCIDFONTMAP not {
132
      /CIDFONTMAP where {
133
        pop [ CIDFONTMAP .pathlist ] {
134
          dup VMDEBUG findlibfile {
135
            exch pop .cjkv_loadCIDFontmap
136
          } {
137
            /undefinedfilename signalerror
138
          } ifelse
139
        } forall
140
      } {
141
        LIBPATH {
142
          _cjkv_defaultcidfontmap 2 copy .cjkv_filenamedirseparator
143
          exch concatstrings concatstrings
144
          3 1 roll pop pop dup
145
          CJKV_DEBUG_FNMAP { (lookup CIDFnmap: ) print flush dup =only } if
146
          VMDEBUG (r) { file } .internalstopped {
147
            CJKV_DEBUG_FNMAP { ( ... not found\n) print flush } if
148
            pop pop
149
          } {
150
            CJKV_DEBUG_FNMAP { ( ... found\n) print flush } if
151
            .cjkv_loadCIDFontmap
152
          } ifelse
153
        } forall
154
      } ifelse
155
    } if
156
 } bind def
157
158
 .cjkv_loadinitialcidfonts
159
160
  /_cjkv_CIDFontmapHandler <<
161
    /nametype {
162
      CJKV_DEBUG_FNMAP { (*** exec _cjkv_CIDFontmapHandler for nametype: ) print dup == flush } if
163
      /CIDFont findresource
164
      /CIDFont defineresource pop
165
    } bind
166
    /stringtype {
167
      CJKV_DEBUG_FNMAP { (*** exec _cjkv_CIDFontmapHandler for stringtype: \() print dup =only (\)\n) print flush } if
168
      findlibfile {
169
        CJKV_DEBUG_FNMAP { (*** exec _cjkv_CIDFontmapHandler found file\n) print } if
170
        exch pop
171
        % Define CIDFont with a name defined in the font file
172
        CJKV_DEBUG_FNMAP { (***      _cjkv_CIDFontmapHandler->.cjkv_loadcidfontwithoutpop\n) print } if
173
174
175
          CJKV_DEBUG_FNMAP { (.cjkv_loadcidfontwithoutpop start\n) print flush } if
176
          dup 4 string .peekstring pop dup (ttcf) eq exch (\000\001\000\000) eq or {
177
            .loadcjkvttcidfont
178
          } {
179
            /CIDFont /Category findresource /.Instances get
180
            dup length 2 div cvi dict .copydict exch
181
            .loadfont
182
            /CIDFont /Category findresource /.Instances get {
183
              2 index 2 index known {
184
                pop pop
185
              } {
186
                pop exch pop /CIDFont findresource exit
187
              } ifelse
188
            } forall
189
            dup /CIDFontName known not {
190
              {Internal Error in .cjkv_loadcidfontwithoutpop} stop
191
            } if
192
          } ifelse
193
          CJKV_DEBUG_FNMAP { (.cjkv_loadcidfontwithoutpop finished\n) print flush } if
194
195
196
        CJKV_DEBUG_FNMAP { (***      _cjkv_CIDFontmapHandler<-.cjkv_loadcidfontwithoutpop\n) print } if
197
        % Define CIDFont with a name define in CIDFontmap
198
        dup length 0 ne {
199
            dup /CIDFontName get 2 index eq {
200
                CJKV_DEBUG_FNMAP { (*** define CIDFont resource with self name\n) print } if
201
                % Avoid duplicated defineresource for the same CIDFont
202
                pop pop
203
            } {
204
                CJKV_DEBUG_FNMAP { (*** rename CIDFont resource\n) print flush } if
205
                % Give a name different from the name defined in the file
206
                /CIDFont
207
                CJKV_DEBUG_FNMAP { (*** exec defineresource: ) print 2 index == ( ) print 1 index == ( ) print 0 index == (\n) print flush } if
208
                defineresource pop
209
                CJKV_DEBUG_FNMAP { (*** exec defineresource ok\n) print flush } if
210
            } ifelse
211
        } {
212
            CJKV_DEBUG_FNMAP { (*** 0-sized CIDFont dict\n) print } if
213
            pop pop
214
        } ifelse
215
      } {
216
        CJKV_DEBUG_FNMAP { (*** exec _cjkv_CIDFontmapHandler cannot find file\n) print } if
217
        /undefinedresource signalerror
218
      } ifelse
219
      CJKV_DEBUG_FNMAP { (*** _cjkv_CIDFontmapHandler END\n) print } if
220
    } bind
221
    /arraytype {
222
    % Replace filename in the array with file
223
        dup 0 get
224
        findlibfile {
225
            3 1 roll pop
226
            copyarray dup 3 1 roll 0
227
            3 -1 roll put
228
            % Expand array
229
            aload pop .loadcjkvttcidfont
230
            /CIDFont defineresource pop
231
        } {
232
            /undefinedresource signalerror
233
        } ifelse
234
    } bind
235
  >> def
236
237
238
  /.cjkv_CIDFontmapKnown {
239
    CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapKnown: ) print flush dup == } if
240
    userdict /_cjkv_CIDFontmap get
241
    CJKV_DEBUG_FNMAP { dup { exch (    key: ) print == (        val: ) print == flush } forall } if
242
    exch known
243
  } bind def
244
245
  /.cjkv_CIDFontmapKnownget {
246
    CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapKnownget: ) print flush dup == } if
247
    userdict /_cjkv_CIDFontmap get exch .knownget
248
  } bind def
249
250
  /.cjkv_CIDFontmapKnowngetBase {
251
    CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapKnowngetBase: ) print flush dup == } if
252
    userdict /_cjkv_CIDFontmap get exch { % dict key
253
      1 index 1 index known {
254
        CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapKnowngetBase: temp: ) print 1 index == flush } if
255
        1 index exch get
256
      } {
257
        CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapKnowngetBase: base: ) print 1 index == flush } if
258
        exit
259
      } ifelse
260
    } loop
261
    exch pop
262
    CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapKnowngetBase: exit with ) print dup == flush } if
263
  } bind def
264
265
  /.cjkv_CIDFontmapRunHandler {
266
    CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapRunHandler START\n) print flush } if
267
    dup
268
    /CIDFont /Category findresource /_cjkv_CIDFontmapHandler get
269
    exch type get
270
    CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapRunHandler EXEC: _cjkv_CIDFontmapHandler:) print dup == flush } if
271
    .execasresource
272
    CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapRunHandler END\n) print flush } if
273
  } bind def
274
275
  /.cjkv_CIDFontmapForAll {
276
    CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapForAll\n) print flush } if
277
    _cjkv_CIDFontmap exch forall
278
  } bind def
279
280
  /.cjkv_CIDFontmapForAllKey {
281
    CJKV_DEBUG_FNMAP { (*** .cjkv_CIDFontmapForAllKey\n) print flush } if
282
    [ /pop cvx 3 -1 roll /exec cvx ] cvx ._cjkv_CIDFontmapForAll
283
  } bind def
284
currentdict
285
end
286
287
288
%
289
% CIDFont resource handler must be modified
290
%
291
languagelevel exch 2 .setlanguagelevel
292
293
/CIDFont /Category findresource dup length dict .copydict
294
copy
295
  /.originalresourceforall 1 index /ResourceForAll get def
296
297
  dup /ResourceForAll {
298
    currentglobal false setglobal
299
    [
300
      4 index {cvn} 4 index .originalresourceforall {
301
        dup length string cvs dup counttomark 4 add index
302
        .stringmatch {
303
          cvn counttomark -1 1 {
304
            index 1 index eq {
305
              pop exit % Duplicated
306
            } if
307
          } for
308
        } {
309
          pop
310
        } ifelse
311
      } .cjkv_CIDFontmapForAllKey
312
    ]
313
    exch setglobal
314
    4 -1 roll pop 3 1 roll [
315
      exch {cvs} aload pop 4 -1 roll aload pop
316
    ] cvx
317
    forall
318
  } put
319
320
  /.cjkv_loadcidfontresource {
321
    CJKV_DEBUG_FNMAP { (.cjkv_loadcidfontresource\n) print flush } if
322
    dup .ResourceFile {
323
      {
324
          CJKV_DEBUG_FNMAP { (.cjkv_loadcidfontwithoutpop start\n) print flush } if
325
          dup 4 string .peekstring pop dup (ttcf) eq exch (\000\001\000\000) eq or {
326
            .loadcjkvttcidfont
327
          } {
328
            /CIDFont /Category findresource /.Instances get
329
            dup length 2 div cvi dict .copydict exch
330
            .loadfont
331
            /CIDFont /Category findresource /.Instances get {
332
              2 index 2 index known {
333
                pop pop
334
              } {
335
                pop exch pop /CIDFont findresource exit
336
              } ifelse
337
            } forall
338
            dup /CIDFontName known not {
339
              {Internal Error in .cjkv_loadcidfontwithoutpop} stop
340
            } if
341
          } ifelse
342
          CJKV_DEBUG_FNMAP { (.cjkv_loadcidfontwithoutpop finished\n) print flush } if
343
          pop
344
345
      } .execasresource
346
    } {
347
      pop dup .cjkv_CIDFontmapKnownget {
348
        .cjkv_CIDFontmapRunHandler
349
      } {
350
        dup /undefinedresource signalerror
351
      } ifelse
352
    } ifelse
353
  } bind def
354
355
  dup /.LoadResource {
356
    CJKV_DEBUG_FNMAP { (.LoadResource\n) print flush } if
357
    currentglobal {
358
      .cjkv_loadcidfontresource
359
    } {
360
      true setglobal {.cjkv_loadcidfontresource} stopped false setglobal {stop} if
361
    } ifelse
362
  } bind put
363
364
  dup /.ResourceFileStatus {
365
    CJKV_DEBUG_FNMAP { (*** cjkv_modified .ResourceFileStatus for CIDFont\n) print flush } if
366
    dup .cjkv_CIDFontmapKnown {
367
      CJKV_DEBUG_FNMAP { (    ResourceFileStatus returns TRUE\n) print flush } if
368
      pop 2 -1 true
369
    } {
370
      .ResourceFile {
371
        CJKV_DEBUG_FNMAP { (    ResourceFileStatus returns TRUE\n) print flush } if
372
        closefile 2 -1 true
373
      } {
374
        CJKV_DEBUG_FNMAP { (    ResourceFileStatus returns FALSE\n) print flush } if
375
        pop false
376
      } ifelse
377
    } ifelse
378
  } bind put
379
380
  dup /.CIDFontmapKnown        { .cjkv_CIDFontmapKnown        } bind put
381
  dup /.CIDFontmapKnownget     { .cjkv_CIDFontmapKnownget     } bind put
382
  dup /.CIDFontmapKnowngetBase { .cjkv_CIDFontmapKnowngetBase } bind put
383
  dup /.CIDFontmapRunHandler   { .cjkv_CIDFontmapRunHandler   } bind put
384
  dup /.CIDFontmapForAll       { .cjkv_CIDFontmapForAll       } bind put
385
  dup /.CIDFontmapForAllKey    { .cjkv_CIDFontmapForAllKey    } bind put
386
387
/CIDFont exch /Category defineresource pop
388
389
.setlanguagelevel
(-)lib/cjkv/cjkvinit.ps (+46 lines)
Line 0 Link Here
1
%!
2
%
3
% Developed by AXE,Inc., BBR Inc. and Turbolinux Inc.
4
%   under the technical advice by suzuki toshiya (Hiroshima University)
5
% For questions, please send mail to espgs8-cjk@printing-japan.org
6
%
7
% (C) Copyright 2006 Center of the International Cooperation for
8
%     Computerization 
9
%
10
% This program is free software;  you can redistribute it and/or
11
% modify it under the terms of the GNU General Public License as
12
% published by the Free Software Foundation; either version 2 of
13
% the License, or (at your option) any later version.
14
%
15
% This program is distributed in the hope that it will be useful,
16
% but WITHOUT ANY WARRANTY; without even the implied warranty of
17
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
% See the GNU General Public License for more details.
19
%
20
% You should have received a copy of the GNU General Public License
21
% along with this program; if not, write to the Free Software Foundation,
22
% Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
%
24
25
/CJKV_DEBUG dup where {
26
  pop pop
27
  currentdict
28
  [
29
    /CJKV_DEBUG_BASE
30
    /CJKV_DEBUG_CIDCM
31
    /CJKV_DEBUG_FNMAP
32
    /CJKV_DEBUG_TTCF
33
    /CJKV_DEBUG_TT11
34
    /CJKV_DEBUG_TT42
35
    /CJKV_DEBUG_GSUB
36
%   /CJKV_DEBUG_OS2	% fragile
37
  ] { true def } forall
38
} if
39
pop
40
41
(cjkv/baseutil.ps) runlibfile
42
(cjkv/tt42util.ps) runlibfile
43
(cjkv/tt11util.ps) runlibfile
44
(cjkv/cjkvttcf.ps) runlibfile
45
(cjkv/cjkfnmap.ps) runlibfile
46
(cjkv/cjkcidcm.ps) runlibfile
(-)lib/cjkv/cjkvttcf.ps (+154 lines)
Line 0 Link Here
1
%!
2
%
3
% Developed by AXE,Inc., BBR Inc. and Turbolinux Inc.
4
%   under the technical advice by suzuki toshiya (Hiroshima University)
5
% For questions, please send mail to espgs8-cjk@printing-japan.org
6
%
7
% (C) Copyright 2006 Center of the International Cooperation for
8
%     Computerization
9
%
10
%
11
% Based on gs-cjk patches
12
% Copyright (C) 2001-2003 gs-cjk project:
13
%   Taiji Yamada, Hideyuki Suzuki, Masatake Yamato and suzuki toshiya.
14
%   All rights reserved.
15
%
16
%
17
% Based on GNU Ghostscript 7.07 and 8.15
18
% Copyright (C) 1996-2003 artofcode LLC.  All rights reserved.
19
%
20
% This software is provided AS-IS with no warranty, either express or
21
% implied.
22
%
23
%
24
% This program is free software;  you can redistribute it and/or
25
% modify it under the terms of the GNU General Public License as
26
% published by the Free Software Foundation; either version 2 of
27
% the License, or (at your option) any later version.
28
%
29
% This program is distributed in the hope that it will be useful,
30
% but WITHOUT ANY WARRANTY; without even the implied warranty of
31
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
32
% See the GNU General Public License for more details.
33
%
34
% You should have received a copy of the GNU General Public License
35
% along with this program; if not, write to the Free Software Foundation,
36
% Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37
%
38
39
40
[
41
   /CJKV_DEBUG_TTCF
42
] {dup where {pop pop} { currentdict exch false def pop } ifelse} forall
43
44
% /Charset /TTEncoding .cjkv_buildcmaptab cmap
45
/.cjkv_buildcmaptab {
46
  _cjkv_type11_util /.cjkv_buildcmapdict get 3 2 roll get begin
47
  cvx exec exch CIDCounts end exch get array
48
  dup length 1 sub 0 1 3 -1 roll { 1 index exch cmapglyphs 0 get put } for
49
  exch exec
50
} bind def
51
52
% -mark- <key> <value> ... .cjkv_definettcidfont <font>
53
%   rapid version of .definecjkvttcidfont
54
% Proposed by Hideyuki Suzuki <hideyuki@sat.t.u-tokyo.ac.jp>
55
% Modified by Taiji Yamada <taiji@aihara.co.jp>
56
/.cjkv_definettcidfont {
57
  CJKV_DEBUG_TTCF { (--- start cjkv_definettcidfontk\n) print flush } if
58
  true setglobal
59
  CJKV_DEBUG_TTCF { (--- making scratch dict...\n) print flush } if
60
  15 _cjkv_base_util /.cjkv_newdicttomark get exec
61
  CJKV_DEBUG_TTCF { (---                       ok\n) print flush } if
62
  dup /CIDFontName fontname dup length string copy put
63
  CJKV_DEBUG_TTCF { (--- CIDFontName put ok\n) print flush } if
64
  dup /CIDFontType 2 put
65
  CJKV_DEBUG_TTCF { (--- CIDFontType put ok\n) print flush } if
66
  dup /CIDSystemInfo
67
    mark
68
    _cjkv_type11_tmp /.cjkv_ttencmapproc get exec
69
    {
70
      _cjkv_type11_util /.cjkv_buildcmapdict get 3 2 roll get begin
71
      cvx exec pop
72
      /Supplement exch
73
      /Registry Registry
74
      /Ordering Ordering
75
      end
76
    } {
77
      /Registry (Adobe)
78
      /Ordering (Identity)	% pursuant to makeIdentityCMap in pdf_font.ps
79
      /Supplement 0
80
    } ifelse
81
    0 _cjkv_base_util /.cjkv_newdicttomark get exec put
82
  CJKV_DEBUG_TTCF { (--- CIDSystemInfo define ok\n) print flush } if
83
  dup /CharStrings mark /.notdef 0 .dicttomark put
84
  CJKV_DEBUG_TTCF { (--- CharStrings define ok\n) print flush } if
85
  _cjkv_type11_tmp /.cjkv_ttencmapproc get exec {
86
    /cmapglyphs _cjkv_ttcmap_tmp /cmaptab get _cjkv_cmaparray def
87
    exec .cjkv_buildcmaptab
88
    dup length /CIDCount exch
89
    3 -1 roll _cjkv_type11_util /.cjkv_makecidmap get exec	% it has not supported a dictionary yet
90
    /CIDMap exch		% it should be a string or an array of strings
91
    4 index 3 1 roll put
92
    2 index 3 1 roll put
93
  } {
94
    dup /CIDCount numloca put
95
    dup /CIDMap 0 put	% an integer interpreted as an offset from GI (see #5012 p.16)
96
  } ifelse
97
  dup /GDBytes 2 put
98
  CJKV_DEBUG_TTCF { (--- GDBytes define ok\n) print flush pstack } if
99
  dup /Encoding [ 256 { /.notdef } repeat ] put
100
  CJKV_DEBUG_TTCF { (--- Encoding define ok\n) print flush } if
101
  end end dup /CIDFontName get exch /CIDFont defineresource
102
  CJKV_DEBUG_TTCF { (--- defineresource ok\n) print flush pstack } if
103
} bind def
104
105
% Load a TrueType font from a file as a CIDFontType 2 font.
106
%   rapid version of .loadcjkvttcidfont
107
% Proposed by Hideyuki Suzuki <hideyuki@sat.t.u-tokyo.ac.jp>
108
% Modified by Taiji Yamada <taiji@aihara.co.jp>
109
%
110
% <file>             .cjkv_loadttcidfont <cidtype2font>
111
% <file> <fontindex> .cjkv_loadttcidfont <cidtype2font>
112
%   detect a kind of CID and encode a TrueType font to a CID-Keyed font.
113
%
114
% <file>             <ttcidcode> .cjkv_loadttcidfont <cidtype2font>
115
% <file> <fontindex> <ttcidcode> .cjkv_loadttcidfont <cidtype2font>
116
%   load a TrueType font and encode it with the kind of CID described
117
%   in <ttcidcode> which is one of entry in .cjkv_ttencmap.
118
/.loadcjkvttcidfont {
119
  CJKV_DEBUG_TTCF { (*** START: .loadcjkvttcidfont: dictstack=) print countdictstack == flush } if
120
  dup type /nametype ne { /Auto } if
121
  1 index type /integertype eq { 3 1 roll } { exch } ifelse
122
  CJKV_DEBUG_TTCF { (*** setup finished dictstack=) print countdictstack == flush } if
123
  _cjkv_type42_util /.cjkv_loadttfonttables get exec
124
  CJKV_DEBUG_TTCF { (*** loadttfonttables finished dictstack=) print countdictstack == flush } if
125
  _cjkv_type42_util /.cjkv_makesfnts get exec
126
  CJKV_DEBUG_TTCF { (*** makesfnts finished dictstack=) print countdictstack == flush } if
127
  _cjkv_type42_util /.cjkv_pickcmap get exec
128
  CJKV_DEBUG_TTCF { (*** pickcmap finished dictstack=) print countdictstack == flush } if
129
  _cjkv_type11_util /.cjkv_getgsub get exec
130
  CJKV_DEBUG_TTCF { (*** getgsub finished dictstack=) print countdictstack == flush } if
131
  _cjkv_type11_util /.cjkv_getos2 get exec
132
  CJKV_DEBUG_TTCF { (*** getos2 finished dictstack=) print countdictstack == flush } if
133
  _cjkv_type11_util /.cjkv_ttencmap get
134
  exch get _cjkv_type11_tmp exch /.cjkv_ttencmapproc exch put
135
  CJKV_DEBUG_TTCF { (*** ttencmap finished dictstack=) print countdictstack == flush } if
136
  mark
137
  _cjkv_type42_util /.cjkv_ttkeys get exec
138
  CJKV_DEBUG_TTCF { (*** ttkeys finished dictstack=) print countdictstack == flush } if
139
  .cjkv_definettcidfont
140
  CJKV_DEBUG_TTCF { (*** END: definettcidfont finished dictstack=) print countdictstack == flush } if
141
} bind def
142
143
% Open and load a TrueType font from a file as a CIDFontType 2 font.
144
% <filename>             .openttcidfont <cidtype2font>
145
% <filename> <fontindex> .openttcidfont <cidtype2font>
146
% <filename>             <ttcidcode> .openttcidfont <cidtype2font>
147
% <filename> <fontindex> <ttcidcode> .openttcidfont <cidtype2font>
148
/.openttcidfont {
149
  1 dup index type /nametype eq { 1 add } if
150
  dup index type /integertype eq { 1 add } if
151
  dup 1 add -1 roll (r) file exch 1 roll
152
  .loadcjkvttcidfont	% rapid version, since 20010316
153
  CJKV_DEBUG_TTCF { (*** .openttcidfont ok\n) print flush } if
154
} bind def
(-)lib/cjkv/tt11util.ps (+708 lines)
Line 0 Link Here
1
%!
2
%
3
% Developed by AXE,Inc., BBR Inc. and Turbolinux Inc.
4
%   under the technical advice by suzuki toshiya (Hiroshima University)
5
% For questions, please send mail to espgs8-cjk@printing-japan.org
6
%
7
% (C) Copyright 2006 Center of the International Cooperation for
8
%     Computerization
9
%
10
%
11
% Based on gs-cjk patches
12
% Copyright (C) 2001-2003 gs-cjk project:
13
%   Taiji Yamada, Hideyuki Suzuki, Masatake Yamato and suzuki toshiya.
14
%   Enhancements by Akira Tagoh and Taiji Yamada, 2005.
15
%   All rights reserved.
16
%
17
%
18
% Based on GNU Ghostscript 7.07 and 8.15
19
% Copyright (C) 1996-2003 artofcode LLC.  All rights reserved.
20
%
21
% This software is provided AS-IS with no warranty, either express or
22
% implied.
23
%
24
%
25
% This program is free software;  you can redistribute it and/or
26
% modify it under the terms of the GNU General Public License as
27
% published by the Free Software Foundation; either version 2 of
28
% the License, or (at your option) any later version.
29
%
30
% This program is distributed in the hope that it will be useful,
31
% but WITHOUT ANY WARRANTY; without even the implied warranty of
32
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
33
% See the GNU General Public License for more details.
34
%
35
% You should have received a copy of the GNU General Public License
36
% along with this program; if not, write to the Free Software Foundation,
37
% Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38
%
39
40
41
[
42
   /CJKV_DEBUG_TT11
43
   /CJKV_DEBUG_OS2
44
   /CJKV_DEBUG_GSUB
45
] {dup where {pop pop} { currentdict exch false def pop } ifelse} forall
46
47
% ---------------- CIDFontType 2 font loading ---------------- %
48
49
/_cjkv_type11_tmp 15 dict def
50
51
/_cjkv_type11_util 30 dict dup begin
52
  
53
  % Create a string with array of CIDs
54
  % [ <cid1> ... <cidN> ] .cjkv_makecidmapstring <string>
55
  /.cjkv_makecidmapstring {
56
    CJKV_DEBUG_TT11 { (.cjkv_makecidmapstring\n) print flush } if
57
    mark exch cvx exec counttomark                % mark 1..N len
58
    dup 2 mul string                              % mark 1..N len s
59
    dup 3 -1 roll 1 sub 2 mul -2 0 {              % mark 1..N s s
60
      2 copy 5 index -8 bitshift put              % mark 1..N s s j2
61
      1 add 4 -1 roll 16#ff and put dup           % mark 1..N-1 s s
62
    } for pop                                     % mark s
63
    exch pop                                      % s
64
  } bind def
65
  
66
  % Create a string or an array of strings with array of CIDs
67
  % [ <cid1> ... <cidN> ] .makecidmap <string>|[<string> ...]
68
  %   written by Taiji Yamada <taiji@aihara.co.jp>
69
  /.cjkv_makecidmap {
70
    CJKV_DEBUG_TT11 { (.cjkv_makecidmap\n) print flush } if
71
    dup length maxstring le {
72
      _cjkv_type11_util /.cjkv_makecidmapstring get exec
73
    } {
74
      dup length dup maxstring idiv exch
75
      maxstring mod 0 ne { 1 add } if array exch
76
      0 1 3 index length 1 sub {
77
        dup maxstring mul 1 index 1 add maxstring mul
78
        3 index length .min 1 index sub
79
        3 index 3 1 roll getinterval
80
        _cjkv_type11_util /.cjkv_makecidmapstring get exec
81
        3 index 3 1 roll put
82
      } for pop
83
    } ifelse
84
  } bind def
85
  
86
  % <file> .cjkv_loadttcidfont <cidtype2font>
87
  /.cjkv_loadttcidfont {
88
    CJKV_DEBUG_TT11 { (+++ .cjkv_loadttcidfont\n) print flush } if
89
    _cjkv_type42_util /.cjkv_loadttfonttables get exec
90
    .cjkv_makesfnts
91
          % CIDFontType2 fonts don't have a cmap: they are indexed by CID.
92
    /.cjkv_ttencmapproc false def
93
    mark
94
    CJKV_DEBUG_TT11 { (+++ mark ok\n) print flush } if
95
    .cjkv_ttkeys
96
    CJKV_DEBUG_TT11 { (+++ .cjkv_ttkeys finished\n) print flush } if
97
    .cjkv_definettcidfont
98
    CJKV_DEBUG_TT11 { (+++ .cjkv_definettcidfont finished\n) print flush } if
99
  } bind def
100
  
101
  % - .getgsub -
102
  % Defines gsubh, gsubv, gsubh2v and also defines gsubver, gsubfmt
103
  %   in the case that GSUB table has 'Single Substitution Format 2'
104
  %   which is formally used for vertically oriented glyphs such as CJK fonts.
105
  % Written by Hideyuki Suzuki <hideyuki@sat.t.u-tokyo.ac.jp>
106
  % Modified by Taiji Yamada <taiji@aihara.co.jp>
107
  %
108
  % [GSUB - The Glyph Substitution Table]
109
  % Index        Size        Type        Name of Entry
110
  % -----------------------------------
111
  % 0        4        Fixed        Version
112
  % 4        2        Offset        ScriptList
113
  % 6        2        Offset        FeatureList
114
  % 8        2        Offset        LookupList
115
  %
116
  % [Single Substitution Format 2, Subtable at LookupList]
117
  % Index        Size        Type        Name of Entry
118
  % -----------------------------------
119
  % 0        2        uint16        SubstFormat
120
  % 4        2        Offset        Coverage(--)
121
  % 6        2        uint16        GlyphCount
122
  % 8        2        GlyphID        Substitute(vertically oriented glyphs)
123
  % --        2        uint16        SubstFormat
124
  % +2        2        uint16        GlyphCount(same as above GlyphCount)
125
  % +4        2        GlyphID        GlyphArray(horizontally oriented glyphs)
126
  % -----------------------------------
127
  % References
128
  % 1. http://www.microsoft.com/typography/OTSPEC/gsub.htm
129
  %
130
  /.cjkv_getgsub {
131
    CJKV_DEBUG_TT11 { (***   getgsub start\n) print } if
132
    _cjkv_type11_tmp /gsubhog null put
133
    _cjkv_type11_tmp /gsubvog null put
134
    _cjkv_type11_tmp /gsubh2v null put
135
    tabdict /GSUB .knownget { % if
136
      CJKV_DEBUG_TT11 { (***      GSUB is known\n) print } if
137
      dup /gsubver exch 0 .cjkv_getu32 _cjkv_type11_tmp 3 1 roll put
138
      % dup /gsubosl exch 4 .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
139
      % dup /gsubofl exch 6 .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
140
      dup /gsuboll exch 8 .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
141
      CJKV_DEBUG_GSUB {
142
        (gsubver: ) print _cjkv_type11_tmp /gsubver get =
143
        % (gsubosl: ) print _cjkv_type11_tmp /gsubosl get =
144
        % (gsubofl: ) print _cjkv_type11_tmp /gsubofl get =
145
        (gsuboll: ) print _cjkv_type11_tmp /gsuboll get =
146
      } if
147
      % dup /gsubfmt exch _cjkv_type11_tmp /gsuboll get 0 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
148
      dup /gsublc exch _cjkv_type11_tmp /gsuboll get 0 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
149
      CJKV_DEBUG_GSUB {
150
        (gsublc: ) print _cjkv_type11_tmp /gsublc get =
151
        % (gsubfmt: ) print _cjkv_type11_tmp /gsubfmt get =
152
      } if
153
      _cjkv_type11_tmp /gsublc get 0 ne {
154
        0 1 _cjkv_type11_tmp /gsublc get 1 sub {
155
          2 mul /gsubolt exch 2 index exch _cjkv_type11_tmp /gsuboll get 2 add add .cjkv_getu16 _cjkv_type11_tmp /gsuboll get add _cjkv_type11_tmp 3 1 roll put
156
          dup /gsubltype exch _cjkv_type11_tmp /gsubolt get 0 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
157
          dup /gsublflag exch _cjkv_type11_tmp /gsubolt get 2 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
158
          dup /gsubsubc exch _cjkv_type11_tmp /gsubolt get 4 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
159
          CJKV_DEBUG_GSUB {
160
            (gsubolt: ) print _cjkv_type11_tmp /gsubolt get =
161
            (gsubltype: ) print _cjkv_type11_tmp /gsubltype get =
162
            (gsublflag: ) print _cjkv_type11_tmp /gsublflag get =
163
            (gsubsubc: ) print _cjkv_type11_tmp /gsubsubc get =
164
          } if
165
          _cjkv_type11_tmp /gsubsubc get 0 ne {
166
            0 1 _cjkv_type11_tmp /gsubsubc get 1 sub {
167
              2 mul /gsubost exch 2 index exch _cjkv_type11_tmp /gsubolt get 6 add add .cjkv_getu16 _cjkv_type11_tmp /gsubolt get add _cjkv_type11_tmp 3 1 roll put
168
              dup /substfmt exch _cjkv_type11_tmp /gsubost get 0 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
169
              CJKV_DEBUG_GSUB {
170
                (gsubost: ) print _cjkv_type11_tmp /gsubost get =
171
                (substfmt: ) print _cjkv_type11_tmp /substfmt get =
172
              } if
173
  %           _cjkv_type11_tmp /gsubver get 16#00010000 eq { % ifelse
174
              _cjkv_type11_tmp /gsubltype get 1 eq _cjkv_type11_tmp /substfmt get 2 eq and { % ifelse
175
                dup /gsubocv exch _cjkv_type11_tmp /gsubost get 2 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
176
                dup /gsubglc exch _cjkv_type11_tmp /gsubost get 4 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
177
                % hacked by suzuki toshiya at 2001/3/6
178
                %dup /gsubvog exch _cjkv_type11_tmp /gsubost get 6 add _cjkv_type11_tmp /gsubglc get getinterval _cjkv_type11_tmp 3 1 roll put
179
                %dup /gsubhog exch _cjkv_type11_tmp /gsubost get _cjkv_type11_tmp /gsubocv get add 4 add _cjkv_type11_tmp /gsubglc get getinterval _cjkv_type11_tmp 3 1 roll put
180
                dup /gsubvog exch _cjkv_type11_tmp /gsubost get 6 add _cjkv_type11_tmp /gsubglc get 2 mul getinterval _cjkv_type11_tmp 3 1 roll put
181
                dup /cvfmt exch _cjkv_type11_tmp /gsubost get _cjkv_type11_tmp /gsubocv get add 0 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
182
                dup /cvglc exch _cjkv_type11_tmp /gsubost get _cjkv_type11_tmp /gsubocv get add 2 add .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
183
                dup /gsubhog exch _cjkv_type11_tmp /gsubost get _cjkv_type11_tmp /gsubocv get add 4 add _cjkv_type11_tmp /cvglc get 2 mul getinterval _cjkv_type11_tmp 3 1 roll put
184
                CJKV_DEBUG_GSUB {
185
                  (gsubocv: ) print _cjkv_type11_tmp /gsubocv get =
186
                  (gsubglc: ) print _cjkv_type11_tmp /gsubglc get =
187
                  (cvfmt: ) print _cjkv_type11_tmp /cvfmt get =
188
  
189
                  (gsubhog->gsubvog ) =
190
                  0 2 _cjkv_type11_tmp /gsubhog get length 2 sub { % for
191
                    dup
192
                    _cjkv_type11_tmp /gsubhog get exch .cjkv_getu16 =only
193
                    (->) =only
194
                    _cjkv_type11_tmp /gsubvog get exch .cjkv_getu16 =
195
                  } for
196
                } if
197
                _cjkv_type11_tmp /cvfmt get 1 eq {
198
                  /gsubh2v << 0 2 _cjkv_type11_tmp /gsubhog get length 2 sub {
199
                    dup _cjkv_type11_tmp /gsubhog get exch .cjkv_getu16
200
                    exch _cjkv_type11_tmp /gsubvog get exch .cjkv_getu16
201
                  } for >> _cjkv_type11_tmp 3 1 roll put
202
                } {
203
                  _cjkv_type11_tmp /cvfmt get 2 eq {
204
                    /gsubh2v << 0 6 _cjkv_type11_tmp /gsubhog get length 6 sub {
205
                      dup 0 add /fgid exch _cjkv_type11_tmp /gsubhog get exch .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
206
                      dup 2 add /lgid exch _cjkv_type11_tmp /gsubhog get exch .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
207
                      4 add /cvidx exch _cjkv_type11_tmp /gsubhog get exch .cjkv_getu16 _cjkv_type11_tmp 3 1 roll put
208
                      CJKV_DEBUG_GSUB {
209
                        (fgid: ) print _cjkv_type11_tmp /fgid get =
210
                        (lgid: ) print _cjkv_type11_tmp /lgid get =
211
                        (cvidx: ) print _cjkv_type11_tmp /cvidx get =
212
                      } if
213
                      _cjkv_type11_tmp /fgid get 1 _cjkv_type11_tmp /lgid get {
214
                        dup _cjkv_type11_tmp /cvidx get add _cjkv_type11_tmp /fgid get sub
215
                        exch _cjkv_type11_tmp /gsubvog get exch .cjkv_getu16
216
                      } for
217
                    } for >> _cjkv_type11_tmp 3 1 roll put
218
                  } {
219
                    %(UNKNWON COVERAGE FORMAT.) = flush
220
                  } ifelse
221
                } ifelse
222
              } {
223
                %(UNKNOWN GSUB FORMAT.) = flush
224
              } ifelse
225
  %           } {
226
  %             (ILLEGAL GSUB VERSION.) = flush
227
  %           } ifelse
228
            } for
229
          } if
230
        } for
231
      } if
232
      pop
233
    } if
234
  } bind def
235
  
236
  % glyphid .gsublookup glyphid
237
  % Lookup substitute table. return the origin if not found.
238
  %   modified by Taiji Yamada <taiji@aihara.co.jp> and Hideyuki Suzuki
239
  /.gsublookup {
240
    CJKV_DEBUG_TT11 { (.gsublookup\n) print flush } if
241
    dup _cjkv_type11_tmp /gsubh2v get exch .knownget { exch pop } if
242
  } bind def
243
  
244
  % - .cjkv_getos2 -
245
  % Defines os2ver, os2cp1, os2cp2
246
  %   to detect the kind of CID with the OS/2 table of a TrueType font.
247
  % Written by Taiji Yamada <taiji@aihara.co.jp>
248
  %
249
  % [OS/2 - OS/2 and Windows Metrics]
250
  % Index        Size        Type        Name of Entry
251
  % -----------------------------------
252
  % 0        2        USHORT        version
253
  % 2        2        SHORT        xAvgCharWidth
254
  % 4        2        USHORT        usWeightClass
255
  % 6        2        USHORT        usWidthClass
256
  % 8        2        SHORT        fsType
257
  % 10        2        SHORT        ySubscriptXSize
258
  % 12        2        SHORT        ySubscriptYSize
259
  % 14        2        SHORT        ySubscriptXOffset
260
  % 16        2        SHORT        ySubscriptYOffset
261
  % 18        2        SHORT        ySuperscriptXSize
262
  % 20        2        SHORT        ySuperscriptYSize
263
  % 22        2        SHORT   ySuperscriptXOffset
264
  % 24        2        SHORT        ySuperscriptYOffset
265
  % 26        2        SHORT        yStrikeoutSize
266
  % 28        2        SHORT        yStrikeoutPosition
267
  % 30        2        SHORT        sFamilyClass
268
  % 32        10        BYTE        panose[10]
269
  % 42        4        ULONG        ulUnicodeRange1
270
  % 46        4        ULONG        ulUnicodeRange2
271
  % 50        4        ULONG        ulUnicodeRange3
272
  % 54        4        ULONG        ulUnicodeRange4
273
  % 58        4        CHAR        achVendID[4]
274
  % 62        2        USHORT        fsSelection
275
  % 64        2        USHORT        usFirstCharIndex
276
  % 66        2        USHORT        usLastCharIndex
277
  % 68        2        SHORT        sTypoAscender
278
  % 70        2        SHORT        sTypoDescender
279
  % 72        2        SHORT        sTypoLineGap
280
  % 74        2        USHORT        usWinAscent
281
  % 76        2        USHORT        usWinDescent
282
  % 78        4        ULONG        ulCodePageRange1
283
  % 82        4        ULONG        ulCodePageRange2
284
  % 86        2        SHORT        sxHeight
285
  % 88        2        SHORT        sCapHeight
286
  % 90        2        USHORT        usDefaultChar
287
  % 92        2        USHORT        usBreakChar
288
  % 94        2        USHORT        usMaxContext
289
  % -----------------------------------
290
  % References
291
  % 1. http://www.microsoft.com/typography/OTSPEC/os2.htm
292
  %
293
  /.cjkv_getos2 {
294
    CJKV_DEBUG_TT11 { (.cjkv_getos2\n) print flush } if
295
    /os2ver 0 def
296
    tabdict (OS/2) cvn .knownget { % if
297
      dup /os2ver exch 0 .cjkv_getu16 def
298
      os2ver 0 gt { % if
299
        %dup /os2typ exch 8 .cjkv_gets16 def
300
        %dup /os2fam exch 30 .cjkv_gets16 def
301
        dup /os2ur1 exch 42 .cjkv_getu32 def
302
        dup /os2ur2 exch 46 .cjkv_getu32 def
303
        dup /os2ur3 exch 50 .cjkv_getu32 def
304
        dup /os2ur4 exch 54 .cjkv_getu32 def
305
        %dup /os2sel exch 62 .cjkv_getu16 def
306
        %dup /os2fci exch 64 .cjkv_getu16 def
307
        %dup /os2lci exch 64 .cjkv_getu16 def
308
        dup /os2cp1 exch 78 .cjkv_getu32 def 
309
        dup /os2cp2 exch 82 .cjkv_getu32 def
310
        CJKV_DEBUG_OS2 {
311
          /tmp 64 string def
312
          (os2ver: ) print os2ver 2 tmp cvrs =
313
          %(os2typ: ) print os2typ 2 tmp cvrs =
314
          %(os2fam: ) print os2fam 2 tmp cvrs =
315
          (os2ur1: ) print os2ur1 2 tmp cvrs =
316
          (os2ur2: ) print os2ur2 2 tmp cvrs =
317
          (os2ur3: ) print os2ur3 2 tmp cvrs =
318
          (os2ur4: ) print os2ur4 2 tmp cvrs =
319
          %(os2sel: ) print os2sel 2 tmp cvrs =
320
          %(os2fci: ) print os2fci 2 tmp cvrs =
321
          %(os2lci: ) print os2lci 2 tmp cvrs =
322
          (os2cp1: ) print os2cp1 2 tmp cvrs =
323
          (os2cp2: ) print os2cp2 2 tmp cvrs =
324
          [
325
            [ 1 0 bitshift (Latin 1)        ]
326
            [ 1 1 bitshift (Latin 2)        ]
327
            [ 1 2 bitshift (Cyrillic)        ]
328
            [ 1 3 bitshift (Greek)        ]
329
            [ 1 4 bitshift (Turkish)        ]
330
            [ 1 5 bitshift (Hebrew)        ]
331
            [ 1 6 bitshift (Arabic)        ]
332
            [ 1 7 bitshift (Baltic)        ]
333
            [ 1 8 bitshift (Vietnamese)        ]
334
            [ 1 16 bitshift (Thai)        ]
335
            [ 1 17 bitshift (Japanese)        ]
336
            [ 1 18 bitshift (Simplified Chinese)        ]
337
            [ 1 19 bitshift (Korean Wansung)        ]
338
            [ 1 20 bitshift (Traditional Chinese)        ]
339
            [ 1 21 bitshift (Korean Johab)        ]
340
            [ 1 31 bitshift (Symbol)        ]
341
          ] { % forall
342
            dup 0 get os2cp1 and 0 gt { % if
343
              (CodePage: ) print 1 get =
344
            } {
345
                pop
346
            } ifelse
347
          } forall
348
        } if
349
      } if
350
      pop
351
    } if
352
  } bind def
353
  
354
  % ---------------- CJK TrueType font loading ---------------- %
355
  
356
  % Written by the gs-cjk project
357
  
358
  % .parsecmap
359
  % push an array as a result of reading a CMap file.
360
  % the array is of the following form.
361
  %   [ [ [ dst src num ] [ dst src num ] ... [ dst src num ] ]
362
  %     [ [ dst src num ] [ dst src num ] ... [ dst src num ] ]
363
  %     ...
364
  %     [ [ dst src num ] [ dst src num ] ... [ dst src num ] ] ]
365
  % each array [dst src num] corresponds to each line within
366
  % /begin{bf,cid}{char,range}/end{bf,cid}{char,range} pairs.
367
  
368
  /.parsecmapdict mark
369
  
370
    CJKV_DEBUG_TT11 { (.parsecmapdict\n) print flush } if
371
    % override system operators
372
    /findresource { pop } bind
373
    /defineresource { pop pop } bind
374
    /dict {}
375
    /def { pop pop } bind
376
    /dup null
377
    /begin { pop } bind
378
    /end {}
379
    /currentdict null
380
  
381
    % override CMap operators
382
    /usecmap { pop } bind
383
    /CMapName null
384
    /begincmap { [ } bind
385
    /endcmap { ] } bind
386
    /begincodespacerange { pop mark } bind
387
    /endcodespacerange { cleartomark } bind
388
    /beginnotdefrange { pop mark } bind
389
    /endnotdefrange { cleartomark } bind
390
    /beginbfchar { /parsecmapcounter exch def } bind        % for FromCID CMaps
391
    /endbfchar {
392
      parsecmapcounter dup array exch 1 sub -1 0 {
393
        [ 5 3 roll exch .cjkv_strtoint 1 ]
394
        2 index 3 1 roll put
395
      } for
396
    } bind
397
    /beginbfrange { begincidrange }                       % for FromCID CMaps
398
    /endbfrange { endcidrange }
399
    /begincidchar { beginbfchar }                                % for ToCID CMaps
400
    /endcidchar { endbfchar }
401
    /begincidrange { /parsecmapcounter exch def } bind        % for ToCID CMaps
402
    /endcidrange {
403
      parsecmapcounter dup array exch 1 sub -1 0 {
404
        [ 6 3 roll 3 1 roll .cjkv_strtoint exch .cjkv_strtoint exch 1 index sub 1 add ]
405
        2 index 3 1 roll put
406
      } for
407
    } bind
408
  
409
    % misc
410
    /parsecmapcounter 0
411
  
412
  .dicttomark def         % .parsecmapdict
413
  
414
  
415
  /.parsecmapfname 100 string def
416
  
417
  % <CMapName> .parsecmap <array>
418
  % Return the contents of the CMap.  If the CMap is not found, empty array
419
  % is returned.  Note that usecmap is ignored because of efficiency.
420
  /.parsecmap {
421
    CJKV_DEBUG_TT11 { (.parsecmap\n) print flush } if
422
    /CMap /Category findresource begin
423
    //.parsecmapfname ResourceFileName end        % filename
424
    dup status {
425
      pop pop pop pop
426
      _cjkv_type11_util /.parsecmapdict get begin run end
427
    } {
428
      pop []
429
    } ifelse
430
  } bind def
431
  
432
  % .cjkv_buildcmaptab
433
  % construct a cmap table using information obtained from horizontal/vertical
434
  % CMaps, ToUnicode CMap, and substition data.
435
  
436
  % cmap /CMap proc .applyCMap cmap
437
  /.applyCMap {
438
    CJKV_DEBUG_TT11 { (.applyCMap\n) print flush } if
439
    exch _cjkv_type11_util /.parsecmap get exec                        % {} [[[].].]
440
    dup length 1 sub -1 0 {                % {} [[[].].] len-1 -1 0 {} for
441
      1 index exch get                        % {} [[[].].] [[].]
442
      dup length 1 sub -1 0 {                % {} [[[].].] [[].] len-1 -1 0 for {}
443
        1 index exch get                        % {} [[[].].] [[].] [ cid gid num ]
444
        cvx exec cmapglyphs                % {} [[[].].] [[].] cid gid num gmap
445
        3 1 roll .cjkv_safegetinterval {        % {} [[[].].] [[].] cid [gid'..]
446
          4 index exec dup cmapglyphs 0 get eq 1 index 0 eq or {
447
            % found no glyph
448
            pop
449
          } {
450
            % found a glyph
451
            5 index exch 2 index exch .cjkv_safeput
452
          } ifelse
453
          1 add                                % {} [[[].].] [[].] cid++
454
        } forall pop
455
      } for                                % {} [[[].].] [[].]
456
      pop                                        % {} [[[].].]
457
    } for                                        % {} [[[].].]
458
    pop pop                                %
459
  } bind def
460
  
461
  % cmap /CMap-V .applyvCMap cmap
462
  /.applyvCMap {
463
    CJKV_DEBUG_TT11 { (.applyvCMap\n) print flush } if
464
    _cjkv_type11_tmp /gsubh2v get null ne {
465
      { _cjkv_type11_util /.gsublookup get exec } _cjkv_type11_util /.applyCMap get exec
466
    } {
467
      { } _cjkv_type11_util /.applyCMap get exec
468
    } ifelse
469
  } bind def
470
  
471
  % cmap /CMap-H .applyhCMap cmap
472
  /.applyhCMap {
473
    CJKV_DEBUG_TT11 { (.applyhCMap\n) print flush } if
474
    { } _cjkv_type11_util /.applyCMap get exec
475
  } bind def
476
  
477
  % cmap /CMap-V .applyvCMapUnicode cmap
478
  /.applyvCMapUnicode {
479
    CJKV_DEBUG_TT11 { (.applyvCMapUnicode\n) print flush } if
480
    _cjkv_type11_tmp /gsubh2v get null ne {
481
      {
482
        dup 16#f900 ge
483
        1 index 16#ff00 ge 2 index 16#ff9f le and not
484
        and not {
485
          _cjkv_type11_util /.gsublookup get exec
486
        } if
487
      } bind _cjkv_type11_util /.applyCMap get exec
488
    } {
489
      { } _cjkv_type11_util /.applyCMap get exec
490
    } ifelse
491
  } bind def
492
  
493
  % cmap /Adobe-*-* .applyCIDToCode cmap
494
  /.applyCIDToCode {
495
    CJKV_DEBUG_TT11 { (.applyCIDToCode\n) print flush } if
496
    _cjkv_type11_util /.parsecmap get exec
497
    {
498
      {                           % cmap [ dist cid num ]
499
        dup 0 get length 2 gt {   % multi-byte dist is not supported yet.
500
          pop
501
        } {
502
          cvx exec exch           % cmap dist num cid
503
          cmapglyphs 4 2 roll     % cmap cid cmapglyphs dist num
504
          exch .cjkv_strtoint exch
505
          .cjkv_safegetinterval        % cmap cid subcmapglyphs
506
          {                       % cmap cid gid
507
            2 index 2 index       % cmap cid gid cmap cid
508
            3 2 roll              % cmap cid cmap cid gid
509
            .cjkv_safeput              % cmap cid
510
            1 add                 % cmap nextcid
511
          } forall pop
512
        } ifelse
513
      } forall
514
    } forall
515
  } bind def
516
  
517
  % cmap /Adobe-*-UCS2 .applyCIDToUnicode cmap
518
  /.applyCIDToUnicode {
519
    CJKV_DEBUG_TT11 { (.applyCIDToUnicode\n) print flush } if
520
    _cjkv_type11_util /.parsecmap get exec
521
    {
522
      {                           % cmap [ distuni cid num ]
523
        dup 0 get length 2 gt     % multi-byte dist is not supported yet.
524
        1 index 0 get <fffd> eq   % the value <fffd> is regard as undefined code.
525
        or {
526
          pop
527
        } {
528
          cvx exec exch           % cmap distuni num cid
529
          cmapglyphs 4 2 roll     % cmap cid cmapglyphs distuni num
530
          exch .cjkv_strtoint exch     % cmap cid cmapglyphs distuni num
531
          .cjkv_safegetinterval        % cmap cid subcmapglyphs
532
          {                       % cmap cid gid
533
            2 index 2 index       % cmap cid gid cmap cid
534
            3 2 roll              % cmap cid cmap cid gid
535
            .cjkv_safeput              % cmap cid
536
            1 add                 % cmap nextcid
537
          } forall pop
538
        } ifelse
539
      } forall
540
    } forall
541
  } bind def
542
  
543
  /.cjkv_buildcmapdict mark
544
    /Adobe-CNS1 <<
545
      /Registry (Adobe)
546
      /Ordering (CNS1)
547
      /CIDCounts [ 14099 17408 17601 18846 18962 ]
548
      /Big5 { 0 {
549
        /Adobe-CNS1-ETen-B5     _cjkv_type11_util /.applyCIDToCode    get exec
550
        /ETen-B5-V              _cjkv_type11_util /.applyvCMap        get exec
551
        /ETen-B5-H              _cjkv_type11_util /.applyhCMap        get exec
552
      } }
553
      /Unicode { 3 {
554
        /Adobe-CNS1-UCS2        _cjkv_type11_util /.applyCIDToUnicode get exec
555
        /UniCNS-UCS2-V          _cjkv_type11_util /.applyvCMapUnicode get exec
556
        /UniCNS-UCS2-H          _cjkv_type11_util /.applyhCMap        get exec
557
      } }
558
    >>
559
    /Adobe-GB1 <<
560
      /Registry (Adobe)
561
      /Ordering (GB1)
562
      /CIDCounts [ 7717 9897 22127 22353 29064 ]
563
      /PRC { 2 {
564
        /Adobe-GB1-GBK-EUC      _cjkv_type11_util /.applyCIDToCode    get exec
565
        /GBK-EUC-V              _cjkv_type11_util /.applyvCMap        get exec
566
        /GBK-EUC-H              _cjkv_type11_util /.applyhCMap        get exec
567
      } }
568
      /Unicode { 4 {
569
        /Adobe-GB1-UCS2         _cjkv_type11_util /.applyCIDToUnicode get exec
570
        /UniGB-UCS2-V           _cjkv_type11_util /.applyvCMapUnicode get exec
571
        /UniGB-UCS2-H           _cjkv_type11_util /.applyhCMap        get exec
572
      } }
573
    >>
574
    /Adobe-Japan1 <<
575
      /Registry (Adobe)
576
      /Ordering (Japan1)
577
      /CIDCounts [ 8284 8359 8720 9354 15444 20317 23058 ]
578
      /ShiftJIS { 2 {
579
        /Adobe-Japan1-90ms-RKSJ _cjkv_type11_util /.applyCIDToCode    get exec
580
        /90ms-RKSJ-V            _cjkv_type11_util /.applyvCMap        get exec
581
        /90ms-RKSJ-H            _cjkv_type11_util /.applyhCMap        get exec
582
      } }
583
      /Unicode { 4 {
584
        /Adobe-Japan1-UCS2      _cjkv_type11_util /.applyCIDToUnicode get exec
585
        /UniJIS-UCS2-V          _cjkv_type11_util /.applyvCMapUnicode get exec
586
        /UniJIS-UCS2-H          _cjkv_type11_util /.applyhCMap        get exec
587
      } }
588
    >>
589
    /Adobe-Japan2 <<
590
      /Registry (Adobe)
591
      /Ordering (Japan2)
592
      /CIDCounts [ 6068 ]
593
      /Unicode { 0  {
594
        /UniHojo-UCS2-V         _cjkv_type11_util /.applyvCMapUnicode get exec
595
        /UniHojo-UCS2-H         _cjkv_type11_util /.applyhCMap        get exec
596
      } }
597
    >>
598
    /Adobe-Korea1 <<
599
      /Registry (Adobe)
600
      /Ordering (Korea1)
601
      /CIDCounts [ 9333 18155 18352 ]
602
      /Johab { 1 {
603
        /KSC-Johab-V            _cjkv_type11_util /.applyvCMap        get exec
604
        /KSC-Johab-H            _cjkv_type11_util /.applyhCMap        get exec
605
      } }
606
      /Unicode { 2 {
607
        /Adobe-Korea1-UCS2      _cjkv_type11_util /.applyCIDToUnicode get exec
608
        /UniKS-UCS2-V           _cjkv_type11_util /.applyvCMapUnicode get exec
609
        /UniKS-UCS2-H           _cjkv_type11_util /.applyhCMap        get exec
610
      } }
611
      /Wansung { 1 {
612
        /Adobe-Korea1-KSCms-UHC _cjkv_type11_util /.applyCIDToCode    get exec
613
        /KSCms-UHC-V            _cjkv_type11_util /.applyvCMap        get exec
614
        /KSCms-UHC-H            _cjkv_type11_util /.applyhCMap        get exec
615
      } }
616
    >>
617
    /Identity <<        % ttcmap ordering CIDMap only for specific and rare CJK TTF
618
      /Registry (Unregistered)        % Thus Registry value is unpredictable. This
619
      /Ordering (Identity)        % CIDFont can be used with Identity-H|V CMap
620
      /CIDCounts [ 65535 ]
621
      /H { 0 {
622
        /Identity-H             _cjkv_type11_util /.applyhCMap        get exec % for ttcmap-order CIDMap
623
      } }
624
      /V { 0 {
625
        /Identity-H             _cjkv_type11_util /.applyvCMap        get exec % for ttcmap-order and vertically-used CIDMap
626
      } }
627
    >>
628
  .dicttomark def
629
  
630
  /.cjkv_ttencmap <<
631
    /Identity              false
632
    /Auto                  { 
633
                             CJKV_DEBUG_TT11 { (+++ ttencmap->Auto exec\n) print flush } if
634
                             _cjkv_type11_util /.cjkv_ttencoding get exec {
635
                               dup
636
                               _cjkv_type11_util /.cjkv_ttcharset get
637
                               exch get
638
                             CJKV_DEBUG_TT11 { (+++                exec\n) print flush } if
639
                               exec
640
                             CJKV_DEBUG_TT11 { (+++                      ok\n) print flush } if
641
                               exch true
642
                             } {
643
                               false
644
                             } ifelse
645
                           } bind
646
    /Adobe-CNS1            { /Adobe-CNS1   _cjkv_type11_util /.cjkv_ttencoding get exec }
647
    /Adobe-GB1             { /Adobe-GB1    _cjkv_type11_util /.cjkv_ttencoding get exec }
648
    /Adobe-Japan1          { /Adobe-Japan1 _cjkv_type11_util /.cjkv_ttencoding get exec }
649
    /Adobe-Japan2          { /Adobe-Japan2 _cjkv_type11_util /.cjkv_ttencoding get exec }
650
    /Adobe-Korea1          { /Adobe-Korea1 _cjkv_type11_util /.cjkv_ttencoding get exec }
651
    /Adobe-CNS1-Big5       { /Adobe-CNS1   /Big5     true }
652
    /Adobe-CNS1-Unicode    { /Adobe-CNS1   /Unicode  true }
653
    /Adobe-GB1-PRC         { /Adobe-GB1    /PRC      true }
654
    /Adobe-GB1-Unicode     { /Adobe-GB1    /Unicode  true }
655
    /Adobe-Japan1-ShiftJIS { /Adobe-Japan1 /ShiftJIS true }
656
    /Adobe-Japan1-Unicode  { /Adobe-Japan1 /Unicode  true }
657
    /Adobe-Japan2-Unicode  { /Adobe-Japan2 /Unicode  true }
658
    /Adobe-Korea1-Johab    { /Adobe-Korea1 /Johab    true }
659
    /Adobe-Korea1-Unicode  { /Adobe-Korea1 /Unicode  true }
660
    /Adobe-Korea1-Wansung  { /Adobe-Korea1 /Wansung  true }
661
    /Identity-H            { /Identity     /H        true }
662
    /Identity-V            { /Identity     /V        true }
663
  >> def
664
  
665
  /.cjkv_ttcharset <<
666
    /Unicode  { _cjkv_type11_util /.cjkv_detectos2 get exec }
667
    /ShiftJIS /Adobe-Japan1
668
    /Big5     /Adobe-CNS1
669
    /PRC      /Adobe-GB1
670
    /Wansung  /Adobe-Korea1
671
    /Johab    /Adobe-Korea1
672
  >> def
673
  
674
  /.cjkv_ttencdict <<
675
    <00030001> /Unicode
676
    <00030002> /ShiftJIS
677
    <00030003> /Big5
678
    <00030004> /PRC
679
    <00030005> /Wansung
680
    <00030006> /Johab
681
  >> def
682
  
683
  /.cjkv_ttencoding {
684
    CJKV_DEBUG_TT11 { (.cjkv_ttencoding\n) print flush } if
685
    _cjkv_type11_util /.cjkv_ttencdict get _cjkv_ttcmap_tmp /cmapsub get 0 4 getinterval .knownget
686
  } bind def
687
  
688
  /.cjkv_ttos2tab [
689
    [ 1 20 bitshift /Adobe-CNS1   ]
690
    [ 1 18 bitshift /Adobe-GB1    ]
691
    [ 1 17 bitshift /Adobe-Japan1 ]
692
    [ 1 19 bitshift /Adobe-Korea1 ]
693
    [ 1 21 bitshift /Adobe-Korea1 ]
694
  ] def
695
  
696
  /.cjkv_detectos2 {
697
    CJKV_DEBUG_TT11 { (.cjkv_detectos2\n) print flush } if
698
    /Identity        % default linear ordering to GID, Adobe Identity CIDs
699
    os2ver 0 gt {
700
      _cjkv_type11_util /.cjkv_ttos2tab get {
701
        dup 0 get os2cp1 and 0 ne {
702
          1 get exch
703
        } if pop
704
      } forall
705
    } if
706
  } bind def
707
708
end readonly def
(-)lib/cjkv/tt42util.ps (+482 lines)
Line 0 Link Here
1
%!
2
%
3
% Developed by AXE,Inc., BBR Inc. and Turbolinux Inc.
4
%   under the technical advice by suzuki toshiya (Hiroshima University)
5
% For questions, please send mail to espgs8-cjk@printing-japan.org
6
%
7
% (C) Copyright 2006 Center of the International Cooperation for
8
%     Computerization
9
%
10
%
11
% Based on gs-cjk patches
12
% Copyright (C) 2001-2003 gs-cjk project:
13
%   Taiji Yamada, Hideyuki Suzuki, Masatake Yamato and suzuki toshiya.
14
%   Enhancements by Akira Tagoh and Taiji Yamada, 2005.
15
%   All rights reserved.
16
%
17
%
18
% Based on GNU Ghostscript 7.07 and 8.15
19
% Copyright (C) 1996-2003 artofcode LLC.  All rights reserved.
20
%
21
% This software is provided AS-IS with no warranty, either express or
22
% implied.
23
%
24
%
25
% This program is free software;  you can redistribute it and/or
26
% modify it under the terms of the GNU General Public License as
27
% published by the Free Software Foundation; either version 2 of
28
% the License, or (at your option) any later version.
29
%
30
% This program is distributed in the hope that it will be useful,
31
% but WITHOUT ANY WARRANTY; without even the implied warranty of
32
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
33
% See the GNU General Public License for more details.
34
%
35
% You should have received a copy of the GNU General Public License
36
% along with this program; if not, write to the Free Software Foundation,
37
% Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38
%
39
40
41
[
42
   /CJKV_DEBUG_TT42
43
] {dup where {pop pop} { currentdict exch false def pop } ifelse} forall
44
45
/_cjkv_type42_tmp 10 dict def
46
47
/_cjkv_type42_util 15 dict dup begin
48
49
  % <tab> .cjkv_printtab -
50
  /.cjkv_printtab {
51
    CJKV_DEBUG_TT42 { (.cjkv_printtab\n) print flush } if
52
    dup 0 4 getinterval print ( ) print
53
    dup 8 .cjkv_getu32 =only ( ) print
54
    12 .cjkv_getu32 =
55
  } bind def
56
  
57
  % <file> .cjkv_loadttfonttables -
58
  % <file> <fontindex> .cjkv_loadttfonttables - % extention by hideyuki
59
  % Pushes .cjkv_loadttfontdict & scratch dict on d-stack.
60
  % Defines f, offsets, tables, tabdict, tabs.
61
  /.cjkv_loadttfonttables {
62
    CJKV_DEBUG_TT42 { (*** .cjkv_loadttfonttables start\n) print flush } if
63
    _cjkv_base_util begin
64
    40 dict begin
65
    dup type /integertype eq % extention by hideyuki
66
    { 1 sub } { 0 } ifelse /findex exch def
67
    /f exch def
68
    /offsets f 12 string readstring pop def
69
  
70
    CJKV_DEBUG_TT42 { (*** .cjkv_loadttfonttables init #1 is ok\n) print flush } if
71
    % TrueType Collection File support
72
    % Jan 11 2000: Hideyuki Suzuki <hideyuki@sat.t.u-tokyo.ac.jp>
73
    % Feb 10 2001: suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
74
    offsets 0 4 getinterval (ttcf) eq {
75
      [ 1 1 offsets 8 .cjkv_getu32 { pop f 4 string readstring pop 0 .cjkv_getu32} for ]
76
      dup findex get dup /ttcheader exch def exch length 4 mul 12 add sub
77
      %dup 0 gt { string f exch readstring pop } if pop
78
      f fileposition add f exch setfileposition
79
      % the previous line is for very large ttcf, hacked by suzuki toshiya
80
      /offsets f 12 string readstring pop def
81
    } { /ttcheader 0 def } ifelse
82
    CJKV_DEBUG_TT42 { (*** .cjkv_loadttfonttables init #2 is ok\n) print flush } if
83
  
84
    /tables f offsets 4 .cjkv_getu16 16 mul string readstring pop def
85
    CJKV_DEBUG_TT42 { (*** .cjkv_loadttfonttables tables def ok\n) print flush } if
86
    /tabdict tables length 16 idiv dict def
87
    CJKV_DEBUG_TT42 { (*** .cjkv_loadttfonttables tabdict def ok\n) print flush } if
88
  	% tabs = tables we want to keep, sorted by file position.
89
    /tabs [ 0 16 tables length 1 sub {
90
      tables exch 16 getinterval
91
      CJKV_DEBUG_TT42 { dup _cjkv_type42_util /.cjkv_printtab get exec } if
92
      dup 0 4 getinterval _cjkv_readtables 1 index known {
93
        tabdict exch 2 index put
94
      } {
95
        pop pop
96
      } ifelse
97
    } for ] {
98
      exch 8 .cjkv_getu32 exch 8 .cjkv_getu32 lt
99
    } .cjkv_sort def
100
  	% In certain malformed TrueType fonts, tables overlap.
101
  	% Truncate tables if necessary.
102
    0 1 tabs length 2 sub {
103
      dup tabs exch get exch 1 add tabs exch get
104
      1 index 8 .cjkv_getu32 2 index 12 .cjkv_getu32 add
105
      1 index 8 .cjkv_getu32 gt {
106
        (**** Warning: ) print 1 index 0 4 getinterval print
107
        ( overlaps ) print dup 0 4 getinterval print
108
        (, truncating.) = flush
109
        dup 8 .cjkv_getu32 2 index 8 .cjkv_getu32 sub
110
        2 index 12 3 -1 roll .cjkv_putu32
111
      } if pop pop
112
    } for
113
    CJKV_DEBUG_TT42 { (*** .cjkv_loadttfonttables finished \n) print flush } if
114
  } bind def
115
  
116
  % - .cjkv_readttdata -
117
  % Read data.  Updates offsets, tabs; stores data in tabdict.
118
  /.cjkv_readttdata {
119
    CJKV_DEBUG_TT42 { (.cjkv_readttdata\n) print flush } if
120
  
121
    % TrueType Collection File support
122
    % Jan 11 2000: Hideyuki Suzuki <hideyuki@sat.t.u-tokyo.ac.jp>
123
    % /fpos offsets length tables length add def
124
    /fpos ttcheader offsets length tables length add add def
125
    /sfpos offsets length tabs length 16 mul add def
126
    offsets 4 tabs length .cjkv_putu16
127
    tabs {
128
      dup 0 4 getinterval /tname exch def
129
      dup 8 .cjkv_getu32 /tpos exch def
130
      dup 12 .cjkv_getu32 /tlen exch def
131
      8 sfpos .cjkv_putu32
132
  	% Skip data between the end of the previous table and
133
  	% the beginning of this one, if any.
134
      tpos fpos gt {
135
        f tpos fpos sub () /SubFileDecode filter dup flushfile closefile
136
        /fpos tpos def
137
      } if
138
      f tlen _cjkv_readtables tname get exec
139
      tabdict tname 3 -1 roll put
140
      /fpos fpos tlen add def
141
  	% Round up the table length to an even value.
142
      /sfpos sfpos tlen dup 1 and add add def
143
    } forall
144
  } bind def
145
  
146
  % Find the string in a list of strings that includes a given index.
147
  % <strings> <index> .findseg <string> <index'>
148
  /.cjkv_findseg {
149
    CJKV_DEBUG_TT42 { (.cjkv_findseg\n) print flush } if
150
    exch {
151
      dup length 2 index gt { exch exit } if
152
      length sub
153
    } forall
154
  } bind def
155
  
156
  % - .cjkv_makesfnts -
157
  % Defines checksum, getloca, head, locatable, numloca, post, sfnts, upem
158
  /.cjkv_makesfnts {
159
    CJKV_DEBUG_TT42 { (.cjkv_makesfnts\n) print flush } if
160
    _cjkv_type42_util /.cjkv_readttdata get exec
161
    /head tabdict /head get def
162
    /locatable tabdict /loca get def
163
    /post tabdict /post .knownget not { null } if def
164
    /numloca
165
      locatable dup type /stringtype eq
166
       { length }
167
       { 0 exch { length add } forall }
168
      ifelse      % no def yet
169
    locatable type /stringtype eq {
170
      _cjkv_type42_tmp /.indexloca {} put
171
    } {
172
      _cjkv_type42_tmp /.indexloca _cjkv_type42_util /.cjkv_findseg get put
173
    } ifelse
174
    head 50 .cjkv_getu16 0 ne {
175
      _cjkv_type42_tmp /getloca {
176
        2 bitshift locatable exch _cjkv_type42_tmp /.indexloca get exec .cjkv_getu32
177
      } put
178
      4 idiv 1 sub
179
    } {
180
      _cjkv_type42_tmp /getloca {
181
        dup add locatable exch _cjkv_type42_tmp /.indexloca get exec .cjkv_getu16 dup add
182
      } put
183
      2 idiv 1 sub
184
    } ifelse def          % numloca
185
          % If necessary, re-partition the glyfs.
186
    tabdict /glyf get dup type /stringtype ne {
187
      _cjkv_type42_util /.cjkv_dividesfnts get exec tabdict /glyf 3 -1 roll put
188
    } {
189
      pop
190
    } ifelse
191
    /sfnts [
192
      offsets tabs { concatstrings } forall
193
      tabs {
194
        0 4 getinterval tabdict exch get
195
        dup type /stringtype ne { aload pop } if
196
      } forall
197
    ] def
198
  } bind def
199
  
200
  % <glyfs> .cjkv_dividesfnts <glyfs'>
201
  /.cjkv_dividesfnts {
202
    CJKV_DEBUG_TT42 { (.cjkv_dividesfnts\n) print flush } if
203
    /glyfs exch def
204
    /len1 0 glyfs { length add } forall def
205
  		% Determine where to split the glyfs by scanning loca.
206
  		% The very last entry in loca may be bogus.
207
  		% Note that some loca entries may be odd, but we can only
208
  		% split at even positions.
209
  		%
210
  		% Construct splitarray, the array of final lengths of
211
  		% the sfnts entries covering the glyfs (i.e., all but
212
  		% the first and last sfnts entries).
213
      /prevsplit 0 def
214
      /prevboundary 0 def
215
      /prevoddboundary 0 def % see TYPE42_NO_ODDSIZE_STR in zfont42.c
216
      /splitarray [
217
        0 1 numloca 1 sub {
218
  	_cjkv_type42_tmp /getloca get exec dup prevsplit maxstring add gt {
219
            prevboundary prevsplit eq { % see TYPE42_NO_ODDSIZE_STR in zfont42.c
220
               /ferr (%stderr) (w) file def
221
               ferr (glyf table ) writestring
222
               ferr prevsplit 10 string cvs writestring
223
               ferr ( - ) writestring
224
               dup 10 string cvs ferr exch writestring
225
               ferr ( too long segment without suitable boundary.\n)
226
               writestring
227
               ferr closefile
228
               /prevboundary prevoddboundary def
229
            } if
230
            CJKV_DEBUG_TT42 {
231
               dup 10 string cvs print
232
               ( segment is longer than maxstring, split now ) print
233
               prevboundary 10 string cvs print
234
               ( - ) print
235
               prevsplit 10 string cvs print
236
               (\n) print
237
            } if
238
  	  prevboundary prevsplit sub exch
239
  	  /prevsplit prevboundary def
240
            % /prevoddboundary 0 def
241
  	} if
242
  	dup 1 and 0 eq { % see TYPE42_NO_ODDSIZE_STR in zfont42.c
243
            CJKV_DEBUG_TT42 {
244
              dup 10 string cvs print
245
              ( \() print
246
              dup prevsplit sub 10 string cvs print
247
              (\) ) print
248
              ( even length OK\n) print
249
  	} if
250
            /prevboundary exch def
251
            % /prevoddboundary 0 def
252
          } {
253
            CJKV_DEBUG_TT42 {
254
              dup 10 string cvs print
255
              ( \() print
256
              dup prevsplit sub 10 string cvs print
257
              (\) ) print
258
              ( odd length!\n) print
259
  	} if
260
            % prevoddboundary 0 eq {
261
              /prevoddboundary exch def
262
            % } { pop } ifelse
263
          } ifelse
264
          % dup 0 eq { (why ZERO?\n) print } if
265
          % dup ==
266
        } for
267
        len1 prevsplit sub
268
      ] def
269
      currentuserparams /VMReclaim get -2 vmreclaim
270
      [
271
  		% Re-split the sfnts glyfs strings according to splitarray.
272
  		% We do this by iterating over the final segments defined
273
  		% by splitarray, and constructing them from pieces of the
274
  		% current glyfs strings.  We recycle the current strings
275
  		% when possible, to avoid stressing the allocator.
276
        /sfnt_idx 0 def
277
        /strpos 0 def
278
        _cjkv_type42_tmp /avail () put
279
        splitarray {
280
  	/seglen exch def
281
  	/segpos 0 def
282
  	_cjkv_type42_tmp /avail get length seglen ge
283
  	  { _cjkv_type42_tmp /avail get 0 seglen getinterval _cjkv_type42_tmp /avail () put } { seglen string }
284
  	ifelse
285
  	{
286
  	  /str glyfs sfnt_idx get def
287
  	  /strlen str length def
288
  	  /strleft strlen strpos sub def
289
  	  seglen segpos sub strleft lt { exit } if
290
  		% Copy the (rest of the) string into the new segment.
291
  		% We know strleft <= segleft.
292
  	  dup segpos str strpos strleft getinterval putinterval
293
  	  /segpos segpos strleft add def
294
  	  _cjkv_type42_tmp /avail str put
295
  	  /sfnt_idx sfnt_idx 1 add def
296
  	  /strpos 0 def
297
  	  segpos seglen eq { exit } if
298
  	} loop
299
  		% Fill up the segment with an initial piece of the next
300
  		% existing glyfs string.  We know strleft > segleft.
301
  	/segleft seglen segpos sub def
302
  	dup segpos str strpos segleft getinterval putinterval
303
  	/strpos strpos segleft add def
304
        } forall
305
      ]
306
      exch vmreclaim
307
  } bind def
308
  
309
  
310
  % - .cjkv_getpost -
311
  % Uses post, defines glyphencoding
312
  /.getpost {
313
    CJKV_DEBUG_TT42 { (.getpost\n) print flush } if
314
    /glyphencoding post null eq {
315
      CJKV_DEBUG_TT42 { (post missing) = flush } if [ ]
316
    } {
317
      postformats post 0 .cjkv_getu32 .knownget {
318
        CJKV_DEBUG_TT42 {
319
          (post: format ) print
320
          post 0 .cjkv_getu16 =only (,) print post 2 .cjkv_getu16 = flush
321
        } if
322
        post exch exec
323
      } {
324
        CJKV_DEBUG_TT42 { (post: unknown format ) print post 0 .cjkv_getu32 = flush } if [ ]
325
      } ifelse
326
    } ifelse def
327
  } bind def
328
  
329
  % - .cjkv_ttkeys <key> <value> ...
330
  /.cjkv_ttkeys {
331
    CJKV_DEBUG_TT42 { (.cjkv_ttkeys\n) print flush } if
332
    count /ttkeycount exch def
333
    /upem head 18 .cjkv_getu16 def
334
    /FontMatrix matrix
335
    /FontBBox [ 36 2 42 { head exch .cjkv_gets16 upem div } for ]
336
    .cjkv_nextxuid
337
    tabdict /name .knownget {
338
  		% Find the names from the 'name' table.
339
      /names exch def
340
      /FontName names 6 .cjkv_findname not { .cjkv_curxuid 16 8 string cvrs } if
341
        /fontname 1 index def
342
      /FontInfo mark
343
        names 0 .cjkv_findname { /Notice exch } if
344
        names 1 .cjkv_findname { /FamilyName exch } if
345
        names 4 .cjkv_findname { /FullName exch } if
346
        names 5 .cjkv_findname { /Version exch } if
347
    } {
348
  		% No name table, fabricate a FontName.
349
      /FontName .cjkv_curxuid 16 8 string cvrs
350
        /fontname 1 index def
351
      /FontInfo mark
352
    } ifelse
353
    CJKV_DEBUG_TT42 { (fontname ) print fontname = } if
354
  		% Stack: ... /FontInfo mark key1 value1 ...
355
    post null ne {
356
      post type /arraytype eq {
357
        % this post table is a big table. /post should be [(...) ...]
358
        % data we actually need here should be first one in array.
359
        /posttable post 1 get def
360
      } {
361
        /posttable post def
362
      } ifelse
363
      /ItalicAngle        posttable  4 .cjkv_gets32 65536.0 div
364
      /isFixedPitch       posttable 12 .cjkv_getu32 0 ne
365
      /UnderlinePosition  posttable  8 .cjkv_gets16 upem div
366
      /UnderlineThickness posttable 10 .cjkv_gets16 upem div
367
    } if
368
    counttomark 0 ne { .dicttomark } { pop pop } ifelse
369
    /XUID [orgXUID 42 .cjkv_curxuid]
370
    CJKV_DEBUG_TT42 {
371
      tabs { _cjkv_type42_util /.cjkv_printtab get exec } forall
372
      [ sfnts { length } forall ] ==
373
      count ttkeycount sub array astore dup { == } forall aload pop
374
    } if
375
    /sfnts sfnts
376
  } bind def
377
  
378
  % ---------------- Standard TrueType font loading ---------------- %
379
  
380
  % - .cjkv_pickcmap -
381
  % Defines cmapsub, cmaptab
382
  /.cjkv_pickcmap {
383
    CJKV_DEBUG_TT42 { (.cjkv_pickcmap\n) print flush } if
384
    tabdict /cmap get
385
  		% The Apple cmap format is no help in determining the encoding.
386
  		% Look for a Microsoft table.  If we can't find one,
387
  		% just use the first table, whatever it is.
388
    dup 4 8 .cjkv_biggetinterval exch             % the default
389
    0 1 2 index 2 .cjkv_biggetu16 1 sub {
390
      8 mul 4 add 1 index exch 8 .cjkv_biggetinterval
391
      dup 0 .cjkv_biggetu16 /cmap_platform exch def
392
      dup 2 .cjkv_biggetu16 /cmap_encoding exch def
393
      CJKV_DEBUG_TT42 {
394
        (cmap: platform ) print cmap_platform =only
395
        ( encoding ) print cmap_encoding = flush
396
      } if
397
      cmap_platform 3 eq { exch 3 -1 roll pop exit } if pop
398
    } for
399
  		% Stack: subentry table
400
    /cmapsub 2 index _cjkv_ttcmap_tmp 3 1 roll put
401
    exch 4 .cjkv_biggetu32 1 index .cjkv_biglength 1 index sub .cjkv_biggetinterval
402
    /cmaptab exch _cjkv_ttcmap_tmp 3 1 roll put
403
  } bind def
404
  
405
  % <glyph> .cjkv_nname <_name>
406
  /.cjkv_nname {
407
    CJKV_DEBUG_TT42 { (.cjkv_nname\n) print flush } if
408
    =string cvs (_) exch concatstrings cvn
409
  } bind def
410
  
411
  % - .cjkv_charkeys /CharStrings <charstrings> /Encoding <encoding>
412
  % Resets glyphencoding
413
  /.cjkv_charkeys {
414
    CJKV_DEBUG_TT42 { (.cjkv_charkeys\n) print flush } if
415
    CJKV_DEBUG_TT42 {
416
      (glyphencoding: length=) print glyphencoding dup length = === flush
417
    } if
418
  		% Hack: if there is no usable post table but the cmap uses
419
  		% the Microsoft Unicode encoding, use ISOLatin1Encoding.
420
    glyphencoding length 0 eq _cjkv_ttcmap_tmp /cmapsub get 0 4 getinterval <00030001> eq and {
421
      /glyphencoding ISOLatin1Encoding dup length array copy def
422
    } if
423
  		% If necessary, fabricate additional glyphencoding entries
424
  		% to cover all of loca, or truncate glyphencoding.
425
    glyphencoding length numloca lt {
426
      /glyphencoding [ glyphencoding aload pop
427
      counttomark 1 numloca 1 sub { .cjkv_nname } for ] def
428
    } {
429
      /glyphencoding glyphencoding 0 numloca getinterval def
430
    } ifelse
431
  		% Some badly designed Chinese fonts have a post table
432
  		% in which all glyphs other than 0 are named .null.
433
  		% Use CharStrings to keep track of the reverse map from
434
  		% names to glyphs, and don't let any name be used for
435
  		% more than one glyph.
436
    /CharStrings glyphencoding dup length 1 add dict	% +1 for .notdef
437
      0 1 3 index length 1 sub {
438
  		% Stack: glyphencoding dict index
439
        2 index 1 index get 2 index 1 index known {
440
  		% The same name maps to more than one glyph.
441
  		% Change the name.
442
  	pop dup .cjkv_nname 3 index 2 index 2 index put
443
        } if
444
        2 index exch 3 -1 roll put
445
      } for exch pop
446
  		% If there is no .notdef entry, map it to glyph 0.
447
    dup /.notdef known not { dup /.notdef 0 put } if
448
    readonly
449
    /Encoding
450
      [ _cjkv_ttcmap_tmp /cmaptab get _cjkv_cmaparray dup length 256 gt { 0 256 getinterval } if
451
      { glyphencoding exch get } forall
452
      counttomark 256 exch sub { /.notdef } repeat ]
453
    CJKV_DEBUG_TT42 { (Encoding: ) print dup === flush } if
454
  } bind def
455
  
456
  % -mark- <key> <value> ... .cjkv_definettfont <font>
457
  /.cjkv_definettfont {
458
    CJKV_DEBUG_TT42 { (.cjkv_definettfont\n) print flush } if
459
    /FontType 42
460
    /PaintType 0
461
    CJKV_DEBUG_TT42 {
462
      (numloca=) print numloca =
463
    } if
464
    .dicttomark
465
    end end dup /FontName get exch definefont
466
  } bind def
467
  
468
  
469
  % <file> .cjkv_loadttfont <type42font>
470
  /.cjkv_loadttfont {
471
    CJKV_DEBUG_TT42 { (.cjkv_loadttfont\n) print flush } if
472
    .cjkv_loadttfonttables
473
    .cjkv_makesfnts
474
    .cjkv_getpost
475
    .cjkv_pickcmap
476
    mark
477
    .cjkv_charkeys
478
    .cjkv_ttkeys
479
    .cjkv_definettfont
480
  } bind def
481
482
end readonly def
(-)lib/gs_init.ps.in (+6 lines)
Lines 148-153 Link Here
148
currentdict /NOFONTMAP known   /NOFONTMAP exch def
148
currentdict /NOFONTMAP known   /NOFONTMAP exch def
149
currentdict /NOFONTPATH known   /NOFONTPATH exch def
149
currentdict /NOFONTPATH known   /NOFONTPATH exch def
150
currentdict /NOGC known   /NOGC exch def
150
currentdict /NOGC known   /NOGC exch def
151
currentdict /NOCJKV known   /NOCJKV exch def
151
currentdict /NOINTERPOLATE .knownget { /INTERPOLATE exch not def } if
152
currentdict /NOINTERPOLATE .knownget { /INTERPOLATE exch not def } if
152
currentdict /NOMEDIAATTRS known /NOMEDIAATTRS exch def
153
currentdict /NOMEDIAATTRS known /NOMEDIAATTRS exch def
153
currentdict /NOOUTERSAVE known   /NOOUTERSAVE exch def
154
currentdict /NOOUTERSAVE known   /NOOUTERSAVE exch def
Lines 2238-2241 Link Here
2238
  { NOOUTERSAVE not { save pop } if }	% do the outermost save unless disabled
2239
  { NOOUTERSAVE not { save pop } if }	% do the outermost save unless disabled
2239
ifelse
2240
ifelse
2240
2241
2242
%Load CJKV environment.
2243
NOCJKV not {
2244
  (cjkv/cjkvinit.ps) runlibfile
2245
} if
2246
2241
% The interpreter will run the initial procedure (start).
2247
% The interpreter will run the initial procedure (start).
(-)src/gdevijs.c (-96 / +75 lines)
Lines 43-48 Link Here
43
 *    This buffer overflow condition occurred with fullbleed print jobs that had k-band images.
43
 *    This buffer overflow condition occurred with fullbleed print jobs that had k-band images.
44
 * 2. Added Dan Coby (artifex) fix for gsijs_read_string_malloc gs_free *str memory leak.
44
 * 2. Added Dan Coby (artifex) fix for gsijs_read_string_malloc gs_free *str memory leak.
45
 *
45
 *
46
 * 06/02/06 David Suffield (gdevijs-krgb-1.3.patch)
47
 * 1. Revisited the krgb buffer overflow issue with out-of-band data in fill_rectangle and 
48
 *    copy_mono. Changed the fill_rectangle and copy_mono to an inner loop buffer check 
49
 *    instead of a outer loop x/y extent check.
50
 * 2. As requested by Ralph Giles, added K 1-bit and 8-bit support for krgb, but only 1-bit is 
51
 *    implemented for now.
52
 *
53
 *    KRGB definition:
54
 *    1. K=1-bit or 8-bit black plane, RGB=24 bit color raster.
55
 *    2. K-plane will only contain objects that are black text and black line drawings.
56
 *    3. RGB raster will not contain K-plane objects.
57
 *    4. K resolution and RGB resolution will be equal.
58
 *    5. K-plane will be byte aligned.
59
 *    6. K-plane 1-bit definition; 1=black, 0=nothing (KRGB).
60
 *    7. K-plane 8-bit definition; 255=black, 0=nothing (KxRGB).
61
 *
46
 */
62
 */
47
63
48
#include "unistd_.h"	/* for dup() */
64
#include "unistd_.h"	/* for dup() */
Lines 115-120 Link Here
115
131
116
    /* Additional parameters for krgb support. */
132
    /* Additional parameters for krgb support. */
117
    int krgb_mode;     /* 0=false, 1=true */
133
    int krgb_mode;     /* 0=false, 1=true */
134
    int k_bits;        /* number of bits in k plane, 1 or 8 */
118
    int k_path;        /* k plane path, 0=false, 1=true */
135
    int k_path;        /* k plane path, 0=false, 1=true */
119
    int k_width;       /* k plane width in pixels */
136
    int k_width;       /* k plane width in pixels */
120
    int k_band_size;   /* k plane buffer size in bytes, byte aligned */
137
    int k_band_size;   /* k plane buffer size in bytes, byte aligned */
Lines 149-154 Link Here
149
    NULL,	/* IjsClient *ctx */
166
    NULL,	/* IjsClient *ctx */
150
    0,		/* ijs_version */
167
    0,		/* ijs_version */
151
    0,          /* krgb_mode */
168
    0,          /* krgb_mode */
169
    0,          /* k_bits */
152
    0,          /* k_path */
170
    0,          /* k_path */
153
    0,          /* k_width */
171
    0,          /* k_width */
154
    0,          /* k_band_size */
172
    0,          /* k_band_size */
Lines 193-199 Link Here
193
      register unsigned char *dest;
211
      register unsigned char *dest;
194
      int dest_start_bit;
212
      int dest_start_bit;
195
      int band_height = ijsdev->k_band_size/raster;
213
      int band_height = ijsdev->k_band_size/raster;
196
      int i,j,x1,y1,w1,h1;
214
      int i,j;
215
      unsigned char *beg = ijsdev->k_band;
216
      unsigned char *end = ijsdev->k_band+ijsdev->k_band_size;
217
      unsigned char *p;
197
218
198
      if (h <= 0 || w <= 0)
219
      if (h <= 0 || w <= 0)
199
         return 0;
220
         return 0;
Lines 202-254 Link Here
202
      if (x >= ijsdev->k_width || y >= band_height)
223
      if (x >= ijsdev->k_width || y >= band_height)
203
         return 0;  /* out-of-band */
224
         return 0;  /* out-of-band */
204
225
205
      /* Check for x clipping. */
226
      dest_start_bit = x & 7;
206
      if (x < 0)
227
      dest=ijsdev->k_band+(raster*y)+(x >> 3);
207
      {
208
         x1 = 0;
209
         w1 = w + x;
210
      }
211
      else if ((x+w) > ijsdev->k_width)
212
      {
213
         x1 = x;
214
         w1 = ijsdev->k_width - x;
215
      }
216
      else
217
      { 
218
         x1 = x;
219
         w1 = w;
220
      }
221
222
      dest_start_bit = x1 & 7;
223
224
      /* Check for y clipping. */
225
      if (y < 0)
226
      {
227
         y1 = 0;
228
         h1 = h + y;
229
      }
230
      else if ((y+h) > band_height)
231
      {
232
         y1 = y;
233
         h1 = band_height - y;
234
      }
235
      else 
236
      {
237
         y1 = y;
238
         h1 = h;
239
      }
240
241
      dest=ijsdev->k_band+(raster*y1)+(x1 >> 3);
242
228
243
      /* Note x,y orgin 0,0 is stored first byte 0 left to right. */
229
      /* Note x,y orgin 0,0 is stored first byte 0 left to right. */
244
230
245
      if (color==0x0)
231
      if (color==0x0)
246
      { 
232
      { 
247
         /* Color is black, store in k plane band instead of regular band. */
233
         /* Color is black, store in k plane band instead of regular band. */
248
         for (j=0; j<h1; j++)
234
         for (j=0; j<h; j++)
249
         {
235
         {
250
            for (i=0; i<w1; i++)
236
            for (i=0; i<w; i++)
251
               dest[(dest_start_bit+i)>>3] |= xmask[(dest_start_bit+i)&7];
237
            {
238
               p = &dest[(dest_start_bit+i)>>3];
239
               if (p >= beg && p <= end)
240
                  *p |= xmask[(dest_start_bit+i)&7];
241
            }
252
            dest+=raster;    
242
            dest+=raster;    
253
         }
243
         }
254
         return 0;
244
         return 0;
Lines 256-265 Link Here
256
      else
246
      else
257
      {
247
      {
258
         /* Color is not black, remove any k plane bits for z-order dependencies, store in regular band. */
248
         /* Color is not black, remove any k plane bits for z-order dependencies, store in regular band. */
259
         for (j=0; j<h1; j++)
249
         for (j=0; j<h; j++)
260
         {
250
         {
261
            for (i=0; i<w1; i++)
251
            for (i=0; i<w; i++)
262
               dest[(dest_start_bit+i)>>3] &= ~xmask[(dest_start_bit+i)&7];
252
            {
253
               p = &dest[(dest_start_bit+i)>>3];
254
               if (p >= beg && p <= end)
255
                  *p &= ~xmask[(dest_start_bit+i)&7];
256
            }
263
            dest+=raster;    
257
            dest+=raster;    
264
         }
258
         }
265
      }
259
      }
Lines 284-290 Link Here
284
      int dest_start_bit;
278
      int dest_start_bit;
285
      int scan_start_bit;
279
      int scan_start_bit;
286
      int band_height = ijsdev->k_band_size/raster;
280
      int band_height = ijsdev->k_band_size/raster;
287
      int i,x1,y1,w1,h1,h=height;
281
      int i,h=height;
282
      unsigned char *beg = ijsdev->k_band;
283
      unsigned char *end = ijsdev->k_band+ijsdev->k_band_size;
284
      unsigned char *p;
288
      
285
      
289
      if (h <= 0 || w <= 0)
286
      if (h <= 0 || w <= 0)
290
         return 0;
287
         return 0;
Lines 293-349 Link Here
293
      if (x >= ijsdev->k_width || y >= band_height)
290
      if (x >= ijsdev->k_width || y >= band_height)
294
         return 0;  /* out-of-band */
291
         return 0;  /* out-of-band */
295
292
296
      /* Check for x clipping. */
297
      if (x < 0)
298
      {
299
         x1 = 0;
300
         w1 = w + x;
301
         /* adj dx here?? */
302
      }
303
      else if ((x+w) > ijsdev->k_width)
304
      {
305
         x1 = x;
306
         w1 = ijsdev->k_width - x;
307
      }
308
      else
309
      { 
310
         x1 = x;
311
         w1 = w;
312
      }
313
314
      scan=data+(dx >> 3);
293
      scan=data+(dx >> 3);
315
      dest_start_bit = x1 & 7;
294
      dest_start_bit = x & 7;
316
      scan_start_bit = dx & 7;
295
      scan_start_bit = dx & 7;
317
296
      dest=ijsdev->k_band+(raster*y)+(x >> 3);
318
      /* Check for y clipping. */
319
      if (y < 0)
320
      {
321
         y1 = 0;
322
         h1 = h + y;
323
         scan+=draster*(h-h1);
324
      }
325
      else if ((y+h) > band_height)
326
      {
327
         y1 = y;
328
         h1 = band_height - y;
329
      }
330
      else 
331
      {
332
         y1 = y;
333
         h1 = h;
334
      }
335
336
      dest=ijsdev->k_band+(raster*y1)+(x1 >> 3);
337
297
338
      if (one==0x0)
298
      if (one==0x0)
339
      {
299
      {
340
         /* Color is black, store in k plane band instead of regular band. */
300
         /* Color is black, store in k plane band instead of regular band. */
341
         while (h1-- > 0)
301
         while (h-- > 0)
342
         {
302
         {
343
            for (i=0; i<w1; i++)
303
            for (i=0; i<w; i++)
344
            {
304
            {
345
               if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
305
               if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
346
                  dest[(dest_start_bit+i)>>3] |= xmask[(dest_start_bit+i)&7];
306
               {
307
                  p = &dest[(dest_start_bit+i)>>3];
308
                  if (p >= beg && p <= end)
309
                     *p |= xmask[(dest_start_bit+i)&7];
310
               }
347
            }
311
            }
348
            scan+=draster;
312
            scan+=draster;
349
            dest+=raster;
313
            dest+=raster;
Lines 353-364 Link Here
353
      else
317
      else
354
      {
318
      {
355
         /* Color is not black, remove any k plane bits for z-order dependencies, store in regular band. */
319
         /* Color is not black, remove any k plane bits for z-order dependencies, store in regular band. */
356
         while (h1-- > 0)
320
         while (h-- > 0)
357
         {
321
         {
358
            for (i=0; i<w1; i++)
322
            for (i=0; i<w; i++)
359
            {
323
            {
360
               if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
324
               if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
361
                  dest[(dest_start_bit+i)>>3] &= ~xmask[(dest_start_bit+i)&7];
325
               {
326
                  p = &dest[(dest_start_bit+i)>>3];
327
                  if (p >= beg && p <= end)
328
                     *p &= ~xmask[(dest_start_bit+i)&7];
329
               }
362
            }
330
            }
363
            scan+=draster;
331
            scan+=draster;
364
            dest+=raster;
332
            dest+=raster;
Lines 479-485 Link Here
479
   return code;
447
   return code;
480
}
448
}
481
449
482
/* See if IJS server supports krgb. Return value: 0=false, 1=true. */
450
/* See if IJS server supports krgb. */
483
private int
451
private int
484
gsijs_set_krgb_mode(gx_device_ijs *ijsdev)
452
gsijs_set_krgb_mode(gx_device_ijs *ijsdev)
485
{
453
{
Lines 487-492 Link Here
487
    int n_chan = ijsdev->color_info.num_components;
455
    int n_chan = ijsdev->color_info.num_components;
488
    int code;
456
    int code;
489
457
458
    ijsdev->krgb_mode = 0;  /* default is no krgb */
459
490
    if (n_chan != 3)
460
    if (n_chan != 3)
491
        return 0;    /* no krgb support, not RGB colorspace */
461
        return 0;    /* no krgb support, not RGB colorspace */
492
462
Lines 494-503 Link Here
494
    code = ijs_client_enum_param(ijsdev->ctx, 0, "ColorSpace", buf, sizeof(buf)-1);
464
    code = ijs_client_enum_param(ijsdev->ctx, 0, "ColorSpace", buf, sizeof(buf)-1);
495
    if (code >= 0)
465
    if (code >= 0)
496
        buf[code] = 0;
466
        buf[code] = 0;
497
    if (strstr(buf, "KRGB") == NULL)
467
    if (strstr(buf, "KRGB") != NULL)
498
        return 0;  /* no krgb support */
468
    {
469
        ijsdev->krgb_mode = 1;     /* yes KRGB is supported */
470
        ijsdev->k_bits = 1;        /* KRGB = 1x8x8x8 */ 
471
    }
472
    else if (strstr(buf, "KxRGB") != NULL)
473
    {
474
        ijsdev->krgb_mode = 1;    /* yes KRGB is supported */
475
        ijsdev->k_bits = 8;       /* KRGB = 8x8x8x8 */
476
    }
499
477
500
    return 1;  /* krgb is supported */
478
    return 0; 
501
}
479
}
502
480
503
/* ------ Private definitions ------ */
481
/* ------ Private definitions ------ */
Lines 852-858 Link Here
852
	code = gsijs_set_margin_params(ijsdev);
830
	code = gsijs_set_margin_params(ijsdev);
853
831
854
    if (code >= 0)
832
    if (code >= 0)
855
        ijsdev->krgb_mode = gsijs_set_krgb_mode(ijsdev);
833
        code = gsijs_set_krgb_mode(ijsdev);
856
834
857
    return code;
835
    return code;
858
}
836
}
Lines 926-931 Link Here
926
    int row_bytes, k_row_bytes=0;
904
    int row_bytes, k_row_bytes=0;
927
    int n_chan = pdev->color_info.num_components;
905
    int n_chan = pdev->color_info.num_components;
928
    int krgb_mode = ijsdev->krgb_mode;
906
    int krgb_mode = ijsdev->krgb_mode;
907
    int k_bits = ijsdev->k_bits;
929
    unsigned char *data;
908
    unsigned char *data;
930
    char buf[256];
909
    char buf[256];
931
    double xres = pdev->HWResolution[0];
910
    double xres = pdev->HWResolution[0];
Lines 966-972 Link Here
966
945
967
    /* This needs to become more sophisticated for DeviceN. */
946
    /* This needs to become more sophisticated for DeviceN. */
968
    strcpy(buf, (n_chan == 4) ? "DeviceCMYK" : 
947
    strcpy(buf, (n_chan == 4) ? "DeviceCMYK" : 
969
	((n_chan == 3) ? (krgb_mode ? "KRGB" : "DeviceRGB") : "DeviceGray"));
948
        ((n_chan == 3) ? (krgb_mode ? ((k_bits == 1) ? "KRGB" : "KxRGB") : "DeviceRGB") : "DeviceGray"));
970
    gsijs_client_set_param(ijsdev, "ColorSpace", buf);
949
    gsijs_client_set_param(ijsdev, "ColorSpace", buf);
971
950
972
    sprintf(buf, "%d", ijs_width);
951
    sprintf(buf, "%d", ijs_width);
(-)src/gdevpdtc.c (-11 / +1 lines)
Lines 653-675 Link Here
653
    if (pdsubf->u.cidfont.glyphshow_font_id != 0)
653
    if (pdsubf->u.cidfont.glyphshow_font_id != 0)
654
 	font0 = (gs_font_type0 *)gs_find_font_by_id(font->dir, 
654
 	font0 = (gs_font_type0 *)gs_find_font_by_id(font->dir, 
655
 		    pdsubf->u.cidfont.glyphshow_font_id, &scaled_font->FontMatrix);
655
 		    pdsubf->u.cidfont.glyphshow_font_id, &scaled_font->FontMatrix);
656
#if 1 /* XXX */
656
    if (font0 == NULL) {
657
    if (font0 == NULL || font0->WMode != scaled_font->WMode) {
658
  	code = gs_font_type0_from_cidfont(&font0, font, scaled_font->WMode,
659
 					  &scale_matrix, font->memory);
660
	if (code < 0)
661
	    return code;
662
 	pdsubf->u.cidfont.glyphshow_font_id = font0->id;
663
 	font0->WMode = scaled_font->WMode; /* should not be here? */
664
    }
665
#else    if (font0 == NULL) {
666
  	code = gs_font_type0_from_cidfont(&font0, font, font->WMode,
657
  	code = gs_font_type0_from_cidfont(&font0, font, font->WMode,
667
 					  &scale_matrix, font->memory);
658
 					  &scale_matrix, font->memory);
668
	if (code < 0)
659
	if (code < 0)
669
	    return code;
660
	    return code;
670
 	pdsubf->u.cidfont.glyphshow_font_id = font0->id;
661
 	pdsubf->u.cidfont.glyphshow_font_id = font0->id;
671
    }
662
    }
672
#endif
673
663
674
    /* Now handle the glyphshow as a show in the Type 0 font. */
664
    /* Now handle the glyphshow as a show in the Type 0 font. */
675
665
(-)src/gdevpdtt.c (-51 lines)
Lines 1802-1812 Link Here
1802
		pwidths->Width.xy.y;
1802
		pwidths->Width.xy.y;
1803
	pwidths->Width.v.x = - pwidths->Width.xy.y / 2;
1803
	pwidths->Width.v.x = - pwidths->Width.xy.y / 2;
1804
	pwidths->Width.v.y = - pwidths->Width.xy.y;
1804
	pwidths->Width.v.y = - pwidths->Width.xy.y;
1805
#if 1 /* XXX */
1806
	/* pwidths->Width.v.y *= 0.84; should use ascent/descent ratio */
1807
	pwidths->Width.v.y *=
1808
		cfont->FontBBox.q.y/(-cfont->FontBBox.p.y+cfont->FontBBox.q.y);
1809
#endif
1810
    } else {
1805
    } else {
1811
	pwidths->Width.xy.x = pwidths->real_width.xy.x =
1806
	pwidths->Width.xy.x = pwidths->real_width.xy.x =
1812
		finfo.MissingWidth * scale_c;
1807
		finfo.MissingWidth * scale_c;
Lines 1885-1923 Link Here
1885
1880
1886
	    if (get_missing_width(cfont, 0, scale_c, &widths1) < 0)
1881
	    if (get_missing_width(cfont, 0, scale_c, &widths1) < 0)
1887
		v.x = 0;
1882
		v.x = 0;
1888
#if 1 /* XXX */	/* Adobe-Japan specific */
1889
#define in_cid(s,e,cid,g) \
1890
    ((gs_min_cid_glyph + cid) <= g && g <= (gs_min_cid_glyph + cid + e - s))
1891
#define Roman(g) in_cid(0x20, 0x7e, 231, g)
1892
#define Hankaku(g) \
1893
    (in_cid(0x20, 0x5f, 231, g) || in_cid(0x60, 0x60, 231, g) || \
1894
     in_cid(0x61, 0x7e, 296, g) || in_cid(0x81, 0x85, 327, g) || \
1895
     in_cid(0x86, 0x8f, 516, g) || in_cid(0x90, 0x90, 342, g) || \
1896
     in_cid(0x91, 0x9f, 526, g) || in_cid(0xa1, 0xdf, 327, g) || \
1897
     in_cid(0xe0, 0xfd, 541, g) || in_cid(0xfe, 0xff, 388, g))
1898
#define Hiragana(g) \
1899
    (in_cid(0x20, 0x20, 515, g) || in_cid(0x21, 0x25, 327, g) || \
1900
     in_cid(0x26, 0x2f, 516, g) || in_cid(0x30, 0x30, 342, g) || \
1901
     in_cid(0x31, 0x5d, 526, g) || in_cid(0x5e, 0x5f, 388, g) || \
1902
     in_cid(0x60, 0x62, 571, g) || in_cid(0x66, 0x7e, 574, g))
1903
1904
#define adobe_japan_ascii(fp, gly) \
1905
    fp->FontType == ft_CID_TrueType && \
1906
    ((gs_font_cid2*)fp)->cidata.common.CIDSystemInfo.Registry.size == 5 && \
1907
    !memcmp(((gs_font_cid2*)fp)->cidata.common.CIDSystemInfo.Registry.data,"Adobe",5) && \
1908
     ((gs_font_cid2*)fp)->cidata.common.CIDSystemInfo.Ordering.size == 6 && \
1909
    !memcmp(((gs_font_cid2*)fp)->cidata.common.CIDSystemInfo.Ordering.data,"Japan1",6) && \
1910
    (Roman(gly) || Hankaku(gly) || Hiragana(gly))
1911
1912
	    else {
1913
		v.x = widths1.Width.w / 2;
1914
		if (adobe_japan_ascii(ofont,glyph))
1915
		    v.x /= 2;
1916
	    }
1917
#else
1918
	    else
1883
	    else
1919
		v.x = widths1.Width.w / 2;
1884
		v.x = widths1.Width.w / 2;
1920
#endif
1921
	} else
1885
	} else
1922
	    v.x = pwidths->Width.v.x;
1886
	    v.x = pwidths->Width.v.x;
1923
    } else if (code < 0)
1887
    } else if (code < 0)
Lines 1939-1959 Link Here
1939
		
1903
		
1940
		if (get_missing_width(cfont, 0, scale_c, &widths1) < 0)
1904
		if (get_missing_width(cfont, 0, scale_c, &widths1) < 0)
1941
		    v.x = 0;
1905
		    v.x = 0;
1942
#if 1 /* XXX */	/* Adobe-Japan specific */
1943
		else {
1944
		    v.x = widths1.Width.w / 2;
1945
		    if (adobe_japan_ascii(ofont,glyph))
1946
			v.x /= 2;
1947
		}
1948
#undef in_cid
1949
#undef Roman
1950
#undef Hankaku
1951
#undef Hiragana
1952
#undef adobe_japan_ascii
1953
#else
1954
		else
1955
		    v.x = widths1.Width.w / 2;
1956
#endif
1957
	    }
1906
	    }
1958
	} else {
1907
	} else {
1959
	    if (info.members  & (GLYPH_INFO_VVECTOR0 << wmode)) {
1908
	    if (info.members  & (GLYPH_INFO_VVECTOR0 << wmode)) {
(-)src/gstype42.c (-53 / +51 lines)
Lines 1-3 Link Here
1
/*
2
 * Modified by AXE,Inc., BBR Inc. and Turbolinux Inc.
3
 *   under the technical advice by suzuki toshiya (Hiroshima University)
4
 * For questions, please send mail to espgs8-cjk@printing-japan.org
5
 *
6
 * (C) Copyright 2006 Center of the International Cooperation for
7
 *     Computerization
8
 */
1
/* Copyright (C) 1996, 2000 Aladdin Enterprises.  All rights reserved.
9
/* Copyright (C) 1996, 2000 Aladdin Enterprises.  All rights reserved.
2
  
10
  
3
  This software is provided AS-IS with no warranty, either express or
11
  This software is provided AS-IS with no warranty, either express or
Lines 146-190 Link Here
146
	    pfont->data.metrics[1].offset = offset;
154
	    pfont->data.metrics[1].offset = offset;
147
	    pfont->data.metrics[1].length = (uint)u32(tab + 12);
155
	    pfont->data.metrics[1].length = (uint)u32(tab + 12);
148
	}
156
	}
149
#if 1 /* XXXX */
150
	else if (!memcmp(tab, "mort", 4)) {
151
	    /* find vertical substitution */
152
	    byte *mort;
153
154
	    ACCESS(offset, 20, mort);	/* length not accurate */
155
	    if ((uint)u32(mort) == 0x00010000) {
156
		int nChains, i;
157
		ulong Chainp = 8;
158
159
		nChains = (int)u32(mort+4);
160
		for (i=1; i <= nChains; i++) {
161
		  int nSub, j;
162
		  ulong Subp;
163
164
		  nSub = U16(mort+Chainp+10);
165
		  Subp = Chainp + U16(mort+Chainp+8)*12 + 12;
166
		  for (j=1; j <= nSub; j++) {
167
		     if ((U16(mort+Subp+2)&7) == 4) {
168
			if ((U16(mort+Subp+8) == 6) &&
169
			    (U16(mort+Subp+10) == 4)) {
170
			  byte *ncgsv;
171
			  int  cnt;
172
			  cnt = U16(mort+Subp+12);
173
			  ACCESS(offset+Subp+20, cnt*4, ncgsv);
174
			  if (!pfont->data.mort_ncgsv_off) {
175
			    pfont->data.mort_ncgsv_off = offset+Subp+20;
176
			    pfont->data.mort_ncgsv_len = cnt*4;
177
			  } else
178
			    dlprintf("multiple ncgsv ignored.\n");
179
			}
180
		     }
181
		     Subp += U16(mort+Subp);
182
		  }
183
		  Chainp += (int)u32(mort+Chainp+4);
184
		}
185
	    }
186
	}
187
#endif
188
    }
157
    }
189
    loca_size >>= pfont->data.indexToLocFormat + 1;
158
    loca_size >>= pfont->data.indexToLocFormat + 1;
190
    pfont->data.numGlyphs = (loca_size == 0 ? 0 : loca_size - 1);
159
    pfont->data.numGlyphs = (loca_size == 0 ? 0 : loca_size - 1);
Lines 206-225 Link Here
206
	pfont->FontBBox.q.x = S16(head_box + 4) / upem;
175
	pfont->FontBBox.q.x = S16(head_box + 4) / upem;
207
	pfont->FontBBox.q.y = S16(head_box + 6) / upem;
176
	pfont->FontBBox.q.y = S16(head_box + 6) / upem;
208
    }
177
    }
209
#if 1 /* XXX */
210
    if (! pfont->data.metrics[1].offset) {
211
	/* no vhea/vmtx
212
	 * shrink/expand the height to 1.0
213
 	 */
214
	float v;
215
	v = - pfont->FontBBox.p.y + pfont->FontBBox.q.y;
216
	    pfont->FontBBox.p.y /= v;
217
	    pfont->FontBBox.q.y /= v;
218
219
	    pfont->FontBBox.p.x /= v;
220
	    pfont->FontBBox.q.x /= v;
221
    }
222
#endif
223
#if NEW_TT_INTERPRETER
178
#if NEW_TT_INTERPRETER
224
    pfont->data.warning_patented = false;
179
    pfont->data.warning_patented = false;
225
    pfont->data.warning_bad_instruction = false;
180
    pfont->data.warning_bad_instruction = false;
Lines 573-578 Link Here
573
			     origin.y + float2fixed(info.width[WMode].y));
528
			     origin.y + float2fixed(info.width[WMode].y));
574
}
529
}
575
530
531
/* Get glyph bounding box from font file */
532
int
533
gs_type42_glyph_fbbox(gs_font *font, uint glyph_index, gs_rect *pbbox)
534
{
535
    gs_font_type42 *const pfont = (gs_font_type42 *)font;
536
    gs_glyph_data_t glyph_data;
537
    double factor = 1.0 / pfont->data.unitsPerEm;
538
    int code = 0;
539
    const byte *gdata;
540
541
    if ((code = pfont->data.get_outline(pfont, glyph_index, &glyph_data)) < 0) {
542
	return code;		/* non-existent glyph */
543
    }
544
    if (glyph_data.bits.size == 0) {
545
	return 1; /* notdef */
546
    }
547
    if (glyph_data.bits.size != 0 && S16(glyph_data.bits.data) == -1) {
548
	/* This is a composite glyph. */
549
	uint flags;
550
	gs_matrix_fixed mat;
551
552
	gdata = glyph_data.bits.data + 10;
553
	memset(&mat, 0, sizeof(mat)); /* arbitrary */
554
	do {
555
	    uint comp_index = U16(gdata + 2);
556
557
	    parse_component(&gdata, &flags, &mat, NULL, pfont, &mat);
558
	    if (flags & TT_CG_USE_MY_METRICS) {
559
		code = gs_type42_glyph_fbbox(pfont, comp_index,pbbox);
560
		goto done;
561
	    }
562
	}
563
	while (flags & TT_CG_MORE_COMPONENTS);
564
    }
565
    gdata = glyph_data.bits.data;
566
    pbbox->p.x = S16(gdata+2)*factor;
567
    pbbox->p.y = S16(gdata+4)*factor;
568
    pbbox->q.x = S16(gdata+6)*factor;
569
    pbbox->q.y = S16(gdata+8)*factor;
570
done:
571
    gs_glyph_data_free(&glyph_data, "gs_type42_enumerate_glyph");
572
    return code;
573
}
576
/* Get glyph info by glyph index. */
574
/* Get glyph info by glyph index. */
577
int
575
int
578
gs_type42_glyph_info_by_gid(gs_font *font, gs_glyph glyph, const gs_matrix *pmat,
576
gs_type42_glyph_info_by_gid(gs_font *font, gs_glyph glyph, const gs_matrix *pmat,
(-)src/gxfont42.h (-7 / +11 lines)
Lines 1-3 Link Here
1
/*
2
 * Modified by AXE,Inc., BBR Inc. and Turbolinux Inc.
3
 *   under the technical advice by suzuki toshiya (Hiroshima University)
4
 * For questions, please send mail to espgs8-cjk@printing-japan.org
5
 *
6
 * (C) Copyright 2006 Center of the International Cooperation for
7
 *     Computerization
8
 */
1
/* Copyright (C) 1996, 2000, 2001 Aladdin Enterprises.  All rights reserved.
9
/* Copyright (C) 1996, 2000, 2001 Aladdin Enterprises.  All rights reserved.
2
  
10
  
3
  This software is provided AS-IS with no warranty, either express or
11
  This software is provided AS-IS with no warranty, either express or
Lines 84-96 Link Here
84
    bool warning_patented;
92
    bool warning_patented;
85
    bool warning_bad_instruction;
93
    bool warning_bad_instruction;
86
#endif
94
#endif
87
#if 1 /* XXXX */
88
    /*
89
     * to find out glyph substitution
90
     */
91
    uint mort_ncgsv_off;	/* vertical substition entry offset */
92
    uint mort_ncgsv_len;	/* total number of bytes (4*#) */
93
#endif
94
};
95
};
95
#define gs_font_type42_common\
96
#define gs_font_type42_common\
96
    gs_font_base_common;\
97
    gs_font_base_common;\
Lines 137-142 Link Here
137
int gs_type42_get_outline_from_TT_file(gs_font_type42 * pfont, stream *s, uint glyph_index,
138
int gs_type42_get_outline_from_TT_file(gs_font_type42 * pfont, stream *s, uint glyph_index,
138
		gs_glyph_data_t *pgd);
139
		gs_glyph_data_t *pgd);
139
140
141
/* Export the function get glypf bounding box from font data */
142
int gs_type42_glyph_fbbox(gs_font *font, uint glyph_index, gs_rect *pbbox);
143
140
/* Export the font procedures so they can be called from the interpreter. */
144
/* Export the font procedures so they can be called from the interpreter. */
141
font_proc_enumerate_glyph(gs_type42_enumerate_glyph);
145
font_proc_enumerate_glyph(gs_type42_enumerate_glyph);
142
font_proc_glyph_info(gs_type42_glyph_info);
146
font_proc_glyph_info(gs_type42_glyph_info);
(-)src/unixinst.mak (+5 lines)
Lines 63-68 Link Here
63
	-mkdir -p $(DESTDIR)$(gsdir)
63
	-mkdir -p $(DESTDIR)$(gsdir)
64
	-mkdir -p $(DESTDIR)$(gsdatadir)
64
	-mkdir -p $(DESTDIR)$(gsdatadir)
65
	-mkdir -p $(DESTDIR)$(gsdatadir)/lib
65
	-mkdir -p $(DESTDIR)$(gsdatadir)/lib
66
	-mkdir -p $(DESTDIR)$(gsdatadir)/lib/cjkv
66
	$(SH) -c 'for f in \
67
	$(SH) -c 'for f in \
67
Fontmap Fontmap.GS cidfmap \
68
Fontmap Fontmap.GS cidfmap \
68
FAPIcidfmap FAPIconfig FAPIfontmap xlatmap \
69
FAPIcidfmap FAPIconfig FAPIfontmap xlatmap \
Lines 88-93 Link Here
88
	$(SH) -c 'for f in $(PSLIBDIR)/*.ppd $(PSLIBDIR)/*.rpd $(PSLIBDIR)/*.upp $(PSLIBDIR)/*.xbm $(PSLIBDIR)/*.xpm;\
89
	$(SH) -c 'for f in $(PSLIBDIR)/*.ppd $(PSLIBDIR)/*.rpd $(PSLIBDIR)/*.upp $(PSLIBDIR)/*.xbm $(PSLIBDIR)/*.xpm;\
89
	do $(INSTALL_DATA) $$f $(install_prefix)$(gsdatadir)/lib ;\
90
	do $(INSTALL_DATA) $$f $(install_prefix)$(gsdatadir)/lib ;\
90
	done'
91
	done'
92
# install cjkv patch
93
	$(SH) -c 'for f in $(PSLIBDIR)/cjkv/*.ps ;\
94
	do $(INSTALL_DATA) $$f $(DESTDIR)$(gsdatadir)/lib/cjkv/ ;\
95
	done'
91
96
92
# install the default resource files
97
# install the default resource files
93
# copy in every category (directory) but CVS
98
# copy in every category (directory) but CVS
(-)src/zcfont.c (-4 lines)
Lines 127-136 Link Here
127
	    if (code < 0)
127
	    if (code < 0)
128
		return code;
128
		return code;
129
	}
129
	}
130
#if 1 /* XXX */
131
	if (scaled_font != root_font)
132
	    scaled_font->WMode = root_font->WMode;	/* need for pdfwrite */
133
#endif
134
	push(3);
130
	push(3);
135
	make_int(op - 2, gs_text_current_char(penum) & 0xff);
131
	make_int(op - 2, gs_text_current_char(penum) & 0xff);
136
	make_real(op - 1, wpt.x);
132
	make_real(op - 1, wpt.x);
(-)src/zchar1.c (-6 / +66 lines)
Lines 1-3 Link Here
1
/*
2
 * Modified by AXE,Inc., BBR Inc. and Turbolinux Inc.
3
 *   under the technical advice by suzuki toshiya (Hiroshima University)
4
 * Based on bugfix by Hideo Saito, 2001.
5
 * For questions, please send mail to espgs8-cjk@printing-japan.org
6
 *
7
 * (C) Copyright 2006 Center of the International Cooperation for
8
 *     Computerization
9
 */
1
/* Copyright (C) 1993, 2000, 2002 Aladdin Enterprises.  All rights reserved.
10
/* Copyright (C) 1993, 2000, 2002 Aladdin Enterprises.  All rights reserved.
2
  
11
  
3
  This software is provided AS-IS with no warranty, either express or
12
  This software is provided AS-IS with no warranty, either express or
Lines 240-245 Link Here
240
	cxs.sbw[2] = 0;
249
	cxs.sbw[2] = 0;
241
	cxs.sbw[3] = -penum->FontBBox_as_Metrics2.x; /* Sic! */
250
	cxs.sbw[3] = -penum->FontBBox_as_Metrics2.x; /* Sic! */
242
	cxs.use_FontBBox_as_Metrics2 = true;
251
	cxs.use_FontBBox_as_Metrics2 = true;
252
	cxs.present = metricsSideBearingAndWidth;
243
    }
253
    }
244
    /* Establish a current point. */
254
    /* Establish a current point. */
245
    code = gs_moveto(igs, 0.0, 0.0);
255
    code = gs_moveto(igs, 0.0, 0.0);
Lines 272-278 Link Here
272
	const ref *opstr = op;
282
	const ref *opstr = op;
273
	ref other_subr;
283
	ref other_subr;
274
284
275
	if (cxs.present == metricsSideBearingAndWidth) {
285
	if (cxs.present == metricsSideBearingAndWidth
286
	    && !cxs.use_FontBBox_as_Metrics2) {
276
	    gs_point sbpt;
287
	    gs_point sbpt;
277
288
278
	    sbpt.x = cxs.sbw[0], sbpt.y = cxs.sbw[1];
289
	    sbpt.x = cxs.sbw[0], sbpt.y = cxs.sbw[1];
Lines 349-359 Link Here
349
    } else {
360
    } else {
350
	/* We have the width and bounding box: */
361
	/* We have the width and bounding box: */
351
	/* set up the cache device now. */
362
	/* set up the cache device now. */
363
        double w[2];
364
        w[0] = pcxs->sbw[2], w[1] = pcxs->sbw[3];
365
      
366
	if (pcxs->use_FontBBox_as_Metrics2) {
367
	   /* In this case, we have to calculate width for WMode=0. 
368
	      pcxs->sbw[2, 3] is width for WMode=1.
369
	      Normally, the width for WMode=0 is not used in WMode=1 
370
	      rendering. However, if CDevProc is defined, 
371
	      the width for WMode=0 is used. 
372
	      Do the same as the case pcxs->present == metricsNone */
373
	     double sbw[4];
374
	     ref cnref;
375
	     ref other_subr;
376
	     int code;
377
	     
378
	    /* Since an OtherSubr callout might change osp, */
379
	    /* save the character name now. */
380
	    ref_assign(&cnref, op - 1);
381
	    code = type1_continue_dispatch(i_ctx_p, pcxs, op, &other_subr, 4);
382
	    op = osp;		/* OtherSubrs might change it */
383
	    switch (code) {
384
 	     default:		/* code < 0 or done, error */
385
		 return ((code < 0 ? code :
386
			 gs_note_error(e_invalidfont)));
387
	    case type1_result_callothersubr:	/* unknown OtherSubr */
388
		return type1_call_OtherSubr(i_ctx_p, pcxs,
389
					    bbox_getsbw_continue,
390
					    &other_subr);
391
	    case type1_result_sbw:	/* [h]sbw, done */
392
		break;
393
	    }
394
	    type1_cis_get_metrics(pcis, sbw);
395
	    w[0] = sbw[2], w[1] = sbw[3];
396
	    /* Now actual width is available, I can calculate much 
397
	       better side bearing for WMode 1 from the width. */
398
	    pcxs->sbw[0] = w[0] / 2;
399
	}
352
 	return zchar_set_cache(i_ctx_p, pbfont, op - 1,
400
 	return zchar_set_cache(i_ctx_p, pbfont, op - 1,
353
			       (pcxs->present == metricsSideBearingAndWidth
401
			       (pcxs->present == metricsSideBearingAndWidth
354
			        && !pcxs->use_FontBBox_as_Metrics2 ?
402
			        && !pcxs->use_FontBBox_as_Metrics2 ?
355
			        pcxs->sbw : NULL),
403
			        pcxs->sbw : NULL),
356
			       pcxs->sbw + 2,
404
			       w,
357
			       &pcxs->char_bbox,
405
			       &pcxs->char_bbox,
358
			       cont, exec_cont, 
406
			       cont, exec_cont, 
359
			       (pcxs->use_FontBBox_as_Metrics2 ? pcxs->sbw : NULL));
407
			       (pcxs->use_FontBBox_as_Metrics2 ? pcxs->sbw : NULL));
Lines 581-587 Link Here
581
    code = type1_exec_init(&cxs.cis, penum, igs, pfont1);
629
    code = type1_exec_init(&cxs.cis, penum, igs, pfont1);
582
    if (code < 0)
630
    if (code < 0)
583
	return code;
631
	return code;
584
    cxs.char_bbox = pfont1->FontBBox;
632
    cxs.char_bbox = bbox;
585
    code = type1exec_bbox(i_ctx_p, &cxs, pfont, exec_cont);
633
    code = type1exec_bbox(i_ctx_p, &cxs, pfont, exec_cont);
586
    return code;
634
    return code;
587
}
635
}
Lines 795-800 Link Here
795
    int code;
843
    int code;
796
    gs_text_enum_t *penum = op_show_find(i_ctx_p);
844
    gs_text_enum_t *penum = op_show_find(i_ctx_p);
797
    gs_font *pfont;
845
    gs_font *pfont;
846
    double w[2];
798
847
799
    if ((code = gs_pathbbox(igs, &pcxs->char_bbox)) < 0 ||
848
    if ((code = gs_pathbbox(igs, &pcxs->char_bbox)) < 0 ||
800
	(code = font_param(op - 3, &pfont)) < 0
849
	(code = font_param(op - 3, &pfont)) < 0
Lines 807-819 Link Here
807
	gs_font_type1 *const pfont1 = (gs_font_type1 *) pfont;
856
	gs_font_type1 *const pfont1 = (gs_font_type1 *) pfont;
808
	op_proc_t cont, exec_cont = 0;
857
	op_proc_t cont, exec_cont = 0;
809
858
810
	if (pcxs->present == metricsNone) {
859
	if (pcxs->present == metricsNone
860
	    || pcxs->use_FontBBox_as_Metrics2) {
811
	    gs_point endpt;
861
	    gs_point endpt;
812
862
813
	    if ((code = gs_currentpoint(igs, &endpt)) < 0)
863
	    if ((code = gs_currentpoint(igs, &endpt)) < 0)
814
		return code;
864
		return code;
815
	    pcxs->sbw[2] = endpt.x, pcxs->sbw[3] = endpt.y;
865
	    /* We will not use sbw[3, 4]. 
866
	       If pcxs->use_FontBBox_as_Metrics2 is true,
867
	       sbw[3, 4] are used as arguments(W1x, W1y) of setcachedevice2. 
868
	       We will use w[0, 1] as W0x and W0y of setcachedevice2.
869
	       W0 and W1 is differrent parameters. Don't confuse. */
870
	    w[0] = endpt.x, w[1] = endpt.y;
816
	    pcxs->present = metricsSideBearingAndWidth;
871
	    pcxs->present = metricsSideBearingAndWidth;
872
	    if (pcxs->use_FontBBox_as_Metrics2) {
873
	      /* Now actual width is available, I can calculate much 
874
		 better side bearing for WMode 1 from the width. */
875
	      pcxs->sbw[0] = w[0] / 2;
876
	    }
817
	}
877
	}
818
	/*
878
	/*
819
	 * We only need to rebuild the path from scratch if we might
879
	 * We only need to rebuild the path from scratch if we might
Lines 830-836 Link Here
830
	} else {
890
	} else {
831
	    cont = (pbfont->PaintType == 0 ? nobbox_fill : nobbox_stroke), exec_cont = 0;
891
	    cont = (pbfont->PaintType == 0 ? nobbox_fill : nobbox_stroke), exec_cont = 0;
832
	    code = zchar_set_cache(i_ctx_p, pbfont, op - 1, NULL,
892
	    code = zchar_set_cache(i_ctx_p, pbfont, op - 1, NULL,
833
				   pcxs->sbw + 2,
893
				    w,
834
				   &pcxs->char_bbox,
894
				   &pcxs->char_bbox,
835
				   cont, &exec_cont,
895
				   cont, &exec_cont,
836
				   (pcxs->use_FontBBox_as_Metrics2 ? pcxs->sbw : NULL));
896
				   (pcxs->use_FontBBox_as_Metrics2 ? pcxs->sbw : NULL));
(-)src/zchar42.c (-3 / +19 lines)
Lines 1-3 Link Here
1
/*
2
 * Modified by AXE,Inc., BBR Inc. and Turbolinux Inc.
3
 *   under the technical advice by suzuki toshiya (Hiroshima University)
4
 * Based on bugfix by Masatake Yamato and Hideo Saito, 2001.
5
 * For questions, please send mail to espgs8-cjk@printing-japan.org
6
 *
7
 * (C) Copyright 2006 Center of the International Cooperation for
8
 *     Computerization
9
 */
1
/* Copyright (C) 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
10
/* Copyright (C) 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
2
  
11
  
3
  This software is provided AS-IS with no warranty, either express or
12
  This software is provided AS-IS with no warranty, either express or
Lines 44-51 Link Here
44
{   double sbw[4];
53
{   double sbw[4];
45
    double w[2];
54
    double w[2];
46
    int present;
55
    int present;
47
    int code = zchar_get_metrics(pbfont, cnref, sbw);
56
    gs_rect bbox, *pbbox;
57
    int code = gs_type42_glyph_fbbox(pbfont, glyph_index, &bbox);
48
58
59
    if (code != 0) {
60
	pbbox = &pbfont->FontBBox;
61
    } else {
62
	pbbox = &bbox;
63
    }
64
    code = zchar_get_metrics(pbfont, cnref, sbw);
49
    if (code < 0)
65
    if (code < 0)
50
	return code;
66
	return code;
51
    present = code;
67
    present = code;
Lines 75-81 Link Here
75
		}
91
		}
76
	    } else {
92
	    } else {
77
		sbw[0] = sbw[2] / 2;
93
		sbw[0] = sbw[2] / 2;
78
		sbw[1] = (pbfont->FontBBox.q.y + pbfont->FontBBox.p.y - sbw42[3]) / 2;
94
		sbw[1] = pbbox->q.y - sbw42[1];
79
		sbw[2] = sbw42[2];
95
		sbw[2] = sbw42[2];
80
		sbw[3] = sbw42[3];
96
		sbw[3] = sbw42[3];
81
	    }
97
	    }
Lines 87-93 Link Here
87
    return zchar_set_cache(i_ctx_p, pbfont, cnref,
103
    return zchar_set_cache(i_ctx_p, pbfont, cnref,
88
			   (put_lsb && present == metricsSideBearingAndWidth ?
104
			   (put_lsb && present == metricsSideBearingAndWidth ?
89
			    sbw : NULL),
105
			    sbw : NULL),
90
			   w, &pbfont->FontBBox,
106
			   w, pbbox,
91
			   cont, exec_cont,
107
			   cont, exec_cont,
92
			   gs_rootfont(igs)->WMode ? sbw : NULL);
108
			   gs_rootfont(igs)->WMode ? sbw : NULL);
93
}
109
}
(-)src/zfcid1.c (-63 lines)
Lines 35-44 Link Here
35
#include "stream.h"
35
#include "stream.h"
36
#include "files.h"
36
#include "files.h"
37
37
38
#if 1 /* XXXX */
39
private uint z11_find_repl_glyph(gs_font_cid2 *, uint);
40
#endif
41
42
/* ---------------- CIDFontType 1 (FontType 10) ---------------- */
38
/* ---------------- CIDFontType 1 (FontType 10) ---------------- */
43
39
44
/* <string|name> <font_dict> .buildfont10 <string|name> <font> */
40
/* <string|name> <font_dict> .buildfont10 <string|name> <font> */
Lines 71-98 Link Here
71
67
72
/* ------ Accessing ------ */
68
/* ------ Accessing ------ */
73
69
74
/* Replace a glyph with a vertical substitution */
75
private uint
76
z11_find_repl_glyph(gs_font_cid2 *pfont, uint glyph)
77
{
78
    int i;
79
    const byte *data;
80
81
    if (pfont->data.mort_ncgsv_off == 0)
82
	return glyph;
83
84
    if ((*pfont->data.string_proc)((gs_font_type42*)pfont,
85
		(ulong)pfont->data.mort_ncgsv_off,
86
		pfont->data.mort_ncgsv_len, &data) == 0) {
87
	for (i=0; i < pfont->data.mort_ncgsv_len; i += 4) {
88
	    if (((data[i]<<8)+data[i+1]) == glyph) {
89
		return (uint)((data[i+2]<<8)+data[i+3]);
90
	    }
91
	}
92
    }
93
    return glyph;
94
}
95
96
/* Map a glyph CID to a TrueType glyph number using the CIDMap. */
70
/* Map a glyph CID to a TrueType glyph number using the CIDMap. */
97
private int
71
private int
98
z11_CIDMap_proc(gs_font_cid2 *pfont, gs_glyph glyph)
72
z11_CIDMap_proc(gs_font_cid2 *pfont, gs_glyph glyph)
Lines 133-175 Link Here
133
    }
107
    }
134
    for (i = 0; i < gdbytes; ++i)
108
    for (i = 0; i < gdbytes; ++i)
135
	gnum = (gnum << 8) + data[i];
109
	gnum = (gnum << 8) + data[i];
136
#if 1 /* XXXX */
137
    if ( gnum != 0 &&
138
	 pfont->cidata.common.CIDSystemInfo.Registry.size == 5 &&
139
	!memcmp(pfont->cidata.common.CIDSystemInfo.Registry.data,"Adobe",5) &&
140
	 pfont->cidata.common.CIDSystemInfo.Ordering.size == 6 &&
141
	!memcmp(pfont->cidata.common.CIDSystemInfo.Ordering.data,"Japan1",6)) {
142
	uint gnum0 = gnum;
143
	  
144
	/* ps string represented in EUC/ShiftJIS are mapped to CID string,
145
	 * while certain characters (e.g. 0xa1c4) are mapped to different CID
146
	 * (668 or 7897) depending on WMode(0 or 1).
147
	 * But, when CID characters are mapped to ShiftJIS/Unicode to get
148
	 * corresponding TTF glyphs, certain CID characters are mapped to
149
	 * glyphs valid for horizonal writing
150
	 * (there is no choice in ShiftJIS encoded TTF), using Resource/CMap
151
	 *
152
	 * Following code maps certain CID (for vertical writing chars)
153
	 * to glyphs for vertical writing regardless of WMode!
154
	 * This automatic mapping enables generating PDF of vertical writing.
155
	 *
156
	 * fixme: range correct?
157
	 */
158
	if (7887 <= cid && cid <= 7960) {
159
	    /* substitute a glyph for vertical writing cid character */
160
	    gnum = z11_find_repl_glyph(pfont, gnum);
161
	}
162
	if (gnum != gnum0) {
163
	    if (gs_debug_c('J'))
164
		dlprintf3("[J]z11_CIDMap_proc(): cid:%d -> %d -> %d\n",
165
				cid, gnum0, gnum);
166
	} else if (gs_debug_c('J')) {
167
	    dlprintf2("[J]z11_CIDMap_proc(): cid:%d -> %d\n", cid, gnum);
168
	}
169
    } else if (gs_debug_c('J')) {
170
	dlprintf2("[J]z11_CIDMap_proc(): cid:%d -> %d\n", cid, gnum);
171
    }
172
#endif
173
    return gnum;
110
    return gnum;
174
}
111
}
175
112

Return to bug 144769