apwfreetypelib

Check-in [ed737aefee]
Login

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

Overview
Comment:fixes.
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:ed737aefee211f7604ac5cc0edcf27f04b8b1c26
User & Date: arnulf 2015-02-15 20:27:05
Context
2015-02-15
20:27
fixes. Leaf check-in: ed737aefee user: arnulf tags: trunk
2015-02-14
20:31
initial version. check-in: d7482c9d4b user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to aftbase/FTCMapClassRec.java.

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143



144







  public String toDebugString() {
    StringBuffer str = new StringBuffer(mySelf()+"\n");
    str.append("..format: "+format+'\n');
    str.append("..length: "+length+'\n');
    return str.toString();
  }

  /* ==================== getFormat ================================== */
  public TTTags.CMapFormat getFormat() {
    return format;
  }

  /* ==================== getLength ================================== */
  public int getLength() {
    return length;
  }

  /* ==================== initCMap ===================================== */
  public FTError.ErrorTag initCMap(FTCMapRec cmap) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    Log.e(TAG, "initCMap not yet implemented");
    return error;
  }
................................................................................
    return null;
  }

  /* ==================== charVariantList ===================================== */
  public int[] charVariantList(FTCMapRec cmap, int char_code) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    Log.e(TAG, "charvariantList not yet implemented");
    return null;
  }

  /* ==================== variantCharList ===================================== */
  public int[] variantCharList(FTCMapRec cmap, int variant_selector) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    Log.e(TAG, "variantcahrList not yet implemented");
    return null;
  }




}














<
<
<
<
<
<
<
<
<
<







 







|











>
>
>
|
>
>
>
>
>
>
>
56
57
58
59
60
61
62










63
64
65
66
67
68
69
...
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
  public String toDebugString() {
    StringBuffer str = new StringBuffer(mySelf()+"\n");
    str.append("..format: "+format+'\n');
    str.append("..length: "+length+'\n');
    return str.toString();
  }











  /* ==================== initCMap ===================================== */
  public FTError.ErrorTag initCMap(FTCMapRec cmap) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    Log.e(TAG, "initCMap not yet implemented");
    return error;
  }
................................................................................
    return null;
  }

  /* ==================== charVariantList ===================================== */
  public int[] charVariantList(FTCMapRec cmap, int char_code) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    Log.e(TAG, "charVariantList not yet implemented");
    return null;
  }

  /* ==================== variantCharList ===================================== */
  public int[] variantCharList(FTCMapRec cmap, int variant_selector) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    Log.e(TAG, "variantcahrList not yet implemented");
    return null;
  }

  /* ==================== getFormat ================================== */
  public TTTags.CMapFormat getFormat() {
    return format;
  }

  /* ==================== getLength ================================== */
  public int getLength() {
    return length;
  }

}

Changes to aftbase/FTCMapRec.java.

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
...
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





















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

  /* ==================== setCharmap ================================== */
  public void setCharmap(FTCharMapRec charmap) {
    this.face = charmap.getFace();
    this.encoding = charmap.getEncoding();
    this.platform_id = charmap.getPlatformId();
    this.encoding_id = charmap.getEncodingId();
  }

  /* ==================== setClazz ================================== */
  public void setClazz(FTCMapClassRec clazz) {
    this.clazz = clazz;
  }

  /* ==================== getClazz ================================== */
  public FTCMapClassRec getClazz() {
    return clazz;
  }

  /* ==================== FTCMapNew ===================================== */
  public static FTError.ErrorTag FTCMapNew(FTCMapClassRec clazz, FTCharMapRec charmap, FTReference<FTCMapRec> cmap_ref) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    FTFaceRec face;
    FTCMapRec cmap = null;

Log.e(TAG, "FTCMapNew: format"+clazz.format);
    if (clazz == null || charmap == null || charmap.getFace() == null) {
      return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;
    }
    face = charmap.getFace();
    switch (clazz.format) {
    case CMap0:
    case CMap2:
................................................................................
    case CMap14:
      cmap = new TTCMap14Rec();
      break;
    default:
      Log.e(TAG, String.format("funny TTCMapClassType: %d", clazz.format));
    }
    cmap.setCharmap(charmap);
    cmap.setClazz(clazz);

    cmap.clazz = clazz;
    error = clazz.initCMap(cmap);
      if (error != FTError.ErrorTag.ERR_OK) {
//FIXME!!      ft_cmap_done_internal(cmap);
        cmap = null;
        if (cmap_ref != null) {
          cmap_ref.Set(cmap);
        }
        return error;
      }
      /* add it to our list of charmaps */
      face.charmaps = (FTCharMapRec[])FTUtil.FT_RENEW_ARRAY(face.charmaps, FTUtilFlags.ArrayType.CHARMAPS, face.getNum_charmaps(), face.getNum_charmaps() + 1);
      face.charmaps[face.getNum_charmaps()] = (FTCharMapRec)cmap;
      face.setNum_charmaps((face.getNum_faces() + 1));
      if (cmap_ref != null) {
        cmap_ref.Set(cmap);
      }
    return error;
  }






 

}



























<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






|







 







|

<

|

|
<
<
<
<
<
<
<
<
<



|
|
>
>
>
>
>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
56
57
58
59
60
61
62


















63
64
65
66
67
68
69
70
71
72
73
74
75
76
..
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

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



















  /* ==================== FTCMapNew ===================================== */
  public static FTError.ErrorTag FTCMapNew(FTCMapClassRec clazz, FTCharMapRec charmap, FTReference<FTCMapRec> cmap_ref) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    FTFaceRec face;
    FTCMapRec cmap = null;

Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "FTCMapNew: format"+clazz.format);
    if (clazz == null || charmap == null || charmap.getFace() == null) {
      return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;
    }
    face = charmap.getFace();
    switch (clazz.format) {
    case CMap0:
    case CMap2:
................................................................................
    case CMap14:
      cmap = new TTCMap14Rec();
      break;
    default:
      Log.e(TAG, String.format("funny TTCMapClassType: %d", clazz.format));
    }
    cmap.setCharmap(charmap);
    cmap.clazz = clazz;


    error = clazz.initCMap(cmap);
    if (error != FTError.ErrorTag.ERR_OK) {
//FIXME!!      ft_cmap_done_internal(cmap);
      cmap = null;









      if (cmap_ref != null) {
        cmap_ref.Set(cmap);
      }
      return error;
    }
    /* add it to our list of charmaps */
    face.charmaps = (FTCharMapRec[])FTUtil.FT_RENEW_ARRAY(face.charmaps, FTUtilFlags.ArrayType.CHARMAPS, face.getNum_charmaps(), face.getNum_charmaps() + 1);
    face.charmaps[face.getNum_charmaps()] = cmap;
    face.setNum_charmaps((face.getNum_charmaps() + 1));
    if (cmap_ref != null) {
      cmap_ref.Set(cmap);
    }
    return error;
  }

  /* ==================== setCharmap ================================== */
  public void setCharmap(FTCharMapRec charmap) {
    this.face = charmap.getFace();
    this.encoding = charmap.getEncoding();
    this.platform_id = charmap.getPlatformId();
    this.encoding_id = charmap.getEncodingId();
  }

  /* ==================== setClazz ================================== */
  public void setClazz(FTCMapClassRec clazz) {
    this.clazz = clazz;
  }

  /* ==================== getClazz ================================== */
  public FTCMapClassRec getClazz() {
    return clazz;
  }

}

Changes to aftbase/FTCharMapRec.java.

95
96
97
98
99
100
101


102
103
104
105
106
107
108
...
115
116
117
118
119
120
121





















































































































































































































122
123
124
125
126
127
128
...
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
  protected FTTags.Encoding encoding = FTTags.Encoding.NONE;
  protected int platform_id = 0;
  protected int encoding_id = 0;


  /* ==================== FTCharMapRec ================================== */
  public FTCharMapRec() {


  }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
................................................................................
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      str.append("..encoding: "+encoding+'\n');
      str.append("..platform_id: "+platform_id+'\n');
      str.append("..encoding_id: "+encoding_id+'\n');
      return str.toString();
    }






















































































































































































































  /* ==================== getPlatformId ================================== */
  public int getPlatformId() {
    return platform_id;
  }

  /* ==================== getEncodingId ================================== */
................................................................................
  }

  /* ==================== setFace ================================== */
  public void setFace(FTFaceRec face) {
    this.face = face;
  }

  /* =====================================================================
   *    GetCMapFormat
   *
   * =====================================================================
   */
  public int GetCMapFormat() {
    FTServiceTTCMapsRec service = null;
    TTCMapInfoRec cmap_info;

    if (face == null) {
      return -1;
    }
    FTModuleRec module = face.getDriver();
Log.e(TAG, "GetCMapFormat not yet fully implemented!!");
//    service = (FTServiceTTCMapsRec)module.module_clazz.  ..mgetInterface(module, "TT_CMAP");
//      FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
    if (service == null) {
      return -1;
    }
    FTReference<TTCMapInfoRec> cmap_info_ref = new FTReference<TTCMapInfoRec>();
    if (service.getCmapInfo(this, cmap_info_ref) == FTError.ErrorTag.ERR_OK) {
      return -1;
    }
    cmap_info = cmap_info_ref.Get();
    return cmap_info.getFormat();
  }

  /* =====================================================================
   *    FTSetCharMap
   *
   * =====================================================================
   */
  public FTError.ErrorTag SetCharmap(FTFaceRec face) {
    FTCharMapRec cur[];
    int curIdx = 0;
    int limit;


    if (face == null) {
      return FTError.ErrorTag.GLYPH_INVALID_FACE_HANDLE;
    }
    cur = face.charmaps;
    if (cur == null) {
      return FTError.ErrorTag.CMAP_INVALID_CHARMAP_HANDLE;
    }
    if (GetCMapFormat() == 14)
      return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;

    limit = face.getNum_charmaps();

    for (curIdx = 0; curIdx < limit; curIdx++) {
      if (cur[curIdx] == this) {
        face.setCharmap(cur[curIdx]);
        return FTError.ErrorTag.ERR_OK;
      }
    }
    return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;
  }

  /* =====================================================================
     * FTGetCharmapIndex
     * =====================================================================
     */
    public static int  FTGetCharmapIndex(FTCharMapRec charmap) {
      int i;

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

    /* =====================================================================
     * FTSelectCharmap
     * =====================================================================
     */
    public FTError.ErrorTag FTSelectCharmap(FTFaceRec face, FTTags.Encoding encoding) {
      FTCharMapRec cur;
      int limit;


      if (face == null) {
        return FTError.ErrorTag.INTERP_INVALID_FACE_HANDLE;
      }
      if (encoding == FTTags.Encoding.NONE) {
        return FTError.ErrorTag.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 == FTTags.Encoding.UNICODE) {
//        return find_unicode_charmap(face);
        return FTError.ErrorTag.INTERP_NOT_YET_IMPLEMENTED;
      }
      cur = face.charmaps[0];
      if (cur == null) {
        return FTError.ErrorTag.INTERP_INVALID_CHARMAP_HANDLE;
      }
      limit = face.getNum_charmaps();
      for (int j = 0; j < limit; j++) {
        cur = face.charmaps[j];
        if (cur.encoding == encoding) {
          face.setCharmap(cur);
          return FTError.ErrorTag.ERR_OK;
        }
      }
      return FTError.ErrorTag.INTERP_INVALID_ARGUMENT;
    }

    /* =====================================================================
     * FTGetCharIndex
     * =====================================================================
     */
    public static int FTGetCharIndex(FTFaceRec face, int charcode) {
      int result = -1;
      int ch_code = charcode;
  
      if (face != null && face.getCharmap() != null) {
        FTCMapRec cmap = (FTCMapRec)(face.getCharmap());

        if (charcode > 0xFFFFFFFFL) {
          FTTrace.Trace(7, TAG, "FT_Get_Char_Index: too large charcode");
          FTTrace.Trace(7, TAG, String.format(" 0x%x is truncated", charcode));
        }
        result = cmap.getClazz().charIndex(cmap, ch_code);
      }
Debug(0, DebugTag.DBG_CACHE, TAG, String.format("FTGetCharIndex: 0x%04x %d", charcode, result));
      return result;
    }

    /* =====================================================================
     * find_unicode_charmap
     * =====================================================================
     */
    public static FTError.ErrorTag find_unicode_charmap(FTFaceRec face) {
      FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
      FTCharMapRec first;
      FTCharMapRec cur;
      int charmaps_idx = 0;
  
      /* caller should have already checked that `face' is valid */
 //     FT_ASSERT( face );
  
Debug(0, DebugTag.DBG_CACHE, TAG, "find_unicode_charmap:");
      first = face.charmaps[charmaps_idx];
      if (first == null) {
        return FTError.ErrorTag.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.getNum_charmaps() - 1;
      for ( ; charmaps_idx >= 0; charmaps_idx--) {
        cur = face.charmaps[charmaps_idx];
if (cur == null) {
  return FTError.ErrorTag.LOAD_INVALID_CHARMAP_HANDLE;
}
        if (cur.encoding == FTTags.Encoding.UNICODE) {
          /* XXX If some new encodings to represent UCS-4 are added, */
          /*     they should be added here.                          */
          if ((cur.platform_id == TTTags.Platform.MICROSOFT.getVal() && cur.encoding_id == TTTags.MsId.UCS_4.getVal())     ||
               (cur.platform_id == TTTags.Platform.APPLE_UNICODE.getVal() && cur.encoding_id == TTTags.AppleId.UNICODE_32.getVal())) {
            face.setCharmap(cur);
            return FTError.ErrorTag.ERR_OK;
          }
        }
      }
      /* We do not have any UCS-4 charmap.                */
      /* Do the loop again and search for UCS-2 charmaps. */
      charmaps_idx = face.getNum_charmaps() - 1;
      for ( ; charmaps_idx >= 0; charmaps_idx--) {
        cur = face.charmaps[charmaps_idx];
        if (cur.encoding == FTTags.Encoding.UNICODE) {
          face.setCharmap(cur);
          return FTError.ErrorTag.ERR_OK;
        }
      }
      return FTError.ErrorTag.LOAD_INVALID_CHARMAP_HANDLE;
    }

}







>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
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
...
371
372
373
374
375
376
377








378














































































































































































































  protected FTTags.Encoding encoding = FTTags.Encoding.NONE;
  protected int platform_id = 0;
  protected int encoding_id = 0;


  /* ==================== FTCharMapRec ================================== */
  public FTCharMapRec() {
    oid++;
    id = oid;
  }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
................................................................................
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      str.append("..encoding: "+encoding+'\n');
      str.append("..platform_id: "+platform_id+'\n');
      str.append("..encoding_id: "+encoding_id+'\n');
      return str.toString();
    }

  /* =====================================================================
   *    GetCMapFormat
   *
   * =====================================================================
   */
  public int GetCMapFormat() {
    FTServiceTTCMapsRec service = null;
    TTCMapInfoRec cmap_info;

    if (face == null) {
      return -1;
    }
    FTModuleRec module = face.getDriver();
Log.e(TAG, "GetCMapFormat not yet fully implemented!!");
//    service = (FTServiceTTCMapsRec)module.module_clazz.  ..mgetInterface(module, "TT_CMAP");
//      FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
    if (service == null) {
      return -1;
    }
    FTReference<TTCMapInfoRec> cmap_info_ref = new FTReference<TTCMapInfoRec>();
    if (service.getCmapInfo(this, cmap_info_ref) == FTError.ErrorTag.ERR_OK) {
      return -1;
    }
    cmap_info = cmap_info_ref.Get();
    return cmap_info.getFormat();
  }

  /* =====================================================================
   *    SetCharMap
   *
   * =====================================================================
   */
  public FTError.ErrorTag SetCharmap(FTFaceRec face) {
    FTCharMapRec cur[];
    int curIdx = 0;
    int limit;


    if (face == null) {
      return FTError.ErrorTag.GLYPH_INVALID_FACE_HANDLE;
    }
    cur = face.charmaps;
    if (cur == null) {
      return FTError.ErrorTag.CMAP_INVALID_CHARMAP_HANDLE;
    }
    if (GetCMapFormat() == 14)
      return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;

    limit = face.getNum_charmaps();

    for (curIdx = 0; curIdx < limit; curIdx++) {
      if (cur[curIdx] == this) {
        face.setCharmap(cur[curIdx]);
        return FTError.ErrorTag.ERR_OK;
      }
    }
    return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;
  }

  /* =====================================================================
   * FTGetCharmapIndex
   * =====================================================================
   */
  public int  FTGetCharmapIndex() {
    int i;

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

  /* =====================================================================
   * FTSelectCharmap
   * =====================================================================
   */
  public FTError.ErrorTag FTSelectCharmap(FTFaceRec face, FTTags.Encoding encoding) {
    FTCharMapRec cur;
    int limit;

    if (face == null) {
      return FTError.ErrorTag.INTERP_INVALID_FACE_HANDLE;
    }
    if (encoding == FTTags.Encoding.NONE) {
      return FTError.ErrorTag.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 == FTTags.Encoding.UNICODE) {
//        return find_unicode_charmap(face);
      return FTError.ErrorTag.INTERP_NOT_YET_IMPLEMENTED;
    }
    cur = face.charmaps[0];
    if (cur == null) {
      return FTError.ErrorTag.INTERP_INVALID_CHARMAP_HANDLE;
    }
    limit = face.getNum_charmaps();
    for (int j = 0; j < limit; j++) {
      cur = face.charmaps[j];
      if (cur.encoding == encoding) {
        face.setCharmap(cur);
        return FTError.ErrorTag.ERR_OK;
      }
    }
    return FTError.ErrorTag.INTERP_INVALID_ARGUMENT;
  }

  /* =====================================================================
   * FTGetCharIndex
   * =====================================================================
   */
  public static int FTGetCharIndex(FTFaceRec face, int charcode) {
    int result = -1;
    int ch_code = charcode;
  
    if (face != null && face.getCharmap() != null) {
      FTCMapRec cmap = (FTCMapRec)(face.getCharmap());

      if (charcode > 0xFFFFFFFFL) {
        FTTrace.Trace(7, TAG, "FT_Get_Char_Index: too large charcode");
        FTTrace.Trace(7, TAG, String.format(" 0x%x is truncated", charcode));
      }
      result = cmap.getClazz().charIndex(cmap, ch_code);
    }
Debug(0, DebugTag.DBG_CACHE, TAG, String.format("FTGetCharIndex: 0x%04x %d", charcode, result));
    return result;
  }

  /* =====================================================================
   * find_unicode_charmap
   * =====================================================================
   */
  public static FTError.ErrorTag find_unicode_charmap(FTFaceRec face) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    FTCharMapRec first;
    FTCharMapRec cur;
    int charmaps_idx = 0;
  
    /* caller should have already checked that `face' is valid */
 //     FT_ASSERT( face );
  
Debug(0, DebugTag.DBG_CACHE, TAG, "find_unicode_charmap:");
    first = face.charmaps[charmaps_idx];
    if (first == null) {
      return FTError.ErrorTag.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.getNum_charmaps() - 1;
    for ( ; charmaps_idx >= 0; charmaps_idx--) {
      cur = face.charmaps[charmaps_idx];
if (cur == null) {
  return FTError.ErrorTag.LOAD_INVALID_CHARMAP_HANDLE;
}
      if (cur.encoding == FTTags.Encoding.UNICODE) {
        /* XXX If some new encodings to represent UCS-4 are added, */
        /*     they should be added here.                          */
        if ((cur.platform_id == TTTags.Platform.MICROSOFT.getVal() && cur.encoding_id == TTTags.MsId.UCS_4.getVal())     ||
             (cur.platform_id == TTTags.Platform.APPLE_UNICODE.getVal() && cur.encoding_id == TTTags.AppleId.UNICODE_32.getVal())) {
          face.setCharmap(cur);
          return FTError.ErrorTag.ERR_OK;
        }
      }
    }
    /* We do not have any UCS-4 charmap.                */
    /* Do the loop again and search for UCS-2 charmaps. */
    charmaps_idx = face.getNum_charmaps() - 1;
    for ( ; charmaps_idx >= 0; charmaps_idx--) {
      cur = face.charmaps[charmaps_idx];
      if (cur.encoding == FTTags.Encoding.UNICODE) {
        face.setCharmap(cur);
        return FTError.ErrorTag.ERR_OK;
      }
    }
    return FTError.ErrorTag.LOAD_INVALID_CHARMAP_HANDLE;
  }

  /* ==================== getPlatformId ================================== */
  public int getPlatformId() {
    return platform_id;
  }

  /* ==================== getEncodingId ================================== */
................................................................................
  }

  /* ==================== setFace ================================== */
  public void setFace(FTFaceRec face) {
    this.face = face;
  }









}














































































































































































































