From ad536c60401445f2316647216fad07a3422ae393 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Sun, 14 Sep 2014 22:38:58 +0200 Subject: [PATCH] Add option `TTFA-info' to library. --- lib/Makefile.am | 1 + lib/ta.h | 9 ++++++++ lib/tadump.c | 2 ++ lib/tattc.c | 39 ++++++++++++++++++++++++++++--- lib/tattf.c | 33 +++++++++++++++++++++++++-- lib/tattfa.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/ttfautohint.c | 4 ++++ lib/ttfautohint.h | 20 ++++++++++++++++ 8 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 lib/tattfa.c diff --git a/lib/Makefile.am b/lib/Makefile.am index eb3eae6..10bd3ad 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -67,6 +67,7 @@ libttfautohint_la_SOURCES = \ tatime.c \ tattc.c \ tattf.c \ + tattfa.c \ tatypes.h \ tawrtsys.h \ ttfautohint.c \ diff --git a/lib/ta.h b/lib/ta.h index 8de89be..e2f4c68 100644 --- a/lib/ta.h +++ b/lib/ta.h @@ -48,6 +48,9 @@ #define BYTE4(x) ((x) & 0x000000FFUL); +/* an SFNT tag for our information table */ +#define TTAG_TTFA FT_MAKE_TAG('T', 'T', 'F', 'A') + /* the length of a dummy `DSIG' table */ #define DSIG_LEN 8 @@ -257,6 +260,7 @@ struct FONT_ FT_Bool symbol; FT_Bool dehint; FT_Bool debug; + FT_Bool TTFA_info; }; @@ -319,6 +323,11 @@ TA_sfnt_build_cvt_table(SFNT* sfnt, FONT* font); FT_Error +TA_table_build_TTFA(FT_Byte** TTFA, + FT_ULong* TTFA_len, + FONT* font); + +FT_Error TA_table_build_DSIG(FT_Byte** DSIG); FT_Error diff --git a/lib/tadump.c b/lib/tadump.c index 3aaf0e2..483f3fb 100644 --- a/lib/tadump.c +++ b/lib/tadump.c @@ -206,6 +206,8 @@ TA_font_dump_parameters(FONT* font, font->increase_x_height); DUMPVAL("symbol", font->symbol); + DUMPVAL("TTFA-info", + font->TTFA_info); DUMPVAL("windows-compatibility", font->windows_compatibility); diff --git a/lib/tattc.c b/lib/tattc.c index 8cab701..6e4c2fb 100644 --- a/lib/tattc.c +++ b/lib/tattc.c @@ -126,9 +126,6 @@ TA_font_build_TTC(FONT* font) SFNT_Table* tables; FT_ULong num_tables; - FT_Byte* DSIG_buf; - SFNT_Table_Info dummy; - FT_Byte* TTC_header_buf; FT_ULong TTC_header_len; @@ -141,10 +138,46 @@ TA_font_build_TTC(FONT* font) FT_Error error; + /* add our information table to first subfont; */ + /* this is enforced by the TTC structure, */ + /* which only allows `DSIG' to be not related to a subfont */ + + if (font->TTFA_info) + { + SFNT* sfnt0 = &sfnts[0]; + + FT_Byte* TTFA_buf; + FT_ULong TTFA_len; + + + error = TA_sfnt_add_table_info(sfnt0); + if (error) + return error; + + error = TA_table_build_TTFA(&TTFA_buf, &TTFA_len, font); + if (error) + return error; + + /* in case of success, `TTFA_buf' gets linked */ + /* and is eventually freed in `TA_font_unload' */ + error = TA_font_add_table(font, + &sfnt0->table_infos[sfnt0->num_table_infos - 1], + TTAG_TTFA, TTFA_len, TTFA_buf); + if (error) + { + free(TTFA_buf); + return error; + } + } + /* replace an existing `DSIG' table with a dummy */ if (font->have_DSIG) { + FT_Byte* DSIG_buf; + SFNT_Table_Info dummy; + + error = TA_table_build_DSIG(&DSIG_buf); if (error) return error; diff --git a/lib/tattf.c b/lib/tattf.c index 1ab4a65..d9d2b14 100644 --- a/lib/tattf.c +++ b/lib/tattf.c @@ -194,8 +194,6 @@ TA_font_build_TTF(FONT* font) FT_ULong SFNT_offset; - FT_Byte* DSIG_buf; - FT_Byte* header_buf; FT_ULong header_len; @@ -203,10 +201,41 @@ TA_font_build_TTF(FONT* font) FT_Error error; + /* add our information table */ + + if (font->TTFA_info) + { + FT_Byte* TTFA_buf; + FT_ULong TTFA_len; + + + error = TA_sfnt_add_table_info(sfnt); + if (error) + return error; + + error = TA_table_build_TTFA(&TTFA_buf, &TTFA_len, font); + if (error) + return error; + + /* in case of success, `TTFA_buf' gets linked */ + /* and is eventually freed in `TA_font_unload' */ + error = TA_font_add_table(font, + &sfnt->table_infos[sfnt->num_table_infos - 1], + TTAG_TTFA, TTFA_len, TTFA_buf); + if (error) + { + free(TTFA_buf); + return error; + } + } + /* replace an existing `DSIG' table with a dummy */ if (font->have_DSIG) { + FT_Byte* DSIG_buf; + + error = TA_sfnt_add_table_info(sfnt); if (error) return error; diff --git a/lib/tattfa.c b/lib/tattfa.c new file mode 100644 index 0000000..44d8aa8 --- /dev/null +++ b/lib/tattfa.c @@ -0,0 +1,68 @@ +/* tattfa.c */ + +/* + * Copyright (C) 2014 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_table_build_TTFA(FT_Byte** TTFA, + FT_ULong* TTFA_len, + FONT* font) +{ + FT_Byte* buf; + FT_UInt buf_len; + + FT_UInt len; + FT_Byte* buf_new; + FT_Byte* p; + + + buf = (FT_Byte*)TA_font_dump_parameters(font, 0); + if (!buf) + return FT_Err_Out_Of_Memory; + buf_len = strlen((char*)buf); + + /* buffer length must be a multiple of four */ + len = (buf_len + 3) & ~3; + buf_new = (FT_Byte*)realloc(buf, len); + if (!buf_new) + { + free(buf); + return FT_Err_Out_Of_Memory; + } + buf = buf_new; + + /* pad end of buffer with zeros */ + p = buf + buf_len; + switch (buf_len % 4) + { + case 1: + *(p++) = 0x00; + case 2: + *(p++) = 0x00; + case 3: + *(p++) = 0x00; + default: + break; + } + + *TTFA = buf; + *TTFA_len = buf_len; + + return TA_Err_Ok; +} + + +/* end of tattfa.c */ diff --git a/lib/ttfautohint.c b/lib/ttfautohint.c index 2e7719c..acbcec9 100644 --- a/lib/ttfautohint.c +++ b/lib/ttfautohint.c @@ -103,6 +103,7 @@ TTF_autohint(const char* options, FT_Bool dehint = 0; FT_Bool debug = 0; + FT_Bool TTFA_info = 0; const char* op; @@ -238,6 +239,8 @@ TTF_autohint(const char* options, progress_data = va_arg(ap, void*); else if (COMPARE("symbol")) symbol = (FT_Bool)va_arg(ap, FT_Int); + else if (COMPARE("TTFA-info")) + TTFA_info = (FT_Bool)va_arg(ap, FT_Int); else if (COMPARE("windows-compatibility")) windows_compatibility = (FT_Bool)va_arg(ap, FT_Int); else if (COMPARE("x-height-snapping-exceptions")) @@ -404,6 +407,7 @@ No_check: font->debug = debug; font->dehint = dehint; + font->TTFA_info = TTFA_info; font->gasp_idx = MISSING; diff --git a/lib/ttfautohint.h b/lib/ttfautohint.h index 3041498..3732393 100644 --- a/lib/ttfautohint.h +++ b/lib/ttfautohint.h @@ -492,6 +492,26 @@ typedef int * value\ 1 to make ttfautohint handle the font. The default value * is\ 0. * + * `TTFA-info` + * : If set to\ 1, ttfautohint creates an SFNT table called `TTFA` and + * fills it with information on the parameters used while calling + * `TTF_autohint`. The format of the output data resembles the + * information at the very beginning of the dump emitted by option + * `debug`. The default value is\ 0. + * + * Main use of this option is for font editing purposes. For example, + * after a font editor has added some glyphs, a front-end to + * `TTF_autohint` can parse `TTFA` and feed the parameters into another + * call of `TTF_autohint`. The new glyphs are then hinted while hints + * of the old glyphs stay unchanged. + * + * If this option is not set, and the font to be processed contains a + * `TTFA` table, it gets removed. + * + * Note that such a `TTFA` table gets ignored by all font rendering + * engines. In TrueType Collections, the `TTFA` table is added to the + * first subfont. + * * `dehint` * : If set to\ 1, remove all hints from the font. All other hinting * options are ignored. -- 2.11.4.GIT