Debian Codegraph @

texk/web2c/luatexdir/font/sfnt.h

raw
1 /* sfnt.h
2
3 Copyright 2002 by Jin-Hwan Cho and Shunsaku Hirata,
4 the dvipdfmx project team <[email protected]>
5 Copyright 2006-2008 Taco Hoekwater <[email protected]>
6
7 This file is part of LuaTeX.
8
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.
13
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.
18
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/>. */
21
22
23 #ifndef _SFNT_H_
24 # define _SFNT_H_
25
26 # if HAVE_CONFIG_H
27 # include <w2c/config.h>
28 # endif /* HAVE_CONFIG_H_ */
29
30 /* Data Types as described in Apple's TTRefMan */
31
32 /*typedef unsigned char BYTE;*/ /* defined in pdfgen.h */
33 typedef signed char ICHAR;
34 typedef unsigned short USHORT;
35 typedef signed short SHORT;
36 /*typedef unsigned long ULONG;*//* defined in pdfgen.h */
37 typedef signed long LONG;
38 typedef unsigned long Fixed; /* 16.16-bit signed fixed-point number */
39 typedef short FWord;
40 typedef unsigned short uFWord;
41 typedef short F2Dot14; /* 16-bit signed fixed number with the low 14 bits representing fraction. */
42
43 struct sfnt_table {
44 /* table header */
45 char tag[4];
46 ULONG check_sum;
47 ULONG offset;
48 ULONG length;
49 char *data; /* table data */
50 };
51
52 # define SFNT_TABLE_REQUIRED (1 << 0)
53
54 struct sfnt_table_directory {
55 ULONG version; /* Fixed for Win */
56 USHORT num_tables;
57 USHORT search_range;
58 USHORT entry_selector;
59 USHORT range_shift;
60 USHORT num_kept_tables; /* number of kept tables */
61 char *flags; /* keep or omit */
62 struct sfnt_table *tables;
63 };
64
65 /* sfnt resource */
66 # define SFNT_TYPE_TRUETYPE (1 << 0)
67 # define SFNT_TYPE_OPENTYPE (1 << 1)
68 # define SFNT_TYPE_POSTSCRIPT (1 << 2)
69 # define SFNT_TYPE_TTC (1 << 4)
70
71 typedef struct {
72 int type;
73 struct sfnt_table_directory *directory;
74 BYTE *buffer;
75 long buflen;
76 long loc;
77 } sfnt;
78
79 /* Convert sfnt "fixed" type to double */
80
81 # define fixed(a) ((double)((a)%0x10000L)/(double)(0x10000L) + \
82 (a)/0x10000L - (((a)/0x10000L > 0x7fffL) ? 0x10000L : 0))
83
84 BYTE get_unsigned_byte(sfnt * f);
85 ICHAR get_signed_byte(sfnt * f);
86 USHORT get_unsigned_pair(sfnt * f);
87 SHORT get_signed_pair(sfnt * f);
88 ULONG get_unsigned_quad(sfnt * f);
89 int do_sfnt_read(unsigned char *dest, int len, sfnt * f);
90
91 #define sfnt_get_byte(s) ((BYTE) get_unsigned_byte(s))
92 #define sfnt_get_char(s) ((ICHAR) get_signed_byte (s))
93 #define sfnt_get_ushort(s) ((USHORT) get_unsigned_pair(s))
94 #define sfnt_get_short(s) ((SHORT) get_signed_pair (s))
95 #define sfnt_get_ulong(s) ((ULONG) get_unsigned_quad(s))
96 #define sfnt_get_long(s) ((LONG) get_signed_quad (s))
97
98 #define sfnt_seek_set(s,o) (s)->loc = (o)
99 #define sfnt_read(b,l,s) do_sfnt_read((b), (l), (s))
100
101 extern int put_big_endian(void *s, LONG q, int n);
102
103 #define sfnt_put_ushort(s,v) put_big_endian((s), v, 2);
104 #define sfnt_put_short(s,v) put_big_endian((s), v, 2);
105 #define sfnt_put_ulong(s,v) put_big_endian((s), v, 4);
106 #define sfnt_put_long(s,v) put_big_endian((s), v, 4);
107
108 extern sfnt *sfnt_open(unsigned char *buffer, int buflen);
109 extern void sfnt_close(sfnt * sfont);
110
111 /* table directory */
112
113 extern int sfnt_read_table_directory(sfnt * sfont, ULONG offset);
114 extern ULONG sfnt_find_table_len(sfnt * sfont, const char *tag);
115 extern ULONG sfnt_find_table_pos(sfnt * sfont, const char *tag);
116 extern ULONG sfnt_locate_table(sfnt * sfont, const char *tag);
117
118 extern void sfnt_set_table(sfnt * sfont,
119 const char *tag, void *data, ULONG length);
120 extern int sfnt_require_table(sfnt * sfont, const char *tag, int must_exist);
121
122 #define ASSERT(a) assert(a)
123 #define RELEASE(a) free(a)
124 #define NEW(a,b) xmalloc((unsigned)((unsigned)(a)*sizeof(b)))
125 #define RENEW(a,b,c) xrealloc(a, (unsigned)((unsigned)(b)*sizeof(c)))
126
127 extern pdf_obj *sfnt_create_FontFile_stream(sfnt * sfont);
128
129 #endif /* _SFNT_H_ */