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_update_post_table(SFNT
* sfnt
,
25 SFNT_Table
* post_table
;
34 if (sfnt
->post_idx
== MISSING
)
37 post_table
= &font
->tables
[sfnt
->post_idx
];
38 buf
= post_table
->buf
;
39 buf_len
= post_table
->len
;
41 if (post_table
->processed
)
44 version
= (FT_ULong
)(buf
[0] << 24
49 /* since we have to add a non-standard glyph name, */
50 /* we must convert `name' tables in formats 1.0 and 2.5 into format 2.0 */
52 if (version
== 0x10000)
56 else if (version
== 0x20000)
59 FT_UShort max_name_idx
;
66 num_glyphs
= (FT_UShort
)(buf
[32] << 8 | buf
[33]);
71 /* get number of glyph names stored in `names' array */
72 for (i
= 0; i
< num_glyphs
; i
++)
81 if (idx
> max_name_idx
)
86 /* we add one entry to the `glyphNameIndex' array, */
87 /* and append TTFAUTOHINT_GLYPH_LEN bytes to the `names' array */
88 buf_new_len
= post_table
->len
+ 2 + TTFAUTOHINT_GLYPH_LEN
;
90 /* make the allocated buffer length a multiple of 4 */
91 len
= (buf_new_len
+ 3) & ~3U;
92 buf_new
= (FT_Byte
*)malloc(len
);
94 return FT_Err_Out_Of_Memory
;
96 /* pad end of buffer with zeros */
97 buf_new
[len
- 1] = 0x00;
98 buf_new
[len
- 2] = 0x00;
99 buf_new
[len
- 3] = 0x00;
101 /* copy the table and insert the new data */
105 memcpy(p_new
, p
, 32); /* header */
109 *p_new
= HIGH(num_glyphs
+ 1);
110 *(p_new
+ 1) = LOW(num_glyphs
+ 1);
114 memcpy(p_new
, p
, num_glyphs
* 2); /* glyphNameIndex */
116 p_new
+= num_glyphs
* 2;
118 *p_new
= HIGH(max_name_idx
+ 1 + 257); /* new entry */
119 *(p_new
+ 1) = LOW(max_name_idx
+ 1 + 257);
122 memcpy(p_new
, p
, (size_t)(buf
+ buf_len
- p
)); /* names */
123 p_new
+= buf
+ buf_len
- p
;
125 strncpy((char*)p_new
, TTFAUTOHINT_GLYPH_FIRST_BYTE TTFAUTOHINT_GLYPH
,
126 TTFAUTOHINT_GLYPH_LEN
); /* new entry */
129 post_table
->buf
= buf_new
;
130 post_table
->len
= buf_new_len
;
132 else if (version
== 0x28000)
137 goto Done
; /* nothing to do for format 3.0 */
139 post_table
->checksum
= TA_table_compute_checksum(post_table
->buf
,
142 post_table
->processed
= 1;
147 /* end of tapost.c */