1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #ifndef _SFNT_H_
22 #define _SFNT_H_
23
24 #include <stdint.h>
25 #include <stddef.h>
26 #include <setjmp.h>
27
28 #include <sys/types.h>
29
30
31
32
33
34
35
36
37
38 enum sfnt_table
39 {
40 SFNT_TABLE_CMAP,
41 SFNT_TABLE_GLYF,
42 SFNT_TABLE_HEAD,
43 SFNT_TABLE_HHEA,
44 SFNT_TABLE_HMTX,
45 SFNT_TABLE_LOCA,
46 SFNT_TABLE_MAXP,
47 SFNT_TABLE_NAME,
48 SFNT_TABLE_META,
49 SFNT_TABLE_CVT ,
50 SFNT_TABLE_FPGM,
51 SFNT_TABLE_PREP,
52 SFNT_TABLE_FVAR,
53 SFNT_TABLE_GVAR,
54 SFNT_TABLE_CVAR,
55 SFNT_TABLE_AVAR,
56 };
57
58 #define SFNT_ENDOF(type, field, type1) \
59 ((size_t) offsetof (type, field) + sizeof (type1))
60
61
62
63
64
65
66
67
68
69
70
71
72
73 struct sfnt_offset_subtable
74 {
75
76 uint32_t scaler_type;
77
78
79 uint16_t num_tables;
80
81
82 uint16_t search_range;
83
84
85 uint16_t entry_selector;
86
87
88 uint16_t range_shift;
89
90
91 struct sfnt_table_directory *subtables;
92 };
93
94
95
96
97 struct sfnt_table_directory
98 {
99
100 uint32_t tag;
101
102
103 uint32_t checksum;
104
105
106 uint32_t offset;
107
108
109 uint32_t length;
110 };
111
112 enum sfnt_scaler_type
113 {
114 SFNT_SCALER_TRUE = 0x74727565,
115 SFNT_SCALER_VER1 = 0x00010000,
116 SFNT_SCALER_TYP1 = 0x74797031,
117 SFNT_SCALER_OTTO = 0x4F54544F,
118 };
119
120 typedef int32_t sfnt_fixed;
121 typedef int16_t sfnt_fword;
122 typedef uint16_t sfnt_ufword;
123
124 #define sfnt_coerce_fixed(fixed) ((sfnt_fixed) (fixed) / 65535.0)
125
126 typedef unsigned int sfnt_glyph;
127 typedef unsigned int sfnt_char;
128
129 struct sfnt_head_table
130 {
131
132 sfnt_fixed version;
133
134
135 sfnt_fixed revision;
136
137
138 uint32_t checksum_adjustment;
139
140
141 uint32_t magic;
142
143
144 uint16_t flags;
145
146
147 uint16_t units_per_em;
148
149
150 uint32_t created_high, created_low;
151
152
153 uint32_t modified_high, modified_low;
154
155
156 sfnt_fword xmin, ymin, xmax, ymax;
157
158
159 uint16_t mac_style;
160
161
162 uint16_t lowest_rec_ppem;
163
164
165 int16_t font_direction_hint;
166
167
168 int16_t index_to_loc_format;
169
170
171 int16_t glyph_data_format;
172 };
173
174 struct sfnt_hhea_table
175 {
176
177 sfnt_fixed version;
178
179
180 sfnt_fword ascent, descent;
181
182
183 sfnt_fword line_gap;
184
185
186 sfnt_ufword advance_width_max;
187
188
189 sfnt_fword min_left_side_bearing, min_right_side_bearing;
190
191
192 sfnt_fword x_max_extent;
193
194
195 int16_t caret_slope_rise, caret_slope_run;
196
197
198 sfnt_fword caret_offset;
199
200
201 int16_t reserved1, reserved2, reserved3, reserved4;
202
203
204 int16_t metric_data_format;
205
206
207 uint16_t num_of_long_hor_metrics;
208 };
209
210 struct sfnt_cmap_table
211 {
212
213 uint16_t version;
214
215
216 uint16_t num_subtables;
217 };
218
219 enum sfnt_platform_id
220 {
221 SFNT_PLATFORM_UNICODE = 0,
222 SFNT_PLATFORM_MACINTOSH = 1,
223 SFNT_PLATFORM_RESERVED = 2,
224 SFNT_PLATFORM_MICROSOFT = 3,
225 };
226
227 enum sfnt_unicode_platform_specific_id
228 {
229 SFNT_UNICODE_1_0 = 0,
230 SFNT_UNICODE_1_1 = 1,
231 SFNT_UNICODE_ISO_10646_1993 = 2,
232 SFNT_UNICODE_2_0_BMP = 3,
233 SFNT_UNICODE_2_0 = 4,
234 SFNT_UNICODE_VARIATION_SEQUENCES = 5,
235 SFNT_UNICODE_LAST_RESORT = 6,
236 };
237
238 enum sfnt_macintosh_platform_specific_id
239 {
240 SFNT_MACINTOSH_ROMAN = 0,
241 SFNT_MACINTOSH_JAPANESE = 1,
242 SFNT_MACINTOSH_TRADITIONAL_CHINESE = 2,
243 SFNT_MACINTOSH_KOREAN = 3,
244 SFNT_MACINTOSH_ARABIC = 4,
245 SFNT_MACINTOSH_HEBREW = 5,
246 SFNT_MACINTOSH_GREEK = 6,
247 SFNT_MACINTOSH_RUSSIAN = 7,
248 SFNT_MACINTOSH_RSYMBOL = 8,
249 SFNT_MACINTOSH_DEVANGARI = 9,
250 SFNT_MACINTOSH_GURMUKHI = 10,
251 SFNT_MACINTOSH_GUJARATI = 11,
252 SFNT_MACINTOSH_ORIYA = 12,
253 SFNT_MACINTOSH_BENGALI = 13,
254 SFNT_MACINTOSH_TAMIL = 14,
255 SFNT_MACINTOSH_TELUGU = 15,
256 SFNT_MACINTOSH_KANNADA = 16,
257 SFNT_MACINTOSH_MALAYALAM = 17,
258 SFNT_MACINTOSH_SINHALESE = 18,
259 SFNT_MACINTOSH_BURMESE = 19,
260 SFNT_MACINTOSH_KHMER = 20,
261 SFNT_MACINTOSH_THAI = 21,
262 SFNT_MACINTOSH_LAOTIAN = 22,
263 SFNT_MACINTOSH_GEORGIAN = 23,
264 SFNT_MACINTOSH_ARMENIAN = 24,
265 SFNT_MACINTOSH_SIMPLIFIED_CHINESE = 25,
266 SFNT_MACINTOSH_TIBETIAN = 26,
267 SFNT_MACINTOSH_MONGOLIAN = 27,
268 SFNT_MACINTOSH_GEEZ = 28,
269 SFNT_MACINTOSH_SLAVIC = 29,
270 SFNT_MACINTOSH_VIETNAMESE = 30,
271 SFNT_MACINTOSH_SINDHI = 31,
272 SFNT_MACINTOSH_UNINTERPRETED = 32,
273 };
274
275 enum sfnt_microsoft_platform_specific_id
276 {
277 SFNT_MICROSOFT_SYMBOL = 0,
278 SFNT_MICROSOFT_UNICODE_BMP = 1,
279 SFNT_MICROSOFT_SHIFT_JIS = 2,
280 SFNT_MICROSOFT_PRC = 3,
281 SFNT_MICROSOFT_BIG_FIVE = 4,
282 SFNT_MICROSOFT_WANSUNG = 5,
283 SFNT_MICROSOFT_JOHAB = 6,
284 SFNT_MICROSOFT_UNICODE_UCS_4 = 10,
285 };
286
287 struct sfnt_cmap_encoding_subtable
288 {
289
290 uint16_t platform_id;
291
292
293 uint16_t platform_specific_id;
294
295
296 uint32_t offset;
297 };
298
299 struct sfnt_cmap_encoding_subtable_data
300 {
301
302 uint16_t format, length;
303 };
304
305 struct sfnt_cmap_format_0
306 {
307
308 uint16_t format;
309
310
311 uint16_t length;
312
313
314 uint16_t language;
315
316
317 uint8_t glyph_index_array[256];
318 };
319
320 struct sfnt_cmap_format_2_subheader
321 {
322 uint16_t first_code;
323 uint16_t entry_count;
324 int16_t id_delta;
325 uint16_t id_range_offset;
326 };
327
328 struct sfnt_cmap_format_2
329 {
330
331 uint16_t format;
332
333
334 uint16_t length;
335
336
337 uint16_t language;
338
339
340 uint16_t sub_header_keys[256];
341
342
343 struct sfnt_cmap_format_2_subheader *subheaders;
344 uint16_t *glyph_index_array;
345 uint16_t num_glyphs;
346 };
347
348 struct sfnt_cmap_format_4
349 {
350
351 uint16_t format;
352
353
354 uint16_t length;
355
356
357 uint16_t language;
358
359
360 uint16_t seg_count_x2;
361
362
363 uint16_t search_range;
364
365
366 uint16_t entry_selector;
367
368
369 uint16_t *end_code;
370 uint16_t *reserved_pad;
371 uint16_t *start_code;
372 int16_t *id_delta;
373 int16_t *id_range_offset;
374 uint16_t *glyph_index_array;
375
376
377 size_t glyph_index_size;
378 };
379
380 struct sfnt_cmap_format_6
381 {
382
383 uint16_t format;
384
385
386 uint16_t length;
387
388
389 uint16_t language;
390
391
392 uint16_t first_code;
393
394
395 uint16_t entry_count;
396
397
398 uint16_t *glyph_index_array;
399 };
400
401 struct sfnt_cmap_format_8_or_12_group
402 {
403 uint32_t start_char_code;
404 uint32_t end_char_code;
405 uint32_t start_glyph_code;
406 };
407
408 struct sfnt_cmap_format_8
409 {
410
411 uint16_t format;
412
413
414 uint16_t reserved;
415
416
417 uint32_t length;
418
419
420 uint32_t language;
421
422
423
424
425 uint8_t is32[65536];
426
427
428 uint32_t num_groups;
429
430
431 struct sfnt_cmap_format_8_or_12_group *groups;
432 };
433
434
435
436 struct sfnt_cmap_format_12
437 {
438
439 uint16_t format;
440
441
442 uint16_t reserved;
443
444
445 uint32_t length;
446
447
448 uint32_t language;
449
450
451 uint32_t num_groups;
452
453
454 struct sfnt_cmap_format_8_or_12_group *groups;
455 };
456
457 struct sfnt_cmap_format_14
458 {
459
460 uint16_t format;
461
462
463 uint32_t length;
464
465
466 uint16_t num_var_selector_records;
467
468
469 off_t offset;
470
471
472 struct sfnt_variation_selector_record *records;
473 };
474
475 struct sfnt_variation_selector_record
476 {
477
478 unsigned int var_selector;
479
480
481 uint32_t default_uvs_offset;
482
483
484 uint32_t nondefault_uvs_offset;
485 };
486
487 struct sfnt_maxp_table
488 {
489
490 sfnt_fixed version;
491
492
493
494 uint16_t num_glyphs;
495
496
497
498 uint16_t max_points;
499
500
501 uint16_t max_contours;
502
503
504 uint16_t max_composite_points;
505
506
507 uint16_t max_composite_contours;
508
509
510
511 uint16_t max_zones;
512
513
514 uint16_t max_twilight_points;
515
516
517 uint16_t max_storage;
518
519
520 uint16_t max_function_defs;
521
522
523 uint16_t max_instruction_defs;
524
525
526
527
528 uint16_t max_stack_elements;
529
530
531 uint16_t max_size_of_instructions;
532
533
534
535 uint16_t max_component_elements;
536
537
538 uint16_t max_component_depth;
539 };
540
541 struct sfnt_loca_table_short
542 {
543
544 uint16_t *offsets;
545
546
547 size_t num_offsets;
548 };
549
550 struct sfnt_loca_table_long
551 {
552
553 uint32_t *offsets;
554
555
556 size_t num_offsets;
557 };
558
559 struct sfnt_glyf_table
560 {
561
562 size_t size;
563
564
565 unsigned char *glyphs;
566
567
568
569 unsigned char *start;
570 };
571
572 struct sfnt_simple_glyph
573 {
574
575 size_t number_of_points;
576
577
578 uint16_t *restrict end_pts_of_contours;
579
580
581 uint16_t instruction_length;
582
583
584 uint8_t *restrict instructions;
585
586
587 uint8_t *restrict flags;
588
589
590 int16_t *restrict x_coordinates;
591
592
593 int16_t *restrict y_coordinates;
594
595
596 int16_t *restrict y_coordinates_end;
597 };
598
599 struct sfnt_compound_glyph_component
600 {
601
602 uint16_t flags;
603
604
605 uint16_t glyph_index;
606
607
608
609 union {
610 uint8_t a;
611 int8_t b;
612 uint16_t c;
613 int16_t d;
614 } argument1;
615
616
617
618 union {
619 uint8_t a;
620 int8_t b;
621 uint16_t c;
622 int16_t d;
623 } argument2;
624
625
626 union {
627 uint16_t scale;
628 struct {
629 uint16_t xscale;
630 uint16_t yscale;
631 } a;
632 struct {
633 uint16_t xscale;
634 uint16_t scale01;
635 uint16_t scale10;
636 uint16_t yscale;
637 } b;
638 } u;
639 };
640
641 struct sfnt_compound_glyph
642 {
643
644 struct sfnt_compound_glyph_component *components;
645
646
647 size_t num_components;
648
649
650 uint8_t *instructions;
651
652
653 uint16_t instruction_length;
654 };
655
656 struct sfnt_glyph
657 {
658
659 int16_t number_of_contours;
660
661
662 sfnt_fword xmin, ymin, xmax, ymax;
663
664
665 sfnt_fword advance_distortion;
666
667
668 sfnt_fword origin_distortion;
669
670
671
672 struct sfnt_simple_glyph *simple;
673 struct sfnt_compound_glyph *compound;
674 };
675
676
677
678
679
680 struct sfnt_point
681 {
682
683 sfnt_fixed x, y;
684 };
685
686 typedef void (*sfnt_move_to_proc) (struct sfnt_point, void *);
687 typedef void (*sfnt_line_to_proc) (struct sfnt_point, void *);
688 typedef void (*sfnt_curve_to_proc) (struct sfnt_point,
689 struct sfnt_point,
690 void *);
691
692 typedef struct sfnt_glyph *(*sfnt_get_glyph_proc) (sfnt_glyph, void *,
693 bool *);
694 typedef void (*sfnt_free_glyph_proc) (struct sfnt_glyph *, void *);
695
696
697
698
699
700 struct sfnt_glyph_outline_command
701 {
702
703 int flags;
704
705
706 sfnt_fixed x, y;
707 };
708
709
710
711
712 struct sfnt_glyph_outline
713 {
714
715 struct sfnt_glyph_outline_command *outline;
716
717
718 size_t outline_size, outline_used;
719
720
721
722 sfnt_fixed xmin, ymin, xmax, ymax;
723
724
725
726 sfnt_fixed origin;
727
728
729 short refcount;
730 };
731
732 enum sfnt_glyph_outline_flags
733 {
734 SFNT_GLYPH_OUTLINE_LINETO = (1 << 1),
735 };
736
737
738
739
740
741 struct sfnt_raster
742 {
743
744 unsigned char *cells;
745
746
747 unsigned short width, height;
748
749
750
751 short offx, offy;
752
753
754 unsigned short stride;
755
756
757 unsigned short refcount;
758 };
759
760 struct sfnt_edge
761 {
762
763 struct sfnt_edge *next;
764
765
766 int winding;
767
768
769 sfnt_fixed x, top, bottom;
770
771
772 sfnt_fixed step_x;
773 };
774
775
776
777
778
779 enum
780 {
781 SFNT_POLY_SHIFT = 3,
782 SFNT_POLY_SAMPLE = (1 << SFNT_POLY_SHIFT),
783 SFNT_POLY_MASK = (SFNT_POLY_SAMPLE - 1),
784 SFNT_POLY_STEP = (0x10000 >> SFNT_POLY_SHIFT),
785 SFNT_POLY_START = (SFNT_POLY_STEP >> 1),
786 };
787
788
789
790
791
792 struct sfnt_long_hor_metric
793 {
794 uint16_t advance_width;
795 int16_t left_side_bearing;
796 };
797
798 struct sfnt_hmtx_table
799 {
800
801 struct sfnt_long_hor_metric *h_metrics;
802
803
804 int16_t *left_side_bearing;
805 };
806
807
808
809
810
811 struct sfnt_glyph_metrics
812 {
813
814
815
816
817
818 sfnt_fixed lbearing;
819
820
821
822
823
824 sfnt_fixed advance;
825 };
826
827
828
829
830
831 struct sfnt_name_record
832 {
833
834 uint16_t platform_id;
835
836
837 uint16_t platform_specific_id;
838
839
840 uint16_t language_id;
841
842
843 uint16_t name_id;
844
845
846 uint16_t length;
847
848
849 uint16_t offset;
850 };
851
852 struct sfnt_name_table
853 {
854
855 uint16_t format;
856
857
858 uint16_t count;
859
860
861 uint16_t string_offset;
862
863
864 struct sfnt_name_record *name_records;
865
866
867 unsigned char *data;
868 };
869
870
871
872
873 enum sfnt_name_identifier_code
874 {
875 SFNT_NAME_COPYRIGHT_NOTICE = 0,
876 SFNT_NAME_FONT_FAMILY = 1,
877 SFNT_NAME_FONT_SUBFAMILY = 2,
878 SFNT_NAME_UNIQUE_SUBFAMILY_IDENTIFICATION = 3,
879 SFNT_NAME_FULL_NAME = 4,
880 SFNT_NAME_NAME_TABLE_VERSION = 5,
881 SFNT_NAME_POSTSCRIPT_NAME = 6,
882 SFNT_NAME_TRADEMARK_NOTICE = 7,
883 SFNT_NAME_MANUFACTURER_NAME = 8,
884 SFNT_NAME_DESIGNER = 9,
885 SFNT_NAME_DESCRIPTION = 10,
886 SFNT_NAME_FONT_VENDOR_URL = 11,
887 SFNT_NAME_FONT_DESIGNER_URL = 12,
888 SFNT_NAME_LICENSE_DESCRIPTION = 13,
889 SFNT_NAME_LICENSE_INFORMATION_URL = 14,
890 SFNT_NAME_PREFERRED_FAMILY = 16,
891 SFNT_NAME_PREFERRED_SUBFAMILY = 17,
892 SFNT_NAME_COMPATIBLE_FULL = 18,
893 SFNT_NAME_SAMPLE_TEXT = 19,
894 SFNT_NAME_VARIATIONS_POSTSCRIPT_NAME_PREFIX = 25,
895 };
896
897 struct sfnt_meta_data_map
898 {
899
900 uint32_t tag;
901
902
903 uint32_t data_offset;
904
905
906 uint32_t data_length;
907 };
908
909 struct sfnt_meta_table
910 {
911
912 uint32_t version;
913
914
915 uint32_t flags;
916
917
918
919 uint32_t data_offset;
920
921
922 uint32_t num_data_maps;
923
924
925 struct sfnt_meta_data_map *data_maps;
926
927
928 unsigned char *data;
929 };
930
931 enum sfnt_meta_data_tag
932 {
933 SFNT_META_DATA_TAG_DLNG = 0x646c6e67,
934 SFNT_META_DATA_TAG_SLNG = 0x736c6e67,
935 };
936
937
938
939
940
941 struct sfnt_ttc_header
942 {
943
944 uint32_t ttctag;
945
946
947 uint32_t version;
948
949
950 uint32_t num_fonts;
951
952
953
954 uint32_t *offset_table;
955
956
957
958 uint32_t ul_dsig_tag;
959
960
961
962 uint32_t ul_dsig_length;
963
964
965
966 uint32_t ul_dsig_offset;
967 };
968
969 enum sfnt_ttc_tag
970 {
971 SFNT_TTC_TTCF = 0x74746366,
972 SFNT_TTC_DSIG = 0x44534947,
973 };
974
975
976
977
978
979 struct sfnt_default_uvs_table
980 {
981
982 uint32_t num_unicode_value_ranges;
983
984
985 struct sfnt_unicode_value_range *ranges;
986 };
987
988 struct sfnt_unicode_value_range
989 {
990
991 unsigned int start_unicode_value;
992
993
994 unsigned char additional_count;
995 };
996
997 struct sfnt_nondefault_uvs_table
998 {
999
1000 uint32_t num_uvs_mappings;
1001
1002
1003 struct sfnt_uvs_mapping *mappings;
1004 };
1005
1006 struct sfnt_uvs_mapping
1007 {
1008
1009 unsigned int unicode_value;
1010
1011
1012 uint16_t base_character_value;
1013 };
1014
1015 struct sfnt_mapped_variation_selector_record
1016 {
1017
1018 unsigned int selector;
1019
1020
1021 struct sfnt_default_uvs_table *default_uvs;
1022
1023
1024 struct sfnt_nondefault_uvs_table *nondefault_uvs;
1025 };
1026
1027
1028
1029
1030 struct sfnt_table_offset_rec
1031 {
1032
1033 off_t offset;
1034
1035
1036 bool is_nondefault_table;
1037
1038
1039 void *table;
1040 };
1041
1042 struct sfnt_uvs_context
1043 {
1044
1045 size_t num_records, nmemb;
1046
1047
1048 struct sfnt_table_offset_rec *tables;
1049
1050
1051
1052 struct sfnt_mapped_variation_selector_record *records;
1053 };
1054
1055
1056
1057 #if defined HAVE_MMAP && !defined TEST
1058
1059
1060
1061 struct sfnt_mapped_table
1062 {
1063
1064 void *data;
1065
1066
1067 void *mapping;
1068
1069
1070 size_t length, size;
1071 };
1072
1073 #endif
1074
1075
1076
1077
1078
1079
1080
1081 typedef int16_t sfnt_f2dot14;
1082
1083
1084 struct sfnt_cvt_table;
1085
1086 struct sfnt_variation_axis
1087 {
1088
1089 uint32_t axis_tag;
1090
1091
1092 sfnt_fixed min_value;
1093
1094
1095 sfnt_fixed default_value;
1096
1097
1098 sfnt_fixed max_value;
1099
1100
1101 uint16_t flags;
1102
1103
1104
1105 uint16_t name_id;
1106 };
1107
1108 struct sfnt_instance
1109 {
1110
1111 uint16_t name_id;
1112
1113
1114 uint16_t flags;
1115
1116
1117 uint16_t ps_name_id;
1118
1119
1120 sfnt_fixed *coords;
1121 };
1122
1123 struct sfnt_fvar_table
1124 {
1125
1126 uint16_t major_version;
1127
1128
1129 uint16_t minor_version;
1130
1131
1132
1133 uint16_t offset_to_data;
1134
1135
1136 uint16_t count_size_pairs;
1137
1138
1139 uint16_t axis_count;
1140
1141
1142
1143 uint16_t axis_size;
1144
1145
1146
1147 uint16_t instance_count;
1148
1149
1150 uint16_t instance_size;
1151
1152
1153 struct sfnt_variation_axis *axis;
1154 struct sfnt_instance *instance;
1155 };
1156
1157 struct sfnt_short_frac_correspondence
1158 {
1159
1160 sfnt_f2dot14 from_coord;
1161
1162
1163 sfnt_f2dot14 to_coord;
1164 };
1165
1166 struct sfnt_short_frac_segment
1167 {
1168
1169 uint16_t pair_count;
1170
1171
1172 struct sfnt_short_frac_correspondence *correspondence;
1173 };
1174
1175 struct sfnt_avar_table
1176 {
1177
1178 sfnt_fixed version;
1179
1180
1181
1182 int32_t axis_count;
1183
1184
1185 struct sfnt_short_frac_segment *segments;
1186 };
1187
1188 struct sfnt_tuple_variation
1189 {
1190
1191 uint16_t *points;
1192
1193
1194 sfnt_fword *deltas;
1195
1196
1197
1198 sfnt_f2dot14 *coordinates;
1199
1200
1201 sfnt_f2dot14 *restrict intermediate_start;
1202
1203
1204 sfnt_f2dot14 *restrict intermediate_end;
1205
1206
1207
1208
1209
1210 uint16_t num_points;
1211 };
1212
1213 struct sfnt_cvar_table
1214 {
1215
1216 sfnt_fixed version;
1217
1218
1219 uint16_t tuple_count;
1220
1221
1222 uint16_t data_offset;
1223
1224
1225 struct sfnt_tuple_variation *variation;
1226 };
1227
1228 struct sfnt_gvar_table
1229 {
1230
1231 uint16_t version;
1232
1233
1234 uint16_t reserved;
1235
1236
1237
1238 uint16_t axis_count;
1239
1240
1241 uint16_t shared_coord_count;
1242
1243
1244
1245 uint32_t offset_to_coord;
1246
1247
1248
1249 uint16_t glyph_count;
1250
1251
1252
1253
1254 uint16_t flags;
1255
1256
1257
1258 uint32_t offset_to_data;
1259
1260
1261 size_t data_size;
1262
1263
1264
1265
1266 union {
1267 uint16_t *offset_word;
1268 uint32_t *offset_long;
1269 } u;
1270
1271
1272 sfnt_f2dot14 *global_coords;
1273 unsigned char *glyph_variation_data;
1274 };
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293 struct sfnt_blend
1294 {
1295
1296
1297 struct sfnt_fvar_table *fvar;
1298
1299
1300 struct sfnt_gvar_table *gvar;
1301
1302
1303
1304 struct sfnt_avar_table *avar;
1305
1306
1307
1308 struct sfnt_cvar_table *cvar;
1309
1310
1311 sfnt_fixed *coords;
1312
1313
1314 sfnt_fixed *norm_coords;
1315 };
1316
1317 struct sfnt_metrics_distortion
1318 {
1319
1320 sfnt_fword origin;
1321
1322
1323 sfnt_fword advance;
1324 };
1325
1326
1327
1328 #define SFNT_CEIL_FIXED(fixed) (((fixed) + 0177777) & 037777600000)
1329 #define SFNT_FLOOR_FIXED(fixed) ((fixed) & 037777600000)
1330
1331
1332
1333
1334
1335
1336
1337 #ifndef TEST
1338
1339 extern struct sfnt_offset_subtable *sfnt_read_table_directory (int);
1340
1341 #define PROTOTYPE \
1342 int, struct sfnt_offset_subtable *, \
1343 struct sfnt_cmap_encoding_subtable **, \
1344 struct sfnt_cmap_encoding_subtable_data ***
1345 extern struct sfnt_cmap_table *sfnt_read_cmap_table (PROTOTYPE);
1346 #undef PROTOTYPE
1347
1348 extern sfnt_glyph sfnt_lookup_glyph (sfnt_char,
1349 struct sfnt_cmap_encoding_subtable_data *);
1350
1351 #define PROTOTYPE int, struct sfnt_offset_subtable *
1352 extern struct sfnt_head_table *sfnt_read_head_table (PROTOTYPE);
1353 extern struct sfnt_hhea_table *sfnt_read_hhea_table (PROTOTYPE);
1354 extern struct sfnt_loca_table_short *sfnt_read_loca_table_short (PROTOTYPE);
1355 extern struct sfnt_loca_table_long *sfnt_read_loca_table_long (PROTOTYPE);
1356 extern struct sfnt_maxp_table *sfnt_read_maxp_table (PROTOTYPE);
1357 extern struct sfnt_glyf_table *sfnt_read_glyf_table (PROTOTYPE);
1358
1359 #ifdef HAVE_MMAP
1360 extern struct sfnt_glyf_table *sfnt_map_glyf_table (PROTOTYPE);
1361 extern int sfnt_unmap_glyf_table (struct sfnt_glyf_table *);
1362 #endif
1363 #undef PROTOTYPE
1364
1365 extern struct sfnt_glyph *sfnt_read_glyph (sfnt_glyph, struct sfnt_glyf_table *,
1366 struct sfnt_loca_table_short *,
1367 struct sfnt_loca_table_long *);
1368 extern void sfnt_free_glyph (struct sfnt_glyph *);
1369
1370 #define PROTOTYPE \
1371 struct sfnt_glyph *, \
1372 sfnt_fixed, \
1373 struct sfnt_glyph_metrics *, \
1374 sfnt_get_glyph_proc, \
1375 sfnt_free_glyph_proc, \
1376 void *
1377 extern struct sfnt_glyph_outline *sfnt_build_glyph_outline (PROTOTYPE);
1378 #undef PROTOTYPE
1379
1380 extern void sfnt_prepare_raster (struct sfnt_raster *,
1381 struct sfnt_glyph_outline *);
1382
1383 #define PROTOTYPE struct sfnt_glyph_outline *
1384 extern struct sfnt_raster *sfnt_raster_glyph_outline (PROTOTYPE);
1385 #undef PROTOTYPE
1386
1387 #define PROTOTYPE \
1388 int, \
1389 struct sfnt_offset_subtable *, \
1390 struct sfnt_hhea_table *, \
1391 struct sfnt_maxp_table *
1392 extern struct sfnt_hmtx_table *sfnt_read_hmtx_table (PROTOTYPE);
1393 #undef PROTOTYPE
1394
1395 extern int sfnt_lookup_glyph_metrics (sfnt_glyph, int,
1396 struct sfnt_glyph_metrics *,
1397 struct sfnt_hmtx_table *,
1398 struct sfnt_hhea_table *,
1399 struct sfnt_head_table *,
1400 struct sfnt_maxp_table *);
1401
1402 extern void sfnt_scale_metrics (struct sfnt_glyph_metrics *,
1403 sfnt_fixed);
1404 extern sfnt_fixed sfnt_get_scale (struct sfnt_head_table *, int);
1405
1406 #define PROTOTYPE int, struct sfnt_offset_subtable *
1407 extern struct sfnt_name_table *sfnt_read_name_table (PROTOTYPE);
1408 #undef PROTOTYPE
1409
1410 extern unsigned char *sfnt_find_name (struct sfnt_name_table *,
1411 enum sfnt_name_identifier_code,
1412 struct sfnt_name_record *);
1413
1414 #define PROTOTYPE int, struct sfnt_offset_subtable *
1415 extern struct sfnt_meta_table *sfnt_read_meta_table (PROTOTYPE);
1416 #undef PROTOTYPE
1417
1418 extern char *sfnt_find_metadata (struct sfnt_meta_table *,
1419 enum sfnt_meta_data_tag,
1420 struct sfnt_meta_data_map *);
1421
1422 extern struct sfnt_ttc_header *sfnt_read_ttc_header (int);
1423
1424
1425
1426 #define PROTOTYPE struct sfnt_cmap_format_14 *, int
1427
1428 extern struct sfnt_uvs_context *sfnt_create_uvs_context (PROTOTYPE);
1429
1430 #undef PROTOTYPE
1431
1432 extern void sfnt_free_uvs_context (struct sfnt_uvs_context *);
1433
1434 #define PROTOTYPE struct sfnt_nondefault_uvs_table *, sfnt_char
1435
1436 extern sfnt_glyph sfnt_variation_glyph_for_char (PROTOTYPE);
1437
1438 #undef PROTOTYPE
1439
1440
1441
1442 #ifdef HAVE_MMAP
1443
1444 extern int sfnt_map_table (int, struct sfnt_offset_subtable *,
1445 uint32_t, struct sfnt_mapped_table *);
1446 extern int sfnt_unmap_table (struct sfnt_mapped_table *);
1447
1448 #endif
1449
1450
1451
1452 extern void *sfnt_read_table (int, struct sfnt_offset_subtable *,
1453 uint32_t, size_t *);
1454
1455
1456
1457 #define PROTOTYPE int, struct sfnt_offset_subtable *
1458
1459 extern struct sfnt_fvar_table *sfnt_read_fvar_table (PROTOTYPE);
1460 extern struct sfnt_gvar_table *sfnt_read_gvar_table (PROTOTYPE);
1461 extern struct sfnt_avar_table *sfnt_read_avar_table (PROTOTYPE);
1462
1463 #undef PROTOTYPE
1464
1465 #define PROTOTYPE \
1466 int, \
1467 struct sfnt_offset_subtable *, \
1468 struct sfnt_fvar_table *, \
1469 struct sfnt_cvt_table *
1470
1471 extern struct sfnt_cvar_table *sfnt_read_cvar_table (PROTOTYPE);
1472
1473 #undef PROTOTYPE
1474
1475
1476
1477 extern void sfnt_init_blend (struct sfnt_blend *,
1478 struct sfnt_fvar_table *,
1479 struct sfnt_gvar_table *,
1480 struct sfnt_avar_table *,
1481 struct sfnt_cvar_table *);
1482 extern void sfnt_free_blend (struct sfnt_blend *);
1483 extern void sfnt_normalize_blend (struct sfnt_blend *);
1484
1485
1486
1487 extern int sfnt_vary_simple_glyph (struct sfnt_blend *, sfnt_glyph,
1488 struct sfnt_glyph *,
1489 struct sfnt_metrics_distortion *);
1490 extern int sfnt_vary_compound_glyph (struct sfnt_blend *, sfnt_glyph,
1491 struct sfnt_glyph *,
1492 struct sfnt_metrics_distortion *);
1493
1494 #endif
1495
1496
1497
1498
1499
1500
1501
1502
1503 struct sfnt_cvt_table
1504 {
1505
1506 size_t num_elements;
1507
1508
1509 sfnt_fword *values;
1510 };
1511
1512 struct sfnt_fpgm_table
1513 {
1514
1515 size_t num_instructions;
1516
1517
1518 unsigned char *instructions;
1519 };
1520
1521 struct sfnt_prep_table
1522 {
1523
1524
1525 size_t num_instructions;
1526
1527
1528 unsigned char *instructions;
1529 };
1530
1531
1532
1533
1534
1535
1536 typedef int32_t sfnt_f26dot6;
1537
1538
1539 typedef int32_t sfnt_f18dot14;
1540
1541
1542
1543
1544
1545 struct sfnt_unit_vector
1546 {
1547
1548 sfnt_f2dot14 x, y;
1549 };
1550
1551 struct sfnt_interpreter_definition
1552 {
1553
1554 uint16_t opcode;
1555
1556
1557 uint16_t instruction_count;
1558
1559
1560
1561
1562
1563 unsigned char *instructions;
1564 };
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583 struct sfnt_interpreter_zone
1584 {
1585
1586
1587 size_t num_points;
1588
1589
1590 size_t num_contours;
1591
1592
1593 size_t *contour_end_points;
1594
1595
1596 sfnt_f26dot6 *restrict x_points;
1597
1598
1599 sfnt_f26dot6 *restrict x_current;
1600
1601
1602 sfnt_f26dot6 *restrict y_points;
1603
1604
1605 sfnt_f26dot6 *restrict y_current;
1606
1607
1608 unsigned char *flags;
1609 };
1610
1611 enum
1612 {
1613
1614
1615
1616
1617 SFNT_POINT_PHANTOM = (1 << 1),
1618
1619
1620
1621 SFNT_POINT_TOUCHED_X = (1 << 7),
1622 SFNT_POINT_TOUCHED_Y = (1 << 6),
1623 SFNT_POINT_TOUCHED_BOTH = (SFNT_POINT_TOUCHED_X
1624 | SFNT_POINT_TOUCHED_Y),
1625 };
1626
1627
1628
1629 struct sfnt_interpreter;
1630
1631 struct sfnt_graphics_state
1632 {
1633
1634
1635
1636
1637
1638
1639
1640 sfnt_f26dot6 (*round) (sfnt_f26dot6, struct sfnt_interpreter *);
1641
1642
1643
1644
1645 sfnt_f26dot6 (*project) (sfnt_f26dot6, sfnt_f26dot6,
1646 struct sfnt_interpreter *);
1647
1648
1649
1650
1651 sfnt_f26dot6 (*dual_project) (sfnt_f26dot6, sfnt_f26dot6,
1652 struct sfnt_interpreter *);
1653
1654
1655
1656
1657 void (*move) (sfnt_f26dot6 *restrict,
1658 sfnt_f26dot6 *restrict, size_t,
1659 struct sfnt_interpreter *,
1660 sfnt_f26dot6, unsigned char *);
1661
1662
1663 sfnt_f2dot14 vector_dot_product;
1664
1665
1666
1667
1668
1669
1670
1671
1672 bool auto_flip;
1673
1674
1675
1676
1677
1678 sfnt_f26dot6 cvt_cut_in;
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691 unsigned short delta_base;
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705 unsigned short delta_shift;
1706
1707
1708
1709
1710
1711 struct sfnt_unit_vector dual_projection_vector;
1712
1713
1714
1715 struct sfnt_unit_vector freedom_vector;
1716
1717
1718
1719
1720
1721 unsigned char instruct_control;
1722
1723
1724
1725
1726
1727 unsigned short loop;
1728
1729
1730
1731 sfnt_f26dot6 minimum_distance;
1732
1733
1734
1735 struct sfnt_unit_vector projection_vector;
1736
1737
1738
1739
1740 int round_state;
1741
1742
1743
1744
1745 uint16_t rp0, rp1, rp2;
1746
1747
1748
1749 int scan_control;
1750
1751
1752
1753
1754 sfnt_f26dot6 sw_cut_in;
1755
1756
1757
1758
1759
1760 sfnt_f26dot6 single_width_value;
1761
1762
1763 int zp0, zp1, zp2;
1764 };
1765
1766 struct sfnt_interpreter
1767 {
1768
1769 uint16_t max_stack_elements;
1770
1771
1772 uint16_t num_instructions;
1773
1774
1775 uint16_t storage_size;
1776
1777
1778 uint16_t function_defs_size;
1779
1780
1781 uint16_t instruction_defs_size;
1782
1783
1784 uint16_t twilight_zone_size;
1785
1786
1787
1788 int IP;
1789
1790
1791 sfnt_fixed scale;
1792
1793
1794 int ppem, point_size;
1795
1796
1797
1798 uint32_t *stack;
1799
1800
1801 uint32_t *SP;
1802
1803
1804 size_t cvt_size;
1805
1806
1807 unsigned char *restrict instructions;
1808
1809
1810 sfnt_f26dot6 *restrict twilight_x, *restrict twilight_y;
1811
1812
1813 sfnt_f26dot6 *restrict twilight_original_x;
1814
1815
1816
1817
1818
1819
1820 sfnt_f26dot6 *restrict twilight_original_y;
1821
1822
1823 struct sfnt_interpreter_zone *glyph_zone;
1824
1825
1826
1827 sfnt_f26dot6 advance_width;
1828
1829
1830 uint32_t *storage;
1831
1832
1833 sfnt_f26dot6 *cvt;
1834
1835
1836 struct sfnt_interpreter_definition *function_defs;
1837
1838
1839 struct sfnt_interpreter_definition *instruction_defs;
1840
1841
1842 struct sfnt_graphics_state state;
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852 sfnt_f26dot6 period, phase, threshold;
1853
1854
1855 int call_depth;
1856
1857
1858 jmp_buf trap;
1859
1860
1861 const char *trap_reason;
1862
1863
1864 int n_axis;
1865
1866
1867 sfnt_fixed *norm_coords;
1868
1869 #ifdef TEST
1870
1871
1872 void (*run_hook) (struct sfnt_interpreter *);
1873
1874
1875
1876 void (*push_hook) (struct sfnt_interpreter *, uint32_t);
1877
1878
1879
1880 void (*pop_hook) (struct sfnt_interpreter *, uint32_t);
1881 #endif
1882 };
1883
1884
1885
1886
1887
1888
1889
1890 struct sfnt_instructed_outline
1891 {
1892
1893
1894 size_t num_points;
1895
1896
1897 size_t num_contours;
1898
1899
1900 size_t *contour_end_points;
1901
1902
1903
1904 sfnt_f26dot6 *restrict x_points, *restrict y_points;
1905
1906
1907 unsigned char *flags;
1908 };
1909
1910
1911
1912
1913
1914 #ifndef TEST
1915
1916 #define PROTOTYPE int, struct sfnt_offset_subtable *
1917
1918 extern struct sfnt_cvt_table *sfnt_read_cvt_table (PROTOTYPE);
1919 extern struct sfnt_fpgm_table *sfnt_read_fpgm_table (PROTOTYPE);
1920 extern struct sfnt_prep_table *sfnt_read_prep_table (PROTOTYPE);
1921
1922 #undef PROTOTYPE
1923
1924 #define PROTOTYPE \
1925 struct sfnt_maxp_table *, \
1926 struct sfnt_cvt_table *, \
1927 struct sfnt_head_table *, \
1928 struct sfnt_fvar_table *, \
1929 int, int
1930
1931 extern struct sfnt_interpreter *sfnt_make_interpreter (PROTOTYPE);
1932
1933 #undef PROTOTYPE
1934
1935 #define PROTOTYPE \
1936 struct sfnt_interpreter *, \
1937 struct sfnt_fpgm_table *
1938
1939 extern const char *sfnt_interpret_font_program (PROTOTYPE);
1940
1941 #undef PROTOTYPE
1942
1943 #define PROTOTYPE \
1944 struct sfnt_interpreter *, \
1945 struct sfnt_prep_table *, \
1946 struct sfnt_graphics_state *
1947
1948 extern const char *sfnt_interpret_control_value_program (PROTOTYPE);
1949
1950 #undef PROTOTYPE
1951
1952 #define PROTOTYPE struct sfnt_instructed_outline *
1953
1954 extern struct sfnt_glyph_outline *sfnt_build_instructed_outline (PROTOTYPE);
1955
1956 #undef PROTOTYPE
1957
1958 #define PROTOTYPE \
1959 struct sfnt_glyph *, \
1960 struct sfnt_interpreter *, \
1961 struct sfnt_glyph_metrics *, \
1962 struct sfnt_instructed_outline **
1963
1964 extern const char *sfnt_interpret_simple_glyph (PROTOTYPE);
1965
1966 #undef PROTOTYPE
1967
1968 #define PROTOTYPE \
1969 struct sfnt_glyph *, \
1970 struct sfnt_interpreter *, \
1971 struct sfnt_graphics_state *, \
1972 sfnt_get_glyph_proc, \
1973 sfnt_free_glyph_proc, \
1974 struct sfnt_hmtx_table *, \
1975 struct sfnt_hhea_table *, \
1976 struct sfnt_maxp_table *, \
1977 struct sfnt_glyph_metrics *, \
1978 void *, \
1979 struct sfnt_instructed_outline **
1980
1981 extern const char *sfnt_interpret_compound_glyph (PROTOTYPE);
1982
1983 #undef PROTOTYPE
1984
1985
1986
1987 extern void sfnt_vary_interpreter (struct sfnt_interpreter *,
1988 struct sfnt_blend *);
1989
1990 #endif
1991
1992
1993
1994 #endif