ApwFreetypeLibrary

Check-in [e10740ef9b]
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:e10740ef9b7d070440c87c26c515b315a48a85fe
User & Date: arnulf 2014-12-29 21:46:11
Context
2014-12-29
21:46
initial version check-in: b5c63cad02 user: arnulf tags: trunk
21:46
initial version. check-in: e10740ef9b user: arnulf tags: trunk
21:44
initial verwsion. check-in: ba5a7822b2 user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added ftbase/FTBitmapGlyphClassRec.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
/* =====================================================================
 *  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 ftbase;

import android.util.Log;

  /* ===================================================================== */
  /*    FTBitmapGlyphClassRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTBitmapGlyphClassRec extends FTGlyphClassRec {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTBitmapGlyphClassRec";

    /* ==================== FTBitmapGlyphClassRec ================================== */
    public FTBitmapGlyphClassRec() {
      oid++;
      id = oid;
      String class_name = "org.apwtcl.gles20.truetype.FTBitmapGlyphFuncs";
      this.glyph_size = 0;
      this.glyph_format = FT_GLYPH_FORMAT_BITMAP;
      this.glyph_init = new FTInstanceMethod(class_name, "ft_bitmap_glyph_init", 1);
      this.glyph_done = new FTInstanceMethod(class_name, "ft_bitmap_glyph_done", 1);
      this.glyph_copy = new FTInstanceMethod(class_name, "ft_bitmap_glyph_copy", 1);
      this.glyph_transform = null;
      this.glyph_bbox = new FTInstanceMethod(class_name, "ft_bitmap_glyph_bbox", 1);
      this.glyph_prepare = null;
    }
    
    /* ==================== 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();
    }
 
    /* =====================================================================
     *    ft_bitmap_glyph_init
     *
     * =====================================================================
     */
    public static int ft_bitmap_glyph_init(Object ... args) {
      Log.w(TAG, "ft_bitmap_glyph_init not yet implemented");
      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ft_bitmap_glyph_done
     *
     * =====================================================================
     */
    public static int ft_bitmap_glyph_done(Object ... args) {
      Log.w(TAG, "ft_bitmap_glyph_done not yet implemented");
      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ft_bitmap_glyph_copy
     *
     * =====================================================================
     */
    public static int ft_bitmap_glyph_copy(Object ... args) {
      Log.w(TAG, "ft_bitmap_glyph_copy not yet implemented");
      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ft_bitmap_glyph_bbox
     *
     * =====================================================================
     */
    public static int ft_bitmap_glyph_bbox(Object ... args) {
      Log.w(TAG, "ft_bitmap_glyph_init bbox yet implemented");
      int error = 0;

      return error;
    }

    /* =====================================================================
     *    FTGlyphTransform
     *
     * =====================================================================
     */
    public static int FTGlyphTransform(Object ... args) {
      Log.w(TAG, "ft_bitmap_glyph_init bbox yet implemented");
      int error = 0;

      return error;
    }
}

Added ftbase/FTBitmapGlyphRec.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
/* =====================================================================
 *  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 ftbase;

//import android.util.Log;
  /* ===================================================================== */
  /*    FTBitmapGlyphRec                                                   */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A structure used for bitmap glyph images.  This really is a        */
  /*    `sub-class' of @FTGlyphRec.                                       */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    root   :: The root @FTGlyph fields.                               */
  /*                                                                       */
  /*    left   :: The left-side bearing, i.e., the horizontal distance     */
  /*              from the current pen position to the left border of the  */
  /*              glyph bitmap.                                            */
  /*                                                                       */
  /*    top    :: The top-side bearing, i.e., the vertical distance from   */
  /*              the current pen position to the top border of the glyph  */
  /*              bitmap.  This distance is positive for upwards~y!        */
  /*                                                                       */
  /*    bitmap :: A descriptor for the bitmap.                             */
  /*                                                                       */
  /* <Note>                                                                */
  /*    You can typecast an @FTGlyph to @FTBitmapGlyph if you have       */
  /*    `glyph->format == FTGLYPH_FORMAT_BITMAP'.  This lets you access   */
  /*    the bitmap's contents easily.                                      */
  /*                                                                       */
  /*    The corresponding pixel buffer is always owned by @FTBitmapGlyph  */
  /*    and is thus created and destroyed with it.                         */
  /*                                                                       */
  /* ===================================================================== */

public class FTBitmapGlyphRec extends FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTBitmapGlyphRec";

    public FTGlyphRec root = null;
    public int left = 0;
    public int top = 0;
    public FTBitmapRec bitmap = null;

    /* ==================== FTBitmapGlyphRec ================================== */
    public FTBitmapGlyphRec() {
      oid++;
      id = oid;
      root = new FTGlyphRec();
      bitmap = new FTBitmapRec();
    }
    
    /* ==================== FTBitmapGlyphRec ================================== */
    public FTBitmapGlyphRec(FTGlyphRec glyph) {
      oid++;
      id = oid;
      root = glyph;
      bitmap = new FTBitmapRec();
FTTrace.Trace(7, TAG, "new FTBitmapGlyphRec with glyph: "+root.library+"!");
      String class_name = "org.apwtcl.gles20.truetype.FTBitmapGlyphFuncs";
      root.clazz.glyph_init = new FTInstanceMethod(class_name, "ft_bitmap_glyph_init", 1);
      root.clazz.glyph_done = new FTInstanceMethod(class_name, "ft_bitmap_glyph_done", 1);
      root.clazz.glyph_copy = new FTInstanceMethod(class_name, "ft_bitmap_glyph_copy", 1);
      root.clazz.glyph_transform = null;
      root.clazz.glyph_bbox = new FTInstanceMethod(class_name, "ft_bitmap_glyph_bbox", 1);
      root.clazz.glyph_prepare = null;

    }
    
    /* ==================== 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();
    }
 
    /* =====================================================================
     * FTGlyphToBitmap
     * =====================================================================
     */
    public static int FTGlyphToBitmap(FTReference<FTGlyphRec> the_glyph_ref,
            long render_mode, FTReference<FTVectorRec> origin_ref, boolean destroy) {
      FTGlyphRec the_glyph = the_glyph_ref.Get();
      FTVectorRec origin;
      FTGlyphSlotRec dummy = new FTGlyphSlotRec();
      FTReference<FTGlyphSlotRec> dummy_ref = new FTReference<FTGlyphSlotRec>();
      FTSlotInternalRec dummy_internal = null;
      int error = FTError.INTERP_ERR_OK;
      FTGlyphRec b = null;
      FTGlyphRec glyph;
      FTReference<FTGlyphRec> glyph_ref = new FTReference<FTGlyphRec>();
      FTBitmapGlyphRec bitmap = null;
      FTGlyphClassRec clazz;
      /* FT_BITMAP_GLYPH_CLASS_GET derefers `library' in PIC mode */
      FTLibraryRec  library;

      if (origin_ref.Get() != null) {
        origin = origin_ref.Get();
      } else {
        origin = null;
      }
      /* check argument */
      if (the_glyph  == null) {
        error = FTError.GLYPH_INVALID_ARGUMENT;
      }
      glyph = the_glyph;
      if (glyph  == null) {
        error = FTError.GLYPH_INVALID_ARGUMENT;
        return error;
      }
      clazz = glyph.clazz;
      library = glyph.library;
      if (library == null || clazz == null) {
        error = FTError.GLYPH_INVALID_ARGUMENT;
        return error;
      }
      /* when called with a bitmap glyph, do nothing and return successfully */
//FIXME!!      if (clazz == FTBitmapGlyphRec.FT_BITMAP_GLYPH_CLASS_GET) {
//        error = FT_Error.GLYPH_INVALID_ARGUMENT;
//        if (error != 0 && bitmap != null) {
//        	FTGlyphLoaderRec.FTDoneGlyph(bitmap.root);
//        }
//        return error;
//      }
System.out.println("PREP: "+clazz.glyph_prepare+"!");
      if (clazz.glyph_prepare == null) {
        error = FTError.GLYPH_INVALID_ARGUMENT;
        return error;
      }
      /* we render the glyph into a glyph bitmap using a `dummy' glyph slot */
      /* then calling FTRenderGlyphInternal()                            */
//      FT_MEM_ZERO( &dummy, sizeof ( dummy ) );
//      FT_MEM_ZERO( &dummy_internal, sizeof ( dummy_internal ) );
      dummy.internal = dummy_internal; // FIXME need address!!
      dummy.library  = library;
      dummy.format   = clazz.glyph_format;
      /* create result bitmap glyph */
      glyph_ref.Set(b);
      error = FTGlyphLoaderFuncs.ft_new_glyph(library, (FTGlyphClassRec)(new FTBitmapGlyphClassRec()), glyph_ref);
      b = glyph_ref.Get();
      if (error != 0) {
        return error;
      }
      bitmap = new FTBitmapGlyphRec(b);
      /* if `origin' is set, translate the glyph image */
      if (origin != null) {
          origin_ref.Set(origin);
          glyph_ref.Set(glyph);
    	  FTGlyphLoaderRec.FTGlyphTransform(glyph_ref, 0, origin_ref);
          glyph = glyph_ref.Get();
          origin = origin_ref.Get();
      }
      /* prepare dummy slot for rendering */
      dummy_ref.Set(dummy);
System.out.println("prep2: "+clazz.glyph_prepare+"!");
      error = (int)clazz.glyph_prepare.callClassMethod(glyph, dummy_ref);
      dummy = dummy_ref.Get();
      if (error == 0) {
        error = FTGlyphRenderFuncs.FTRenderGlyphInternal(glyph.library, dummy, render_mode);
      }
      if (destroy && origin != null) {
        FTVectorRec v = new FTVectorRec();
        FTReference<FTVectorRec>v_ref = new FTReference<FTVectorRec>();
        v.x = -origin.x;
        v.y = -origin.y;
        v_ref.Set(v);
        glyph_ref.Set(glyph);
        FTGlyphLoaderRec.FTGlyphTransform(glyph_ref, 0, v_ref);
        v = v_ref.Get();
        glyph = glyph_ref.Get();
      }
      if (error != 0) {
        if (error != 0 && bitmap != null) {
        	FTGlyphLoaderRec.FTDoneGlyph(bitmap.root);
        }
        return error;
      }
      /* in case of success, copy the bitmap to the glyph bitmap */
      error = (int)FTBitmapGlyphClassRec.ft_bitmap_glyph_init((Object)bitmap, null);
      if (error != 0) {
        if (error != 0 && bitmap != null) {
        	FTGlyphLoaderRec.FTDoneGlyph(bitmap.root);
        }
        return error;
      }
      /* copy advance */
      bitmap.root.advance = glyph.advance;
      if (destroy) {
    	  FTGlyphLoaderRec.FTDoneGlyph(glyph);
      }
      the_glyph_ref.Set(bitmap.root);
      if (error != 0 && bitmap != null) {
    	  FTGlyphLoaderRec.FTDoneGlyph(bitmap.root);
      }
      return error;
    }

}

Added ftbase/FTBitmapRec.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
/* =====================================================================
 *  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 ftbase;

import android.util.Log;

  /* ===================================================================== */
  /*    FTBitmapRec                                                           */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A structure used to describe a bitmap or pixmap to the raster.     */
  /*    Note that we now manage pixmaps of various depths through the      */
  /*    `pixel_mode' field.                                                */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    rows         :: The number of bitmap rows.                         */
  /*                                                                       */
  /*    width        :: The number of pixels in bitmap row.                */
  /*                                                                       */
  /*    pitch        :: The pitch's absolute value is the number of bytes  */
  /*                    taken by one bitmap row, including padding.        */
  /*                    However, the pitch is positive when the bitmap has */
  /*                    a `down' flow, and negative when it has an `up'    */
  /*                    flow.  In all cases, the pitch is an offset to add */
  /*                    to a bitmap pointer in order to go down one row.   */
  /*                                                                       */
  /*                    Note that `padding' means the alignment of a       */
  /*                    bitmap to a byte border, and FreeType functions    */
  /*                    normally align to the smallest possible integer    */
  /*                    value.                                             */
  /*                                                                       */
  /*                    For the B/W rasterizer, `pitch' is always an even  */
  /*                    number.                                            */
  /*                                                                       */
  /*                    To change the pitch of a bitmap (say, to make it a */
  /*                    multiple of 4), use @FT_Bitmap_Convert.            */
  /*                    Alternatively, you might use callback functions to */
  /*                    directly render to the application's surface; see  */
  /*                    the file `example2.cpp' in the tutorial for a      */
  /*                    demonstration.                                     */
  /*                                                                       */
  /*    buffer       :: A typeless pointer to the bitmap buffer.  This     */
  /*                    value should be aligned on 32-bit boundaries in    */
  /*                    most cases.                                        */
  /*                                                                       */
  /*    num_grays    :: This field is only used with                       */
  /*                    @FT_PIXEL_MODE_GRAY; it gives the number of gray   */
  /*                    levels used in the bitmap.                         */
  /*                                                                       */
  /*    pixel_mode   :: The pixel mode, i.e., how pixel bits are stored.   */
  /*                    See @FT_Pixel_Mode for possible values.            */
  /*                                                                       */
  /*    palette_mode :: This field is intended for paletted pixel modes;   */
  /*                    it indicates how the palette is stored.  Not       */
  /*                    used currently.                                    */
  /*                                                                       */
  /*    palette      :: A typeless pointer to the bitmap palette; this     */
  /*                    field is intended for paletted pixel modes.  Not   */
  /*                    used currently.                                    */
  /*                                                                       */
  /* <Note>                                                                */
  /*   For now, the only pixel modes supported by FreeType are mono and    */
  /*   grays.  However, drivers might be added in the future to support    */
  /*   more `colorful' options.                                            */
  /*                                                                       */
  /* ===================================================================== */

public class FTBitmapRec extends FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTBitmapRec";

    public int rows = 0;
    public int width = 0;
    public int pitch = 0;
    public byte[] buffer = null;
    public short num_grays = 0;
    public Byte pixel_mode = FT_PIXEL_MODE_GRAY;
    public Byte palette_mode = 0;
    public Object palette = null;

    /* ==================== FTBitmapRec ================================== */
    public FTBitmapRec() {
      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();
    }
 
    /* =====================================================================
     * FTBitmapNew
     * =====================================================================
     */
    public static int FTBitmapNew(FTReference<FTBitmapRec> bitmap_ref) {
      int error = 0;

      FTBitmapRec bitmap = new FTBitmapRec();
      bitmap_ref.Set(bitmap);
      return error;
    }

    /* =====================================================================
     * FTBitmapConvert
     * =====================================================================
     */
    public static int FTBitmapConvert(FTLibraryRec library, FTBitmapRec source, FTReference<FTBitmapRec> target_bitmap_ref, int alignment) {
      int error = 0;
      int row = 0;
      int col = 0;
      int idx;
      int pitch = source.pitch;
      StringBuffer str = new StringBuffer();
      FTBitmapRec target = target_bitmap_ref.Get();

      if (library == null) {
        return FTError.GLYPH_INVALID_LIBRARY_HANDLE;
      }
Debug(0, DBG_LOAD_GLYPH, TAG, "Bitmap slot buffer:");
idx = 0;
for (row = 0; row < source.rows; row++) {
  str.delete(0, str.length());
  str.append(String.format("row: %02d ", row));
  for (col = 0; col < source.width; col++) {
    str.append(String.format(" 0x%02x", source.buffer[idx]));
    idx++;
  }
  Debug(0, DBG_LOAD_GLYPH, TAG, str.toString());
}
      switch (source.pixel_mode) {
      case FT_PIXEL_MODE_MONO:
      case FT_PIXEL_MODE_GRAY:
      case FT_PIXEL_MODE_GRAY2:
      case FT_PIXEL_MODE_GRAY4:
      case FT_PIXEL_MODE_LCD:
      case FT_PIXEL_MODE_LCD_V:
      case FT_PIXEL_MODE_BGRA:
        {
          int pad;
          int old_size;

Debug(0, DBG_LOAD_GLYPH, TAG, String.format("CONVERT 1: rows: %d, width: %d", source.rows, source.width));
          old_size = target.rows * target.pitch;
          if (old_size < 0) {
            old_size = -old_size;
          }
          target.pixel_mode = FT_PIXEL_MODE_GRAY;
          target.rows = source.rows;
          target.width = source.width;
          pad = 0;
          if (alignment > 0) {
            pad = source.width % alignment;
            if (pad != 0) {
              pad = alignment - pad;
            }
          }
          target.pitch = source.width + pad;
Debug(0, DBG_LOAD_GLYPH, TAG, String.format("pitch: %d rows: %d %d div: %d", target.pitch, target.rows, FT_ULONG_MAX, (target.pitch > 0 ? (FT_ULONG_MAX / target.pitch) : 0)));
          if (target.pitch > 0 &&
               (long)target.rows > (FT_ULONG_MAX / target.pitch)) {
            return FTError.GLYPH_INVALID_ARGUMENT;
          }
          if (target.rows * target.pitch > old_size) {
            target.buffer = new byte[target.rows * target.pitch];
          }
          if (target.rows * target.pitch > old_size /* &&
               FT_QREALLOC(target.buffer, old_size, target.rows * target.pitch) */  && target.buffer == null) {
            return error;
          }
        }
        break;
      default:
        error = FTError.GLYPH_INVALID_ARGUMENT;
      }
      switch (source.pixel_mode) {
      case FT_PIXEL_MODE_MONO:
        {
          byte[] s = source.buffer;
          byte[] t = target.buffer;
          int i;
          int s_idx = 0;
          int t_idx = 0;

Debug(0, DBG_LOAD_GLYPH, TAG, "CONVERT 2");
          target.num_grays = 2;
          for (i = source.rows; i > 0; i--) {
            byte[] ss = s;
            byte[] tt = t;
            int j;
            int ss_idx = s_idx;
            int tt_idx = t_idx;

            /* get the full bytes */
            for (j = source.width >> 3; j > 0; j--) {
              int val = ss[ss_idx + 0]; /* avoid a byte.int cast on each line */

              tt[tt_idx + 0] = (byte)((val & 0x80) >> 7);
              tt[tt_idx + 1] = (byte)((val & 0x40) >> 6);
              tt[tt_idx + 2] = (byte)((val & 0x20) >> 5);
              tt[tt_idx + 3] = (byte)((val & 0x10) >> 4);
              tt[tt_idx + 4] = (byte)((val & 0x08) >> 3);
              tt[tt_idx + 5] = (byte)((val & 0x04) >> 2);
              tt[tt_idx + 6] = (byte)((val & 0x02) >> 1);
              tt[tt_idx + 7] = (byte)( val & 0x01);
              tt_idx += 8;
              ss_idx += 1;
            }
            /* get remaining pixels (if any) */
            j = source.width & 7;
            if (j > 0) {
              int val = ss[ss_idx + 0];

              for ( ; j > 0; j--) {
                tt[tt_idx + 0] = (byte)((val & 0x80) >> 7);
                val <<= 1;
                tt_idx += 1;
              }
            }
            s_idx += source.pitch;
            t_idx += target.pitch;
          }
        }
        break;
      case FT_PIXEL_MODE_GRAY:
      case FT_PIXEL_MODE_LCD:
      case FT_PIXEL_MODE_LCD_V:
        {
Debug(0, DBG_LOAD_GLYPH, TAG, "CONVERT 3");
          int width = source.width;
          int i;
          int s_idx = 0;
          int t_idx = 0;

          target.num_grays = 256;
          for (i = source.rows; i > 0; i--) {
            for (int j = 0; j < width; j++) {
              target.buffer[t_idx + j] = source.buffer[s_idx + j];
            }
            s_idx += source.pitch;
            t_idx += target.pitch;
          }
        }
        break;
      case FT_PIXEL_MODE_GRAY2:
        {
          int i;
          int s_idx = 0;
          int t_idx = 0;

Debug(0, DBG_LOAD_GLYPH, TAG, "CONVERT 4");
          target.num_grays = 4;
          for (i = source.rows; i > 0; i--) {
            int j;
            int ss_idx = s_idx;
            int tt_idx = t_idx;

            /* get the full bytes */
            for (j = source.width >> 2; j > 0; j--) {
              int val = source.buffer[ss_idx + 0];

              target.buffer[tt_idx + 0] = (byte)((val & 0xC0) >> 6);
              target.buffer[tt_idx + 1] = (byte)((val & 0x30) >> 4);
              target.buffer[tt_idx + 2] = (byte)((val & 0x0C) >> 2);
              target.buffer[tt_idx + 3] = (byte)((val & 0x03));
              ss_idx += 1;
              tt_idx += 4;
            }
            j = source.width & 3;
            if (j > 0) {
              int val = source.buffer[ss_idx + 0];

              for (; j > 0; j--) {
                target.buffer[tt_idx + 0] = (byte)((val & 0xC0) >> 6);
                val <<= 2;
                tt_idx += 1;
              }
            }
            s_idx += source.pitch;
            t_idx += target.pitch;
          }
        }
        break;
      case FT_PIXEL_MODE_GRAY4:
        {
          int i;
          int s_idx = 0;
          int t_idx = 0;

Debug(0, DBG_LOAD_GLYPH, TAG, "CONVERT 5");
          target.num_grays = 16;
          for (i = source.rows; i > 0; i--) {
            int j;
            int ss_idx = s_idx;
            int tt_idx = t_idx;

            /* get the full bytes */
            for (j = source.width >> 1; j > 0; j--) {
              int val = source.buffer[ss_idx + 0];

              target.buffer[tt_idx + 0] = (byte)((val & 0xF0) >> 4);
              target.buffer[tt_idx + 1] = (byte)((val & 0x0F));
              ss_idx += 1;
              tt_idx += 2;
            }
            if ((source.width & 1) != 0) {
              target.buffer[0] = (byte)((source.buffer[ss_idx + 0] & 0xF0) >> 4);
            }
            s_idx += source.pitch;
            t_idx += target.pitch;
          }
        }
        break;
      case FT_PIXEL_MODE_BGRA:
        {
          int s_pitch = source.pitch;
          int t_pitch = target.pitch;
          int i;
          int s_idx = 0;
          int t_idx = 0;

Debug(0, DBG_LOAD_GLYPH, TAG, "CONVERT 6");
          target.num_grays = 256;
          for (i = source.rows; i > 0; i--) {
            int j;
            int ss_idx = s_idx;
            int tt_idx = t_idx;

            for (j = source.width; j > 0; j--) {
              FTReference<byte[]> ss_ref = new FTReference<byte[]>();
              ss_ref.Set(source.buffer);
              target.buffer[tt_idx + 0] = ft_gray_for_premultiplied_srgb_bgra(ss_ref, ss_idx);
              source.buffer = ss_ref.Get();
              ss_idx += 4;
              tt_idx += 1;
            }
            s_idx += s_pitch;
            t_idx += t_pitch;
          }
        }
        break;
      default:
        ;
      }
      target_bitmap_ref.Set(target);
      return error;
    }

    /* =====================================================================
     * FTBitmapDone
     * =====================================================================
     */
    public static int FTBitmapDone(FTLibraryRec library, FTBitmapRec bitmap) {
      Log.w(TAG, "FTBitmapDone: not yet implemented\n");
      if (library == null) {
        return FTError.RENDER_INVALID_LIBRARY_HANDLE;
      }
      if (bitmap == null) {
        return FTError.RENDER_INVALID_ARGUMENT;
      }
      bitmap.rows = 0;
      bitmap.width = 0;
      bitmap.pitch = 0;
      bitmap.buffer = null;
      bitmap.num_grays = 0;
      bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
      bitmap.palette_mode = 0;
      bitmap.palette = null;
      return 0;
    }

    /* =====================================================================
     * ft_gray_for_premultiplied_srgb_bgra
     * =====================================================================
     */
    public static Byte ft_gray_for_premultiplied_srgb_bgra(FTReference<byte[]> ss_ref, int ss_idx) {
      Log.w(TAG, "ft_gray_for_premultiplied_srgb_bgra: not yet implemented!!\n");
      byte[] ss = ss_ref.Get();
      return ss[ss_idx];
    }
    
}

