ApwFreetypeLibrary

Check-in [b5c63cad02]
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:b5c63cad0202542d74176ab3a4f9be45eb32cb66
User & Date: arnulf 2014-12-29 21:46:57
Context
2014-12-29
23:19
fixes. check-in: 10229f2a18 user: arnulf tags: trunk
21:46
initial version check-in: b5c63cad02 user: arnulf tags: trunk
21:46
initial version. check-in: e10740ef9b user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

  /* ===================================================================== */
  /*    FTBBoxRec                                                             */
  /* <Description>                                                         */
  /*    A structure used to hold an outline's bounding box, i.e., the      */
  /*    coordinates of its extrema in the horizontal and vertical          */
  /*    directions.                                                        */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    xMin :: The horizontal minimum (left-most).                        */
  /*                                                                       */
  /*    yMin :: The vertical minimum (bottom-most).                        */
  /*                                                                       */
  /*    xMax :: The horizontal maximum (right-most).                       */
  /*                                                                       */
  /*    yMax :: The vertical maximum (top-most).                           */
  /*                                                                       */
  /* <Note>                                                                */
  /*    The bounding box is specified with the coordinates of the lower    */
  /*    left and the upper right corner.  In PostScript, those values are  */
  /*    often called (llx,lly) and (urx,ury), respectively.                */
  /*                                                                       */
  /*    If `yMin' is negative, this value gives the glyph's descender.     */
  /*    Otherwise, the glyph doesn't descend below the baseline.           */
  /*    Similarly, if `ymax' is positive, this value gives the glyph's     */
  /*    ascender.                                                          */
  /*                                                                       */
  /*    `xMin' gives the horizontal distance from the glyph's origin to    */
  /*    the left edge of the glyph's bounding box.  If `xMin' is negative, */
  /*    the glyph extends to the left of the origin.                       */
  /*                                                                       */
  /*                                                                       */
  /* ===================================================================== */

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

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

    public long xMin = 0L;
    public long xMax = 0L;
    public long yMin = 0L;
    public long yMax = 0L;

    /* ==================== FTBBoxRec ================================== */
    public FTBBoxRec() {
      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/FTCalc.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
/* =====================================================================
 *  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;

  /* ===================================================================== */
  /*    FTCalc                                                          */
  /*                                                                       */
  /* ===================================================================== */

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

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

    /* ==================== FTCalc ================================== */
    public FTCalc() {
      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();
    }
 
    /* ==================== FT_PAD_FLOOR ===================================== */
    public static long FT_PAD_FLOOR(long x, int n) {
        return (x & ~(n - 1));
    }

    /* ==================== FT_PAD_ROUND ===================================== */
    public static long FT_PAD_ROUND(long x, int n) {
      return FT_PAD_FLOOR(x + (n / 2), n);
    }

    /* ==================== FT_PAD_CEIL ===================================== */
    public static Long FT_PAD_CEIL(long x, int n) {
        return FT_PAD_FLOOR(x + (n - 1), n);
    }

    /* ==================== FT_PIX_FLOOR ===================================== */
    public static long FT_PIX_FLOOR(long x) {
        return (x & ~63);
    }

    /* ==================== FT_PIX_ROUND ===================================== */
    public static long FT_PIX_ROUND(long x) {
        return FT_PIX_FLOOR(x + 32);
    }

    /* ==================== FT_PIX_CEIL ===================================== */
    public static long FT_PIX_CEIL(long x) {
        return FT_PIX_FLOOR(x + 63);
    }

    /* ==================== FT_ABS ===================================== */
    public static long FT_ABS(long a) {
        return (a < 0) ? -a : a;
    }

    /* ==================== FT_MulDivNoRound ===================================== */
    public static long FT_MulDivNoRound(long a, long b, long c) {
      long  s;
      Long  d;

      s = 1;
      if (a < 0) {
        a = -a;
       	s = -1;
      }
      if (b < 0) {
        b = -b;
       	s = -s;
      }
      if (c < 0) {
        c = -c;
       	s = -s;
      }
      d = (c > 0 ? a * b / c : 0x7FFFFFFFL);
      return (s > 0) ? d : -d;
    }

    /* ==================== FT_MulDiv ===================================== */
    public static long FT_MulDiv(long a, long b, long c) {
      long  s;
      long  d;


      s = 1L;
      if (a < 0) {
        a = -a;
       	s = -1L;
      }
      if (b < 0) {
        b = -b;
       	s = -s;
      }
      if (c < 0) {
        c = -c;
       	s = -s;
      }
      d = c > 0 ? (a * b + (c >> 1)) / c : 0x7FFFFFFFL;
      return (s > 0) ? d : -d;
    }

    /* =====================================================================
     *    FTDivFix
     *
     * <Description>
     *    A very simple function used to perform the computation
     *    `(a*0x10000)/b' with maximum accuracy.  Most of the time, this is
     *    used to divide a given value by a 16.16 fixed-point factor.
     *
     * <Input>
     *    a :: The first multiplier.
     *    b :: The second multiplier.  Use a 16.16 factor here whenever
     *         possible (see note below).
     *
     * <Return>
     *    The result of `(a*0x10000)/b'.
     *
     * <Note>
     *    The optimization for FTDivFix() is simple: If (a~<<~16) fits in
     *    32~bits, then the division is computed directly.  Otherwise, we
     *    use a specialized version of @FT_MulDiv.
     * =====================================================================
     */

    public static long FTDivFix(long a, long b) {
      long s;
      long q;

      s = 1L;
      if (a < 0) {
        a = -a;
        s = -1L;
      }
      if (b < 0) {
        b = -b;
        s = -s;
      }
      if (b == 0) {
        /* check for division by 0 */
        q = 0x7FFFFFFFL;
      } else {
        /* compute result directly */
        q = (long)((((a << 16) + (b >> 1)) / b));
      }
      return (s < 0 ? -q : q);
    }

    /* ==================== FTMulFix ===================================== */
    public static long FTMulFix(long a, long b) {
      int s = 1;
      long  c;

      if (a < 0) {
        a = -a;
        s = -1;
      }
      if (b < 0) {
        b = -b;
        s = -s;
      }
      c = (a * b + 0x8000L) >> 16;
      return (s > 0) ? c : -c;
    }

    /* ==================== FT_MSB ===================================== */
    public static int FT_MSB(long z) {
      int shift = 0;

      /* determine msb bit index in `shift' */
      if (z >= (1L << 16)) {
        z >>= 16;
        shift += 16;
      }
      if (z >= (1L << 8)) {
        z >>= 8;
        shift += 8;
      }
      if (z >= (1L << 4)) {
        z >>= 4;
        shift += 4;
      }
      if (z >= (1L << 2)) {
        z >>= 2;
        shift += 2;
      }
      if (z >= (1L << 1)) {
        z >>= 1;
        shift += 1;
      }
      return shift;
    }

    /* ==================== FTHypot ===================================== */
    public static long FTHypot(long x, long y) {
      FTVectorRec v = new FTVectorRec();
      v.x = x;
      v.y = y;
      return FTTrigonometric.FTVectorLength(v);
    }

}

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

  /* ===================================================================== */
  /*    FTCharMapRec                                                       */
  /* <Description>                                                         */
  /*    The base charmap structure.                                        */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    face        :: A handle to the parent face object.                 */
  /*                                                                       */
  /*    encoding    :: An @FT_Encoding tag identifying the charmap.  Use   */
  /*                   this with @FT_Select_Charmap.                       */
  /*                                                                       */
  /*    platform_id :: An ID number describing the platform for the        */
  /*                   following encoding ID.  This comes directly from    */
  /*                   the TrueType specification and should be emulated   */
  /*                   for other formats.                                  */
  /*                                                                       */
  /*    encoding_id :: A platform specific encoding number.  This also     */
  /*                   comes from the TrueType specification and should be */
  /*                   emulated similarly.                                 */
  /*                                                                       */
  /* <Values>                                                              */
  /*    FT_ENCODING_NONE ::                                                */
  /*      The encoding value~0 is reserved.                                */
  /*                                                                       */
  /*    FT_ENCODING_UNICODE ::                                             */
  /*      Corresponds to the Unicode character set.  This value covers     */
  /*      all versions of the Unicode repertoire, including ASCII and      */
  /*      Latin-1.  Most fonts include a Unicode charmap, but not all      */
  /*      of them.                                                         */
  /*                                                                       */
  /*      For example, if you want to access Unicode value U+1F028 (and    */
  /*      the font contains it), use value 0x1F028 as the input value for  */
  /*      @FT_Get_Char_Index.                                              */
  /*                                                                       */
  /*    FT_ENCODING_MS_SYMBOL ::                                           */
  /*      Corresponds to the Microsoft Symbol encoding, used to encode     */
  /*      mathematical symbols in the 32..255 character code range.  For   */
  /*      more information, see `http://www.ceviz.net/symbol.htm'.         */
  /*                                                                       */
  /*    FT_ENCODING_SJIS ::                                                */
  /*      Corresponds to Japanese SJIS encoding.  More info at             */
  /*      at `http://langsupport.japanreference.com/encoding.shtml'.       */
  /*      See note on multi-byte encodings below.                          */
  /*                                                                       */
  /*    FT_ENCODING_GB2312 ::                                              */
  /*      Corresponds to an encoding system for Simplified Chinese as used */
  /*      used in mainland China.                                          */
  /*                                                                       */
  /*    FT_ENCODING_BIG5 ::                                                */
  /*      Corresponds to an encoding system for Traditional Chinese as     */
  /*      used in Taiwan and Hong Kong.                                    */
  /*                                                                       */
  /*    FT_ENCODING_WANSUNG ::                                             */
  /*      Corresponds to the Korean encoding system known as Wansung.      */
  /*      For more information see                                         */
  /*      `http://www.microsoft.com/typography/unicode/949.txt'.           */
  /*                                                                       */
  /*    FT_ENCODING_JOHAB ::                                               */
  /*      The Korean standard character set (KS~C 5601-1992), which        */
  /*      corresponds to MS Windows code page 1361.  This character set    */
  /*      includes all possible Hangeul character combinations.            */
  /*                                                                       */
  /*    FT_ENCODING_ADOBE_LATIN_1 ::                                       */
  /*      Corresponds to a Latin-1 encoding as defined in a Type~1         */
  /*      PostScript font.  It is limited to 256 character codes.          */
  /*                                                                       */
  /*    FT_ENCODING_ADOBE_STANDARD ::                                      */
  /*      Corresponds to the Adobe Standard encoding, as found in Type~1,  */
  /*      CFF, and OpenType/CFF fonts.  It is limited to 256 character     */
  /*      codes.                                                           */
  /*                                                                       */
  /*    FT_ENCODING_ADOBE_EXPERT ::                                        */
  /*      Corresponds to the Adobe Expert encoding, as found in Type~1,    */
  /*      CFF, and OpenType/CFF fonts.  It is limited to 256 character     */
  /*      codes.                                                           */
  /*                                                                       */
  /*    FT_ENCODING_ADOBE_CUSTOM ::                                        */
  /*      Corresponds to a custom encoding, as found in Type~1, CFF, and   */
  /*      OpenType/CFF fonts.  It is limited to 256 character codes.       */
  /*                                                                       */
  /*    FT_ENCODING_APPLE_ROMAN ::                                         */
  /*      Corresponds to the 8-bit Apple roman encoding.  Many TrueType    */
  /*      and OpenType fonts contain a charmap for this encoding, since    */
  /*      older versions of Mac OS are able to use it.                     */
  /*                                                                       */
  /*    FT_ENCODING_OLD_LATIN_2 ::                                         */
  /*      This value is deprecated and was never used nor reported by      */
  /*      FreeType.  Don't use or test for it.                             */
  /*                                                                       */
  /*    FT_ENCODING_MS_SJIS ::                                             */
  /*      Same as FT_ENCODING_SJIS.  Deprecated.                           */
  /*                                                                       */
  /*    FT_ENCODING_MS_GB2312 ::                                           */
  /*      Same as FT_ENCODING_GB2312.  Deprecated.                         */
  /*                                                                       */
  /*    FT_ENCODING_MS_BIG5 ::                                             */
  /*      Same as FT_ENCODING_BIG5.  Deprecated.                           */
  /*                                                                       */
  /*    FT_ENCODING_MS_WANSUNG ::                                          */
  /*      Same as FT_ENCODING_WANSUNG.  Deprecated.                        */
  /*                                                                       */
  /*    FT_ENCODING_MS_JOHAB ::                                            */
  /*      Same as FT_ENCODING_JOHAB.  Deprecated.                          */
  /*                                                                       */
  /* <Note>                                                                */
  /*    By default, FreeType automatically synthesizes a Unicode charmap   */
  /*    for PostScript fonts, using their glyph names dictionaries.        */
  /*    However, it also reports the encodings defined explicitly in the   */
  /*    font file, for the cases when they are needed, with the Adobe      */
  /*    values as well.                                                    */
  /*                                                                       */
  /*    FT_ENCODING_NONE is set by the BDF and PCF drivers if the charmap  */
  /*    is neither Unicode nor ISO-8859-1 (otherwise it is set to          */
  /*    FT_ENCODING_UNICODE).  Use @FT_Get_BDF_Charset_ID to find out      */
  /*    which encoding is really present.  If, for example, the            */
  /*    `cs_registry' field is `KOI8' and the `cs_encoding' field is `R',  */
  /*    the font is encoded in KOI8-R.                                     */
  /*                                                                       */
  /*    FT_ENCODING_NONE is always set (with a single exception) by the    */
  /*    winfonts driver.  Use @FT_Get_WinFNT_Header and examine the        */
  /*    `charset' field of the @FT_WinFNT_HeaderRec structure to find out  */
  /*    which encoding is really present.  For example,                    */
  /*    @FT_WinFNT_ID_CP1251 (204) means Windows code page 1251 (for       */
  /*    Russian).                                                          */
  /*                                                                       */
  /*    FT_ENCODING_NONE is set if `platform_id' is @TT_PLATFORM_MACINTOSH */
  /*    and `encoding_id' is not @TT_MAC_ID_ROMAN (otherwise it is set to  */
  /*    FT_ENCODING_APPLE_ROMAN).                                          */
  /*                                                                       */
  /*    If `platform_id' is @TT_PLATFORM_MACINTOSH, use the function       */
  /*    @FT_Get_CMap_Language_ID  to query the Mac language ID which may   */
  /*    be needed to be able to distinguish Apple encoding variants.  See  */
  /*                                                                       */
  /*      http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/README.TXT  */
  /*                                                                       */
  /*    to get an idea how to do that.  Basically, if the language ID      */
  /*    is~0, don't use it, otherwise subtract 1 from the language ID.     */
  /*    Then examine `encoding_id'.  If, for example, `encoding_id' is     */
  /*    @TT_MAC_ID_ROMAN and the language ID (minus~1) is                  */
  /*    `TT_MAC_LANGID_GREEK', it is the Greek encoding, not Roman.        */
  /*    @TT_MAC_ID_ARABIC with `TT_MAC_LANGID_FARSI' means the Farsi       */
  /*    variant the Arabic encoding.                                       */
  /* ===================================================================== */

