4 * Copyright (C) 2011-2014 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
= buf
[0] << 24;
45 version
+= buf
[1] << 16;
46 version
+= buf
[2] << 8;
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
= buf
[32] << 8;
67 num_glyphs
+= buf
[33];
72 /* get number of glyph names stored in `names' array */
73 for (i
= 0; i
< num_glyphs
; i
++)
83 if (idx
> max_name_idx
)
88 /* we add one entry to the `glyphNameIndex' array, */
89 /* and append TTFAUTOHINT_GLYPH_LEN bytes to the `names' array */
90 buf_new_len
= post_table
->len
+ 2 + TTFAUTOHINT_GLYPH_LEN
;
92 /* make the allocated buffer length a multiple of 4 */
93 len
= (buf_new_len
+ 3) & ~3;
94 buf_new
= (FT_Byte
*)malloc(len
);
96 return FT_Err_Out_Of_Memory
;
98 /* pad end of buffer with zeros */
99 buf_new
[len
- 1] = 0x00;
100 buf_new
[len
- 2] = 0x00;
101 buf_new
[len
- 3] = 0x00;
103 /* copy the table and insert the new data */
107 memcpy(p_new
, p
, 32); /* header */
111 *p_new
= HIGH(num_glyphs
+ 1);
112 *(p_new
+ 1) = LOW(num_glyphs
+ 1);
116 memcpy(p_new
, p
, num_glyphs
* 2); /* glyphNameIndex */
118 p_new
+= num_glyphs
* 2;
120 *p_new
= HIGH(max_name_idx
+ 1 + 257); /* new entry */
121 *(p_new
+ 1) = LOW(max_name_idx
+ 1 + 257);
124 memcpy(p_new
, p
, buf
+ buf_len
- p
); /* names */
125 p_new
+= buf
+ buf_len
- p
;
127 strncpy((char*)p_new
, TTFAUTOHINT_GLYPH_FIRST_BYTE TTFAUTOHINT_GLYPH
,
128 TTFAUTOHINT_GLYPH_LEN
); /* new entry */
131 post_table
->buf
= buf_new
;
132 post_table
->len
= buf_new_len
;
134 else if (version
== 0x28000)
139 goto Done
; /* nothing to do for format 3.0 */
141 post_table
->checksum
= TA_table_compute_checksum(post_table
->buf
,
144 post_table
->processed
= 1;
149 /* end of tapost.c */