ApwFreetypeLibrary

Check-in [7dfcd6bfd2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:initial version.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:7dfcd6bfd28fdac662efacc68d41976e4e4c894e
User & Date: arnulf 2014-12-31 14:38:29
Context
2015-01-02
10:59
fixes. Leaf check-in: 7af4a1e516 user: arnulf tags: trunk
2014-12-31
14:38
initial version. check-in: 7dfcd6bfd2 user: arnulf tags: trunk
14:38
fixes. check-in: 41da7c263e user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added fttruetype/TTFaceFuncs.java.





























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package fttruetype;

import android.util.Log;

  /* ===================================================================== */
  /*    TTFaceFuncs                                                        */
  /*                                                                       */
  /* ===================================================================== */

public class TTFaceFuncs extends ftbase.FTDebug {
    private static int oid = 0;
    
    public final static Long TTAG_true = (long)('t' << 24 | 'r' << 16 | 'u' << 8 | 'e');

    private int id;
    private static String TAG = "TTFaceFuncs";
    
    /* ==================== TTFaceFuncs ================================== */
    public TTFaceFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * <Function>
     *    tt_face_init
     *
     * <Description>
     *    Initialize a given TrueType face object.
     *
     * <Input>
     *    stream     :: The source font stream.
     *
     *    face_index :: The index of the font face in the resource.
     *
     *    num_params :: Number of additional generic parameters.  Ignored.
     *
     *    params     :: Additional generic parameters.  Ignored.
     *
     * <InOut>
     *    face       :: The newly built face object.
     *
     * <Return>
     *    FreeType error code.  0 means success.
     * =====================================================================
     */
     public static int tt_face_init(Object ... args) {
       //FT_Stream      stream,
       //FT_Face        ttface,      /* TT_Face */
       //FT_Int         face_index,
       //FT_Int         num_params,
       //FT_Parameter*  params

      int error = 0;
      ftbase.FTStreamRec stream = (ftbase.FTStreamRec)args[0];
      ftbase.FTReference<ftbase.FTFaceRec> face_ref = (ftbase.FTReference<ftbase.FTFaceRec>)args[1];
      ftbase.FTFaceRec ttface = face_ref.Get();
      Long val1 = (Long)args[2];
      int face_index = val1.intValue();
      val1 = (Long)args[3];
      int num_params = val1.intValue();
      ftbase.FTParameter params = (ftbase.FTParameter)args[4];
      ftbase.FTLibraryRec library;
      ftsfnt.FTSfntInterfaceClass sfnt = null;
      TTFaceRec face = (TTFaceRec)ttface;
      
Debug(0, DBG_INIT, TAG, "tt_face_init");
      ftbase.FTTrace.Trace(7, TAG, "TTF driver");
      library = ttface.driver.library;
      sfnt = (ftsfnt.FTSfntInterfaceClass)ftbase.FTModuleRec.FTGetModuleInterface(library, "sfnt");
      if (sfnt == null) {
        ftbase.FTTrace.Trace(7, TAG, "tt_face_init: cannot access `sfnt' module");
        error = ftbase.FTError.INTERP_MISSING_MODULE;
        return error;
      }
      /* create input stream from resource */
      if (stream.seek(0) < 0) {
        return error;
      }
      /* check that we have a valid TrueType file */
      error = (int)sfnt.init_face.callClassMethod(stream, face, new Long(face_index), new Long(num_params), params);
      if (error != 0) {
        return error;
      }
      /* We must also be able to accept Mac/GX fonts, as well as OT ones. */
      /* The 0x00020000 tag is completely undocumented; some fonts from   */
      /* Arphic made for Chinese Windows 3.1 have this.                   */
      if (face.format_tag != 0x00010000L &&  /* MS fonts  */
           face.format_tag != 0x00020000L && /* CJK fonts for Win 3.1 */
           face.format_tag != TTAG_true) {   /* Mac fonts */
        ftbase.FTTrace.Trace(7, TAG, "  not a TTF font");
        error = ftbase.FTError.INTERP_UNKNOWN_FILE_FORMAT;
        return error;
      }
      ttface.face_flags |= ftbase.FTFaceRec.FT_FACE_FLAG_HINTER;
      /* If we are performing a simple font format check, exit immediately. */
      if (face_index < 0) {
        return ftbase.FTError.INTERP_ERR_OK;
      }
      /* Load font directory */
      error = (int)sfnt.load_face.callClassMethod((Object)stream, (Object)face, (Object)(new Integer(face_index)), (Object)(new Integer(num_params)), (Object)params);
      if (error != 0) {
        return error;
      }
Debug(0, DBG_INIT, TAG, "tt_face_init: after sfnt_load_face");
//      if (tt_check_trickyness(ttface)) {
//        ttface.face_flags |= FTFaceRec.FT_FACE_FLAG_TRICKY;
//      }
//      error = tt_face_load_hdmx(face, stream);
      if (error != 0) {
        return error;
      }
// FIXME!!
ttface.face_flags |= FT_FACE_FLAG_SCALABLE;
      if ((ttface.face_flags & FT_FACE_FLAG_SCALABLE ) != 0) {
        if (error == 0) {
          error = tt_face_load_loca(face, stream);
        }
        if (error == 0) {
          error = tt_face_load_cvt(face, stream);
        }
        if (error == 0) {
          error = tt_face_load_fpgm(face, stream);
        }
        if (error == 0) {
          error = tt_face_load_prep(face, stream);
        }
        /* Check the scalable flag based on `loca'. */
/*
        if (ttface.num_fixed_sizes != 0 && face.glyph_locations != 0 &&
             tt_check_single_notdef(ttface)) {
          FT_Trace.Trace((7, TAG, "tt_face_init: \n"+
                      " Only the `.notdef' glyph has an outline.\n"+
                      "             "+
                      " Resetting scalable flag to FALSE.");
          ttface.face_flags &= ~FTFaceRec.FT_FACE_FLAG_SCALABLE;
        }
*/
      }
      /* initialize standard glyph loading routines */
      TTFaceRec.TTInitGlyphLoading(face);
      face_ref.Set(face);
      return error;
    }

    /* =====================================================================
     *
     * <Function>
     *    tt_face_done
     *
     * <Description>
     *    Finalize a given face object.
     *
     * <Input>
     *    face :: A pointer to the face object to destroy. 
     * =====================================================================
     */
    public static void tt_face_done(Object ... args) {   /* TT_Face */
      //TT_Face       face = (TT_Face)ttface;
      //FT_Memory     memory;
      //FT_Stream     stream;
      //SFNT_Service  sfnt;
    	
Debug(0, DBG_INIT, TAG, "tt_face_done");
      TTFaceRec face = (TTFaceRec)args[0];
//      FTStreamRec stream = (FTStreamRec)args[1];
//      FTSfntInterfaceClass sfnt = (FTSfntInterfaceClass)args[2];

      if (face == null) {
       return;
      }
//      stream = ttface.stream;
//      sfnt = (FTSfntInterface)face.sfnt;
      /* for `extended TrueType formats' (i.e. compressed versions) */
//      if (face.extra.finalizer) {
//        face.extra.finalizer(face.extra.data);
//      }
//      if (sfnt != null) {
//        sfnt.done_face(face);
//      }
      /* freeing the locations table */
//      tt_face_done_loca(face);
//      tt_face_free_hdmx(face);
      /* freeing the CVT */
//      FT_FREE(face.cvt);
      face.cvt_size = 0L;
      /* freeing the programs */
//      FT_FRAME_RELEASE( face->font_program );
//      FT_FRAME_RELEASE( face->cvt_program );
      face.font_program_size = 0L;
      face.cvt_program_size  = 0L;
    }

 
    /* =====================================================================
     * tt_slot_init
     *
     * <Description>
     *    Initialize a new slot object.
     *
     * <InOut>
     *    slot :: A handle to the slot object.
     *
     * <Return>
     *    FreeType error code.  0 means success.
     *
     * =====================================================================
     */
    public static int tt_slot_init(Object ... args) {
      int error = 0;
      ftbase.FTReference<ftbase.FTGlyphSlotRec> slot_ref = (ftbase.FTReference<ftbase.FTGlyphSlotRec>)args[0];
      ftbase.FTGlyphSlotRec slot = slot_ref.Get();
      ftbase.FTReference<ftbase.FTGlyphLoaderRec> loader_ref = new ftbase.FTReference<ftbase.FTGlyphLoaderRec>();
      loader_ref.Set(slot.internal.loader);

Debug(0, DBG_INIT, TAG, "tt_slot_init");
      error = ftbase.FTGlyphLoaderRec.FTGlyphLoaderCreateExtra(loader_ref);
      slot.internal.loader = loader_ref.Get();
      slot_ref.Set(slot);
      return error;
    }

    /* =====================================================================
     * tt_get_kerning
     *
     * <Description>
     *    A driver method used to return the kerning vector between two
     *    glyphs of the same face.
     *
     * <Input>
     *    face        :: A handle to the source face object.
     *
     *    left_glyph  :: The index of the left glyph in the kern pair.
     *
     *    right_glyph :: The index of the right glyph in the kern pair.
     *
     * <Output>
     *    kerning     :: The kerning vector.  This is in font units for
     *                   scalable formats, and in pixels for fixed-sizes
     *                   formats.
     *
     * <Return> 
     *    FreeType error code.  0 means success.
     *
     * <Note>
     *    Only horizontal layouts (left-to-right & right-to-left) are
     *    supported by this function.  Other layouts, or more sophisticated
     *    kernings, are out of scope of this method (the basic driver
     *    interface is meant to be simple).
     *
     *    They can be implemented by format-specific interfaces.
     *
     * =====================================================================
     */
    public static int tt_get_kerning(Object ... args) {
      int error = 0;
      ftbase.FTReference<ftbase.FTFaceRec> face_ref = (ftbase.FTReference<ftbase.FTFaceRec>)args[0];
      ftbase.FTFaceRec face = face_ref.Get();
//      Integer left_glyph = (Integer)args[1];
//      Integer right_glyph = (Integer)args[2];
      ftbase.FTReference<ftbase.FTVectorRec> kerning_ref = (ftbase.FTReference<ftbase.FTVectorRec>)args[4];
      ftbase.FTVectorRec kerning = kerning_ref.Get();

      Log.w(TAG, "WARNING: tt_get_kerning not yet implemented");
System.out.println("tt_get_kerning not yet implemented!!");
      face_ref.Set(face);
      kerning_ref.Set(kerning);
      return error;
    }

    /* =====================================================================
     * tt_get_advances
     * =====================================================================
     */
    public static int tt_get_advances(Object ... args) {
      int error = 0;
      ftbase.FTReference<ftbase.FTFaceRec> face_ref = (ftbase.FTReference<ftbase.FTFaceRec>)args[0];
      ftbase.FTFaceRec face = face_ref.Get();
//      Integer start = (Integer)args[1];
//      Integer count = (Integer)args[2];
//      Integer flags = (Integer)args[3];
      ftbase.FTReference<ftbase.FTReference<Long>> advances_ref = (ftbase.FTReference<ftbase.FTReference<Long>>)args[4];
      ftbase.FTReference<Long> advances = new ftbase.FTReference<Long>();
      
      Log.w(TAG, "WARNING: tt_get_advances not yet implemented");
System.out.println("tt_get_advances not yet implemented!!");
      face_ref.Set(face);
      advances_ref.Set(advances);
      return error;
    }

    /* =====================================================================
     * tt_face_load_loca
     *
     * <Description>
     *    Load the locations table.
     *
     * <InOut>
     *    face   :: A handle to the target face object.
     *
     * <Input>
     *    stream :: The input stream.
     *
     * <Return>
     *    FreeType error code.  0 means success.
     *
     * =====================================================================
     */
    public static int tt_face_load_loca(TTFaceRec face, ftbase.FTStreamRec stream) {
      int error = 0;
      long table_len = 0;
      int shift;
      ftbase.FTReference<Long> length_ref = new ftbase.FTReference<Long>();

      /* we need the size of the `glyf' table for malformed `loca' tables */
      length_ref.Set(face.glyf_len);
      error = (int)face.goto_table.callClassMethod(face, ftsfnt.TTSfntLoad.TTAG_glyf, stream, length_ref);
      face.glyf_len = length_ref.Get();
      /* it is possible that a font doesn't have a glyf table at all */
      /* or its size is zero                                         */
      if (error != 0 && error != ftbase.FTError.GLYPH_TABLE_MISSING) {
        face.glyf_len = 0L;
      } else {
        if (error != 0) {
          return error;
        }
      }
      ftbase.FTTrace.Trace(7, TAG, "Locations ");
      length_ref.Set(table_len);
      error = (int)face.goto_table.callClassMethod(face, ftsfnt.TTSfntLoad.TTAG_loca, stream, length_ref);
      table_len = length_ref.Get();
      if (error != 0) {
        error = ftbase.FTError.INTERP_TABLE_LOCATIONS_MISSING;
        return error;
      }
      if (face.header.Index_To_Loc_Format != 0) {
        shift = 2;
        if (table_len >= 0x40000L) {
          Log.e(TAG,"table too large");
          error = ftbase.FTError.INTERP_INVALID_TABLE;
          return error;
        }
        face.num_locations = table_len >> shift;
      } else {
        shift = 1;
        if (table_len >= 0x20000L) {
          Log.e(TAG, "table too large");
          error = ftbase.FTError.INTERP_INVALID_TABLE;
          return error;
        }
        face.num_locations = table_len >> shift;
      }
      if (face.num_locations != (long)face.num_glyphs + 1) {
        ftbase.FTTrace.Trace(7, TAG, String.format("glyph count mismatch!  loca: %d, maxp: %d",
                    face.num_locations - 1, face.num_glyphs));
        /* we only handle the case where `maxp' gives a larger value */
        if (face.num_locations <= (long)face.num_glyphs) {
          long new_loca_len = ((long)(face.num_glyphs) + 1) << shift;

          TTTableRec entry;
          int i = 0;
          int limit = face.num_tables;
          long pos  = stream.pos();
          long dist = 0x7FFFFFFFL;

          /* compute the distance to next table in font file */
          for (i = 0; i < limit; i++) {
        	entry = face.dir_tables[i];  
            long diff = entry.Offset - pos;

            if (diff > 0 && diff < dist) {
              dist = diff;
            }
          }
          if (i == limit) {
            /* `loca' is the last table */
            dist = stream.size - pos;
          }
          if (new_loca_len <= dist) {
            face.num_locations = face.num_glyphs + 1;
            table_len = new_loca_len;
            ftbase.FTTrace.Trace(7, TAG, String.format("adjusting num_locations to %d", face.num_locations));
          }
        }
      }
      /*
       * Extract the frame.  We don't need to decompress it since
       * we are able to parse it directly.
       */
      if (face.glyph_locations == null) {
    	face.glyph_locations = new byte[(int)table_len];	  
      }
      if (stream.read(face.glyph_locations, (short)table_len, stream) < 0) {
        error = -888;
    	return error;
      }
      ftbase.FTTrace.Trace(7, TAG, "loaded");
      return error;
    }

    /* =====================================================================
     * tt_face_load_cvt
     *
     * <Description>
     *    Load the control value table into a face object.
     *
     * <InOut>
     *    face   :: A handle to the target face object.
     *
     * <Input>
     *    stream :: A handle to the input stream.
     *
     * <Return>
     *    FreeType error code.  0 means success.
     *
     * =====================================================================
     */
    public static int tt_face_load_cvt(TTFaceRec face, ftbase.FTStreamRec stream) {
      int error = 0;
      long table_len = 0;
      ftbase.FTReference<Long> length_ref = new ftbase.FTReference<Long>();

      ftbase.FTTrace.Trace(7, TAG, "CVT ");
      length_ref.Set(table_len);
      error = (int)face.goto_table.callClassMethod(face, ftsfnt.TTSfntLoad.TTAG_cvt, stream, length_ref);
      table_len = length_ref.Get();
      if (error != 0) {
        ftbase.FTTrace.Trace(7, TAG, "is missing");
        face.cvt_size = 0L;
        face.cvt = null;
        error = ftbase.FTError.INTERP_ERR_OK;
        return error;
      }
      face.cvt_size = table_len / 2;
      face.cvt = new short[(int)face.cvt_size];
      if (face.cvt == null) {
    	face.cvt = new short[(int)face.cvt_size];	  
      }
   //   if (stream.readShortArray(face.cvt, face.cvt_size.shortValue(), stream) < 0) {
   //     error = -888;
   //   	return error;
   //   }
      {
        int limit = (int)face.cvt_size;

        for (int i = 0; i < limit; i++) {
          face.cvt[i] = stream.readShort(stream);
        }
      }
      ftbase.FTTrace.Trace(7, TAG, "loaded");
      return error;
    }

    /* =====================================================================
     * tt_face_load_fpgm
     *
     * <Description>
     *    Load the font program.
     *
     * <InOut>
     *    face   :: A handle to the target face object.
     *
     * <Input>
     *    stream :: A handle to the input stream.
     *
     * <Return>
     *    FreeType error code.  0 means success.
     *
     * =====================================================================
     */
    public static int tt_face_load_fpgm(TTFaceRec face, ftbase.FTStreamRec stream) {
      int error = 0;
      long table_len = 0;
      ftbase.FTReference<Long> length_ref = new ftbase.FTReference<Long>();

      ftbase.FTTrace.Trace(7, TAG, "Font program ");
      /* The font program is optional */
      length_ref.Set(table_len);
      error = (int)face.goto_table.callClassMethod(face, ftsfnt.TTSfntLoad.TTAG_fpgm, stream, length_ref);
      table_len = length_ref.Get();
      if (error != 0) {
        face.font_program = null;
        face.font_program_size = 0L;
        error = ftbase.FTError.INTERP_ERR_OK;
        ftbase.FTTrace.Trace(7, TAG, "is missing");
      } else {
        face.font_program_size = table_len;
        if (face.font_program == null) {
      	  face.font_program = new byte[(int)table_len];	  
        }
        if (stream.read(face.font_program, (short)table_len, stream) < 0) {
          error = -888;
          return error;
        }
        ftbase.FTTrace.Trace(7, TAG, String.format("loaded, %12d bytes", face.font_program_size));
      }
      return error;
    }

    /* =====================================================================
     * tt_face_load_prep
     *
     * <Description>
     *    Load the cvt program.
     *
     * <InOut>
     *    face   :: A handle to the target face object.
     *
     * <Input>
     *    stream :: A handle to the input stream.
     *
     * <Return>
     *    FreeType error code.  0 means success.
     *
     * =====================================================================
     */
    public static int tt_face_load_prep(TTFaceRec face, ftbase.FTStreamRec stream) {
      int error = 0;
      long table_len = 0;
      ftbase.FTReference<Long> length_ref = new ftbase.FTReference<Long>();

      ftbase.FTTrace.Trace(7, TAG, "Prep program ");
      length_ref.Set(table_len);
      error = (int)face.goto_table.callClassMethod(face, ftsfnt.TTSfntLoad.TTAG_prep, stream, length_ref);
      table_len = length_ref.Get();
      if (error != 0) {
        face.cvt_program = null;
        face.cvt_program_size = 0L;
        error = ftbase.FTError.INTERP_ERR_OK;
        ftbase.FTTrace.Trace(7, TAG, "is missing");
      } else {
        face.cvt_program_size = table_len;
        if (face.cvt_program == null) {
          face.cvt_program = new byte[(int)table_len];	  
        }
        if (stream.read(face.cvt_program, (short)table_len, stream) < 0) {
          error = -888;
          return error;
        }
        ftbase.FTTrace.Trace(7, TAG, String.format("loaded, %12d bytes", face.cvt_program_size));
      }
      return error;
    }

}