4 * Copyright (C) 2011 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.
19 #define TTFAUTOHINT_GLYPH "\x0C.ttfautohint" /* first byte is string length */
20 #define TTFAUTOHINT_GLYPH_LEN 13
23 TA_sfnt_update_post_table(SFNT
* sfnt
,
26 SFNT_Table
* post_table
= &font
->tables
[sfnt
->post_idx
];
27 FT_Byte
* buf
= post_table
->buf
;
28 FT_ULong buf_len
= post_table
->len
;
35 if (post_table
->processed
)
38 version
= buf
[0] << 24;
39 version
+= buf
[1] << 16;
40 version
+= buf
[2] << 8;
43 /* since we have to add a non-standard glyph name, */
44 /* we must convert `name' tables in formats 1.0 and 2.5 into format 2.0 */
46 if (version
== 0x10000)
50 else if (version
== 0x20000)
53 FT_UShort max_name_idx
;
60 num_glyphs
= buf
[32] << 8;
61 num_glyphs
+= buf
[33];
66 /* get number of glyph names stored in `names' array */
67 for (i
= 0; i
< num_glyphs
; i
++)
77 if (idx
> max_name_idx
)
82 /* we add one entry to the `glyphNameIndex' array, */
83 /* and append TTFAUTOHINT_GLYPH_LEN bytes to the `names' array */
84 buf_new_len
= post_table
->len
+ 2 + TTFAUTOHINT_GLYPH_LEN
;
86 /* make the allocated buffer length a multiple of 4 */
87 len
= (buf_new_len
+ 3) & ~3;
88 buf_new
= (FT_Byte
*)malloc(len
);
90 return FT_Err_Out_Of_Memory
;
92 /* pad end of buffer with zeros */
93 buf_new
[len
- 1] = 0x00;
94 buf_new
[len
- 2] = 0x00;
95 buf_new
[len
- 3] = 0x00;
97 /* copy the table and insert the new data */
101 memcpy(p_new
, p
, 32); /* header */
105 *p_new
= HIGH(num_glyphs
+ 1);
106 *(p_new
+ 1) = LOW(num_glyphs
+ 1);
110 memcpy(p_new
, p
, num_glyphs
* 2); /* glyphNameIndex */
112 p_new
+= num_glyphs
* 2;
114 *p_new
= HIGH(max_name_idx
+ 1); /* new entry */
115 *(p_new
+ 1) = LOW(max_name_idx
+ 1);
118 memcpy(p_new
, p
, buf
+ buf_len
- p
); /* names */
119 p_new
+= buf
+ buf_len
- p
;
121 strncpy((char*)p_new
, TTFAUTOHINT_GLYPH
,
122 TTFAUTOHINT_GLYPH_LEN
); /* new entry */
125 post_table
->buf
= buf_new
;
126 post_table
->len
= buf_new_len
;
128 else if (version
== 0x28000)
133 goto Done
; /* nothing to do for format 3.0 */
135 post_table
->checksum
= TA_table_compute_checksum(post_table
->buf
,
138 post_table
->processed
= 1;
143 /* end of tapost.c */