4 * Copyright (C) 2011-2017 by Werner Lemberg.
6 * This file is part of the ttfautohint library, and may only be used,
7 * modified, and distributed under the terms given in `COPYING'. By
8 * continuing to use, modify, or distribute this file you indicate that you
9 * have read `COPYING' and understand and accept it fully.
11 * The file `COPYING' mentioned in the previous paragraph is distributed
12 * with the ttfautohint library.
22 TA_sfnt_add_table_info(SFNT
* sfnt
)
24 SFNT_Table_Info
* table_infos_new
;
27 sfnt
->num_table_infos
++;
29 (SFNT_Table_Info
*)realloc(sfnt
->table_infos
, sfnt
->num_table_infos
30 * sizeof (SFNT_Table_Info
));
33 sfnt
->num_table_infos
--;
34 return FT_Err_Out_Of_Memory
;
37 sfnt
->table_infos
= table_infos_new
;
39 sfnt
->table_infos
[sfnt
->num_table_infos
- 1] = MISSING
;
46 TA_table_compute_checksum(FT_Byte
* buf
,
49 FT_Byte
* end_buf
= buf
+ len
;
50 FT_ULong checksum
= 0;
53 /* we expect that the length of `buf' is a multiple of 4 */
56 checksum
+= NEXT_ULONG(buf
);
63 TA_font_add_table(FONT
* font
,
64 SFNT_Table_Info
* table_info
,
69 SFNT_Table
* tables_new
;
70 SFNT_Table
* table_last
;
74 tables_new
= (SFNT_Table
*)realloc(font
->tables
,
75 font
->num_tables
* sizeof (SFNT_Table
));
79 return FT_Err_Out_Of_Memory
;
82 font
->tables
= tables_new
;
84 table_last
= &font
->tables
[font
->num_tables
- 1];
86 table_last
->tag
= tag
;
87 table_last
->len
= len
;
88 table_last
->buf
= buf
;
89 table_last
->checksum
= TA_table_compute_checksum(buf
, len
);
90 table_last
->offset
= 0; /* set in `TA_font_compute_table_offsets' */
91 table_last
->data
= NULL
;
92 table_last
->processed
= 0;
94 /* link table and table info */
95 *table_info
= font
->num_tables
- 1;
102 TA_sfnt_sort_table_info(SFNT
* sfnt
,
105 /* Looking into an arbitrary TTF (with a `DSIG' table), tags */
106 /* starting with an uppercase letter are sorted before lowercase */
107 /* letters. In other words, the alphabetical ordering (as */
108 /* mandated by signing a font) is a simple numeric comparison of */
109 /* the 32bit tag values. */
111 SFNT_Table
* tables
= font
->tables
;
113 SFNT_Table_Info
* table_infos
= sfnt
->table_infos
;
114 FT_ULong num_table_infos
= sfnt
->num_table_infos
;
121 for (i
= 1; i
< num_table_infos
; i
++)
123 for (j
= i
; j
> 0; j
--)
125 SFNT_Table_Info swap
;
130 tag1
= (table_infos
[j
] == MISSING
)
132 : tables
[table_infos
[j
]].tag
;
133 tag2
= (table_infos
[j
- 1] == MISSING
)
135 : tables
[table_infos
[j
- 1]].tag
;
140 swap
= table_infos
[j
];
141 table_infos
[j
] = table_infos
[j
- 1];
142 table_infos
[j
- 1] = swap
;
149 TA_font_compute_table_offsets(FONT
* font
,
153 FT_ULong offset
= start
;
156 for (i
= 0; i
< font
->num_tables
; i
++)
158 SFNT_Table
* table
= &font
->tables
[i
];
161 table
->offset
= offset
;
163 /* table offsets must be multiples of 4; */
164 /* this also fits the actual buffer lengths */
165 offset
+= (table
->len
+ 3) & ~3U;
169 /* end of tatables.c */