~ubuntu-branches/ubuntu/karmic/pango1.0/karmic-security

« back to all changes in this revision

Viewing changes to pango/opentype/harfbuzz-dump-main.c

Tags: upstream-1.15.4
ImportĀ upstreamĀ versionĀ 1.15.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* harfbuzz-dump-main.c: Test program for OpenType
 
2
 *
 
3
 * Copyright (C) 2000 Red Hat Software
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Library General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Library General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Library General Public
 
16
 * License along with this library; if not, write to the
 
17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
 * Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include <stdio.h>
 
22
#include <stdlib.h>
 
23
 
 
24
#include "harfbuzz-open.h"
 
25
 
 
26
#include "harfbuzz-dump.h"
 
27
 
 
28
#define N_ELEMENTS(arr) (sizeof(arr)/ sizeof((arr)[0]))
 
29
 
 
30
static int
 
31
croak (const char *situation, FT_Error error)
 
32
{
 
33
  fprintf (stderr, "%s: Error %d\n", situation, error);
 
34
 
 
35
  exit (1);
 
36
}
 
37
 
 
38
#if 0
 
39
enum {
 
40
  I = 1 << 0,
 
41
  M = 1 << 1,
 
42
  F = 1 << 2,
 
43
  L = 1 << 3
 
44
};
 
45
 
 
46
static void
 
47
print_tag (FT_ULong tag)
 
48
{
 
49
  fprintf (stderr, "%c%c%c%c", 
 
50
          (unsigned char)(tag >> 24),
 
51
          (unsigned char)((tag >> 16) & 0xff),
 
52
          (unsigned char)((tag >> 8) & 0xff),
 
53
          (unsigned char)(tag & 0xff));
 
54
}
 
55
 
 
56
static void
 
57
maybe_add_feature (HB_GSUB  gsub,
 
58
                   FT_UShort script_index,
 
59
                   FT_ULong  tag,
 
60
                   FT_UShort property)
 
61
{
 
62
  FT_Error error;
 
63
  FT_UShort feature_index;
 
64
  
 
65
  /* 0xffff == default language system */
 
66
  error = HB_GSUB_Select_Feature (gsub, tag, script_index, 0xffff, &feature_index);
 
67
  
 
68
  if (error)
 
69
    {
 
70
      if (error == HB_Err_Not_Covered)
 
71
        {
 
72
          print_tag (tag);
 
73
          fprintf (stderr, " not covered, ignored\n");
 
74
          return;
 
75
        }
 
76
 
 
77
      croak ("HB_GSUB_Select_Feature", error);
 
78
    }
 
79
 
 
80
  if ((error = HB_GSUB_Add_Feature (gsub, feature_index, property)))
 
81
    croak ("HB_GSUB_Add_Feature", error);
 
82
}
 
83
 
 
84
static void
 
85
select_cmap (FT_Face face)
 
86
{
 
87
  FT_UShort  i;
 
88
  FT_CharMap cmap = NULL;
 
89
  
 
90
  for (i = 0; i < face->num_charmaps; i++)
 
91
    {
 
92
      if (face->charmaps[i]->platform_id == 3 && face->charmaps[i]->encoding_id == 1)
 
93
        {
 
94
          cmap = face->charmaps[i];
 
95
          break;
 
96
        }
 
97
    }
 
98
  
 
99
  /* we try only pid/eid (0,0) if no (3,1) map is found -- many Windows
 
100
     fonts have only rudimentary (0,0) support.                         */
 
101
 
 
102
  if (!cmap)
 
103
    for (i = 0; i < face->num_charmaps; i++)
 
104
      {
 
105
        if (face->charmaps[i]->platform_id == 3 && face->charmaps[i]->encoding_id == 1)
 
106
          {
 
107
            cmap = face->charmaps[i];
 
108
            break;
 
109
          }
 
110
      }
 
111
 
 
112
  if (cmap)
 
113
    FT_Set_Charmap (face, cmap);
 
114
  else
 
115
    {
 
116
      fprintf (stderr, "Sorry, but this font doesn't contain"
 
117
               " any Unicode mapping table.\n");
 
118
      exit (1);
 
119
    }
 
120
}
 
121
 
 
122
static void
 
123
add_features (HB_GSUB gsub)
 
124
{
 
125
  FT_Error error;
 
126
  FT_ULong tag = FT_MAKE_TAG ('a', 'r', 'a', 'b');
 
127
  FT_UShort script_index;
 
128
 
 
129
  error = HB_GSUB_Select_Script (gsub, tag, &script_index);
 
130
 
 
131
  if (error)
 
132
    {
 
133
      if (error == HB_Err_Not_Covered)
 
134
        {
 
135
          fprintf (stderr, "Arabic not covered, no features used\n");
 
136
          return;
 
137
        }
 
138
 
 
139
      croak ("HB_GSUB_Select_Script", error);
 
140
    }
 
141
 
 
142
  maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('i', 'n', 'i', 't'), I);
 