import ftcache.FTCMapRec;

public class FTCharMapRec extends ftbase.FTEncoding {
    private static int oid = 0;

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

    public final static int TT_PLATFORM_APPLE_UNICODE = 0;
    public final static int TT_PLATFORM_MACINTOSH     = 1;
    public final static int TT_PLATFORM_ISO           = 2; /* deprecated */
    public final static int TT_PLATFORM_MICROSOFT     = 3;
    public final static int TT_PLATFORM_CUSTOM        = 4;
    public final static int TT_PLATFORM_ADOBE         = 7; /* artificial */

    public final static int  TT_MS_ID_SYMBOL_CS  =  0;
    public final static int  TT_MS_ID_UNICODE_CS =  1;
    public final static int  TT_MS_ID_SJIS       =  2;
    public final static int  TT_MS_ID_GB2312     =  3;
    public final static int  TT_MS_ID_BIG_5      =  4;
    public final static int  TT_MS_ID_WANSUNG    =  5;
    public final static int  TT_MS_ID_JOHAB      =  6;
    public final static int  TT_MS_ID_UCS_4      = 10;

    public final static int  TT_APPLE_ID_DEFAULT          = 0; /* Unicode 1.0 */
    public final static int  TT_APPLE_ID_UNICODE_1_1      = 1; /* specify Hangul at U+34xx */
    public final static int  TT_APPLE_ID_ISO_10646        = 2; /* deprecated */
    public final static int  TT_APPLE_ID_UNICODE_2_0      = 3; /* or later */
    public final static int  TT_APPLE_ID_UNICODE_32       = 4; /* 2.0 or later, full repertoire */
    public final static int  TT_APPLE_ID_VARIANT_SELECTOR = 5; /* variation selector data */


    public ftbase.FTFaceRec face = null;
    public long encoding = 0L;
    public short platform_id = 0;
    public short encoding_id = 0;

    /* ==================== FTCharMapRec ================================== */
    public FTCharMapRec() {
    }
    
    /* ==================== FTCharMapRec ================================== */
    public FTCharMapRec(ftbase.FTStreamRec stream) {
      oid++;
      id = oid;
//      if (frame_info.size() == 0) {
//        va = new FTInstanceVariable(my_class_name, this, "format_tag", 1);
//        frame_info.add(new FTFrameEntry("format_tag", va, readInt, VAR_IS_INT));
//      }
//      fillVariables();
Debug(0, DBG_CACHE, TAG, "FTCharMapRec offset: "+String.format("0x%08x", stream.pos()));
      encoding = (long)stream.readInt(stream);
      platform_id = stream.readShort(stream);
      encoding_id = stream.readShort(stream);
    }
    
    /* ==================== 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();
    }
 
    /* =====================================================================
     * FTGetCharmapIndex
     * =====================================================================
     */
    public static int  FTGetCharmapIndex(FTCharMapRec charmap) {
      int i;

      if (charmap == null || charmap.face == null) {
        return -1;
      }
      for (i = 0; i < charmap.face.num_charmaps; i++) {
        if (charmap.face.charmaps[i] == charmap) {
          break;
        }
      }
      if (i >= charmap.face.num_charmaps) {
        return -1;
      }
      return i;
    }

    /* =====================================================================
     * FTSelectCharmap
     * =====================================================================
     */
    public int FTSelectCharmap(FTFaceRec face, long encoding) {
      FTCharMapRec cur;
      int limit;


      if (face == null) {
        return FTError.INTERP_INVALID_FACE_HANDLE;
      }
      if (encoding == FT_ENCODING_NONE) {
        return FTError.INTERP_INVALID_ARGUMENT;
      }
      /* FT_ENCODING_UNICODE is special.  We try to find the `best' Unicode */
      /* charmap available, i.e., one with UCS-4 characters, if possible.   */
      /*                                                                    */
      /* This is done by find_unicode_charmap() above, to share code.       */
      if (encoding == FT_ENCODING_UNICODE) {
//        return find_unicode_charmap(face);
        return FTError.INTERP_NOT_YET_IMPLEMENTED;
      }
      cur = face.charmaps[0];
      if (cur == null) {
        return FTError.INTERP_INVALID_CHARMAP_HANDLE;
      }
      limit = face.num_charmaps;
      for (int j = 0; j < limit; j++) {
        cur = face.charmaps[j];
        if (cur.encoding == encoding) {
          face.charmap = cur;
          return ftbase.FTError.INTERP_ERR_OK;
        }
      }
      return ftbase.FTError.INTERP_INVALID_ARGUMENT;
    }

    /* =====================================================================
     * FTGetCharIndex
     * =====================================================================
     */
    public static int FTGetCharIndex(ftbase.FTFaceRec face, int charcode) {
      int result = 0;
      Integer ch_code = charcode;
  
      if (face != null && face.charmap != null) {
        FTCMapRec cmap = (FTCMapRec)(face.charmap);
  
        if (charcode > 0xFFFFFFFFL) {
          ftbase.FTTrace.Trace(7, TAG, "FT_Get_Char_Index: too large charcode");
          ftbase.FTTrace.Trace(7, TAG, String.format(" 0x%x is truncated", charcode));
        }
        result = (int)cmap.clazz.char_index.callClassMethod((Object)cmap, (Object)ch_code);
      }
Debug(0, DBG_CACHE, TAG, String.format("FTGetCharIndex: 0x%04x %d", charcode, result));
      return result;
    }

