1 /* writettf.h
2 
3    Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
4    Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
5 
6    This file is part of LuaTeX.
7 
8    LuaTeX is free software; you can redistribute it and/or modify it under
9    the terms of the GNU General Public License as published by the Free
10    Software Foundation; either version 2 of the License, or (at your
11    option) any later version.
12 
13    LuaTeX is distributed in the hope that it will be useful, but WITHOUT
14    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16    License for more details.
17 
18    You should have received a copy of the GNU General Public License along
19    with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
20 
21 
22 #ifndef WRITETTF_H
23 #  define WRITETTF_H 1
24 typedef signed char TTF_CHAR;
25 typedef unsigned char TTF_BYTE;
26 typedef signed short TTF_SHORT;
27 typedef unsigned short TTF_USHORT;
28 typedef signed long TTF_LONG;
29 typedef unsigned long TTF_ULONG;
30 typedef unsigned long TTF_FIXED;
31 typedef unsigned short TTF_FUNIT;
32 typedef signed short TTF_FWORD;
33 typedef unsigned short TTF_UFWORD;
34 typedef unsigned short TTF_F2DOT14;
35 
36 #  define TTF_CHAR_SIZE    1
37 #  define TTF_BYTE_SIZE    1
38 #  define TTF_SHORT_SIZE   2
39 #  define TTF_USHORT_SIZE  2
40 #  define TTF_LONG_SIZE    4
41 #  define TTF_ULONG_SIZE   4
42 #  define TTF_FIXED_SIZE   4
43 #  define TTF_FWORD_SIZE   2
44 #  define TTF_UFWORD_SIZE  2
45 #  define TTF_F2DOT14_SIZE 2
46 
47 /*
48  * TrueType outline data.
49  */
50 #  define ARG_1_AND_2_ARE_WORDS       (1<<0)
51 #  define ARGS_ARE_XY_VALUES          (1<<1)
52 #  define ROUND_XY_TO_GRID            (1<<2)
53 #  define WE_HAVE_A_SCALE             (1<<3)
54 #  define RESERVED                    (1<<4)
55 #  define MORE_COMPONENTS             (1<<5)
56 #  define WE_HAVE_AN_X_AND_Y_SCALE    (1<<6)
57 #  define WE_HAVE_A_TWO_BY_TWO        (1<<7)
58 #  define WE_HAVE_INSTRUCTIONS        (1<<8)
59 #  define USE_MY_METRICS              (1<<9)
60 
61 #  define get_type(t)     ((t)ttf_getnum(t##_SIZE))
62 #  define ttf_skip(n)     ttf_getnum(n)
63 
64 #  define get_byte()      get_type(TTF_BYTE)
65 #  define get_char()      get_type(TTF_CHAR)
66 #  define get_ushort()    get_type(TTF_USHORT)
67 #  define get_short()     get_type(TTF_SHORT)
68 #  define get_ulong()     get_type(TTF_ULONG)
69 #  define get_long()      get_type(TTF_LONG)
70 #  define get_fixed()     get_type(TTF_FIXED)
71 #  define get_funit()     get_type(TTF_FUNIT)
72 #  define get_fword()     get_type(TTF_FWORD)
73 #  define get_ufword()    get_type(TTF_UFWORD)
74 #  define get_f2dot14()   get_type(TTF_F2DOT14)
75 
76 #  define put_num(t,n)    ((t)ttf_putnum(pdf,t##_SIZE, n))
77 
78 #  define put_char(n)     (void)put_num(TTF_CHAR, n)
79 #  define put_byte(n)     (void)put_num(TTF_BYTE, n)
80 #  define put_short(n)    put_num(TTF_SHORT, n)
81 #  define put_ushort(n)   put_num(TTF_USHORT, n)
82 #  define put_long(n)     put_num(TTF_LONG, n)
83 #  define put_ulong(n)    (void)put_num(TTF_ULONG, n)
84 #  define put_fixed(n)    (void)put_num(TTF_FIXED, n)
85 #  define put_funit(n)    put_num(TTF_FUNIT, n)
86 #  define put_fword(n)    put_num(TTF_FWORD, n)
87 #  define put_ufword(n)   (void)put_num(TTF_UFWORD, n)
88 #  define put_f2dot14(n)  put_num(TTF_F2DOT14, n)
89 
90 #  define copy_byte()     put_byte(get_byte())
91 #  define copy_char()     put_char(get_char())
92 #  define copy_ushort()   put_ushort(get_ushort())
93 #  define copy_short()    put_short(get_short())
94 #  define copy_ulong()    put_ulong(get_ulong())
95 #  define copy_long()     put_long(get_long())
96 #  define copy_fixed()    put_fixed(get_fixed())
97 #  define copy_funit()    put_funit(get_funit())
98 #  define copy_fword()    put_fword(get_fword())
99 #  define copy_ufword()   put_ufword(get_ufword())
100 #  define copy_f2dot14()  put_f2dot14(get_f2dot14())
101 
102 #  define is_unicode_mapping(e) \
103     (e->platform_id == 0 || (e->platform_id == 3 || e->encoding_id == 1))
104 
105 
106 #  define NMACGLYPHS      258
107 #  define TABDIR_OFF      12
108 #  define ENC_BUF_SIZE    1024
109 
110 #  define GLYPH_PREFIX_INDEX    "index"
111 #  define GLYPH_PREFIX_UNICODE  "uni"
112 
113 typedef struct {
114     char tag[4];
115     TTF_ULONG checksum;
116     TTF_ULONG offset;
117     TTF_ULONG length;
118 } dirtab_entry;
119 
120 typedef struct {
121     TTF_USHORT platform_id;
122     TTF_USHORT encoding_id;
123     TTF_ULONG offset;
124     TTF_USHORT format;
125 } cmap_entry;
126 
127 typedef struct {
128     TTF_USHORT endCode;
129     TTF_USHORT startCode;
130     TTF_USHORT idDelta;
131     TTF_USHORT idRangeOffset;
132 } seg_entry;
133 
134 typedef struct {
135     TTF_LONG offset;
136     TTF_LONG newoffset;
137     TTF_UFWORD advWidth;
138     TTF_FWORD lsb;
139     const char *name;           /* name of glyph */
140     TTF_SHORT newindex;         /* new index of glyph in output file */
141     TTF_USHORT name_index;      /* index of name as read from font file */
142 } glyph_entry;
143 
144 /* some functions and variables are used by writetype0.c */
145 
146 extern fd_entry *fd_cur;        /* pointer to the current font descriptor */
147 extern unsigned char *ttf_buffer;
148 extern int ttf_size;
149 extern int ttf_curbyte;
150 extern glyph_entry *glyph_tab;
151 extern dirtab_entry *dir_tab;
152 extern dirtab_entry *ttf_name_lookup(const char *s, boolean required);
153 extern dirtab_entry *ttf_seek_tab(const char *name, TTF_LONG offset);
154 
155 extern void ttf_read_tabdir(void);
156 extern void ttf_read_head(void);
157 extern void ttf_read_hhea(void);
158 extern void ttf_read_pclt(void);
159 extern void ttf_read_post(void);
160 
161 extern FILE *ttf_file;
162 
163 #  define ttf_open(a)      \
164     (ttf_file = fopen((char *) (a), FOPEN_RBIN_MODE))
165 #  define otf_open(a)      \
166     (ttf_file = fopen((char *) (a), FOPEN_RBIN_MODE))
167 #  define ttf_read_file()  \
168     readbinfile(ttf_file,&ttf_buffer,&ttf_size)
169 #  define ttf_close()      xfclose(ttf_file,cur_file_name)
170 #  define ttf_getchar()    ttf_buffer[ttf_curbyte++]
171 #  define ttf_eof()        (ttf_curbyte>ttf_size)
172 
173 extern long ttf_putnum(PDF pdf, int s, long n);
174 extern long ttf_getnum(int s);
175 #endif
176