Debian Codegraph @

texk/dvipdfm-x/sfnt.h

raw
1 /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
2
3 Copyright (C) 2002-2020 by Jin-Hwan Cho and Shunsaku Hirata,
4 the dvipdfmx project team.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 */
20
21 #ifndef _SFNT_H_
22 #define _SFNT_H_
23
24 #include "mfileio.h"
25 #include "numbers.h"
26 #include "pdfobj.h"
27
28 /* Avoid conflict with CHAR ... from <winnt.h>. */
29 #define CHAR SFNT_CHAR
30 #define ULONG SFNT_ULONG
31 #define LONG SFNT_LONG
32
33 /* Data Types as described in Apple's TTRefMan */
34 typedef unsigned char BYTE;
35 typedef signed char CHAR;
36 typedef unsigned short USHORT;
37 typedef signed short SHORT;
38 typedef uint32_t ULONG;
39 typedef int32_t LONG;
40 typedef uint32_t Fixed; /* 16.16-bit signed fixed-point number */
41 typedef short FWord;
42 typedef unsigned short uFWord;
43
44 struct sfnt_table
45 {
46 /* table header */
47 char tag[4];
48 ULONG check_sum;
49 ULONG offset;
50 ULONG length;
51 char *data; /* table data */
52 };
53
54 #define SFNT_TABLE_REQUIRED (1 << 0)
55
56 struct sfnt_table_directory
57 {
58 ULONG version; /* Fixed for Win */
59 USHORT num_tables;
60 USHORT search_range;
61 USHORT entry_selector;
62 USHORT range_shift;
63 USHORT num_kept_tables; /* number of kept tables */
64 char *flags; /* keep or omit */
65 struct sfnt_table *tables;
66 };
67
68 /* sfnt resource */
69 #define SFNT_TYPE_TRUETYPE (1 << 0)
70 #define SFNT_TYPE_OPENTYPE (1 << 1)
71 #define SFNT_TYPE_POSTSCRIPT (1 << 2)
72 #define SFNT_TYPE_TTC (1 << 4)
73 #define SFNT_TYPE_DFONT (1 << 8)
74
75 typedef struct
76 {
77 int type;
78 struct sfnt_table_directory *directory;
79 FILE *stream;
80 ULONG offset;
81 } sfnt;
82
83 /* Convert sfnt "fixed" type to double */
84 #define fixed(a) ((double)((a)%0x10000L)/(double)(0x10000L) + \
85 (a)/0x10000L - (((a)/0x10000L > 0x7fffL) ? 0x10000L : 0))
86
87 /* get_***_*** from numbers.h */
88 #define sfnt_get_byte(s) ((BYTE) get_unsigned_byte((s)->stream))
89 #define sfnt_get_char(s) ((CHAR) get_signed_byte ((s)->stream))
90 #define sfnt_get_ushort(s) ((USHORT) get_unsigned_pair((s)->stream))
91 #define sfnt_get_short(s) ((SHORT) get_signed_pair ((s)->stream))
92 #define sfnt_get_ulong(s) ((ULONG) get_unsigned_quad((s)->stream))
93 #define sfnt_get_long(s) ((LONG) get_signed_quad ((s)->stream))
94
95 #define sfnt_get_uint24(s) ((ULONG) get_unsigned_triple((s)->stream))
96
97 #define sfnt_seek_set(s,o) seek_absolute((s)->stream, (o))
98 #define sfnt_read(b,l,s) fread((b), 1, (l), (s)->stream)
99
100 extern int put_big_endian (void *s, LONG q, int n);
101
102 #define sfnt_put_ushort(s,v) put_big_endian((s), v, 2);
103 #define sfnt_put_short(s,v) put_big_endian((s), v, 2);
104 #define sfnt_put_ulong(s,v) put_big_endian((s), v, 4);
105 #define sfnt_put_long(s,v) put_big_endian((s), v, 4);
106
107 extern sfnt *sfnt_open (FILE *fp);
108 extern sfnt *dfont_open (FILE *fp, int index);
109 extern void sfnt_close (sfnt *sfont);
110
111 /* table directory */
112 extern int sfnt_read_table_directory (sfnt *sfont, ULONG offset);
113 extern ULONG sfnt_find_table_len (sfnt *sfont, const char *tag);
114 extern ULONG sfnt_find_table_pos (sfnt *sfont, const char *tag);
115 extern ULONG sfnt_locate_table (sfnt *sfont, const char *tag);
116
117 extern void sfnt_set_table (sfnt *sfont,
118 const char *tag, void *data, ULONG length);
119 extern int sfnt_require_table (sfnt *sfont, const char *tag, int must_exist);
120
121 extern pdf_obj *sfnt_create_FontFile_stream (sfnt *sfont);
122
123 #endif /* _SFNT_H_ */