Changes to aftbase/FTOutlineRec.java.

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
          v_last.setX(v_start.getX());
          v_last.setY(v_start.getY());
        }
        pointIdx--;
        tagsIdx--;
      }
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "Decompose:");
      FTTrace.Trace(7, TAG, String.format("  move to (%.2f, %.2f)",
                  v_start.getX() / 64.0, v_start.getY() / 64.0));
      error = moveTo(v_start, user);
      FTTrace.Trace(7, TAG, String.format("  move to after (%.2f, %.2f)",
          v_start.getX() / 64.0, v_start.getY() / 64.0));
      if (error != FTError.ErrorTag.ERR_OK) {
        FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
        return error;
      }
      while (pointIdx < limit) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("decompose1: pointIdx: %d, limit: %d, n: %d, outline.n_contours: %d", pointIdx, limit, n, n_contours));
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("==2 v_start.x: %d, v_start.y: %d", v_start.getX(), v_start.getY()));
................................................................................
        pointIdx++;
        tagsIdx++;
        tag = tags[tagsIdx];
        if (tag.contains(Flags.Curve.ON)) {
          /* emit a single line_to */
          FTVectorRec vec = new FTVectorRec();

Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "FT_CURVE_TAG_ON");
          vec.setX((((points[pointIdx].getX())) << shift) - delta);
          vec.setY(((points[pointIdx].getY()) << shift) - delta);
          FTTrace.Trace(7, TAG, String.format("  line to (%.2f, %.2f)\n",
                vec.getX() / 64.0, vec.getY() / 64.0));
          error = lineTo(vec, user);
          if (error != FTError.ErrorTag.ERR_OK) {
            FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
            return error;
          }
          continue;
        }







|
|

|
|







 







|


|
|







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
          v_last.setX(v_start.getX());
          v_last.setY(v_start.getY());
        }
        pointIdx--;
        tagsIdx--;
      }
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "Decompose:");
      FTTrace.Trace(7, TAG, String.format("  move to (%.2f, %.2f), x: %d, y: %d",
                  v_start.getX() / 64.0, v_start.getY() / 64.0, v_start.getX(), v_start.getY()));
      error = moveTo(v_start, user);
      FTTrace.Trace(7, TAG, String.format("  move to after (%.2f, %.2f), x: %d, y: %d",
          v_start.getX() / 64.0, v_start.getY() / 64.0, v_start.getX(), v_start.getY()));
      if (error != FTError.ErrorTag.ERR_OK) {
        FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
        return error;
      }
      while (pointIdx < limit) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("decompose1: pointIdx: %d, limit: %d, n: %d, outline.n_contours: %d", pointIdx, limit, n, n_contours));
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("==2 v_start.x: %d, v_start.y: %d", v_start.getX(), v_start.getY()));
................................................................................
        pointIdx++;
        tagsIdx++;
        tag = tags[tagsIdx];
        if (tag.contains(Flags.Curve.ON)) {
          /* emit a single line_to */
          FTVectorRec vec = new FTVectorRec();

Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("FT_CURVE_TAG_ON shift: %d, delta: %d", shift, delta));
          vec.setX((((points[pointIdx].getX())) << shift) - delta);
          vec.setY(((points[pointIdx].getY()) << shift) - delta);
          FTTrace.Trace(7, TAG, String.format("  line to (%.2f, %.2f) x: %d y: %d\n",
                vec.getX() / 64.0, vec.getY() / 64.0, vec.getX(), vec.getY()));
          error = lineTo(vec, user);
          if (error != FTError.ErrorTag.ERR_OK) {
            FTTrace.Trace(7, TAG, String.format("FT_Outline_Decompose: Error %d", error));
            return error;
          }
          continue;
        }

Changes to aftbase/FTSizeMetricsRec.java.

78
79
80
81
82
83
84















































































































































85
86
87
88
89
90
91
...
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
    y_scale = from.y_scale;
    ascender = from.ascender;
    descender = from.descender;
    height = from.height;
    max_advance = from.max_advance;

  }
















































































































































  /* ==================== getX_ppem ================================== */
  public int getX_ppem() {
    return x_ppem;
  }

  /* ==================== setX_ppem ================================== */
................................................................................
  }

  /* ==================== setMax_advance ================================== */
  public void setMax_advance(int max_advance) {
    this.max_advance = max_advance;
  }

  /* =====================================================================
   * RequestMetrics
   * =====================================================================
   */
  public FTError.ErrorTag RequestMetrics(FTFaceRec face, FTSizeRequestRec req) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    boolean doall = true;

Debug(0, DebugTag.DBG_INIT, TAG, "FTRequestMetrics:");
    FTSizeMetricsRec metrics;

    metrics = face.getSize().metrics;
    if (face.getFace_flags().contains(Flags.Face.SCALABLE)) {
      int w = 0;
      int h = 0;
      int scaled_w = 0;
      int scaled_h = 0;

      switch (req.getType()) {
      case NOMINAL:
        h = face.getUnits_per_EM();
        w = h;
Debug(0, DebugTag.DBG_INIT, TAG, "met1: "+w+"!"+h+"!");
        break;
      case REAL_DIM:
        h = face.getAscender() - face.getDescender();
        w = h;
Debug(0, DebugTag.DBG_INIT, TAG, "met2: "+w+"!"+h+"!");
        break;
      case BBOX:
        w = face.getBbox().getxMax() - face.getBbox().getxMin();
        h = face.getBbox().getyMax() - face.getBbox().getyMin();
Debug(0, DebugTag.DBG_INIT, TAG, "met3: "+w+"!"+h+"!");
        break;
      case CELL:
        w = face.getMax_advance_width();
        h = face.getAscender() - face.getDescender();
Debug(0, DebugTag.DBG_INIT, TAG, "met4: "+w+"!"+h+"!");
        break;
      case SCALES:
        metrics.x_scale = req.getWidth();
        metrics.y_scale = req.getHeight();
        if (metrics.x_scale == 0) {
          metrics.x_scale = metrics.y_scale;
        } else {
          if (metrics.y_scale == 0) {
            metrics.y_scale = metrics.x_scale;
          }
        }
        doall = false;
Debug(0, DebugTag.DBG_INIT, TAG, "met5: "+w+"!"+h+"!");
        break;
      case MAX:
        break;
      }
      if (doall) {
        /* to be on the safe side */
        if (w < 0) {
          w = -w;
        }
        if (h < 0) {
          h = -h;
        }
        scaled_w = req.getHoriResolution() != 0
            ? ((req.getWidth() * req.getHoriResolution() + 36) / 72)
            : req.getWidth();
        scaled_h = req.getVertResolution() != 0
            ? ((req.getHeight() * req.getVertResolution() + 36) / 72)
            : req.getHeight();
Debug(0, DebugTag.DBG_INIT, TAG, "scaled_w: "+scaled_w+"!"+scaled_h+"!"+req);
        /* determine scales */
        if (req.getWidth() != 0) {
          metrics.x_scale = FTCalc.FTDivFix(scaled_w, w);
          if (req.getHeight() != 0) {
            metrics.y_scale = FTCalc.FTDivFix(scaled_h, h);
            if (req.getType() == FTTags.SizeRequestType.CELL) {
              if (metrics.y_scale > metrics.x_scale) {
                metrics.y_scale = metrics.x_scale;
              } else {
                metrics.x_scale = metrics.y_scale;
              }
            }
          } else {
          metrics.y_scale = metrics.x_scale;
            scaled_h = FTCalc.FT_MulDiv(scaled_w, h, w);
          }
        } else {
          metrics.x_scale = metrics.y_scale = FTCalc.FTDivFix(scaled_h, h);
          scaled_w = FTCalc.FT_MulDiv(scaled_h, w, h);
        }
      }
      /* calculate the ppems */
      if (req.getType() != FTTags.SizeRequestType.NOMINAL) {
        scaled_w = FTCalc.FTMulFix(face.getUnits_per_EM(), metrics.x_scale);
        scaled_h = FTCalc.FTMulFix(face.getUnits_per_EM(), metrics.y_scale);
      }
      metrics.x_ppem = (short)((scaled_w + 32) >> 6);
      metrics.y_ppem = (short)((scaled_h + 32) >> 6);
Debug(0, DebugTag.DBG_INIT, TAG, String.format("scaled: %d %d %d %d", scaled_w, scaled_h, metrics.x_ppem, metrics.y_ppem));
      FTReference<FTSizeMetricsRec> metrics_ref = new FTReference<FTSizeMetricsRec>();
      metrics_ref.Set(metrics);
      ft_recompute_scaled_metrics(face, metrics_ref);
      metrics = metrics_ref.Get();
    } else {
//        FT_ZERO( metrics );
      metrics.x_scale = 1 << 16;
      metrics.y_scale = 1 << 16;
    }
    FTTrace.Trace(7, TAG, "FT_Request_Metrics:");
    FTTrace.Trace(7, TAG, String.format("  x scale: %d (%f)",
                metrics.x_scale, metrics.x_scale / 65536.0 ));
    FTTrace.Trace(7, TAG, String.format("  y scale: %d (%f)",
                metrics.y_scale, metrics.y_scale / 65536.0 ));
    FTTrace.Trace(7, TAG, String.format("  ascender: %f", metrics.ascender / 64.0));
    FTTrace.Trace(7, TAG, String.format("  descender: %f", metrics.descender / 64.0));
    FTTrace.Trace(7, TAG, String.format("  height: %f", metrics.height / 64.0));
    FTTrace.Trace(7, TAG, String.format("  max advance: %f", metrics.max_advance / 64.0));
    FTTrace.Trace(7, TAG, String.format("  x ppem: %d", metrics.x_ppem ));
    FTTrace.Trace(7, TAG, String.format("  y ppem: %d", metrics.y_ppem ));
    return error;
  }
 
  /* =====================================================================
   * ft_recompute_scaled_metrics
   * =====================================================================
   */
  public int ft_recompute_scaled_metrics(FTFaceRec face, FTReference<FTSizeMetricsRec> metrics_ref) {
    int error = 0;
    FTSizeMetricsRec metrics = metrics_ref.Get();

Debug(0, DebugTag.DBG_INIT, TAG, "ft_recompute_scaled_metrics:");
    /* Compute root ascender, descender, test height, and max_advance */

//    metrics->ascender    = FT_PIX_CEIL( FT_MulFix( face->ascender, metrics->y_scale ) ); 
//    metrics->descender   = FT_PIX_FLOOR( FT_MulFix( face->descender, metrics->y_scale ) );
//    metrics->height      = FT_PIX_ROUND( FT_MulFix( face->height, metrics->y_scale ) );
//    metrics->max_advance = FT_PIX_ROUND( FT_MulFix( face->max_advance_width, metrics->x_scale ) );
    metrics.ascender = FTCalc.FTMulFix(face.getAscender(), metrics.y_scale);
    metrics.descender = FTCalc.FTMulFix(face.getDescender(), metrics.y_scale);
    metrics.height = FTCalc.FTMulFix(face.getHeight(), metrics.y_scale);
    metrics.max_advance = FTCalc.FTMulFix(face.getMax_advance_width(), metrics.x_scale);
    metrics_ref.Set(metrics);
    return error;
  }

}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
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
...
302
303
304
305
306
307
308







309










































































































































    y_scale = from.y_scale;
    ascender = from.ascender;
    descender = from.descender;
    height = from.height;
    max_advance = from.max_advance;

  }

  /* =====================================================================
   * RequestMetrics
   * =====================================================================
   */
  public FTError.ErrorTag RequestMetrics(FTFaceRec face, FTSizeRequestRec req) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    boolean doall = true;

Debug(0, DebugTag.DBG_SIZE, TAG, "FTRequestMetrics:");
    FTSizeMetricsRec metrics;

    metrics = face.getSize().metrics;
    if (face.getFace_flags().contains(Flags.Face.SCALABLE)) {
      int w = 0;
      int h = 0;
      int scaled_w = 0;
      int scaled_h = 0;

      switch (req.getType()) {
      case NOMINAL:
        h = face.getUnits_per_EM();
        w = h;
Debug(0, DebugTag.DBG_SIZE, TAG, "met1: "+w+"!"+h+"!");
        break;
      case REAL_DIM:
        h = face.getAscender() - face.getDescender();
        w = h;
Debug(0, DebugTag.DBG_SIZE, TAG, "met2: "+w+"!"+h+"!");
        break;
      case BBOX:
        w = face.getBbox().getxMax() - face.getBbox().getxMin();
        h = face.getBbox().getyMax() - face.getBbox().getyMin();
Debug(0, DebugTag.DBG_SIZE, TAG, "met3: "+w+"!"+h+"!");
        break;
      case CELL:
        w = face.getMax_advance_width();
        h = face.getAscender() - face.getDescender();
Debug(0, DebugTag.DBG_SIZE, TAG, "met4: "+w+"!"+h+"!");
        break;
      case SCALES:
        metrics.x_scale = req.getWidth();
        metrics.y_scale = req.getHeight();
        if (metrics.x_scale == 0) {
          metrics.x_scale = metrics.y_scale;
        } else {
          if (metrics.y_scale == 0) {
            metrics.y_scale = metrics.x_scale;
          }
        }
        doall = false;
Debug(0, DebugTag.DBG_SIZE, TAG, "met5: "+w+"!"+h+"!");
        break;
      case MAX:
        break;
      }
      if (doall) {
        /* to be on the safe side */
        if (w < 0) {
          w = -w;
        }
        if (h < 0) {
          h = -h;
        }
Debug(0, DebugTag.DBG_SIZE, TAG, "req: "+req.getWidth()+" "+req.getHeight()+" "+req.getHoriResolution()+" "+req.getVertResolution());
        scaled_w = req.getHoriResolution() != 0
            ? ((req.getWidth() * req.getHoriResolution() + 36) / 72)
            : req.getWidth();
        scaled_h = req.getVertResolution() != 0
            ? ((req.getHeight() * req.getVertResolution() + 36) / 72)
            : req.getHeight();
Debug(0, DebugTag.DBG_SIZE, TAG, "scaled_w: "+scaled_w+"!"+scaled_h+"!"+req);
        /* determine scales */
        if (req.getWidth() != 0) {
          metrics.x_scale = FTCalc.FTDivFix(scaled_w, w);
          if (req.getHeight() != 0) {
            metrics.y_scale = FTCalc.FTDivFix(scaled_h, h);
            if (req.getType() == FTTags.SizeRequestType.CELL) {
              if (metrics.y_scale > metrics.x_scale) {
                metrics.y_scale = metrics.x_scale;
              } else {
                metrics.x_scale = metrics.y_scale;
              }
            }
          } else {
            metrics.y_scale = metrics.x_scale;
            scaled_h = FTCalc.FT_MulDiv(scaled_w, h, w);
          }
        } else {
          metrics.x_scale = metrics.y_scale = FTCalc.FTDivFix(scaled_h, h);
          scaled_w = FTCalc.FT_MulDiv(scaled_h, w, h);
        }
      }
      /* calculate the ppems */
      if (req.getType() != FTTags.SizeRequestType.NOMINAL) {
        scaled_w = FTCalc.FTMulFix(face.getUnits_per_EM(), metrics.x_scale);
        scaled_h = FTCalc.FTMulFix(face.getUnits_per_EM(), metrics.y_scale);
      }
      metrics.x_ppem = (short)((scaled_w + 32) >> 6);
      metrics.y_ppem = (short)((scaled_h + 32) >> 6);
Debug(0, DebugTag.DBG_SIZE, TAG, String.format("scaled: %d %d %d %d", scaled_w, scaled_h, metrics.x_ppem, metrics.y_ppem));
      ft_recompute_scaled_metrics(face);
    } else {
//        FT_ZERO( metrics );
      metrics.x_scale = 1 << 16;
      metrics.y_scale = 1 << 16;
    }
Debug(0, DebugTag.DBG_SIZE, TAG, String.format("metrics: asc: %d, desc: %d, height: %d, max_advance: %d", metrics.ascender, metrics.descender, metrics.height, metrics.max_advance));
    FTTrace.Trace(7, TAG, "FT_Request_Metrics:");
    FTTrace.Trace(7, TAG, String.format("  x scale: %d (%f)",
                metrics.x_scale, metrics.x_scale / 65536.0 ));
    FTTrace.Trace(7, TAG, String.format("  y scale: %d (%f)",
                metrics.y_scale, metrics.y_scale / 65536.0 ));
    FTTrace.Trace(7, TAG, String.format("  ascender: %f", metrics.ascender / 64.0));
    FTTrace.Trace(7, TAG, String.format("  descender: %f", metrics.descender / 64.0));
    FTTrace.Trace(7, TAG, String.format("  height: %f", metrics.height / 64.0));
    FTTrace.Trace(7, TAG, String.format("  max advance: %f", metrics.max_advance / 64.0));
    FTTrace.Trace(7, TAG, String.format("  x ppem: %d", metrics.x_ppem ));
    FTTrace.Trace(7, TAG, String.format("  y ppem: %d", metrics.y_ppem ));
    return error;
  }
 
  /* =====================================================================
   * ft_recompute_scaled_metrics
   * =====================================================================
   */
  public int ft_recompute_scaled_metrics(FTFaceRec face) {
    int error = 0;

Debug(0, DebugTag.DBG_SIZE, TAG, "ft_recompute_scaled_metrics:");
    /* Compute root ascender, descender, test height, and max_advance */

    ascender = FTCalc.FT_PIX_CEIL(FTCalc.FTMulFix(face.getAscender(), y_scale));
    descender = FTCalc.FT_PIX_FLOOR(FTCalc.FTMulFix(face.getDescender(), y_scale));
    height = FTCalc.FT_PIX_ROUND(FTCalc.FTMulFix(face.getHeight(), y_scale));
    max_advance = FTCalc.FT_PIX_ROUND(FTCalc.FTMulFix(face.getMax_advance_width(), x_scale));

//    ascender = FTCalc.FTMulFix(face.getAscender(), y_scale);
//    descender = FTCalc.FTMulFix(face.getDescender(), y_scale);
//    height = FTCalc.FTMulFix(face.getHeight(), y_scale);
//    max_advance = FTCalc.FTMulFix(face.getMax_advance_width(), x_scale);
    return error;
  }

  /* ==================== getX_ppem ================================== */
  public int getX_ppem() {
    return x_ppem;
  }

  /* ==================== setX_ppem ================================== */
................................................................................
  }

  /* ==================== setMax_advance ================================== */
  public void setMax_advance(int max_advance) {
    this.max_advance = max_advance;
  }








}










































































































































Changes to aftbase/FTSizeRec.java.

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
...
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
...
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
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
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
...
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
  public static FTError.ErrorTag FTNewSize(FTFaceRec face, FTReference<FTSizeRec> size_ref) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    FTDriverRec driver = null;
    FTDriverClassRec clazz;
    FTSizeRec size;
    FTListNodeRec node = null;

Debug(0, DebugTag.DBG_INIT, TAG, "FTNewSize");
    if (face == null) {
      size_ref.Set(null);
      return FTError.ErrorTag.INTERP_INVALID_FACE_HANDLE;
    }
    if (face.getDriver() == null) {
      size_ref.Set(null);
      return FTError.ErrorTag.INTERP_INVALID_DRIVER_HANDLE;
................................................................................
      node.data = size;
      node.FTListAdd(face.getSizes_list());
    }
    if (error != FTError.ErrorTag.ERR_OK) {
//        FT_FREE( node );
//        FT_FREE( size );
    }
