1 /* Copyright (C) 1991, 1995, 1996, 1997, 1998, 1999 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: zfont2.c,v 1.7 2004/08/04 19:36:13 stefan Exp $ */
18 /* Type 2 font creation operators */
19 #include "ghost.h"
20 #include "oper.h"
21 #include "gxfixed.h"
22 #include "gsmatrix.h"
23 #include "gxfont.h"
24 #include "gxfont1.h"
25 #include "bfont.h"
26 #include "idict.h"
27 #include "idparam.h"
28 #include "ifont1.h"
29 #include "ifont2.h"
30 #include "ialloc.h"
31
32 /* Private utilities */
33 private uint
subr_bias(const ref * psubrs)34 subr_bias(const ref * psubrs)
35 {
36 uint size = r_size(psubrs);
37
38 return (size < 1240 ? 107 : size < 33900 ? 1131 : 32768);
39 }
40
41 /*
42 * Get the additional parameters for a Type 2 font (or FontType 2 FDArray
43 * entry in a CIDFontType 0 font), beyond those common to Type 1 and Type 2
44 * fonts.
45 */
46 int
type2_font_params(const_os_ptr op,charstring_font_refs_t * pfr,gs_type1_data * pdata1)47 type2_font_params(const_os_ptr op, charstring_font_refs_t *pfr,
48 gs_type1_data *pdata1)
49 {
50 int code;
51 float dwx, nwx;
52 ref *temp;
53
54 pdata1->interpret = gs_type2_interpret;
55 pdata1->lenIV = DEFAULT_LENIV_2;
56 pdata1->subroutineNumberBias = subr_bias(pfr->Subrs);
57 /* Get information specific to Type 2 fonts. */
58 if (dict_find_string(pfr->Private, "GlobalSubrs", &temp) > 0) {
59 if (!r_is_array(temp))
60 return_error(e_typecheck);
61 pfr->GlobalSubrs = temp;
62 }
63 pdata1->gsubrNumberBias = subr_bias(pfr->GlobalSubrs);
64 if ((code = dict_uint_param(pfr->Private, "gsubrNumberBias",
65 0, max_uint, pdata1->gsubrNumberBias,
66 &pdata1->gsubrNumberBias)) < 0 ||
67 (code = dict_float_param(pfr->Private, "defaultWidthX", 0.0,
68 &dwx)) < 0 ||
69 (code = dict_float_param(pfr->Private, "nominalWidthX", 0.0,
70 &nwx)) < 0
71 )
72 return code;
73 pdata1->defaultWidthX = float2fixed(dwx);
74 pdata1->nominalWidthX = float2fixed(nwx);
75 {
76 ref *pirs;
77
78 if (dict_find_string(pfr->Private, "initialRandomSeed", &pirs) <= 0)
79 pdata1->initialRandomSeed = 0;
80 else if (!r_has_type(pirs, t_integer))
81 return_error(e_typecheck);
82 else
83 pdata1->initialRandomSeed = pirs->value.intval;
84 }
85 return 0;
86 }
87
88 /* <string|name> <font_dict> .buildfont2 <string|name> <font> */
89 /* Build a type 2 (compact Adobe encrypted) font. */
90 private int
zbuildfont2(i_ctx_t * i_ctx_p)91 zbuildfont2(i_ctx_t *i_ctx_p)
92 {
93 os_ptr op = osp;
94 charstring_font_refs_t refs;
95 build_proc_refs build;
96 int code = build_proc_name_refs(imemory, &build,
97 "%Type2BuildChar", "%Type2BuildGlyph");
98 gs_type1_data data1;
99
100 if (code < 0)
101 return code;
102 code = charstring_font_get_refs(op, &refs);
103 if (code < 0)
104 return code;
105 code = type2_font_params(op, &refs, &data1);
106 if (code < 0)
107 return code;
108 return build_charstring_font(i_ctx_p, op, &build, ft_encrypted2, &refs,
109 &data1, bf_notdef_required);
110 }
111
112 /* ------ Initialization procedure ------ */
113
114 const op_def zfont2_op_defs[] =
115 {
116 {"2.buildfont2", zbuildfont2},
117 op_def_end(0)
118 };
119