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