Debug(0, DebugTag.DBG_INIT, TAG, "FTNewSize END: "+error+"!");
    size_ref.Set(size);
    return error;
  }

  /* =====================================================================
   * ActivateSize
   * =====================================================================
   */
  public FTError.ErrorTag ActivateSize() {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    FTFaceRec face;

Debug(0, DebugTag.DBG_INIT, TAG, "FTActivateSize");
    face = this.face;
    if (face == null || face.getDriver() == null) {
      return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;
    }
    /* we don't need anything more complex than that; all size objects */
    /* are already listed by the face                                  */
    face.setSize(this);
Debug(0, DebugTag.DBG_INIT, TAG, "FTActivateSize END: "+error+"!");
    return error;
  }

  /* =====================================================================
   * MatchSize
   * =====================================================================
   */
  public FTError.ErrorTag MatchSize(FTFaceRec face, FTSizeRequestRec req, boolean ignore_width, FTReference<Integer> size_index_ref) {
    Debug(0, DebugTag.DBG_INIT, TAG, "FTMatchSize:");
    int i;
    int w;
    int h;

    if (!face.getFace_flags().contains(Flags.Face.FIXED_SIZES)) {
      return FTError.ErrorTag.GLYPH_INVALID_FACE_HANDLE;
    }
................................................................................
  /* =====================================================================
   * SelectMetrics
   * =====================================================================
   */
  public FTError.ErrorTag SelectMetrics(int strike_index) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    Debug(0, DebugTag.DBG_INIT, TAG, "FTSelectMetrics:");
    FTBitmapSize  bsize;

    bsize = face.getAvailable_sizes()[strike_index];
    metrics.setX_ppem(((bsize.x_ppem + 32) >> 6));
    metrics.setY_ppem(((bsize.y_ppem + 32) >> 6));
    if (face.getFace_flags().contains(Flags.Face.SCALABLE)) {
      metrics.setX_scale(FTCalc.FTDivFix(bsize.x_ppem, face.getUnits_per_EM()));
      metrics.setY_scale(FTCalc.FTDivFix(bsize.y_ppem, face.getUnits_per_EM()));
      FTReference<FTSizeMetricsRec> metrics_ref = new FTReference<FTSizeMetricsRec>();
      metrics_ref.Set(metrics);
      metrics.ft_recompute_scaled_metrics(face, metrics_ref);
      metrics = metrics_ref.Get();
    } else {
      metrics.setX_scale(1 << 16);
      metrics.setY_scale(1 << 16);
      metrics.setAscender(bsize.y_ppem);
      metrics.setDescender(0);
      metrics.setHeight(bsize.height << 6);
      metrics.setMax_advance(bsize.x_ppem);
................................................................................
  /* =====================================================================
   * SelectSize
   * =====================================================================
   */
  public FTError.ErrorTag SelectSize(FTFaceRec face, int strike_index) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    Debug(0, DebugTag.DBG_INIT, TAG, "FTSelectSize:");
    FTDriverClassRec clazz;

    if (face == null || !face.getFace_flags().contains(Flags.Face.FIXED_SIZES)) {
      return FTError.ErrorTag.GLYPH_INVALID_FACE_HANDLE;
    }
    if (strike_index < 0 || strike_index >= face.getNum_fixed_sizes()) {
      return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;
................................................................................
   */
  public FTError.ErrorTag RequestSize(FTFaceRec face, FTReference<FTSizeRequestRec> req_ref) {
    FTSizeRequestRec req = req_ref.Get();
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    FTDriverClassRec clazz;
    int strike_index;

    Debug(0, DebugTag.DBG_INIT, TAG, "FTRequestSize:");
    if (face == null) {
      return FTError.ErrorTag.GLYPH_INVALID_FACE_HANDLE;
    }
    if (req == null || req.getWidth() < 0 || req.getHeight() < 0 ||
        req.getType().getVal() >= FTTags.SizeRequestType.MAX.getVal()) {
      return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;
    }
    clazz = face.getDriver().getDriver_clazz();
    FTSizeMetricsRec metrics = face.getSize().metrics;
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "ME1: "+face.getSize().metrics.getX_ppem()+"!"+face.getSize().metrics.getY_ppem()+"!");
    error = clazz.requestSize(face.getSize(), req);
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "ME2: "+face.getSize().metrics.getX_ppem()+"!"+face.getSize().metrics.getY_ppem()+"!");
    if (error != FTError.ErrorTag.FACE_NO_SIZE_REQUEST_FUNCTION) {
      FTTrace.Trace(9, TAG, "FT_Request_Size (font driver's `request_size'):");
      FTTrace.Trace(9, TAG, String.format("  x scale: %d (%f)",
          metrics.getX_scale(), metrics.getX_scale() / 65536.0));
      FTTrace.Trace(9, TAG, String.format("  y scale: %d (%f)",
          metrics.getY_scale(), metrics.getY_scale() / 65536.0));
      FTTrace.Trace(9, TAG, String.format("  ascender: %f", metrics.getAscender() / 64.0));
      FTTrace.Trace(9, TAG, String.format("  descender: %f", metrics.getDescender() / 64.0));
      FTTrace.Trace(9, TAG, String.format("  height: %f", metrics.getHeight() / 64.0));
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "ascender: "+metrics.getAscender()+" "+metrics.getDescender()+" "+metrics.getHeight());
      FTTrace.Trace(9, TAG, String.format("  max advance: %f", metrics.getMax_advance() / 64.0));
      FTTrace.Trace(9, TAG, String.format("  x ppem: %d", metrics.getX_ppem()));
      FTTrace.Trace(9, TAG, String.format("  y ppem: %d", metrics.getY_ppem()));
      return error;
    }
    /*
     * The reason that a driver doesn't have `request_size' defined is
................................................................................
      if (error != FTError.ErrorTag.ERR_OK) {
        return error;
      }
      return SelectSize(face, (int)strike_index);
    }
    face.getSize().getMetrics().RequestMetrics(face, req);

    Debug(0, DebugTag.DBG_INIT, TAG, "FTRequestSize: done");
    return FTError.ErrorTag.ERR_OK;
  }

  /* =====================================================================
   * SetCharSize
   * =====================================================================
   */
  public FTError.ErrorTag SetCharSize(FTFaceRec face, int char_width, int char_height, int horz_resolution, int vert_resolution) {
    FTReference<FTSizeRequestRec> req_ref = new FTReference<FTSizeRequestRec>();
    FTSizeRequestRec req = new FTSizeRequestRec();

 Debug(0, DebugTag.DBG_INIT, TAG, String.format("FTSetCharSize: cw: %d ch: %d hr: %d vr: %d", char_width, char_height, horz_resolution, vert_resolution));
    if (char_width == 0) {
      char_width = char_height;
    } else {
      if (char_height == 0) {
        char_height = char_width;
      }
    }







|







 







|












|







|








|







 







|








<
<
|
<







 







|







 







|









|

|









|







 







|








|


|







79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
...
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
...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207


208

209
210
211
212
213
214
215
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
...
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
...
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
  public static FTError.ErrorTag FTNewSize(FTFaceRec face, FTReference<FTSizeRec> size_ref) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    FTDriverRec driver = null;
    FTDriverClassRec clazz;
    FTSizeRec size;
    FTListNodeRec node = null;

Debug(0, DebugTag.DBG_SIZE, TAG, "FTNewSize");
    if (face == null) {
      size_ref.Set(null);
      return FTError.ErrorTag.INTERP_INVALID_FACE_HANDLE;
    }
    if (face.getDriver() == null) {
      size_ref.Set(null);
      return FTError.ErrorTag.INTERP_INVALID_DRIVER_HANDLE;
................................................................................
      node.data = size;
      node.FTListAdd(face.getSizes_list());
    }
    if (error != FTError.ErrorTag.ERR_OK) {
//        FT_FREE( node );
//        FT_FREE( size );
    }
Debug(0, DebugTag.DBG_SIZE, TAG, "FTNewSize END: "+error+"!");
    size_ref.Set(size);
    return error;
  }

  /* =====================================================================
   * ActivateSize
   * =====================================================================
   */
  public FTError.ErrorTag ActivateSize() {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    FTFaceRec face;

Debug(0, DebugTag.DBG_SIZE, TAG, "FTActivateSize");
    face = this.face;
    if (face == null || face.getDriver() == null) {
      return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;
    }
    /* we don't need anything more complex than that; all size objects */
    /* are already listed by the face                                  */
    face.setSize(this);
Debug(0, DebugTag.DBG_SIZE, TAG, "FTActivateSize END: "+error+"!");
    return error;
  }

  /* =====================================================================
   * MatchSize
   * =====================================================================
   */
  public FTError.ErrorTag MatchSize(FTFaceRec face, FTSizeRequestRec req, boolean ignore_width, FTReference<Integer> size_index_ref) {
    Debug(0, DebugTag.DBG_SIZE, TAG, "FTMatchSize:");
    int i;
    int w;
    int h;

    if (!face.getFace_flags().contains(Flags.Face.FIXED_SIZES)) {
      return FTError.ErrorTag.GLYPH_INVALID_FACE_HANDLE;
    }
................................................................................
  /* =====================================================================
   * SelectMetrics
   * =====================================================================
   */
  public FTError.ErrorTag SelectMetrics(int strike_index) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

Debug(0, DebugTag.DBG_SIZE, TAG, "FTSelectMetrics:");
    FTBitmapSize  bsize;

    bsize = face.getAvailable_sizes()[strike_index];
    metrics.setX_ppem(((bsize.x_ppem + 32) >> 6));
    metrics.setY_ppem(((bsize.y_ppem + 32) >> 6));
    if (face.getFace_flags().contains(Flags.Face.SCALABLE)) {
      metrics.setX_scale(FTCalc.FTDivFix(bsize.x_ppem, face.getUnits_per_EM()));
      metrics.setY_scale(FTCalc.FTDivFix(bsize.y_ppem, face.getUnits_per_EM()));


      metrics.ft_recompute_scaled_metrics(face);

    } else {
      metrics.setX_scale(1 << 16);
      metrics.setY_scale(1 << 16);
      metrics.setAscender(bsize.y_ppem);
      metrics.setDescender(0);
      metrics.setHeight(bsize.height << 6);
      metrics.setMax_advance(bsize.x_ppem);
................................................................................
  /* =====================================================================
   * SelectSize
   * =====================================================================
   */
  public FTError.ErrorTag SelectSize(FTFaceRec face, int strike_index) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

Debug(0, DebugTag.DBG_SIZE, TAG, "FTSelectSize:");
    FTDriverClassRec clazz;

    if (face == null || !face.getFace_flags().contains(Flags.Face.FIXED_SIZES)) {
      return FTError.ErrorTag.GLYPH_INVALID_FACE_HANDLE;
    }
    if (strike_index < 0 || strike_index >= face.getNum_fixed_sizes()) {
      return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;
................................................................................
   */
  public FTError.ErrorTag RequestSize(FTFaceRec face, FTReference<FTSizeRequestRec> req_ref) {
    FTSizeRequestRec req = req_ref.Get();
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    FTDriverClassRec clazz;
    int strike_index;

Debug(0, DebugTag.DBG_SIZE, TAG, "FTRequestSize:");
    if (face == null) {
      return FTError.ErrorTag.GLYPH_INVALID_FACE_HANDLE;
    }
    if (req == null || req.getWidth() < 0 || req.getHeight() < 0 ||
        req.getType().getVal() >= FTTags.SizeRequestType.MAX.getVal()) {
      return FTError.ErrorTag.GLYPH_INVALID_ARGUMENT;
    }
    clazz = face.getDriver().getDriver_clazz();
    FTSizeMetricsRec metrics = face.getSize().metrics;
Debug(0, DebugTag.DBG_SIZE, TAG, "ME1: "+face.getSize().metrics.getX_ppem()+"!"+face.getSize().metrics.getY_ppem()+"!");
    error = clazz.requestSize(face.getSize(), req);
Debug(0, DebugTag.DBG_SIZE, TAG, "ME2: "+face.getSize().metrics.getX_ppem()+"!"+face.getSize().metrics.getY_ppem()+"!");
    if (error != FTError.ErrorTag.FACE_NO_SIZE_REQUEST_FUNCTION) {
      FTTrace.Trace(9, TAG, "FT_Request_Size (font driver's `request_size'):");
      FTTrace.Trace(9, TAG, String.format("  x scale: %d (%f)",
          metrics.getX_scale(), metrics.getX_scale() / 65536.0));
      FTTrace.Trace(9, TAG, String.format("  y scale: %d (%f)",
          metrics.getY_scale(), metrics.getY_scale() / 65536.0));
      FTTrace.Trace(9, TAG, String.format("  ascender: %f", metrics.getAscender() / 64.0));
      FTTrace.Trace(9, TAG, String.format("  descender: %f", metrics.getDescender() / 64.0));
      FTTrace.Trace(9, TAG, String.format("  height: %f", metrics.getHeight() / 64.0));
Debug(0, DebugTag.DBG_SIZE, TAG, "ascender: "+metrics.getAscender()+" "+metrics.getDescender()+" "+metrics.getHeight());
      FTTrace.Trace(9, TAG, String.format("  max advance: %f", metrics.getMax_advance() / 64.0));
      FTTrace.Trace(9, TAG, String.format("  x ppem: %d", metrics.getX_ppem()));
      FTTrace.Trace(9, TAG, String.format("  y ppem: %d", metrics.getY_ppem()));
      return error;
    }
    /*
     * The reason that a driver doesn't have `request_size' defined is
................................................................................
      if (error != FTError.ErrorTag.ERR_OK) {
        return error;
      }
      return SelectSize(face, (int)strike_index);
    }
    face.getSize().getMetrics().RequestMetrics(face, req);

Debug(0, DebugTag.DBG_SIZE, TAG, "FTRequestSize: done");
    return FTError.ErrorTag.ERR_OK;
  }

  /* =====================================================================
   * SetCharSize
   * =====================================================================
   */
  public FTError.ErrorTag SetCharSize(FTFaceRec face, int char_width, int char_height, int horz_resolution, int vert_resolution) {
    FTReference<FTSizeRequestRec> req_ref = new FTReference<>();
    FTSizeRequestRec req = new FTSizeRequestRec();

 Debug(0, DebugTag.DBG_SIZE, TAG, String.format("FTSetCharSize: cw: %d ch: %d hr: %d vr: %d", char_width, char_height, horz_resolution, vert_resolution));
    if (char_width == 0) {
      char_width = char_height;
    } else {
      if (char_height == 0) {
        char_height = char_width;
      }
    }

Changes to aftbase/FTValidatorRec.java.

49
50
51
52
53
54
55






56
57
58
59
60
61
62
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  /* ==================== toDebugString ===================================== */
  public String toDebugString() {
    StringBuffer str = new StringBuffer(mySelf()+"\n");
    str.append("..level: "+level+'\n');
    str.append("..error: "+error+'\n');
    return str.toString();
  }







  /* ==================== getLevel ============================== */
  public FTTags.Validate getLevel() {
    return level;
  }

  /* ==================== getError ============================== */
................................................................................
  }

  /* ==================== setError ============================== */
  public void setError(FTError.ErrorTag errror) {
    this.error = error;
  }

  /* ==================== init ============================== */
  public void init(FTTags.Validate level) {
    level = level;
    error = FTError.ErrorTag.ERR_OK;
  }

}







>
>
>
>
>
>







 







<
<
<
<
|
<
<
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
..
71
72
73
74
75
76
77




78


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

  /* ==================== init ============================== */
  public void init(FTTags.Validate level) {
    this.level = level;
    error = FTError.ErrorTag.ERR_OK;
  }

  /* ==================== getLevel ============================== */
  public FTTags.Validate getLevel() {
    return level;
  }

  /* ==================== getError ============================== */
................................................................................
  }

  /* ==================== setError ============================== */
  public void setError(FTError.ErrorTag errror) {
    this.error = error;
  }





}


Changes to aftbase/MD5CTX.java.

445
446
447
448
449
450
451
452
453
454
455
456
    result[10] = (byte)(this.c >> 16);
    result[11] = (byte)(this.c >> 24);
    result[12] = (byte)this.d;
    result[13] = (byte)(this.d >> 8);
    result[14] = (byte)(this.d >> 16);
    result[15] = (byte)(this.d >> 24);
for(int j = 0; j < 16; j++) {
  Debug(2, DebugTag.DBG_MD5, TAG, String.format("MD5 j: %d 0x%02x", j, result[j] & 0xFF));
}
  }

}







|




445
446
447
448
449
450
451
452
453
454
455
456
    result[10] = (byte)(this.c >> 16);
    result[11] = (byte)(this.c >> 24);
    result[12] = (byte)this.d;
    result[13] = (byte)(this.d >> 8);
    result[14] = (byte)(this.d >> 16);
    result[15] = (byte)(this.d >> 24);
for(int j = 0; j < 16; j++) {
  Debug(0, DebugTag.DBG_MD5, TAG, String.format("MD5 j: %d 0x%02x", j, result[j] & 0xFF));
}
  }

}

