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/>. */
27 # include <w2c/config.h>
28 # endif /* HAVE_CONFIG_H_ */
30 /* Data Types as described in Apple's TTRefMan */
31 typedef unsigned char BYTE
;
32 typedef signed char ICHAR
;
33 typedef unsigned short USHORT
;
34 typedef signed short SHORT
;
35 typedef unsigned long ULONG
;
36 typedef signed long LONG
;
37 typedef unsigned long Fixed
; /* 16.16-bit signed fixed-point number */
39 typedef unsigned short uFWord
;
40 typedef short F2Dot14
; /* 16-bit signed fixed number with the low 14 bits representing fraction. */
48 char *data
; /* table data */
51 # define SFNT_TABLE_REQUIRED (1 << 0)
53 struct sfnt_table_directory
{
54 ULONG version
; /* Fixed for Win */
57 USHORT entry_selector
;
59 USHORT num_kept_tables
; /* number of kept tables */
60 char *flags
; /* keep or omit */
61 struct sfnt_table
*tables
;
65 # define SFNT_TYPE_TRUETYPE (1 << 0)
66 # define SFNT_TYPE_OPENTYPE (1 << 1)
67 # define SFNT_TYPE_POSTSCRIPT (1 << 2)
68 # define SFNT_TYPE_TTC (1 << 4)
72 struct sfnt_table_directory
*directory
;
76 # elif defined(pdfTeX)
85 /* Convert sfnt "fixed" type to double */
86 # define fixed(a) ((double)((a)%0x10000L)/(double)(0x10000L) + \
87 (a)/0x10000L - (((a)/0x10000L > 0x7fffL) ? 0x10000L : 0))
90 UNSIGNED_BYTE
ft_unsigned_byte(sfnt
* f
);
91 SIGNED_BYTE
ft_signed_byte(sfnt
* f
);
92 UNSIGNED_PAIR
ft_unsigned_pair(sfnt
* f
);
93 SIGNED_PAIR
ft_signed_pair(sfnt
* f
);
94 UNSIGNED_QUAD
ft_unsigned_quad(sfnt
* f
);
95 unsigned long ft_read(unsigned char *buf
, unsigned long len
, sfnt
* f
);
97 # define sfnt_get_byte(s) ((BYTE) ft_unsigned_byte(s))
98 # define sfnt_get_char(s) ((ICHAR) ft_signed_byte (s))
99 # define sfnt_get_ushort(s) ((USHORT) ft_unsigned_pair(s))
100 # define sfnt_get_short(s) ((SHORT) ft_signed_pair (s))
101 # define sfnt_get_ulong(s) ((ULONG) ft_unsigned_quad(s))
102 # define sfnt_get_long(s) ((LONG) ft_signed_quad (s))
104 # define sfnt_seek_set(s,o) (s)->loc = (o)
105 # define sfnt_read(b,l,s) ft_read((b), (l), (s))
106 # elif defined(pdfTeX)
107 BYTE
get_unsigned_byte(sfnt
* f
);
108 ICHAR
get_signed_byte(sfnt
* f
);
109 USHORT
get_unsigned_pair(sfnt
* f
);
110 SHORT
get_signed_pair(sfnt
* f
);
111 ULONG
get_unsigned_quad(sfnt
* f
);
112 int do_sfnt_read(unsigned char *dest
, int len
, sfnt
* f
);
114 # define sfnt_get_byte(s) ((BYTE) get_unsigned_byte(s))
115 # define sfnt_get_char(s) ((ICHAR) get_signed_byte (s))
116 # define sfnt_get_ushort(s) ((USHORT) get_unsigned_pair(s))
117 # define sfnt_get_short(s) ((SHORT) get_signed_pair (s))
118 # define sfnt_get_ulong(s) ((ULONG) get_unsigned_quad(s))
119 # define sfnt_get_long(s) ((LONG) get_signed_quad (s))
121 # define sfnt_seek_set(s,o) (s)->loc = (o)
122 # define sfnt_read(b,l,s) do_sfnt_read((b), (l), (s))
124 /* get_***_*** from numbers.h */
125 # define sfnt_get_byte(s) ((BYTE) get_unsigned_byte((s)->stream))
126 # define sfnt_get_char(s) ((ICHAR) get_signed_byte ((s)->stream))
127 # define sfnt_get_ushort(s) ((USHORT) get_unsigned_pair((s)->stream))
128 # define sfnt_get_short(s) ((SHORT) get_signed_pair ((s)->stream))
129 # define sfnt_get_ulong(s) ((ULONG) get_unsigned_quad((s)->stream))
130 # define sfnt_get_long(s) ((LONG) get_signed_quad ((s)->stream))
132 # define sfnt_seek_set(s,o) seek_absolute((s)->stream, (o))
133 # define sfnt_read(b,l,s) fread((b), 1, (l), (s)->stream)
136 extern int put_big_endian(void *s
, LONG q
, int n
);
138 # define sfnt_put_ushort(s,v) put_big_endian((s), v, 2);
139 # define sfnt_put_short(s,v) put_big_endian((s), v, 2);
140 # define sfnt_put_ulong(s,v) put_big_endian((s), v, 4);
141 # define sfnt_put_long(s,v) put_big_endian((s), v, 4);
144 extern sfnt
*sfnt_open(FT_Face face
, int accept_types
);
145 # elif defined(pdfTeX)
146 extern sfnt
*sfnt_open(unsigned char *buffer
, int buflen
);
148 extern sfnt
*sfnt_open(FILE * fp
);
150 extern void sfnt_close(sfnt
* sfont
);
152 /* table directory */
153 extern int sfnt_read_table_directory(sfnt
* sfont
, ULONG offset
);
154 extern ULONG
sfnt_find_table_len(sfnt
* sfont
, const char *tag
);
155 extern ULONG
sfnt_find_table_pos(sfnt
* sfont
, const char *tag
);
156 extern ULONG
sfnt_locate_table(sfnt
* sfont
, const char *tag
);
158 extern void sfnt_set_table(sfnt
* sfont
,
159 const char *tag
, void *data
, ULONG length
);
160 extern int sfnt_require_table(sfnt
* sfont
, const char *tag
, int must_exist
);
168 # define ASSERT(a) assert(a)
169 # define RELEASE(a) free(a)
170 # define NEW(a,b) xmalloc((unsigned)((unsigned)(a)*sizeof(b)))
171 # define RENEW(a,b,c) xrealloc(a, (unsigned)((unsigned)(b)*sizeof(c)))
175 extern pdf_obj
*sfnt_create_FontFile_stream(sfnt
* sfont
);
177 #endif /* _SFNT_H_ */