143
  maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('m', 'e', 'd', 'i'), M);
 
144
  maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('f', 'i', 'n', 'a'), F);
 
145
  maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('l', 'i', 'g', 'a'), L);
 
146
}
 
147
#endif
 
148
 
 
149
#if 0
 
150
void 
 
151
dump_string (HB_GSUB_String *str)
 
152
{
 
153
  FT_ULong i;
 
154
 
 
155
  fprintf (stderr, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
 
156
  for (i = 0; i < str->length; i++)
 
157
    {
 
158
      fprintf (stderr, "%2lu: %#06x %#06x %4d %4d\n",
 
159
               i,
 
160
               str->string[i],
 
161
               str->properties[i],
 
162
               str->components[i],
 
163
               str->ligIDs[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
            HB_GSUB   gsub)
 
175
{
 
176
  FT_Error error;
 
177
  HB_GSUB_String *in_str;
 
178
  HB_GSUB_String *out_str;
 
179
  FT_ULong i;
 
180
 
 
181
  if ((error = HB_GSUB_String_New (face->memory, &in_str)))
 
182
    croak ("HB_GSUB_String_New", error);
 
183
  if ((error = HB_GSUB_String_New (face->memory, &out_str)))
 
184
    croak ("HB_GSUB_String_New", error);
 
185
 
 
186
  if ((error = HB_GSUB_String_Set_Length (in_str, N_ELEMENTS (arabic_str))))
 
187
    croak ("HB_GSUB_String_Set_Length", error);
 
188
 
 
189
  for (i=0; i < N_ELEMENTS (arabic_str); i++)
 
190
    {
 
191
      in_str->string[i] = FT_Get_Char_Index (face, arabic_str[i]);
 
192
      in_str->properties[i] = arabic_props[i];
 
193
      in_str->components[i] = i;
 
194
      in_str->ligIDs[i] = i;
 
195
    }
 
196
 
 
197
  if ((error = HB_GSUB_Apply_String (gsub, in_str, out_str)))
 
198
    croak ("HB_GSUB_Apply_String", error);
 
199
 
 
200
  dump_string (in_str);
 
201
  dump_string (out_str);
 
202
 
 
203
  if ((error = HB_GSUB_String_Done (in_str)))
 
204
    croak ("HB_GSUB_String_New", error);
 
205
  if ((error = HB_GSUB_String_Done (out_str)))
 
206
    croak ("HB_GSUB_String_New", error);
 
207
}
 
208
#endif
 
209
 
 
210
int 
 
211
main (int argc, char **argv)
 
212
{
 
213
  FT_Error error;
 
214
  FT_Library library;
 
215
  FT_Face face;
 
216
  HB_GSUB gsub;
 
217
  HB_GPOS gpos;
 
218
 
 
219
  if (argc != 2)
 
220
    {
 
221
      fprintf (stderr, "Usage: ottest MYFONT.TTF\n");
 
222
      exit(1);
 
223
    }
 
224
 
 
225
  if ((error = FT_Init_FreeType (&library)))
 
226
    croak ("FT_Init_FreeType", error);
 
227
 
 
228
  if ((error = FT_New_Face (library, argv[1], 0, &face)))
 
229
    croak ("FT_New_Face", error);
 
230
 
 
231
  printf ("<?xml version=\"1.0\"?>\n");
 
232
  printf ("<OpenType>\n");
 
233
 
 
234
  if (!(error = HB_Load_GSUB_Table (face, &gsub, NULL)))
 
235
    {
 
236
      HB_Dump_GSUB_Table (gsub, stdout);
 
237
      
 
238
      if ((error = HB_Done_GSUB_Table (gsub)))
 
239
        croak ("HB_Done_GSUB_Table", error);
 
240
    }
 
241
  else if (error != FT_Err_Table_Missing)
 
242
    fprintf (stderr, "HB_Load_GSUB_Table %x\n", error);
 
243
 
 
244
  if (!(error = HB_Load_GPOS_Table (face, &gpos, NULL)))
 
245
    {
 
246
      HB_Dump_GPOS_Table (gpos, stdout);
 
247
      
 
248
      if ((error = HB_Done_GPOS_Table (gpos)))
 
249
        croak ("HB_Done_GPOS_Table", error);
 
250
    }
 
251
  else if (error != FT_Err_Table_Missing)
 
252
    fprintf (stderr, "HB_Load_GPOS_Table %x\n", error);
 
253
 
 
254
  printf ("</OpenType>\n");
 
255
 
 
256
#if 0  
 
257
  select_cmap (face);
 
258
 
 
259
  add_features (gsub);
 
260
  try_string (library, face, gsub);
 
261
#endif
 
262
 
 
263
 
 
264
  if ((error = FT_Done_Face (face)))
 
265
    croak ("FT_Done_Face", error);
 
266
 
 
267
  if ((error = FT_Done_FreeType (library)))
 
268
    croak ("FT_Done_FreeType", error);
 
269
  
 
270
  return 0;
 
271
}
 
272