-
Notifications
You must be signed in to change notification settings - Fork 1
/
cff_tables.c
274 lines (246 loc) · 11.2 KB
/
cff_tables.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#include "cff_tables.h"
#include <string.h>
#include <stdlib.h>
// static const struct CFF_OPS cffop_##name={#name,value,defval,flags}
#define CFF_OP(name,value,defval,flags) \
{#name,value,defval,flags}
#define CFF_TOPOP(name,value,type,defval) \
CFF_OP(name,value,defval,CFFOP_DICT_TOP|CFFOP_TYPE_##type)
#define CFF_TOPFIOP(name,value,type,defval) \
CFF_OP(name,value,defval,CFFOP_DICT_FONTINFO|CFFOP_TYPE_##type)
#define CFF_PRIVOP(name,value,type,defval) \
CFF_OP(name,value,defval,CFFOP_DICT_PRIV|CFFOP_TYPE_##type)
// values 0..21
static const struct CFF_OPS cff_ops1[]={
CFF_TOPFIOP(version,0,SID,NULL),
CFF_TOPFIOP(Notice,1,SID,NULL),
CFF_TOPFIOP(FullName,2,SID,NULL),
CFF_TOPFIOP(FamilyName,3,SID,NULL),
CFF_TOPFIOP(Weight,4,SID,NULL),
CFF_TOPOP(FontBBox,5,ARRAY,"\x8b\x8b\x8b\x8b"), // 0 0 0 0
CFF_PRIVOP(BlueValues,6,DELTA,NULL),
CFF_PRIVOP(OtherBlues,7,DELTA,NULL),
CFF_PRIVOP(FamilyBlues,8,DELTA,NULL),
CFF_PRIVOP(FamilyOtherBlues,9,DELTA,NULL),
CFF_PRIVOP(StdHW,10,NUMBER,NULL),
CFF_PRIVOP(StdVW,11,NUMBER,NULL),
{NULL}, // 12 is escape
CFF_TOPOP(UniqueID,13,NUMBER,NULL),
CFF_TOPOP(XUID,14,ARRAY,NULL),
CFF_TOPOP(charset,15,NUMBER,"\x8b"),
CFF_TOPOP(Encoding,16,NUMBER,"\x8b"),
CFF_TOPOP(CharStrings,17,NUMBER,NULL),
CFF_TOPOP(Private,18,NUMNUM,NULL),
CFF_PRIVOP(Subrs,19,NUMBER,NULL),
CFF_PRIVOP(defaultWidthX,20,NUMBER,"\x8b"),
CFF_PRIVOP(nominalWidthX,21,NUMBER,"\x8b")
};
// values 0x0c00..0x0c26
static const struct CFF_OPS cff_ops2[]={
CFF_TOPFIOP(Copyright,0x0c00,SID,NULL),
CFF_TOPFIOP(isFixedPitch,0x0c01,BOOL,"\x8b"), // 0 (false)
CFF_TOPFIOP(ItalicAngle,0x0c02,NUMBER,"\x8b"),
CFF_TOPFIOP(UnderlinePosition,0x0c03,NUMBER,"\x27"), // -100
CFF_TOPFIOP(UnderlineThickness,0x0c04,NUMBER,"\xbd"), // 50
CFF_TOPOP(PaintType,0x0c05,NUMBER,"\x8b"),
CFF_TOPOP(CharstringType,0x0c06,NUMBER,"\x8d"), // 2
CFF_TOPOP(FontMatrix,0x0c07,ARRAY,"\x1e\x1c\x3f\x8d\x8d\x1e\x1c\x3f\x8d\x8d"), // 0.001 0 0 0.001 0 0
CFF_TOPOP(StrokeWidth,0x0c08,NUMBER,"\x8b"),
CFF_PRIVOP(BlueScale,0x0c09,NUMBER,"\x1e\xa0\x39\x62\x5f"), // 0.039625
CFF_PRIVOP(BlueShift,0x0c0a,NUMBER,"\x92"), // 7
CFF_PRIVOP(BlueFuzz,0x0c0b,NUMBER,"\x8c"), // 1
CFF_PRIVOP(StemSnapH,0x0c0c,DELTA,NULL),
CFF_PRIVOP(StemSnapV,0x0c0d,DELTA,NULL),
CFF_PRIVOP(ForceBold,0x0c0e,BOOL,"\x8b"),
{NULL},{NULL}, // 0x0c0f, 0x0c10 reserved
CFF_PRIVOP(LanguageGroup,0x0c11,NUMBER,"\x8b"),
CFF_PRIVOP(ExpansionFactor,0x0c12,NUMBER,"\x1e\xa0\x6f"), // 0.06
CFF_PRIVOP(initialRandomSeed,0x0c13,NUMBER,"\x8b"),
CFF_TOPOP(SyntheticBase,0x0c14,NUMBER,NULL),
CFF_TOPOP(PostScript,0x0c15,SID,NULL),
CFF_TOPOP(BaseFontName,0x0c16,SID,NULL),
CFF_TOPOP(BaseFontBlend,0x0c17,DELTA,NULL),
{NULL},{NULL},{NULL},{NULL},{NULL},{NULL}, // 0x0c18..0x0c1d reserved
// CID
CFF_TOPOP(ROS,0x0c1e,SIDSIDNUM,NULL),
CFF_TOPOP(CIDFontVersion,0x0c1f,NUMBER,"\x8b"),
CFF_TOPOP(CIDFontRevision,0x0c20,NUMBER,"\x8b"),
CFF_TOPOP(CIDFontType,0x0c21,NUMBER,"\x8b"),
CFF_TOPOP(CIDCount,0x0c22,NUMBER,"\x1c\x22\x11"), // 8720
CFF_TOPOP(UIDBase,0x0c23,NUMBER,NULL),
CFF_TOPOP(FDArray,0x0c24,NUMBER,NULL),
CFF_TOPOP(FDSelect,0x0c25,NUMBER,NULL),
CFF_TOPOP(FontName,0x0c26,SID,NULL)
};
// sorted by name
static const struct CFF_OPS *cff_opnames[]={
cff_ops2+0x17, // BaseFontBlend
cff_ops2+0x16, // BaseFontName
cff_ops2+0x0b, // BlueFuzz
cff_ops2+0x09, // BlueScale
cff_ops2+0x0a, // BlueShift
cff_ops1+6, // BlueValues
cff_ops2+0x22, // CIDCount
cff_ops2+0x20, // CIDFontRevision
cff_ops2+0x21, // CIDFontType
cff_ops2+0x1f, // CIDFontVersion
cff_ops1+17, // CharStrings
cff_ops2+0x06, // CharstringType
cff_ops2+0x00, // Copyright
cff_ops1+16, // Encoding
cff_ops2+0x12, // ExpansionFactor
cff_ops2+0x24, // FDArray
cff_ops2+0x25, // FDSelect
cff_ops1+8, // FamilyBlues
cff_ops1+3, // FamilyName
cff_ops1+9, // FamilyOtherBlues
cff_ops1+5, // FontBBox
cff_ops2+0x07, // FontMatrix
cff_ops2+0x26, // FontName
cff_ops2+0x0e, // ForceBold
cff_ops1+2, // FullName
cff_ops2+0x02, // ItalicAngle
cff_ops2+0x11, // LanguageGroup
cff_ops1+1, // Notice
cff_ops1+7, // OtherBlues
cff_ops2+0x05, // PaintType
cff_ops2+0x15, // PostScript
cff_ops1+18, // Private
cff_ops2+0x1e, // ROS
cff_ops1+10, // StdHW
cff_ops1+11, // StdVW
cff_ops2+0x0c, // StemSnapH
cff_ops2+0x0d, // StemSnapV
cff_ops2+0x08, // StrokeWidth
cff_ops1+19, // Subrs
cff_ops2+0x14, // SyntheticBase
cff_ops2+0x23, // UIDBase
cff_ops2+0x03, // UnderlinePosition
cff_ops2+0x04, // UnderlineThickness
cff_ops1+13, // UniqueID
cff_ops1+4, // Weight
cff_ops1+14, // XUID
cff_ops1+15, // charset
cff_ops1+20, // defaultWidthX
cff_ops2+0x13, // initialRandomSeed
cff_ops2+0x01, // isFixedPitch
cff_ops1+21, // nominalWidthX
cff_ops1+0 // version
};
const struct CFF_OPS *cffop_get_by_value(int value) // {{{
{
if ( (value>=0)&&(value<sizeof(cff_ops1)/sizeof(*cff_ops1)) ) {
return &cff_ops1[value];
}
value-=0x0c00;
if ( (value>=0)&&(value<sizeof(cff_ops2)/sizeof(*cff_ops2)) ) {
return &cff_ops2[value];
}
return NULL;
}
// }}}
int cffop_cmp(const void *a,const void *b) // {{{
{
const struct CFF_OPS *oa=a;
const struct CFF_OPS *ob=b;
return strcmp(oa->name,ob->name);
}
// }}}
const struct CFF_OPS *cffop_get_by_name(const char *name) // {{{
{
const struct CFF_OPS key={name};
return bsearch(&key,cff_opnames,sizeof(cff_opnames)/sizeof(*cff_opnames),sizeof(key),cffop_cmp);
}
// }}}
static const char *cff_stdstr[]={
".notdef", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand",
"quoteright", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period",
"slash", "zero", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater",
"question", "at", "A", "B", "C", "D", "E", "F",
"G", "H", "I", "J", "K", "L", "M", "N",
"O", "P", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum",
"underscore", "quoteleft", "a", "b", "c", "d", "e", "f",
"g", "h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde",
"exclamdown", "cent", "sterling", "fraction", "yen", "florin", "section", "currency",
"quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl", "endash",
"dagger", "daggerdbl", "peridcentered", "paragraph", "bullet", "quotesinglebase", "quotedblbase", "quotedblright",
"guillemotright", "ellipsis", "perthousand", "questiondown", "grave", "acute", "circumflex", "tilde",
"macron", "breve", "dotaccent", "dieresis", "ring", "cedilla", "hungarumlaut", "ogonek",
"caron", "emdash", "AE", "ordfeminine", "Lslash", "Oslash", "OE", "ordmasculine",
"ae", "dotlessi", "lslash", "oslash", "oe", "germandbls", "onesuperior", "logicalnot",
"mu", "trademark", "Eth", "onehalf", "plusminus", "Thorn", "onequarter", "divide",
"brokenbar", "degree", "thorn", "threequarters", "twosuperior", "registered", "minus", "eth",
"multiply", "threesuperior", "copyright", "Aacute", "Acircumflex", "Adieresis", "Agrave", "Aring",
"Atilde", "Ccedilla", "Eacute", "Ecircumflex", "Edieresis", "Egrave", "Iacute", "Icircumflex",
"Idieresis", "Igrave", "Ntilde", "Oacute", "Ocircumflex", "Odieresis", "Ograve", "Otilde",
"Scaron", "Uacute", "Ucircumflex", "Udieresis", "Ugrave", "Yacute", "Ydieresis", "Zcaron",
"aacute", "acircumflex", "adieresis", "agrave", "aring", "atilde", "ccedilla", "eacute",
"ecircumflex", "edieresis", "egrave", "iacute", "icircumflex", "idieresis", "igrave", "ntilde",
"oacute", "ocircumflex", "odieresis", "ograve", "otilde", "scaron", "uacute", "ucircumflex",
"udieresis", "ugrave", "yacute", "ydieresis", "zcaron", "exclamsmall", "Hungarumlautsmall", "dollaroldstyle",
"dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior",
"parenrightsuperior", "twodotenleader", "onedotenleader", "zerooldstyle",
"oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle",
"nineoldstyle", "commasuperior", "threequartersemdash", "periodsuperior", "questionsmall", "asuperior", "bsuperior", "centsuperior",
"dsuperior", "esuperior", "isuperior", "lsuperior", "msuperior", "nsuperior", "osuperior", "rsuperior",
"ssuperior", "tsuperior", "ff", "ffi", "ffl", "parenleftinferior", "parenrightinferior", "Circumflexsmall",
"hyphensuperior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall",
"Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall",
"Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall",
"Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall",
"exclamdownsmall", "centoldstyle", "Lslashsmall", "Scaronsmall", "Zcaronsmall", "Dieresissmall", "Brevesmall", "Caronsmall",
"Dotaccentsmall", "Macronsmall", "figuredash", "hypheninferior", "Ogoneksmall", "Ringsmall", "Cedillasmall", "questiondownsmall",
"oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothird", "zerosuperior", "foursuperior",
"fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior", "zeroinferior", "oneinferior", "twoinferior",
"threeinferior", "fourinferior", "fiveinferior", "sixinferior", "seveninferior", "eightinferior", "nineinferior", "centinferior",
"dollarinferior", "periodinferior", "commainferior", "Agravesmall", "Aacutesmall", "Acircumflexsmall", "Atildesmall", "Adieresissmall",
"Aringsmall", "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall", "Ecircumflexsmall", "Edieresissmall", "Igravesmall",
"Iacutesmall", "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall", "Ogravesmall", "Oacutesmall", "Ocircumflexsmall",
"Otildesmall", "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall", "Ucircumflexsmall", "Udieresissmall",
"Yacutesmall", "Thornsmall", "Ydieresissmall", "001.000", "001.001", "001.002", "001.003", "Black",
"Bold", "Book", "Light", "Medium", "Regular", "Roman", "Semibold"
};
int cff_pstrcmp(const void *a,const void *b) // {{{
{
const char ** const *pa=a;
const char ** const *pb=b;
return strcmp(**pa,**pb);
}
// }}}
static const char **cff_rev_stdstr[sizeof(cff_stdstr)/sizeof(*cff_stdstr)]={0};
static void init_rev_stdstr() // {{{
{
if (*cff_rev_stdstr) {
return;
}
int iA;
for (iA=0;iA<sizeof(cff_stdstr)/sizeof(*cff_stdstr);iA++) {
cff_rev_stdstr[iA]=cff_stdstr+iA;
}
qsort(cff_rev_stdstr,sizeof(cff_rev_stdstr)/sizeof(*cff_rev_stdstr),sizeof(*cff_rev_stdstr),cff_pstrcmp);
}
// }}}
const char *cff_get_stdstr(int sid) // {{{
{
if ( (sid<0)||(sid>sizeof(cff_stdstr)/sizeof(*cff_stdstr)) ) {
return NULL;
}
return cff_stdstr[sid];
}
// }}}
int cff_find_stdstr(const char *str) // {{{
{
// assert(str);
init_rev_stdstr();
const char **key=&str;
const char ***res=bsearch(&key,cff_rev_stdstr,sizeof(cff_rev_stdstr)/sizeof(*cff_rev_stdstr),sizeof(*cff_rev_stdstr),cff_pstrcmp);
if (!res) {
return -1;
}
return *res-cff_stdstr;
}
// }}}