    /* =====================================================================
     * find_unicode_charmap
     * =====================================================================
     */
    public static int  find_unicode_charmap(ftbase.FTFaceRec face) {
      int error = 0;
      FTCharMapRec first;
      FTCharMapRec cur;
      int charmaps_idx = 0;
  
      /* caller should have already checked that `face' is valid */
 //     FT_ASSERT( face );
  
Debug(0, DBG_CACHE, TAG, "find_unicode_charmap:");
      first = face.charmaps[charmaps_idx];
      if (first == null) {
        return ftbase.FTError.LOAD_INVALID_CHARMAP_HANDLE;
      } 
      /*
       *  The original TrueType specification(s) only specified charmap
       *  formats that are capable of mapping 8 or 16 bit character codes to
       *  glyph indices.
       *
       *  However, recent updates to the Apple and OpenType specifications
       *  introduced new formats that are capable of mapping 32-bit character
       *  codes as well.  And these are already used on some fonts, mainly to
       *  map non-BMP Asian ideographs as defined in Unicode.
       *
       *  For compatibility purposes, these fonts generally come with
       *  *several* Unicode charmaps:
       *
       *   - One of them in the "old" 16-bit format, that cannot access
       *     all glyphs in the font.
       *
       *   - Another one in the "new" 32-bit format, that can access all
       *     the glyphs.
       *
       *  This function has been written to always favor a 32-bit charmap
       *  when found.  Otherwise, a 16-bit one is returned when found.
       */
  
      /* Since the `interesting' table, with IDs (3,10), is normally the */
      /* last one, we loop backwards.  This loses with type1 fonts with  */
      /* non-BMP characters (<.0001%), this wins with .ttf with non-BMP  */
      /* chars (.01% ?), and this is the same about 99.99% of the time!  */
  
      charmaps_idx = face.num_charmaps - 1;
      for ( ; charmaps_idx >= 0; charmaps_idx--) {
        cur = face.charmaps[charmaps_idx];
        if (cur.encoding == FT_ENCODING_UNICODE ) {
          /* XXX If some new encodings to represent UCS-4 are added, */
          /*     they should be added here.                          */
          if ((cur.platform_id == FTCharMapRec.TT_PLATFORM_MICROSOFT && cur.encoding_id == TT_MS_ID_UCS_4)     ||
               (cur.platform_id == TT_PLATFORM_APPLE_UNICODE && cur.encoding_id == FTCharMapRec.TT_APPLE_ID_UNICODE_32)) {
            face.charmap = cur;
            return ftbase.FTError.INTERP_ERR_OK;
          }
        }
      }
      /* We do not have any UCS-4 charmap.                */
      /* Do the loop again and search for UCS-2 charmaps. */
      charmaps_idx = face.num_charmaps - 1;
      for ( ; charmaps_idx >= 0; charmaps_idx--) {
        cur = face.charmaps[charmaps_idx];
        if (cur.encoding == FT_ENCODING_UNICODE) {
          face.charmap = cur;
          return ftbase.FTError.INTERP_ERR_OK;
        }
      }
      return ftbase.FTError.LOAD_INVALID_CHARMAP_HANDLE;
    }

}

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

  /* ===================================================================== */
  /*    FTDriverClassRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTDriverClassRec extends FTModuleClassRec {
    private static int oid = 0;

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

    public final static int FACE_REC_TYPE_UNKNOWN = 0;
    public final static int SIZE_REC_TYPE_UNKNOWN = 0;
    public final static int SLOT_REC_TYPE_UNKNOWN = 0;
    public final static int FACE_REC_TYPE_TT = 10;
    public final static int SIZE_REC_TYPE_TT = 20;
    public final static int SLOT_REC_TYPE_FT_GLYPH = 30;

    public int face_object_type = FACE_REC_TYPE_UNKNOWN;
    public int size_object_type = SIZE_REC_TYPE_UNKNOWN;
    public int slot_object_type = SLOT_REC_TYPE_UNKNOWN;
    public FTInstanceMethod init_face = null;
    public FTInstanceMethod done_face = null;
    public FTInstanceMethod init_size = null;
    public FTInstanceMethod done_size = null;
    public FTInstanceMethod init_slot = null;
    public FTInstanceMethod done_slot = null;
    public FTInstanceMethod load_glyph = null;
    public FTInstanceMethod get_kerning = null;
    public FTInstanceMethod attach_file = null;
    public FTInstanceMethod get_advances = null;
    public FTInstanceMethod request_size = null;
    public FTInstanceMethod select_size = null;

    /* ==================== FTDriverClassRec ================================== */
    public FTDriverClassRec() {
      super();
      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/FTDriverRec.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
// ----------------------------------------------------------------
// FTDriverRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// 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;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf ont files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTDriverRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTDriverRec extends FTModuleRec {
    private static int oid = 0;

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

    public FTDriverClassRec driver_clazz = null;
    public FTListRec faces_list = null;
    public FTGlyphLoaderRec glyph_loader = null;

    /* ==================== FTDriverRec ================================== */
    public FTDriverRec() {
      super();
      oid++;
      id = oid;
      
      faces_list = new FTListRec("FTDriverRec.faces_list 1");
      FT_Trace.Trace(7, TAG, "faces_list 1 new FTListRec: "+ faces_list.mySelf());
    }
    
    /* ==================== FTDriverRec ================================== */
    public FTDriverRec(FTModuleRec module) {
      oid++;
      id = oid;
      
if (FTInit.initDebug > 2) {
System.out.println("FTDriverRec module: "+module.library);      
}
      this.module_clazz = module.module_clazz;
      this.library = module.library;
      driver_clazz = (FTDriverClassRec)module.module_clazz;
      faces_list = new FTListRec("FTDriverRec.faces_list 2");
      FT_Trace.Trace(7, TAG, "faces_list 2 new FTListRec: "+ faces_list.mySelf());
    }
    
    /* ==================== FTDriverRec ================================== */
    public FTDriverRec(FTDriverClassRec driver_clazz) {
      super();
      oid++;
      id = oid;
      
      this.module_clazz = new FTModuleClassRec();
      this.driver_clazz = driver_clazz;
      faces_list = new FTListRec("FTDriverRec.faces_list 3");
      FT_Trace.Trace(7, TAG, "faces_list 3 new FTListRec: "+ faces_list.mySelf());
      glyph_loader = new FTGlyphLoaderRec();
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
}

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

  /* ===================================================================== */
  /*    FTEncoding                                                          */
  /*                                                                       */
  /* <Description>                                                         */
  /*    An enumeration used to specify character sets supported by         */
  /*    charmaps.  Used in the @FT_Select_Charmap API function.            */
  /*                                                                       */
  /* <Note>                                                                */
  /*    Despite the name, this enumeration lists specific character        */
  /*    repertories (i.e., charsets), and not text encoding methods (e.g., */
  /*    UTF-8, UTF-16, etc.).                                              */
  /*                                                                       */
  /*    Other encodings might be defined in the future.                    */
  /*                                                                       */
  /* <Values>                                                              */
  /*    FT_ENCODING_NONE ::                                                */
  /*      The encoding value~0 is reserved.                                */
  /*                                                                       */
  /*    FT_ENCODING_UNICODE ::                                             */
  /*      Corresponds to the Unicode character set.  This value covers     */
  /*      all versions of the Unicode repertoire, including ASCII and      */
  /*      Latin-1.  Most fonts include a Unicode charmap, but not all      */
  /*      of them.                                                         */
  /*                                                                       */
  /*      For example, if you want to access Unicode value U+1F028 (and    */
  /*      the font contains it), use value 0x1F028 as the input value for  */
  /*      @FT_Get_Char_Index.                                              */
  /*                                                                       */
  /*    FT_ENCODING_MS_SYMBOL ::                                           */
  /*      Corresponds to the Microsoft Symbol encoding, used to encode     */
  /*      mathematical symbols in the 32..255 character code range.  For   */
  /*      more information, see `http://www.ceviz.net/symbol.htm'.         */
  /*                                                                       */
  /*    FT_ENCODING_SJIS ::                                                */
  /*      Corresponds to Japanese SJIS encoding.  More info at             */
  /*      at `http://langsupport.japanreference.com/encoding.shtml'.       */
  /*      See note on multi-byte encodings below.                          */
  /*                                                                       */
  /*    FT_ENCODING_GB2312 ::                                              */
  /*      Corresponds to an encoding system for Simplified Chinese as used */
  /*      used in mainland China.                                          */
  /*                                                                       */
  /*    FT_ENCODING_BIG5 ::                                                */
  /*      Corresponds to an encoding system for Traditional Chinese as     */
  /*      used in Taiwan and Hong Kong.                                    */
  /*                                                                       */
  /*    FT_ENCODING_WANSUNG ::                                             */
  /*      Corresponds to the Korean encoding system known as Wansung.      */
  /*      For more information see                                         */
  /*      `http://www.microsoft.com/typography/unicode/949.txt'.           */
  /*                                                                       */
  /*    FT_ENCODING_JOHAB ::                                               */
  /*      The Korean standard character set (KS~C 5601-1992), which        */
  /*      corresponds to MS Windows code page 1361.  This character set    */
  /*      includes all possible Hangeul character combinations.            */
  /*                                                                       */
  /*    FT_ENCODING_ADOBE_LATIN_1 ::                                       */
  /*      Corresponds to a Latin-1 encoding as defined in a Type~1         */
  /*      PostScript font.  It is limited to 256 character codes.          */
  /*                                                                       */
  /*    FT_ENCODING_ADOBE_STANDARD ::                                      */
  /*      Corresponds to the Adobe Standard encoding, as found in Type~1,  */
  /*      CFF, and OpenType/CFF fonts.  It is limited to 256 character     */
  /*      codes.                                                           */
  /*                                                                       */
  /*    FT_ENCODING_ADOBE_EXPERT ::                                        */
  /*      Corresponds to the Adobe Expert encoding, as found in Type~1,    */
  /*      CFF, and OpenType/CFF fonts.  It is limited to 256 character     */
  /*      codes.                                                           */
  /*                                                                       */
  /*    FT_ENCODING_ADOBE_CUSTOM ::                                        */
  /*      Corresponds to a custom encoding, as found in Type~1, CFF, and   */
  /*      OpenType/CFF fonts.  It is limited to 256 character codes.       */
  /*                                                                       */
  /*    FT_ENCODING_APPLE_ROMAN ::                                         */
  /*      Corresponds to the 8-bit Apple roman encoding.  Many TrueType    */
  /*      and OpenType fonts contain a charmap for this encoding, since    */
  /*      older versions of Mac OS are able to use it.                     */
  /*                                                                       */
  /*    FT_ENCODING_OLD_LATIN_2 ::                                         */
  /*      This value is deprecated and was never used nor reported by      */
  /*      FreeType.  Don't use or test for it.                             */
  /*                                                                       */
  /*    FT_ENCODING_MS_SJIS ::                                             */
  /*      Same as FT_ENCODING_SJIS.  Deprecated.                           */
  /*                                                                       */
  /*    FT_ENCODING_MS_GB2312 ::                                           */
  /*      Same as FT_ENCODING_GB2312.  Deprecated.                         */
  /*                                                                       */
  /*    FT_ENCODING_MS_BIG5 ::                                             */
  /*      Same as FT_ENCODING_BIG5.  Deprecated.                           */
  /*                                                                       */
  /*    FT_ENCODING_MS_WANSUNG ::                                          */
  /*      Same as FT_ENCODING_WANSUNG.  Deprecated.                        */
  /*                                                                       */
  /*    FT_ENCODING_MS_JOHAB ::                                            */
  /*      Same as FT_ENCODING_JOHAB.  Deprecated.                          */
  /*                                                                       */
  /* <Note>                                                                */
  /*    By default, FreeType automatically synthesizes a Unicode charmap   */
  /*    for PostScript fonts, using their glyph names dictionaries.        */
  /*    However, it also reports the encodings defined explicitly in the   */
  /*    font file, for the cases when they are needed, with the Adobe      */
  /*    values as well.                                                    */
  /*                                                                       */
  /*    FT_ENCODING_NONE is set by the BDF and PCF drivers if the charmap  */
  /*    is neither Unicode nor ISO-8859-1 (otherwise it is set to          */
  /*    FT_ENCODING_UNICODE).  Use @FT_Get_BDF_Charset_ID to find out      */
  /*    which encoding is really present.  If, for example, the            */
  /*    `cs_registry' field is `KOI8' and the `cs_encoding' field is `R',  */
  /*    the font is encoded in KOI8-R.                                     */
  /*                                                                       */
  /*    FT_ENCODING_NONE is always set (with a single exception) by the    */
  /*    winfonts driver.  Use @FT_Get_WinFNT_Header and examine the        */
  /*    `charset' field of the @FT_WinFNT_HeaderRec structure to find out  */
  /*    which encoding is really present.  For example,                    */
  /*    @FT_WinFNT_ID_CP1251 (204) means Windows code page 1251 (for       */
  /*    Russian).                                                          */
  /*                                                                       */
  /*    FT_ENCODING_NONE is set if `platform_id' is @TT_PLATFORM_MACINTOSH */
  /*    and `encoding_id' is not @TT_MAC_ID_ROMAN (otherwise it is set to  */
  /*    FT_ENCODING_APPLE_ROMAN).                                          */
  /*                                                                       */
  /*    If `platform_id' is @TT_PLATFORM_MACINTOSH, use the function       */
  /*    @FT_Get_CMap_Language_ID  to query the Mac language ID which may   */
  /*    be needed to be able to distinguish Apple encoding variants.  See  */
  /*                                                                       */
  /*      http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/README.TXT  */
  /*                                                                       */
  /*    to get an idea how to do that.  Basically, if the language ID      */
  /*    is~0, don't use it, otherwise subtract 1 from the language ID.     */
  /*    Then examine `encoding_id'.  If, for example, `encoding_id' is     */
  /*    @TT_MAC_ID_ROMAN and the language ID (minus~1) is                  */
  /*    `TT_MAC_LANGID_GREEK', it is the Greek encoding, not Roman.        */
  /*    @TT_MAC_ID_ARABIC with `TT_MAC_LANGID_FARSI' means the Farsi       */
  /*    variant the Arabic encoding.                                       */
  /*                                                                       */
  /* ===================================================================== */

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

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

    public static TEncoding[] tt_encodings= null;

    /* ==================== FTEncoding ================================== */
    public FTEncoding() {
      oid++;
      id = oid;
      tt_encodings = new TEncoding[12];
      tt_encodings[0] = new TEncoding(TTNameTableRec.TT_PLATFORM_ISO,
              -1, FT_ENCODING_UNICODE);
      tt_encodings[1] = new TEncoding(TTNameTableRec.TT_PLATFORM_APPLE_UNICODE,
              -1, FT_ENCODING_UNICODE);
      tt_encodings[2] = new TEncoding(TTNameTableRec.TT_PLATFORM_MACINTOSH,
              TTNameTableRec.TT_MAC_ID_ROMAN, FT_ENCODING_APPLE_ROMAN);
      tt_encodings[3] = new TEncoding(TTNameTableRec.TT_PLATFORM_MICROSOFT,
              TTNameTableRec.TT_MS_ID_SYMBOL_CS, FT_ENCODING_MS_SYMBOL);
      tt_encodings[4] = new TEncoding(TTNameTableRec.TT_PLATFORM_MICROSOFT,
              TTNameTableRec.TT_MS_ID_UCS_4, FT_ENCODING_UNICODE);
      tt_encodings[5] = new TEncoding(TTNameTableRec.TT_PLATFORM_MICROSOFT,
              TTNameTableRec.TT_MS_ID_UNICODE_CS, FT_ENCODING_UNICODE);
      tt_encodings[6] = new TEncoding(TTNameTableRec.TT_PLATFORM_MICROSOFT,
              TTNameTableRec.TT_MS_ID_SJIS, FT_ENCODING_SJIS);
      tt_encodings[7] = new TEncoding(TTNameTableRec.TT_PLATFORM_MICROSOFT,
              TTNameTableRec.TT_MS_ID_GB2312, FT_ENCODING_GB2312);
      tt_encodings[8] = new TEncoding(TTNameTableRec.TT_PLATFORM_MICROSOFT,
              TTNameTableRec.TT_MS_ID_BIG_5, FT_ENCODING_BIG5);
      tt_encodings[9] = new TEncoding(TTNameTableRec.TT_PLATFORM_MICROSOFT,
              TTNameTableRec.TT_MS_ID_WANSUNG, FT_ENCODING_WANSUNG);
      tt_encodings[10] = new TEncoding(TTNameTableRec.TT_PLATFORM_MICROSOFT,
              TTNameTableRec.TT_MS_ID_JOHAB, FT_ENCODING_JOHAB);
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * sfnt_find_encoding
     * =====================================================================
     */
    public static Long sfnt_find_encoding(short platform_id, short encoding_id) {
      TEncoding cur;
      int limit;

      limit = 12;
      for (int i = 0; i < limit; i++) {
        cur = tt_encodings[i];
        if (cur.platform_id == platform_id) {
          if (cur.encoding_id == encoding_id || cur.encoding_id == -1) {
            return cur.encoding;
          }
        }
      }
      return FT_ENCODING_NONE;
    }
}

Added ftbase/FTFaceInternalRec.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
// ----------------------------------------------------------------
// FTFaceInternalRec.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// 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;

/* ======================================================================= */
/*  This Java implementation is derived from the Freetype code             */
/*  and has been implemented to work together with the Apache batik code   */
/*  for reading .ttf font files                                             */
/*                                                                         */
/*  Copyright (C) of the Java implementation 2014                          */
/*  Arnulf Wiedemann                                                       */
/*                                                                         */
/*  See the file "license.terms" for information on usage and              */
/*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.   */
/*                                                                         */
/*  in this directory the truetype opcode interpreter is ported to Java    */
/*                                                                         */
/*  the next blocks are taken from the original source code                */
/*                                                                         */
/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,   */
/*            2010 by                                                      */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/* ======================================================================= */

  /* ===================================================================== */
  /*    FTFaceInternalRec                                                  */
  /*                                                                       */
  /* <Description>                                                         */
  /*    This structure contains the internal fields of each FT_Face        */
  /*    object.  These fields may change between different releases of     */
  /*    FreeType.                                                          */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    max_points ::                                                      */
  /*      The maximum number of points used to store the vectorial outline */
  /*      of any glyph in this face.  If this value cannot be known in     */
  /*      advance, or if the face isn't scalable, this should be set to 0. */
  /*      Only relevant for scalable formats.                              */
  /*                                                                       */
  /*    max_contours ::                                                    */
  /*      The maximum number of contours used to store the vectorial       */
  /*      outline of any glyph in this face.  If this value cannot be      */
  /*      known in advance, or if the face isn't scalable, this should be  */
  /*      set to 0.  Only relevant for scalable formats.                   */
  /*                                                                       */
  /*    transform_matrix ::                                                */
  /*      A 2x2 matrix of 16.16 coefficients used to transform glyph       */
  /*      outlines after they are loaded from the font.  Only used by the  */
  /*      convenience functions.                                           */
  /*                                                                       */
  /*    transform_delta ::                                                 */
  /*      A translation vector used to transform glyph outlines after they */
  /*      are loaded from the font.  Only used by the convenience          */
  /*      functions.                                                       */
  /*                                                                       */
  /*    transform_flags ::                                                 */
  /*      Some flags used to classify the transform.  Only used by the     */
  /*      convenience functions.                                           */
  /*                                                                       */
  /*    services ::                                                        */
  /*      A cache for frequently used services.  It should be only         */
  /*      accessed with the macro `FT_FACE_LOOKUP_SERVICE'.                */
  /*                                                                       */
  /*    incremental_interface ::                                           */
  /*      If non-null, the interface through which glyph data and metrics  */
  /*      are loaded incrementally for faces that do not provide all of    */
  /*      this data when first opened.  This field exists only if          */
  /*      @FT_CONFIG_OPTION_INCREMENTAL is defined.                        */
  /*                                                                       */
  /*    ignore_unpatented_hinter ::                                        */
  /*      This boolean flag instructs the glyph loader to ignore the       */
  /*      native font hinter, if one is found.  This is exclusively used   */
  /*      in the case when the unpatented hinter is compiled within the    */
  /*      library.                                                         */
  /*                                                                       */
  /*    refcount ::                                                        */
  /*      A counter initialized to~1 at the time an @FT_Face structure is  */
  /*      created.  @FT_Reference_Face increments this counter, and        */
  /*      @FT_Done_Face only destroys a face if the counter is~1,          */
  /*      otherwise it simply decrements it.                               */
  /*                                                                       */
  /* ===================================================================== */

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

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

    FTMatrixRec transform_matrix = null;
    FTVectorRec transform_delta = null;
    int transform_flags = 0;
    FTServiceCacheRec  services = null;
    boolean ignore_unpatented_hinter = false;
    int refcount;

    /* ==================== FTFaceInternalRec ================================== */
    public FTFaceInternalRec() {
      oid++;
      id = oid;
      transform_matrix = new FTMatrixRec();
      transform_delta = new FTVectorRec();
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * =====================================================================
     */

}

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

  /* ===================================================================== */
  /*    FTFaceRec                                                          */
  /*                                                                       */
  /* <Description>                                                         */
  /*    FreeType root face class structure.  A face object models a        */
  /*    typeface in a font file.                                           */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    num_faces           :: The number of faces in the font file.  Some */
  /*                           font formats can have multiple faces in     */
  /*                           a font file.                                */
  /*                                                                       */
  /*    face_index          :: The index of the face in the font file.  It */
  /*                           is set to~0 if there is only one face in    */
  /*                           the font file.                              */
  /*                                                                       */
  /*    face_flags          :: A set of bit flags that give important      */
  /*                           information about the face; see             */
  /*                           @FT_FACE_FLAG_XXX for the details.          */
  /*                                                                       */
  /*    style_flags         :: A set of bit flags indicating the style of  */
  /*                           the face; see @FT_STYLE_FLAG_XXX for the    */
  /*                           details.                                    */
  /*                                                                       */
  /*    num_glyphs          :: The number of glyphs in the face.  If the   */
  /*                           face is scalable and has sbits (see         */
  /*                           `num_fixed_sizes'), it is set to the number */
  /*                           of outline glyphs.                          */
  /*                                                                       */
  /*                           For CID-keyed fonts, this value gives the   */
  /*                           highest CID used in the font.               */
  /*                                                                       */
  /*    family_name         :: The face's family name.  This is an ASCII   */
  /*                           string, usually in English, which describes */
  /*                           the typeface's family (like `Times New      */
  /*                           Roman', `Bodoni', `Garamond', etc).  This   */
  /*                           is a least common denominator used to list  */
  /*                           fonts.  Some formats (TrueType & OpenType)  */
  /*                           provide localized and Unicode versions of   */
  /*                           this string.  Applications should use the   */
  /*                           format specific interface to access them.   */
  /*                           Can be NULL (e.g., in fonts embedded in a   */
  /*                           PDF file).                                  */
  /*                                                                       */
  /*    style_name          :: The face's style name.  This is an ASCII    */
  /*                           string, usually in English, which describes */
  /*                           the typeface's style (like `Italic',        */
  /*                           `Bold', `Condensed', etc).  Not all font    */
  /*                           formats provide a style name, so this field */
  /*                           is optional, and can be set to NULL.  As    */
  /*                           for `family_name', some formats provide     */
  /*                           localized and Unicode versions of this      */
  /*                           string.  Applications should use the format */
  /*                           specific interface to access them.          */
  /*                                                                       */
  /*    num_fixed_sizes     :: The number of bitmap strikes in the face.   */
  /*                           Even if the face is scalable, there might   */
  /*                           still be bitmap strikes, which are called   */
  /*                           `sbits' in that case.                       */
  /*                                                                       */
  /*    available_sizes     :: An array of @FT_Bitmap_Size for all bitmap  */
  /*                           strikes in the face.  It is set to NULL if  */
  /*                           there is no bitmap strike.                  */
  /*                                                                       */
  /*    num_charmaps        :: The number of charmaps in the face.         */
  /*                                                                       */
  /*    charmaps            :: An array of the charmaps of the face.       */
  /*                                                                       */
  /*    generic             :: A field reserved for client uses.  See the  */
  /*                           @FT_Generic type description.               */
  /*                                                                       */
  /*    bbox                :: The font bounding box.  Coordinates are     */
  /*                           expressed in font units (see                */
  /*                           `units_per_EM').  The box is large enough   */
  /*                           to contain any glyph from the font.  Thus,  */
  /*                           `bbox.yMax' can be seen as the `maximum     */
  /*                           ascender', and `bbox.yMin' as the `minimum  */
  /*                           descender'.  Only relevant for scalable     */
  /*                           formats.                                    */
  /*                                                                       */
  /*                           Note that the bounding box might be off by  */
  /*                           (at least) one pixel for hinted fonts.  See */
  /*                           @FT_Size_Metrics for further discussion.    */
  /*                                                                       */
  /*    units_per_EM        :: The number of font units per EM square for  */
  /*                           this face.  This is typically 2048 for      */
  /*                           TrueType fonts, and 1000 for Type~1 fonts.  */
  /*                           Only relevant for scalable formats.         */
  /*                                                                       */
  /*    ascender            :: The typographic ascender of the face,       */
  /*                           expressed in font units.  For font formats  */
  /*                           not having this information, it is set to   */
  /*                           `bbox.yMax'.  Only relevant for scalable    */
  /*                           formats.                                    */
  /*                                                                       */
  /*    descender           :: The typographic descender of the face,      */
  /*                           expressed in font units.  For font formats  */
  /*                           not having this information, it is set to   */
  /*                           `bbox.yMin'.  Note that this field is       */
  /*                           usually negative.  Only relevant for        */
  /*                           scalable formats.                           */
  /*                                                                       */
  /*    height              :: This value is the vertical distance         */
  /*                           between two consecutive baselines,          */
  /*                           expressed in font units.  It is always      */
  /*                           positive.  Only relevant for scalable       */
  /*                           formats.                                    */
  /*                                                                       */
  /*                           If you want the global glyph height, use    */
  /*                           `ascender - descender'.                     */
  /*                                                                       */
  /*    max_advance_width   :: The maximum advance width, in font units,   */
  /*                           for all glyphs in this face.  This can be   */
  /*                           used to make word wrapping computations     */
  /*                           faster.  Only relevant for scalable         */
  /*                           formats.                                    */
  /*                                                                       */
  /*    max_advance_height  :: The maximum advance height, in font units,  */
  /*                           for all glyphs in this face.  This is only  */
  /*                           relevant for vertical layouts, and is set   */
  /*                           to `height' for fonts that do not provide   */
  /*                           vertical metrics.  Only relevant for        */
  /*                           scalable formats.                           */
  /*                                                                       */
  /*    underline_position  :: The position, in font units, of the         */
  /*                           underline line for this face.  It is the    */
  /*                           center of the underlining stem.  Only       */
  /*                           relevant for scalable formats.              */
  /*                                                                       */
  /*    underline_thickness :: The thickness, in font units, of the        */
  /*                           underline for this face.  Only relevant for */
  /*                           scalable formats.                           */
  /*                                                                       */
  /*    glyph               :: The face's associated glyph slot(s).        */
  /*                                                                       */
  /*    size                :: The current active size for this face.      */
  /*                                                                       */
  /*    charmap             :: The current active charmap for this face.   */
  /*                                                                       */
  /* <Note>                                                                */
  /*    Fields may be changed after a call to @FT_Attach_File or           */
  /*    @FT_Attach_Stream.                                                 */
  /*                                                                       */
  /* ===================================================================== */

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

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

    public final static long FT_FACE_FLAG_SCALABLE         = (1L <<  0);
    public final static long FT_FACE_FLAG_FIXED_SIZES      = (1L <<  1);
    public final static long FT_FACE_FLAG_FIXED_WIDTH      = (1L <<  2);
    public final static long FT_FACE_FLAG_SFNT             = (1L <<  3);
    public final static long FT_FACE_FLAG_HORIZONTAL       = (1L <<  4);
    public final static long FT_FACE_FLAG_VERTICAL         = (1L <<  5);
    public final static long FT_FACE_FLAG_KERNING          = (1L <<  6);
    public final static long FT_FACE_FLAG_FAST_GLYPHS      = (1L <<  7);
    public final static long FT_FACE_FLAG_MULTIPLE_MASTERS = (1L <<  8);
    public final static long FT_FACE_FLAG_GLYPH_NAMES      = (1L <<  9);
    public final static long FT_FACE_FLAG_EXTERNAL_STREAM  = (1L << 10);
    public final static long FT_FACE_FLAG_HINTER           = (1L << 11);
    public final static long FT_FACE_FLAG_CID_KEYED        = (1L << 12);
    public final static long FT_FACE_FLAG_TRICKY           = (1L << 13);

    private String initStr = "??";
    
    public int num_faces = 0;
    public int face_index =0;
    public long face_flags = 0L;
    public long style_flags = 0L;
    public int num_glyphs = 0;
    public String family_name = null;
    public String style_name = null;
    public int num_fixed_sizes = 0;
    public FTBitmapSize[] available_sizes = null;
    public int num_charmaps = 0;
    public FTCharMapRec[] charmaps = null;
//    public FTGeneric generic;
    /*# The following member variables (down to `underline_thickness') */
    /*# are only relevant to scalable outlines; cf. @FT_Bitmap_Size    */
    /*# for bitmap fonts.                                              */
    public FTBBoxRec bbox = null;
    public short units_per_EM = 0;
    public short ascender = 0;
    public short descender = 0;
    public short height = 0;
    public short max_advance_width = 0;
    public short max_advance_height = 0;
    public short underline_position = 0;
    public short underline_thickness = 0;
    public FTGlyphSlotRec glyph = null;
    public FTSizeRec size = null;
    public FTCharMapRec charmap = null;
    /*@private begin */
    public FTDriverRec driver = null;
    public FTStreamRec stream = null;
    public FTListRec sizes_list = null;
//    public FTGeneric autohint;   /* face-specific auto-hinter data */
    public FTFaceInternalRec internal = null;

    /* ==================== FTFaceRec ================================== */
    public FTFaceRec(String initStr) {
      oid++;
      id = oid;
      
      this.initStr = initStr;
      bbox = new FTBBoxRec();
      sizes_list = new FTListRec("FTFaceRec.sizes_list 1");
      internal = new FTFaceInternalRec();
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!"+initStr+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * FTNewFace
     * =====================================================================
     */
    public static int FTNewFace(FTLibraryRec library, String pathname, long face_index,
            FTReference<FTFaceRec> face_ref) {
      FTOpenArgs args = new FTOpenArgs();
      int error;

Debug(0, DBG_LOAD_GLYPH, TAG, "FTNewFace: pathname: "+pathname+"!");
      /* test for valid `library' and `face_ref' delayed to FT_Open_Face() */
      if (pathname == null) {
Debug(0, DBG_LOAD_GLYPH, TAG, "FTNewFace1 inv arg");
        return FTError.INTERP_INVALID_ARGUMENT;
      }
      args.flags = FTOpenArgs.FT_OPEN_PATHNAME;
      args.pathname = pathname;
      args.stream   = null;
      error = FTOpenFace(library, args, face_index, face_ref);
      return error;
    }
 
    /* =====================================================================
     * open_face
     * =====================================================================
     */
    public static int open_face(FTDriverRec driver, FTStreamRec stream, Long face_index, int num_params, 
            FTParameter params, FTReference<FTFaceRec> face_ref) {
      FTDriverClassRec clazz;
      FTFaceRec face = null;
      int error = 0;
      int error2 = 0;

      FTTrace.Trace(7, TAG, "open_face");
      clazz  = driver.driver_clazz;
      /* allocate the face object and perform basic initialization */
      switch (clazz.face_object_type) {
      case TTDriverClass.FACE_REC_TYPE_TT:
        face = (FTFaceRec)new TTFaceRec();
        break;
      default:
        return FTError.FACE_BAD_FACE_OBJECT_TYPE;
      }
      face.driver = driver;
      face.stream = stream;
      FTTrace.Trace(7, TAG, "clazz->init_face: "+clazz.init_face+"!"+stream+"!");
      if (clazz.init_face != null) {
          face_ref.Set(face);    	  
          error = (int)clazz.init_face.callClassMethod(stream, face_ref, new Long(face_index), new Long(num_params), params);
//        error = clazz.init_face(stream, face, face_index, num_params, params);
          face = face_ref.Get();
      }
      FTTrace.Trace(7, TAG, String.format("clazz init_face2: %d", error));
      if (error != 0) {
//      destroy_charmaps(face, memory);
        if (clazz.done_face != null) {
//          clazz.done_face(face);
        }
        face_ref.Set(null);
        return error;
      }
      /* select Unicode charmap by default */
      error2 = FTCharMapRec.find_unicode_charmap(face);
      /* if no Unicode charmap can be found, FT_Err_Invalid_CharMap_Handle */
      /* is returned.                                                      */
      /* no error should happen, but we want to play safe */
      if ((error2 != 0) && (error2 != FTError.INTERP_INVALID_CHARMAP_HANDLE)) {
        error = error2;
//        destroy_charmaps(face, memory);
        if (clazz.done_face != null) {
//          clazz.done_face( face );
        }
        face_ref.Set(null);
        return error;
      }
      face_ref.Set(face);
      return error;
    }

    /* =====================================================================
     * FTOpenFace
     * =====================================================================
     */
    public static int FTOpenFace(FTLibraryRec library, FTOpenArgs args, long face_index, FTReference<FTFaceRec> face_ref) {
      int error;
      FTDriverRec driver = null;
      FTReference<RandomAccessFile> stream_ref = new FTReference<RandomAccessFile>();
      FTFaceRec face = null;
      FTListNodeRec node = null;
      boolean external_stream;
      FTModuleRec cur;
      int module_idx = 0;
      int limit = 0;
      FTStreamRec stream = new FTStreamRec();
      boolean is_success = false;

//FT_Trace.Trace(7, TAG, "FT_Open_Face");
Debug(0, DBG_LOAD_GLYPH, TAG, "FT_OPEN_FACE: args.pathname: "+args.pathname+"!");
    /* test for valid `library' delayed to */
    /* FTStreamNew()                     */
    if ((face_ref == null && face_index >= 0) || args == null) {
Debug(0, DBG_LOAD_GLYPH, TAG, "FTOpenFace1 inv arg");
      return FTError.INTERP_INVALID_ARGUMENT;
    }
    external_stream = ((args.flags & FTOpenArgs.FT_OPEN_STREAM) != 0 && args.stream != null);
    /* create input stream */
    error = stream.FTStreamNew(library, args, stream_ref);
    if (error != 0) {
      /* If we are on the mac, and we get an                          */
      /* FT_Err_Invalid_Stream_Operation it may be because we have an */
      /* empty data fork, so we need to check the resource fork.      */
      if (error != FTError.INTERP_CANNOT_OPEN_STREAM &&
          error != FTError.INTERP_UNKNOWN_FILE_FORMAT &&
          error != FTError.INTERP_INVALID_STREAM_OPERATION) {
//        FTStreamFree(stream, external_stream);
        FTTrace.Trace(7, TAG, "FT_Open_Face: Return "+error);
        return error;
      }
      /* no driver is able to handle this format */
      error = FTError.INTERP_UNKNOWN_FILE_FORMAT;
//      FTStreamFree(stream, external_stream);
      FTTrace.Trace(7, TAG, "FT_Open_Face: Return "+error);
      return error;
    }
    /* If the font driver is specified in the `args' structure, use */
    /* it.  Otherwise, we scan the list of registered drivers.      */
    if ((args.flags & FTOpenArgs.FT_OPEN_DRIVER) != 0 && args.driver != null) {
      driver = new FTDriverRec(args.driver);
      /* not all modules are drivers, so check... */
      if ((driver.driver_clazz.module_flags & FTModuleClassRec.FT_MODULE_FONT_DRIVER) != 0) {
        int num_params = 0;
        FTParameter params =null ;

        if ((args.flags & FTOpenArgs.FT_OPEN_PARAMS) != 0) {
          num_params = args.num_params;
          params = args.params;
        }
        error = open_face(driver, stream, face_index, num_params, params, face_ref);
        face = face_ref.Get();
        if (error == 0) {
          FTTrace.Trace(7, TAG, "FT_Open_Face: Return "+error);
          return error;
        } else
          error = FTError.INTERP_INVALID_HANDLE;
        }
//        FTStreamFree(stream, external_stream);
        FTTrace.Trace(7, TAG, "FT_Open_Face: Return "+error);
        return error;
      } else {
        error = FTError.INTERP_MISSING_MODULE;
        /* check each font driver for an appropriate format */
        cur = library.modules[0];
        limit = library.num_modules;
        for (module_idx = 0; module_idx < limit; module_idx++) {
          cur = (FTModuleRec)library.modules[module_idx];
          /* not all modules are font drivers, so check... */
          if ((cur.module_clazz.module_flags & FTModuleClassRec.FT_MODULE_FONT_DRIVER) != 0) {
            int num_params = 0;
            FTParameter params = null;
            
            TTDriverRec cur_obj = (TTDriverRec)library.modules[module_idx];
            driver = (FTDriverRec)cur_obj;
            if ((args.flags & FTOpenArgs.FT_OPEN_PARAMS) != 0) {
              num_params = args.num_params;
              params = args.params;
            }
            error = open_face(driver, stream, face_index, num_params, params, face_ref);
            face = face_ref.Get();
            if (error  == 0) {
              is_success = true;
              break;
            }
            if (error !=  FTError.INTERP_UNKNOWN_FILE_FORMAT) {
                /* If we are on the mac, and we get an                          */
                /* FT_Err_Invalid_Stream_Operation it may be because we have an */
                /* empty data fork, so we need to check the resource fork.      */
                if (error != FTError.INTERP_CANNOT_OPEN_STREAM &&
                    error != FTError.INTERP_UNKNOWN_FILE_FORMAT &&
                    error != FTError.INTERP_INVALID_STREAM_OPERATION) {
//                  FTStreamFree(stream, external_stream);
                  FTTrace.Trace(7, TAG, "FT_Open_Face: Return "+error);
                  return error;
                }
                /* no driver is able to handle this format */
                error = FTError.INTERP_UNKNOWN_FILE_FORMAT;
                FTTrace.Trace(7, TAG, "FT_Open_Face: Return "+error);
                return error;
            }
          }
        }
        if (! is_success) {
          /* If we are on the mac, and we get an                          */
          /* FT_Err_Invalid_Stream_Operation it may be because we have an */
          /* empty data fork, so we need to check the resource fork.      */
          if (error != FTError.INTERP_CANNOT_OPEN_STREAM &&
              error != FTError.INTERP_UNKNOWN_FILE_FORMAT &&
              error != FTError.INTERP_INVALID_STREAM_OPERATION) {
//            FTStreamFree(stream, external_stream);
            FTTrace.Trace(7, TAG, "FT_Open_Face: Return "+error);
            return error;
          }
          /* no driver is able to handle this format */
          error = FTError.INTERP_UNKNOWN_FILE_FORMAT;
//          FTStreamFree(stream, external_stream);
          FTTrace.Trace(7, TAG, "FT_Open_Face: Return "+error);
          return error;
        }
      }
//      stream = stream_ref.Get();
      FTTrace.Trace(7, TAG, "FT_Open_Face: New face object, adding to list stream: "+stream+"!");
      /* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */
      if (external_stream) {
        face.face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
      }
      /* add the face object to its driver's list */
      node = new FTListNodeRec();
      face.stream = stream;
      node.data = face;
      /* don't assume driver is the same as face->driver, so use */
      /* face->driver instead.                                   */
      FTListNodeRec.FTListAdd(face.driver.faces_list, node);
      /* now allocate a glyph slot object for the face */
      FTTrace.Trace(7, TAG, "FT_Open_Face: Creating glyph slot");
      if (face_index >= 0) {
        FTReference<FTGlyphSlotRec> slot_ref = new FTReference<FTGlyphSlotRec>();
        error = FTGlyphSlotRec.FTNewGlyphSlot(face, slot_ref);
        if (error != 0) {
          FTTrace.Trace(7, TAG, "FT_Open_Face: Return "+error);
          return error;
        }
        /* finally, allocate a size object for the face */
        {
          FTSizeRec size;

          FTTrace.Trace(7, TAG, "FT_Open_Face: Creating size object");
          FTReference<FTSizeRec> lst2_ref = new FTReference<FTSizeRec>();
          error = FTSizeRec.FTNewSize(face, lst2_ref);
          size = lst2_ref.Get();
          if (error != 0) {
            FTTrace.Trace(7, TAG, "FT_Open_Face: Return "+error);
            return error;
          }
          face.size = size;
        }
      }
      /* some checks */
      if ((face.face_flags & FTFaceRec.FT_FACE_FLAG_SCALABLE) != 0) {
        if (face.height < 0) {
          face.height = (short)-face.height;
        }
        if ((face.face_flags & FTFaceRec.FT_FACE_FLAG_VERTICAL) != 0) {
          face.max_advance_height = (Short)face.height;
        }
      }
      if ((face.face_flags & FTFaceRec.FT_FACE_FLAG_FIXED_SIZES) != 0) {
        int i;

        for (i = 0; i < face.num_fixed_sizes; i++) {
          FTBitmapSize bsize = face.available_sizes[i];

          if (bsize.height < 0) {
            bsize.height = (short)-bsize.height;
          }
          if (bsize.x_ppem < 0) {
            bsize.x_ppem = (short)-bsize.x_ppem;
          }
          if (bsize.y_ppem < 0) {
            bsize.y_ppem = -bsize.y_ppem;
          }
        }
      }
      /* initialize internal face data */
      {
        face.internal.transform_matrix.xx = 0x10000L;
        face.internal.transform_matrix.xy = 0L;
        face.internal.transform_matrix.yx = 0L;
        face.internal.transform_matrix.yy = 0x10000L;
        face.internal.transform_delta.x = 0L;
        face.internal.transform_delta.y = 0L;
        face.internal.refcount = 1;
      }
      if (face_ref != null) {
        face_ref.Set(face);
      } else {
//        FTDoneFace(face);
      }
      FTTrace.Trace(7, TAG, "FT_Open_Face: Return "+error);
      return error;
    }
 
}

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

  /* ===================================================================== */
  /*    FTInit                                                          */
  /*                                                                       */
  /* ===================================================================== */

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

    private int id;
    private static String TAG = "FTInit";
    
    protected final static int SUCCESS = 0;
    protected final static int FAILURE = 1;

    public FTModules ft_modules = null;
    public FTModuleRec root;

    /* ==================== FTInit ================================== */
    public FTInit() {
      ft_modules = new FTModules();
      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();
    }

    /* =====================================================================
     * FTInitFreeType
     * =====================================================================
     */

    public int FTInitFreeType(FTReference<FTLibraryRec> library_ref) {
      int error;
      FTLibraryRec library;

       error = FTError.INTERP_ERR_OK;
      FTTrace.Trace(7, TAG, "FTInitFreeType");
Debug(0, DBG_INIT, TAG, "FT_Init_FreeType call FT_New_Library");
      library = new FTLibraryRec();
Debug(0, DBG_INIT, TAG, "FT_Init_FreeType call FT_Add_Default_Modules");
      ft_modules.FTAddDefaultModules(library);
      library_ref.Set(library);
Debug(0, DBG_INIT, TAG, "FT_Init_FreeType done");
      return error;
    }


}