Added ftbase/FTBitmapSize.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
/* =====================================================================
 *  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 ftbase;

  /* ===================================================================== */
  /*    FTBitmapSize                                                          */
  /* <Description>                                                         */
  /*    This structure models the metrics of a bitmap strike (i.e., a set  */
  /*    of glyphs for a given point size and resolution) in a bitmap font. */
  /*    It is used for the `available_sizes' field of @FT_Face.            */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    height :: The vertical distance, in pixels, between two            */
  /*              consecutive baselines.  It is always positive.           */
  /*                                                                       */
  /*    width  :: The average width, in pixels, of all glyphs in the       */
  /*              strike.                                                  */
  /*                                                                       */
  /*    size   :: The nominal size of the strike in 26.6 fractional        */
  /*              points.  This field is not very useful.                  */
  /*                                                                       */
  /*    x_ppem :: The horizontal ppem (nominal width) in 26.6 fractional   */
  /*              pixels.                                                  */
  /*                                                                       */
  /*    y_ppem :: The vertical ppem (nominal height) in 26.6 fractional    */
  /*              pixels.                                                  */
  /*                                                                       */
  /* <Note>                                                                */
  /*    Windows FNT:                                                       */
  /*      The nominal size given in a FNT font is not reliable.  Thus when */
  /*      the driver finds it incorrect, it sets `size' to some calculated */
  /*      values and sets `x_ppem' and `y_ppem' to the pixel width and     */
  /*      height given in the font, respectively.                          */
  /*                                                                       */
  /*    TrueType embedded bitmaps:                                         */
  /*      `size', `width', and `height' values are not contained in the    */
  /*      bitmap strike itself.  They are computed from the global font    */
  /*      parameters.                                                      */
  /*                                                                       */
  /* ===================================================================== */

