Version 0.6.1.
[ttfautohint.git] / src / tahmtx.c
blob05408d2c70bf845a35f87e2cd048be86912bad66
1 /* tahmtx.c */
3 /*
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.
16 #include "ta.h"
19 FT_Error
20 TA_sfnt_update_hmtx_table(SFNT* sfnt,
21 FONT* font)
23 SFNT_Table* hmtx_table = &font->tables[sfnt->hmtx_idx];
24 FT_Byte* buf_new;
25 FT_ULong buf_len;
26 FT_ULong i;
29 if (hmtx_table->processed)
30 return TA_Err_Ok;
32 /* the metrics of the added composite element doesn't matter; */
33 /* for this reason, we simply append two zero bytes, */
34 /* indicating a zero value in the `leftSideBearing' array */
35 /* (this works because we don't increase the `numberOfHMetrics' field) */
37 hmtx_table->len += 2;
38 /* make the allocated buffer length a multiple of 4 */
39 buf_len = (hmtx_table->len + 3) & ~3;
40 buf_new = (FT_Byte*)realloc(hmtx_table->buf, buf_len);
41 if (!buf_new)
43 hmtx_table->len -= 2;
44 return FT_Err_Out_Of_Memory;
47 /* pad end of buffer with zeros */
48 for (i = hmtx_table->len - 2; i < buf_len; i++)
49 buf_new[i] = 0x00;
51 hmtx_table->buf = buf_new;
52 hmtx_table->checksum = TA_table_compute_checksum(hmtx_table->buf,
53 hmtx_table->len);
54 hmtx_table->processed = 1;
56 return TA_Err_Ok;
59 /* end of tahmtx.c */