3 Copyright 2002 by Jin-Hwan Cho and Shunsaku Hirata,
4 the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
5 Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
7 This file is part of LuaTeX.
9 LuaTeX is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2 of the License, or (at your
12 option) any later version.
14 LuaTeX is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 License for more details.
19 You should have received a copy of the GNU General Public License along
20 with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
23 #ifndef _CFF_LIMITS_H_
24 # define _CFF_LIMITS_H_
28 # define CFF_INT_MAX 0x7fffffff
29 # define CFF_INT_MIN (-0x7fffffff - 1)
31 # if (LONG_MAX < CFF_INT_MAX || LONG_MIN > CFF_INT_MIN)
32 # error "CFF support won't work on this system."
35 # define CFF_SID_MAX 64999
36 # define CFF_STDSTR_MAX 391
38 /* Type 2 Charstring */
39 # define CS_NUM_SUBR_MAX 65536
40 # define CS_STR_LEN_MAX 65536
41 # define CS_STEM_ZONE_MAX 96
42 # define CS_ARG_STACK_MAX 48
43 # define CS_TRANS_ARRAY_MAX 32
44 # define CS_SUBR_NEST_MAX 10
46 #endif /* _CFF_LIMITS_H_ */
49 # define _CFF_TYPES_H_
53 # define CFF_TYPE_UNKNOWN 0
54 # define CFF_TYPE_INTEGER (1 << 0)
55 # define CFF_TYPE_REAL (1 << 1)
56 # define CFF_TYPE_NUMBER (CFF_TYPE_INTEGER|CFF_TYPE_REAL)
57 # define CFF_TYPE_BOOLEAN (1 << 2)
58 # define CFF_TYPE_SID (1 << 3)
59 # define CFF_TYPE_ARRAY (1 << 4)
60 # define CFF_TYPE_DELTA (1 << 5)
63 # define CFF_TYPE_ROS (1 << 6)
65 # define CFF_TYPE_OFFSET (1 << 7)
67 # define CFF_TYPE_SZOFF (1 << 8)
69 typedef unsigned char card8
; /* 1-byte unsigned number */
70 typedef unsigned short card16
; /* 2-byte unsigned number */
71 typedef unsigned char c_offsize
; /* 1-byte unsigned number specifies the size
72 of an Offset field or fields, range 1-4 */
73 typedef unsigned long l_offset
; /* 1, 2, 3, or 4-byte offset */
74 typedef unsigned short s_SID
; /* 2-byte string identifier */
76 typedef unsigned long l_size
;
79 card16 count
; /* number of objects stored in INDEX */
80 c_offsize offsize
; /* Offset array element size, 1-4 */
81 l_offset
*offset
; /* Offset array, count + 1 offsets */
82 card8
*data
; /* Object data */
88 int id
; /* encoded data value (as card8 or card16) */
89 const char *key
; /* opname */
90 int count
; /* number of values */
91 double *values
; /* values */
97 cff_dict_entry
*entries
;
100 /* Encoding, Charset and FDSelect */
102 s_SID first
; /* SID or CID, or card8 for Encoding */
103 card8 n_left
; /* no. of remaining gids/codes in this range */
107 s_SID first
; /* SID or CID (card16) */
108 card16 n_left
; /* card16-version of range1 */
117 card8 format
; /* if (format & 0x80) then have supplement */
118 card8 num_entries
; /* number of entries */
120 card8
*codes
; /* format 0 */
121 cff_range1
*range1
; /* format 1 */
123 card8 num_supps
; /* number of supplementary data */
124 cff_map
*supp
; /* supplement */
131 s_SID
*glyphs
; /* format 0 */
132 cff_range1
*range1
; /* format 1 */
133 cff_range2
*range2
; /* format 2 */
137 /* CID-Keyed font specific */
145 card16 num_entries
; /* number of glyphs/ranges */
147 card8
*fds
; /* format 0 */
148 cff_range3
*ranges
; /* format 3 */
150 /* card16 sentinel; *//* format 3 only, must be equals to num_glyphs */
153 #endif /* _CFF_TYPES_H_ */
155 #ifndef _CFF_STDSTR_H_
156 # define _CFF_STDSTR_H_
158 # define CFF_STDSTR_MAX 391
160 extern const char *const cff_stdstr
[];
161 #endif /* _CFF_STDSTR_H_ */
166 /*#include "mfileio.h"*/
169 # define FONTTYPE_CIDFONT (1 << 0)
170 # define FONTTYPE_FONT (1 << 1)
171 # define FONTTYPE_MMASTER (1 << 2)
173 # define ENCODING_STANDARD (1 << 3)
174 # define ENCODING_EXPERT (1 << 4)
176 # define CHARSETS_ISOADOBE (1 << 5)
177 # define CHARSETS_EXPERT (1 << 6)
178 # define CHARSETS_EXPSUB (1 << 7)
180 # define HAVE_STANDARD_ENCODING (ENCODING_STANDARD|ENCODING_EXPERT)
181 # define HAVE_STANDARD_CHARSETS \
182 (CHARSETS_ISOADOBE|CHARSETS_EXPERT|CHARSETS_EXPSUB)
184 # define CFF_STRING_NOTDEF 65535
187 char *fontname
; /* FontName */
189 /* - CFF structure - */
191 card8 header_major
; /* major version */
192 card8 header_minor
; /* minor version */
193 card8 header_hdr_size
; /* Header size (bytes) */
194 c_offsize header_offsize
; /* Absolute offset (0) size */
196 cff_index
*name
; /* Name INDEX */
197 cff_dict
*topdict
; /* Top DICT (single) */
198 cff_index
*string
; /* String INDEX */
199 cff_index
*gsubr
; /* Global Subr INDEX */
200 cff_encoding
*encoding
; /* Encodings */
201 cff_charsets
*charsets
; /* Charsets */
202 cff_fdselect
*fdselect
; /* FDSelect, CIDFont only */
203 cff_index
*cstrings
; /* CharStrings */
204 cff_dict
**fdarray
; /* CIDFont only */
205 cff_dict
**private; /* per-Font DICT */
206 cff_index
**subrs
; /* Local Subr INDEX, per-Private DICT */
208 /* -- extra data -- */
209 l_offset gsubr_offset
;
210 card16 num_glyphs
; /* number of glyphs (CharString INDEX count) */
211 card8 num_fds
; /* number of Font DICT */
213 /* Updated String INDEX.
214 * Please fix this. We should separate input and output.
218 unsigned char *stream
;
220 l_offset stream_size
;
222 int index
; /* CFF fontset index */
223 int flag
; /* Flag: see above */
226 extern cff_font
*cff_open(unsigned char *stream
, long stream_size
, int n
);
227 extern void cff_close(cff_font
* cff
);
229 # define cff_seek_set(c, p) seek_absolute (((c)->stream), ((c)->offset) + (p));
232 extern long cff_put_header(cff_font
* cff
, card8
* dest
, long destlen
);
235 extern cff_index
*cff_get_index(cff_font
* cff
);
236 extern cff_index
*cff_get_index_header(cff_font
* cff
);
237 extern void cff_release_index(cff_index
* idx
);
238 extern cff_index
*cff_new_index(card16 count
);
239 extern long cff_index_size(cff_index
* idx
);
240 extern long cff_pack_index(cff_index
* idx
, card8
* dest
, long destlen
);
243 extern char *cff_get_name(cff_font
* cff
);
244 extern long cff_set_name(cff_font
* cff
, char *name
);
246 /* Global and Local Subrs INDEX */
247 extern long cff_read_subrs(cff_font
* cff
);
250 extern long cff_read_encoding(cff_font
* cff
);
251 extern long cff_pack_encoding(cff_font
* cff
, card8
* dest
, long destlen
);
252 extern card16
cff_encoding_lookup(cff_font
* cff
, card8 code
);
253 extern void cff_release_encoding(cff_encoding
* encoding
);
256 extern long cff_read_charsets(cff_font
* cff
);
257 extern long cff_pack_charsets(cff_font
* cff
, card8
* dest
, long destlen
);
259 /* Returns GID of PS name "glyph" */
260 extern card16
cff_glyph_lookup(cff_font
* cff
, const char *glyph
);
261 /* Returns GID of glyph with SID/CID "cid" */
262 extern card16
cff_charsets_lookup(cff_font
* cff
, card16 cid
);
263 extern void cff_release_charsets(cff_charsets
* charset
);
264 /* Returns SID or CID */
265 extern card16
cff_charsets_lookup_inverse(cff_font
* cff
, card16 gid
);
268 extern long cff_read_fdselect(cff_font
* cff
);
269 extern long cff_pack_fdselect(cff_font
* cff
, card8
* dest
, long destlen
);
270 extern card8
cff_fdselect_lookup(cff_font
* cff
, card16 gid
);
271 extern void cff_release_fdselect(cff_fdselect
* fdselect
);
274 extern long cff_read_fdarray(cff_font
* cff
);
276 /* Private DICT(s) */
277 extern long cff_read_private(cff_font
* cff
);
280 extern int cff_match_string(cff_font
* cff
, const char *str
, s_SID sid
);
281 extern char *cff_get_string(cff_font
* cff
, s_SID id
);
282 extern long cff_get_sid(cff_font
* cff
, const char *str
);
283 extern s_SID
cff_add_string(cff_font
* cff
, const char *str
);
284 extern void cff_update_string(cff_font
* cff
);
286 # define cff_is_stdstr(s) (cff_get_sid(NULL, (s)) >= 0)
291 # define _CFF_DICT_H_
293 # define CFF_CIDCOUNT_DEFAULT 8720
294 # define CFF_NOMINALWIDTHX_DEFAULT 0.0
295 # define CFF_DEFAULTWIDTHX_DEFAULT 0.0
297 extern cff_dict
*cff_new_dict(void);
298 extern void cff_release_dict(cff_dict
* dict
);
300 extern void cff_dict_set(cff_dict
* dict
, const char *key
, int idx
,
302 extern double cff_dict_get(cff_dict
* dict
, const char *key
, int idx
);
303 extern void cff_dict_add(cff_dict
* dict
, const char *key
, int count
);
304 extern void cff_dict_remove(cff_dict
* dict
, const char *key
);
305 extern int cff_dict_known(cff_dict
* dict
, const char *key
);
307 /* decode/encode DICT */
308 extern cff_dict
*cff_dict_unpack(card8
* data
, card8
* endptr
);
309 extern long cff_dict_pack(cff_dict
* dict
, card8
* dest
, long destlen
);
311 extern void cff_dict_update(cff_dict
* dict
, cff_font
* cff
);
313 #endif /* _CFF_DICT_H_ */
316 # define _CS_TYPE2_H_
319 int flags
; /* unused in Type 2 charstring */
322 double llx
, lly
, urx
, ury
;
325 double asb
, adx
, ady
;
327 } seac
; /* unused in Type 2 charstring */
330 extern long cs_copy_charstring(card8
* dest
, long destlen
,
331 card8
* src
, long srclen
,
332 cff_index
* gsubr
, cff_index
* subr
,
333 double default_width
, double nominal_width
,
335 #endif /* _CS_TYPE2_H_ */
337 #define cff_is_cidfont(a) (a->flag & FONTTYPE_CIDFONT)
338 #define cff_understandable(a) (a->header_major==1)
340 extern cff_font
*read_cff(unsigned char *buf
, long buflength
, int subf
);
342 extern void write_cff(PDF pdf
, cff_font
* cff
, fd_entry
* fd
);
343 extern void write_cid_cff(PDF pdf
, cff_font
* cffont
, fd_entry
* fd
);