From 1299f5593751a39174051b59f77ecefc618f42ef Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Sat, 17 Dec 2011 08:17:19 +0100 Subject: [PATCH] Add code to adjust `hmtx' table. --- src/Makefile.am | 1 + src/ta.h | 5 +++++ src/tahmtx.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/tasfnt.c | 3 +++ 4 files changed, 68 insertions(+) create mode 100644 src/tahmtx.c diff --git a/src/Makefile.am b/src/Makefile.am index 51faaa7..a0314f6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,6 +29,7 @@ libttfautohint_a_SOURCES = ta.h \ taglyf.c \ tagpos.c \ tahints.c tahints.h \ + tahmtx.c \ talatin.c talatin.h \ taloader.c taloader.h \ taloca.c \ diff --git a/src/ta.h b/src/ta.h index c4bd7ff..554954e 100644 --- a/src/ta.h +++ b/src/ta.h @@ -138,6 +138,7 @@ typedef struct SFNT_ { FT_ULong glyf_idx; FT_ULong loca_idx; FT_ULong head_idx; + FT_ULong hmtx_idx; FT_ULong maxp_idx; FT_ULong OS2_idx; FT_ULong GPOS_idx; @@ -246,6 +247,10 @@ TA_sfnt_create_glyf_data(SFNT* sfnt, FONT* font); FT_Error +TA_sfnt_update_hmtx_table(SFNT* sfnt, + FONT* font); + +FT_Error TA_sfnt_build_loca_table(SFNT* sfnt, FONT* font); diff --git a/src/tahmtx.c b/src/tahmtx.c new file mode 100644 index 0000000..80886d8 --- /dev/null +++ b/src/tahmtx.c @@ -0,0 +1,59 @@ +/* tahmtx.c */ + +/* + * Copyright (C) 2011 by Werner Lemberg. + * + * This file is part of the ttfautohint library, and may only be used, + * modified, and distributed under the terms given in `COPYING'. By + * continuing to use, modify, or distribute this file you indicate that you + * have read `COPYING' and understand and accept it fully. + * + * The file `COPYING' mentioned in the previous paragraph is distributed + * with the ttfautohint library. + */ + + +#include "ta.h" + + +FT_Error +TA_sfnt_update_hmtx_table(SFNT* sfnt, + FONT* font) +{ + SFNT_Table* hmtx_table = &font->tables[sfnt->hmtx_idx]; + FT_Byte* buf_new; + FT_ULong buf_len; + FT_ULong i; + + + if (hmtx_table->processed) + return TA_Err_Ok; + + /* the metrics of the added composite element doesn't matter; */ + /* for this reason, we simply append two zero bytes, */ + /* indicating a zero value in the `leftSideBearing' array */ + /* (this works because we don't increase the `numberOfHMetrics' field) */ + + hmtx_table->len += 2; + /* make the allocated buffer length a multiple of 4 */ + buf_len = (hmtx_table->len + 3) & ~3; + buf_new = (FT_Byte*)realloc(hmtx_table->buf, hmtx_table->len); + if (!buf_new) + { + hmtx_table->len -= 2; + return FT_Err_Out_Of_Memory; + } + + /* pad end of buffer with zeros */ + for (i = hmtx_table->len - 2; i < buf_len; i++) + buf_new[i] = 0x00; + + hmtx_table->buf = buf_new; + hmtx_table->checksum = TA_table_compute_checksum(hmtx_table->buf, + hmtx_table->len); + hmtx_table->processed = 1; + + return TA_Err_Ok; +} + +/* end of tahmtx.c */ diff --git a/src/tasfnt.c b/src/tasfnt.c index 2598d07..2c27b5f 100644 --- a/src/tasfnt.c +++ b/src/tasfnt.c @@ -41,6 +41,7 @@ TA_sfnt_split_into_SFNT_tables(SFNT* sfnt, sfnt->glyf_idx = MISSING; sfnt->loca_idx = MISSING; sfnt->head_idx = MISSING; + sfnt->hmtx_idx = MISSING; sfnt->maxp_idx = MISSING; sfnt->OS2_idx = MISSING; sfnt->GPOS_idx = MISSING; @@ -117,6 +118,8 @@ TA_sfnt_split_into_SFNT_tables(SFNT* sfnt, sfnt->head_idx = j; else if (tag == TTAG_glyf) sfnt->glyf_idx = j; + else if (tag == TTAG_hmtx) + sfnt->hmtx_idx = j; else if (tag == TTAG_loca) sfnt->loca_idx = j; else if (tag == TTAG_maxp) -- 2.11.4.GIT