~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/opentype/ottest.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Pango
 
2
 * otttest.c: Test program for OpenType
 
3
 *
 
4
 * Copyright (C) 2000 Red Hat Software
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 */
 
21
 
 
22
#include <stdio.h>
 
23
#include <stdlib.h>
 
24
 
 
25
#include "ftxopen.h"
 
26
#include <freetype/internal/ftmemory.h>
 
27
 
 
28
#include "disasm.h"
 
29
 
 
30
#define N_ELEMENTS(arr) (sizeof(arr)/ sizeof((arr)[0]))
 
31
 
 
32
int
 
33
croak (const char *situation, FT_Error error)
 
34
{
 
35
  fprintf (stderr, "%s: Error %d\n", situation, error);
 
36
 
 
37
  exit (1);
 
38
}
 
39
 
 
40
enum {
 
41
  I = 1 << 0,
 
42
  M = 1 << 1,
 
43
  F = 1 << 2,
 
44
  L = 1 << 3
 
45
};
 
46
 
 
47
void
 
48
print_tag (FT_ULong tag)
 
49
{
 
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));
 
55
}
 
56
 
 
57
#if 0
 
58
void
 
59
maybe_add_feature (TTO_GSUB  gsub,
 
60
                   FT_UShort script_index,
 
61
                   FT_ULong  tag,
 
62
                   FT_UShort property)
 
63
{
 
64
  FT_Error error;
 
65
  FT_UShort feature_index;
 
66
 
 
67
  /* 0xffff == default language system */
 
68
  error = TT_GSUB_Select_Feature (gsub, tag, script_index, 0xffff, &feature_index);
 
69
 
 
70
  if (error)
 
71
    {
 
72
      if (error == TTO_Err_Not_Covered)
 
73
        {
 
74
          print_tag (tag);
 
75
          fprintf (stderr, " not covered, ignored\n");
 
76
          return;
 
77
        }
 
78
 
 
79
      croak ("TT_GSUB_Select_Feature", error);
 
80
    }
 
81
 
 
82
  if ((error = TT_GSUB_Add_Feature (gsub, feature_index, property)))
 
83
    croak ("TT_GSUB_Add_Feature", error);
 
84
}
 
85
 
 
86
void
 
87
select_cmap (FT_Face face)
 
88
{
 
89
  FT_UShort  i;
 
90
  FT_CharMap cmap = NULL;
 
91
 
 
92
  for (i = 0; i < face->num_charmaps; i++)
 
93
    {
 
94
      if (face->charmaps[i]->platform_id == 3 && face->charmaps[i]->encoding_id == 1)
 
95
        {
 
96
          cmap = face->charmaps[i];
 
97
          break;
 
98
        }
 
99
    }
 
100
 
 
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.                         */
 
103
 
 
104
  if (!cmap)
 
105
    for (i = 0; i < face->num_charmaps; i++)
 
106
      {
 
107
        if (face->charmaps[i]->platform_id == 3 && face->charmaps[i]->encoding_id == 1)
 
108
          {
 
109
            cmap = face->charmaps[i];
 
110
            break;
 
111
          }
 
112
      }
 
113
 
 
114
  if (cmap)
 
115
    FT_Set_Charmap (face, cmap);
 
116
  else
 
117
    {
 
118
      fprintf (stderr, "Sorry, but this font doesn't contain"
 
119
               " any Unicode mapping table.\n");
 
120
      exit (1);
 
121
    }
 
122
}
 
123
 
 
124
void
 
125
add_features (TTO_GSUB gsub)
 
126
{
 
127
  FT_Error error;
 
128
  FT_ULong tag = FT_MAKE_TAG ('a', 'r', 'a', 'b');
 
129
  FT_UShort script_index;
 
130
 
 
131
  error = TT_GSUB_Select_Script (gsub, tag, &script_index);
 
132
 
 
133
  if (error)
 
134
    {
 
135
      if (error == TTO_Err_Not_Covered)
 
136
        {
 
137
          fprintf (stderr, "Arabic not covered, no features used\n");
 
138
          return;
 
139
        }
 
140
 
 
141
      croak ("TT_GSUB_Select_Script", error);
 
142
    }
 
143
 
 
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);
 