public class FTBitmapSize extends FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTBitmapSize";

    public short height = 0;
    public short width = 0;
    public long size = 0L;
    public long x_ppem = 0L;
    public long y_ppem = 0L;

    /* ==================== FTBitmapSize ================================== */
    public FTBitmapSize() {
      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();
    }
 
}

Added ftbase/FTFrameEntry.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
/* =====================================================================
 *  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 ftbase;

  /* ===================================================================== */
  /*    FTFrameEntry                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTFrameEntry extends Object {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTFrameEntry";

    public FTInstanceMethod stream_method;
    public FTInstanceVariable class_variable;
    public String field_name;
    public int type;

    /* ==================== FTFrameEntry ================================== */
    public FTFrameEntry() {
      oid++;
      id = oid;
    }
    
    /* ==================== FTFrameEntry ================================== */
    public FTFrameEntry(String name, FTInstanceVariable va, FTInstanceMethod me, int type) {
      oid++;
      id = oid;
      this.stream_method = me;
      this.class_variable = va;
      this.type = type;
      this.field_name = name;
    }
    
    /* ==================== 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();
    }
 
}

Added ftbase/FTFrameField.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
/* =====================================================================
 *  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 ftbase;

  /* ===================================================================== */
  /*    FTFrameField                                                       */
  /*                                                                       */
  /* format of an 8-bit frame_op value:           */
  /*                                              */
  /* bit  76543210                                */
  /*      xxxxxxes                                */
  /*                                              */
  /* s is set to 1 if the value is signed.        */
  /* e is set to 1 if the value is little-endian. */
  /* xxx is a command.                            */
  /* ===================================================================== */

