Add NUMBERSET_NOT_ASCENDING error code.
[ttfautohint.git] / lib / tahmtx.c
blob2a9361c81925c6e90b53754dfb89b9b52c6390c0
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;
24 FT_Byte* buf_new;
25 FT_ULong buf_len;
26 FT_ULong i;
29 if (sfnt->hmtx_idx == MISSING)
30 return TA_Err_Ok;
32 hmtx_table = &font->tables[sfnt->hmtx_idx];
34 if (hmtx_table->processed)
35 return TA_Err_Ok;
37 /* the metrics of the added composite element doesn't matter; */
38 /* for this reason, we simply append two zero bytes, */
39 /* indicating a zero value in the `leftSideBearing' array */
40 /* (this works because we don't increase the `numberOfHMetrics' field) */
42 hmtx_table->len += 2;
43 /* make the allocated buffer length a multiple of 4 */
44 buf_len = (hmtx_table->len + 3) & ~3;
45 buf_new = (FT_Byte*)realloc(hmtx_table->buf, buf_len);
46 if (!buf_new)
48 hmtx_table->len -= 2;
49 return FT_Err_Out_Of_Memory;
52 /* pad end of buffer with zeros */
53 for (i = hmtx_table->len - 2; i < buf_len; i++)
54 buf_new[i] = 0x00;
56 hmtx_table->buf = buf_new;
57 hmtx_table->checksum = TA_table_compute_checksum(hmtx_table->buf,
58 hmtx_table->len);
59 hmtx_table->processed = 1;
61 return TA_Err_Ok;
64 /* end of tahmtx.c */