2
* otttest.c: Test program for OpenType
4
* Copyright (C) 2000 Red Hat Software
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library 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 GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU Library General Public
17
* License along with this library; if not, write to the
18
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
26
#include <freetype/internal/ftmemory.h>
30
#define N_ELEMENTS(arr) (sizeof(arr)/ sizeof((arr)[0]))
33
croak (const char *situation, FT_Error error)
35
fprintf (stderr, "%s: Error %d\n", situation, error);
48
print_tag (FT_ULong tag)
50
fprintf (stderr, "%c%c%c%c",
51
(unsigned char)(tag >> 24),
52
(unsigned char)((tag & 0xff0000) >> 16),
53
(unsigned char)((tag & 0xff00) >> 8),
54
(unsigned char)(tag & 0xff));
59
maybe_add_feature (TTO_GSUB gsub,
60
FT_UShort script_index,
65
FT_UShort feature_index;
67
/* 0xffff == default language system */
68
error = TT_GSUB_Select_Feature (gsub, tag, script_index, 0xffff, &feature_index);
72
if (error == TTO_Err_Not_Covered)
75
fprintf (stderr, " not covered, ignored\n");
79
croak ("TT_GSUB_Select_Feature", error);
82
if ((error = TT_GSUB_Add_Feature (gsub, feature_index, property)))
83
croak ("TT_GSUB_Add_Feature", error);
87
select_cmap (FT_Face face)
90
FT_CharMap cmap = NULL;
92
for (i = 0; i < face->num_charmaps; i++)
94
if (face->charmaps[i]->platform_id == 3 && face->charmaps[i]->encoding_id == 1)
96
cmap = face->charmaps[i];
101
/* we try only pid/eid (0,0) if no (3,1) map is found -- many Windows
102
fonts have only rudimentary (0,0) support. */
105
for (i = 0; i < face->num_charmaps; i++)
107
if (face->charmaps[i]->platform_id == 3 && face->charmaps[i]->encoding_id == 1)
109
cmap = face->charmaps[i];
115
FT_Set_Charmap (face, cmap);
118
fprintf (stderr, "Sorry, but this font doesn't contain"
119
" any Unicode mapping table.\n");
125
add_features (TTO_GSUB gsub)
128
FT_ULong tag = FT_MAKE_TAG ('a', 'r', 'a', 'b');
129
FT_UShort script_index;
131
error = TT_GSUB_Select_Script (gsub, tag, &script_index);
135
if (error == TTO_Err_Not_Covered)
137
fprintf (stderr, "Arabic not covered, no features used\n");
141
croak ("TT_GSUB_Select_Script", error);
144
maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('i', 'n', 'i', 't'), I);
145
maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('m', 'e', 'd', 'i'), M);
146
maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('f', 'i', 'n', 'a'), F);
147
maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('l', 'i', 'g', 'a'), L);
151
dump_string (TTO_GSUB_String *str)
155
fprintf (stderr, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
156
for (i = 0; i < (int)str->length; i++)
158
fprintf (stderr, "%2d: %#01x %#02x %4d %4d\n",
161
str->glyph_properties[i].type,
162
str->glyph_properties[i].component,
163
str->character_index[i]);
165
fprintf (stderr, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
168
FT_UShort arabic_str[] = { 0x645, 0x643, 0x64a, 0x644, 0x639, 0x20, 0x645, 0x627, 0x644, 0x633, 0x644, 0x627 };
169
FT_UShort arabic_props[] = { I|L, M|L, M|L, M|L, M|L, F|L, I|L, M|L, M|L, M|L, M|L, F|L };
172
try_string (FT_Library library,
177
TTO_GSUB_String *in_str;
178
TTO_GSUB_String *out_str;
179
TTO_GSUB_String *tmp_str;
182
if ((error = TT_GSUB_String_New (face->memory, &in_str)))
183
croak ("TT_GSUB_String_New", error);
184
if ((error = TT_GSUB_String_New (face->memory, &out_str)))
185
croak ("TT_GSUB_String_New", error);
186
if ((error = TT_GSUB_String_New (face->memory, &tmp_str)))
187
croak ("TT_GSUB_String_New", error);
189
if ((error = TT_GSUB_String_Set_Length (in_str, N_ELEMENTS (arabic_str))))
190
croak ("TT_GSUB_String_Set_Length", error);
192
for (i=0; i < (int)N_ELEMENTS (arabic_str); i++)
194
in_str->string[i] = FT_Get_Char_Index (face, arabic_str[i]);
195
in_str->properties[i] = arabic_props[i];
196
in_str->components[i] = i;
197
in_str->ligIDs[i] = i;
200
if ((error = TT_GSUB_Apply_String (gsub, in_str, &out_str, &tmp_str)))
201
croak ("TT_GSUB_Apply_String", error);
203
dump_string (in_str);
204
dump_string (out_str);
206
if ((error = TT_GSUB_String_Done (in_str)))
207
croak ("TT_GSUB_String_New", error);
208
if ((error = TT_GSUB_String_Done (out_str)))
209
croak ("TT_GSUB_String_New", error);
210
if ((error = TT_GSUB_String_Done (tmp_str)))
211
croak ("TT_GSUB_String_New", error);
216
main (int argc, char **argv)
226
fprintf (stderr, "Usage: ottest MYFONT.TTF\n");
230
if ((error = FT_Init_FreeType (&library)))
231
croak ("FT_Init_FreeType", error);
233
if ((error = FT_New_Face (library, argv[1], 0, &face)))
234
croak ("FT_New_Face", error);
236
printf("----> GSUB <----\n");
237
if (!(error = TT_Load_GSUB_Table (face, &gsub, NULL)))
239
TT_Dump_GSUB_Table (gsub, stdout);
241
if ((error = TT_Done_GSUB_Table (gsub)))
242
croak ("FT_Done_GSUB_Table", error);
245
fprintf (stderr, "TT_Load_GSUB_Table %x\n", error);
247
printf("----> GPOS <----\n");
248
if (!(error = TT_Load_GPOS_Table (face, &gpos, NULL)))
250
TT_Dump_GPOS_Table (gpos, stdout);
252
if ((error = TT_Done_GPOS_Table (gpos)))
253
croak ("FT_Done_GPOS_Table", error);
256
fprintf (stderr, "TT_Load_GPOS_Table %x\n", error);
262
try_string (library, face, gsub);
266
if ((error = FT_Done_Face (face)))
267
croak ("FT_Done_Face", error);
269
if ((error = FT_Done_FreeType (library)))
270
croak ("FT_Done_FreeType", error);