Debian Codegraph @

texk/xdvipsk/otflib/sfnt.h

raw
1 /* This is xdvipsk, an eXtended version of dvips(k) by Tomas Rokicki.
2
3 Copyright (C) 2016 by VTeX Ltd (www.vtex.lt),
4 the xdvipsk project team - Sigitas Tolusis and Arunas Povilaitis.
5
6 Program original code copyright (C) 2007-2014 by Jin-Hwan Cho and
7 Shunsaku Hirata, the dvipdfmx project team.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 */
23
24 #ifndef _SFNT_H_
25 #define _SFNT_H_
26
27 #include "mfileio.h"
28 #include "numbers.h"
29
30 /* Acoid conflict with CHAR from <winnt.h>. */
31 #define CHAR SFNT_CHAR
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 unsigned long ULONG;
39 typedef signed long LONG;
40 typedef unsigned long Fixed; /* 16.16-bit signed fixed-point number */
41 typedef short FWord;
42 typedef unsigned short uFWord;
43 typedef short F2Dot14; /* 16-bit signed fixed number with the low
44 14 bits representing fraction. */
45
46 struct sfnt_table
47 {
48 /* table header */
49 char tag[4];
50 ULONG check_sum;
51 ULONG offset;
52 ULONG length;
53 char *data; /* table data */
54 };
55
56 #define SFNT_TABLE_REQUIRED (1 << 0)
57
58 struct sfnt_table_directory
59 {
60 ULONG version; /* Fixed for Win */
61 USHORT num_tables;
62 USHORT search_range;
63 USHORT entry_selector;
64 USHORT range_shift;
65 USHORT num_kept_tables; /* number of kept tables */
66 char *flags; /* keep or omit */
67 struct sfnt_table *tables;
68 };
69
70 /* sfnt resource */
71 #define SFNT_TYPE_TRUETYPE (1 << 0)
72 #define SFNT_TYPE_OPENTYPE (1 << 1)
73 #define SFNT_TYPE_POSTSCRIPT (1 << 2)
74 #define SFNT_TYPE_TTC (1 << 4)
75 #define SFNT_TYPE_DFONT (1 << 8)
76
77 typedef struct
78 {
79 int type;
80 struct sfnt_table_directory *directory;
81 FILE *stream;
82 ULONG offset;
83 } sfnt;
84
85 /* Convert sfnt "fixed" type to double */
86 #define fixed(a) ((double)((a)%0x10000L)/(double)(0x10000L) + \
87 (a)/0x10000L - (((a)/0x10000L > 0x7fffL) ? 0x10000L : 0))
88
89 /* get_***_*** from numbers.h */
90 #define sfnt_get_byte(s) ((BYTE) get_unsigned_byte((s)->stream))
91 #define sfnt_get_char(s) ((CHAR) get_signed_byte ((s)->stream))
92 #define sfnt_get_ushort(s) ((USHORT) get_unsigned_pair((s)->stream))
93 #define sfnt_get_short(s) ((SHORT) get_signed_pair ((s)->stream))
94 #define sfnt_get_ulong(s) ((ULONG) get_unsigned_quad((s)->stream))
95 #define sfnt_get_long(s) ((LONG) get_signed_quad ((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 long sfnt_make_fontfile (sfnt *sfont, BYTE **buffer);
122
123 #endif /* _SFNT_H_ */