1 /* Copyright (C) 2002 Aladdin Enterprises. All rights reserved.
2
3 This software is provided AS-IS with no warranty, either express or
4 implied.
5
6 This software is distributed under license and may not be copied,
7 modified or distributed except as expressly authorized under the terms
8 of the license contained in the file LICENSE in this distribution.
9
10 For more information about licensing, please refer to
11 http://www.ghostscript.com/licensing/. For information on
12 commercial licensing, go to http://www.artifex.com/licensing/ or
13 contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 San Rafael, CA 94903, U.S.A., +1(415)492-9861.
15 */
16
17 /* $Id: zcidtest.c,v 1.3 2003/05/22 15:41:03 igor Exp $ */
18 /* Operators for testing CIDFont and CMap facilities */
19 #include "string_.h"
20 #include "ghost.h"
21 #include "gxfont.h"
22 #include "gxfont0c.h"
23 #include "gdevpsf.h"
24 #include "stream.h"
25 #include "spprint.h"
26 #include "oper.h"
27 #include "files.h"
28 #include "idict.h"
29 #include "ifont.h"
30 #include "igstate.h"
31 #include "iname.h"
32 #include "store.h"
33
34 /* - .wrapfont - */
35 private int
zwrapfont(i_ctx_t * i_ctx_p)36 zwrapfont(i_ctx_t *i_ctx_p)
37 {
38 gs_font *font = gs_currentfont(igs);
39 gs_font_type0 *font0;
40 int wmode = 0;
41 int code;
42
43 switch (font->FontType) {
44 case ft_TrueType:
45 code = gs_font_type0_from_type42(&font0, (gs_font_type42 *)font, wmode,
46 true, font->memory);
47 if (code < 0)
48 return code;
49 /*
50 * Patch up BuildChar and CIDMap. This isn't necessary for
51 * TrueType fonts in general, only for Type 42 fonts whose
52 * BuildChar is implemented in PostScript code.
53 */
54 {
55 font_data *pdata = pfont_data(font);
56 const char *bgstr = "%Type11BuildGlyph";
57 ref temp;
58
59 make_int(&temp, 0);
60 ref_assign(&pdata->u.type42.CIDMap, &temp);
61 code = name_ref((const byte *)bgstr, strlen(bgstr), &temp, 1);
62 if (code < 0)
63 return code;
64 r_set_attrs(&temp, a_executable);
65 ref_assign(&pdata->BuildGlyph, &temp);
66 }
67 break;
68 case ft_CID_encrypted:
69 case ft_CID_user_defined:
70 case ft_CID_TrueType:
71 code = gs_font_type0_from_cidfont(&font0, font, wmode, NULL,
72 font->memory);
73 break;
74 default:
75 return_error(e_rangecheck);
76 }
77 if (code < 0)
78 return code;
79 gs_setfont(igs, (gs_font *)font0);
80 return 0;
81 }
82
83 /* <file> <cmap> .writecmap - */
84 private int
zfcmap_put_name_default(stream * s,const byte * str,uint size)85 zfcmap_put_name_default(stream *s, const byte *str, uint size)
86 {
87 stream_putc(s, '/');
88 stream_write(s, str, size);
89 return 0;
90 }
91 private int
zwritecmap(i_ctx_t * i_ctx_p)92 zwritecmap(i_ctx_t *i_ctx_p)
93 {
94 os_ptr op = osp;
95 ref *pcodemap;
96 gs_cmap_t *pcmap;
97 int code;
98 stream *s;
99
100 check_type(*op, t_dictionary);
101 if (dict_find_string(op, "CodeMap", &pcodemap) <= 0 ||
102 !r_is_struct(pcodemap)
103 )
104 return_error(e_typecheck);
105 check_write_file(s, op - 1);
106 pcmap = r_ptr(pcodemap, gs_cmap_t);
107 code = psf_write_cmap(s, pcmap, zfcmap_put_name_default, NULL, -1);
108 if (code >= 0)
109 pop(2);
110 return code;
111 }
112
113 /* <file> <cid9font> .writefont9 - */
114 private int
zwritefont9(i_ctx_t * i_ctx_p)115 zwritefont9(i_ctx_t *i_ctx_p)
116 {
117 os_ptr op = osp;
118 gs_font *pfont;
119 gs_font_cid0 *pfcid;
120 int code = font_param(op, &pfont);
121 stream *s;
122
123 if (code < 0)
124 return code;
125 if (pfont->FontType != ft_CID_encrypted)
126 return_error(e_invalidfont);
127 check_write_file(s, op - 1);
128 pfcid = (gs_font_cid0 *)pfont;
129 code = psf_write_cid0_font(s, pfcid,
130 WRITE_TYPE2_NO_LENIV | WRITE_TYPE2_CHARSTRINGS,
131 NULL, 0, NULL);
132 if (code >= 0)
133 pop(2);
134 return code;
135 }
136
137 /* ------ Initialization procedure ------ */
138
139 const op_def zcidtest_op_defs[] =
140 {
141 {"1.wrapfont", zwrapfont},
142 {"2.writecmap", zwritecmap},
143 {"2.writefont9", zwritefont9},
144 op_def_end(0)
145 };
146