Changes to aftcache/FTCSizeListClass.java.

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  /* =====================================================================
   *    ftc_size_node_init
   *
   * =====================================================================
   */
  public FTError.ErrorTag ftc_size_node_init(FTReference<FTCMruNodeRec> obj_ref, Object key, Object data) {
    FTCSizeNodeRec size_node = (FTCSizeNodeRec)obj_ref.Get();
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

Debug(0, DebugTag.DBG_CACHE, TAG, "ftc_size_node_init");
    size_node.setScaler((FTCScalerRec)key);
    FTReference<FTSizeRec> size_ref = new FTReference<FTSizeRec>();
    error = ((FTCScalerRec)key).ftc_scaler_lookup_size((FTCManagerRec)data, (FTCScalerRec)key, size_ref);
    size_node.setSize(size_ref.Get());
    obj_ref.Set(size_node);







|







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  /* =====================================================================
   *    ftc_size_node_init
   *
   * =====================================================================
   */
  public FTError.ErrorTag ftc_size_node_init(FTReference<FTCMruNodeRec> obj_ref, Object key, Object data) {
    FTCSizeNodeRec size_node = (FTCSizeNodeRec)obj_ref.Get();
    FTError.ErrorTag error;

Debug(0, DebugTag.DBG_CACHE, TAG, "ftc_size_node_init");
    size_node.setScaler((FTCScalerRec)key);
    FTReference<FTSizeRec> size_ref = new FTReference<FTSizeRec>();
    error = ((FTCScalerRec)key).ftc_scaler_lookup_size((FTCManagerRec)data, (FTCScalerRec)key, size_ref);
    size_node.setSize(size_ref.Get());
    obj_ref.Set(size_node);

Changes to aftdemo/FTDemoFaceRequester.java.

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import org.apwtcl.apwfreetypelib.aftutil.FTError;
import org.apwtcl.apwfreetypelib.aftutil.FTReference;

public class FTDemoFaceRequester extends FTFaceRequester {
  private static int oid = 0;

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

  /* ==================== FTCSBitRec ================================== */
  public FTDemoFaceRequester() {
    oid++;
    id = oid;
  }

................................................................................
  @Override
  public FTError.ErrorTag requestFace(Object face_id, FTLibraryRec library, Object request_data, FTReference<FTFaceRec> face_ref) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    FTFaceRec face = null;
    TFont font = (TFont)face_id;

    face_ref.Set(null);
Debug(0, DebugTag.DBG_INIT, TAG, "my_face_requester");
    if (font.getFile_address() != null) {
      Log.w(TAG, "file_address not yet implemented");
//        error = FTNewMemoryFace(lib,
//               (byte[]*)font.file_address, font.file_size, font.face_index, aface);
    } else {
      error = FTFaceRec.FTNewFace(library, font.getFilepathname(), font.getFace_index(), face_ref);
      face = face_ref.Get();







|







 







|







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import org.apwtcl.apwfreetypelib.aftutil.FTError;
import org.apwtcl.apwfreetypelib.aftutil.FTReference;

public class FTDemoFaceRequester extends FTFaceRequester {
  private static int oid = 0;

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

  /* ==================== FTCSBitRec ================================== */
  public FTDemoFaceRequester() {
    oid++;
    id = oid;
  }

................................................................................
  @Override
  public FTError.ErrorTag requestFace(Object face_id, FTLibraryRec library, Object request_data, FTReference<FTFaceRec> face_ref) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    FTFaceRec face = null;
    TFont font = (TFont)face_id;

    face_ref.Set(null);
Debug(0, DebugTag.DBG_INIT, TAG, "requestFace");
    if (font.getFile_address() != null) {
      Log.w(TAG, "file_address not yet implemented");
//        error = FTNewMemoryFace(lib,
//               (byte[]*)font.file_address, font.file_size, font.face_index, aface);
    } else {
      error = FTFaceRec.FTNewFace(library, font.getFilepathname(), font.getFace_index(), face_ref);
      face = face_ref.Get();

Changes to aftdemo/demo1.java.

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
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

      if (error != FTError.ErrorTag.ERR_OK) {
        Log.e(TAG, "could not load glyph 72");
        return;
      }


        FTFaceRequester requester = new FTDemoFaceRequester();
      FTCManagerRec manager = new FTCManagerRec(library, max_faces, max_sizes, requester, font_args);

      FTCGCacheClassRec sbits_cache = new FTCBasicSCacheClass();    /* the glyph small bitmaps cache */
      error = manager.RegisterCache(sbits_cache);
Debug(0, DebugTag.DBG_INIT, TAG, "sbits_cache: " + sbits_cache.toDebugString());
      if (error != FTError.ErrorTag.ERR_OK) {
        Log.e(TAG, "could not initialize small bitmaps cache");
................................................................................
      error = manager.RegisterCache(image_cache);
      if (error != FTError.ErrorTag.ERR_OK) {
        Log.e(TAG, "could not initialize glyph image cache");
        return;
      }

      FTCGCacheClassRec cmap_cache = new FTCCMapCacheClass();     /* the charmap cache             */
      Debug(0, DebugTag.DBG_INIT, TAG, "cmap_cache: " + cmap_cache.toDebugString());
      error = manager.RegisterCache(cmap_cache);
      if (error != FTError.ErrorTag.ERR_OK) {
        Log.e(TAG, "could not initialize charmap cache");
        return;
      }

      FTBitmapRec bitmap = new FTBitmapRec();
      FTStrokerRec stroker = new FTStrokerRec(library);

      FTReference<FTSizeRec> size_ref = new FTReference<>();
      FTSizeRec size = null;
      FTCScalerRec scaler = new FTCScalerRec();
      scaler.setFace_id(font_args);




      error = manager.LookupSize(scaler, size_ref);
      if (error != FTError.ErrorTag.ERR_OK) {
        Log.e(TAG, "could not initialize size rec");
        return;
      }
      size = size_ref.Get();

//FIXME!!
      font_args.setCmap_index(0);
      int charcode = 'H';
      int gindex;




      gindex = ((FTCCMapCacheClass) cmap_cache).FTCCMapCacheLookup(font_args, font_args.getCmap_index(), charcode);
      System.out.println(String.format("gindex for charcode: %c 0x%02x %d", charcode, charcode, gindex));

      charcode = 'e';
      gindex = ((FTCCMapCacheClass) cmap_cache).FTCCMapCacheLookup(font_args, font_args.getCmap_index(), charcode);
      System.out.println(String.format("gindex for charcode: %c 0x%02x %d", charcode, charcode, gindex));








|







 







|













>
>
>
>








|
|

>
>
>
>







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
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

      if (error != FTError.ErrorTag.ERR_OK) {
        Log.e(TAG, "could not load glyph 72");
        return;
      }


      FTFaceRequester requester = new FTDemoFaceRequester();
      FTCManagerRec manager = new FTCManagerRec(library, max_faces, max_sizes, requester, font_args);

      FTCGCacheClassRec sbits_cache = new FTCBasicSCacheClass();    /* the glyph small bitmaps cache */
      error = manager.RegisterCache(sbits_cache);
Debug(0, DebugTag.DBG_INIT, TAG, "sbits_cache: " + sbits_cache.toDebugString());
      if (error != FTError.ErrorTag.ERR_OK) {
        Log.e(TAG, "could not initialize small bitmaps cache");
................................................................................
      error = manager.RegisterCache(image_cache);
      if (error != FTError.ErrorTag.ERR_OK) {
        Log.e(TAG, "could not initialize glyph image cache");
        return;
      }

      FTCGCacheClassRec cmap_cache = new FTCCMapCacheClass();     /* the charmap cache             */
Debug(0, DebugTag.DBG_INIT, TAG, "cmap_cache: " + cmap_cache.toDebugString());
      error = manager.RegisterCache(cmap_cache);
      if (error != FTError.ErrorTag.ERR_OK) {
        Log.e(TAG, "could not initialize charmap cache");
        return;
      }

      FTBitmapRec bitmap = new FTBitmapRec();
      FTStrokerRec stroker = new FTStrokerRec(library);

      FTReference<FTSizeRec> size_ref = new FTReference<>();
      FTSizeRec size = null;
      FTCScalerRec scaler = new FTCScalerRec();
      scaler.setFace_id(font_args);
      scaler.setWidth(768);
      scaler.setHeight(768);
      scaler.setX_res(72);
      scaler.setX_res(72);
      error = manager.LookupSize(scaler, size_ref);
      if (error != FTError.ErrorTag.ERR_OK) {
        Log.e(TAG, "could not initialize size rec");
        return;
      }
      size = size_ref.Get();

//FIXME!!
      font_args.setCmap_index(face.getCharmap().FTGetCharmapIndex());
      int charcode = 'e';
      int gindex;
      gindex = ((FTCCMapCacheClass) cmap_cache).FTCCMapCacheLookup(font_args, font_args.getCmap_index(), charcode);
      System.out.println(String.format("gindex for charcode: %c 0x%02x %d", charcode, charcode, gindex));

      charcode = 'H';
      gindex = ((FTCCMapCacheClass) cmap_cache).FTCCMapCacheLookup(font_args, font_args.getCmap_index(), charcode);
      System.out.println(String.format("gindex for charcode: %c 0x%02x %d", charcode, charcode, gindex));

      charcode = 'e';
      gindex = ((FTCCMapCacheClass) cmap_cache).FTCCMapCacheLookup(font_args, font_args.getCmap_index(), charcode);
      System.out.println(String.format("gindex for charcode: %c 0x%02x %d", charcode, charcode, gindex));

Changes to aftraster/grayTRasterRec.java.

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
..
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
 *    gray_raster_reset
 *
 * =====================================================================
 */
  public FTError.ErrorTag gray_raster_reset(grayTWorkerRec worker, byte[] pool_base, int pool_size) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_reset");
    if (pool_base != null) {
      buffer = pool_base;
      buffer_size = pool_size;
//      band_size = (int)buffer_size / sizeof(TCell) * 8;
      band_size = buffer_size / 20;  // FIXME!!!
//      grayTWorkerRec worker =  new grayTWorkerRec();
      setWorker(worker);
................................................................................

  /* =====================================================================
   *    gray_raster_render
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_raster_render(FTRasterParamsRec params) {
    Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_render");
    FTOutlineRec outline = (FTOutlineRec)params.getSource();
    FTBitmapRec target_map = params.getTarget();

    if (buffer == null || buffer_size == 0) {
      return FTError.ErrorTag.RENDER_INVALID_ARGUMENT;
    }
    if (outline == null) {
................................................................................

  /* =====================================================================
   *    gray_raster_done
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_raster_done() {
    Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_done");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    // nothing to do
    return error;
  }










|







 







|







 







|







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
..
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
 *    gray_raster_reset
 *
 * =====================================================================
 */
  public FTError.ErrorTag gray_raster_reset(grayTWorkerRec worker, byte[] pool_base, int pool_size) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_reset");
    if (pool_base != null) {
      buffer = pool_base;
      buffer_size = pool_size;
//      band_size = (int)buffer_size / sizeof(TCell) * 8;
      band_size = buffer_size / 20;  // FIXME!!!
//      grayTWorkerRec worker =  new grayTWorkerRec();
      setWorker(worker);
................................................................................

  /* =====================================================================
   *    gray_raster_render
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_raster_render(FTRasterParamsRec params) {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_render");
    FTOutlineRec outline = (FTOutlineRec)params.getSource();
    FTBitmapRec target_map = params.getTarget();

    if (buffer == null || buffer_size == 0) {
      return FTError.ErrorTag.RENDER_INVALID_ARGUMENT;
    }
    if (outline == null) {
................................................................................

  /* =====================================================================
   *    gray_raster_done
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_raster_done() {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_done");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    // nothing to do
    return error;
  }



Changes to aftraster/grayTWorkerDecomposeRec.java.

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
...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
...
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
...
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
...
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
...
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
...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
...
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
...
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
...
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
...
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
...
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
...
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
...
573
574
575
576
577
578
579




580


581
582
583
584
585
586
587
588
589
590
591
...
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
...
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
...
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
...
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844


845







846











847













































  public String toString() {
    return mySelf()+"!";
  }

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

  /* =====================================================================
   *    gray_move_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_move_to(FTVectorRec to) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    int x;
    int y;
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_move_to: to.x: %d, to.y: %d", to.getX(), to.getY()));

      /* record current cell, if any */
    gray_record_cell();
      /* start to a new position */
    x = RasterUtil.UPSCALE(to.getX());
    y = RasterUtil.UPSCALE(to.getY());
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_move_to2: x(UPSCALE): %d, y(UPSCALE): %d", x, y));
    gray_start_cell(RasterUtil.TRUNC(x), RasterUtil.TRUNC(y));
    this.x = x;
    this.y = y;
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_move_to end: worker.x: %d(%d)(%f), worker.y: %d(%d)(%f)", this.x, this.x/4, this.x/256.0, this.y, this.y/4, this.y/256.0));
    return error;
  }

  /* =====================================================================
   *    gray_line_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_line_to(FTVectorRec to) {
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_line_to: to.x: %d, to.y: %d", to.getX(), to.getY()));
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_line_to call gray_render_line");
    gray_render_line(RasterUtil.UPSCALE(to.getX()), RasterUtil.UPSCALE(to.getY()));
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_line_to after call gray_render_line");
    return error;
  }

  /* =====================================================================
   *    gray_conic_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_conic_to(FTVectorRec control, FTVectorRec to) {
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_conic_to");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    gray_render_conic(control, to);
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_conic_to end");
    return error;
  }

  /* =====================================================================
   *    gray_cubic_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_cubic_to(FTVectorRec control1, FTVectorRec control2, FTVectorRec to) {
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_cubic_to");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    gray_render_cubic(control1, control2, to);
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_cubic_to end");
    return error;
  }

  /* =====================================================================
   *    gray_find_cell
   *
   * =====================================================================
   */
  private TCellRec gray_find_cell() {
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("  gray_find_cell: ras.ex: %d, ras.ey: %d, ras.count_ex: %d, ras.num_cells: %d", this.ex, this.ey, count_ex, num_cells));
    int pcellIdx;
    int cellIdx;
    TCellRec cell = null;
    TCellRec pcell = null;
    int x = ex;
    boolean useYcells = true;
    boolean isYcell = true;
................................................................................
      while( cell != null) {
        cell = cell.getNext();
        if (cell != null) {
          str.append(String.format("\n\t\tidx: %2d, x: %2d, a: %06x, c: %06x",
              cell.getSelf_idx(), cell.getX(), cell.getArea() & 0xFFFFFF, cell.getCover() & 0xFFFFFF));
        }
      }
      Debug(0, DebugTag.DBG_DECOMPOSE, TAG, str.toString());
    }

    pcellIdx = ey;
    cellIdx = -1;
    for (;;) {
      if (cellIdx == -1) {
        cell = ycells[pcellIdx];
................................................................................
    }
    if (num_cells >= max_cells) {
//FIXME!!        ft_longjmp( worker.jump_buffer, 1 );
      Log.e(TAG, "out of worker.cells: " + num_cells + "!" + max_cells);
    }
    cell = cells[num_cells];
    num_cells = num_cells + 1;
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("new cell: x: %d, worker.ex: %d, worker.ey: %d", x, ex, ey));
    cell.setSelf_idx(num_cells - 1);
    cell.setX(x);
    cell.setArea(0);
    cell.setCover(0);
    if (useYcells) {
      cell.setNext(ycells[pcellIdx]);
//System.out.println(String.format("pcellIdx: %d",  pcellIdx));
      ycells[pcellIdx] = cell;
    } else {
      if (isYcell) {
        cell.setNext(ycells[pcellIdx].getNext());
        Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("cellIdx. %d pcellIdx: %d",  cellIdx, pcellIdx));
        ycells[pcellIdx].setNext(cell);
        Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("isYcell: cell idx: %d cell next idx: %d ", cell.getSelf_idx(), cell.getNext() == null ? -1 : cell.getNext().getSelf_idx()));
      } else {
        cell.setNext(cells[cellIdx].getNext());
        Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("cellIdx. %d pcellIdx: %d",  cellIdx, pcellIdx));
        cells[cellIdx].setNext(cell);
      }
    }
    return cell;
  }

  /* =====================================================================
   *    gray_start_cell
   *
   * =====================================================================
   */
  private void gray_start_cell(int ex, int ey) {
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_start_cell: ex: %d, ey: %d, worker.max_ex: %d, worker.min_ex: %d", ex, ey, max_ex, min_ex));

    if (ex > max_ex) {
      ex = max_ex;
    }
    if (ex < min_ex) {
      ex = min_ex - 1;
    }
    area = 0;
    cover = 0;
    this.ex = ex - min_ex;
    this.ey = ey - min_ey;
    last_ey = RasterUtil.SUBPIXELS(ey);
    invalid = false;
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_start_cell2: worker.x: %d, worker.y: %d, worker.ex: %d, worker.ex: %d, worker.getlast_ey: %d", this.x, this.y, this.ex, this.ey, last_ey));
    gray_set_cell(ex, ey);
  }


  /* =====================================================================
   *    gray_record_cell
   *
   * =====================================================================
   */
  public void gray_record_cell() {
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_record_cell: ras.invalid: %b, ras.area: %x, ras.cover: %x\n", invalid, area, cover));

    if (!invalid && (area | cover) != 0) {
      TCellRec cell = gray_find_cell();

      cell.setArea(cell.getArea() + area);
      cell.setCover(cell.getCover() + cover);
      Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_record_cell2: cell.area: %x, cell.cover: %x worker.area: %x, worker.cover: %x\n", cell.getArea(), cell.getCover(), area, cover));
    }
  }

  /* =====================================================================
   *    gray_set_cell
   *
   * Move the cell pointer to a new position.  We set the `invalid'
................................................................................
   *
   * Note that if a cell is to the left of the clipping region, it is
   * actually set to the (min_ex-1) horizontal position.
   *
   * =====================================================================
   */
  private void gray_set_cell(int ex, int ey) {
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_set_cell: ex: %d, ey: %d, invalid: %b, worker.ex: %d, worker.ey: %d", ex, ey, invalid, this.ex, this.ey));
      /* All cells that are on the left of the clipping region go to the */
      /* min_ex - 1 horizontal position.                                 */
    ey -= min_ey;
    if (ex > max_ex) {
      ex = max_ex;
    }
    ex -= min_ex;
................................................................................
      ex = -1;
    }
      /* are we moving to a different cell ? */
    if (ex != this.ex || ey != this.ey) {
        /* record the current one if it is valid */
      if (!invalid) {
        gray_record_cell();
        Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_set_cell after call gray_record_cell"));
      }
      area = 0;
      cover = 0;
    }
    this.ex = ex;
    this.ey = ey;
    invalid = (ey >= count_ey || ex >= count_ex);
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_set_cell2: invalid: %b, worker.area: %d, worker.cover: %d, worker.ex: %d, worker.ey: %d, worker.x: %d, worker.y: %d", invalid, area, cover, this.ex, this.ey, this.x, this.y));
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_set_cell end"));
  }

  /* =====================================================================
   *    gray_render_scanline
   *
   * =====================================================================
   */
  private void gray_render_scanline(int ey, int x1, int y1, int x2, int y2) {
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_scanline0 x1: %d(%d)(%.2f) y1: %d(%d)(%.2f), x2: %d(%d)(%.2f), y2: %d(%d)(%.2f)", x1, x1/4, x1/256.0, y1, y1/4, y1/256.0, x2, x2/4, x2/256.0, y2, y2/4, y2/256.0));
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_scanline1 worker.area: 0x%08x, worker.cover: 0x%08x", area, cover));
    int ex1;
    int ex2;
    int fx1;
    int fx2;
    int delta;
    int mod;
    int p;
................................................................................
    dx = x2 - x1;
    ex1 = RasterUtil.TRUNC(x1);
    ex2 = RasterUtil.TRUNC(x2);
    fx1 = x1 - RasterUtil.SUBPIXELS(ex1);
    fx2 = x2 - RasterUtil.SUBPIXELS(ex2);
      /* trivial case.  Happens often */
    if (y1 == y2) {
      Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("call gray_set_cell ex2: %d, ey: %d", ex2, ey));
      gray_set_cell(ex2, ey);
      return;
    }
      /* everything is located in a single cell.  That is easy! */
      /*                                                        */
    if (ex1 == ex2) {
      delta = y2 - y1;
      area = area + ((fx1 + fx2) * delta);
      cover = cover + delta;
      Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_scanline return2: worker.area: 0x%08x, worker.cover: 0x%08x", area, cover));
      Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_scanline return2 ex1 == ex2: %d", ex2));
      return;
    }
      /* ok, we'll have to render a run of adjacent cells on the same */
      /* scanline...                                                  */
      /*                                                              */
    p = (RasterUtil.ONE_PIXEL() - fx1) * (y2 - y1);
    first = RasterUtil.ONE_PIXEL();
................................................................................
      p = fx1 * (y2 - y1);
      first = 0;
      incr = -1;
      dx = -dx;
    }
    delta = (p / dx);
    mod   = (p % dx);
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("delta: 0x%08x, p: 0x%08x, dx: 0x%08x, mod: 0x%08x", delta, p, dx, mod));
    if (mod < 0) {
      delta--;
      mod += dx;
    }
    area = area + ((fx1 + first) * delta);
    cover = cover + delta;
    ex1 += incr;
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("call gray_set_cell2 ex1: %d, ey: %d", ex1, ey));
    gray_set_cell(ex1, ey);
    y1  += delta;
    if (ex1 != ex2) {
      int lift;
      int rem;

      p = RasterUtil.ONE_PIXEL() * (y2 - y1 + delta);
................................................................................
      rem  = (p % dx);
      if (rem < 0) {
        lift--;
        rem += dx;
      }
      mod -= (int)dx;
      while (ex1 != ex2) {
        Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("ex1: %d ex2: %d incr: %d", ex1, ex2, incr));
        delta = lift;
        mod  += rem;
        if (mod >= 0) {
          mod -= dx;
          delta++;
        }
        area = area + (RasterUtil.ONE_PIXEL() * delta);
        cover = cover + delta;
        Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_scanline3: worker.area: 0x%08x, worker.cover: 0x%08x", area, cover));
        y1 += delta;
        ex1 += incr;
        gray_set_cell(ex1, ey);
      }
    }
    delta = y2 - y1;
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("return end delta: %d", delta));
    area = area  + ((fx2 + RasterUtil.ONE_PIXEL() - first) * delta);
    cover = cover + delta;
  }

  /* =====================================================================
   *    gray_render_line
   *
................................................................................
    int p;
    int first;
    int delta;
    int rem;
    int lift;
    int incr;

    Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_line: to_x: %d, to_y: %d", to_x, to_y));
    ey1 = RasterUtil.TRUNC(last_ey);
    ey2 = RasterUtil.TRUNC(to_y);     /* if (ey2 >= ras.max_ey) ey2 = ras.max_ey-1; */
    fy1 = (this.y - last_ey);
    fy2 = (to_y - RasterUtil.SUBPIXELS(ey2));
    dx = to_x - this.x;
    dy = to_y - this.y;
      /* XXX: we should do something about the trivial case where dx == 0, */