public class FTFrameField extends FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTFrameField";

    public final static int FT_FRAME_OP_SHIFT  = 2;
    public final static int FT_FRAME_OP_SIGNED = 1;
    public final static int FT_FRAME_OP_LITTLE = 2;
    public final static int FT_FRAME_OP_END    = 0;
    public final static int FT_FRAME_OP_START  = 1; /* start a new frame     */
    public final static int FT_FRAME_OP_BYTE   = 2; /* read 1-byte value     */
    public final static int FT_FRAME_OP_SHORT  = 3; /* read 2-byte value     */
    public final static int FT_FRAME_OP_LONG   = 4; /* read 4-byte value     */
    public final static int FT_FRAME_OP_OFF3   = 5; /* read 3-byte value     */
    public final static int FT_FRAME_OP_BYTES  = 6; /* read a bytes sequence */

    public final static int ft_frame_end = 0;
    public final static int ft_frame_start = (FT_FRAME_OP_START << FT_FRAME_OP_SHIFT | 0 << 1 | 0);
    public final static int ft_frame_byte      = (FT_FRAME_OP_BYTE << FT_FRAME_OP_SHIFT | 0 << 1 | 0 );
    public final static int ft_frame_schar     = (FT_FRAME_OP_BYTE << FT_FRAME_OP_SHIFT | 0 << 1 | 1 );
    public final static int ft_frame_ushort_be = (FT_FRAME_OP_SHORT << FT_FRAME_OP_SHIFT | 0 << 1 | 0 );
    public final static int ft_frame_short_be  = (FT_FRAME_OP_SHORT << FT_FRAME_OP_SHIFT | 0 << 1 | 1 );
    public final static int ft_frame_ushort_le = (FT_FRAME_OP_SHORT << FT_FRAME_OP_SHIFT | 1 << 1 | 0 );
    public final static int ft_frame_short_le  = (FT_FRAME_OP_SHORT << FT_FRAME_OP_SHIFT | 1 << 1 | 1 );
    public final static int ft_frame_ulong_be  = (FT_FRAME_OP_LONG << FT_FRAME_OP_SHIFT | 0 << 1 | 0 );
    public final static int ft_frame_long_be   = (FT_FRAME_OP_LONG << FT_FRAME_OP_SHIFT | 0 << 1 | 1 );
    public final static int ft_frame_ulong_le  = (FT_FRAME_OP_LONG << FT_FRAME_OP_SHIFT | 1 << 1 | 0 );
    public final static int ft_frame_long_le   = (FT_FRAME_OP_LONG << FT_FRAME_OP_SHIFT | 1 << 1 | 1 );
    public final static int ft_frame_uoff3_be  = (FT_FRAME_OP_OFF3 << FT_FRAME_OP_SHIFT | 0 << 1 | 0 );
    public final static int ft_frame_off3_be   = (FT_FRAME_OP_OFF3 << FT_FRAME_OP_SHIFT | 0 << 1 | 1 );
    public final static int ft_frame_uoff3_le  = (FT_FRAME_OP_OFF3 << FT_FRAME_OP_SHIFT | 1 << 1 | 0 );
    public final static int ft_frame_off3_le   = (FT_FRAME_OP_OFF3 << FT_FRAME_OP_SHIFT | 1 << 1 | 1 );
    public final static int ft_frame_bytes     = (FT_FRAME_OP_BYTES << FT_FRAME_OP_SHIFT | 0 << 1 | 0 );
    public final static int ft_frame_skip      = (FT_FRAME_OP_BYTES << FT_FRAME_OP_SHIFT | 0 << 1 | 1 );

    public byte value = 0;
    public byte size = 0;
    public Short offset = 0;

    /* ==================== FTFrameField ================================== */
    public FTFrameField() {
      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();
    }
 
    public static FTFrameField FT_FRAME_START(byte psize) {
       FTFrameField ff = new FTFrameField();
       ff.value = ft_frame_start;
       ff.offset = 0;
       ff.size = psize;
       return ff;
    }

    public static FTFrameField FT_FRAME_END() {
       FTFrameField ff = new FTFrameField();
       ff.value = ft_frame_end;
       ff.offset = 0;
       ff.size = 0;
       return ff;
    }

}

