-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTests.java
More file actions
1787 lines (1362 loc) · 55 KB
/
Tests.java
File metadata and controls
1787 lines (1362 loc) · 55 KB
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
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import generaloss.freetype.FreeType;
import generaloss.freetype.UnicodeVariationSelector;
import generaloss.freetype.freetype.*;
import generaloss.freetype.gload.FTGlyphLoader;
import generaloss.freetype.gload.FTSubGlyph;
import generaloss.freetype.glyph.FTBitmapGlyph;
import generaloss.freetype.glyph.FTGlyph;
import generaloss.freetype.glyph.FTGlyphBBoxMode;
import generaloss.freetype.image.*;
import generaloss.freetype.outln.FTOrientation;
import generaloss.freetype.stroke.FTStroker;
import generaloss.freetype.stroke.FTStrokerBorder;
import generaloss.freetype.stroke.FTStrokerLineCap;
import generaloss.freetype.stroke.FTStrokerLineJoin;
import generaloss.freetype.system.FTMemory;
import generaloss.freetype.types.*;
import jpize.util.res.Resource;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
public class Tests {
@Test
public void ftNewMemoryFace() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.done();
lib.done();
}
@Test
public void ftLoadGlyph() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0); // corrupted size vs. prev_size
final long glyphIndex = face.getCharIndex('A');
face.loadGlyph(glyphIndex);
face.done();
lib.done();
}
@Test
public void ftLoadChar() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.loadChar('A');
face.done();
lib.done();
}
@Test
public void ftFaceProperties() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final FTParameter property1 = new FTParameter()
.setTag(FTParamTag.STEM_DARKENING)
.setData(true);
final FTParameter property2 = new FTParameter()
.setTag(FTParamTag.LCD_FILTER_WEIGHTS)
.setData(new byte[] { 0x11, 0x44, 0x56, 0x44, 0x11 });
final FTParameter property3 = new FTParameter()
.setTag(FTParamTag.RANDOM_SEED)
.setData(314159265);
face.properties(property1, property2, property3);
face.done();
lib.done();
}
@Test
public void ftGetGlyphName() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final long glyphIndex = face.getCharIndex('A');
final ByteBuffer buffer = ByteBuffer.allocateDirect(2);
face.getGlyphName(glyphIndex, buffer);
Assertions.assertEquals('䄀', buffer.getChar());
face.done();
lib.done();
}
@Test
public void ftInitFreeType() {
final FTLibrary lib = new FTLibrary();
lib.done();
}
@Test
public void ftDoneFreeType() {
final FTLibrary lib = new FTLibrary();
lib.done();
}
@Test
public void ftNewFace() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newFace("src/test/resources/droidsans.ttf", 0);
face.done();
lib.done();
}
@Test
public void ftOpenFace_FILE() {
final FTLibrary lib = new FTLibrary();
final FTOpenArgs args = new FTOpenArgs();
args.setFlags(FTOpen.PATHNAME);
args.setPathname("src/test/resources/droidsans.ttf");
final FTFace face = lib.openFace(args, 0);
face.done();
lib.done();
}
@Test
public void ftOpenFace_MEMORY() {
final FTLibrary lib = new FTLibrary();
final FTOpenArgs args = new FTOpenArgs();
args.setFlags(FTOpen.MEMORY);
args.setMemoryBase(Resource.internal("/droidsans.ttf").readByteBuffer());
final FTFace face = lib.openFace(args, 0);
face.done();
lib.done();
}
@Test
public void ftOpenFace_STREAM() {
final FTLibrary lib = new FTLibrary();
final ByteArrayInputStream bais = new ByteArrayInputStream(Resource.internal("/main.ttf").readBytes());
final FTStream stream = new FTStream();
stream.setSize(bais.available());
stream.setRead((long offset, byte[] buffer, long count) -> {
bais.reset();
bais.skip(offset);
return bais.read(buffer, 0, (int) count);
});
stream.setClose(bais::close);
final FTOpenArgs args = new FTOpenArgs();
args.setFlags(FTOpen.STREAM);
args.setStream(stream);
final FTFace face = lib.openFace(args, 0);
face.done();
stream.free();
lib.done();
}
@Test
public void ftAttachFile() {
// (postscript type 1 font)
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/bchb8i.pfb").readByteBuffer(), 0);
face.attachFile("src/test/resources/bchb8i.afm");
face.done();
lib.done();
}
@Test
public void ftAttachStream() {
// (postscript type 1 font)
final FTStream stream = new FTStream();
stream.set(Resource.internal("/bchb8i.afm").readBytes());
final FTOpenArgs args = new FTOpenArgs();
args.setFlags(FTOpen.STREAM);
args.setStream(stream);
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/bchb8i.pfb").readByteBuffer(), 0);
face.attachStream(args);
stream.free();
args.free();
face.done();
lib.done();
}
@Test
public void ftReferenceFace() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0); // new => refcount=1
face.referenceFace(); // refcount++ = 2
face.referenceFace(); // refcount++ = 3
face.done(); // refcount-- = 2
face.referenceFace(); // refcount++ = 3
face.done(); // refcount-- = 2
face.done(); // refcount-- = 1
face.done(); // refcount=0 => done
lib.done();
}
@Test
public void ftDoneFace() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.done();
lib.done();
}
@Test
public void ftSelectSize() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/ter-u32n.bdf").readByteBuffer(), 0);
final int strikeCount = face.getNumFixedSizes();
if(strikeCount == 0)
throw new RuntimeException("Face has no available bitmap sizes");
FreeType.ftSelectSize(face, 0);
FreeType.ftLoadGlyph(face, face.getCharIndex('A'));
// Load bitmap glyph using FT_Select_Size strike[0]
final FTGlyphSlot glyph = face.getGlyph();
if(glyph.getFormat() != FTGlyphFormat.BITMAP)
throw new RuntimeException("Expected bitmap glyph, but got: " + glyph.getFormat());
face.done();
lib.done();
}
@Test
public void ftRequestSize() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final FTSizeRequest request = new FTSizeRequest();
request.setType(FTSizeRequestType.REAL_DIM);
request.setWidth(0L);
request.setHeight(12L * 64L); // 12pt in 1/64th points (internal FreeType format)
request.setHoriResolution(72L); // 72 DPI
request.setVertResolution(72L); // 72 DPI
face.requestSize(request);
Assertions.assertEquals(2384, face.getHeight());
face.done();
lib.done();
}
@Test
public void ftSetCharSize() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.setCharSize(0F, 16F, 300, 300); // 16pt, 300dpi
final FTSizeMetrics metrics = face.getSize().getMetrics();
Assertions.assertEquals(78F, metrics.getHeight(), 0F);
face.done();
lib.done();
}
@Test
public void ftSetPixelSizes() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.setPixelSizes(0L, 24L);
final FTSizeMetrics metrics = face.getSize().getMetrics();
Assertions.assertEquals(28F, metrics.getHeight(), 0F);
face.done();
lib.done();
}
@Test
public void ftSetTransform() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final FTMatrix matrix = new FTMatrix().setIdentity();
final FTVector delta = new FTVector().set(10F, 20F, PosType.F26DOT6);
face.setTransform(matrix, delta);
matrix.setXX(0F).setYY(0F);
delta.set(0F, PosType.F26DOT6);
face.getTransform(matrix, delta);
Assertions.assertEquals(1F, matrix.getXX(), 0F);
Assertions.assertEquals(1F, matrix.getYY(), 0F);
Assertions.assertEquals(10F, delta.getX(PosType.F26DOT6), 0F);
Assertions.assertEquals(20F, delta.getY(PosType.F26DOT6), 0F);
matrix.free();
delta.free();
face.done();
lib.done();
}
@Test
public void ftGetTransform() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final FTMatrix matrix = new FTMatrix().setIdentity();
final FTVector delta = new FTVector().set(10F, 20F, PosType.F26DOT6);
face.setTransform(matrix, delta);
matrix.setXX(0F).setYY(0F);
delta.set(0F, PosType.F26DOT6);
face.getTransform(matrix, delta);
Assertions.assertEquals(1F, matrix.getXX(), 0F);
Assertions.assertEquals(1F, matrix.getYY(), 0F);
Assertions.assertEquals(10F, delta.getX(PosType.F26DOT6), 0F);
Assertions.assertEquals(20F, delta.getY(PosType.F26DOT6), 0F);
matrix.free();
delta.free();
face.done();
lib.done();
}
@Test
public void ftRenderGlyph() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.setPixelSizes(32L, 32L);
face.loadChar('A');
final FTGlyphSlot slot = face.getGlyph();
slot.renderGlyph(FTRenderMode.NORMAL);
face.done();
lib.done();
}
@Test
public void ftGetKerning() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.setPixelSizes(0L, 64L);
final long left = face.getCharIndex('A');
final long right = face.getCharIndex('V');
final FTVector dstKerning = new FTVector();
face.getKerning(left, right, FTKerningMode.DEFAULT, dstKerning);
Assertions.assertEquals(-2F, dstKerning.getX(PosType.F26DOT6), 0F);
face.done();
lib.done();
}
@Test
public void ftGetTrackKerning() { // old enough postscript type1 font was not found => 0F track kerning
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/bchb8i.pfb").readByteBuffer(), 0);
final FTStream stream = new FTStream();
stream.set(Resource.internal("/bchb8i.afm").readBytes());
final FTOpenArgs args = new FTOpenArgs();
args.setFlags(FTOpen.STREAM);
args.setStream(stream);
face.attachStream(args);
stream.free();
args.free();
face.setPixelSizes(0L, 16L);
Assertions.assertEquals(0F, face.getTrackKerning(32L, 0), 0F);
face.done();
lib.done();
}
@Test
public void ftSelectCharmap() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.selectCharmap(FTEncoding.APPLE_ROMAN);
Assertions.assertEquals(FTEncoding.APPLE_ROMAN, face.getCharmap().getEncoding());
face.selectCharmap(FTEncoding.UNICODE);
Assertions.assertEquals(FTEncoding.UNICODE, face.getCharmap().getEncoding());
face.done();
lib.done();
}
@Test
public void ftSetCharmap() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final List<FTCharMap> list = new ArrayList<>(Arrays.asList(face.getCharmaps()));
list.remove(face.getCharmap());
final FTCharMap target = list.get(0);
face.setCharmap(target);
Assertions.assertEquals(target, face.getCharmap());
face.done();
lib.done();
}
@Test
public void ftGetCharmapIndex() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final FTCharMap[] charmaps = face.getCharmaps();
final int index = (charmaps.length - 1); // last
final FTCharMap charmap = face.getCharmaps()[index];
Assertions.assertEquals(index, charmap.getIndex());
face.done();
lib.done();
}
@Test
public void ftGetCharIndex() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final long indexA = face.getCharIndex('A');
final long indexZ = face.getCharIndex('Z');
final long invalidChar = face.getCharIndex(0xFFFF);
Assertions.assertTrue(indexA > 0L);
Assertions.assertTrue(indexZ > 0L);
Assertions.assertEquals(0L, invalidChar);
face.done();
lib.done();
}
@Test
public void ftGetFirstChar() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final long[] dstGlyphIndex = new long[1];
final long charcode = face.getFirstChar(dstGlyphIndex);
Assertions.assertTrue(charcode > 0L);
Assertions.assertEquals(face.getCharIndex(charcode), dstGlyphIndex[0]);
face.done();
lib.done();
}
@Test
public void ftGetNextChar() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final long first = face.getFirstChar(null);
final long next = face.getNextChar(first, null);
Assertions.assertTrue(next > first);
Assertions.assertTrue(next > 0L);
face.done();
lib.done();
}
@Test
public void ftGetNameIndex() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final long index = face.getNameIndex("copyright");
Assertions.assertTrue(index >= 0L);
face.done();
lib.done();
}
@Test
public void ftGetPostscriptName() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final String postscriptName = face.getPostscriptName();
Assertions.assertEquals("DroidSans", postscriptName);
face.done();
lib.done();
}
@Test
public void ftGetSubGlyphInfo() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.loadChar('Ǽ', FTLoad.NO_RECURSE);
final FTGlyphSlot glyph = face.getGlyph();
final FTSubGlyph[] subglyphs = glyph.getSubglyphs();
final int index = (subglyphs.length - 1); // last
final FTSubGlyph target = subglyphs[index];
final int[] dstPIndex = new int[1];
final long[] dstPFlags = new long[1];
final int[] dstPArg1 = new int[1];
final int[] dstPArg2 = new int[1];
final FTMatrix dstPTransform = new FTMatrix();
glyph.getSubGlyphInfo(index, dstPIndex, dstPFlags, dstPArg1, dstPArg2, dstPTransform);
Assertions.assertEquals(target.getIndex(), dstPIndex[0]);
Assertions.assertEquals(target.getFlagsRaw(), dstPFlags[0]);
Assertions.assertEquals(target.getArg1(), dstPArg1[0]);
Assertions.assertEquals(target.getArg2(), dstPArg2[0]);
Assertions.assertEquals(target.getTransform(), dstPTransform);
dstPTransform.free();
face.done();
lib.done();
}
@Test
public void ftGetFSTypeFlags() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final FSTypeFlags flags = face.getFSTypeFlags();
Assertions.assertFalse(flags.isDefault());
face.done();
lib.done();
}
@Test
public void ftFaceGetCharVariantIndex() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/apple-color-emoji.ttf").readByteBuffer(), 0);
final long variantIndex = face.getCharVariantIndex('❤', UnicodeVariationSelector.VS16_EMOJI);
Assertions.assertEquals(168L, variantIndex);
face.done();
lib.done();
}
@Test
public void ftFaceGetCharVariantIsDefault() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/apple-color-emoji.ttf").readByteBuffer(), 0);
final int isDefault = face.getCharVariantIsDefault('❤', UnicodeVariationSelector.VS16_EMOJI);
Assertions.assertEquals(1, isDefault);
face.done();
lib.done();
}
@Test
public void ftFaceGetVariantSelectors() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/apple-color-emoji.ttf").readByteBuffer(), 0);
final long[] selectors = face.getVariantSelectors();
Assertions.assertTrue(selectors.length > 0);
Assertions.assertEquals(UnicodeVariationSelector.VS16_EMOJI.code, selectors[0]);
face.done();
lib.done();
}
@Test
public void ftFaceGetVariantsOfChar() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/apple-color-emoji.ttf").readByteBuffer(), 0);
final long[] variants = face.getVariantsOfChar('❤');
Assertions.assertTrue(variants.length > 0);
face.done();
lib.done();
}
@Test
public void ftFaceGetCharsOfVariant() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/main.ttf").readByteBuffer(), 0);
final long[] chars = face.getCharsOfVariant(face.getVariantSelectors()[0]);
Assertions.assertTrue(chars.length > 0);
face.done();
lib.done();
}
@Test
public void ftMulDiv() {
Assertions.assertEquals(2L, FreeType.ftMulDiv(4L, 5L, 10L));
}
@Test
public void ftMulFix() {
Assertions.assertEquals(8L, FreeType.ftMulFix(1024L, 512L));
}
@Test
public void ftDivFix() {
Assertions.assertEquals(1024L, FreeType.ftDivFix(8L, 512L));
}
@Test
public void ftRoundFix() {
final FTFixed num = new FTFixed().set(1.5F);
Assertions.assertEquals(2F, FreeType.ftRoundFix(num), 0F);
num.free();
}
@Test
public void ftCeilFix() {
final FTFixed num = new FTFixed().set(1.5F);
Assertions.assertEquals(2F, FreeType.ftCeilFix(num), 0F);
num.free();
}
@Test
public void ftFloorFix() {
final FTFixed num = new FTFixed().set(1.5F);
Assertions.assertEquals(1F, FreeType.ftFloorFix(num), 0F);
num.free();
}
@Test
public void ftVectorTransform() {
final FTVector vector = new FTVector().set(10F, 20F, PosType.F16DOT16);
final FTMatrix matrix = new FTMatrix().setScale(2F);
vector.transform(matrix);
Assertions.assertEquals(20F, vector.getX(PosType.F16DOT16), 0F);
Assertions.assertEquals(40F, vector.getY(PosType.F16DOT16), 0F);
vector.free();
matrix.free();
}
@Test
public void ftLibraryVersion() {
final FTLibrary lib = new FTLibrary();
final String version = lib.getVersion();
Assertions.assertTrue(version.matches("\\d+\\.\\d+\\.\\d+"));
lib.done();
}
@Test
public void ftFaceCheckTrueTypePatents() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
final boolean hasPatents = face.checkTrueTypePatents();
Assertions.assertFalse(hasPatents);
face.done();
lib.done();
}
@Test
public void ftGlyphLoaderNew() {
final FTLibrary lib = new FTLibrary();
final FTMemory memory = lib.getMemory();
final FTGlyphLoader loader = memory.newGlyphLoader();
loader.done();
lib.done();
}
@Test
public void ftGlyphLoaderCreateExtra() {
final FTLibrary lib = new FTLibrary();
final FTMemory memory = lib.getMemory();
final FTGlyphLoader loader = memory.newGlyphLoader();
loader.createExtra();
loader.done();
lib.done();
}
@Test
public void ftGlyphLoaderDone() {
final FTLibrary lib = new FTLibrary();
final FTMemory memory = lib.getMemory();
final FTGlyphLoader loader = memory.newGlyphLoader();
loader.done();
lib.done();
}
@Test
public void ftGlyphLoaderReset() {
final FTLibrary lib = new FTLibrary();
final FTMemory memory = lib.getMemory();
final FTGlyphLoader loader = memory.newGlyphLoader();
loader.reset();
loader.done();
lib.done();
}
@Test
public void ftGlyphLoaderRewind() {
final FTLibrary lib = new FTLibrary();
final FTMemory memory = lib.getMemory();
final FTGlyphLoader loader = memory.newGlyphLoader();
loader.rewind();
loader.done();
lib.done();
}
@Test
public void ftGlyphLoaderCheckPoints() {
final FTLibrary lib = new FTLibrary();
final FTMemory memory = lib.getMemory();
final FTGlyphLoader loader = memory.newGlyphLoader();
loader.prepare(); // prepare current
loader.checkPoints(10, 5);
loader.getCurrent().getOutline().setNPoints(10);
loader.getCurrent().getOutline().setNContours(5);
loader.add(); // copy current -> base
final FTOutline outline = loader.getBase().getOutline();
Assertions.assertEquals(10, outline.getNPoints());
Assertions.assertEquals(5, outline.getNContours());
loader.done();
lib.done();
}
@Test
public void ftGlyphLoaderCheckSubGlyphs() {
final FTLibrary lib = new FTLibrary();
final FTMemory memory = lib.getMemory();
final FTGlyphLoader loader = memory.newGlyphLoader();
loader.prepare(); // prepare current
loader.checkSubGlyphs(3); // allocate 3 subglyphs
loader.getCurrent().setNumSubglyphs(3);
loader.getCurrent().getSubglyphs()[0].setIndex(228);
loader.add(); // copy current -> base
Assertions.assertEquals(3, loader.getBase().getNumSubglyphs());
Assertions.assertEquals(228, loader.getBase().getSubglyphs()[0].getIndex());
loader.done();
lib.done();
}
@Test
public void ftGlyphLoaderPrepare() {
final FTLibrary lib = new FTLibrary();
final FTMemory memory = lib.getMemory();
final FTGlyphLoader loader = memory.newGlyphLoader();
loader.prepare(); // prepare current
loader.done();
lib.done();
}
@Test
public void ftGlyphLoaderAdd() {
final FTLibrary lib = new FTLibrary();
final FTMemory memory = lib.getMemory();
final FTGlyphLoader loader = memory.newGlyphLoader();
loader.prepare(); // prepare current
loader.checkPoints(1, 1); // allocate 1 point + 1 contour
final FTOutline currentOutline = loader.getCurrent().getOutline();
currentOutline.setNPoints(1);
currentOutline.setNContours(1);
currentOutline.getPoints()[0].set(100F, 200F, PosType.INT);
loader.add(); // copy current -> base
final FTOutline baseOutline = loader.getBase().getOutline();
Assertions.assertEquals(1, baseOutline.getNPoints());
Assertions.assertEquals(100F, baseOutline.getPoints()[0].getX(PosType.INT), 0F);
Assertions.assertEquals(200F, baseOutline.getPoints()[0].getY(PosType.INT), 0F);
loader.done();
lib.done();
}
@Test
public void ftNewGlyph() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.setPixelSizes(0L, 16L);
face.loadChar('A');
final FTGlyphSlot slot = face.getGlyph();
final FTGlyph glyph = lib.newGlyph(FTGlyphFormat.OUTLINE);
Assertions.assertEquals(FTGlyphFormat.OUTLINE, glyph.getFormat());
glyph.done();
face.done();
lib.done();
}
@Test
public void ftGetGlyph() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.setPixelSizes(0L, 16L);
face.loadChar('A');
final FTGlyphSlot slot = face.getGlyph();
final FTGlyph glyph = slot.getGlyph();
Assertions.assertEquals(lib, glyph.getLibrary());
glyph.done();
face.done();
lib.done();
}
@Test
public void ftGlyphCopy() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.setPixelSizes(0L, 16L);
face.loadChar('A');
final FTGlyph original = face.getGlyph().getGlyph();
final FTGlyph copy = original.copy();
Assertions.assertEquals(lib, copy.getLibrary());
Assertions.assertTrue(original.getPointer() != copy.getPointer());
copy.done();
original.done();
face.done();
lib.done();
}
@Test
public void ftGlyphTransform() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.setPixelSizes(0L, 16L);
face.loadChar('A');
final FTGlyph glyph = face.getGlyph().getGlyph();
final FTMatrix matrix = new FTMatrix().setRotation(45F);
final FTVector delta = new FTVector().set(10F, 20F, PosType.F26DOT6);
glyph.transform(matrix, delta);
matrix.free();
delta.free();
glyph.done();
face.done();
lib.done();
}
@Test
public void ftGlyphGetCBox() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.setPixelSizes(0L, 16L);
face.loadChar('A');
final FTGlyph glyph = face.getGlyph().getGlyph();
final FTBBox bbox = new FTBBox();
final FTGlyphBBoxMode bboxMode = FTGlyphBBoxMode.TRUNCATE;
glyph.getCBox(bboxMode, bbox);
Assertions.assertTrue(bbox.getXMin(PosType.F26DOT6) < bbox.getXMax(bboxMode.posType));
Assertions.assertTrue(bbox.getYMin(PosType.F26DOT6) < bbox.getYMax(bboxMode.posType));
bbox.free();
glyph.done();
face.done();
lib.done();
}
@Test
public void ftGlyphToBitmap() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.setPixelSizes(0L, 16L);
face.loadChar('A');
final FTGlyph glyph = face.getGlyph().getGlyph();
final FTBitmapGlyph bitmapGlyph = glyph.toBitmap(FTRenderMode.NORMAL, new FTVector(), false);
final FTBitmap bitmap = bitmapGlyph.getBitmap();
Assertions.assertTrue(bitmap.getWidth() > 0L);
Assertions.assertTrue(bitmap.getRows() > 0L);
glyph.done();
face.done();
lib.done();
}
@Test
public void ftDoneGlyph() {
final FTLibrary lib = new FTLibrary();
final FTFace face = lib.newMemoryFace(Resource.internal("/droidsans.ttf").readByteBuffer(), 0);
face.setPixelSizes(0L, 16L);
face.loadChar('A');
final FTGlyph glyph = face.getGlyph().getGlyph();
glyph.done();
face.done();
lib.done();
}
@Test
public void ftMatrixMultiply() {
final FTMatrix a = new FTMatrix().setScale(2F);
final FTMatrix b = new FTMatrix().setScale(2F);
a.multiply(b);
Assertions.assertEquals(4F, b.getXX(), 0F);
Assertions.assertEquals(4F, b.getYY(), 0F);
a.free();
b.free();
}
@Test
public void ftMatrixInvert() {
final FTMatrix matrix = new FTMatrix().setScale(2F);
matrix.invert();
Assertions.assertEquals(0.5F, matrix.getXX(), 0F);
matrix.free();
}
@Test
public void ftOutlineDecompose() {
final FTLibrary lib = new FTLibrary();
final FTStroker stroker = lib.newStroker();