................................................................................
        min = ey2;
        max = ey1;
      }
      if (min >= max_ey || max < min_ey) {
        this.x = to_x;
        this.y = to_y;
        last_ey = RasterUtil.SUBPIXELS(ey2);
        Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line return 1");
        return;
      }
    }
      /* everything is on a single scanline */
    if (ey1 == ey2) {
      gray_render_scanline(ey1, this.x, fy1, to_x, fy2);
      this.x = to_x;
      this.y = to_y;
      last_ey = RasterUtil.SUBPIXELS(ey2);
      Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line return 2");
      return;
    }
      /* vertical line - avoid calling gray_render_scanline */
    incr = 1;
    if (dx == 0) {
      int ex = RasterUtil.TRUNC(this.x);
      int two_fx = ((this.x - RasterUtil.SUBPIXELS(ex)) << 1);
................................................................................
      gray_set_cell(ex, ey1);
      delta = (first + first - RasterUtil.ONE_PIXEL());
      area = two_fx * delta;
      while (ey1 != ey2) {
        this.area = this.area + area;
        this.cover = this.cover + delta;
        ey1 += incr;
        Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line call gray_set_cell while");
        gray_set_cell(ex, ey1);
      }
      delta = (fy2 - RasterUtil.ONE_PIXEL() + first);
      this.area = this.area + two_fx * delta;
      this.cover = this.cover + delta;
      this.x = to_x;
      this.y = to_y;
      last_ey = RasterUtil.SUBPIXELS(ey2);
      Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line return 3");
      return;
    }
      /* ok, we have to render several scanlines */
    p = (RasterUtil.ONE_PIXEL() - fy1) * dx;
    first = RasterUtil.ONE_PIXEL();
    incr = 1;
    if (dy < 0) {
................................................................................
    delta = p / dy;
    mod = p % dy;
    if (mod < 0) {
      delta--;
      mod += dy;
    }
    x = this.x + delta;
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line call gray_render_scanline 1");
    gray_render_scanline(ey1, this.x, fy1, x, first);
    ey1 += incr;
    gray_set_cell(RasterUtil.TRUNC(x), ey1);
    if (ey1 != ey2) {
      p = RasterUtil.ONE_PIXEL() * dx;
      lift = (p / dy);
      rem = (p % dy);
................................................................................
        delta = lift;
        mod += rem;
        if (mod >= 0) {
          mod -= dy;
          delta++;
        }
        x2 = x + delta;
        Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line call gray_render_scanline 2");
        gray_render_scanline(ey1, x, RasterUtil.ONE_PIXEL() - first, x2, first);
        x = x2;
        ey1 += incr;
        gray_set_cell(RasterUtil.TRUNC(x), ey1);
      }
    }
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line call gray_render_scanline 3");
    gray_render_scanline(ey1, x, RasterUtil.ONE_PIXEL() - first, to_x, fy2);
    this.x = to_x;
    this.y = to_y;
    last_ey = RasterUtil.SUBPIXELS(ey2);
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line end");
  }

  /* =====================================================================
   *    gray_split_conic
   *
   * =====================================================================
   */
  private void gray_split_conic(FTVectorRec[] base, int arcIdx) {
    Debug(0, DebugTag.DBG_RENDER, TAG, "gray_split_conic");
    int a;
    int b;

    base[arcIdx + 4].setX(base[arcIdx + 2].getX());
    b = base[arcIdx + 1].getX();
    base[arcIdx + 3].setX((base[arcIdx + 2].getX() + b) / 2);
    a = base[arcIdx + 3].getX();
................................................................................
    int top;
    int level;
    int[] levels;
    FTVectorRec[] arc;
    int arcIdx = 0;
    boolean doDraw = false;





    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_conic");


    levels = lev_stack;
    arc = bez_stack;
    arc[arcIdx + 0].setX(RasterUtil.UPSCALE(to.getX()));
    arc[arcIdx + 0].setY(RasterUtil.UPSCALE(to.getY()));
    arc[arcIdx + 1].setX(RasterUtil.UPSCALE(control.getX()));
    arc[arcIdx + 1].setY(RasterUtil.UPSCALE(control.getY()));
    arc[arcIdx + 2].setX(this.x);
    arc[arcIdx + 2].setY(this.y);
    top = 0;
    dx = FTCalc.FT_ABS(arc[arcIdx + 2].getX() + arc[arcIdx].getX() - 2 * arc[arcIdx + 1].getX());
    dy = FTCalc.FT_ABS(arc[arcIdx + 2].getY() + arc[arcIdx].getY() - 2 * arc[arcIdx + 1].getY());
................................................................................
      if (!doDraw) {
        level = levels[top];
        if (level > 0) {
          gray_split_conic(arc, arcIdx);
          arcIdx += 2;
          top++;
          levels[top] = levels[top - 1] = level - 1;
          Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_conic !doDraw continue level: %d", level));
          continue;
        }
      }
      doDraw = false;
      Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_conic call gray_render_line top: %d", top));

      gray_render_line(arc[arcIdx + 0].getX(), arc[arcIdx + 0].getY());
      Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_conic call after gray_render_line top: %d", top));
      top--;
      arcIdx -= 2;
    } while ( top >= 0 );
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_conic end top: %d", top));
  }

  /* =====================================================================
   *    gray_split_cubic
   *
   * =====================================================================
   */
  private void gray_split_cubic(FTVectorRec[] base, int arcIdx) {
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_split_cubic");
    int a;
    int b;
    int c;
    int d;

    base[arcIdx + 6].setX(base[arcIdx + 3].getX());
    c = base[arcIdx + 1].getX();
................................................................................
    FTVectorRec[] arc;
    int arcIdx = 0;
    int min;
    int max;
    int y;
    boolean noSplit = false;

    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_cubic");
    arc = bez_stack;
    arc[arcIdx + 0].setX(RasterUtil.UPSCALE(to.getX()));
    arc[arcIdx + 0].setY(RasterUtil.UPSCALE(to.getY()));
    arc[arcIdx + 1].setX(RasterUtil.UPSCALE(control2.getX()));
    arc[arcIdx + 1].setY(RasterUtil.UPSCALE(control2.getY()));
    arc[arcIdx + 2].setX(RasterUtil.UPSCALE(control1.getX()));
    arc[arcIdx + 2].setY(RasterUtil.UPSCALE(control1.getY()));
................................................................................
    if (y < min) {
      min = y;
    }
    if (y > max) {
      max = y;
    }
    if (RasterUtil.TRUNC(min) >= max_ey || RasterUtil.TRUNC(max) < min_ey) {
      Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_cubic call gray_render_line"));
      gray_render_line(arc[arcIdx].getX(), arc[arcIdx].getY());
      if (arc == bez_stack) {
        return;
      }
      arcIdx -= 3;
    }
    for (;;) {
................................................................................
        noSplit = true;
      }
      if (! noSplit) {
        gray_split_cubic(arc, arcIdx);
        arcIdx += 3;
        continue;
      }
      Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_cubic 2 call gray_render_line"));
      gray_render_line(arc[arcIdx + 0].getX(), arc[arcIdx + 0].getY());
      if (arc == bez_stack) {
        return;
      }
      arcIdx -= 3;
      bez_stack = arc;
    }
  }























}




















































|



<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<





|







 







|







 







|











|

|


|












|













|










|






|







 







|







 







|







|
|








|
|







 







|









|
|







 







|







|







 







|








|






|







 







|







 







|









|







 







|








|







 







|







 







|






|




|








|







 







>
>
>
>
|
>
>


|
|







 







|




|


|



|








|







 







|







 







|







 







|









>
>
|
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
39
40
41
42
43
44
45
46
47
48
49



































































50
51
52
53
54
55
56
57
58
59
60
61
62
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
...
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
...
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
...
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
...
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
...
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
...
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
...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
...
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
...
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
...
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
...
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
...
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
...
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
...
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
...
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
...
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
  public String toString() {
    return mySelf()+"!";
  }

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

  /* =====================================================================



































































   *    gray_find_cell
   *
   * =====================================================================
   */
  private TCellRec gray_find_cell() {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("  gray_find_cell: ras.ex: %d, ras.ey: %d, ras.count_ex: %d, ras.num_cells: %d", this.ex, this.ey, count_ex, num_cells));
    int pcellIdx;
    int cellIdx;
    TCellRec cell = null;
    TCellRec pcell = null;
    int x = ex;
    boolean useYcells = true;
    boolean isYcell = true;
................................................................................
      while( cell != null) {
        cell = cell.getNext();
        if (cell != null) {
          str.append(String.format("\n\t\tidx: %2d, x: %2d, a: %06x, c: %06x",
              cell.getSelf_idx(), cell.getX(), cell.getArea() & 0xFFFFFF, cell.getCover() & 0xFFFFFF));
        }
      }
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, str.toString());
    }

    pcellIdx = ey;
    cellIdx = -1;
    for (;;) {
      if (cellIdx == -1) {
        cell = ycells[pcellIdx];
................................................................................
    }
    if (num_cells >= max_cells) {
//FIXME!!        ft_longjmp( worker.jump_buffer, 1 );
      Log.e(TAG, "out of worker.cells: " + num_cells + "!" + max_cells);
    }
    cell = cells[num_cells];
    num_cells = num_cells + 1;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("new cell: x: %d, worker.ex: %d, worker.ey: %d", x, ex, ey));
    cell.setSelf_idx(num_cells - 1);
    cell.setX(x);
    cell.setArea(0);
    cell.setCover(0);
    if (useYcells) {
      cell.setNext(ycells[pcellIdx]);
//System.out.println(String.format("pcellIdx: %d",  pcellIdx));
      ycells[pcellIdx] = cell;
    } else {
      if (isYcell) {
        cell.setNext(ycells[pcellIdx].getNext());
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("cellIdx. %d pcellIdx: %d",  cellIdx, pcellIdx));
        ycells[pcellIdx].setNext(cell);
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("isYcell: cell idx: %d cell next idx: %d ", cell.getSelf_idx(), cell.getNext() == null ? -1 : cell.getNext().getSelf_idx()));
      } else {
        cell.setNext(cells[cellIdx].getNext());
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("cellIdx. %d pcellIdx: %d",  cellIdx, pcellIdx));
        cells[cellIdx].setNext(cell);
      }
    }
    return cell;
  }

  /* =====================================================================
   *    gray_start_cell
   *
   * =====================================================================
   */
  private void gray_start_cell(int ex, int ey) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_start_cell: ex: %d, ey: %d, worker.max_ex: %d, worker.min_ex: %d", ex, ey, max_ex, min_ex));

    if (ex > max_ex) {
      ex = max_ex;
    }
    if (ex < min_ex) {
      ex = min_ex - 1;
    }
    area = 0;
    cover = 0;
    this.ex = ex - min_ex;
    this.ey = ey - min_ey;
    last_ey = RasterUtil.SUBPIXELS(ey);
    invalid = false;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_start_cell2: worker.x: %d, worker.y: %d, worker.ex: %d, worker.ex: %d, worker.getlast_ey: %d", this.x, this.y, this.ex, this.ey, last_ey));
    gray_set_cell(ex, ey);
  }


  /* =====================================================================
   *    gray_record_cell
   *
   * =====================================================================
   */
  public void gray_record_cell() {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_record_cell: ras.invalid: %b, ras.area: %x, ras.cover: %x\n", invalid, area, cover));

    if (!invalid && (area | cover) != 0) {
      TCellRec cell = gray_find_cell();

      cell.setArea(cell.getArea() + area);
      cell.setCover(cell.getCover() + cover);
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_record_cell2: cell.area: %x, cell.cover: %x worker.area: %x, worker.cover: %x\n", cell.getArea(), cell.getCover(), area, cover));
    }
  }

  /* =====================================================================
   *    gray_set_cell
   *
   * Move the cell pointer to a new position.  We set the `invalid'
................................................................................
   *
   * Note that if a cell is to the left of the clipping region, it is
   * actually set to the (min_ex-1) horizontal position.
   *
   * =====================================================================
   */
  private void gray_set_cell(int ex, int ey) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_set_cell: ex: %d, ey: %d, invalid: %b, worker.ex: %d, worker.ey: %d", ex, ey, invalid, this.ex, this.ey));
      /* All cells that are on the left of the clipping region go to the */
      /* min_ex - 1 horizontal position.                                 */
    ey -= min_ey;
    if (ex > max_ex) {
      ex = max_ex;
    }
    ex -= min_ex;
................................................................................
      ex = -1;
    }
      /* are we moving to a different cell ? */
    if (ex != this.ex || ey != this.ey) {
        /* record the current one if it is valid */
      if (!invalid) {
        gray_record_cell();
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_set_cell after call gray_record_cell"));
      }
      area = 0;
      cover = 0;
    }
    this.ex = ex;
    this.ey = ey;
    invalid = (ey >= count_ey || ex >= count_ex);
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_set_cell2: invalid: %b, worker.area: %d, worker.cover: %d, worker.ex: %d, worker.ey: %d, worker.x: %d, worker.y: %d", invalid, area, cover, this.ex, this.ey, this.x, this.y));
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_set_cell end"));
  }

  /* =====================================================================
   *    gray_render_scanline
   *
   * =====================================================================
   */
  private void gray_render_scanline(int ey, int x1, int y1, int x2, int y2) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_scanline0 x1: %d(%d)(%.2f) y1: %d(%d)(%.2f), x2: %d(%d)(%.2f), y2: %d(%d)(%.2f), ey: %d", x1, x1/4, x1/256.0, y1, y1/4, y1/256.0, x2, x2/4, x2/256.0, y2, y2/4, y2/256.0, ey));
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_scanline1 worker.area: 0x%08x, worker.cover: 0x%08x", area, cover));
    int ex1;
    int ex2;
    int fx1;
    int fx2;
    int delta;
    int mod;
    int p;
................................................................................
    dx = x2 - x1;
    ex1 = RasterUtil.TRUNC(x1);
    ex2 = RasterUtil.TRUNC(x2);
    fx1 = x1 - RasterUtil.SUBPIXELS(ex1);
    fx2 = x2 - RasterUtil.SUBPIXELS(ex2);
      /* trivial case.  Happens often */
    if (y1 == y2) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("call gray_set_cell ex2: %d, ey: %d", ex2, ey));
      gray_set_cell(ex2, ey);
      return;
    }
      /* everything is located in a single cell.  That is easy! */
      /*                                                        */
    if (ex1 == ex2) {
      delta = y2 - y1;
      area = area + ((fx1 + fx2) * delta);
      cover = cover + delta;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_scanline return2: worker.area: 0x%08x, worker.cover: 0x%08x", area, cover));
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_scanline return2 ex1 == ex2: %d", ex2));
      return;
    }
      /* ok, we'll have to render a run of adjacent cells on the same */
      /* scanline...                                                  */
      /*                                                              */
    p = (RasterUtil.ONE_PIXEL() - fx1) * (y2 - y1);
    first = RasterUtil.ONE_PIXEL();
................................................................................
      p = fx1 * (y2 - y1);
      first = 0;
      incr = -1;
      dx = -dx;
    }
    delta = (p / dx);
    mod   = (p % dx);
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("delta: 0x%08x, p: 0x%08x, dx: 0x%08x, mod: 0x%08x", delta, p, dx, mod));
    if (mod < 0) {
      delta--;
      mod += dx;
    }
    area = area + ((fx1 + first) * delta);
    cover = cover + delta;
    ex1 += incr;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("call gray_set_cell2 ex1: %d, ey: %d", ex1, ey));
    gray_set_cell(ex1, ey);
    y1  += delta;
    if (ex1 != ex2) {
      int lift;
      int rem;

      p = RasterUtil.ONE_PIXEL() * (y2 - y1 + delta);
................................................................................
      rem  = (p % dx);
      if (rem < 0) {
        lift--;
        rem += dx;
      }
      mod -= (int)dx;
      while (ex1 != ex2) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("ex1: %d ex2: %d incr: %d", ex1, ex2, incr));
        delta = lift;
        mod  += rem;
        if (mod >= 0) {
          mod -= dx;
          delta++;
        }
        area = area + (RasterUtil.ONE_PIXEL() * delta);
        cover = cover + delta;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_scanline3: worker.area: 0x%08x, worker.cover: 0x%08x", area, cover));
        y1 += delta;
        ex1 += incr;
        gray_set_cell(ex1, ey);
      }
    }
    delta = y2 - y1;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("return end delta: %d", delta));
    area = area  + ((fx2 + RasterUtil.ONE_PIXEL() - first) * delta);
    cover = cover + delta;
  }

  /* =====================================================================
   *    gray_render_line
   *
................................................................................
    int p;
    int first;
    int delta;
    int rem;
    int lift;
    int incr;

Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_line: to_x: %d, to_y: %d", to_x, to_y));
    ey1 = RasterUtil.TRUNC(last_ey);
    ey2 = RasterUtil.TRUNC(to_y);     /* if (ey2 >= ras.max_ey) ey2 = ras.max_ey-1; */
    fy1 = (this.y - last_ey);
    fy2 = (to_y - RasterUtil.SUBPIXELS(ey2));
    dx = to_x - this.x;
    dy = to_y - this.y;
      /* XXX: we should do something about the trivial case where dx == 0, */
................................................................................
        min = ey2;
        max = ey1;
      }
      if (min >= max_ey || max < min_ey) {
        this.x = to_x;
        this.y = to_y;
        last_ey = RasterUtil.SUBPIXELS(ey2);
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line return 1");
        return;
      }
    }
      /* everything is on a single scanline */
    if (ey1 == ey2) {
      gray_render_scanline(ey1, this.x, fy1, to_x, fy2);
      this.x = to_x;
      this.y = to_y;
      last_ey = RasterUtil.SUBPIXELS(ey2);
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line return 2");
      return;
    }
      /* vertical line - avoid calling gray_render_scanline */
    incr = 1;
    if (dx == 0) {
      int ex = RasterUtil.TRUNC(this.x);
      int two_fx = ((this.x - RasterUtil.SUBPIXELS(ex)) << 1);
................................................................................
      gray_set_cell(ex, ey1);
      delta = (first + first - RasterUtil.ONE_PIXEL());
      area = two_fx * delta;
      while (ey1 != ey2) {
        this.area = this.area + area;
        this.cover = this.cover + delta;
        ey1 += incr;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line call gray_set_cell while");
        gray_set_cell(ex, ey1);
      }
      delta = (fy2 - RasterUtil.ONE_PIXEL() + first);
      this.area = this.area + two_fx * delta;
      this.cover = this.cover + delta;
      this.x = to_x;
      this.y = to_y;
      last_ey = RasterUtil.SUBPIXELS(ey2);
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line return 3");
      return;
    }
      /* ok, we have to render several scanlines */
    p = (RasterUtil.ONE_PIXEL() - fy1) * dx;
    first = RasterUtil.ONE_PIXEL();
    incr = 1;
    if (dy < 0) {
................................................................................
    delta = p / dy;
    mod = p % dy;
    if (mod < 0) {
      delta--;
      mod += dy;
    }
    x = this.x + delta;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line call gray_render_scanline 1");
    gray_render_scanline(ey1, this.x, fy1, x, first);
    ey1 += incr;
    gray_set_cell(RasterUtil.TRUNC(x), ey1);
    if (ey1 != ey2) {
      p = RasterUtil.ONE_PIXEL() * dx;
      lift = (p / dy);
      rem = (p % dy);
................................................................................
        delta = lift;
        mod += rem;
        if (mod >= 0) {
          mod -= dy;
          delta++;
        }
        x2 = x + delta;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line call gray_render_scanline 2");
        gray_render_scanline(ey1, x, RasterUtil.ONE_PIXEL() - first, x2, first);
        x = x2;
        ey1 += incr;
        gray_set_cell(RasterUtil.TRUNC(x), ey1);
      }
    }
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line call gray_render_scanline 3");
    gray_render_scanline(ey1, x, RasterUtil.ONE_PIXEL() - first, to_x, fy2);
    this.x = to_x;
    this.y = to_y;
    last_ey = RasterUtil.SUBPIXELS(ey2);
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_line end");
  }

  /* =====================================================================
   *    gray_split_conic
   *
   * =====================================================================
   */
  private void gray_split_conic(FTVectorRec[] base, int arcIdx) {
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_split_conic arcIdx: %d", arcIdx));
    int a;
    int b;

    base[arcIdx + 4].setX(base[arcIdx + 2].getX());
    b = base[arcIdx + 1].getX();
    base[arcIdx + 3].setX((base[arcIdx + 2].getX() + b) / 2);
    a = base[arcIdx + 3].getX();
................................................................................
    int top;
    int level;
    int[] levels;
    FTVectorRec[] arc;
    int arcIdx = 0;
    boolean doDraw = false;

Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_conic 1a to_x: %d(%d)(%.2f) to_y: %d(%d)(%.2f)",
    RasterUtil.UPSCALE(to.getX()), to.getX(), to.getX()/64.0, RasterUtil.UPSCALE(to.getX()), to.getY(), to.getY()/64.0));
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_conic 1b control_x: %d(%d)(%.2f), control_y: %d(%d)(%.2f)",
    RasterUtil.UPSCALE(control.getX()), control.getX(), control.getX()/64.0, RasterUtil.UPSCALE(control.getY()), control.getY(), control.getY()/64.0));
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_conic 1c x: %d(%d)(%.2f), y: %d(%d)(%.2f)",
    this.x, RasterUtil.DOWNSCALE(this.x), this.x/256.0, this.y, RasterUtil.DOWNSCALE(this.y), this.y/256.0));

    levels = lev_stack;
    arc = bez_stack;
    arc[arcIdx].setX(RasterUtil.UPSCALE(to.getX()));
    arc[arcIdx].setY(RasterUtil.UPSCALE(to.getY()));
    arc[arcIdx + 1].setX(RasterUtil.UPSCALE(control.getX()));
    arc[arcIdx + 1].setY(RasterUtil.UPSCALE(control.getY()));
    arc[arcIdx + 2].setX(this.x);
    arc[arcIdx + 2].setY(this.y);
    top = 0;
    dx = FTCalc.FT_ABS(arc[arcIdx + 2].getX() + arc[arcIdx].getX() - 2 * arc[arcIdx + 1].getX());
    dy = FTCalc.FT_ABS(arc[arcIdx + 2].getY() + arc[arcIdx].getY() - 2 * arc[arcIdx + 1].getY());