Added ftbase/FTFrameRead.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
/* =====================================================================
 *  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 ftbase;

import java.util.ArrayList;

  /* ===================================================================== */
  /*    FTFrameRead                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTFrameRead extends FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTFrameRead";

    protected final static int VAR_IS_INT = 0x1;
    protected final static int VAR_IS_SHORT = 0x2;
    protected final static int VAR_IS_LONG = 0x4;

    protected final static  String stream_class_name = "org.apwtcl.gles20.truetype.FTStreamRec";
    protected String my_class_name;
    protected ArrayList<FTFrameEntry> frame_info = new ArrayList<FTFrameEntry>();
    protected FTInstanceMethod readLong;
    protected FTInstanceMethod readInt;
    protected FTInstanceMethod readShort;
    protected FTStreamRec stream;

    /* ==================== FTFrameRead ================================== */
    public FTFrameRead(FTStreamRec stream) {
      oid++;
      id = oid;
      this.stream = stream;
      readLong = new FTInstanceMethod(stream_class_name, "readLong", 1);
      readInt = new FTInstanceMethod(stream_class_name, "readInt", 1);
      readShort = new FTInstanceMethod(stream_class_name, "readShort", 1);
    }
    
    /* ==================== 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();
    }
 
    /* =====================================================================
     * =====================================================================
     */
    public int fillVariables() {
      for (int i = 0; i < frame_info.size(); i ++) {
        FTInstanceMethod me = frame_info.get(i).stream_method;
        FTInstanceVariable va = frame_info.get(i).class_variable;
        int type = frame_info.get(i).type;
        String name = frame_info.get(i).field_name;
	    Object obj = me.callClassMethod((Object)stream);
Debug(0, DBG_LOAD_GLYPH, TAG, "obj: "+obj+"!");
        switch (type) {
        case VAR_IS_INT:
          va.setIntVariable(new Integer((int)obj));      
          break;
        case VAR_IS_SHORT:
          va.setShortVariable(new Short((short)obj));      
          break;
        case VAR_IS_LONG:
          va.setLongVariable(new Long((long)obj));      
          break;
        default:
          break;
        }
      }
      return 0;
    }

}

Added ftbase/FTOutlineFuncs.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
/* =====================================================================
 *  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 ftbase;

  /* ===================================================================== */
  /*    FTOutlineFuncs                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTOutlineFuncs extends FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTOutlineFuncs";

    public FTInstanceMethod move_to = null;
    public FTInstanceMethod line_to = null;
    public FTInstanceMethod conic_to = null;
    public FTInstanceMethod cubic_to = null;
    public int shift = 0;
    public long delta = 0;

    /* ==================== FTOutlineFuncs ================================== */
    public FTOutlineFuncs() {
      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();
    }
 
}

