ApwFreetypeLibrary

Check-in [170c896db0]
Login

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

Overview
Comment:initial version.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:170c896db0424e342c56da4dfcd63bd58c41acdf
User & Date: arnulf 2014-12-30 23:01:08
Context
2014-12-31
14:38
fixes. check-in: 41da7c263e user: arnulf tags: trunk
2014-12-30
23:01
initial version. check-in: 170c896db0 user: arnulf tags: trunk
23:00
fixes. check-in: bb1dc76dfa user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added ftraster/FTGrayOutlineClassFuncs.java.





































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    FTGrayOutlineClassFuncs                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTGrayOutlineClassFuncs extends ftbase.FTOutlineFuncs {
    private static int oid = 0;

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

    public static int PIXEL_BITS = 8;

    /* ==================== FTGrayOutlineClassFuncs ================================== */
    public FTGrayOutlineClassFuncs() {
      oid++;
      id = oid;
      String class_name = "org.apwtcl.gles20.truetype.FTGrayOutlineFuncs";
      move_to = new ftbase.FTInstanceMethod(class_name, "gray_move_to", 1);
      line_to = new ftbase.FTInstanceMethod(class_name, "gray_line_to", 1);
      conic_to = new ftbase.FTInstanceMethod(class_name, "gray_conic_to", 1);
      cubic_to = new ftbase.FTInstanceMethod(class_name, "gray_cubic_to", 1);
      shift = 0;
      delta = 0L;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * ONE_PIXEL
     * =====================================================================
     */
    public static long ONE_PIXEL() {
      return (1L << PIXEL_BITS);
    }
 
    /* =====================================================================
     * PIXEL_MASK
     * =====================================================================
     */
    public static long PIXEL_MASK() {
      return (-1L << PIXEL_BITS);
    }
 
    /* =====================================================================
     * TRUNC
     * =====================================================================
     */
    public static long TRUNC(long x) {
      return ((long)(x >> PIXEL_BITS));
    }
 
    /* =====================================================================
     * SUBPIXELS
     * =====================================================================
     */
    public static long SUBPIXELS(long x) {
      return ((long)x << PIXEL_BITS);
    }
 
    /* =====================================================================
     * FLOOR
     * =====================================================================
     */
    public static long FLOOR(long x) {
      return (x & -ONE_PIXEL());
    }
 
    /* =====================================================================
     * CEILING
     * =====================================================================
     */
    public static long CEILING(long x) {
      return ((x + ONE_PIXEL() - 1) & -ONE_PIXEL());
    }
 
    /* =====================================================================
     * ROUND
     * =====================================================================
     */
    public static long ROUND(long x) {
      return ((x + ONE_PIXEL() / 2) & -ONE_PIXEL());
    }
 
    /* =====================================================================
     * UPSCALE
     * =====================================================================
     */
    public static long UPSCALE(long x) {
      return (x << (PIXEL_BITS - 6));
    }
 
    /* =====================================================================
     * DOWNSCALE
     * =====================================================================
     */
    public static long DOWNSCALE(long x) {
      return (x >> (PIXEL_BITS - 6));
    }

}

Added ftraster/FTGrayOutlineFuncs.java.



























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

import android.util.Log;

  /* ===================================================================== */
  /*    FTGrayOutlineFuncs                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTGrayOutlineFuncs extends ftbase.FTDebug {
    private static int oid = 0;

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

    /* ==================== FTGrayOutlineFuncs ================================== */
    public FTGrayOutlineFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     *    gray_move_to
     *
     * =====================================================================
     */
    public static int gray_move_to(Object ... args) {
      ftbase.FTVectorRec to = (ftbase.FTVectorRec)args[0];
      grayTWorker worker = (grayTWorker)args[1];
      int error = 0;
      long x;
      long y;
Debug(0, DBG_RENDER, TAG, String.format("gray_move_to: to.x: %d, to.y: %d", to.x, to.y));

      /* record current cell, if any */
      gray_record_cell(worker);
      /* start to a new position */
      x = FTGrayOutlineClassFuncs.UPSCALE(to.x);
      y = FTGrayOutlineClassFuncs.UPSCALE(to.y);
      gray_start_cell(worker, FTGrayOutlineClassFuncs.TRUNC(x), FTGrayOutlineClassFuncs.TRUNC(y));
      worker.x = x;
      worker.y = y;
      return error;
    }

    /* =====================================================================
     *    gray_line_to
     *
     * =====================================================================
     */
    public static int gray_line_to(Object ... args) {
      ftbase.FTVectorRec to = (ftbase.FTVectorRec)args[0];
Debug(0, DBG_RENDER, TAG, String.format("gray_line_to: to.x: %d, to.y: %d", to.x, to.y));
      grayTWorker worker = (grayTWorker)args[1];
      int error = 0;

Debug(0, DBG_RENDER, TAG, "gray_line_to call gray_render_line");
      gray_render_line(worker, FTGrayOutlineClassFuncs.UPSCALE(to.x), FTGrayOutlineClassFuncs.UPSCALE(to.y));
Debug(0, DBG_RENDER, TAG, "gray_line_to after call gray_render_line");
      return error;
    }

    /* =====================================================================
     *    gray_conic_to
     *
     * =====================================================================
     */
    public static int gray_conic_to(Object ... args) {
Debug(0, DBG_RENDER, TAG, "gray_conic_to");
      ftbase.FTVectorRec control = (ftbase.FTVectorRec)args[0];
      ftbase.FTVectorRec to = (ftbase.FTVectorRec)args[1];
      grayTWorker worker = (grayTWorker)args[2];
      int error = 0;

      gray_render_conic(control, to, worker);
Debug(0, DBG_RENDER, TAG, "gray_conic_to end");
      return error;
    }

    /* =====================================================================
     *    gray_cubic_to
     *
     * =====================================================================
     */
    public static int gray_cubic_to(Object ... args) {
Debug(0, DBG_RENDER, TAG, "gray_cubic_to");
      ftbase.FTVectorRec control1 = (ftbase.FTVectorRec)args[0];
      ftbase.FTVectorRec control2 = (ftbase.FTVectorRec)args[1];
      ftbase.FTVectorRec to = (ftbase.FTVectorRec)args[2];
      grayTWorker worker = (grayTWorker)args[3];
      int error = 0;

      FTGrayOutlineFuncs.gray_render_cubic(control1, control2, to, worker);
Debug(0, DBG_RENDER, TAG, "gray_cubic_to end");
      return error;
    }

    /* =====================================================================
     *    gray_find_cell
     *
     * =====================================================================
     */
    public static TCell gray_find_cell(grayTWorker worker) {
Debug(0, DBG_RENDER, TAG, String.format("gray_find_cell: ras.ex: %d, ras.ey: %d, ras.count_ex: %d, ras.num_cells: %d", worker.ex, worker.ey, worker.count_ex, worker.num_cells));
      int pcellIdx;
      int cellIdx;
      TCell cell = null;
      TCell pcell = null;
      long x = worker.ex;
      boolean useYcells = true;
      boolean isYcell = true;

      if (x > worker.count_ex) {
        x = worker.count_ex;
      }
for(int j = 0; j < worker.ycount; j++) {
  long a = worker.ycells[j] == null ? -1 : worker.ycells[j].area;
  long c = worker.ycells[j] == null ? -1 : worker.ycells[j].cover; 
  StringBuffer str = new StringBuffer("");
  str.append(String.format("ycells j: %2d, idx: %2d, x: %4d, a: %6x, c: %6x", j,
      worker.ycells[j] == null ? -1 : worker.ycells[j].self_idx,
      worker.ycells[j] == null ? -1 : worker.ycells[j].x,
      a & 0xFFFFFF, c & 0xFFFFFF));
  cell = worker.ycells[j];
  while( cell != null) {
    cell = cell.next;
    if (cell != null) {
      str.append(String.format("\n              idx: %2d, x: %4d, a: %6x, c: %6x",
          cell.self_idx, cell.x, cell.area & 0xFFFFFF, cell.cover & 0xFFFFFF));
    }
  }
  Debug(0, DBG_RENDER, TAG, str.toString());
}

      
      pcellIdx = (int)worker.ey;
      cellIdx = -1;
      for (;;) {
        if (cellIdx == -1) {
          cell = worker.ycells[pcellIdx];
        } else {
          cell = cell.next;        
        }
        if (cell == null || cell.x > x) {
          break;
        }
        if (cell.x == x) {
          return cell;
        }
        if (!useYcells) {
          isYcell = false; 
        }
        useYcells = false;
        cellIdx = cell.self_idx;
      }
      if (worker.num_cells >= worker.max_cells) {
//FIXME!!        ft_longjmp( worker.jump_buffer, 1 );
Log.e(TAG, "out of worker.cells: "+worker.num_cells+"!"+worker.max_cells);
      }
      cell = worker.cells[worker.num_cells++];
      cell.self_idx = worker.num_cells - 1;
      cell.x = x;
      cell.area = 0;
      cell.cover = 0;
      if (useYcells) {
        cell.next = worker.ycells[pcellIdx];
//System.out.println(String.format("pcellIdx: %d",  pcellIdx));        
        worker.ycells[pcellIdx] = cell;
      } else {
        if (isYcell) {
          cell.next = worker.ycells[pcellIdx].next;          
Debug(0, DBG_RENDER, TAG, String.format("cellIdx. %d pcellIdx: %d",  cellIdx, pcellIdx));
          worker.ycells[pcellIdx].next = cell;
Debug(0, DBG_RENDER, TAG, String.format("isYcell: cell idx: %d cell next idx: %d ", cell.self_idx, cell.next == null ? -1 : cell.next.self_idx));
        } else {
          cell.next = worker.cells[cellIdx].next;
Debug(0, DBG_RENDER, TAG, String.format("cellIdx. %d pcellIdx: %d",  cellIdx, pcellIdx));
          worker.cells[cellIdx].next = cell;
        }
      }
      return cell;
    }

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

      if (!worker.invalid && (worker.area | worker.cover) != 0) {
        TCell cell = gray_find_cell(worker);

        cell.area  += worker.area;
        cell.cover += worker.cover;
Debug(0, DBG_RENDER, TAG, String.format("gray_record_cell2: cell.area: %x, cell.cover: %x worker.area: %x, worker.cover: %x\n", cell.area, cell.cover, worker.area, worker.cover));
      }
    }

    /* =====================================================================
     *    gray_set_cell
     *
     * Move the cell pointer to a new position.  We set the `invalid'
     * flag to indicate that the cell isn't part of those we're interested
     * in during the render phase.  This means that:
     *
     * . the new vertical position must be within min_ey..max_ey-1.
     * . the new horizontal position must be strictly less than max_ex 
     *
     * Note that if a cell is to the left of the clipping region, it is
     * actually set to the (min_ex-1) horizontal position.
     *
     * =====================================================================
     */
    public static void gray_set_cell(grayTWorker worker, long ex, long ey) {
Debug(0, DBG_RENDER, TAG, String.format("gray_set_cell: ex: %d, ey: %d, invalid: %b, ras.ex: %d, ras.ey: %d", ex, ey, worker.invalid, worker.ex, worker.ey));
      /* All cells that are on the left of the clipping region go to the */
      /* min_ex - 1 horizontal position.                                 */
      ey -= worker.min_ey;
      if (ex > worker.max_ex) {
        ex = worker.max_ex;
      }
      ex -= worker.min_ex;
      if (ex < 0) {
        ex = -1;
      }
      /* are we moving to a different cell ? */
      if (ex != worker.ex || ey != worker.ey) {
        /* record the current one if it is valid */
        if (!worker.invalid) {
          gray_record_cell(worker);
Debug(0, DBG_RENDER, TAG, String.format("gray_set_cell after call gray_record_cell"));
        }
        worker.area  = 0;
        worker.cover = 0;
      }
      worker.ex = ex;
      worker.ey = ey;
      worker.invalid = (ey >= worker.count_ey || ex >= worker.count_ex);
Debug(0, DBG_RENDER, TAG, String.format("gray_set_cell end"));
    }

    /* =====================================================================
     *    gray_start_cell
     *
     * =====================================================================
     */
    public static void gray_start_cell(grayTWorker worker, long ex, long ey) {
Debug(0, DBG_RENDER, TAG, String.format("gray_start_cell: ex: %d, ey: %d", ex, ey));

      if (ex > worker.max_ex) {
        ex = (long)(worker.max_ex);
      }
      if (ex < worker.min_ex) {
        ex = (long)(worker.min_ex - 1);
      }
      worker.area = 0;
      worker.cover = 0;
      worker.ex = ex - worker.min_ex;
      worker.ey = ey - worker.min_ey;
      worker.last_ey = FTGrayOutlineClassFuncs.SUBPIXELS(ey);
      worker.invalid = false;
      gray_set_cell(worker, ex, ey);
    }


    /* =====================================================================
     *    gray_render_scanline
     *
     * =====================================================================
     */
    public static void gray_render_scanline(grayTWorker worker, long ey, long x1, long y1, long x2, long y2) {
Debug(0, DBG_RENDER, TAG, "gray_render_scanline");
      long ex1;
      long ex2;
      long fx1;
      long fx2;
      long delta;
      long mod;
      long p;
      long first;
      long dx;
      int incr;

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

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

    /* =====================================================================
     *    gray_render_line
     *
     * =====================================================================
     */
    public static void gray_render_line(grayTWorker worker, long to_x, long to_y) {
      long ey1;
      long ey2;
      long fy1;
      long fy2;
      long mod;
      long dx;
      long dy;
      long x;
      long x2;
      long p;
      long first;
      int delta;
      int rem;
      int lift;
      int incr;

Debug(0, DBG_RENDER, TAG, String.format("gray_render_line: to_x: %d, to_y: %d", to_x, to_y));
      ey1 = FTGrayOutlineClassFuncs.TRUNC(worker.last_ey);
      ey2 = FTGrayOutlineClassFuncs.TRUNC(to_y);     /* if (ey2 >= ras.max_ey) ey2 = ras.max_ey-1; */
      fy1 = (long)(worker.y - worker.last_ey);
      fy2 = (long)(to_y - FTGrayOutlineClassFuncs.SUBPIXELS(ey2));
      dx = to_x - worker.x;
      dy = to_y - worker.y;
      /* XXX: we should do something about the trivial case where dx == 0, */
      /*      as it happens very often!                                    */

      /* perform vertical clipping */
      {
        long min;
        long max;

        min = ey1;
        max = ey2;
        if (ey1 > ey2) {
          min = ey2;
          max = ey1;
        }
        if (min >= worker.max_ey || max < worker.min_ey) {
          worker.x = to_x;
          worker.y = to_y;
          worker.last_ey = FTGrayOutlineClassFuncs.SUBPIXELS(ey2);
Debug(0, DBG_RENDER, TAG, "gray_render_line return 1");
          return;
        }
      }
      /* everything is on a single scanline */
      if (ey1 == ey2) {
        gray_render_scanline(worker, ey1, worker.x, fy1, to_x, fy2);
        worker.x = to_x;
        worker.y = to_y;
        worker.last_ey = FTGrayOutlineClassFuncs.SUBPIXELS(ey2);
Debug(0, DBG_RENDER, TAG, "gray_render_line return 2");
        return;
      }
      /* vertical line - avoid calling gray_render_scanline */
      incr = 1;
      if (dx == 0) {
        long ex = FTGrayOutlineClassFuncs.TRUNC(worker.x);
        long two_fx = (long)((worker.x - FTGrayOutlineClassFuncs.SUBPIXELS(ex)) << 1);
        long area;

        first = FTGrayOutlineClassFuncs.ONE_PIXEL();
        if (dy < 0) {
          first = 0;
          incr  = -1;
        }
        delta = (int)(first - fy1);
        worker.area  += (long)two_fx * delta;
        worker.cover += delta;
        ey1 += incr;
        gray_set_cell(worker, ex, ey1);
        delta = (int)(first + first - FTGrayOutlineClassFuncs.ONE_PIXEL());
        area = (long)two_fx * delta;
        while (ey1 != ey2) {
          worker.area += area;
          worker.cover += delta;
          ey1 += incr;
Debug(0, DBG_RENDER, TAG, "gray_render_line call gray_set_cell while");
          gray_set_cell(worker, ex, ey1);
        }
        delta = (int)(fy2 - FTGrayOutlineClassFuncs.ONE_PIXEL() + first);
        worker.area += (long)two_fx * delta;
        worker.cover += delta;
        worker.x = to_x;
        worker.y = to_y;
        worker.last_ey = FTGrayOutlineClassFuncs.SUBPIXELS(ey2);
Debug(0, DBG_RENDER, TAG, "gray_render_line return 3");
        return;
      }
      /* ok, we have to render several scanlines */
      p = (FTGrayOutlineClassFuncs.ONE_PIXEL() - fy1) * dx;
      first = FTGrayOutlineClassFuncs.ONE_PIXEL();
      incr = 1;
      if (dy < 0) {
        p = fy1 * dx;
        first = 0;
        incr = -1;
        dy = -dy;
      }
      delta = (int)(p / dy);
      mod = (int)(p % dy);
      if (mod < 0) {
        delta--;
        mod += (long)dy;
      }
      x = worker.x + delta;
Debug(0, DBG_RENDER, TAG, "gray_render_line call gray_render_scanline 1");
      gray_render_scanline(worker, ey1, worker.x, fy1, x, (long)first);
      ey1 += incr;
      gray_set_cell(worker, FTGrayOutlineClassFuncs.TRUNC(x), ey1);
      if (ey1 != ey2) {
        p = FTGrayOutlineClassFuncs.ONE_PIXEL() * dx;
        lift  = (int)(p / dy);
        rem   = (int)(p % dy);
        if (rem < 0) {
          lift--;
          rem += (int)dy;
        }
        mod -= (int)dy;
        while (ey1 != ey2) {
          delta = lift;
          mod += rem;
          if (mod >= 0) {
            mod -= (int)dy;
            delta++;
          }
          x2 = x + delta;
Debug(0, DBG_RENDER, TAG, "gray_render_line call gray_render_scanline 2");
          gray_render_scanline(worker, ey1, x,
                 (long)(FTGrayOutlineClassFuncs.ONE_PIXEL() - first), x2, (long)first );
          x = x2;
          ey1 += incr;
          gray_set_cell(worker, FTGrayOutlineClassFuncs.TRUNC(x), ey1);
        }
      }
Debug(0, DBG_RENDER, TAG, "gray_render_line call gray_render_scanline 3");
      gray_render_scanline(worker, ey1, x,
                 (long)(FTGrayOutlineClassFuncs.ONE_PIXEL() - first), to_x, fy2);
      worker.x = to_x;
      worker.y = to_y;
      worker.last_ey = FTGrayOutlineClassFuncs.SUBPIXELS(ey2);
Debug(0, DBG_RENDER, TAG, "gray_render_line end");
    }

    /* =====================================================================
     *    gray_split_conic
     *
     * =====================================================================
     */
    public static void gray_split_conic(ftbase.FTReference<ftbase.FTVectorRec[]> base_ref, int arcIdx) {
Debug(0, DBG_RENDER, TAG, "gray_split_conic");
      ftbase.FTVectorRec[] base = base_ref.Get();
      long a;
      long b;

      base[arcIdx + 4].x = base[arcIdx + 2].x;
      b = base[arcIdx + 1].x;
      a = base[arcIdx + 3].x = (base[arcIdx + 2].x + b) / 2;
      b = base[arcIdx + 1].x = (base[arcIdx + 0].x + b) / 2;
      base[arcIdx + 2].x = (a + b) / 2;
      base[arcIdx + 4].y = base[arcIdx + 2].y;
      b = base[arcIdx + 1].y;
      a = base[arcIdx + 3].y = (base[arcIdx + 2].y + b) / 2;
      b = base[arcIdx + 1].y = (base[arcIdx + 0].y + b) / 2;
      base[arcIdx + 2].y = (a + b) / 2;
      base_ref.Set(base);
    }

    /* =====================================================================
     *    gray_render_conic
     *
     * =====================================================================
     */
    public static void gray_render_conic(ftbase.FTVectorRec control, ftbase.FTVectorRec to, grayTWorker worker) {
      long dx;
      long dy;
      long min;
      long max;
      long y;
      int top;
      int level;
      int[] levels;
      ftbase.FTVectorRec[] arc;
      ftbase.FTReference<ftbase.FTVectorRec[]> arc_ref = new ftbase.FTReference<ftbase.FTVectorRec[]>();
      int arcIdx = 0;
      boolean doDraw = false;

Debug(0, DBG_RENDER, TAG, "gray_render_conic");
      levels = worker.lev_stack;
      arc = worker.bez_stack;
      arc[arcIdx + 0].x = FTGrayOutlineClassFuncs.UPSCALE(to.x);
      arc[arcIdx + 0].y = FTGrayOutlineClassFuncs.UPSCALE(to.y);
      arc[arcIdx + 1].x = FTGrayOutlineClassFuncs.UPSCALE(control.x);
      arc[arcIdx + 1].y = FTGrayOutlineClassFuncs.UPSCALE(control.y);
      arc[arcIdx + 2].x = worker.x;
      arc[arcIdx + 2].y = worker.y;
      top = 0;
      dx = ftbase.FTCalc.FT_ABS(arc[arcIdx + 2].x + arc[arcIdx + 0].x - 2 * arc[arcIdx + 1].x);
      dy = ftbase.FTCalc.FT_ABS(arc[arcIdx + 2].y + arc[arcIdx + 0].y - 2 * arc[arcIdx + 1].y);
      if (dx < dy) {
        dx = dy;
      }
      if (dx < FTGrayOutlineClassFuncs.ONE_PIXEL() / 4) {
        doDraw = true;
      }
      if (!doDraw) {
        /* short-cut the arc that crosses the current band */
        min = max = arc[arcIdx + 0].y;
        y = arc[arcIdx + 1].y;
        if (y < min) {
           min = y;
        }
        if (y > max) {
          max = y;
        }
        y = arc[arcIdx + 2].y;
        if (y < min) {
          min = y;
        }
        if (y > max) {
          max = y;
        }
        if (FTGrayOutlineClassFuncs.TRUNC(min) >= worker.max_ey || FTGrayOutlineClassFuncs.TRUNC(max) < worker.min_ey) {
          doDraw = true;
        }
      }
      if (!doDraw) {
        level = 0;
        do {
          dx >>= 2;
          level++;
        } while (dx > FTGrayOutlineClassFuncs.ONE_PIXEL() / 4);
        levels[0] = level;
      }
      do {
        if (!doDraw) {
          level = levels[top];
          if (level > 0) {
            arc_ref.Set(arc);
            gray_split_conic(arc_ref, arcIdx);
            arc = arc_ref.Get();
            arcIdx += 2;
            top++;
            levels[top] = levels[top - 1] = level - 1;
Debug(0, DBG_RENDER, TAG, String.format("gray_render_conic !doDraw continue level: %d", level));
            continue;
          }
        }
        doDraw = false;
Debug(0, DBG_RENDER, TAG, String.format("gray_render_conic call gray_render_line top: %d", top));

        gray_render_line(worker, arc[arcIdx + 0].x, arc[arcIdx + 0].y);
Debug(0, DBG_RENDER, TAG, String.format("gray_render_conic call after gray_render_line top: %d", top));
        top--;
        arcIdx -= 2;
      } while ( top >= 0 );
Debug(0, DBG_RENDER, TAG, String.format("gray_render_conic end top: %d", top));
    }

    /* =====================================================================
     *    gray_split_cubic
     *
     * =====================================================================
     */
    public static void gray_split_cubic(ftbase.FTReference<ftbase.FTVectorRec[]> base_ref, int arcIdx) {
Debug(0, DBG_RENDER, TAG, "gray_split_cubic");
      ftbase.FTVectorRec[] base = base_ref.Get();
      long a;
      long b;
      long c;
      long d;

      base[arcIdx + 6].x = base[arcIdx + 3].x;
      c = base[arcIdx + 1].x;
      d = base[arcIdx + 2].x;
      base[arcIdx + 1].x = a = (base[arcIdx + 0].x + c) / 2;
      base[arcIdx + 5].x = b = (base[arcIdx + 3].x + d) / 2;
      c = (c + d) / 2;
      base[arcIdx + 2].x = a = (a + c) / 2;
      base[arcIdx + 4].x = b = (b + c) / 2;
      base[arcIdx + 3].x = (a + b) / 2;
      base[arcIdx + 6].y = base[arcIdx + 3].y;
      c = base[arcIdx + 1].y;
      d = base[arcIdx + 2].y;
      base[arcIdx + 1].y = a = (base[arcIdx + 0].y + c) / 2;
      base[arcIdx + 5].y = b = (base[arcIdx + 3].y + d) / 2;
      c = (c + d) / 2;
      base[arcIdx + 2].y = a = (a + c) / 2;
      base[arcIdx + 4].y = b = (b + c) / 2;
      base[arcIdx + 3].y = (a + b) / 2;
      base_ref.Set(base);
    }

    /* =====================================================================
     *    gray_render_cubic
     *
     * =====================================================================
     */
    public static void gray_render_cubic(ftbase.FTVectorRec control1, ftbase.FTVectorRec control2, ftbase.FTVectorRec to, grayTWorker worker) {
      ftbase.FTVectorRec[] arc;
      ftbase.FTReference<ftbase.FTVectorRec[]> arc_ref = new ftbase.FTReference<ftbase.FTVectorRec[]>();
      int arcIdx = 0;
      long min;
      long max;
      long y;
      boolean noSplit = false;

Debug(0, DBG_RENDER, TAG, "gray_render_cubic");
      arc = worker.bez_stack;
      arc[arcIdx + 0].x = FTGrayOutlineClassFuncs.UPSCALE(to.x);
      arc[arcIdx + 0].y = FTGrayOutlineClassFuncs.UPSCALE(to.y);
      arc[arcIdx + 1].x = FTGrayOutlineClassFuncs.UPSCALE(control2.x);
      arc[arcIdx + 1].y = FTGrayOutlineClassFuncs.UPSCALE(control2.y);
      arc[arcIdx + 2].x = FTGrayOutlineClassFuncs.UPSCALE(control1.x);
      arc[arcIdx + 2].y = FTGrayOutlineClassFuncs.UPSCALE(control1.y);
      arc[arcIdx + 3].x = worker.x;
      arc[arcIdx + 3].y = worker.y;
      /* Short-cut the arc that crosses the current band. */
      min = max = arc[arcIdx + 0].y;
      y = arc[arcIdx + 1].y;
      if (y < min) {
        min = y;
      }
      if (y > max) {
        max = y;
      }
      y = arc[arcIdx + 2].y;
      if (y < min) {
        min = y;
      }
      if (y > max) {
        max = y;
      }
      y = arc[arcIdx + 3].y;
      if (y < min) {
        min = y;
      }
      if (y > max) {
        max = y;
      }
      if (FTGrayOutlineClassFuncs.TRUNC(min) >= worker.max_ey || FTGrayOutlineClassFuncs.TRUNC(max) < worker.min_ey) {
Debug(0, DBG_RENDER, TAG, String.format("gray_render_cubic call gray_render_line"));
        gray_render_line(worker, arc[arcIdx + 0].x, arc[arcIdx + 0].y);
        if (arc == worker.bez_stack) {
          return;
        }
        arcIdx -= 3;
      }
      for (;;) {
        /* Decide whether to split or draw. See `Rapid Termination          */
        /* Evaluation for Recursive Subdivision of Bezier Curves' by Thomas */
        /* F. Hain, at                                                      */
        /* http://www.cis.southalabama.edu/~hain/general/Publications/Bezier/Camera-ready%20CISST02%202.pdf */

        noSplit = false;
        {
          long dx;
          long dy;
          long dx_;
          long dy_;
          long dx1;
          long dy1;
          long dx2;
          long dy2;
          long L;
          long s;
          long s_limit;

          /* dx and dy are x and y components of the P0-P3 chord vector. */
          dx = arc[arcIdx + 3].x - arc[arcIdx + 0].x;
          dy = arc[arcIdx + 3].y - arc[arcIdx + 0].y;
          /* L is an (under)estimate of the Euclidean distance P0-P3.       */
          /*                                                                */
          /* If dx >= dy, then r = sqrt(dx^2 + dy^2) can be overestimated   */
          /* with least maximum error by                                    */
          /*                                                                */
          /*   r_upperbound = dx + (sqrt(2) - 1) * dy  ,                    */
          /*                                                                */
          /* where sqrt(2) - 1 can be (over)estimated by 107/256, giving an */
          /* error of no more than 8.4%.                                    */
          /*                                                                */
          /* Similarly, some elementary calculus shows that r can be        */
          /* underestimated with least maximum error by                     */
          /*                                                                */
          /*   r_lowerbound = sqrt(2 + sqrt(2)) / 2 * dx                    */
          /*                  + sqrt(2 - sqrt(2)) / 2 * dy  .               */
          /*                                                                */
          /* 236/256 and 97/256 are (under)estimates of the two algebraic   */
          /* numbers, giving an error of no more than 8.1%.                 */
          dx_ = ftbase.FTCalc.FT_ABS(dx);
          dy_ = ftbase.FTCalc.FT_ABS(dy);
          /* This is the same as                     */
          /*                                         */
          /*   L = ( 236 * FT_MAX( dx_, dy_ )        */
          /*       + 97 * FT_MIN( dx_, dy_ ) ) >> 8; */
          L = (dx_ > dy_ ? 236 * dx_ +  97 * dy_ :  97 * dx_ + 236 * dy_) >> 8;
          /* Avoid possible arithmetic overflow below by splitting. */
          if (L > 32767) {
            arc_ref.Set(arc);
            gray_split_cubic(arc_ref, arcIdx);
            arc = arc_ref.Get();
            arcIdx += 3;
            continue;
          }
          /* Max deviation may be as much as (s/L) * 3/4 (if Hain's v = 1). */
          s_limit = L * (long)(FTGrayOutlineClassFuncs.ONE_PIXEL() / 6);
          /* s is L * the perpendicular distance from P1 to the line P0-P3. */
          dx1 = arc[arcIdx + 1].x - arc[arcIdx + 0].x;
          dy1 = arc[arcIdx + 1].y - arc[arcIdx + 0].y;
          s = ftbase.FTCalc.FT_ABS(dy * dx1 - dx * dy1);
          if (s > s_limit) {
            arc_ref.Set(arc);
            gray_split_cubic(arc_ref, arcIdx);
            arc = arc_ref.Get();
            arcIdx += 3;
            continue;
          }
          /* s is L * the perpendicular distance from P2 to the line P0-P3. */
          dx2 = arc[arcIdx + 2].x - arc[arcIdx + 0].x;
          dy2 = arc[arcIdx + 2].y - arc[arcIdx + 0].y;
          s = ftbase.FTCalc.FT_ABS(dy * dx2 - dx * dy2);
          if (s > s_limit) {
            arc_ref.Set(arc);
            gray_split_cubic(arc_ref, arcIdx);
            arc = arc_ref.Get();
            arcIdx += 3;
            continue;
          }
          /* Split super curvy segments where the off points are so far
             from the chord that the angles P0-P1-P3 or P0-P2-P3 become
             acute as detected by appropriate dot products. */
          if (dx1 * (dx1 - dx) + dy1 * (dy1 - dy) > 0 ||
               dx2 * (dx2 - dx) + dy2 * (dy2 - dy) > 0) {
            arc_ref.Set(arc);
            gray_split_cubic(arc_ref, arcIdx);
            arc = arc_ref.Get();
            arcIdx += 3;
            continue;
          }
          /* No reason to split. */
          noSplit = true;
        }
        if (! noSplit) {
          arc_ref.Set(arc);
          gray_split_cubic(arc_ref, arcIdx);
          arc = arc_ref.Get();
          arcIdx += 3;
          continue;
        }
Debug(0, DBG_RENDER, TAG, String.format("gray_render_cubic 2 call gray_render_line"));
        gray_render_line(worker, arc[arcIdx + 0].x, arc[arcIdx + 0].y);
        if (arc == worker.bez_stack) {
          return;
        }
        arcIdx -= 3;
        worker.bez_stack = arc;
      }
    }

    /* =====================================================================
     *    gray_compute_cbox
     *
     * =====================================================================
     */
    public static void gray_compute_cbox(grayTWorker worker) {
      ftbase.FTOutlineRec outline = worker.outline;
      ftbase.FTVectorRec vec;
      int vecIdx = 0;
      int limit = outline.n_points;

Debug(0, DBG_RENDER, TAG, String.format("gray_compute_cbox"));
      if (outline.n_points <= 0) {
        worker.min_ex = worker.max_ex = 0;
        worker.min_ey = worker.max_ey = 0;
        return;
      }
      worker.min_ex = worker.max_ex = outline.points[vecIdx].x;
      worker.min_ey = worker.max_ey = outline.points[vecIdx].y;
Debug(0, DBG_RENDER, TAG, String.format("cbox01: %d %d %d %d", worker.min_ex, worker.min_ey, worker.max_ex, worker.max_ey));
      vecIdx++;
      for ( ; vecIdx < limit; vecIdx++) {
        vec = outline.points[vecIdx];
        long x = vec.x;
        long y = vec.y;

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

}

Added ftraster/FTGrayRasterClassFuncs.java.























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    FTGrayRasterFuncs                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTGrayRasterClassFuncs extends FTRasterFuncs {
    private static int oid = 0;

    private int id;
    private static String TAG = "FTGrayRasterFuncs";
    
    public static ftbase.FTInstanceMethod gray_render_span;

    /* ==================== FTGrayRasterClassFuncs ========================= */
    public FTGrayRasterClassFuncs() {
      oid++;
      id = oid;
      glyph_format = FT_GLYPH_FORMAT_OUTLINE;
      String class_name = "org.apwtcl.gles20.truetype.FTGrayRasterFuncs";
      raster_new = new ftbase.FTInstanceMethod(class_name, "gray_raster_new", 1);
      raster_reset = new ftbase.FTInstanceMethod(class_name, "gray_raster_reset", 1);
      raster_set_mode = null;
      raster_render = new ftbase.FTInstanceMethod(class_name, "gray_raster_render", 1);
      raster_done = new ftbase.FTInstanceMethod(class_name, "gray_raster_done", 1);
      gray_render_span = new ftbase.FTInstanceMethod(class_name, "gray_render_span", 1);
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftraster/FTGrayRasterFuncs.java.

















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
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
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;


  /* ===================================================================== */
  /*    FTGrayRasterFuncs                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTGrayRasterFuncs extends ftbase.FTDebug {
    private static int oid = 0;

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

    /* ==================== FTGrayRasterFuncs ================================== */
    public FTGrayRasterFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     *    gray_raster_new
     *
     * =====================================================================
     */
    public static int gray_raster_new(Object ... args) {
Debug(0, DBG_RENDER, TAG, "gray_raster_new");
      ftbase.FTReference<grayTRaster> raster_ref = (ftbase.FTReference<grayTRaster>)args[0];
      int error = 0;
      grayTRaster raster = null;
      raster_ref.Set(null);
      raster = new grayTRaster();
      if (raster != null) {
        raster_ref.Set(raster);
      }
      return error;
    }

    /* =====================================================================
     *    gray_raster_reset
     *
     * =====================================================================
     */
    public static int gray_raster_reset(Object ... args) {
      ftbase.FTReference<FTRasterRec> raster_ref = (ftbase.FTReference<FTRasterRec>)args[0];
      grayTRaster raster = new grayTRaster(raster_ref.Get());
      byte[] pool_base = (byte[])args[1];
      long pool_size = (long)args[2];
      int error = 0;

Debug(0, DBG_RENDER, TAG, "gray_raster_reset");
      if (raster != null) {
        if (pool_base != null) {
          grayTWorker worker =  new grayTWorker();
          raster.buffer = pool_base;
          raster.buffer_size = (long)pool_size;
//          raster.band_size = (int)raster.buffer_size / sizeof(TCell) * 8;
          raster.band_size = (int)raster.buffer_size / 20;  // FIXME!!!
          raster.worker = worker;
        } else {
          raster.buffer = null;
          raster.buffer_size = 0;
          raster.worker = null;
        }
        raster_ref.Set((FTRasterRec)raster);
      }
      return error;
    }

    /* =====================================================================
     *    gray_raster_render
     *
     * =====================================================================
     */
    public static int gray_raster_render(Object ... args) {
Debug(0, DBG_RENDER, TAG, "gray_raster_render");
      grayTRaster raster = (grayTRaster)args[0];
      FTRasterParams params = (FTRasterParams)args[1];
      ftbase.FTOutlineRec outline = (ftbase.FTOutlineRec)params.source;
      ftbase.FTBitmapRec target_map = params.target;
      grayTWorker worker;

      if (raster == null || raster.buffer == null || raster.buffer_size == 0) {
        return ftbase.FTError.RENDER_INVALID_ARGUMENT;
      }
      if (outline == null) {
        return ftbase.FTError.RENDER_INVALID_OUTLINE;
      }
      /* return immediately if the outline is empty */
      if (outline.n_points == 0 || outline.n_contours <= 0) {
        return 0;
      }
      if (outline.contours == null || outline.points== null) {
        return ftbase.FTError.RENDER_INVALID_OUTLINE;
      }
      if (outline.n_points != outline.contours[outline.n_contours - 1] + 1) {
        return ftbase.FTError.RENDER_INVALID_OUTLINE;
      }
      worker = raster.worker;
      /* if direct mode is not set, we must have a target bitmap */
      if ((params.flags & FTRasterParams.FT_RASTER_FLAG_DIRECT) == 0) {
        if (target_map == null) {
          return ftbase.FTError.RENDER_INVALID_ARGUMENT;
        }
        /* nothing to do */
        if (target_map.width == 0|| target_map.rows == 0) {
          return 0;
        }
        if (target_map.buffer == null) {
          return ftbase.FTError.RENDER_INVALID_ARGUMENT;
        }
      }
      /* this version does not support monochrome rendering */
      if ((params.flags & FTRasterParams.FT_RASTER_FLAG_AA) == 0) {
        return ftbase.FTError.RENDER_INVALID_MODE;
      }
      /* compute clipping box */
      if ((params.flags & FTRasterParams.FT_RASTER_FLAG_DIRECT) == 0) {
        /* compute clip box from target pixmap */
        worker.clip_box.xMin = 0L;
        worker.clip_box.yMin = 0L;
        worker.clip_box.xMax = (long)target_map.width;
        worker.clip_box.yMax = (long)target_map.rows;
      } else {
        if ((params.flags & FTRasterParams.FT_RASTER_FLAG_CLIP) != 0) {
          worker.clip_box = params.clip_box;
        } else {
          worker.clip_box.xMin = -32768L;
          worker.clip_box.yMin = -32768L;
          worker.clip_box.xMax = 32767L;
          worker.clip_box.yMax = 32767L;
        }
      }
      gray_init_cells(worker, raster.buffer, raster.buffer_size);
      worker.outline = outline;
      worker.num_cells = 0;
      worker.invalid = true;
      worker.band_size = raster.band_size;
      worker.num_gray_spans = 0;
      if ((params.flags & FTRasterParams.FT_RASTER_FLAG_DIRECT) != 0) {
        worker.render_span = params.gray_spans;
        worker.render_span_data = params.user;
      } else {
        worker.target = target_map;
        worker.render_span = FTGrayRasterClassFuncs.gray_render_span;
        worker.render_span_data = worker;
      }
      return gray_convert_glyph(worker);
    }

    /* =====================================================================
     *    gray_raster_done
     *
     * =====================================================================
     */
    public static int gray_raster_done(Object ... args) {
Debug(0, DBG_RENDER, TAG, "gray_raster_done");
      int error = 0;
      // nothing to do
      return error;
    }

    /* =====================================================================
     *    gray_render_span
     *
     * =====================================================================
     */
    public static void gray_render_span(Object ... args) {
      int y = (int)args[0];
      int count = (int)args[1];
      FTSpan[] spans = (FTSpan[])args[2];
      int spansIdx = 0;
      grayTWorker worker = (grayTWorker)args[3];
//      char[] p; // map.buffer
      int pIdx;
      int qIdx;
      ftbase.FTBitmapRec map = worker.target;
Debug(0, DBG_RENDER, TAG, String.format("gray_render_span y: %d, count: %d", y, count));

      /* first of all, compute the scanline offset */
      pIdx = 0 - y * map.pitch;
      if (map.pitch >= 0) {
        pIdx += ((map.rows - 1) * map.pitch);
      }
      for (; count > 0; count--, spansIdx++) {
        byte coverage = spans[spansIdx].coverage;

        if (coverage != 0) {
          /* For small-spans it is faster to do it by ourselves than
           * calling `memset'.  This is mainly due to the cost of the
           * function call.
           */
          if (spans[spansIdx].len >= 8) {
            int lgth = spans[spansIdx].len;
            int i;
            for (i = spans[spansIdx].x; i < spans[spansIdx].x + lgth; i++) {
              map.buffer[i] = (byte)coverage;	
            }
//            FT_MEM_SET(p + spans[spansIdx].x, (char)coverage, spans[spansIdx].len);
          } else {
//            char*  q = p + spans.x;
            qIdx = pIdx + spans[spansIdx].x;

            switch (spans[spansIdx].len) {
            case 7: map.buffer[qIdx++] = (byte)coverage;
            case 6: map.buffer[qIdx++] = (byte)coverage;
            case 5: map.buffer[qIdx++] = (byte)coverage;
            case 4: map.buffer[qIdx++] = (byte)coverage;
            case 3: map.buffer[qIdx++] = (byte)coverage;
            case 2: map.buffer[qIdx++] = (byte)coverage;
            case 1: map.buffer[qIdx] = (byte)coverage;
            default:
              ;
            }
          }
        }
      }
    }

    /* =====================================================================
     *    gray_init_cells
     *
     * =====================================================================
     */
    public static void gray_init_cells(Object ... args) {
Debug(0, DBG_RENDER, TAG, "+++ gray_init_cells");
      grayTWorker worker = (grayTWorker)args[0];
      byte[] buffer = (byte[])args[1];
      long byte_size = (long)args[2];

      worker.buffer = buffer;
      worker.buffer_size = byte_size;
      worker.ycells = new TCell[(int)byte_size / 10];
      worker.cells = null;
      worker.max_cells = 0;
      worker.num_cells = 0;
      worker.area = 0;
      worker.cover = 0;
      worker.invalid = true;
    }

    /* =====================================================================
     *    gray_convert_glyph_inner
     *
     * =====================================================================
     */
    public static int gray_convert_glyph_inner(grayTWorker worker) {
Debug(0, DBG_RENDER, TAG, "gray_convert_glyph_inner");
      FTGrayOutlineClassFuncs func_interface = new FTGrayOutlineClassFuncs();
      ftbase.FTReference<ftbase.FTOutlineRec> outline_ref = new ftbase.FTReference<ftbase.FTOutlineRec>();
      int error = 0;

//      if (ft_setjmp(ras.jump_buffer) == 0) {
        outline_ref.Set(worker.outline);
        error = ftbase.FTOutlineRec.FTOutlineDecompose(outline_ref, (ftbase.FTOutlineFuncs)func_interface, worker);
        worker.outline = outline_ref.Get();
        FTGrayOutlineFuncs.gray_record_cell(worker);
//      } else {
//        error = FT_THROW( Memory_Overflow );
//      }
      return error;
    }

    /* =====================================================================
     *    gray_hline
     *
     * =====================================================================
     */
    public static void gray_hline(grayTWorker worker, long x, long y, long area, long acount) {
Debug(0, DBG_RENDER, 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) */
      /*                                                           */
      coverage = (int)(area >> (FTGrayOutlineClassFuncs.PIXEL_BITS * 2 + 1 - 8));
                                                      /* use range 0..256 */
      if (coverage < 0) {
        coverage = -coverage;
      }
      if ((worker.outline.flags & ftbase.FTOutlineRec.FT_OUTLINE_EVEN_ODD_FILL) != 0) {
        coverage &= 511;
        if (coverage > 256) {
          coverage = 512 - coverage;
        } else {
          if (coverage == 256) {
            coverage = 255;
          }
        }
      } else {
        /* normal non-zero winding rule */
        if (coverage >= 256) {
          coverage = 255;
        }
      }
      y += (long)worker.min_ey;
      x += (long)worker.min_ex;
      /* FT_Span.x is a 16-bit short, so limit our coordinates appropriately */
      if (x >= 32767) {
        x = 32767;
      }
      /* FT_Span.y is an integer, so limit our coordinates appropriately */
      if (y >= 0xFFFF) {
        y = 0xFFFF;
      }
Debug(0, DBG_RENDER, TAG, String.format("x: %d, y: %d, coverage: %x", x, y, coverage));
      if (coverage != 0) {
        int count;
        FTSpan span = null;

        /* see whether we can add this span to the current list */
        count = worker.num_gray_spans;
        spanIdx = count - 1;
        if (count > 0) {
//for( int j = 0; j < worker.num_gray_spans; j++) {
//  span = worker.gray_spans[j];
//  System.out.println(String.format("j: %d x: %d len: %d coverage: %x", j, span.x, span.len, span.coverage));
//}
          span = worker.gray_spans[count - 1];
//System.out.println(String.format("count a: %d, span.x: %d, len: %d, coverage: %x, worker.span_y: %d, y: %d, x: %d, span.coverage: %x, coverage: %x", count, span.x, span.len, span.coverage, worker.span_y, y, x, span.coverage & 0xFF, coverage));        
        } else {
//System.out.println(String.format("count b: %d, worker.span_y: %d, y: %d, x: %d, coverage: %x", count, worker.span_y, y, x, coverage));
        }
        if (count > 0 && worker.span_y == y && (int)span.x + span.len == (int)x &&
             (span.coverage & 0xFF) == coverage) {
//System.out.println(String.format("span.len: %d, acount: %d", span.len, acount));          
          span.len = (short)(span.len + acount);
          worker.gray_spans[count - 1] = span;
//System.out.println("gray_hline END 1");      
          return;
        }
//System.out.println(String.format("worker.span_y: %d, y: %d, count: %d", worker.span_y, y, count));
        if (worker.span_y != y || count >= FTSpan.FT_MAX_GRAY_SPANS) {
          if (worker.render_span != null && count > 0) {
            worker.render_span.callClassMethod(worker.span_y, count, worker.gray_spans,
                             worker.render_span_data);
          }
          if (count > 0) {
//int j;
//for(j = 0; j < worker.num_gray_spans; j++) {
//System.out.println(String.format("++ j: %d, span.x: %d, span.len: %d", j, worker.gray_spans[j].x, worker.gray_spans[j].len));  
//}
          }
          if (count > 0) {
            int  n;
            StringBuffer str = new StringBuffer();

            str.append(String.format("y = %3d ", worker.span_y));
            for (n = 0; n < count; n++) {
              str.append(String.format("  [%d..%d]:0x%02x ",
                  worker.gray_spans[n].x, worker.gray_spans[n].x + worker.gray_spans[n].len - 1, worker.gray_spans[n].coverage));
            }
            ftbase.FTTrace.Trace(7, TAG, str.toString());
          }
          worker.num_gray_spans = 0;
          worker.span_y = (int)y;
          count = 0;
          spanIdx = 0;
        } else {
            spanIdx++;
        }
        /* add a gray span to the current list */
        worker.gray_spans[spanIdx].x = (short)x;
        worker.gray_spans[spanIdx].len = (short)acount;
        worker.gray_spans[spanIdx].coverage = (byte)coverage;
//System.out.println(String.format("span: %d x: %d,  len: %d, coverage: 0x%02x", spanIdx, x, acount, coverage));        
        worker.num_gray_spans++;
      }
Debug(0, DBG_RENDER, TAG, "gray_hline END 2");
    }

    /* =====================================================================
     *    gray_sweep
     *
     * =====================================================================
     */
    public static void gray_sweep(grayTWorker worker, ftbase.FTBitmapRec target) {
Debug(0, DBG_RENDER, TAG, "gray_sweep");
      int  yindex;

      if (worker.num_cells == 0) {
        return;
      }
      worker.num_gray_spans = 0;
      ftbase.FTTrace.Trace(7, TAG, "gray_sweep: start "+worker.ycount);
      for (yindex = 0; yindex < worker.ycount; yindex++) {
        TCell cell  = worker.ycells[yindex];
        long cover = 0L;
        long x = 0L;

        for ( ; cell != null; cell = cell.next) {
          long area;

//System.out.println(String.format("cell->next: %d", cell.next == null ? -1 : cell.next.self_idx));          
Debug(0, DBG_RENDER, TAG, String.format("gray_sweep 1: cell.x: %d x: %d,  yindex: %d, cover: %x", cell.x, x, yindex, cover));
          if (cell.x > x && cover != 0) {
            gray_hline(worker, x, yindex, cover * (FTGrayOutlineClassFuncs.ONE_PIXEL() * 2), cell.x - x );
          }
          cover += cell.cover;
          area = cover * (FTGrayOutlineClassFuncs.ONE_PIXEL() * 2) - cell.area;
          if (area != 0 && cell.x >= 0) {
            gray_hline(worker, cell.x, yindex, area, 1 );
          }
          x = cell.x + 1;
        }
        if (cover != 0) {
          gray_hline(worker, x, yindex, cover * (FTGrayOutlineClassFuncs.ONE_PIXEL() * 2), worker.count_ex - x);
        }
      }
      if (worker.render_span != null && worker.num_gray_spans > 0) {
        worker.render_span.callClassMethod(worker.span_y, worker.num_gray_spans,
                 worker.gray_spans, worker.render_span_data);
      }
      if (worker.num_gray_spans > 0) {
        FTSpan span;
        int spanIdx = 0;
        int n;
        StringBuffer str = new StringBuffer("");

        str.append(String.format("y = %3d ", worker.span_y));
        for (n = 0; n < worker.num_gray_spans; n++, spanIdx++) {
          span = worker.gray_spans[spanIdx];
          str.append(String.format("  [%d..%d]:0x%02x ",
              span.x, span.x + span.len - 1, span.coverage & 0xFF));
        }
        ftbase.FTTrace.Trace(7, TAG, str.toString());
      }
      ftbase.FTTrace.Trace(7, TAG, "gray_sweep: end");
    }

    /* =====================================================================
     *    gray_convert_glyph
     *
     * =====================================================================
     */
    public static int gray_convert_glyph(grayTWorker worker) {
Debug(0, DBG_RENDER, TAG, "gray_convert_glyph");
      int error = 0;
      grayTBand[] bands = new grayTBand[40];
      int bandIdx = 0;
      int n;
      int i;
      int num_bands;
      long min;
      long max;
      long max_y;
      ftbase.FTBBoxRec clip;
      boolean reduceBands = false;

      for (i = 0; i < 40; i++) {
        bands[i] = new grayTBand();
      }

      /* Set up state in the raster object */
      FTGrayOutlineFuncs.gray_compute_cbox(worker);
      /* clip to target bitmap, exit if nothing to do */
      clip = worker.clip_box;
      if (worker.max_ex <= clip.xMin || worker.min_ex >= clip.xMax ||
           worker.max_ey <= clip.yMin || worker.min_ey >= clip.yMax) {
        return error;
      }
      if (worker.min_ex < clip.xMin) {
        worker.min_ex = clip.xMin;
      }
      if (worker.min_ey < clip.yMin) {
        worker.min_ey = clip.yMin;
      }
      if (worker.max_ex > clip.xMax) {
        worker.max_ex = clip.xMax;
      }
      if (worker.max_ey > clip.yMax) {
        worker.max_ey = clip.yMax;
      }
      worker.count_ex = worker.max_ex - worker.min_ex;
      worker.count_ey = worker.max_ey - worker.min_ey;
      /* set up vertical bands */
      num_bands = (int)((worker.max_ey - worker.min_ey) / worker.band_size);
      if (num_bands == 0) {
        num_bands = 1;
      }
      if (num_bands >= 39) {
        num_bands = 39;
      }
      worker.band_shoot = 0;
      min = worker.min_ey;
      max_y = worker.max_ey;
      for (n = 0; n < num_bands; n++, min = max) {
        max = min + worker.band_size;
        if (n == num_bands - 1 || max > max_y) {
          max = max_y;
        }
        bands[0].min = (short)min;
        bands[0].max = (short)max;
        bandIdx = 0;
        while (bandIdx >= 0) {
          long bottom;
          long top;
          long middle;
          {
            long cells_max;
            int yindex;
            long cell_start;
            long cell_end;
            long cellsIdx = 0;

//            worker.ycells = (TCell[])worker.buffer;
            worker.ycount = bands[bandIdx].max - bands[bandIdx].min;
            worker.ycells = new TCell[(int)worker.ycount];
            cell_start = 0;
            cell_end = 1024;             
//            cell_start = TCellSize * worker.ycount;
//            cell_mod = cell_start % TCellSize;
//            if (cell_mod > 0) {
//              cell_start += TCellSize - cell_mod;
//            }
//            cell_end = worker.buffer_size;
//            cell_end -= cell_end % TCellSize;
            cells_max = cell_end;
            cellsIdx = cell_start;
            cellsIdx = 0;
            worker.cells = new TCell[(int)cells_max];
            for (int j = 0; j < cells_max; j++) {
              worker.cells[j] = new TCell();
            }
            if (cellsIdx >= cells_max) {
              reduceBands = true;
            }
            if (!reduceBands) {
              worker.max_cells = (int)(cells_max - cellsIdx);
              if (worker.max_cells < 2) {
                reduceBands = true;
              }
            }
            if (!reduceBands) {
              for (yindex = 0; yindex < worker.ycount; yindex++) {
                worker.ycells[yindex] = null;
              }
            }
          }
          if (!reduceBands) {
            worker.num_cells = 0;
            worker.invalid = true;
            worker.min_ey = bands[bandIdx].min;
            worker.max_ey = bands[bandIdx].max;
            worker.count_ey = bands[bandIdx].max - bands[bandIdx].min;
            error = gray_convert_glyph_inner(worker);
            if (error == 0) {
              gray_sweep(worker, worker.target);
              bandIdx--;
              continue;
            } else {
              if (error != ftbase.FTError.RASTER_MEMORY_OVERFLOW) {
                return error;
              }
            }
          }
          reduceBands = false;
          /* render pool overflow; we will reduce the render band by half */
          bottom = bands[bandIdx].min;
          top = bands[bandIdx].max;
          middle = bottom + ((top - bottom) >> 1);
          /* This is too complex for a single scanline; there must */
          /* be some problems.                                     */
          if (middle == bottom) {
            ftbase.FTTrace.Trace(7, TAG, "gray_convert_glyph: rotten glyph");
            return ftbase.FTError.GLYPH_ROTTEN_GLYPH;
          }
          if (bottom-top >= worker.band_size) {
            worker.band_shoot++;
          }
          bands[bandIdx + 1].min = (short)bottom;
          bands[bandIdx + 1].max = (short)middle;
          bands[bandIdx + 0].min = (short)middle;
          bands[bandIdx + 0].max = (short)top;
          bandIdx++;
        }
      }
      if (worker.band_shoot > 8 && worker.band_size > 16) {
        worker.band_size = worker.band_size / 2;
      }
      return error;
    }

}

Added ftraster/FTRaster1RendererClass.java.















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    FTRaster1RendererClass                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTRaster1RendererClass extends ftbase.FTRendererClassRec {
    private static int oid = 0;

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



    /* ==================== FTRaster1RendererClass ================================== */
    public FTRaster1RendererClass() {
      super();
      oid++;
      id = oid;

      module_flags = (long)ftbase.FTModuleClassRec.FT_MODULE_RENDERER;  /* a renderer */
      module_type = FT_MODULE_TYPE_FT_RENDERER_REC;
      module_name = "raster1";     /* driver name */
      module_version = 0x10000L;   /* driver version 1.0 */
      module_requires = 0x20000L;  /* driver requires FreeType 2.0 or higher */
      module_interface = null;     /* module specific interface */

      String class_name = "org.apwtcl.gles20.truetype.FTRaster1RendererFuncs";
      module_init = new ftbase.FTInstanceMethod(class_name, "ft_raster1_init", 1);
      module_done = null;
      get_interface = null;

      glyph_format = FT_GLYPH_FORMAT_OUTLINE;
      render_glyph = new ftbase.FTInstanceMethod(class_name, "ft_raster1_render", 1);
      transform_glyph = new ftbase.FTInstanceMethod(class_name, "ft_raster1_transform", 1);
      get_glyph_cbox = new ftbase.FTInstanceMethod(class_name, "ft_raster1_get_cbox", 1);
      set_mode = new ftbase.FTInstanceMethod(class_name, "ft_raster1_set_mode", 1);
      raster_class = new FTStandardRasterClass();
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftraster/FTRaster1RendererFuncs.java.











































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

import android.util.Log;

  /* ===================================================================== */
  /*    FTRaster1RendererFuncs                                                        */
  /*                                                                       */
  /* ===================================================================== */

public class FTRaster1RendererFuncs extends ftbase.FTDebug {
    private static int oid = 0;

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

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * ft_raster1_init
     * =====================================================================
     */
    public static int ft_raster1_init(Object ... args) {
      ftbase.FTModuleRec module = (ftbase.FTModuleRec)args[0];
      ftbase.FTLibraryRec library = module.library;
      ftbase.FTRendererRec render = (ftbase.FTRendererRec)module;
Debug(0, DBG_INIT, TAG, "ft_raster1_init");
      ftbase.FTReference<FTRasterRec> raster_ref = new ftbase.FTReference<FTRasterRec>();
      raster_ref.Set(render.raster);
      render.clazz.raster_class.raster_reset.callClassMethod(raster_ref,
              library.raster_pool, library.raster_pool_size);
      render.raster = raster_ref.Get();
      return ftbase.FTError.INTERP_ERR_OK;
    }

    /* =====================================================================
     * ft_raster1_render
     * =====================================================================
     */
    public static int ft_raster1_render(Object ... args) {
      ftbase.FTRendererRec render = (ftbase.FTRendererRec) args[0];
      ftbase.FTGlyphSlotRec slot = (ftbase.FTGlyphSlotRec)args[1];
      long  mode = (long)args[2];
      ftbase.FTVectorRec origin = (ftbase.FTVectorRec)args[3];

      int error = 0;
      ftbase.FTOutlineRec outline;
      ftbase.FTBBoxRec cbox = new ftbase.FTBBoxRec();
      Integer width;
      Integer height;
      Integer pitch;
      ftbase.FTBitmapRec bitmap;
      FTRasterParams params = new FTRasterParams();
      ftbase.FTReference<ftbase.FTBBoxRec> cbox_ref = new ftbase.FTReference<ftbase.FTBBoxRec>();

      /* check glyph image format */
      if (slot.format != render.glyph_format) {
        error = ftbase.FTError.GLYPH_INVALID_ARGUMENT;
        return error;
      }
      /* check rendering mode */
      if (mode != FT_RENDER_MODE_MONO) {
        /* raster1 is only capable of producing monochrome bitmaps */
        if (render.module_clazz.module_name == "raster1") {
          return ftbase.FTError.GLYPH_CANNOT_RENDER_GLYPH;
        }
      } else {
        /* raster5 is only capable of producing 5-gray-levels bitmaps */
        if (render.module_clazz.module_name == "raster5")
          return ftbase.FTError.GLYPH_CANNOT_RENDER_GLYPH;
      }
      outline = slot.outline;
      /* translate the outline to the new origin if needed */
      ftbase.FTReference<ftbase.FTOutlineRec> outline_ref = new ftbase.FTReference<ftbase.FTOutlineRec>();
      if (origin != null) {
        outline_ref.Set(outline);
        ftbase.FTOutlineRec.FTOutlineTranslate(outline_ref, origin.x, origin.y);
        outline = outline_ref.Get();
      }
      /* compute the control box, and grid fit it */
      outline_ref.Set(outline);
      cbox_ref.Set(cbox);
      ftbase.FTOutlineRec.FTOutlineGetCBox(outline_ref, cbox_ref);
      cbox = cbox_ref.Get();
      outline = outline_ref.Get();
      /* undocumented but confirmed: bbox values get rounded */
      cbox.xMin = ftbase.FTCalc.FT_PIX_ROUND(cbox.xMin);
      cbox.yMin = ftbase.FTCalc.FT_PIX_ROUND(cbox.yMin);
      cbox.xMax = ftbase.FTCalc.FT_PIX_ROUND(cbox.xMax);
      cbox.yMax = ftbase.FTCalc.FT_PIX_ROUND(cbox.yMax);
      width  = (int)((cbox.xMax - cbox.xMin) >> 6);
      height = (int)((cbox.yMax - cbox.yMin) >> 6);
      if (width > 0xFFFF || height > 0xFFFF) {
        error = ftbase.FTError.GLYPH_INVALID_ARGUMENT;
        return error;
      }
      bitmap = slot.bitmap;
      /* release old bitmap buffer */
      if ((slot.internal.flags & ftbase.FTGlyphLoaderFlags.FT_GLYPH_OWN_BITMAP) != 0) {
//        FT_FREE(bitmap.buffer);
        slot.internal.flags &= ~ftbase.FTGlyphLoaderFlags.FT_GLYPH_OWN_BITMAP;
      }
      /* allocate new one, depends on pixel format */
      if ((mode & FT_RENDER_MODE_MONO) == 0) {
        /* we pad to 32 bits, only for backwards compatibility with FT 1.x */
        pitch = ftbase.FTCalc.FT_PAD_CEIL((long)width, 4).intValue();
        bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
        bitmap.num_grays = 256;
      } else {
        pitch = ((width + 15) >> 4) << 1;
        bitmap.pixel_mode = FT_PIXEL_MODE_MONO;
      }
      bitmap.width = width;
      bitmap.rows  = height;
      bitmap.pitch = pitch;
      // realloc cout = pitch, item_size ) height
      bitmap.buffer = new byte[pitch * height]; 
      if (bitmap.buffer == null) {
        return error;
      }
      slot.internal.flags |= ftbase.FTGlyphLoaderFlags.FT_GLYPH_OWN_BITMAP;
Debug(0, DBG_INIT, TAG, String.format("cbox_xMin: %d %dn", -cbox.xMin, -cbox.yMin));
      /* translate outline to render it into the bitmap */
      outline_ref.Set(outline);
      ftbase.FTOutlineRec.FTOutlineTranslate(outline_ref, -cbox.xMin, -cbox.yMin);
      outline = outline_ref.Get();
      /* set up parameters */
      params.target = bitmap;
      params.source = outline;
      params.flags  = 0;
      if (bitmap.pixel_mode == FT_PIXEL_MODE_GRAY) {
        params.flags |= FTRasterParams.FT_RASTER_FLAG_AA;
      }
      /* render outline into the bitmap */
      ftbase.FTReference<FTRasterRec> raster_ref = new ftbase.FTReference<FTRasterRec>();
      raster_ref.Set(render.raster);
      error = (int)render.raster_render.callClassMethod(raster_ref, params);
      render.raster = raster_ref.Get();
      outline_ref.Set(outline);
      ftbase.FTOutlineRec.FTOutlineTranslate(outline_ref, cbox.xMin, cbox.yMin);
      outline = outline_ref.Get();
      if (error != 0) {
        return error;
      }
      slot.format = FT_GLYPH_FORMAT_BITMAP;
      slot.bitmap_left = (int)(cbox.xMin >> 6);
      slot.bitmap_top = (int)(cbox.yMax >> 6);
      return error;
    }

    /* =====================================================================
     * ft_raster1_transform
     * =====================================================================
     */
    public static int ft_raster1_transform(Object ... args) {
      Log.w(TAG, "WARNING: ft_raster1_transform not yet implemented");
System.out.println("ft_raster1_transform not yet implemented!!");
      return 1;
    }

    /* =====================================================================
     * ft_raster1_get_cbox
     * =====================================================================
     */
    public static int ft_raster1_get_cbox(Object ... args) {
      Log.w(TAG, "WARNING: ft_raster1_get_cbox not yet implemented");
System.out.println("ft_raster1_get_cbox not yet implemented!!");
      return 1;
    }

    /* =====================================================================
     * ft_raster1_set_mode
     * =====================================================================
     */
    public static int ft_raster1_set_mode(Object ... args) {
      Log.w(TAG, "WARNING: ft_raster1_set_mode not yet implemented");
System.out.println("ft_raster1_set_mode not yet implemented!!");
      return 1;
    }

}

Added ftraster/FTRasterParams.java.











































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    FTRasterParams                                                          */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A structure to hold the arguments used by a raster's render        */
  /*    function.                                                          */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    target      :: The target bitmap.                                  */
  /*                                                                       */
  /*    source      :: A pointer to the source glyph image (e.g., an       */
  /*                   @FT_Outline).                                       */
  /*                                                                       */
  /*    flags       :: The rendering flags.                                */
  /*                                                                       */
  /*    gray_spans  :: The gray span drawing callback.                     */
  /*                                                                       */
  /*    black_spans :: The black span drawing callback.  UNIMPLEMENTED!    */
  /*                                                                       */
  /*    bit_test    :: The bit test callback.  UNIMPLEMENTED!              */
  /*                                                                       */
  /*    bit_set     :: The bit set callback.  UNIMPLEMENTED!               */
  /*                                                                       */
  /*    user        :: User-supplied data that is passed to each drawing   */
  /*                   callback.                                           */
  /*                                                                       */
  /*    clip_box    :: An optional clipping box.  It is only used in       */
  /*                   direct rendering mode.  Note that coordinates here  */
  /*                   should be expressed in _integer_ pixels (and not in */
  /*                   26.6 fixed-point units).                            */
  /*                                                                       */
  /* <Note>                                                                */
  /*    An anti-aliased glyph bitmap is drawn if the @FT_RASTER_FLAG_AA    */
  /*    bit flag is set in the `flags' field, otherwise a monochrome       */
  /*    bitmap is generated.                                               */
  /*                                                                       */
  /*    If the @FT_RASTER_FLAG_DIRECT bit flag is set in `flags', the      */
  /*    raster will call the `gray_spans' callback to draw gray pixel      */
  /*    spans, in the case of an aa glyph bitmap, it will call             */
  /*    `black_spans', and `bit_test' and `bit_set' in the case of a       */
  /*    monochrome bitmap.  This allows direct composition over a          */
  /*    pre-existing bitmap through user-provided callbacks to perform the */
  /*    span drawing/composition.                                          */
  /*                                                                       */
  /*    Note that the `bit_test' and `bit_set' callbacks are required when */
  /*    rendering a monochrome bitmap, as they are crucial to implement    */
  /*    correct drop-out control as defined in the TrueType specification. */
  /*                                                                       */
  /* ===================================================================== */

  /* ===================================================================== */
  /*    FT_RASTER_FLAG_XXX                                                 */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A list of bit flag constants as used in the `flags' field of a     */
  /*    @FT_Raster_Params structure.                                       */
  /*                                                                       */
  /* <Values>                                                              */
  /*    FT_RASTER_FLAG_DEFAULT :: This value is 0.                         */
  /*                                                                       */
  /*    FT_RASTER_FLAG_AA      :: This flag is set to indicate that an     */
  /*                              anti-aliased glyph image should be       */
  /*                              generated.  Otherwise, it will be        */
  /*                              monochrome (1-bit).                      */
  /*                                                                       */
  /*    FT_RASTER_FLAG_DIRECT  :: This flag is set to indicate direct      */
  /*                              rendering.  In this mode, client         */
  /*                              applications must provide their own span */
  /*                              callback.  This lets them directly       */
  /*                              draw or compose over an existing bitmap. */
  /*                              If this bit is not set, the target       */
  /*                              pixmap's buffer _must_ be zeroed before  */
  /*                              rendering.                               */
  /*                                                                       */
  /*                              Note that for now, direct rendering is   */
  /*                              only possible with anti-aliased glyphs.  */
  /*                                                                       */
  /*    FT_RASTER_FLAG_CLIP    :: This flag is only used in direct         */
  /*                              rendering mode.  If set, the output will */
  /*                              be clipped to a box specified in the     */
  /*                              `clip_box' field of the                  */
  /*                              @FT_Raster_Params structure.             */
  /*                                                                       */
  /*                              Note that by default, the glyph bitmap   */
  /*                              is clipped to the target pixmap, except  */
  /*                              in direct rendering mode where all spans */
  /*                              are generated if no clipping box is set. */
  /*                                                                       */
  /* ===================================================================== */

public class FTRasterParams extends ftbase.FTDebug {
    private static int oid = 0;

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

    public final static int FT_RASTER_FLAG_DEFAULT = 0x0;
    public final static int FT_RASTER_FLAG_AA      =  0x1;
    public final static int FT_RASTER_FLAG_DIRECT  =  0x2;
    public final static int FT_RASTER_FLAG_CLIP    =  0x4;

    public ftbase.FTBitmapRec target = null;
    public Object source = null;
    public int flags;
    public ftbase.FTInstanceMethod gray_spans = null;
    // FT_SpanFunc             black_spans;  /* doesn't work! */
    // FT_Raster_BitTest_Func  bit_test;     /* doesn't work! */
    // FT_Raster_BitSet_Func   bit_set;      /* doesn't work! */
    public Object user = null;
    public ftbase.FTBBoxRec clip_box = null;

    /* ==================== FTRasterParams ================================== */
    public FTRasterParams() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftraster/FTSmoothRendererClass.java.











































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    FTSmoothRendererClass                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTSmoothRendererClass extends ftbase.FTRendererClassRec {
    private static int oid = 0;

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



    /* ==================== FTSmoothRendererClass ================================== */
    public FTSmoothRendererClass() {
      super();
      oid++;
      id = oid;

      module_flags = (long)ftbase.FTModuleClassRec.FT_MODULE_RENDERER;  /* a renderer */
      module_type = FT_MODULE_TYPE_FT_RENDERER_REC;
      module_name = "smooth";     /* driver name */
      module_version = 0x10000L;   /* driver version 1.0 */
      module_requires = 0x20000L;  /* driver requires FreeType 2.0 or higher */
      module_interface = null;     /* module specific interface */
      raster_class = new FTGrayRasterClassFuncs();
      String class_name = "org.apwtcl.gles20.truetype.FTSmoothRendererFuncs";
      module_init = new ftbase.FTInstanceMethod(class_name, "ft_smooth_init", 1);
      module_done = null;
      get_interface = null;
      glyph_format = FT_GLYPH_FORMAT_OUTLINE;
      render_glyph = new ftbase.FTInstanceMethod(class_name, "ft_smooth_render", 1);
      transform_glyph = new ftbase.FTInstanceMethod(class_name, "ft_smooth_transform", 1);
      get_glyph_cbox = new ftbase.FTInstanceMethod(class_name, "ft_smooth_get_cbox", 1);
      set_mode = new ftbase.FTInstanceMethod(class_name, "ft_smooth_set_mode", 1);
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftraster/FTSmoothRendererFuncs.java.









































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

import android.util.Log;

  /* ===================================================================== */
  /*    FTSmoothRendererFuncs                                                        */
  /*                                                                       */
  /* ===================================================================== */

public class FTSmoothRendererFuncs extends ftbase.FTDebug {
    private static int oid = 0;

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

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     * ft_smooth_init
     * =====================================================================
     */
    public static int ft_smooth_init(Object ... args) {
      ftbase.FTModuleRec module = (ftbase.FTModuleRec)args[0];
      ftbase.FTLibraryRec library = module.library;
      ftbase.FTRendererRec render = (ftbase.FTRendererRec)module;
Debug(0, DBG_INIT, TAG, "ft_smooth_init");
      ftbase.FTReference<FTRasterRec> raster_ref = new ftbase.FTReference<FTRasterRec>();
      raster_ref.Set(render.raster);
      render.clazz.raster_class.raster_reset.callClassMethod(raster_ref,
              library.raster_pool, library.raster_pool_size);
      render.raster = raster_ref.Get();
      return ftbase.FTError.INTERP_ERR_OK;
    }

    /* =====================================================================
     * ft_smooth_render_generic
     * =====================================================================
     */
    public static int ft_smooth_render_generic(ftbase.FTRendererRec render, ftbase.FTGlyphSlotRec slot, long  mode, ftbase.FTVectorRec origin, long required_mode) {
      int error = 0;
      ftbase.FTBBoxRec cbox = new ftbase.FTBBoxRec();
      int width;
      int height;
      int pitch;
      ftbase.FTBitmapRec bitmap = slot.bitmap;  // FIXME set slot after modifying bitmap!!
      boolean hmul = mode == ftbase.FTRendererRec.FT_RENDER_MODE_LCD;
      boolean vmul = mode == ftbase.FTRendererRec.FT_RENDER_MODE_LCD_V;
      long x_shift = 0;
      long y_shift = 0;
      long x_left = 0;
      long y_top = 0;
      int height_org;
      int width_org;
      FTRasterParams params = new FTRasterParams();
      boolean have_translated_origin = false;
      boolean have_outline_shifted = false;
      boolean have_buffer = false;
      ftbase.FTReference<ftbase.FTBBoxRec> cbox_ref = new ftbase.FTReference<ftbase.FTBBoxRec>();
      ftbase.FTReference<ftbase.FTOutlineRec> outline_ref = new ftbase.FTReference<ftbase.FTOutlineRec>();

      /* check glyph image format */
      if (slot.format != render.glyph_format) {
        error = ftbase.FTError.GLYPH_INVALID_ARGUMENT;
        return error;
      }
      /* check rendering mode */
      if (mode != required_mode) {
        return ftbase.FTError.GLYPH_CANNOT_RENDER_GLYPH;
      }
      /* translate the outline to the new origin if needed */
      if (origin != null) {
        outline_ref.Set(slot.outline);
        ftbase.FTOutlineRec.FTOutlineTranslate(outline_ref, origin.x, origin.y);
        slot.outline = outline_ref.Get();
        have_translated_origin = true;
      }
      /* compute the control box, and grid fit it */
      outline_ref.Set(slot.outline);
      cbox_ref.Set(cbox);
      ftbase.FTOutlineRec.FTOutlineGetCBox(outline_ref, cbox_ref);
      cbox = cbox_ref.Get();
      slot.outline = outline_ref.Get();
      /* undocumented but confirmed: bbox values get rounded */
      cbox.xMin = ftbase.FTCalc.FT_PIX_ROUND(cbox.xMin);
      cbox.yMin = ftbase.FTCalc.FT_PIX_ROUND(cbox.yMin);
      cbox.xMax = ftbase.FTCalc.FT_PIX_ROUND(cbox.xMax);
      cbox.yMax = ftbase.FTCalc.FT_PIX_ROUND(cbox.yMax);
      width  = (int)((cbox.xMax - cbox.xMin) >> 6);
      height = (int)((cbox.yMax - cbox.yMin) >> 6);
      if (width > 0xFFFF || height > 0xFFFF) {
        error = ftbase.FTError.RENDER_RASTER_OVERFLOW;
        return error;
      }
      bitmap = slot.bitmap;
      width_org = width;
      height_org = height;
      /* release old bitmap buffer */
      if ((slot.internal.flags & ftbase.FTGlyphLoaderFlags.FT_GLYPH_OWN_BITMAP) != 0) {
//        FT_FREE(bitmap.buffer);
        slot.internal.flags &= ~ftbase.FTGlyphLoaderFlags.FT_GLYPH_OWN_BITMAP;
      }
      /* allocate new one */
      pitch = width;
Debug(0, DBG_INIT, TAG, String.format("ft_smooth_render_generic: pitch: %d, width: %d, height: %d", pitch, width, height));
      if (hmul) {
        width = width * 3;
        pitch = ftbase.FTCalc.FT_PAD_CEIL((long)width, 4).intValue();
      }
      if (vmul) {
        height *= 3;
      }
      x_shift = cbox.xMin;
      y_shift = cbox.yMin;
      x_left = (int)(cbox.xMin >> 6);
      y_top = (int)(cbox.yMax >> 6);
      bitmap.pixel_mode = ftbase.FTBitmapRec.FT_PIXEL_MODE_GRAY;
      bitmap.num_grays = 256;
      bitmap.width = width;
      bitmap.rows = height;
      bitmap.pitch = pitch;
      /* translate outline to render it into the bitmap */
      outline_ref.Set(slot.outline);
      ftbase.FTOutlineRec.FTOutlineTranslate(outline_ref, -x_shift, -y_shift);
      slot.outline = outline_ref.Get();
      have_outline_shifted = true;
      bitmap.buffer = new byte[pitch * height];

//      if ( FT_ALLOC( bitmap.buffer, (FT_ULong)pitch * height ) ) {
//        goto Exit;
//      } else {
        have_buffer = true;
//      }
      slot.internal.flags |= ftbase.FTGlyphLoaderFlags.FT_GLYPH_OWN_BITMAP;
      /* set up parameters */
      params.target = bitmap;
      params.source = slot.outline;
      params.flags = FTRasterParams.FT_RASTER_FLAG_AA;
      /* render outline into bitmap */
      error = (int)render.raster_render.callClassMethod(render.raster, params);
      if (error != 0) {
        if (have_outline_shifted) {
          outline_ref.Set(slot.outline);
          ftbase.FTOutlineRec.FTOutlineTranslate(outline_ref, x_shift, y_shift);
          slot.outline = outline_ref.Get();
        }
        if (have_translated_origin) {
          outline_ref.Set(slot.outline);
          ftbase.FTOutlineRec.FTOutlineTranslate(outline_ref, -origin.x, -origin.y);
          slot.outline = outline_ref.Get();
        }
        if (have_buffer) {
//          FT_FREE( bitmap.buffer );
          slot.internal.flags &= ~ftbase.FTGlyphLoaderFlags.FT_GLYPH_OWN_BITMAP;
        }
        return error;
      }
      /* expand it horizontally */
      if (hmul) {
//        FT_Byte*  line = bitmap.buffer;
        int lineIdx = 0;
        int hh;

        for (hh = height_org; hh > 0; hh--, lineIdx += pitch) {
          int xx;
//          FT_Byte*  end = line + width;
          int endIdx = width;

          if (lineIdx == 0) ; // unused
          for (xx = width_org; xx > 0; xx--) {
            int pixel = bitmap.buffer[xx-1];

            bitmap.buffer[endIdx - 3] = (byte)pixel;
            bitmap.buffer[endIdx - 2] = (byte)pixel;
            bitmap.buffer[endIdx - 1] = (byte)pixel;
            endIdx -= 3;
          }
        }
      }
      /* expand it vertically */
      if (vmul) {
//        FT_Byte*  read  = bitmap.buffer + ( height - height_org ) * pitch;
        int readIdx = (height - height_org) * pitch;
//        FT_Byte*  write = bitmap.buffer;
        int writeIdx = 0;
        int   hh;

        for (hh = height_org; hh > 0; hh--) {
          System.arraycopy(bitmap.buffer, writeIdx, bitmap.buffer, readIdx, pitch);
//          ft_memcpy(write, read, pitch);
          writeIdx += pitch;
          System.arraycopy(bitmap.buffer, writeIdx, bitmap.buffer, readIdx, pitch);
//          ft_memcpy(write, read, pitch);
          writeIdx += pitch;
          System.arraycopy(bitmap.buffer, writeIdx, bitmap.buffer, readIdx, pitch);
//          ft_memcpy( write, read, pitch );
          writeIdx += pitch;
          readIdx += pitch;
        }
      }
      /*
       * XXX: on 16bit system, we return an error for huge bitmap
       * to prevent an overflow.
       */
      if (x_left > 0xFFFF || y_top > 0xFFFF) {
        error = ftbase.FTError.RENDER_INVALID_PIXEL_SIZE;
      } else {
          slot.format = FT_GLYPH_FORMAT_BITMAP;
          slot.bitmap_left = (int)x_left;
          slot.bitmap_top = (int)y_top;
          slot.bitmap = bitmap;
          /* everything is fine; don't deallocate buffer */
          have_buffer = false;
          error = ftbase.FTError.INTERP_ERR_OK;
      }
      if (have_outline_shifted) {
        outline_ref.Set(slot.outline);	  
        ftbase.FTOutlineRec.FTOutlineTranslate(outline_ref, x_shift, y_shift);
        slot.outline = outline_ref.Get();
      }
      if (have_translated_origin) {
        outline_ref.Set(slot.outline);	  
        ftbase.FTOutlineRec.FTOutlineTranslate(outline_ref, -origin.x, -origin.y);
        slot.outline = outline_ref.Get();
      }
      if (have_buffer) {
//        FT_FREE( bitmap.buffer );
        slot.internal.flags &= ~ftbase.FTGlyphLoaderFlags.FT_GLYPH_OWN_BITMAP;
      }
      return error;
    }

    /* =====================================================================
     * ft_smooth_render
     * =====================================================================
     */
    public static int ft_smooth_render(Object ... args) {
      ftbase.FTRendererRec render = (ftbase.FTRendererRec) args[0];
      ftbase.FTGlyphSlotRec slot = (ftbase.FTGlyphSlotRec)args[1];
      long  mode = (long)args[2];
      ftbase.FTVectorRec origin = (ftbase.FTVectorRec)args[3];

      return ft_smooth_render_generic(render, slot, mode, origin, FT_RENDER_MODE_NORMAL);
    }

    /* =====================================================================
     * ft_smooth_transform
     * =====================================================================
     */
    public static int ft_smooth_transform(Object ... args) {
      Log.w(TAG, "WARNING: ft_smooth_transform not yet implemented");
System.out.println("ft_smooth_transform not yet implemented!!");
      return 1;
    }

    /* =====================================================================
     * ft_smooth_get_cbox
     * =====================================================================
     */
    public static int ft_smooth_get_cbox(Object ... args) {
      Log.w(TAG, "WARNING: ft_smooth_get_cbox not yet implemented");
System.out.println("ft_smooth_get_cbox not yet implemented!!");
      return 1;
    }

    /* =====================================================================
     * ft_smooth_set_mode
     * =====================================================================
     */
    public static int ft_smooth_set_mode(Object ... args) {
      Log.w(TAG, "WARNING: ft_smooth_set_mode not yet implemented");
System.out.println("ft_smooth_set_mode not yet implemented!!");
      return 1;
    }

}

Added ftraster/FTSpan.java.

























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    FTSpan                                                             */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A structure used to model a single span of gray (or black) pixels  */
  /*    when rendering a monochrome or anti-aliased bitmap.                */
  /*                                                                       */
  /* <Fields>                                                              */
  /*    x        :: The span's horizontal start position.                  */
  /*                                                                       */
  /*    len      :: The span's length in pixels.                           */
  /*                                                                       */
  /*    coverage :: The span color/coverage, ranging from 0 (background)   */
  /*                to 255 (foreground).  Only used for anti-aliased       */
  /*                rendering.                                             */
  /*                                                                       */
  /* <Note>                                                                */
  /*    This structure is used by the span drawing callback type named     */
  /*    @FT_SpanFunc which takes the y~coordinate of the span as a         */
  /*    a parameter.                                                       */
  /*                                                                       */
  /*    The coverage value is always between 0 and 255.  If you want less  */
  /*    gray values, the callback function has to reduce them.             */
  /*                                                                       */
  /* ===================================================================== */

public class FTSpan extends ftbase.FTDebug {
    private static int oid = 0;

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

    public static int FT_MAX_GRAY_SPANS = 32;

    public short x;
    public short len;
    public byte coverage;

    /* ==================== FTSpan ================================== */
    public FTSpan() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftraster/FTStandardRasterClass.java.

















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    FTStandardRasterClass                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTStandardRasterClass extends FTRasterFuncs {
    private static int oid = 0;

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

    /* ==================== FTStandardRasterClass ================================== */
    public FTStandardRasterClass() {
      oid++;
      id = oid;
      glyph_format = FT_GLYPH_FORMAT_OUTLINE;
      String class_name = "org.apwtcl.gles20.truetype.FTStandardRasterFuncs";
      raster_new = new ftbase.FTInstanceMethod(class_name, "ft_black_new", 1);
      raster_reset = new ftbase.FTInstanceMethod(class_name, "ft_black_reset", 1);
      raster_set_mode = new ftbase.FTInstanceMethod(class_name, "ft_black_set_mode", 1);
      raster_render = new ftbase.FTInstanceMethod(class_name, "ft_black_render", 1);
      raster_done = new ftbase.FTInstanceMethod(class_name, "ft_black_done", 1);
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftraster/FTStandardRasterFuncs.java.

















































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

import android.util.Log;

  /* ===================================================================== */
  /*    FTStandardRasterFuncs                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class FTStandardRasterFuncs extends ftbase.FTDebug {
    private static int oid = 0;

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

    /* ==================== FTStandardRasterFuncs ================================== */
    public FTStandardRasterFuncs() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

    /* ==================== toDebugString ===================================== */
    public String toDebugString() {
      StringBuffer str = new StringBuffer(mySelf()+"\n");
      return str.toString();
    }
 
    /* =====================================================================
     *    ft_black_init
     *
     * =====================================================================
     */
    public static int ft_black_init(Object ... args) {
Debug(0, DBG_INIT, TAG, "ft_black_init");
      ftbase.FTReference<blackTRaster> raster_ref = (ftbase.FTReference<blackTRaster>)args[0];
      int error = 0;
      // nothing to do yet
      return error;
    }

    /* =====================================================================
     *    ft_black_new
     *
     * =====================================================================
     */
    public static int ft_black_new(Object ... args) {
Debug(0, DBG_INIT, TAG, "ft_black_new");
      ftbase.FTReference<blackTRaster> raster_ref = (ftbase.FTReference<blackTRaster>)args[0];
      int error = 0;
      blackTRaster raster = null;
      raster_ref.Set(null);
      raster = new blackTRaster();
      if (raster != null) {
        raster_ref.Set(raster);
        ft_black_init(raster_ref);
        raster = raster_ref.Get();
        raster_ref.Set(raster);
      }
      return error;
    }

    /* =====================================================================
     *    ft_black_reset
     *
     * =====================================================================
     */
    public static int ft_black_reset(Object ... args) {
      ftbase.FTReference<FTRasterRec> raster_ref = (ftbase.FTReference<FTRasterRec>)args[0];
      blackTRaster raster = new blackTRaster(raster_ref.Get());
      byte[] pool_base = (byte[])args[1];
      long pool_size = (long)args[2];
      int error = 0;

      if (raster != null) {
        if (pool_base != null) {
          blackTWorker worker =  new blackTWorker();
          raster.buffer = pool_base;
          raster.buffer_size = (long)pool_size;
          raster.worker = worker;
        } else {
          raster.buffer = null;
          raster.buffer_size = 0;
          raster.worker = null;
        }
        raster_ref.Set((FTRasterRec)raster);
      }
      return error;
    }

    /* =====================================================================
     *    ft_black_set_mode
     *
     * =====================================================================
     */
    public static int ft_black_set_mode(Object ... args) {
      Log.w(TAG, "WARNING: ft_black_set_mode not yet implemented");
      System.out.println("ft_black_set_mode not yet implemented!!");
      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ft_black_render
     *
     * =====================================================================
     */
    public static int ft_black_render(Object ... args) {
      Log.w(TAG, "WARNING: ft_black_render not yet implemented");
      System.out.println("ft_black_render not yet implemented!!");
      int error = 0;

      return error;
    }

    /* =====================================================================
     *    ft_black_done
     *
     * =====================================================================
     */
    public static int ft_black_done(Object ... args) {
      Log.w(TAG, "WARNING: ft_black_done not yet implemented");
      System.out.println("ft_black_done not yet implemented!!");
      int error = 0;

      return error;
    }

}

Added ftraster/TCell.java.













































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// ----------------------------------------------------------------
// FTRaster1RendererFuncs.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftraster;

  /* ===================================================================== */
  /*    TCell                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class TCell extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "TCell";
    public static TCell[] tcells = new TCell[2048];
    public static int tcells_idx = 0;

    public long x;     /* same with grayTWorker.ex    */
    public long cover; /* same with grayTWorker.cover */
    public long area;
    public int nextIdx;
    public TCell next;
    public int self_idx;

    /* ==================== TCell ================================== */
    public TCell() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftraster/blackTBand.java.









































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    blackTBand                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class blackTBand extends ftbase.FTDebug {
    private static int oid = 0;

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

    public Short y_min = 0;   /* band's minimum */
    public Short y_max = 0;   /* band's maximum */

    /* ==================== blackTBand ================================== */
    public blackTBand() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftraster/blackTRaster.java.



























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    blackTRaster                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class blackTRaster extends FTRasterRec {
    private static int oid = 0;

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

    public blackTWorker worker = null;
    public byte[] grays = new byte[5];
    public short gray_width = 0;

    /* ==================== blackTRaster ================================== */
    public blackTRaster() {
      oid++;
      id = oid;
    }
    
    /* ==================== blackTRaster ================================== */
    public blackTRaster(FTRasterRec raster_rec) {
      oid++;
      id = oid;
      this.buffer = raster_rec.buffer;
      this.buffer_size = raster_rec.buffer_size;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftraster/blackTWorker.java.





















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    blackTWorker                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class blackTWorker extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "blackTWorker";
    private final static int MaxBezier = 32;

    public int precision_bits = 0;     /* precision related variables         */
    public int precision = 0;
    public int precision_half = 0;
    public int precision_shift = 0;
    public int precision_step = 0;
    public int precision_jitter = 0;
    public int scale_shift = 0;        /* == precision_shift   for bitmaps    */
                                       /* == precision_shift+1 for pixmaps    */
    public int[] buff = null;               /* The profiles buffer                 */
    public int sizeBuff = 0;           /* Render pool size                    */
    public int maxBuff = 0;            /* Profiles buffer size                */
    public int top = 0;                /* Current cursor in buffer            */
    public int error = 0;
    public int numTurns = 0;             /* number of Y-turns in outline        */
    public ftdemo.TPoint arc = null;            /* current Bezier arc pointer          */
    public Short bWidth = 0;             /* target bitmap width                 */
    public byte[] bTarget = null;        /* target bitmap buffer                */
    public byte[] gTarget = null;        /* target pixmap buffer                */
    public long lastX = 0L;
    public long lastY = 0L;
    public long minY = 0L;
    public long maxY = 0L;
    public Short num_Profs = 0;          /* current number of profiles          */
    public boolean fresh = false;        /* signals a fresh new profile which   */
                                  /* `start' field must be completed     */
    public boolean joint = false;        /* signals that the last arc ended     */
                                  /* exactly on a scanline.  Allows      */
                                  /* removal of doublets                 */
    public ftdemo.TProfile cProfile = null;     /* current profile                     */
    public ftdemo.TProfile fProfile = null;     /* head of linked list of profiles     */
    public ftdemo.TProfile gProfile = null;     /* contour's first profile in case     */
                                         /* of impact                           */
    public ftdemo.TStates state = null;         /* rendering state                     */
    public ftbase.FTBitmapRec target = null;    /* description of target bit/pixmap    */
    public ftbase.FTOutlineRec outline = null;
    public long traceOfs = 0L;           /* current offset in target bitmap     */
    public long traceG = 0L;             /* current offset in target pixmap     */
    public short traceIncr = 0;          /* sweep's increment in target bitmap  */
    public short gray_min_x = 0;         /* current min x during gray rendering */
    public short gray_max_x = 0;         /* current max x during gray rendering */
    /* dispatch variables */
    public ftbase.FTInstanceMethod Proc_Sweep_Init = null;
    public ftbase.FTInstanceMethod Proc_Sweep_Span = null;
    public ftbase.FTInstanceMethod Proc_Sweep_Drop = null;
    public ftbase.FTInstanceMethod Proc_Sweep_Step = null;
    public byte dropOutControl = 0;      /* current drop_out control method     */
    public boolean second_pass = false;  /* indicates whether a horizontal pass */
                                  /* should be performed to control      */
                                  /* drop-out accurately when calling    */
                                  /* Render_Glyph.  Note that there is   */
                                  /* no horizontal pass during gray      */
                                  /* rendering.                          */
    public ftdemo.TPoint[] arcs = new ftdemo.TPoint[3 * MaxBezier + 1]; /* The Bezier stack  */
    public blackTBand[] band_stack = new blackTBand[16]; /* band stack used for sub-banding */
    public int band_top;                /* band stack top                      */

    /* ==================== blackTWorker ================================== */
    public blackTWorker() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftraster/grayTBand.java.









































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    grayTBand                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class grayTBand extends ftbase.FTDebug {
    private static int oid = 0;

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

    public short min = 0;   /* band's minimum */
    public short max = 0;   /* band's maximum */

    /* ==================== grayTBand ================================== */
    public grayTBand() {
      oid++;
      id = oid;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftraster/grayTRaster.java.























































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// ----------------------------------------------------------------
// grayTRaster.java --
//
// Copyright (c) 2014 by Arnulf P. Wiedemann
//
// See the file "license.terms" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//------------------------------------------------------------------------

package ftraster;

//import android.util.Log;

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

  /* ===================================================================== */
  /*    grayTRaster                                                          */
  /*                                                                       */
  /* ===================================================================== */

public class grayTRaster extends FTRasterRec {
    private static int oid = 0;

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

    public int band_size = 0;
    public grayTWorker worker = null;

    /* ==================== grayTRaster ================================== */
    public grayTRaster() {
      oid++;
      id = oid;
    }
    
    /* ==================== grayTRaster ================================== */
    public grayTRaster(FTRasterRec raster_rec) {
      oid++;
      id = oid;
      this.buffer = raster_rec.buffer;
      this.buffer_size = raster_rec.buffer_size;
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      String str = TAG+"!"+id+"!";
      return str;
    } 
        
    /* ==================== toString ===================================== */
    public String toString() {
      StringBuffer str = new StringBuffer(mySelf()+"!");
      return str.toString();
    }

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

}

Added ftraster/grayTWorker.java.





































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftraster;

  /* ===================================================================== */
  /*    grayTWorker                                                        */
  /*                                                                       */
  /* ===================================================================== */

public class grayTWorker extends ftbase.FTDebug {
    private static int oid = 0;

    private int id;
    private static String TAG = "grayTWorker";
    private final static int MaxBezier = 32;

    public long ex;
    public long ey;
    public long min_ex;
    public long max_ex;
    public long min_ey;
    public long max_ey;
    public long count_ex;
    public long count_ey;
    public long area;
    public long cover;
    public boolean invalid;
    public TCell[] cells = null;
    public int max_cells;
    public int num_cells;
    public long cx;
    public long cy;
    public long x;
    public long y;
    public long last_ey;
    public ftbase.FTVectorRec[] bez_stack = new ftbase.FTVectorRec[MaxBezier * 3 + 1];
    public int[] lev_stack = new int[32];
    public ftbase.FTOutlineRec outline;
    public ftbase.FTBitmapRec target;
    public ftbase.FTBBoxRec clip_box;
    public FTSpan[] gray_spans = new FTSpan [FTSpan.FT_MAX_GRAY_SPANS];
    public int num_gray_spans;
    public ftbase.FTInstanceMethod render_span;
    public Object render_span_data;
    public int span_y;
    public int band_size;
    public int band_shoot;
//    public ft_jmp_buf jump_buffer;
    public Object buffer;
    public long buffer_size;
    public TCell[] ycells;
    public long ycount;

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

      oid++;
      id = oid;
      target = new ftbase.FTBitmapRec();
      outline = new ftbase.FTOutlineRec();
      clip_box = new ftbase.FTBBoxRec();
      for (i = 0; i < FTSpan.FT_MAX_GRAY_SPANS; i++) {
        gray_spans[i] = new FTSpan();
      }
      for (i = 0; i < MaxBezier * 3 + 1; i++) {
        bez_stack[i] = new ftbase.FTVectorRec();
      }
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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

Added ftsfnt/SfntModuleClass.java.































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann arnulf at wiedemann-pri.de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package ftsfnt;

  /* ===================================================================== */
  /*    SfntModuleClass                                                    */
  /*                                                                       */
  /* ===================================================================== */

public class SfntModuleClass extends ftbase.FTModuleClassRec {
    private static int oid = 0;

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



    /* ==================== SfntModuleClass ================================== */
    public SfntModuleClass() {
      super();
      oid++;
      id = oid;

      module_flags = 0L;  /* not a font driver or renderer */
      module_type = FT_MODULE_TYPE_FT_MODULE_REC;
      module_name = "sfnt";        /* driver name */
      module_version = 0x10000L;   /* driver version 1.0 */
      module_requires = 0x20000L;  /* driver requires FreeType 2.0 or higher */
      module_interface = new FTSfntInterfaceClass(); /* "Sfnt_Interface"; /* module specific interface */
      module_init = null;
      module_done = null;
      String class_name = "org.apwtcl.gles20.truetype.TTSfntLoad";
      get_interface = new ftbase.FTInstanceMethod(class_name, "sfnt_get_interface", 1);
    }
    
    /* ==================== mySelf ================================== */
    public String mySelf() {
      return TAG+"!"+id+"!";
    }
        
    /* ==================== toString ===================================== */
    public String toString() {
      return mySelf()+"!";
    }

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