................................................................................
      if (!doDraw) {
        level = levels[top];
        if (level > 0) {
          gray_split_conic(arc, arcIdx);
          arcIdx += 2;
          top++;
          levels[top] = levels[top - 1] = level - 1;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_conic !doDraw continue level: %d", level));
          continue;
        }
      }
      doDraw = false;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_conic call gray_render_line top: %d", top));

      gray_render_line(arc[arcIdx + 0].getX(), arc[arcIdx + 0].getY());
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_conic call after gray_render_line top: %d", top));
      top--;
      arcIdx -= 2;
    } while ( top >= 0 );
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_conic end top: %d", top));
  }

  /* =====================================================================
   *    gray_split_cubic
   *
   * =====================================================================
   */
  private void gray_split_cubic(FTVectorRec[] base, int arcIdx) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_split_cubic");
    int a;
    int b;
    int c;
    int d;

    base[arcIdx + 6].setX(base[arcIdx + 3].getX());
    c = base[arcIdx + 1].getX();
................................................................................
    FTVectorRec[] arc;
    int arcIdx = 0;
    int min;
    int max;
    int y;
    boolean noSplit = false;

Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_render_cubic");
    arc = bez_stack;
    arc[arcIdx + 0].setX(RasterUtil.UPSCALE(to.getX()));
    arc[arcIdx + 0].setY(RasterUtil.UPSCALE(to.getY()));
    arc[arcIdx + 1].setX(RasterUtil.UPSCALE(control2.getX()));
    arc[arcIdx + 1].setY(RasterUtil.UPSCALE(control2.getY()));
    arc[arcIdx + 2].setX(RasterUtil.UPSCALE(control1.getX()));
    arc[arcIdx + 2].setY(RasterUtil.UPSCALE(control1.getY()));
................................................................................
    if (y < min) {
      min = y;
    }
    if (y > max) {
      max = y;
    }
    if (RasterUtil.TRUNC(min) >= max_ey || RasterUtil.TRUNC(max) < min_ey) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_cubic call gray_render_line"));
      gray_render_line(arc[arcIdx].getX(), arc[arcIdx].getY());
      if (arc == bez_stack) {
        return;
      }
      arcIdx -= 3;
    }
    for (;;) {
................................................................................
        noSplit = true;
      }
      if (! noSplit) {
        gray_split_cubic(arc, arcIdx);
        arcIdx += 3;
        continue;
      }
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_render_cubic 2 call gray_render_line"));
      gray_render_line(arc[arcIdx + 0].getX(), arc[arcIdx + 0].getY());
      if (arc == bez_stack) {
        return;
      }
      arcIdx -= 3;
      bez_stack = arc;
    }
  }

  /* =====================================================================
   *    gray_move_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_move_to(FTVectorRec to) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    int x;
    int y;
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_move_to: to.x: %d, to.y: %d", to.getX(), to.getY()));

      /* record current cell, if any */
    gray_record_cell();
      /* start to a new position */
    x = RasterUtil.UPSCALE(to.getX());
    y = RasterUtil.UPSCALE(to.getY());
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_move_to2: x(UPSCALE): %d, y(UPSCALE): %d", x, y));
    gray_start_cell(RasterUtil.TRUNC(x), RasterUtil.TRUNC(y));
    this.x = x;
    this.y = y;
    Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_move_to end: worker.x: %d(%d)(%f), worker.y: %d(%d)(%f)", this.x, this.x/4, this.x/256.0, this.y, this.y/4, this.y/256.0));
    return error;
  }

  /* =====================================================================
   *    gray_line_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_line_to(FTVectorRec to) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, String.format("gray_line_to: to.x: %d, to.y: %d", to.getX(), to.getY()));
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_line_to call gray_render_line");
    gray_render_line(RasterUtil.UPSCALE(to.getX()), RasterUtil.UPSCALE(to.getY()));
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_line_to after call gray_render_line");
    return error;
  }

  /* =====================================================================
   *    gray_conic_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_conic_to(FTVectorRec control, FTVectorRec to) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_conic_to");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    gray_render_conic(control, to);
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_conic_to end");
    return error;
  }

  /* =====================================================================
   *    gray_cubic_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_cubic_to(FTVectorRec control1, FTVectorRec control2, FTVectorRec to) {
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_cubic_to");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    gray_render_cubic(control1, control2, to);
Debug(0, DebugTag.DBG_DECOMPOSE, TAG, "gray_cubic_to end");
    return error;
  }

}

Changes to aftraster/grayTWorkerRec.java.

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
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
...
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
  public String toString() {
    return mySelf() + "!";
  }

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

  /* =====================================================================
   *    gray_convert_glyph_inner
   *
   * =====================================================================
   */
................................................................................

  /* =====================================================================
   *    gray_convert_glyph
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_convert_glyph() {
    Debug(0, DebugTag.DBG_RENDER, TAG, "gray_convert_glyph");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    grayTBandRec[] bands = new grayTBandRec[40];
    int bandIdx = 0;
    int n;
    int i;
    int num_bands;
    int min;
................................................................................
    if (num_bands >= 39) {
      num_bands = 39;
    }
    band_shoot = 0;
    min = min_ey;
    max_y = max_ey;
    for (n = 0; n < num_bands; n++, min = max) {
      Debug(0, DebugTag.DBG_RENDER, TAG, "num_bands: n: "+n+" "+num_bands);
      max = min + band_size;
      if (n == num_bands - 1 || max > max_y) {
        max = max_y;
      }
      bands[0].setMin(min);
      bands[0].setMax(max);
      bandIdx = 0;
................................................................................
   * =====================================================================
   */
  public void gray_compute_cbox() {
    FTVectorRec vec;
    int vecIdx = 0;
    int limit = outline.getN_points();

    Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_compute_cbox"));
    if (outline.getN_points() <= 0) {
      min_ex = 0;
      max_ex = 0;
      min_ey = 0;
      max_ey = 0;
      return;
    }
    min_ex = outline.getPoints()[vecIdx].getX();
    max_ex = outline.getPoints()[vecIdx].getX();
    min_ey = outline.getPoints()[vecIdx].getY();
    max_ey = outline.getPoints()[vecIdx].getY();
    Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox01: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
    vecIdx++;
    for ( ; vecIdx < limit; vecIdx++) {
      vec = outline.getPoints()[vecIdx];
      int x = vec.getX();
      int y = vec.getY();

      if (x < min_ex) {
................................................................................
      }
      if (y < min_ey) {
        min_ey = y;
      }
      if (y > max_ey) {
        max_ey = y;
      }
      Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox11: %d %d", x, y));
      Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox12: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
    }
    Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox2: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
      /* truncate the bounding box to integer pixels */
    min_ex = min_ex >> 6;
    min_ey = min_ey >> 6;
    max_ex = (max_ex + 63) >> 6;
    max_ey = (max_ey + 63) >> 6;
    Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_compute_cbox end: min_ex: %d min_ey: %d max_ex: %d max_ey: %d", min_ex, min_ey, max_ex, max_ey));
  }

}







|







 







|







 







|







 







|











|







 







|
|

|





|



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
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
...
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
  public String toString() {
    return mySelf() + "!";
  }

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

  /* =====================================================================
   *    gray_convert_glyph_inner
   *
   * =====================================================================
   */
................................................................................

  /* =====================================================================
   *    gray_convert_glyph
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_convert_glyph() {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_convert_glyph");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    grayTBandRec[] bands = new grayTBandRec[40];
    int bandIdx = 0;
    int n;
    int i;
    int num_bands;
    int min;
................................................................................
    if (num_bands >= 39) {
      num_bands = 39;
    }
    band_shoot = 0;
    min = min_ey;
    max_y = max_ey;
    for (n = 0; n < num_bands; n++, min = max) {
Debug(0, DebugTag.DBG_RENDER, TAG, "num_bands: n: "+n+" "+num_bands);
      max = min + band_size;
      if (n == num_bands - 1 || max > max_y) {
        max = max_y;
      }
      bands[0].setMin(min);
      bands[0].setMax(max);
      bandIdx = 0;
................................................................................
   * =====================================================================
   */
  public void gray_compute_cbox() {
    FTVectorRec vec;
    int vecIdx = 0;
    int limit = outline.getN_points();

Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_compute_cbox"));
    if (outline.getN_points() <= 0) {
      min_ex = 0;
      max_ex = 0;
      min_ey = 0;
      max_ey = 0;
      return;
    }
    min_ex = outline.getPoints()[vecIdx].getX();
    max_ex = outline.getPoints()[vecIdx].getX();
    min_ey = outline.getPoints()[vecIdx].getY();
    max_ey = outline.getPoints()[vecIdx].getY();
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox01: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
    vecIdx++;
    for ( ; vecIdx < limit; vecIdx++) {
      vec = outline.getPoints()[vecIdx];
      int x = vec.getX();
      int y = vec.getY();

      if (x < min_ex) {
................................................................................
      }
      if (y < min_ey) {
        min_ey = y;
      }
      if (y > max_ey) {
        max_ey = y;
      }
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox11: %d %d", x, y));
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox12: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
    }
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox2: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
      /* truncate the bounding box to integer pixels */
    min_ex = min_ex >> 6;
    min_ey = min_ey >> 6;
    max_ex = (max_ex + 63) >> 6;
    max_ey = (max_ey + 63) >> 6;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_compute_cbox end: min_ex: %d min_ey: %d max_ex: %d max_ey: %d", min_ex, min_ey, max_ex, max_ey));
  }

}