Added ftbase/FTOutlineRec.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
/* =====================================================================
 *  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 ftbase;

  /* ===================================================================== */
  /*    FTOutlineRec                                                          */
  /*                                                                       */
  /* <Description>                                                         */
  /*    This structure is used to describe an outline to the scan-line     */
  /*    converter.                                                         */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    n_contours :: The number of contours in the outline.               */
  /*                                                                       */
  /*    n_points   :: The number of points in the outline.                 */
  /*                                                                       */
  /*    points     :: A pointer to an array of `n_points' @FT_Vector       */
  /*                  elements, giving the outline's point coordinates.    */
  /*                                                                       */
  /*    tags       :: A pointer to an array of `n_points' chars, giving    */
  /*                  each outline point's type.                           */
  /*                                                                       */
  /*                  If bit~0 is unset, the point is `off' the curve,     */
  /*                  i.e., a Bézier control point, while it is `on' if    */
  /*                  set.                                                 */
  /*                                                                       */
  /*                  Bit~1 is meaningful for `off' points only.  If set,  */
  /*                  it indicates a third-order Bézier arc control point; */
  /*                  and a second-order control point if unset.           */
  /*                                                                       */
  /*                  If bit~2 is set, bits 5-7 contain the drop-out mode  */
  /*                  (as defined in the OpenType specification; the value */
  /*                  is the same as the argument to the SCANMODE          */
  /*                  instruction).                                        */
  /*                                                                       */
  /*                  Bits 3 and~4 are reserved for internal purposes.     */
  /*                                                                       */
  /*    contours   :: An array of `n_contours' shorts, giving the end      */
  /*                  point of each contour within the outline.  For       */
  /*                  example, the first contour is defined by the points  */
  /*                  `0' to `contours[0]', the second one is defined by   */
  /*                  the points `contours[0]+1' to `contours[1]', etc.    */
  /*                                                                       */
  /*    flags      :: A set of bit flags used to characterize the outline  */
  /*                  and give hints to the scan-converter and hinter on   */
  /*                  how to convert/grid-fit it.  See @FT_OUTLINE_FLAGS.  */
  /*                                                                       */
  /* <Note>                                                                */
  /*    The B/W rasterizer only checks bit~2 in the `tags' array for the   */
  /*    first point of each contour.  The drop-out mode as given with      */
  /*    @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, and       */
  /*    @FT_OUTLINE_INCLUDE_STUBS in `flags' is then overridden.           */
  /*                                                                       */
  /* ===================================================================== */