Added ftbase/FTInstanceVariable.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
/* =====================================================================
 *  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.lang.reflect.Field;

  /* ===================================================================== */
  /*    FTInstanceVariable                                                          */
  /*                                                                       */
  /* ===================================================================== */

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

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

    private Object objs[];
    private Object[] args_objs;

    public int num_params;
    public Field v;
    public Object instance;
    public Class<?> cls;
    public Class<?> params[];
    public String variable_name;

    /* ==================== FTInstanceVariable ================================== */
    public FTInstanceVariable(String class_name, Object instance, String variable_name, int num_params) {
      oid++;
      id = oid;

      FTTrace.Trace(7, TAG, "instvar constructor called for: "+variable_name);
      this.num_params = num_params;
      this.variable_name = variable_name;
      this.objs = new Object[1];
//      this.args_objs = new Object[1];
//      this.objs[0] = this.args_objs;
      try {
        cls = Class.forName(class_name);
//        params = new Class<?>[num_params];
//        for (int i = 0; i < num_params; i++) {
//          params[i] = Class.forName("java.lang.Object");
//        }
        v = cls.getField(variable_name);
        this.instance = instance;
//        instance = cls.newInstance();
      } catch (NoSuchFieldException x) {
        x.printStackTrace();
//      } catch (IllegalAccessException x) {
//        x.printStackTrace();
      } catch (ClassNotFoundException x) {
        x.printStackTrace();
//      } catch (InstantiationException x) {
//          x.printStackTrace();
      }
    }
    
    /* ==================== 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 void setShortVariable(Object ... args) {
      FTTrace.Trace(7, TAG, "setShortVariable called for: "+variable_name);
      try {
        this.objs[0] = args;
        Short xx = (Short)args[0];
        v.setShort(instance, xx.shortValue());
      } catch (IllegalAccessException x) {
        x.printStackTrace();
      }
    }

    /* =====================================================================
     * =====================================================================
     */
    public void setIntVariable(Object ... args) {
      FTTrace.Trace(7, TAG, "setIntVariable called for: "+variable_name);
      try {
        this.objs[0] = args;
        Integer xx = (Integer)args[0];
        v.setInt(instance, xx.intValue());
      } catch (IllegalAccessException x) {
        x.printStackTrace();
      }
    }

    /* =====================================================================
     * =====================================================================
     */
    public void setLongVariable(Object ... args) {
      FTTrace.Trace(7, TAG, "setLongVariable called for: "+variable_name);
      try {
        this.objs[0] = args;
        Long xx = (Long)args[0];
        v.setLong(instance, xx.longValue());
      } catch (IllegalAccessException x) {
        x.printStackTrace();
      }
    }

}

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

  /*    FTMatrixRec                                                           */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A simple structure used to store a 2x2 matrix.  Coefficients are   */
  /*    in 16.16 fixed-point format.  The computation performed is:        */
  /*                                                                       */
  /*       {                                                               */
  /*          x' = x*xx + y*xy                                             */
  /*          y' = x*yx + y*yy                                             */
  /*       }                                                               */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    xx :: Matrix coefficient.                                          */
  /*                                                                       */
  /*    xy :: Matrix coefficient.                                          */
  /*                                                                       */
  /*    yx :: Matrix coefficient.                                          */
  /*                                                                       */
  /*    yy :: Matrix coefficient.                                          */
  /*                                                                       */
  /* ===================================================================== */

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

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

    public long xx = 0L;
    public long xy = 0L;
    public long yx = 0L;
    public long yy = 0L;

    /* ==================== FTMatricRec ================================== */
    public FTMatrixRec() {
      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/FTOpenArgs.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
/* =====================================================================
 *  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.io.*;

  /* ===================================================================== */
  /*    FTOpenArgs                                                          */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A structure used to indicate how to open a new font file or        */
  /*    stream.  A pointer to such a structure can be used as a parameter  */
  /*    for the functions @FT_Open_Face and @FT_Attach_Stream.             */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    flags       :: A set of bit flags indicating how to use the        */
  /*                   structure.                                          */
  /*                                                                       */
  /*    memory_base :: The first byte of the file in memory.               */
  /*                                                                       */
  /*    memory_size :: The size in bytes of the file in memory.            */
  /*                                                                       */
  /*    pathname    :: A pointer to an 8-bit file pathname.                */
  /*                                                                       */
  /*    stream      :: A handle to a source stream object.                 */
  /*                                                                       */
  /*    driver      :: This field is exclusively used by @FT_Open_Face;    */
  /*                   it simply specifies the font driver to use to open  */
  /*                   the face.  If set to~0, FreeType tries to load the  */
  /*                   face with each one of the drivers in its list.      */
  /*                                                                       */
 /*    num_params  :: The number of extra parameters.                     */
  /*                                                                       */
  /*    params      :: Extra parameters passed to the font driver when     */
  /*                   opening a new face.                                 */
  /*                                                                       */
  /* <Note>                                                                */
  /*    The stream type is determined by the contents of `flags' which     */
  /*    are tested in the following order by @FT_Open_Face:                */
  /*                                                                       */
  /*    If the `FT_OPEN_MEMORY' bit is set, assume that this is a          */
  /*    memory file of `memory_size' bytes, located at `memory_address'.   */
  /*    The data are are not copied, and the client is responsible for     */
  /*    releasing and destroying them _after_ the corresponding call to    */
  /*    @FT_Done_Face.                                                     */
  /*                                                                       */
  /*    Otherwise, if the `FT_OPEN_STREAM' bit is set, assume that a       */
  /*    custom input stream `stream' is used.                              */
  /*                                                                       */
  /*    Otherwise, if the `FT_OPEN_PATHNAME' bit is set, assume that this  */
  /*    is a normal file and use `pathname' to open it.                    */
  /*                                                                       */
  /*    If the `FT_OPEN_DRIVER' bit is set, @FT_Open_Face only tries to    */
 /*    open the file with the driver whose handler is in `driver'.        */
  /*                                                                       */
  /*    If the `FT_OPEN_PARAMS' bit is set, the parameters given by        */
  /*    `num_params' and `params' is used.  They are ignored otherwise.    */
  /*                                                                       */
  /*    Ideally, both the `pathname' and `params' fields should be tagged  */
  /*    as `const'; this is missing for API backwards compatibility.  In   */
  /*    other words, applications should treat them as read-only.          */
  /*                                                                       */
  /* ===================================================================== */

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

    private int id;
    private static String TAG = "FTOpenArgs";
    
    public static final int FT_OPEN_MEMORY = 0x1;
    public static final int FT_OPEN_STREAM = 0x2;
    public static final int FT_OPEN_PATHNAME = 0x4;
    public static final int FT_OPEN_DRIVER = 0x8;
    public static final int FT_OPEN_PARAMS = 0x10;

    public Integer flags = 0;
    public String pathname = null;
    public ByteArrayInputStream stream = null;
    public FTModuleRec driver = null;
    public int num_params = 0;
    public FTParameter params = null;

    /* ==================== FTOpenArgs ================================== */
    public FTOpenArgs() {
      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/FTTrigonometric.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
/* =====================================================================
 *  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;

  /* ===================================================================== */
  /*    FTTrigonometric                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTTrigonometric extends FTDebug {
    private static int oid = 0;
    private static long[] ft_trig_arctan_table = new long[]
        {
          1740967L, 919879L, 466945L, 234379L, 117304L, 58666L, 29335L,
          14668L, 7334L, 3667L, 1833L, 917L, 458L, 229L, 115L,
          57L, 29L, 14L, 7L, 4L, 2L, 1L
        };
    private final static long FT_ANGLE_PI = 180L << 16;
    private final static long FT_ANGLE_PI2 = FT_ANGLE_PI/2;
    private final static int FT_TRIG_SAFE_MSB = 29;
    private final static int FT_TRIG_MAX_ITERS = 23;
    private final static long FT_TRIG_SCALE = 0xDBD95B16L;

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

    /* ==================== FTTrigonometric ================================== */
    public FTTrigonometric() {
      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();
    }
 
    /* ==================== ft_trig_downscale ================================ */
    private static long ft_trig_downscale(long val) {
      long s;
      long v1;
      long v2;
      long k1;
      long k2;
      long hi;
      long lo1;
      long lo2;
      long lo3;

Debug(0, DBG_RENDER, TAG, "ft_trig_downscale");
      s   = val;
      val = FTCalc.FT_ABS(val);
      v1 = (val >> 16);
      v2 = (val & 0xFFFFL);
Debug(0, DBG_RENDER, TAG, String.format("ft_trig_downscale: s: 0x%x, val: 0x%x, v1: 0x%x, v2: 0x%x", s, val, v1, v2));
      k1 = FT_TRIG_SCALE >> 16;         /* constant */
      k2 = (FT_TRIG_SCALE & 0xFFFFL);   /* constant */
      hi = k1 * v1;
      lo1 = k1 * v2 + k2 * v1;       /* can't overflow */
      lo2 = (k2 * v2) >> 16;
      lo3 = lo1 > lo2 ? lo1 : lo2;
Debug(0, DBG_RENDER, TAG, String.format("ft_trig_downscale2: k1: 0x%x, k2: 0x%x, hi: 0x%x, lo1: 0x%x, lo2: 0x%x, lo3: 0x%x", k1, k2, hi, lo1, lo2, lo3));
      lo1 += lo2;
      hi  += lo1 >> 16;
      if (lo1 < lo3) {
        hi += 0x10000L;
      }
      val  = hi;
      return (s >= 0) ? val : -val;
    }

    /* ==================== ft_trig_prenorm ===================================== */
    private static int ft_trig_prenorm(FTReference<FTVectorRec> vec_ref) {
      long x;
      long y;
      FTVectorRec vec = vec_ref.Get();
      int  shift;

      x = vec.x;
      y = vec.y;
      shift = FTCalc.FT_MSB(FTCalc.FT_ABS(x) | FTCalc.FT_ABS(y));
      if (shift <= FT_TRIG_SAFE_MSB) {
        shift  = FT_TRIG_SAFE_MSB - shift;
        vec.x = x << shift;
        vec.y = y << shift;
      } else {
        shift -= FT_TRIG_SAFE_MSB;
        vec.x = x >> shift;
        vec.y = y >> shift;
        shift  = -shift;
      }
      vec_ref.Set( vec);
      return shift;
    }

    /* ==================== ft_trig_pseudo_polarize ========================= */
    private static void ft_trig_pseudo_polarize (FTReference<FTVectorRec> vec_ref) {
      FTVectorRec vec = vec_ref.Get();
      long theta;
      int i;
      long x;
      long y;
      long xtemp;
      long b;
      int arctanIdx;
      long arctan;

      x = vec.x;
      y = vec.y;
      /* Get the vector into [-PI/4,PI/4] sector */
      if (y > x) {
        if (y > -x) {
          theta = FT_ANGLE_PI2;
          xtemp =  y;
          y = -x;
          x =  xtemp;
        } else {
          theta =  y > 0 ? FT_ANGLE_PI : -FT_ANGLE_PI;
          x = -x;
          y = -y;
        }
      } else {
        if (y < -x) {
          theta = -FT_ANGLE_PI2;
          xtemp = -y;
          y =  x;
          x =  xtemp;
        } else {
          theta = 0L;
        }
      }
Debug(0, DBG_RENDER, TAG, String.format("theta0: 0x%x, x: 5x%x, y: 0x%x", theta, x, y));
      arctanIdx = 0;
      arctan = ft_trig_arctan_table[arctanIdx];
      /* Pseudorotations, with right shifts */
      b = 1L;
      for (i = 1; i < FT_TRIG_MAX_ITERS; b <<= 1, i++) {
        arctan = ft_trig_arctan_table[arctanIdx];
        if (y > 0) {
          xtemp = x + ((y + b) >> i);
          y = y - ((x + b) >> i);
          x = xtemp;
          theta += arctan;
        } else {
          xtemp = x - ((y + b) >> i);
          y = y + ((x + b) >> i);
          x = xtemp;
          theta -= arctan;
        }
        arctanIdx++;
Debug(0, DBG_RENDER, TAG, String.format("theta1: 0x%x, x: 5x%x, y: 0x%x", theta, x, y));
      }
      /* round theta */
      if (theta >= 0) {
        theta = FTCalc.FT_PAD_ROUND(theta, 32);
      } else {
        theta = -FTCalc.FT_PAD_ROUND(-theta, 32);
      }
      vec.x = x;
      vec.y = theta;
      vec_ref.Set(vec);
    }

    /* ==================== FTVectorLength ===================================== */
    public static long FTVectorLength(FTVectorRec vec) {
      int shift;
      FTVectorRec v;
      FTReference<FTVectorRec> v_ref = new FTReference<FTVectorRec>();

Debug(0, DBG_RENDER, TAG, "FTVectorLength");
      v = vec;
      /* handle trivial cases */
      if (v.x == 0) {
        return FTCalc.FT_ABS(v.y);
      } else {
        if (v.y == 0) {
          return FTCalc.FT_ABS(v.x);
        }
      }
      /* general case */
      v_ref.Set(v);
      shift = ft_trig_prenorm(v_ref);
      v = v_ref.Get();
Debug(0, DBG_RENDER, TAG, String.format("shift1: %d, x: 0x%x, y: 0x%x", shift, v.x, v.y));
      ft_trig_pseudo_polarize(v_ref);
      v = v_ref.Get();
Debug(0, DBG_RENDER, TAG, String.format("shift2: %d, x: 0x%x, y: 0x%x", shift, v.x, v.y));
      v.x = ft_trig_downscale(v.x);
Debug(0, DBG_RENDER, TAG, String.format("shift3: %d, x: 0x%x, y: 0x%x", shift, v.x, v.y));
      if (shift > 0) {
        return (v.x + (1 << (shift - 1))) >> shift;
      }
      return (long)(v.x << -shift);
    }

}

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

  /* ===================================================================== */
  /*    FTVectorRec                                                           */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A simple structure used to store a 2D vector; coordinates are of   */
  /*    the FTPos type.                                                   */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    x :: The horizontal coordinate.                                    */
  /*    y :: The vertical coordinate.                                      */
  /* ===================================================================== */

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

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

    public long x = 0L;
    public long y = 0L;

    /* ==================== FTVectorRec ================================== */
    public FTVectorRec() {
      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/IUPWorkerRec.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
/* =====================================================================
 *  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;

  /* ===================================================================== */
  /*    IUPWorkerRec                                                          */
  /*                                                                       */
  /* ===================================================================== */

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

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

    public FTVectorRec[] orgs; /* original and current coordinate */
    public int org_idx;
    public FTVectorRec[] curs; /* arrays */
    public int cur_idx;
    public FTVectorRec[] orus; /* arrays */
    public int orus_idx;
    public int max_points;

    /* ==================== IUPWorkerRec ================================== */
    public IUPWorkerRec() {
      oid++;
      id = oid;

      max_points = 0;
    }
    
    /* ==================== 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/MD5CTX.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
/* =====================================================================
 *  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;

  /* ===================================================================== */
  /*    MD5CTX                                                          */
  /*                                                                       */
  /* ===================================================================== */

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

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

    public long lo = 0;
    public long hi = 0;
    public long a = 0;
    public long b = 0;
    public long c = 0;
    public long d = 0;
    public byte[] buffer = new byte[64];
    public long[] block = new long[16];

    /* ==================== MD5CTX ================================== */
    public MD5CTX() {
      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();
    }
 
    /* =====================================================================
     * F
     * =====================================================================
     */
    private static long F(long x, long y, long z) {
//System.out.println(String.format("F fcn: x: 0x%08x, y: 0x%08x, z: 0x%08x, val: 0x%08x", x, y, z, (z ^ (x & (y ^ z)))));
      return (z ^ (x & (y ^ z)));
    }

    /* =====================================================================
     * G
     * =====================================================================
     */
    private static long G(long x, long y, long z) {
//System.out.println(String.format("G fcn: x: 0x%08x, y: 0x%08x, z: 0x%08x, val: 0x%08x", x, y, z, (y ^ (z & (x ^ y)))));
      return (y ^ (z & (x ^ y)));
    }

    /* =====================================================================
     * H
     * =====================================================================
     */
    private static long H(long x, long y, long z) {
//System.out.println(String.format("H fcn: x: 0x%08x, y: 0x%08x, z: 0x%08x, val: 0x%08x", x, y, z, (x ^ y ^ z)));
      return (x ^ y ^ z);
    }

    /* =====================================================================
     * I
     * =====================================================================
     */
    private static long I(long x, long y, long z) {
Debug(0, DBG_RENDER, TAG, String.format("I fcn: x: 0x%08x, y: 0x%08x, z: 0x%08x, val: 0x%08x", x, y, z, (y ^ (x | ~z))));
      return (y ^ (x | ~z));
    }

    /* =====================================================================
     * SET
     * =====================================================================
     */
    private static long SET(MD5CTX ctx, byte[] ptr, int ptr_idx, int n) {
//System.out.println(String.format("SET: 0x%08x 0x%08x 0x%08x 0x%08x", ptr[(ptr_idx + n) * 4],
//              ((ptr[(ptr_idx + n) * 4 + 1] & 0xFF) << 8),
//              ((ptr[(ptr_idx + n) * 4 + 2] & 0xFF) << 16),
//              ((ptr[(ptr_idx + n) * 4 + 3] & 0xFF) << 24)));
      ctx.block[n] = (ptr[(ptr_idx + n) * 4] & 0xFF) |
	            ((ptr[(ptr_idx + n) * 4 + 1] & 0xFF) << 8) |
	            ((ptr[(ptr_idx + n) * 4 + 2] & 0xFF) << 16) |
	            ((ptr[(ptr_idx + n) * 4 + 3] & 0xFF) << 24);
      ctx.block[n] &= 0xFFFFFFFFL;
      return ctx.block[n];
    }

    /* =====================================================================
     * GET
     * =====================================================================
     */
    private static long GET(MD5CTX ctx, int n) {
      return ctx.block[n];
    }

    /* =====================================================================
     * STEP
     * =====================================================================
     */
    private static long STEP(String func, long a, long b, long c, long d, 
            long x, long t, long s) {
      
      a = a & 0xFFFFFFFFL;
      b = b & 0xFFFFFFFFL;
      c = c & 0xFFFFFFFFL;
      d = d & 0xFFFFFFFFL;
      x = x & 0xFFFFFFFFL;
      t = t & 0xFFFFFFFFL;
      s = s & 0xFFFFFFFFL;
//System.out.println(String.format("STEP F01: x: 0x%08x, t: 0x%08x, a: 0x%08x", x, t, a));        
      switch(func) {
      case "F":
        a += F(b, c, d) + x + t;
//System.out.println(String.format("STEP F1: x: 0x%08x, t: 0x%08x, s: 0x%08x, a: 0x%08x", x, t, s, a));        
//System.out.println(String.format("a1: 0x%08x, a2: 0x%08x", (a << s) & 0xFFFFFFFFL, ((((long)a & 0xFFFFFFFFL) >> (32 - s))) & 0xFFFFFFFFL));
        a = ((a << s) & 0xFFFFFFFFL) | ((((long)a & 0xFFFFFFFFL) >> (32 - s) & 0xFFFFFFFFL));
//System.out.println(String.format("STEP F2: a: 0x%08x", a));        
        a += b;
        a &= 0xFFFFFFFFL;
//System.out.println(String.format("STEP F3: a: 0x%08x", a));        
        break;
      case "G":
//System.out.println(String.format("STEP F02: a: 0x%08x 0x%08x", a, G(b, c, d) + x + t));        
        a += G(b, c, d) + x + t;
//System.out.println(String.format("STEP G1: x: 0x%08x, t: 0x%08x, s: 0x%08x, a: 0x%08x", x, t, s, a & 0xFFFFFFFFL));        
//System.out.println(String.format("a1: 0x%08x, a2: 0x%08x", (a << s) & 0xFFFFFFFFL, ((((long)a & 0xFFFFFFFFL) >> (32 - s))) & 0xFFFFFFFFL));
        a = ((a << s) & 0xFFFFFFFFL) | ((((long)a & 0xFFFFFFFFL) >> (32 - s) & 0xFFFFFFFFL));
//System.out.println(String.format("STEP G2: a: 0x%08x", a));        
        a += b;
        a &= 0xFFFFFFFFL;
//System.out.println(String.format("STEP G3: a: 0x%08x", a));        
        break;
      case "H":
        a += H(b, c, d) + x + t;
//System.out.println(String.format("STEP H1: x: 0x%08x, t: 0x%08x, s: 0x%08x, a: 0x%08x", x, t, s, a));        
//System.out.println(String.format("a1: 0x%08x, a2: 0x%08x", (a << s) & 0xFFFFFFFFL, ((((long)a & 0xFFFFFFFFL) >> (32 - s))) & 0xFFFFFFFFL));
        a = ((a << s) & 0xFFFFFFFFL) | ((((long)a & 0xFFFFFFFFL) >> (32 - s) & 0xFFFFFFFFL));
//System.out.println(String.format("STEP H2: a: 0x%08x", a));        
        a += b;
        a &= 0xFFFFFFFFL;
//System.out.println(String.format("STEP H3: a: 0x%08x", a));        
        break;
      case "I":
        a += I(b, c, d) + x + t;
//System.out.println(String.format("STEP I1: x: 0x%08x, t: 0x%08x, s: 0x%08x, a: 0x%08x", x, t, s, a));        
//System.out.println(String.format("a1: 0x%08x, a2: 0x%08x", (a << s) & 0xFFFFFFFFL, ((((long)a & 0xFFFFFFFFL) >> (32 - s))) & 0xFFFFFFFFL));
        a = ((a << s) & 0xFFFFFFFFL) | ((((long)a & 0xFFFFFFFFL) >> (32 - s) & 0xFFFFFFFFL));
//System.out.println(String.format("STEP I2: a: 0x%08x", a));        
        a += b;
        a &= 0xFFFFFFFFL;
//System.out.println(String.format("STEP I3: a: 0x%08x", a));        
        break;
      }
      return a;
    }

    /* =====================================================================
     * body
     *
     * This processes one or more 64-byte data blocks, but does NOT update
     * the bit counters.  There are no alignment requirements.
     * =====================================================================
     */
    public static int body(FTReference<MD5CTX> ctx_ref, FTReference<byte[]> data_ref, int ptr_idx, long size) {
      byte[] ptr;
      MD5CTX ctx = ctx_ref.Get();
      long a;
      long b;
      long c;
      long d;
      long saved_a;
      long saved_b;
      long saved_c;
      long saved_d;

Debug(0, DBG_RENDER, TAG, "BODY:");
      ptr = data_ref.Get();
      ctx.a = ctx.a & 0xFFFFFFFFL;
      ctx.b = ctx.b & 0xFFFFFFFFL;
      ctx.c = ctx.c & 0xFFFFFFFFL;
      ctx.d = ctx.d & 0xFFFFFFFFL;
      a = ctx.a;
      b = ctx.b;
      c = ctx.c;
      d = ctx.d;
Debug(0, DBG_RENDER, TAG, String.format("ctx.a: 0x%08x", a));
Debug(0, DBG_RENDER, TAG, String.format("ctx.b: 0x%08x", b));
Debug(0, DBG_RENDER, TAG, String.format("ctx.c: 0x%08x", c));
Debug(0, DBG_RENDER, TAG, String.format("ctx.d: 0x%08x", d));
      do {
        saved_a = a;
        saved_b = b;
        saved_c = c;
        saved_d = d;
/* Round 1 */
//System.out.println("ROUND1");        
        a = STEP("F", a, b, c, d, SET(ctx, ptr, ptr_idx, 0), 0xd76aa478, 7);
//System.out.println(String.format("F: a: 0x%08x", a));
        d = STEP("F", d, a, b, c, SET(ctx, ptr, ptr_idx, 1), 0xe8c7b756, 12);
//System.out.println(String.format("F: d: 0x%08x", d));
        c = STEP("F", c, d, a, b, SET(ctx, ptr, ptr_idx, 2), 0x242070db, 17);
//System.out.println(String.format("F: c: 0x%08x", c));
        b = STEP("F", b, c, d, a, SET(ctx, ptr, ptr_idx, 3), 0xc1bdceee, 22);
//System.out.println(String.format("F: b: 0x%08x", b));

        a = STEP("F", a, b, c, d, SET(ctx, ptr, ptr_idx, 4), 0xf57c0faf, 7);
        d = STEP("F", d, a, b, c, SET(ctx, ptr, ptr_idx, 5), 0x4787c62a, 12);
        c = STEP("F", c, d, a, b, SET(ctx, ptr, ptr_idx, 6), 0xa8304613, 17);
        b = STEP("F", b, c, d, a, SET(ctx, ptr, ptr_idx, 7), 0xfd469501, 22);
        
        a = STEP("F", a, b, c, d, SET(ctx, ptr, ptr_idx, 8), 0x698098d8, 7);
        d = STEP("F", d, a, b, c, SET(ctx, ptr, ptr_idx, 9), 0x8b44f7af, 12);
        c = STEP("F", c, d, a, b, SET(ctx, ptr, ptr_idx, 10), 0xffff5bb1, 17);
        b = STEP("F", b, c, d, a, SET(ctx, ptr, ptr_idx, 11), 0x895cd7be, 22);
        
        a = STEP("F", a, b, c, d, SET(ctx, ptr, ptr_idx, 12), 0x6b901122, 7);
        d = STEP("F", d, a, b, c, SET(ctx, ptr, ptr_idx, 13), 0xfd987193, 12);
        c = STEP("F", c, d, a, b, SET(ctx, ptr, ptr_idx, 14), 0xa679438e, 17);
        b = STEP("F", b, c, d, a, SET(ctx, ptr, ptr_idx, 15), 0x49b40821, 22);

/* Round 2 */
//System.out.println(String.format("ROUND2 a: 0x%08x, b: 0x%08x, c: 0x%08x, d: 0x%08x", a, b, c, d));        
      	a = STEP("G", a, b, c, d, GET(ctx, 1), 0xf61e2562, 5);
      	d = STEP("G", d, a, b, c, GET(ctx, 6), 0xc040b340, 9);
      	c = STEP("G", c, d, a, b, GET(ctx, 11), 0x265e5a51, 14);
      	b = STEP("G", b, c, d, a, GET(ctx, 0), 0xe9b6c7aa, 20);
      	
      	a = STEP("G", a, b, c, d, GET(ctx, 5), 0xd62f105d, 5);
      	d = STEP("G", d, a, b, c, GET(ctx, 10), 0x02441453, 9);
      	c = STEP("G", c, d, a, b, GET(ctx, 15), 0xd8a1e681, 14);
      	b = STEP("G", b, c, d, a, GET(ctx, 4), 0xe7d3fbc8, 20);
      	
      	a = STEP("G", a, b, c, d, GET(ctx, 9), 0x21e1cde6, 5);
      	d = STEP("G", d, a, b, c, GET(ctx, 14), 0xc33707d6, 9);
      	c = STEP("G", c, d, a, b, GET(ctx, 3), 0xf4d50d87, 14);
      	b = STEP("G", b, c, d, a, GET(ctx, 8), 0x455a14ed, 20);
      	
      	a = STEP("G", a, b, c, d, GET(ctx, 13), 0xa9e3e905, 5);
      	d = STEP("G", d, a, b, c, GET(ctx, 2), 0xfcefa3f8, 9);
      	c = STEP("G", c, d, a, b, GET(ctx, 7), 0x676f02d9, 14);
      	b = STEP("G", b, c, d, a, GET(ctx, 12), 0x8d2a4c8a, 20);

/* Round 3 */
//System.out.println("ROUND3");        
      	a = STEP("H", a, b, c, d, GET(ctx, 5), 0xfffa3942, 4);
      	d = STEP("H", d, a, b, c, GET(ctx, 8), 0x8771f681, 11);
      	c = STEP("H", c, d, a, b, GET(ctx, 11), 0x6d9d6122, 16);
      	b = STEP("H", b, c, d, a, GET(ctx, 14), 0xfde5380c, 23);
      	
      	a = STEP("H", a, b, c, d, GET(ctx, 1), 0xa4beea44, 4);
      	d = STEP("H", d, a, b, c, GET(ctx, 4), 0x4bdecfa9, 11);
      	c = STEP("H", c, d, a, b, GET(ctx, 7), 0xf6bb4b60, 16);
      	b = STEP("H", b, c, d, a, GET(ctx, 10), 0xbebfbc70, 23);
      	
      	a = STEP("H", a, b, c, d, GET(ctx, 13), 0x289b7ec6, 4);
      	d = STEP("H", d, a, b, c, GET(ctx, 0), 0xeaa127fa, 11);
      	c = STEP("H", c, d, a, b, GET(ctx, 3), 0xd4ef3085, 16);
      	b = STEP("H", b, c, d, a, GET(ctx, 6), 0x04881d05, 23);
      	
      	a = STEP("H", a, b, c, d, GET(ctx, 9), 0xd9d4d039, 4);
      	d = STEP("H", d, a, b, c, GET(ctx, 12), 0xe6db99e5, 11);
      	c = STEP("H", c, d, a, b, GET(ctx, 15), 0x1fa27cf8, 16);
      	b = STEP("H", b, c, d, a, GET(ctx, 2), 0xc4ac5665, 23);

/* Round 4 */
//System.out.println("ROUND4");        
      	a = STEP("I", a, b, c, d, GET(ctx, 0), 0xf4292244, 6);
      	d = STEP("I", d, a, b, c, GET(ctx, 7), 0x432aff97, 10);
      	c = STEP("I", c, d, a, b, GET(ctx, 14), 0xab9423a7, 15);
      	b = STEP("I", b, c, d, a, GET(ctx, 5), 0xfc93a039, 21);
      	
      	a = STEP("I", a, b, c, d, GET(ctx, 12), 0x655b59c3, 6);
      	d = STEP("I", d, a, b, c, GET(ctx, 3), 0x8f0ccc92, 10);
      	c = STEP("I", c, d, a, b, GET(ctx, 10), 0xffeff47d, 15);
      	b = STEP("I", b, c, d, a, GET(ctx, 1), 0x85845dd1, 21);
      	
      	a = STEP("I", a, b, c, d, GET(ctx, 8), 0x6fa87e4f, 6);
      	d = STEP("I", d, a, b, c, GET(ctx, 15), 0xfe2ce6e0, 10);
      	c = STEP("I", c, d, a, b, GET(ctx, 6), 0xa3014314, 15);
      	b = STEP("I", b, c, d, a, GET(ctx, 13), 0x4e0811a1, 21);
      	
      	a = STEP("I", a, b, c, d, GET(ctx, 4), 0xf7537e82, 6);
      	d = STEP("I", d, a, b, c, GET(ctx, 11), 0xbd3af235, 10);
      	c = STEP("I", c, d, a, b, GET(ctx, 2), 0x2ad7d2bb, 15);
      	b = STEP("I", b, c, d, a, GET(ctx, 9), 0xeb86d391, 21);

      	a += saved_a;
      	a &= 0xFFFFFFFFL;
      	b += saved_b;
        b &= 0xFFFFFFFFL;
      	c += saved_c;
        c &= 0xFFFFFFFFL;
      	d += saved_d;
        d &= 0xFFFFFFFFL;

      	ptr_idx += 64;
//System.out.println(String.format("SIZE: %d", size));              	
      } while ((size -= 64) != 0);

      ctx.a = a;
      ctx.b = b;
      ctx.c = c;
      ctx.d = d;
Debug(0, DBG_RENDER, TAG, String.format("end ctx.a: 0x%08x", a));
Debug(0, DBG_RENDER, TAG, String.format("end ctx.b: 0x%08x", b));
Debug(0, DBG_RENDER, TAG, String.format("end ctx.c: 0x%08x", c));
Debug(0, DBG_RENDER, TAG, String.format("end ctx.d: 0x%08x", d));
      ctx_ref.Set(ctx);
      return ptr_idx;
    }


    /* =====================================================================
     * MD5Init
     * =====================================================================
     */
    public static void MD5Init(FTReference<MD5CTX> ctx_ref) {
      MD5CTX ctx = ctx_ref.Get();
      ctx.a = 0x67452301;
      ctx.b = 0xefcdab89;
      ctx.c = 0x98badcfe;
      ctx.d = 0x10325476;
      ctx.lo = 0;
      ctx.hi = 0;
    }

    /* =====================================================================
     * MD5Update
     * =====================================================================
     */
    public static void MD5Update(FTReference<MD5CTX> ctx_ref, FTReference<Object> data_ref, long size) {
      long saved_lo;
      int used;
      int free;
      MD5CTX ctx = ctx_ref.Get();
      byte[] data = (byte[])data_ref.Get();
      int i;
      int ctx_buffer_idx = 0;
      int data_idx = 0;
      FTReference<byte[]> buffer_ref = new FTReference<byte[]>();
      long orig_size = size;

      saved_lo = ctx.lo;
      if ((ctx.lo = (saved_lo + size) & 0x1FFFFFFFL) < saved_lo) {
      	ctx.hi++;
      }
      ctx.hi += size >> 29;
      used = (int)(saved_lo & 0x3FL);
//System.out.println(String.format("USED: %d", used));      
      if (used != 0) {
      	free = 64 - used;
      	if (size < free) {
      	  i = 0;
          for (ctx_buffer_idx = used; ctx_buffer_idx < used + size; ctx_buffer_idx++) {
            ctx.buffer[ctx_buffer_idx] = data[i++];
          }
      	  return;
      	}
      	i = 0;
        for (ctx_buffer_idx = used; ctx_buffer_idx < used + free; ctx_buffer_idx++) {
      	  ctx.buffer[ctx_buffer_idx] = data[i++];
        }
        data_idx = free;
      	size -= free;
      	buffer_ref.Set(ctx.buffer);
      	ctx_ref.Set(ctx);
      	ctx_buffer_idx = body(ctx_ref, buffer_ref, 0, 64);
      	ctx = ctx_ref.Get();
      	ctx.buffer = buffer_ref.Get();
      }
      if (size >= 64) {
        buffer_ref.Set(data);
        ctx_ref.Set(ctx);
      	data_idx = body(ctx_ref, buffer_ref, data_idx, (size & ~0x3FL));
      	ctx = ctx_ref.Get();
      	ctx.buffer = buffer_ref.Get();
      	size &= 0x3f;
      }
      for (i = 0; i < size; i++) {
        Debug(0, DBG_RENDER, TAG, String.format("ctx.buffer[i]: %d 0x%02x", i, ctx.buffer[i]));
      }
      for (i = 0; i < size; i++) {
        ctx.buffer[i] = data[data_idx++];
      }
      ctx_ref.Set(ctx);
      data_ref.Set(data);
    }

    /* =====================================================================
     * MD5Final
     * =====================================================================
     */
    public static void MD5Final(FTReference<byte[]> result_ref, FTReference<MD5CTX> ctx_ref) {
      int used;
      int free;
      byte[] result = result_ref.Get();
      int i;
      MD5CTX ctx = ctx_ref.Get();
      FTReference<byte[]> buffer_ref = new FTReference<byte[]>();

      used = (int)(ctx.lo & 0x3FL);
      ctx.buffer[used++] = (byte)0x80;
      free = 64 - used;
      if (free < 8) {
        for (i = used; i < used + free; i++) {
      	  ctx.buffer[i] = 0;
        }
        buffer_ref.Set(ctx.buffer);
        ctx_ref.Set(ctx);
      	body(ctx_ref, buffer_ref, 0, 64);
      	ctx = ctx_ref.Get();
      	ctx.buffer = buffer_ref.Get();
      	used = 0;
      	free = 64;
      }
      for (i = used; i < used + free - 8; i++) {
        ctx.buffer[i] = 0;
      }
      ctx.lo <<= 3;
      ctx.buffer[56] = (byte)ctx.lo;
      ctx.buffer[57] = (byte)(ctx.lo >> 8);
      ctx.buffer[58] = (byte)(ctx.lo >> 16);
      ctx.buffer[59] = (byte)(ctx.lo >> 24);
      ctx.buffer[60] = (byte)ctx.hi;
      ctx.buffer[61] = (byte)(ctx.hi >> 8);
      ctx.buffer[62] = (byte)(ctx.hi >> 16);
      ctx.buffer[63] = (byte)(ctx.hi >> 24);
      buffer_ref.Set(ctx.buffer);
      ctx_ref.Set(ctx);
      body(ctx_ref, buffer_ref, 0, 64);
      ctx = ctx_ref.Get();
      ctx.buffer = buffer_ref.Get();
      result[0] = (byte)ctx.a;
      result[1] = (byte)(ctx.a >> 8);
      result[2] = (byte)(ctx.a >> 16);
      result[3] = (byte)(ctx.a >> 24);
      result[4] = (byte)ctx.b;
      result[5] = (byte)(ctx.b >> 8);
      result[6] = (byte)(ctx.b >> 16);
      result[7] = (byte)(ctx.b >> 24);
      result[8] = (byte)ctx.c;
      result[9] = (byte)(ctx.c >> 8);
      result[10] = (byte)(ctx.c >> 16);
      result[11] = (byte)(ctx.c >> 24);
      result[12] = (byte)ctx.d;
      result[13] = (byte)(ctx.d >> 8);
      result[14] = (byte)(ctx.d >> 16);
      result[15] = (byte)(ctx.d >> 24);
for(int j = 0; j < 16; j++) {
  Debug(0, DBG_RENDER, TAG, String.format("MD5 j: %d 0x%02x", j, result[j] & 0xFF));
}
      ctx = new MD5CTX();
      ctx_ref.Set(ctx);
      result_ref.Set(result);
    }

}

Added ftbase/TEncoding.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;

  /* ===================================================================== */
  /*    TEncoding                                                          */
  /*                                                                       */
  /* ===================================================================== */

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

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

    public int platform_id = -1;
    public int encoding_id = -1;
    public long encoding = 0L;

    /* ==================== TEncoding ================================== */
    public TEncoding(int platform_id, int encoding_id, long encoding) {
      oid++;
      id = oid;
      this.platform_id = platform_id;
      this.encoding_id = encoding_id;
      this.encoding = encoding;
    }
    
    /* ==================== 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();
    }
 
}