Changes to aftraster/grayTWorkerSweepRec.java.

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  public String toString() {
    return mySelf()+"!";
  }

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

  /* =====================================================================
   *    gray_hline
   *
   * =====================================================================
   */
  public void gray_hline(int x, int y, int area, int acount) {
    Debug(0, DebugTag.DBG_SWEEP, TAG, String.format("gray_hline: x: %d, y: %d, area: 0x%08x, acount: %d", x, y, area, acount));
    int coverage = 0;
    int spanIdx = 0;

      /* compute the coverage line's coverage, depending on the    */
      /* outline fill rule                                         */
      /*                                                           */
      /* the coverage percentage is area/(PIXEL_BITS*PIXEL_BITS*2) */
................................................................................
    if (x >= 32767) {
      x = 32767;
    }
      /* FT_Span.y is an integer, so limit our coordinates appropriately */
    if (y >= 0xFFFF) {
      y = 0xFFFF;
    }
    Debug(0, DebugTag.DBG_SWEEP, TAG, String.format("x: %d, y: %d, coverage: %x", x, y, coverage));
    if (coverage != 0) {
      int count;
      FTSpanRec span = null;

        /* see whether we can add this span to the current list */
      count = num_gray_spans;
      spanIdx = count - 1;
................................................................................
      }
        /* add a gray span to the current list */
      gray_spans[spanIdx].setX(x);
      gray_spans[spanIdx].setLen(acount);
      gray_spans[spanIdx].setCoverage((byte)coverage);
      num_gray_spans = num_gray_spans + 1;
    }
    Debug(0, DebugTag.DBG_SWEEP, TAG, "gray_hline END 2");
  }

  /* =====================================================================
   *    gray_sweep
   *
   * =====================================================================
   */
  public void gray_sweep(FTBitmapRec target) {
    Debug(0, DebugTag.DBG_SWEEP, TAG, "gray_sweep");
    int  yindex;

    if (num_cells == 0) {
      return;
    }
    num_gray_spans = 0;
    FTTrace.Trace(7, TAG, "gray_sweep: start "+ycount);
................................................................................
      TCellRec cell = ycells[yindex];
      int cover = 0;
      int x = 0;

      for ( ; cell != null; cell = cell.getNext()) {
        int area;

        Debug(0, DebugTag.DBG_SWEEP, TAG, String.format("cell->next: %d", cell.getNext() == null ? -1 : cell.getNext().getSelf_idx()));
        Debug(0, DebugTag.DBG_SWEEP, TAG, String.format("gray_sweep 1: cell.x: %d x: %d,  yindex: %d, cover: %x", cell.getX(), x, yindex, cover));
        if (cell.getX() > x && cover != 0) {
          gray_hline(x, yindex, cover * (RasterUtil.ONE_PIXEL() * 2), cell.getX() - x );
        }
        cover += cell.getCover();
        area = cover * (RasterUtil.ONE_PIXEL() * 2) - cell.getArea();
        if (area != 0 && cell.getX() >= 0) {
          gray_hline(cell.getX(), yindex, area, 1 );







|








|







 







|







 







|








|







 







|
|







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  public String toString() {
    return mySelf()+"!";
  }

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

  /* =====================================================================
   *    gray_hline
   *
   * =====================================================================
   */
  public void gray_hline(int x, int y, int area, int acount) {
Debug(0, DebugTag.DBG_SWEEP, TAG, String.format("gray_hline: x: %d, y: %d, area: 0x%08x, acount: %d", x, y, area, acount));
    int coverage = 0;
    int spanIdx = 0;

      /* compute the coverage line's coverage, depending on the    */
      /* outline fill rule                                         */
      /*                                                           */
      /* the coverage percentage is area/(PIXEL_BITS*PIXEL_BITS*2) */
................................................................................
    if (x >= 32767) {
      x = 32767;
    }
      /* FT_Span.y is an integer, so limit our coordinates appropriately */
    if (y >= 0xFFFF) {
      y = 0xFFFF;
    }
Debug(0, DebugTag.DBG_SWEEP, TAG, String.format("x: %d, y: %d, coverage: %x", x, y, coverage));
    if (coverage != 0) {
      int count;
      FTSpanRec span = null;

        /* see whether we can add this span to the current list */
      count = num_gray_spans;
      spanIdx = count - 1;
................................................................................
      }
        /* add a gray span to the current list */
      gray_spans[spanIdx].setX(x);
      gray_spans[spanIdx].setLen(acount);
      gray_spans[spanIdx].setCoverage((byte)coverage);
      num_gray_spans = num_gray_spans + 1;
    }
Debug(0, DebugTag.DBG_SWEEP, TAG, "gray_hline END 2");
  }

  /* =====================================================================
   *    gray_sweep
   *
   * =====================================================================
   */
  public void gray_sweep(FTBitmapRec target) {
Debug(0, DebugTag.DBG_SWEEP, TAG, "gray_sweep");
    int  yindex;

    if (num_cells == 0) {
      return;
    }
    num_gray_spans = 0;
    FTTrace.Trace(7, TAG, "gray_sweep: start "+ycount);
................................................................................
      TCellRec cell = ycells[yindex];
      int cover = 0;
      int x = 0;

      for ( ; cell != null; cell = cell.getNext()) {
        int area;

Debug(0, DebugTag.DBG_SWEEP, TAG, String.format("cell->next: %d", cell.getNext() == null ? -1 : cell.getNext().getSelf_idx()));
Debug(0, DebugTag.DBG_SWEEP, TAG, String.format("gray_sweep 1: cell.x: %d x: %d,  yindex: %d, cover: %x", cell.getX(), x, yindex, cover));
        if (cell.getX() > x && cover != 0) {
          gray_hline(x, yindex, cover * (RasterUtil.ONE_PIXEL() * 2), cell.getX() - x );
        }
        cover += cell.getCover();
        area = cover * (RasterUtil.ONE_PIXEL() * 2) - cell.getArea();
        if (area != 0 && cell.getX() >= 0) {
          gray_hline(cell.getX(), yindex, area, 1 );

Changes to afttruetype/TTCMap4Class.java.

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
...
301
302
303
304
305
306
307

308
309
310
311
312
313
314
...
494
495
496
497
498
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
...
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
...
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
    reserved_pad = stream.readShort();
    start_code = new byte[num_segs * 2];
    stream.readByteArray(start_code, (num_segs * 2));
    id_delta = new byte[num_segs * 2];
    stream.readByteArray(id_delta, (num_segs * 2));
    id_range_offset = new byte[num_segs * 2];
    stream.readByteArray(id_range_offset, (num_segs * 2));
//    glyph_index_array = new byte[num_segs * 2]; ???
//    stream.readByteArray(glyph_index_array, (num_segs * 2));
    Debug(0, DebugTag.DBG_CMAP, TAG, "Cmap4Class: "+toDebugString());
    return error;
  }

  /* =====================================================================
   *    tt_cmap4_validate
   *
................................................................................
   * =====================================================================
   */
  private FTError.ErrorTag tt_cmap4_init(TTCMap4Rec cmap) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    cmap.setCur_charcode(0xFFFFFFFF);
    cmap.setCur_gindex(0);

    return error;
  }

  /* =====================================================================
   *    tt_cmap4_set_range
   *
   * =====================================================================
................................................................................
    int delta;
    int max;
    int min;
    int mid;
    int num_segs;
    int charcode = charcode_ref.Get();
    int gindex   = 0;
    int table_idx;


    table_idx = 0;
    num_segs2 = (int)FTCalc.FT_PAD_FLOOR(FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx), 2);


    if (num_segs2 == 0) {
      return 0;
    }
    num_segs = num_segs2 >> 1;
      /* make compiler happy */
    mid = num_segs;
    end = 0xFFFF;
    if (next) {
      charcode++;
    }
    min = 0;
    max = num_segs;
      /* binary search */
    while (min < max) {
      mid = (min + max) >> 1;
      table_idx = 8 + mid * 2;
      end = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
      table_idx += 2 + num_segs2;
      start = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
      if (charcode < start) {
        max = mid;
      } else {
        if (charcode > end) {
          min = mid + 1;
        } else {
          table_idx += num_segs2;
          delta = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
          table_idx += num_segs2;
          offset = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
            /* some fonts have an incorrect last segment; */
            /* we have to catch it                        */
          if (mid >= num_segs - 1 && start == 0xFFFF && end == 0xFFFF) {
/*
            TTFaceRec face  = (TTFaceRec)cmap.face;
            int limit = (int)face.cmap_size;

................................................................................
            max = mid;
            if (offset == 0xFFFF) {
              mid = max + 1;
            }
              /* search in segments before the current segment */
            for (i = max ; i > 0; i--) {
              int prev_end;
              int  oldIdx;

              oldIdx = table_idx;
              table_idx = 8 + ( i - 1 ) * 2;
              prev_end = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
              if (charcode > prev_end) {
                table_idx = oldIdx;
                break;
              }
              end = prev_end;
              table_idx += 2 + num_segs2;
              start = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
              table_idx += num_segs2;
              delta = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
              table_idx += num_segs2;
              offset = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
              if (offset != 0xFFFF) {
                mid = i - 1;
              }
            }
              /* no luck */
            if (mid == max + 1) {
              if (i != max) {
                table_idx = 8 + max * 2;
                end = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
                table_idx += 2 + num_segs2;
                start = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
                table_idx += num_segs2;
                delta = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
                table_idx += num_segs2;
                offset = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
              }
              mid = max;
                /* search in segments after the current segment */
              for (i = max + 1; i < num_segs; i++) {
                int next_end;
                int next_start;

                table_idx = 8 + i * 2;
                next_end = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
                table_idx += 2 + num_segs2;
                next_start = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
                if (charcode < next_start) {
                  break;
                }
                end = next_end;
                start = next_start;
                table_idx += num_segs2;
                delta  = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
                table_idx += num_segs2;
                offset = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
                if (offset != 0xFFFF) {
                  mid = i;
                }
              }
              i--;
                /* still no luck */
              if (mid == max) {
                mid = i;
                break;
              }
            }
              /* end, start, delta, and offset are for the i'th segment */
            if (mid != i) {
              table_idx = 8 + mid * 2;
              end = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
              table_idx += 2 + num_segs2;
              start = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
              table_idx += num_segs2;
              delta = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
              table_idx += num_segs2;
              offset = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
            }
          } else {
            if (offset == 0xFFFF) {
              break;
            }
          }
          if (offset != 0) {
            table_idx += offset + (charcode - start) * 2;
            gindex = FTUtil.FT_PEEK_USHORT(cmap.getCur_values(), table_idx);
            if (gindex != 0) {
              gindex = (int)(gindex + delta) & 0xFFFF;
            }
          } else {
            gindex = (int)(charcode + delta) & 0xFFFF;
          }
          break;
        }
      }
      if (next) {
        TTCMap4Rec cmap4 = (TTCMap4Rec)cmap;
          /* if `charcode' is not in any segment, then `mid' is */
................................................................................
  public FTError.ErrorTag getCmapInfo(FTCMapRec cmap) {
    return tt_cmap4_get_info(cmap);
  }

  /* ==================== charIndex ===================================== */
  @Override
  public int charIndex(FTCMapRec cmap, int char_code) {
    Log.e(TAG, "charIndex not yet implemented");
    return -1;
  }

  /* ==================== charNext ===================================== */
  @Override
  public int charNext(FTCMapRec cmap, FTReference<Integer> char_code_ref) {
    Log.e(TAG, "charNext not yet implemented");
    return -1;
  }

}







|
|







 







>







 







<

<
<
<
<
>



|
<
<
<








<
|
<
|






<
|
<
|







 







<

<
<
|

<



<
|
<
|
<
|







<
|
<
|
<
|
<
|







<
|
<
|





<
|
<
|













<
|
<
|
<
|
<
|







<
|

|


|







 







|
<










108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
...
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
...
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
...
544
545
546
547
548
549
550

551


552
553

554
555
556

557

558

559
560
561
562
563
564
565
566

567

568

569

570
571
572
573
574
575
576
577

578

579
580
581
582
583
584

585

586
587
588
589
590
591
592
593
594
595
596
597
598
599

600

601

602

603
604
605
606
607
608
609
610

611
612
613
614
615
616
617
618
619
620
621
622
623
...
719
720
721
722
723
724
725
726

727
728
729
730
731
732
733
734
735
736
    reserved_pad = stream.readShort();
    start_code = new byte[num_segs * 2];
    stream.readByteArray(start_code, (num_segs * 2));
    id_delta = new byte[num_segs * 2];
    stream.readByteArray(id_delta, (num_segs * 2));
    id_range_offset = new byte[num_segs * 2];
    stream.readByteArray(id_range_offset, (num_segs * 2));
    glyph_index_array = new byte[num_segs * 2];
    stream.readByteArray(glyph_index_array, (num_segs * 2));
    Debug(0, DebugTag.DBG_CMAP, TAG, "Cmap4Class: "+toDebugString());
    return error;
  }

  /* =====================================================================
   *    tt_cmap4_validate
   *
................................................................................
   * =====================================================================
   */
  private FTError.ErrorTag tt_cmap4_init(TTCMap4Rec cmap) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    cmap.setCur_charcode(0xFFFFFFFF);
    cmap.setCur_gindex(0);
    cmap.setNum_ranges(num_segs);
    return error;
  }

  /* =====================================================================
   *    tt_cmap4_set_range
   *
   * =====================================================================
................................................................................
    int delta;
    int max;
    int min;
    int mid;
    int num_segs;
    int charcode = charcode_ref.Get();
    int gindex   = 0;






    num_segs2 = this.num_segs * 2;
    if (num_segs2 == 0) {
      return 0;
    }
    num_segs = this.num_segs;



    if (next) {
      charcode++;
    }
    min = 0;
    max = num_segs;
      /* binary search */
    while (min < max) {
      mid = (min + max) >> 1;

      end = FTUtil.FT_PEEK_USHORT(end_code, mid * 2);

      start = FTUtil.FT_PEEK_USHORT(start_code, mid * 2);
      if (charcode < start) {
        max = mid;
      } else {
        if (charcode > end) {
          min = mid + 1;
        } else {

          delta = FTUtil.FT_PEEK_USHORT(id_delta, mid * 2);

          offset = FTUtil.FT_PEEK_USHORT(id_range_offset, mid * 2);
            /* some fonts have an incorrect last segment; */
            /* we have to catch it                        */
          if (mid >= num_segs - 1 && start == 0xFFFF && end == 0xFFFF) {
/*
            TTFaceRec face  = (TTFaceRec)cmap.face;
            int limit = (int)face.cmap_size;

................................................................................
            max = mid;
            if (offset == 0xFFFF) {
              mid = max + 1;
            }
              /* search in segments before the current segment */
            for (i = max ; i > 0; i--) {
              int prev_end;




              prev_end = FTUtil.FT_PEEK_USHORT(end_code, (i - 1) * 2);
              if (charcode > prev_end) {

                break;
              }
              end = prev_end;

              start = FTUtil.FT_PEEK_USHORT(start_code, (i - 1) * 2);

              delta = FTUtil.FT_PEEK_USHORT(id_delta, (i - 1) * 2);

              offset = FTUtil.FT_PEEK_USHORT(id_range_offset, (i - 1) * 2);
              if (offset != 0xFFFF) {
                mid = i - 1;
              }
            }
              /* no luck */
            if (mid == max + 1) {
              if (i != max) {

                end = FTUtil.FT_PEEK_USHORT(end_code, max * 2);

                start = FTUtil.FT_PEEK_USHORT(start_code, max * 2);

                delta = FTUtil.FT_PEEK_USHORT(id_delta, max * 2);

                offset = FTUtil.FT_PEEK_USHORT(id_range_offset, max * 2);
              }
              mid = max;
                /* search in segments after the current segment */
              for (i = max + 1; i < num_segs; i++) {
                int next_end;
                int next_start;


                next_end = FTUtil.FT_PEEK_USHORT(end_code, i * 2);

                next_start = FTUtil.FT_PEEK_USHORT(start_code, i * 2);
                if (charcode < next_start) {
                  break;
                }
                end = next_end;
                start = next_start;

                delta  = FTUtil.FT_PEEK_USHORT(id_delta, i * 2);

                offset = FTUtil.FT_PEEK_USHORT(id_range_offset, i * 2);
                if (offset != 0xFFFF) {
                  mid = i;
                }
              }
              i--;
                /* still no luck */
              if (mid == max) {
                mid = i;
                break;
              }
            }
              /* end, start, delta, and offset are for the i'th segment */
            if (mid != i) {

              end = FTUtil.FT_PEEK_USHORT(end_code, mid * 2);

              start = FTUtil.FT_PEEK_USHORT(start_code, mid * 2);

              delta = FTUtil.FT_PEEK_USHORT(id_delta, mid * 2);

              offset = FTUtil.FT_PEEK_USHORT(id_range_offset, mid * 2);
            }
          } else {
            if (offset == 0xFFFF) {
              break;
            }
          }
          if (offset != 0) {

            gindex = FTUtil.FT_PEEK_USHORT(glyph_index_array, (charcode - start) * 2);
            if (gindex != 0) {
              gindex = (gindex + delta) & 0xFFFF;
            }
          } else {
            gindex = (charcode + delta) & 0xFFFF;
          }
          break;
        }
      }
      if (next) {
        TTCMap4Rec cmap4 = (TTCMap4Rec)cmap;
          /* if `charcode' is not in any segment, then `mid' is */
................................................................................
  public FTError.ErrorTag getCmapInfo(FTCMapRec cmap) {
    return tt_cmap4_get_info(cmap);
  }

  /* ==================== charIndex ===================================== */
  @Override
  public int charIndex(FTCMapRec cmap, int char_code) {
    return tt_cmap4_char_index((TTCMap4Rec)cmap, char_code);

  }

  /* ==================== charNext ===================================== */
  @Override
  public int charNext(FTCMapRec cmap, FTReference<Integer> char_code_ref) {
    Log.e(TAG, "charNext not yet implemented");
    return -1;
  }

}

Changes to afttruetype/TTCMapClassRec.java.

68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
    return error;
  }

  /* ==================== initCMap ===================================== */
  @Override
  public FTError.ErrorTag initCMap(FTCMapRec cmap) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    Log.e(TAG, "initCMap not yet implemented");
//    cmap.data = table;

    return error;
  }

  /* ==================== doneCMap ===================================== */
  @Override
  public FTError.ErrorTag doneCMap(FTCMapRec cmap) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;







|
|
>







68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    return error;
  }

  /* ==================== initCMap ===================================== */
  @Override
  public FTError.ErrorTag initCMap(FTCMapRec cmap) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    // we can use this common method for nearly all TTCMap*ClassRec classes
    // these classes know about their own clazz.glyph_indices,
    // so we do not need the cmap.data field used in the original code.
    return error;
  }

  /* ==================== doneCMap ===================================== */
  @Override
  public FTError.ErrorTag doneCMap(FTCMapRec cmap) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

Changes to afttruetype/TTCMapRec.java.

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
...
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











    }

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

  /* ==================== getFlags ===================================== */
  public int getFlags(int flags) {
    return flags;
  }

  /* ==================== setFlags ===================================== */
  public void setFlags(int flags) {
    this.flags = flags;
  }

  /* =====================================================================
   * tt_face_build_cmaps
   * =====================================================================
   */
  public static FTError.ErrorTag buildCMaps(TTFaceRec ttface) {
Debug(0, DebugTag.DBG_CMAP, TAG, "buildCMaps");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    int num_tables = ttface.getCmap_table().getNumSubtables();
    for (int n = 0; n < num_tables; n++) {
      FTCharMapRec charmap = new FTCharMapRec();
      TTCMapClassRec my_clazz = null;

      TTCmapEncodingRec entry = ttface.getCmap_table().getSubtableEncoding(n);
      charmap.setPlatformId(entry.getPlatformId());
      charmap.setEncodingId(entry.getEncodingId());
      charmap.setEncoding(FTTags.Encoding.NONE);
      charmap.setFace(ttface);
      int format = ttface.getCmap_table().getFormatEntry(n);
      TTTags.CMapFormat cmap_format;
      switch (TTTags.CMapFormat.getTableTag(format)) {
        case CMap0:
          my_clazz = ttface.getCmap_table().getCMapClassEntry(TTTags.CMapFormat.CMap0);
          break;
        case CMap2:
          my_clazz = ttface.getCmap_table().getCMapClassEntry(TTTags.CMapFormat.CMap2);
          break;
................................................................................
      }
      TTValidatorRec valid = new TTValidatorRec();
      error = FTError.ErrorTag.ERR_OK;

System.out.println("validate format: "+my_clazz.getFormat());
      valid.init(FTTags.Validate.DEFAULT);
      valid.setNumGlyphs(ttface.getMax_profile().getNumGlyphs());
      error = ((TTCMapClassRec) my_clazz).validate(valid);
      if (valid.getError() == FTError.ErrorTag.ERR_OK) {
        TTCMapRec ttcmap = null;

                /* It might make sense to store the single variation         */
                /* selector cmap somewhere special.  But it would have to be */
                /* in the public FTFaceRec, and we can't change that.       */
        FTReference<FTCMapRec> ttcmap_ref = new FTReference<FTCMapRec>();
        ttcmap_ref.Set(ttcmap);
        if (FTCMapRec.FTCMapNew((FTCMapClassRec) my_clazz, charmap, ttcmap_ref) != FTError.ErrorTag.ERR_OK) {
                  /* it is simpler to directly set `flags' than adding */
                  /* a parameter to FTCMapNew                        */
          ttcmap = (TTCMapRec) ttcmap_ref.Get();
          ttcmap.setFlags(error.getVal());
        }
      } else {
        FTTrace.Trace(7, TAG, "buildCMaps: broken cmap sub-table ignored");
      }
    }
    return error;
  }

}


















<
<
<
<
<
<
<
<
<
<
<

|













|


<







 







|



|
|
|


|
|
|










|
>
>
>
>
>
>
>
>
>
>
>
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
...
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
    }

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











  /* =====================================================================
   * buildCMaps (tt_face_build_cmaps)
   * =====================================================================
   */
  public static FTError.ErrorTag buildCMaps(TTFaceRec ttface) {
Debug(0, DebugTag.DBG_CMAP, TAG, "buildCMaps");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    int num_tables = ttface.getCmap_table().getNumSubtables();
    for (int n = 0; n < num_tables; n++) {
      FTCharMapRec charmap = new FTCharMapRec();
      TTCMapClassRec my_clazz = null;

      TTCmapEncodingRec entry = ttface.getCmap_table().getSubtableEncoding(n);
      charmap.setPlatformId(entry.getPlatformId());
      charmap.setEncodingId(entry.getEncodingId());
      charmap.setEncoding(FTTags.Encoding.NONE);  /* will be filled later */
      charmap.setFace(ttface);
      int format = ttface.getCmap_table().getFormatEntry(n);

      switch (TTTags.CMapFormat.getTableTag(format)) {
        case CMap0:
          my_clazz = ttface.getCmap_table().getCMapClassEntry(TTTags.CMapFormat.CMap0);
          break;
        case CMap2:
          my_clazz = ttface.getCmap_table().getCMapClassEntry(TTTags.CMapFormat.CMap2);
          break;
................................................................................
      }
      TTValidatorRec valid = new TTValidatorRec();
      error = FTError.ErrorTag.ERR_OK;

System.out.println("validate format: "+my_clazz.getFormat());
      valid.init(FTTags.Validate.DEFAULT);
      valid.setNumGlyphs(ttface.getMax_profile().getNumGlyphs());
      error = my_clazz.validate(valid);
      if (valid.getError() == FTError.ErrorTag.ERR_OK) {
        TTCMapRec ttcmap = null;

        /* It might make sense to store the single variation         */
        /* selector cmap somewhere special.  But it would have to be */
        /* in the public FTFaceRec, and we can't change that.       */
        FTReference<FTCMapRec> ttcmap_ref = new FTReference<FTCMapRec>();
        ttcmap_ref.Set(ttcmap);
        if (FTCMapRec.FTCMapNew(my_clazz, charmap, ttcmap_ref) != FTError.ErrorTag.ERR_OK) {
          /* it is simpler to directly set `flags' than adding */
          /* a parameter to FTCMapNew                        */
          ttcmap = (TTCMapRec) ttcmap_ref.Get();
          ttcmap.setFlags(error.getVal());
        }
      } else {
        FTTrace.Trace(7, TAG, "buildCMaps: broken cmap sub-table ignored");
      }
    }
    return error;
  }


  /* ==================== getFlags ===================================== */
  public int getFlags(int flags) {
    return flags;
  }

  /* ==================== setFlags ===================================== */
  public void setFlags(int flags) {
    this.flags = flags;
  }

}

Changes to afttruetype/TTSizeRec.java.

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
...
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
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
...
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
...
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
    instruction_defs = new TTDefRec[1];
    codeRangeTable = new TTCodeRange[TT_MAX_CODE_RANGES];
    for (int i = 0; i < TT_MAX_CODE_RANGES; i++) {
      codeRangeTable[i] = new TTCodeRange();
    }
    graphics_state = new TTDefaultGraphicsStateClass();
    twilight = new TTGlyphZoneRec();
Debug(0, DebugTag.DBG_INIT, TAG, "exec1 ttsize: "+context+"!");
  }
    
  /* ==================== mySelf ================================== */
  public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
................................................................................
  *
  * <Return>
  *    FreeType error code.  0 means success.
  *
  * =====================================================================
 */
  public FTError.ErrorTag tt_size_init() {
    Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "tt_size_init");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    bytecode_ready = false;
    cvt_ready = false;
    ttmetrics.setValid(false);
    strike_index = 0xFFFFFFFF;
    return error;
................................................................................

  /* =====================================================================
   *    tt_size_done_bytecode
   *
   * =====================================================================
   */
  public void tt_size_done_bytecode() {   /* TT_Face */
    Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "tt_size_done_bytecode");

    cvt = null;
    cvt_size = 0;
      /* twilight zone */
    twilight.tt_glyphzone_done();
    function_defs = null;
    instruction_defs = null;