public class FTOutlineRec extends FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTOutlineRec";

    public short n_contours = 0;    /* number of contours in glyph        */
    public short n_points = 0;      /* number of points in the glyph      */
    public FTVectorRec[] points = null;  /* the outline's points               */
    public byte[] tags = null;      /* the points flags                   */
    public short[] contours = null; /* the contour end points             */
    public int flags = 0;           /* outline masks                      */
    public int points_idx = 0;
    public int tags_idx = 0;
    public int contours_idx = 0;

    /* ==================== FTOutlineRec ================================== */
    public FTOutlineRec() {
      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();
    }
 
    /* ==================== toDebugString ===================================== */
    public void copy(FTOutlineRec from) {
      n_contours = from.n_contours;
      n_points = from.n_points;
      points = from.points;
      tags = from.tags;
      contours = from.contours;
      flags = from.flags;
      points_idx = from.points_idx;
      tags_idx = from.tags_idx;
      contours_idx = from.contours_idx;
    }
    
    /* =====================================================================
     *    FTOutlineCheck
     *
     * <Description>
     *    Check the contents of an outline descriptor.
     *
     * <Input>
     *    outline :: A handle to a source outline.
     *
     * <Return>
     *    FreeType error code.  0~means success.
     *
     * =====================================================================
     */
    public static int FTOutlineCheck(FTOutlineRec outline) {
      int error = 0;

      if (outline != null) {
        int n_points = outline.n_points;
        int n_contours = outline.n_contours;
        int end0, end;
        int n;

        /* empty glyph? */
        if (n_points == 0 && n_contours == 0) {
          return 0;
        }
        /* check point and contour counts */
        if (n_points <= 0 || n_contours <= 0) {
          error = FTError.LOAD_INVALID_ARGUMENT;
          return error;
        }
        end0 = end = -1;
        for (n = 0; n < n_contours; n++) {
          end = outline.contours[n];
          /* note that we don't accept empty contours */
          if (end <= end0 || end >= n_points) {
            error = FTError.LOAD_INVALID_ARGUMENT;
            return error;
          }
          end0 = end;
        }
        if (end != n_points - 1) {
          error = FTError.LOAD_INVALID_ARGUMENT;
          return error;
        }
        /* XXX: check the tags array */
        return error;
      }
      return error;
    }

    /* =====================================================================
     * FTOutlineTranslate
     * =====================================================================
     */
    public static void FTOutlineTranslate(FTReference<FTOutlineRec> outline_ref,
            long xOffset, long yOffset) {
      FTOutlineRec outline = outline_ref.Get();
      short n;


Debug(0, DBG_RENDER, TAG, "FTOutlineTranslate");
      if (outline  == null) {
        return;
      }
      for (n = 0; n < outline.n_points; n++) {
        outline.points[n].x += xOffset;
        outline.points[n].y += yOffset;
      }
      outline_ref.Set(outline);
    }

    /* =====================================================================
     * FTOutlineTransform
     * =====================================================================
     */
    public static void FTOutlineTransform(FTReference<FTOutlineRec> outline_ref,
            FTReference<FTMatrixRec> matrix_ref) {
      FTOutlineRec outline = outline_ref.Get();
      FTMatrixRec matrix = matrix_ref.Get();
      FTReference<FTVectorRec> vec_ref = new FTReference<FTVectorRec>();
      FTVectorRec vec;
      int limit;
      int vecIdx = 0;

      if (outline == null || matrix == null) {
        return;
      }
      vec = outline.points[vecIdx];
      limit = outline.n_points;
      for ( ; vecIdx < limit; vecIdx++) {
        vec = outline.points[vecIdx];
        vec_ref.Set(vec);
        FTVectorTransform(vec_ref, matrix_ref);
        outline.points[vecIdx] = vec_ref.Get();
      }
      outline_ref.Set(outline);
      matrix_ref.Set(matrix);
    }
    
    /* =====================================================================
     * FTVectorTransform
     * =====================================================================
     */
    public static void FTVectorTransform(FTReference<FTVectorRec> vector_ref, FTReference<FTMatrixRec> matrix_ref) {
      FTVectorRec vector = vector_ref.Get();
      FTMatrixRec matrix = matrix_ref.Get();
      long xz;
      long yz;

      if (vector == null || matrix == null) {
        return;
      }
      xz = FTCalc.FTMulFix(vector.x, matrix.xx) + FTCalc.FTMulFix(vector.y, matrix.xy);
      yz = FTCalc.FTMulFix(vector.x, matrix.yx) + FTCalc.FTMulFix(vector.y, matrix.yy);
      vector.x = xz;
      vector.y = yz;
      vector_ref.Set(vector);
      matrix_ref.Set(matrix);
    }
    
    /* =====================================================================
     * FTOutlineGetCBox
     * =====================================================================
     */
    public static void FTOutlineGetCBox(FTReference<FTOutlineRec> outline_ref, FTReference<FTBBoxRec> cbox_ref) {
      FTBBoxRec cbox = cbox_ref.Get();
      FTOutlineRec outline = outline_ref.Get();
      long xMin;
      long yMin;
      long xMax;
      long yMax;

System.out.println(String.format("FTOutlineGetCBox: n_points: %d", outline.n_points));
      if (outline != null && cbox != null) {
        if (outline.n_points == 0) {
          xMin = 0;
          yMin = 0;
          xMax = 0;
          yMax = 0;
        } else {
          int vecIdx = 0;
          int limit = outline.n_points;
          FTVectorRec vec;

int i;
for (i = 0; i < outline.n_points; i++) {
Debug(0, DBG_RENDER, TAG, String.format("FTOutLineGetCBox: i: %d x: %d y: %d\n", i, outline.points[i].x, outline.points[i].y));
}
          vec = outline.points[vecIdx];
          xMin = xMax = vec.x;
          yMin = yMax = vec.y;
          vecIdx++;
Debug(0, DBG_RENDER, TAG, String.format("xMin: xMin: %d xMax: %d yMin: %d yMax: %d vecIdx: %d", xMin, xMax, yMin, yMax, vecIdx));

          for ( ; vecIdx < limit; vecIdx++) {
            long x;
            long y;

            vec = outline.points[vecIdx];
Debug(0, DBG_RENDER, TAG, String.format("vec: %d %d %d", vecIdx, vec.x, vec.y));
            x = vec.x;
            if (x < xMin) {
              xMin = x;
            }
            if (x > xMax) {
              xMax = x;
            }
            y = vec.y;
            if (y < yMin) {
              yMin = y;
            }
            if (y > yMax) {
              yMax = y;
            }
          }
        }
        cbox.xMin = xMin;
        cbox.xMax = xMax;
        cbox.yMin = yMin;
        cbox.yMax = yMax;
Debug(0, DBG_RENDER, TAG, String.format("FTOutlineGetCBox end:: xMin: %d xMax: %d yMin: %d yMax: %d", xMin, xMax, yMin, yMax));
      }
      cbox_ref.Set(cbox);
    }

    
    /* =====================================================================
     * clear
     * =====================================================================
     */
    public void clear() {
      n_contours = 0;
      n_points = 0;
//      points = null;
//      tags = null;
//      contours = null;
      flags = 0;
      points_idx = 0;
      tags_idx = 0;
      contours_idx = 0;
    }
 
    /* =====================================================================
     *    FTOutlineDecompose
     *
     * =====================================================================
     */
    public static int FTOutlineDecompose(FTReference<FTOutlineRec> outline_ref, FTOutlineFuncs func_interface, Object user) {
      int error = 0;
      FTOutlineRec outline = outline_ref.Get();
      FTVectorRec v_last;
      FTVectorRec v_control = new FTVectorRec();
      FTVectorRec v_start;
      int pointIdx;
      int limit;
      int tagsIdx;
      int n;        /* index of contour in outline     */
      int first = 0; /* index of first point in contour */
      int tag;       /* current point's state           */
      int shift;
      long delta;
      boolean doConic = true;
      boolean doContinue = false;
      boolean isClosed = false;

Debug(0, DBG_RENDER, TAG, "ftoutline FTOutlineDecompose");
      if (outline == null || func_interface == null) {
        return FTError.RENDER_INVALID_ARGUMENT;
      }
      shift = func_interface.shift;
      delta = func_interface.delta;
      first = 0;
      for (n = 0; n < outline.n_contours; n++) {
        int last;  /* index of last point in contour */

        FTTrace.Trace(7, TAG, String.format("ftoutline FT_Outline_Decompose: Outline %d of %d", n, outline.n_contours));
        last = outline.contours[n];
        if (last < 0) {
          return FTError.RENDER_INVALID_OUTLINE;
        }
        limit = last;
        v_start = outline.points[first];
Debug(0, DBG_RENDER, TAG, String.format("first: %d,  last: %d, v_start.x: %d, v_start.y: %d", first, last, v_start.x, v_start.y));
Debug(0, DBG_RENDER, TAG, String.format("delta: %d, shift: %d", delta, shift));
        v_start.x = (((v_start.x) << shift) - delta);
        v_start.y = (((v_start.y) << shift) - delta);
        v_last = outline.points[last];
Debug(0, DBG_RENDER, TAG, String.format("v_last.x: %d, v_last.y: %d", v_last.x, v_last.y));
        v_last.x = (((v_last.x) << shift) - delta);
        v_last.y = (((v_last.y) << shift) - delta);
        v_control.x = v_start.x;
        v_control.y = v_start.y;
Debug(0, DBG_RENDER, TAG, String.format("v_start: %d %d v_last: %d %d", v_start.x, v_start.y, v_last.x, v_last.y));
        pointIdx = first;
        tagsIdx = first;
        tag = outline.tags[tagsIdx] & 3;
        /* A contour cannot start with a cubic control point! */
        if (tag == FT_CURVE_TAG_CUBIC) {
          return FTError.RENDER_INVALID_OUTLINE;
        }
        /* check first point to determine origin */
        if (tag == FT_CURVE_TAG_CONIC) {
          /* first point is conic control.  Yes, this happens. */
          if ((outline.tags[last] & 3) == FT_CURVE_TAG_ON) {
            /* start at last point if it is on the curve */
            v_start.x = v_last.x;
            v_start.y = v_last.y;
            limit--;
          } else {
            /* if both first and last points are conic,         */
            /* start at their middle and record its position    */
            /* for closure                                      */
            v_start.x = (v_start.x + v_last.x) / 2;
            v_start.y = (v_start.y + v_last.y) / 2;
            v_last.x = v_start.x;
            v_last.y = v_start.y;
          }
          pointIdx--;
          tagsIdx--;
        }
Debug(0, DBG_RENDER, TAG, "Decompose:");
        FTTrace.Trace(7, TAG, String.format("  move to (%.2f, %.2f)",
                    v_start.x / 64.0, v_start.y / 64.0));
        error = (int)func_interface.move_to.callClassMethod(v_start, user);
        FTTrace.Trace(7, TAG, String.format("  move to after (%.2f, %.2f)",
            v_start.x / 64.0, v_start.y / 64.0));
        if (error != 0) {
          FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
          return error;
        }
        while (pointIdx < limit) {
Debug(0, DBG_RENDER, TAG, String.format("decompose1: pointIdx: %d, limit: %d, n: %d, outline.n_contours: %d", pointIdx, limit, n, outline.n_contours));
Debug(0, DBG_RENDER, TAG, String.format("==2 v_start.x: %d, v_start.y: %d", v_start.x, v_start.y));
          pointIdx++;
          tagsIdx++;
          tag = outline.tags[tagsIdx] & 3;
          switch (tag)
          {
          case FT_CURVE_TAG_ON:  /* emit a single line_to */
            {
              FTVectorRec vec = new FTVectorRec();

Debug(0, DBG_RENDER, TAG, "FT_CURVE_TAG_ON");
              vec.x = (((outline.points[pointIdx].x) << shift) - delta);
              vec.y = (((outline.points[pointIdx].y) << shift) - delta);
              FTTrace.Trace(7, TAG, String.format("  line to (%.2f, %.2f)\n",
                          vec.x / 64.0, vec.y / 64.0));
              error = (int)func_interface.line_to.callClassMethod(vec, user);
              if (error != 0) {
                FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
                return error;
              }
              continue;
            }
          case FT_CURVE_TAG_CONIC:  /* consume conic arcs */
Debug(0, DBG_RENDER, TAG, "FT_CURVE_TAG_CONIC");
Debug(0, DBG_RENDER, TAG, String.format("==3a v_start.x: %d, v_start.y: %d", v_start.x, v_start.y));
            v_control.x = (((outline.points[pointIdx].x) << shift) - delta);
            v_control.y = (((outline.points[pointIdx].y) << shift) - delta);
            doConic = true;
            while (doConic) {
Debug(0, DBG_RENDER, TAG, String.format("decompose doConic: pointIdx: %d,  limit: %d", pointIdx, limit));
              doConic = false;
Debug(0, DBG_RENDER, TAG, String.format("==3b v_start.x: %d, v_start.y: %d", v_start.x, v_start.y));
              doContinue = false;
              if (pointIdx < limit) {
                FTVectorRec vec = new FTVectorRec();
                FTVectorRec v_middle = new FTVectorRec();

                pointIdx++;
                tagsIdx++;
                tag = outline.tags[tagsIdx] & 3;
                vec.x = (((outline.points[pointIdx].x) << shift) - delta);
                vec.y = (((outline.points[pointIdx].y) << shift) - delta);
Debug(0, DBG_RENDER, TAG, String.format("tag: %d, tagIdx: %d, pointIdx: %d, limit: %d, vec.x: %d, vec.y: %d", tag, tagsIdx, pointIdx, limit, vec.x, vec.y));
                if (tag == FT_CURVE_TAG_ON) {
                  FTTrace.Trace(0, TAG, String.format("  1 conic to (%.2f, %.2f)"+
                            " with control (%.2f, %.2f)",
                            vec.x / 64.0, vec.y / 64.0,
                            v_control.x / 64.0, v_control.y / 64.0));
                  error = (int)func_interface.conic_to.callClassMethod(v_control, vec, user);
Debug(0, DBG_RENDER, TAG, "Decompose2: after call conic_to");
                  if (error != 0) {
                    FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
                    return error;
                  }
                  doContinue = true;
                  break;
                }
                if (tag != FT_CURVE_TAG_CONIC) {
                  return FTError.RENDER_INVALID_OUTLINE;
                }
                v_middle.x = ( v_control.x + vec.x ) / 2;
                v_middle.y = ( v_control.y + vec.y ) / 2;
                FTTrace.Trace(7, TAG, String.format("  2 conic to (%.2f, %.2f)"+
                          " with control (%.2f, %.2f)",
                          v_middle.x / 64.0, v_middle.y / 64.0,
                          v_control.x / 64.0, v_control.y / 64.0));
                error = (int)func_interface.conic_to.callClassMethod(v_control, v_middle, user);
 Debug(0, DBG_RENDER, TAG, "Decompose3: after call conic_to");
                if (error != 0) {
                  FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
                  return error;
                }
                v_control.x = vec.x;
                v_control.y = vec.y;
                doConic = true;
Debug(0, DBG_RENDER, TAG, String.format("==4a v_start.x: %d, v_start.y: %d", v_start.x, v_start.y));
              }
            }
Debug(0, DBG_RENDER, TAG, String.format("==4b v_start.x: %d, v_start.y: %d", v_start.x, v_start.y));
            if (doContinue) {
              continue;
            }
            FTTrace.Trace(8, TAG, String.format(" 3 conic to (%.2f, %.2f)"+
                        " with control (%.2f, %.2f)",
                        v_start.x / 64.0, v_start.y / 64.0,
                        v_control.x / 64.0, v_control.y / 64.0));
            error = (int)func_interface.conic_to.callClassMethod(v_control, v_start, user);
            if (error != 0) {
              FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
              return error;
            }
            isClosed = true;
            break;
          default:  /* FT_CURVE_TAG_CUBIC */
            {
              FTVectorRec vec1 = new FTVectorRec();
              FTVectorRec vec2 = new FTVectorRec();

Debug(0, DBG_RENDER, TAG, "FT_CURVE_TAG_CUBIC");
              if (pointIdx + 1 > limit ||
                   (outline.tags[tagsIdx + 1] & 3) != FT_CURVE_TAG_CUBIC) {
                return FTError.RENDER_INVALID_OUTLINE;
              }
              pointIdx += 2;
              tagsIdx += 2;
              vec1.x = (((outline.points[pointIdx - 2].x) << shift) - delta);;
              vec1.y = (((outline.points[pointIdx - 2].y) << shift) - delta);;
              vec2.x = (((outline.points[pointIdx - 1].x) << shift) - delta);;
              vec2.y = (((outline.points[pointIdx - 1].y) << shift) - delta);;
              if (pointIdx <= limit) {
                FTVectorRec vec = new FTVectorRec();

                vec.x = (((outline.points[pointIdx].x) << shift) - delta);;
                vec.y = (((outline.points[pointIdx].y) << shift) - delta);
                FTTrace.Trace(7, TAG, String.format(" 1 cubic to (%.2f, %.2f)"+
                            " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
                            vec.x / 64.0, vec.y / 64.0,
                            vec1.x / 64.0, vec1.y / 64.0,
                            vec2.x / 64.0, vec2.y / 64.0));
                error = (int)func_interface.cubic_to.callClassMethod(vec1, vec2, vec, user);
                if (error != 0) {
                  FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
                  return error;
                }
                continue;
              }
              FTTrace.Trace(7, TAG, String.format(" 2 cubic to (%.2f, %.2f)"+
                          " with controls (%.2f, %.2f) and (%.2f, %.2f)",
                          v_start.x / 64.0, v_start.y / 64.0,
                          vec1.x / 64.0, vec1.y / 64.0,
                          vec2.x / 64.0, vec2.y / 64.0));
              error = (int)func_interface.cubic_to.callClassMethod(vec1, vec2, v_start, user);
              if (error != 0) {
                FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
                return error;
              }
              isClosed = true;
              break;
            }
          }
        }
Debug(0, DBG_RENDER, TAG, String.format("==5 v_start.x: %d, v_start.y: %d", v_start.x, v_start.y));
        if (! isClosed) {
          /* close the contour with a line segment */
          FTTrace.Trace(7, TAG, String.format(" 2 line to (%.2f, %.2f)",
                    v_start.x / 64.0, v_start.y / 64.0));
          error = (int)func_interface.line_to.callClassMethod(v_start, user);
        }
        if (error != 0) {
          FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
          return error;
        }
        first = last + 1;
      }

      FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Done %d", n));
      return FTError.INTERP_ERR_OK;
    }

}