4 * Copyright (C) 2011-2012 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 */
57 checksum
+= *(buf
++) << 24;
58 checksum
+= *(buf
++) << 16;
59 checksum
+= *(buf
++) << 8;
68 TA_font_add_table(FONT
* font
,
69 SFNT_Table_Info
* table_info
,
74 SFNT_Table
* tables_new
;
75 SFNT_Table
* table_last
;
79 tables_new
= (SFNT_Table
*)realloc(font
->tables
,
80 font
->num_tables
* sizeof (SFNT_Table
));
84 return FT_Err_Out_Of_Memory
;
87 font
->tables
= tables_new
;
89 table_last
= &font
->tables
[font
->num_tables
- 1];
91 table_last
->tag
= tag
;
92 table_last
->len
= len
;
93 table_last
->buf
= buf
;
94 table_last
->checksum
= TA_table_compute_checksum(buf
, len
);
95 table_last
->offset
= 0; /* set in `TA_font_compute_table_offsets' */
96 table_last
->data
= NULL
;
97 table_last
->processed
= 0;
99 /* link table and table info */
100 *table_info
= font
->num_tables
- 1;
107 TA_sfnt_sort_table_info(SFNT
* sfnt
,
110 /* Looking into an arbitrary TTF (with a `DSIG' table), tags */
111 /* starting with an uppercase letter are sorted before lowercase */
112 /* letters. In other words, the alphabetical ordering (as */
113 /* mandated by signing a font) is a simple numeric comparison of */
114 /* the 32bit tag values. */
116 SFNT_Table
* tables
= font
->tables
;
118 SFNT_Table_Info
* table_infos
= sfnt
->table_infos
;
119 FT_ULong num_table_infos
= sfnt
->num_table_infos
;
126 for (i
= 1; i
< num_table_infos
; i
++)
128 for (j
= i
; j
> 0; j
--)
130 SFNT_Table_Info swap
;
135 tag1
= (table_infos
[j
] == MISSING
)
137 : tables
[table_infos
[j
]].tag
;
138 tag2
= (table_infos
[j
- 1] == MISSING
)
140 : tables
[table_infos
[j
- 1]].tag
;
145 swap
= table_infos
[j
];
146 table_infos
[j
] = table_infos
[j
- 1];
147 table_infos
[j
- 1] = swap
;
154 TA_font_compute_table_offsets(FONT
* font
,
158 FT_ULong offset
= start
;
161 for (i
= 0; i
< font
->num_tables
; i
++)
163 SFNT_Table
* table
= &font
->tables
[i
];
166 table
->offset
= offset
;
168 /* table offsets must be multiples of 4; */
169 /* this also fits the actual buffer lengths */
170 offset
+= (table
->len
+ 3) & ~3;
174 /* end of tatables.c */