148
}
 
149
 
 
150
void
 
151
dump_string (TTO_GSUB_String *str)
 
152
{
 
153
  int i;
 
154
 
 
155
  fprintf (stderr, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
 
156
  for (i = 0; i < (int)str->length; i++)
 
157
    {
 
158
      fprintf (stderr, "%2d: %#01x %#02x %4d %4d\n",
 
159
               i,
 
160
               str->string[i],
 
161
               str->glyph_properties[i].type,
 
162
               str->glyph_properties[i].component,
 
163
               str->character_index[i]);
 
164
    }
 
165
  fprintf (stderr, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
 
166
}
 
167
 
 
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 };
 
170
 
 
171
void
 
172
try_string (FT_Library library,
 
173
            FT_Face    face,
 
174
            TTO_GSUB   gsub)
 
175
{
 
176
  FT_Error error;
 
177
  TTO_GSUB_String *in_str;
 
178
  TTO_GSUB_String *out_str;
 
179
  TTO_GSUB_String *tmp_str;
 
180
  int i;
 
181
 
 
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);
 
188
 
 
189
  if ((error = TT_GSUB_String_Set_Length (in_str, N_ELEMENTS (arabic_str))))
 
190
    croak ("TT_GSUB_String_Set_Length", error);
 
191
 
 
192
  for (i=0; i < (int)N_ELEMENTS (arabic_str); i++)
 
193
    {
 
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;
 
198
    }
 
199
 
 
200
  if ((error = TT_GSUB_Apply_String (gsub, in_str, &out_str, &tmp_str)))
 
201
    croak ("TT_GSUB_Apply_String", error);
 
202
 
 
203
  dump_string (in_str);
 
204
  dump_string (out_str);
 
205
 
 
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);
 
212
}
 
213
#endif
 
214
 
 
215
int
 
216
main (int argc, char **argv)
 
217
{
 
218
  FT_Error error;
 
219
  FT_Library library;
 
220
  FT_Face face;
 
221
  TTO_GSUB gsub;
 
222
  TTO_GPOS gpos;
 
223
 
 
224
  if (argc != 2)
 
225
    {
 
226
      fprintf (stderr, "Usage: ottest MYFONT.TTF\n");
 
227
      exit(1);
 
228
    }
 
229
 
 
230
  if ((error = FT_Init_FreeType (&library)))
 
231
    croak ("FT_Init_FreeType", error);
 
232
 
 
233
  if ((error = FT_New_Face (library, argv[1], 0, &face)))
 
234
    croak ("FT_New_Face", error);
 
235
 
 
236
  printf("----> GSUB <----\n");
 
237
  if (!(error = TT_Load_GSUB_Table (face, &gsub, NULL)))
 
238
    {
 
239
      TT_Dump_GSUB_Table (gsub, stdout);
 
240
 
 
241
      if ((error = TT_Done_GSUB_Table (gsub)))
 
242
        croak ("FT_Done_GSUB_Table", error);
 
243
    }
 
244
  else
 
245
    fprintf (stderr, "TT_Load_GSUB_Table %x\n", error);
 
246
 
 
247
  printf("----> GPOS <----\n");
 
248
  if (!(error = TT_Load_GPOS_Table (face, &gpos, NULL)))
 
249
    {
 
250
      TT_Dump_GPOS_Table (gpos, stdout);
 
251
 
 
252
      if ((error = TT_Done_GPOS_Table (gpos)))
 
253
        croak ("FT_Done_GPOS_Table", error);
 
254
    }
 
255
  else
 
256
    fprintf (stderr, "TT_Load_GPOS_Table %x\n", error);
 
257
 
 
258
#if 0
 
259
  select_cmap (face);
 
260
 
 
261
  add_features (gsub);
 
262
  try_string (library, face, gsub);
 
263
#endif
 
264
 
 
265
 
 
266
  if ((error = FT_Done_Face (face)))
 
267
    croak ("FT_Done_Face", error);
 
268
 
 
269
  if ((error = FT_Done_FreeType (library)))
 
270
    croak ("FT_Done_FreeType", error);
 
271
 
 
272
  return 0;
 
273
}
 
274