................................................................................
  }

  /* =====================================================================
   * tt_size_request
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_request(FTSizeRequestRec req) {
    Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "tt_size_request");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    face.getSize().getMetrics().RequestMetrics(face, req);
    if (face.getFace_flags().contains(Flags.Face.SCALABLE)) {
      error = tt_size_reset();
    }
    return error;
................................................................................
   *
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_reset() {
    TTFaceRec ttface = (TTFaceRec)face;
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "tt_size_reset");
    ttmetrics.setValid(false);
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "facse ascender: "+ttface.getAscender()+" "+ttface.getDescender()+" "+ttface.getHeight());
      /* copy the result from base layer */
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "RES: "+metrics.getX_ppem()+"!"+metrics.getY_ppem()+"!"+local_metrics.getX_ppem()+"!"+local_metrics.getY_ppem()+"!");
    local_metrics.copy(metrics);
    if (local_metrics.getX_ppem() < 1 || local_metrics.getY_ppem() < 1) {
      return FTError.ErrorTag.GLYPH_INVALID_PPEM;
    }
      /* This bit flag, if set, indicates that the ppems must be       */
      /* rounded to integers.  Nearly all TrueType fonts have this bit */
      /* set, as hinting won't work really well otherwise.             */
      /*                                                               */
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "face.header.flags: "+(ttface.getHeader().getFlags() & 8)+"!");
    if ((ttface.getHeader().getFlags() & 8) != 0) {
      local_metrics.setX_scale(FTCalc.FTDivFix(local_metrics.getX_ppem() << 6, ttface.getUnits_per_EM()));
      local_metrics.setY_scale(FTCalc.FTDivFix(local_metrics.getY_ppem() << 6, ttface.getUnits_per_EM()));

      local_metrics.setAscender(FTCalc.FT_PIX_ROUND(FTCalc.FTMulFix(ttface.getAscender(), local_metrics.getY_scale())));
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "ascender: "+local_metrics.getAscender()+" "+ttface.getAscender()+" "+local_metrics.getY_scale());
      local_metrics.setDescender(FTCalc.FT_PIX_ROUND(FTCalc.FTMulFix(ttface.getDescender(), local_metrics.getY_scale())));
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "descender: "+local_metrics.getDescender()+" "+ttface.getDescender()+" "+local_metrics.getY_scale());
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "descender2: "+metrics.getDescender()+" "+ttface.getDescender()+" "+local_metrics.getY_scale());
      local_metrics.setHeight(FTCalc.FT_PIX_ROUND(FTCalc.FTMulFix(ttface.getHeight(), local_metrics.getY_scale())));
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "height: "+local_metrics.getHeight()+" "+ttface.getHeight()+" "+local_metrics.getY_scale());
      local_metrics.setMax_advance(FTCalc.FT_PIX_ROUND(FTCalc.FTMulFix(ttface.getMax_advance_width(), local_metrics.getX_scale())));
    }
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "tt_size_reset: size: "+this+"!");
      /* compute new transformation */
    if (local_metrics.getX_ppem() >= local_metrics.getY_ppem()) {
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "x_scale: "+local_metrics.getX_scale()+"!"+ttmetrics.getScale()+"!");
      ttmetrics.setScale(local_metrics.getX_scale());
      ttmetrics.setPpem(local_metrics.getX_ppem());
      ttmetrics.setX_ratio(0x10000);
      ttmetrics.setY_ratio(FTCalc.FTDivFix(local_metrics.getY_ppem(), local_metrics.getX_ppem()));
    } else {
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "y_scale: "+local_metrics.getX_scale()+"!"+ttmetrics.getScale()+"!");
      ttmetrics.setScale(local_metrics.getY_scale());
      ttmetrics.setPpem(local_metrics.getY_ppem());
      ttmetrics.setX_ratio(FTCalc.FTDivFix(local_metrics.getX_ppem(), local_metrics.getY_ppem()));
      ttmetrics.setY_ratio(0x10000);
    }
    cvt_ready = false;
    if (error == FTError.ErrorTag.ERR_OK) {
................................................................................
  }

  /* =====================================================================
   * tt_size_ready_bytecode
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_ready_bytecode(boolean pedantic) {
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "tt_size_ready_bytecode");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    TTFaceRec ttface = (TTFaceRec)face;

    if (!bytecode_ready) {
      error = tt_size_init_bytecode(pedantic);
      if (error != FTError.ErrorTag.ERR_OK) {
        return error;
................................................................................
    }
      /* rescale CVT when needed */
    if (!cvt_ready) {
      int i;

        /* Scale the cvt values to the new ppem.          */
        /* We use by default the y ppem to scale the CVT. */
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "tt_size_ready_bytecode: "+this+"!");
      for (i = 0; i < cvt_size; i++) {
        cvt[i] = TTUtil.FTMulFix(ttface.getCvt_table().getCvtValue(i), ttmetrics.getScale());
        Debug(-1, DebugTag.DBG_LOAD_GLYPH, TAG, "size->cvt: i: "+i+" cvt[i]: "+cvt[i]+" cvt_value: "+ttface.getCvt_table().getCvtValue(i)+" scale: "+ttmetrics.getScale()+"!");
      }
        /* all twilight points are originally zero */
      for (i = 0; i < twilight.getN_points(); i++) {
        twilight.resetOrgPoint(i);
................................................................................
   *
   * <Return>
   *    FreeType error code.  0 means success.
   *
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_run_prep(boolean pedantic) {
    Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "tt_size_run_prep");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    TTExecContextRec exec;
    TTFaceRec ttface = (TTFaceRec)face;

      /* debugging instances have their own context */
    if (debug) {
      exec = context;
................................................................................
    exec.TTLoadContext(ttface, this);
    exec.callTop = 0;
    exec.top     = 0;
    exec.instruction_trap = false;
    exec.pedantic_hinting = pedantic;
    exec.TTSetCodeRange(TTInterpTags.CodeRange.CVT, ttface.getPrep_table().getPrepProgram(), null, ttface.getPrep_table().getPrepProgramSize());
    exec.TTClearCodeRange(TTInterpTags.CodeRange.GLYPH);
    Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "cvt_program_size: "+ttface.getPrep_table().getPrepProgramSize()+"!");
    if (ttface.getPrep_table().getPrepProgramSize() > 0) {
      error = (exec.TTGotoCodeRange(TTInterpTags.CodeRange.CVT, 0) == FTError.ErrorTag.ERR_OK ? FTError.ErrorTag.ERR_OK : FTError.ErrorTag.UNEXPECTED_NULL_VALUE);
      if (error == FTError.ErrorTag.ERR_OK && !debug) {
        FTTrace.Trace(7, TAG, "Executing `prep' table.");
        if (exec.code == null) {
          return FTError.ErrorTag.UNEXPECTED_NULL_VALUE;
        }
................................................................................
  }

  /* =====================================================================
   * tt_size_init_bytecode
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_init_bytecode(boolean pedantic) {
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "tt_size_init_bytecode");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    TTFaceRec ttface = (TTFaceRec)face;
    int i;
    int n_twilight;
    TTMaxProfileRec maxp = ttface.getMax_profile();
    bytecode_ready = true;
    cvt_ready = false;
................................................................................
   *
   * <Return>
   *    FreeType error code.  0 means success.
   *
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_run_fpgm(boolean pedantic) {
Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "tt_size_run_fpgm");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    TTFaceRec ttface = (TTFaceRec)face;
    TTDriverRec ttdriver = (TTDriverRec)ttface.getDriver();
    TTExecContextRec exec;

      /* debugging instances have their own context */
    if (debug) {
................................................................................

  /* =====================================================================
   * TTSaveContext
   *
   * =====================================================================
   */
  public FTError.ErrorTag TTSaveContext(TTExecContextRec exec) {
    Debug(0, DebugTag.DBG_LOAD_GLYPH, TAG, "TTSaveContext");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    int i;

      /* XXX: Will probably disappear soon with all the code range */
      /*      management, which is now rather obsolete.            */
      /*                                                           */
    num_function_defs = exec.numFDefs;







|







 







|







 







|







 







|







 







|

|

|








|





|

|
|

|


|


|





|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
...
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
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
...
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
...
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
    instruction_defs = new TTDefRec[1];
    codeRangeTable = new TTCodeRange[TT_MAX_CODE_RANGES];
    for (int i = 0; i < TT_MAX_CODE_RANGES; i++) {
      codeRangeTable[i] = new TTCodeRange();
    }
    graphics_state = new TTDefaultGraphicsStateClass();
    twilight = new TTGlyphZoneRec();
Debug(0, DebugTag.DBG_SIZE, TAG, "exec1 ttsize: "+context+"!");
  }
    
  /* ==================== mySelf ================================== */
  public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
................................................................................
  *
  * <Return>
  *    FreeType error code.  0 means success.
  *
  * =====================================================================
 */
  public FTError.ErrorTag tt_size_init() {
Debug(0, DebugTag.DBG_SIZE, TAG, "tt_size_init");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    bytecode_ready = false;
    cvt_ready = false;
    ttmetrics.setValid(false);
    strike_index = 0xFFFFFFFF;
    return error;
................................................................................

  /* =====================================================================
   *    tt_size_done_bytecode
   *
   * =====================================================================
   */
  public void tt_size_done_bytecode() {   /* TT_Face */
Debug(0, DebugTag.DBG_SIZE, TAG, "tt_size_done_bytecode");

    cvt = null;
    cvt_size = 0;
      /* twilight zone */
    twilight.tt_glyphzone_done();
    function_defs = null;
    instruction_defs = null;
................................................................................
  }

  /* =====================================================================
   * tt_size_request
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_request(FTSizeRequestRec req) {
Debug(0, DebugTag.DBG_SIZE, TAG, "tt_size_request");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    face.getSize().getMetrics().RequestMetrics(face, req);
    if (face.getFace_flags().contains(Flags.Face.SCALABLE)) {
      error = tt_size_reset();
    }
    return error;
................................................................................
   *
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_reset() {
    TTFaceRec ttface = (TTFaceRec)face;
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

Debug(0, DebugTag.DBG_SIZE, TAG, "tt_size_reset");
    ttmetrics.setValid(false);
Debug(0, DebugTag.DBG_SIZE, TAG, "facse ascender: "+ttface.getAscender()+" "+ttface.getDescender()+" "+ttface.getHeight());
      /* copy the result from base layer */
Debug(0, DebugTag.DBG_SIZE, TAG, "RES: "+metrics.getX_ppem()+"!"+metrics.getY_ppem()+"!"+local_metrics.getX_ppem()+"!"+local_metrics.getY_ppem()+"!");
    local_metrics.copy(metrics);
    if (local_metrics.getX_ppem() < 1 || local_metrics.getY_ppem() < 1) {
      return FTError.ErrorTag.GLYPH_INVALID_PPEM;
    }
      /* This bit flag, if set, indicates that the ppems must be       */
      /* rounded to integers.  Nearly all TrueType fonts have this bit */
      /* set, as hinting won't work really well otherwise.             */
      /*                                                               */
Debug(0, DebugTag.DBG_SIZE, TAG, "face.header.flags: "+(ttface.getHeader().getFlags() & 8)+"!");
    if ((ttface.getHeader().getFlags() & 8) != 0) {
      local_metrics.setX_scale(FTCalc.FTDivFix(local_metrics.getX_ppem() << 6, ttface.getUnits_per_EM()));
      local_metrics.setY_scale(FTCalc.FTDivFix(local_metrics.getY_ppem() << 6, ttface.getUnits_per_EM()));

      local_metrics.setAscender(FTCalc.FT_PIX_ROUND(FTCalc.FTMulFix(ttface.getAscender(), local_metrics.getY_scale())));
Debug(0, DebugTag.DBG_SIZE, TAG, "ascender: "+local_metrics.getAscender()+" "+ttface.getAscender()+" "+local_metrics.getY_scale());
      local_metrics.setDescender(FTCalc.FT_PIX_ROUND(FTCalc.FTMulFix(ttface.getDescender(), local_metrics.getY_scale())));
Debug(0, DebugTag.DBG_SIZE, TAG, "descender: "+local_metrics.getDescender()+" "+ttface.getDescender()+" "+local_metrics.getY_scale());
Debug(0, DebugTag.DBG_SIZE, TAG, "descender2: "+metrics.getDescender()+" "+ttface.getDescender()+" "+local_metrics.getY_scale());
      local_metrics.setHeight(FTCalc.FT_PIX_ROUND(FTCalc.FTMulFix(ttface.getHeight(), local_metrics.getY_scale())));
Debug(0, DebugTag.DBG_SIZE, TAG, "height: "+local_metrics.getHeight()+" "+ttface.getHeight()+" "+local_metrics.getY_scale());
      local_metrics.setMax_advance(FTCalc.FT_PIX_ROUND(FTCalc.FTMulFix(ttface.getMax_advance_width(), local_metrics.getX_scale())));
    }
Debug(0, DebugTag.DBG_SIZE, TAG, "tt_size_reset: size: "+this+"!");
      /* compute new transformation */
    if (local_metrics.getX_ppem() >= local_metrics.getY_ppem()) {
Debug(0, DebugTag.DBG_SIZE, TAG, "x_scale: "+local_metrics.getX_scale()+"!"+ttmetrics.getScale()+"!");
      ttmetrics.setScale(local_metrics.getX_scale());
      ttmetrics.setPpem(local_metrics.getX_ppem());
      ttmetrics.setX_ratio(0x10000);
      ttmetrics.setY_ratio(FTCalc.FTDivFix(local_metrics.getY_ppem(), local_metrics.getX_ppem()));
    } else {
Debug(0, DebugTag.DBG_SIZE, TAG, "y_scale: "+local_metrics.getX_scale()+"!"+ttmetrics.getScale()+"!");
      ttmetrics.setScale(local_metrics.getY_scale());
      ttmetrics.setPpem(local_metrics.getY_ppem());
      ttmetrics.setX_ratio(FTCalc.FTDivFix(local_metrics.getX_ppem(), local_metrics.getY_ppem()));
      ttmetrics.setY_ratio(0x10000);
    }
    cvt_ready = false;
    if (error == FTError.ErrorTag.ERR_OK) {
................................................................................
  }

  /* =====================================================================
   * tt_size_ready_bytecode
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_ready_bytecode(boolean pedantic) {
Debug(0, DebugTag.DBG_SIZE, TAG, "tt_size_ready_bytecode");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    TTFaceRec ttface = (TTFaceRec)face;

    if (!bytecode_ready) {
      error = tt_size_init_bytecode(pedantic);
      if (error != FTError.ErrorTag.ERR_OK) {
        return error;
................................................................................
    }
      /* rescale CVT when needed */
    if (!cvt_ready) {
      int i;

        /* Scale the cvt values to the new ppem.          */
        /* We use by default the y ppem to scale the CVT. */
Debug(0, DebugTag.DBG_SIZE, TAG, "tt_size_ready_bytecode: "+this+"!");
      for (i = 0; i < cvt_size; i++) {
        cvt[i] = TTUtil.FTMulFix(ttface.getCvt_table().getCvtValue(i), ttmetrics.getScale());
        Debug(-1, DebugTag.DBG_LOAD_GLYPH, TAG, "size->cvt: i: "+i+" cvt[i]: "+cvt[i]+" cvt_value: "+ttface.getCvt_table().getCvtValue(i)+" scale: "+ttmetrics.getScale()+"!");
      }
        /* all twilight points are originally zero */
      for (i = 0; i < twilight.getN_points(); i++) {
        twilight.resetOrgPoint(i);
................................................................................
   *
   * <Return>
   *    FreeType error code.  0 means success.
   *
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_run_prep(boolean pedantic) {
Debug(0, DebugTag.DBG_SIZE, TAG, "tt_size_run_prep");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    TTExecContextRec exec;
    TTFaceRec ttface = (TTFaceRec)face;

      /* debugging instances have their own context */
    if (debug) {
      exec = context;
................................................................................
    exec.TTLoadContext(ttface, this);
    exec.callTop = 0;
    exec.top     = 0;
    exec.instruction_trap = false;
    exec.pedantic_hinting = pedantic;
    exec.TTSetCodeRange(TTInterpTags.CodeRange.CVT, ttface.getPrep_table().getPrepProgram(), null, ttface.getPrep_table().getPrepProgramSize());
    exec.TTClearCodeRange(TTInterpTags.CodeRange.GLYPH);
Debug(0, DebugTag.DBG_SIZE, TAG, "cvt_program_size: "+ttface.getPrep_table().getPrepProgramSize()+"!");
    if (ttface.getPrep_table().getPrepProgramSize() > 0) {
      error = (exec.TTGotoCodeRange(TTInterpTags.CodeRange.CVT, 0) == FTError.ErrorTag.ERR_OK ? FTError.ErrorTag.ERR_OK : FTError.ErrorTag.UNEXPECTED_NULL_VALUE);
      if (error == FTError.ErrorTag.ERR_OK && !debug) {
        FTTrace.Trace(7, TAG, "Executing `prep' table.");
        if (exec.code == null) {
          return FTError.ErrorTag.UNEXPECTED_NULL_VALUE;
        }
................................................................................
  }

  /* =====================================================================
   * tt_size_init_bytecode
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_init_bytecode(boolean pedantic) {
Debug(0, DebugTag.DBG_SIZE, TAG, "tt_size_init_bytecode");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    TTFaceRec ttface = (TTFaceRec)face;
    int i;
    int n_twilight;
    TTMaxProfileRec maxp = ttface.getMax_profile();
    bytecode_ready = true;
    cvt_ready = false;
................................................................................
   *
   * <Return>
   *    FreeType error code.  0 means success.
   *
   * =====================================================================
   */
  public FTError.ErrorTag tt_size_run_fpgm(boolean pedantic) {
Debug(0, DebugTag.DBG_SIZE, TAG, "tt_size_run_fpgm");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    TTFaceRec ttface = (TTFaceRec)face;
    TTDriverRec ttdriver = (TTDriverRec)ttface.getDriver();
    TTExecContextRec exec;

      /* debugging instances have their own context */
    if (debug) {
................................................................................

  /* =====================================================================
   * TTSaveContext
   *
   * =====================================================================
   */
  public FTError.ErrorTag TTSaveContext(TTExecContextRec exec) {
Debug(0, DebugTag.DBG_SIZE, TAG, "TTSaveContext");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    int i;

      /* XXX: Will probably disappear soon with all the code range */
      /*      management, which is now rather obsolete.            */
      /*                                                           */
    num_function_defs = exec.numFDefs;

Changes to aftutil/FTDebug.java.

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
..
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
..
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113
114
public class FTDebug extends Object {
  private static int oid = 0;

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

  public enum DebugTag {
    DBG_BASE(1, 0, true, "DBG_BASE"),

    DBG_CACHE(2, 0, true, "DBG_CACHE"),
    DBG_CMAP(3, 0, true, "DBG_CMAP"),
    DBG_INIT(4, 2, true, "DBG_INIT"),
    DBG_INTERP(5, 2, true, "DBG_INTERP"),
    DBG_LIBRARY(6, 0, true, "DBG_LIBRARY"),
    DBG_LOAD_FACE(7, 0, true, "DBG_LOAD_FACE"),
    DBG_LOAD_GLYPH(8, 2, true, "DBG_LOAD_GLYPH"),
    DBG_RENDER(9, 0, true, "DBG_RENDER"),
    DBG_DECOMPOSE(10, 0, true, "DBG_DECOMPOSE"),
    DBG_SWEEP(11, 0, true, "DBG_SWEEP"),
    DBG_MD5(12, 2, true, "DBG_MD5");

    private int val;
    private int level;
    private boolean dbgIsOn;
    private String str;
    private static SparseArray<DebugTag> tagToDebugTagMapping;
    public static DebugTag getTableTag(int i) {
................................................................................
    public int getVal() {
        return val;
      }
    public String getDescription() {
        return str;
      }
  }
  private static final int DBG_MAX_TYPES = 20;

  /* ==================== constructor ================================== */
  public FTDebug() {
    oid++;
    id = oid;
            
  }
................................................................................
  public String toDebugString() {
    StringBuffer str = new StringBuffer(mySelf()+"\n");
    return str.toString();
  }
 
  /* ==================== Debug ================================== */
  public static void Debug(int level, DebugTag type, String tag, String str) throws IndexOutOfBoundsException {

    if (type.getVal() < 0 || type.getVal() >= DBG_MAX_TYPES) {
      throw new IndexOutOfBoundsException(String.format("bad type: %d in FTShowDebug", type));
    }
    if (type.isOn() && level >= type.level()) {
      Log.i(TAG, type.getDescription()+": "+tag+": "+str);
    }
  }
    
}







|
>
|
|
|
|
|
|
|
|
|
|
|







 







|







 







>
|
|







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
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
public class FTDebug extends Object {
  private static int oid = 0;

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

  public enum DebugTag {
    DBG_BASE(1 << 0, 0, true, "DBG_BASE"),
    DBG_SIZE(1 << 1, 0, true, "DBG_SIZE"),
    DBG_CACHE(1 << 2, 0, true, "DBG_CACHE"),
    DBG_CMAP(1 << 3, 0, true, "DBG_CMAP"),
    DBG_INIT(1 << 4, 2, true, "DBG_INIT"),
    DBG_INTERP(1 << 5, 2, true, "DBG_INTERP"),
    DBG_LIBRARY(1 << 6, 0, true, "DBG_LIBRARY"),
    DBG_LOAD_FACE(1 << 7, 0, true, "DBG_LOAD_FACE"),
    DBG_LOAD_GLYPH(1 << 8, 2, true, "DBG_LOAD_GLYPH"),
    DBG_RENDER(1 << 9, 0, true, "DBG_RENDER"),
    DBG_DECOMPOSE(1 << 10, 0, true, "DBG_DECOMPOSE"),
    DBG_SWEEP(1 << 11, 0, true, "DBG_SWEEP"),
    DBG_MD5(1 << 12, 2, true, "DBG_MD5");

    private int val;
    private int level;
    private boolean dbgIsOn;
    private String str;
    private static SparseArray<DebugTag> tagToDebugTagMapping;
    public static DebugTag getTableTag(int i) {
................................................................................
    public int getVal() {
        return val;
      }
    public String getDescription() {
        return str;
      }
  }
  private static final int DBG_MAX_TYPES = 32;

  /* ==================== constructor ================================== */
  public FTDebug() {
    oid++;
    id = oid;
            
  }
................................................................................
  public String toDebugString() {
    StringBuffer str = new StringBuffer(mySelf()+"\n");
    return str.toString();
  }
 
  /* ==================== Debug ================================== */
  public static void Debug(int level, DebugTag type, String tag, String str) throws IndexOutOfBoundsException {
    // ATTENTION take care that 1 << <nn> in th next line fits to the maximum Debug type!!
    if (type.getVal() < 0 || type.getVal() > (1 << 12)) {
      throw new IndexOutOfBoundsException(String.format("bad type: %s (0x%08x) in Debug", type, type.getVal()));
    }
    if (type.isOn() && level >= type.level()) {
      Log.i(TAG, type.getDescription()+": "+tag+": "+str);
    }
  }
    
}