1 /* Copyright (C) 2001-2006 Artifex Software, Inc.
2 All Rights Reserved.
3
4 This software is provided AS-IS with no warranty, either express or
5 implied.
6
7 This software is distributed under license and may not be copied, modified
8 or distributed except as expressly authorized under the terms of that
9 license. Refer to licensing information at http://www.artifex.com/
10 or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11 San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
12 */
13
14 /* $Id: zfont2.c 9043 2008-08-28 22:48:19Z giles $ */
15 /* Type 2 font creation operators */
16 #include "ghost.h"
17 #include "oper.h"
18 #include "gxfixed.h"
19 #include "gsmatrix.h"
20 #include "gxfont.h"
21 #include "gxfont1.h"
22 #include "bfont.h"
23 #include "idict.h"
24 #include "idparam.h"
25 #include "ifont1.h"
26 #include "ifont2.h"
27 #include "ialloc.h"
28
29 /* Private utilities */
30 static uint
subr_bias(const ref * psubrs)31 subr_bias(const ref * psubrs)
32 {
33 uint size = r_size(psubrs);
34
35 return (size < 1240 ? 107 : size < 33900 ? 1131 : 32768);
36 }
37
38 /*
39 * Get the additional parameters for a Type 2 font (or FontType 2 FDArray
40 * entry in a CIDFontType 0 font), beyond those common to Type 1 and Type 2
41 * fonts.
42 */
43 int
type2_font_params(const_os_ptr op,charstring_font_refs_t * pfr,gs_type1_data * pdata1)44 type2_font_params(const_os_ptr op, charstring_font_refs_t *pfr,
45 gs_type1_data *pdata1)
46 {
47 int code;
48 float dwx, nwx;
49 ref *temp;
50
51 pdata1->interpret = gs_type2_interpret;
52 pdata1->lenIV = DEFAULT_LENIV_2;
53 pdata1->subroutineNumberBias = subr_bias(pfr->Subrs);
54 /* Get information specific to Type 2 fonts. */
55 if (dict_find_string(pfr->Private, "GlobalSubrs", &temp) > 0) {
56 if (!r_is_array(temp))
57 return_error(e_typecheck);
58 pfr->GlobalSubrs = temp;
59 }
60 pdata1->gsubrNumberBias = subr_bias(pfr->GlobalSubrs);
61 if ((code = dict_uint_param(pfr->Private, "gsubrNumberBias",
62 0, max_uint, pdata1->gsubrNumberBias,
63 &pdata1->gsubrNumberBias)) < 0 ||
64 (code = dict_float_param(pfr->Private, "defaultWidthX", 0.0,
65 &dwx)) < 0 ||
66 (code = dict_float_param(pfr->Private, "nominalWidthX", 0.0,
67 &nwx)) < 0
68 )
69 return code;
70 pdata1->defaultWidthX = float2fixed(dwx);
71 pdata1->nominalWidthX = float2fixed(nwx);
72 {
73 ref *pirs;
74
75 if (dict_find_string(pfr->Private, "initialRandomSeed", &pirs) <= 0)
76 pdata1->initialRandomSeed = 0;
77 else if (!r_has_type(pirs, t_integer))
78 return_error(e_typecheck);
79 else
80 pdata1->initialRandomSeed = pirs->value.intval;
81 }
82 return 0;
83 }
84
85 /* <string|name> <font_dict> .buildfont2 <string|name> <font> */
86 /* Build a type 2 (compact Adobe encrypted) font. */
87 static int
zbuildfont2(i_ctx_t * i_ctx_p)88 zbuildfont2(i_ctx_t *i_ctx_p)
89 {
90 os_ptr op = osp;
91 charstring_font_refs_t refs;
92 build_proc_refs build;
93 int code = build_proc_name_refs(imemory, &build,
94 "%Type2BuildChar", "%Type2BuildGlyph");
95 gs_type1_data data1;
96
97 if (code < 0)
98 return code;
99 code = charstring_font_get_refs(op, &refs);
100 if (code < 0)
101 return code;
102 code = type2_font_params(op, &refs, &data1);
103 if (code < 0)
104 return code;
105 return build_charstring_font(i_ctx_p, op, &build, ft_encrypted2, &refs,
106 &data1, bf_notdef_required);
107 }
108
109 /* ------ Initialization procedure ------ */
110
111 const op_def zfont2_op_defs[] =
112 {
113 {"2.buildfont2", zbuildfont2},
114 op_def_end(0)
115 };
116