From b3765beed3d9b789eaf3dc3bb4a1a594cbf70f3b Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Fri, 26 Sep 2014 10:39:52 +0200 Subject: [PATCH] Rename `deltas exceptions' to `control instructions'. We are going to extend the structures to provide more possibilities to control the hinting process... In the C code we do s/Deltas/Control/ s/Delta/Ctrl/ s/deltas/control/ s/DELTA/CONTROL_DELTA/ --- lib/Makefile.am | 30 +- lib/ta.h | 24 +- lib/tabytecode.c | 52 ++-- ...tas-flex-wrapper.c => tacontrol-flex-wrapper.c} | 6 +- lib/{tadeltas.bison => tacontrol.bison} | 150 +++++----- lib/{tadeltas.c => tacontrol.c} | 276 +++++++++---------- lib/{tadeltas.flex => tacontrol.flex} | 60 ++-- lib/tacontrol.h | 303 +++++++++++++++++++++ lib/tadeltas.h | 303 --------------------- lib/tadump.c | 8 +- lib/tafile.c | 32 +-- lib/tafont.c | 6 +- lib/tafpgm.c | 12 +- lib/taharfbuzz.c | 2 +- lib/taprep.c | 6 +- lib/tattfa.c | 2 +- lib/ttfautohint-errors.h | 26 +- lib/ttfautohint.c | 52 ++-- lib/ttfautohint.h | 25 +- 19 files changed, 687 insertions(+), 688 deletions(-) rename lib/{tadeltas-flex-wrapper.c => tacontrol-flex-wrapper.c} (86%) rename lib/{tadeltas.bison => tacontrol.bison} (76%) rename lib/{tadeltas.c => tacontrol.c} (54%) rename lib/{tadeltas.flex => tacontrol.flex} (82%) create mode 100644 lib/tacontrol.h delete mode 100644 lib/tadeltas.h diff --git a/lib/Makefile.am b/lib/Makefile.am index fc45f19..07f3f8f 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -27,7 +27,7 @@ libnumberset_la_SOURCES = \ # We have to bypass automake's default handling of flex (.l) and bison (.y) # files, since such files are always treated as traditional lex and yacc # files, not allowing for flex and bison extensions. For this reason, we -# call our source files `tadeltas.flex' and `tadeltas.bison' and write +# call our source files `tacontrol.flex' and `tacontrol.bison' and write # explicit dependency rules. libttfautohint_la_SOURCES = \ @@ -35,11 +35,11 @@ libttfautohint_la_SOURCES = \ ta.h \ tablue.c tablue.h \ tabytecode.c tabytecode.h \ + tacontrol.c tacontrol.h \ + tacontrol-flex-wrapper.c tacontrol-flex.h \ + tacontrol-bison.c tacontrol-bison.h \ tacover.h \ tacvt.c \ - tadeltas.c tadeltas.h \ - tadeltas-flex-wrapper.c tadeltas-flex.h \ - tadeltas-bison.c tadeltas-bison.h \ tadsig.c \ tadummy.c tadummy.h \ tadump.c \ @@ -86,15 +86,15 @@ libttfautohint_la_LIBADD = \ BUILT_SOURCES = \ tablue.c tablue.h \ - tadeltas-flex.c tadeltas-flex.h \ - tadeltas-bison.c tadeltas-bison.h + tacontrol-flex.c tacontrol-flex.h \ + tacontrol-bison.c tacontrol-bison.h EXTRA_DIST = \ afblue.pl \ sds.c \ tablue.cin tablue.hin \ tablue.dat \ - tadeltas.flex tadeltas.bison tadeltas-flex.c + tacontrol.flex tacontrol.bison tacontrol-flex.c tablue.c: tablue.dat tablue.cin $(AM_V_GEN)rm -f $@-t $@ \ @@ -116,18 +116,18 @@ TA_V_FLEX_0 = @echo " FLEX " $@; # we use `touch' to make the created .h file newer than the created .c file -tadeltas-flex.c tadeltas-flex.h: tadeltas.flex - $(TA_V_FLEX)$(FLEX) tadeltas.flex \ - && touch tadeltas-flex.h -tadeltas-flex.h: tadeltas-flex.c +tacontrol-flex.c tacontrol-flex.h: tacontrol.flex + $(TA_V_FLEX)$(FLEX) tacontrol.flex \ + && touch tacontrol-flex.h +tacontrol-flex.h: tacontrol-flex.c TA_V_BISON = $(TA_V_BISON_@AM_V@) TA_V_BISON_ = $(TA_V_BISON_@AM_DEFAULT_V@) TA_V_BISON_0 = @echo " BISON " $@; -tadeltas-bison.c tadeltas-bison.h: tadeltas.bison - $(TA_V_BISON)$(BISON) tadeltas.bison \ - && touch tadeltas-bison.h -tadeltas-bison.h: tadeltas-bison.c +tacontrol-bison.c tacontrol-bison.h: tacontrol.bison + $(TA_V_BISON)$(BISON) tacontrol.bison \ + && touch tacontrol-bison.h +tacontrol-bison.h: tacontrol-bison.c ## end of Makefile.am diff --git a/lib/ta.h b/lib/ta.h index 30bbebc..acb7896 100644 --- a/lib/ta.h +++ b/lib/ta.h @@ -202,7 +202,7 @@ typedef struct SFNT_ FT_UShort max_components; } SFNT; -typedef struct Deltas_ Deltas; +typedef struct Control_ Control; /* our font object; the `FONT' typedef is in `taloader.h' */ struct FONT_ @@ -215,8 +215,8 @@ struct FONT_ FT_Byte* out_buf; size_t out_len; - char* deltas_buf; - size_t deltas_len; + char* control_buf; + size_t control_len; SFNT* sfnts; FT_Long num_sfnts; @@ -229,12 +229,12 @@ struct FONT_ /* we have a single `gasp' table for all subfonts */ FT_ULong gasp_idx; - /* the delta exceptions data */ - Deltas* deltas; + /* the control instructions */ + Control* control; - /* two generic pointers into the the delta exceptions tree */ - void* deltas_data_head; - void* deltas_data_cur; + /* two generic pointers into the control instructions tree */ + void* control_data_head; + void* control_data_cur; TA_LoaderRec loader[1]; /* the interface to the autohinter */ @@ -267,7 +267,7 @@ struct FONT_ #include "tatables.h" #include "tabytecode.h" -#include "tadeltas.h" +#include "tacontrol.h" /* in file `tascript.c' */ @@ -298,7 +298,7 @@ void TA_font_unload(FONT* font, const char* in_buf, char** out_bufp, - const char* deltas_buf); + const char* control_buf); FT_Error TA_font_file_read(FONT* font, @@ -307,8 +307,8 @@ FT_Error TA_font_file_write(FONT* font, FILE* out_file); FT_Error -TA_deltas_file_read(FONT* font, - FILE* deltas_file); +TA_control_file_read(FONT* font, + FILE* control_file); FT_Error TA_sfnt_build_glyph_instructions(SFNT* sfnt, diff --git a/lib/tabytecode.c b/lib/tabytecode.c index 889fd39..f1e92a9 100644 --- a/lib/tabytecode.c +++ b/lib/tabytecode.c @@ -600,7 +600,7 @@ TA_sfnt_build_glyph_segments(SFNT* sfnt, static void -build_delta_exception(const Delta* delta, +build_delta_exception(const Ctrl* ctrl, FT_UInt** delta_args, int* num_delta_args) { @@ -610,7 +610,7 @@ build_delta_exception(const Delta* delta, int y_shift; - ppem = delta->ppem - DELTA_PPEM_MIN; + ppem = ctrl->ppem - CONTROL_DELTA_PPEM_MIN; if (ppem < 16) offset = 0; @@ -640,32 +640,32 @@ build_delta_exception(const Delta* delta, * (note that there is no index for a zero shift). */ - if (delta->x_shift < 0) - x_shift = delta->x_shift + 8; + if (ctrl->x_shift < 0) + x_shift = ctrl->x_shift + 8; else - x_shift = delta->x_shift + 7; + x_shift = ctrl->x_shift + 7; - if (delta->y_shift < 0) - y_shift = delta->y_shift + 8; + if (ctrl->y_shift < 0) + y_shift = ctrl->y_shift + 8; else - y_shift = delta->y_shift + 7; + y_shift = ctrl->y_shift + 7; /* add point index and exception specification to appropriate stack */ - if (delta->x_shift) + if (ctrl->x_shift) { *(delta_args[offset] + num_delta_args[offset]++) = (ppem << 4) + x_shift; *(delta_args[offset] + num_delta_args[offset]++) = - delta->point_idx; + ctrl->point_idx; } - if (delta->y_shift) + if (ctrl->y_shift) { offset += 3; *(delta_args[offset] + num_delta_args[offset]++) = (ppem << 4) + y_shift; *(delta_args[offset] + num_delta_args[offset]++) = - delta->point_idx; + ctrl->point_idx; } } @@ -692,21 +692,21 @@ TA_sfnt_build_delta_exceptions(SFNT* sfnt, FT_Bool need_word_counts = 0; FT_Bool allocated = 0; - const Delta* delta; + const Ctrl* ctrl; num_points = font->loader->gloader->base.outline.n_points; - /* loop over all fitting delta exceptions */ + /* loop over all fitting control instructions */ for (;;) { - delta = TA_deltas_get_delta(font); + ctrl = TA_control_get_ctrl(font); - /* too large values of font and glyph indices in `delta' */ + /* too large values of font and glyph indices in `ctrl' */ /* are handled by later calls of this function */ - if (!delta - || face->face_index < delta->font_idx - || idx < delta->glyph_idx) + if (!ctrl + || face->face_index < ctrl->font_idx + || idx < ctrl->glyph_idx) break; if (!allocated) @@ -729,18 +729,18 @@ TA_sfnt_build_delta_exceptions(SFNT* sfnt, } /* since we walk sequentially over all glyphs (with points), */ - /* and the delta entries have the same order, */ + /* and the control instruction entries have the same order, */ /* we don't need to test for equality of font and glyph indices: */ /* at this very point in the code we certainly have a hit */ - build_delta_exception(delta, delta_args, num_delta_args); + build_delta_exception(ctrl, delta_args, num_delta_args); - if (delta->point_idx > 255) + if (ctrl->point_idx > 255) need_words = 1; - TA_deltas_get_next(font); + TA_control_get_next(font); } - /* nothing to do if no delta data */ + /* nothing to do if no control instructions */ if (!allocated) return bufp; @@ -2305,7 +2305,7 @@ TA_sfnt_build_glyph_instructions(SFNT* sfnt, * adding some bytes for the necessary overhead. */ ins_len = hints->num_points - * (1000 + ((font->deltas_data_head != NULL) ? 400 : 0)); + * (1000 + ((font->control_data_head != NULL) ? 400 : 0)); ins_buf = (FT_Byte*)malloc(ins_len); if (!ins_buf) return FT_Err_Out_Of_Memory; @@ -2548,7 +2548,7 @@ Done: Done1: /* handle delta exceptions */ - if (font->deltas_data_head) + if (font->control_data_head) { bufp = TA_sfnt_build_delta_exceptions(sfnt, font, idx, bufp); if (!bufp) diff --git a/lib/tadeltas-flex-wrapper.c b/lib/tacontrol-flex-wrapper.c similarity index 86% rename from lib/tadeltas-flex-wrapper.c rename to lib/tacontrol-flex-wrapper.c index 128d498..bd2a10a 100644 --- a/lib/tadeltas-flex-wrapper.c +++ b/lib/tacontrol-flex-wrapper.c @@ -1,4 +1,4 @@ -/* tadeltas-flex-wrapper.c */ +/* tacontrol-flex-wrapper.c */ /* * Copyright (C) 2014 by Werner Lemberg. @@ -21,6 +21,6 @@ #include "config.h" -#include "tadeltas-flex.c" +#include "tacontrol-flex.c" -/* end of tadeltas-flex-wrapper.c */ +/* end of tacontrol-flex-wrapper.c */ diff --git a/lib/tadeltas.bison b/lib/tacontrol.bison similarity index 76% rename from lib/tadeltas.bison rename to lib/tacontrol.bison index 9577bef..37e9659 100644 --- a/lib/tadeltas.bison +++ b/lib/tacontrol.bison @@ -1,4 +1,4 @@ -/* tadeltas.bison */ +/* tacontrol.bison */ /* * Copyright (C) 2014 by Werner Lemberg. @@ -14,13 +14,13 @@ /* - * grammar for parsing delta exceptions + * grammar for parsing ttfautohint control instructions * * Parsing errors that essentially belong to the lexing stage are handled * with `store_error_data'; in case the lexer detects an error, it returns * the right token type but sets `context->error'. Syntax errors and fatal * lexer errors (token `INTERNAL_FLEX_ERROR') are handled with - * `TA_deltas_error'. + * `TA_control_error'. */ /* @@ -29,8 +29,8 @@ * was extremely helpful in writing this code. */ -%output "tadeltas-bison.c" -%defines "tadeltas-bison.h" +%output "tacontrol-bison.c" +%defines "tacontrol-bison.h" %define api.pure %error-verbose @@ -38,15 +38,15 @@ %glr-parser %lex-param { void* scanner } %locations -%name-prefix "TA_deltas_" -%parse-param { Deltas_Context* context } +%name-prefix "TA_control_" +%parse-param { Control_Context* context } %require "2.5" /* note that some versions < 2.7 use `//' in comments */ %code requires { #include "ta.h" /* we don't change the name prefix of flex functions */ -#define TA_deltas_lex yylex +#define TA_control_lex yylex } %union { @@ -55,20 +55,20 @@ char* name; number_range* range; double real; - Deltas* deltas; + Control* control; } %{ -#include "tadeltas-flex.h" +#include "tacontrol-flex.h" void -TA_deltas_error(YYLTYPE *locp, - Deltas_Context* context, - char const* msg); +TA_control_error(YYLTYPE *locp, + Control_Context* context, + char const* msg); void store_error_data(const YYLTYPE *locp, - Deltas_Context* context, + Control_Context* context, TA_Error error); @@ -84,11 +84,11 @@ store_error_data(const YYLTYPE *locp, %token NAME "glyph name" %token REAL "real number" -%type entry +%type entry %type font_idx %type glyph_idx %type glyph_name -%type input +%type input %type integer %type left_limited %type number_set @@ -104,7 +104,7 @@ store_error_data(const YYLTYPE *locp, %type x_shift %type y_shift -%destructor { TA_deltas_free($$); } +%destructor { TA_control_free($$); } %destructor { number_set_free($$); } %printer { fprintf(yyoutput, "`%ld'", $$); } @@ -132,21 +132,21 @@ store_error_data(const YYLTYPE *locp, /* `number_range' list elements are stored in reversed order; */ -/* the call to `TA_deltas_new' fixes this */ +/* the call to `TA_control_new' fixes this */ -/* `Deltas' list elements are stored in reversed order, too; */ -/* this gets fixed by an explicit call to `TA_deltas_reverse' */ +/* `Control' list elements are stored in reversed order, too; */ +/* this gets fixed by an explicit call to `TA_control_reverse' */ start: input - { context->result = TA_deltas_reverse($input); } + { context->result = TA_control_reverse($input); } ; input[result]: /* empty */ { $result = NULL; } | input[left] entry - { $result = TA_deltas_prepend($left, $entry); } + { $result = TA_control_prepend($left, $entry); } ; entry: @@ -154,15 +154,15 @@ entry: { $entry = NULL; } | font_idx glyph_idx point_set x_shift y_shift ppem_set EOE { - $entry = TA_deltas_new($font_idx, - $glyph_idx, - $point_set, - $x_shift, - $y_shift, - $ppem_set); + $entry = TA_control_new($font_idx, + $glyph_idx, + $point_set, + $x_shift, + $y_shift, + $ppem_set); if (!$entry) { - store_error_data(&@$, context, TA_Err_Deltas_Allocation_Error); + store_error_data(&@$, context, TA_Err_Control_Allocation_Error); YYABORT; } } @@ -179,7 +179,7 @@ font_idx: $font_idx = $integer; if ($font_idx >= context->font->num_sfnts) { - store_error_data(&@$, context, TA_Err_Deltas_Invalid_Font_Index); + store_error_data(&@$, context, TA_Err_Control_Invalid_Font_Index); YYABORT; } context->font_idx = $font_idx; @@ -195,7 +195,7 @@ glyph_idx: $glyph_idx = $integer; if ($glyph_idx >= face->num_glyphs) { - store_error_data(&@$, context, TA_Err_Deltas_Invalid_Glyph_Index); + store_error_data(&@$, context, TA_Err_Control_Invalid_Glyph_Index); YYABORT; } context->glyph_idx = $glyph_idx; @@ -221,7 +221,7 @@ glyph_idx: if ($glyph_idx < 0) { - store_error_data(&@$, context, TA_Err_Deltas_Invalid_Glyph_Name); + store_error_data(&@$, context, TA_Err_Control_Invalid_Glyph_Name); YYABORT; } context->glyph_idx = $glyph_idx; @@ -234,7 +234,7 @@ glyph_name: $glyph_name = strdup("p"); if ($glyph_name) { - store_error_data(&@$, context, TA_Err_Deltas_Allocation_Error); + store_error_data(&@$, context, TA_Err_Control_Allocation_Error); YYABORT; } } @@ -243,7 +243,7 @@ glyph_name: $glyph_name = strdup("x"); if ($glyph_name) { - store_error_data(&@$, context, TA_Err_Deltas_Allocation_Error); + store_error_data(&@$, context, TA_Err_Control_Allocation_Error); YYABORT; } } @@ -252,7 +252,7 @@ glyph_name: $glyph_name = strdup("y"); if ($glyph_name) { - store_error_data(&@$, context, TA_Err_Deltas_Allocation_Error); + store_error_data(&@$, context, TA_Err_Control_Allocation_Error); YYABORT; } } @@ -281,7 +281,7 @@ point_set: error = FT_Load_Glyph(face, context->glyph_idx, FT_LOAD_NO_SCALE); if (error) { - store_error_data(&@$, context, TA_Err_Deltas_Invalid_Glyph); + store_error_data(&@$, context, TA_Err_Control_Invalid_Glyph); YYABORT; } @@ -311,9 +311,9 @@ y_shift: shift: real { - if ($real < DELTA_SHIFT_MIN || $real > DELTA_SHIFT_MAX) + if ($real < CONTROL_DELTA_SHIFT_MIN || $real > CONTROL_DELTA_SHIFT_MAX) { - store_error_data(&@$, context, TA_Err_Deltas_Invalid_Shift); + store_error_data(&@$, context, TA_Err_Control_Invalid_Shift); YYABORT; } $shift = $real; @@ -323,8 +323,8 @@ shift: ppem_set: '@' { - context->number_set_min = DELTA_PPEM_MIN; - context->number_set_max = DELTA_PPEM_MAX; + context->number_set_min = CONTROL_DELTA_PPEM_MIN; + context->number_set_max = CONTROL_DELTA_PPEM_MAX; } number_set { $ppem_set = $number_set; } @@ -382,14 +382,14 @@ number_set: { number_set_free($right_limited); number_set_free($range_elems); - store_error_data(&@3, context, TA_Err_Deltas_Ranges_Not_Ascending); + store_error_data(&@3, context, TA_Err_Control_Ranges_Not_Ascending); YYABORT; } if ($number_set == NUMBERSET_OVERLAPPING_RANGES) { number_set_free($right_limited); number_set_free($range_elems); - store_error_data(&@3, context, TA_Err_Deltas_Overlapping_Ranges); + store_error_data(&@3, context, TA_Err_Control_Overlapping_Ranges); YYABORT; } } @@ -400,14 +400,14 @@ number_set: { number_set_free($range_elems); number_set_free($left_limited); - store_error_data(&@3, context, TA_Err_Deltas_Ranges_Not_Ascending); + store_error_data(&@3, context, TA_Err_Control_Ranges_Not_Ascending); YYABORT; } if ($number_set == NUMBERSET_OVERLAPPING_RANGES) { number_set_free($range_elems); number_set_free($left_limited); - store_error_data(&@3, context, TA_Err_Deltas_Overlapping_Ranges); + store_error_data(&@3, context, TA_Err_Control_Overlapping_Ranges); YYABORT; } } @@ -423,7 +423,7 @@ unlimited: /* range of `$unlimited' is always valid */ if ($unlimited == NUMBERSET_ALLOCATION_ERROR) { - store_error_data(&@$, context, TA_Err_Deltas_Allocation_Error); + store_error_data(&@$, context, TA_Err_Control_Allocation_Error); YYABORT; } } @@ -438,12 +438,12 @@ right_limited: context->number_set_max); if ($right_limited == NUMBERSET_INVALID_RANGE) { - store_error_data(&@$, context, TA_Err_Deltas_Invalid_Range); + store_error_data(&@$, context, TA_Err_Control_Invalid_Range); YYABORT; } if ($right_limited == NUMBERSET_ALLOCATION_ERROR) { - store_error_data(&@$, context, TA_Err_Deltas_Allocation_Error); + store_error_data(&@$, context, TA_Err_Control_Allocation_Error); YYABORT; } } @@ -458,12 +458,12 @@ left_limited: context->number_set_max); if ($left_limited == NUMBERSET_INVALID_RANGE) { - store_error_data(&@$, context, TA_Err_Deltas_Invalid_Range); + store_error_data(&@$, context, TA_Err_Control_Invalid_Range); YYABORT; } if ($left_limited == NUMBERSET_ALLOCATION_ERROR) { - store_error_data(&@$, context, TA_Err_Deltas_Allocation_Error); + store_error_data(&@$, context, TA_Err_Control_Allocation_Error); YYABORT; } } @@ -479,14 +479,14 @@ range_elems[result]: { number_set_free($left); number_set_free($range_elem); - store_error_data(&@3, context, TA_Err_Deltas_Ranges_Not_Ascending); + store_error_data(&@3, context, TA_Err_Control_Ranges_Not_Ascending); YYABORT; } if ($result == NUMBERSET_OVERLAPPING_RANGES) { number_set_free($left); number_set_free($range_elem); - store_error_data(&@3, context, TA_Err_Deltas_Overlapping_Ranges); + store_error_data(&@3, context, TA_Err_Control_Overlapping_Ranges); YYABORT; } } @@ -501,12 +501,12 @@ range_elem: context->number_set_max); if ($range_elem == NUMBERSET_INVALID_RANGE) { - store_error_data(&@$, context, TA_Err_Deltas_Invalid_Range); + store_error_data(&@$, context, TA_Err_Control_Invalid_Range); YYABORT; } if ($range_elem == NUMBERSET_ALLOCATION_ERROR) { - store_error_data(&@$, context, TA_Err_Deltas_Allocation_Error); + store_error_data(&@$, context, TA_Err_Control_Allocation_Error); YYABORT; } } @@ -523,12 +523,12 @@ range: context->number_set_max); if ($range == NUMBERSET_INVALID_RANGE) { - store_error_data(&@$, context, TA_Err_Deltas_Invalid_Range); + store_error_data(&@$, context, TA_Err_Control_Invalid_Range); YYABORT; } if ($range == NUMBERSET_ALLOCATION_ERROR) { - store_error_data(&@$, context, TA_Err_Deltas_Allocation_Error); + store_error_data(&@$, context, TA_Err_Control_Allocation_Error); YYABORT; } } @@ -539,14 +539,14 @@ range: void -TA_deltas_error(YYLTYPE *locp, - Deltas_Context* context, - char const* msg) +TA_control_error(YYLTYPE *locp, + Control_Context* context, + char const* msg) { /* if `error' is already set, we have a fatal flex error */ if (!context->error) { - context->error = TA_Err_Deltas_Syntax_Error; + context->error = TA_Err_Control_Syntax_Error; strncpy(context->errmsg, msg, sizeof (context->errmsg)); } @@ -558,7 +558,7 @@ TA_deltas_error(YYLTYPE *locp, void store_error_data(const YYLTYPE *locp, - Deltas_Context* context, + Control_Context* context, TA_Error error) { context->error = error; @@ -578,8 +578,8 @@ store_error_data(const YYLTYPE *locp, * * make libnumberset.la * - * flex -d tadeltas.flex \ - * && bison -t tadeltas.bison \ + * flex -d tacontrol.flex \ + * && bison -t tacontrol.bison \ * && gcc -g3 -O0 \ * -Wall -W \ * -I.. \ @@ -587,10 +587,10 @@ store_error_data(const YYLTYPE *locp, * -I/usr/local/include/freetype2 \ * -I/usr/local/include/harfbuzz \ * -L.libs \ - * -o tadeltas-bison \ - * tadeltas-bison.c \ - * tadeltas-flex.c \ - * tadeltas.c \ + * -o tacontrol-bison \ + * tacontrol-bison.c \ + * tacontrol-flex.c \ + * tacontrol.c \ * -lfreetype \ * -lnumberset */ @@ -613,7 +613,7 @@ main(int argc, int bison_error; int retval = 1; - Deltas_Context context; + Control_Context context; FONT font; SFNT sfnts[1]; FT_Library library; @@ -651,24 +651,24 @@ main(int argc, font.num_sfnts = 1; font.sfnts = sfnts; - font.deltas_buf = (char*)input; - font.deltas_len = strlen(input); + font.control_buf = (char*)input; + font.control_len = strlen(input); - TA_deltas_debug = 1; + TA_control_debug = 1; - TA_deltas_scanner_init(&context, &font); + TA_control_scanner_init(&context, &font); if (context.error) goto Exit2; - bison_error = TA_deltas_parse(&context); + bison_error = TA_control_parse(&context); if (bison_error) goto Exit3; retval = 0; Exit3: - TA_deltas_scanner_done(&context); - TA_deltas_free(context.result); + TA_control_scanner_done(&context); + TA_control_free(context.result); Exit2: FT_Done_Face(face); @@ -682,4 +682,4 @@ Exit0: #endif -/* end of tadeltas.bison */ +/* end of tacontrol.bison */ diff --git a/lib/tadeltas.c b/lib/tacontrol.c similarity index 54% rename from lib/tadeltas.c rename to lib/tacontrol.c index df97c1b..e2b6bbc 100644 --- a/lib/tadeltas.c +++ b/lib/tacontrol.c @@ -1,4 +1,4 @@ -/* tadeltas.c */ +/* tacontrol.c */ /* * Copyright (C) 2014 by Werner Lemberg. @@ -21,43 +21,43 @@ #include /* for llrb.h */ #include "llrb.h" /* a red-black tree implementation */ -#include "tadeltas-bison.h" - -Deltas* -TA_deltas_new(long font_idx, - long glyph_idx, - number_range* point_set, - double x_shift, - double y_shift, - number_range* ppem_set) +#include "tacontrol-bison.h" + +Control* +TA_control_new(long font_idx, + long glyph_idx, + number_range* point_set, + double x_shift, + double y_shift, + number_range* ppem_set) { - Deltas* deltas; + Control* control; - deltas = (Deltas*)malloc(sizeof (Deltas)); - if (!deltas) + control = (Control*)malloc(sizeof (Control)); + if (!control) return NULL; - deltas->font_idx = font_idx; - deltas->glyph_idx = glyph_idx; - deltas->points = number_set_reverse(point_set); + control->font_idx = font_idx; + control->glyph_idx = glyph_idx; + control->points = number_set_reverse(point_set); - /* we round shift values to multiples of 1/(2^DELTA_SHIFT) */ - deltas->x_shift = (char)(x_shift * DELTA_FACTOR - + (x_shift > 0 ? 0.5 : -0.5)); - deltas->y_shift = (char)(y_shift * DELTA_FACTOR - + (y_shift > 0 ? 0.5 : -0.5)); + /* we round shift values to multiples of 1/(2^CONTROL_DELTA_SHIFT) */ + control->x_shift = (char)(x_shift * CONTROL_DELTA_FACTOR + + (x_shift > 0 ? 0.5 : -0.5)); + control->y_shift = (char)(y_shift * CONTROL_DELTA_FACTOR + + (y_shift > 0 ? 0.5 : -0.5)); - deltas->ppems = number_set_reverse(ppem_set); - deltas->next = NULL; + control->ppems = number_set_reverse(ppem_set); + control->next = NULL; - return deltas; + return control; } -Deltas* -TA_deltas_prepend(Deltas* list, - Deltas* element) +Control* +TA_control_prepend(Control* list, + Control* element) { if (!element) return list; @@ -68,10 +68,10 @@ TA_deltas_prepend(Deltas* list, } -Deltas* -TA_deltas_reverse(Deltas* list) +Control* +TA_control_reverse(Control* list) { - Deltas* cur; + Control* cur; cur = list; @@ -79,7 +79,7 @@ TA_deltas_reverse(Deltas* list) while (cur) { - Deltas* tmp; + Control* tmp; tmp = cur; @@ -93,26 +93,26 @@ TA_deltas_reverse(Deltas* list) void -TA_deltas_free(Deltas* deltas) +TA_control_free(Control* control) { - while (deltas) + while (control) { - Deltas* tmp; + Control* tmp; - number_set_free(deltas->points); - number_set_free(deltas->ppems); + number_set_free(control->points); + number_set_free(control->ppems); - tmp = deltas; - deltas = deltas->next; + tmp = control; + control = control->next; free(tmp); } } sds -deltas_show_line(FONT* font, - Deltas* deltas) +control_show_line(FONT* font, + Control* control) { char glyph_name_buf[64]; char* points_buf = NULL; @@ -125,40 +125,40 @@ deltas_show_line(FONT* font, s = sdsempty(); - if (!deltas) + if (!control) goto Exit; - if (deltas->font_idx >= font->num_sfnts) + if (control->font_idx >= font->num_sfnts) goto Exit; - face = font->sfnts[deltas->font_idx].face; + face = font->sfnts[control->font_idx].face; glyph_name_buf[0] = '\0'; if (FT_HAS_GLYPH_NAMES(face)) - FT_Get_Glyph_Name(face, deltas->glyph_idx, glyph_name_buf, 64); + FT_Get_Glyph_Name(face, control->glyph_idx, glyph_name_buf, 64); - points_buf = number_set_show(deltas->points, -1, -1); + points_buf = number_set_show(control->points, -1, -1); if (!points_buf) goto Exit; - ppems_buf = number_set_show(deltas->ppems, -1, -1); + ppems_buf = number_set_show(control->ppems, -1, -1); if (!ppems_buf) goto Exit; /* display glyph index if we don't have a glyph name */ if (*glyph_name_buf) s = sdscatprintf(s, "%ld %s p %s x %.20g y %.20g @ %s", - deltas->font_idx, + control->font_idx, glyph_name_buf, points_buf, - (double)deltas->x_shift / DELTA_FACTOR, - (double)deltas->y_shift / DELTA_FACTOR, + (double)control->x_shift / CONTROL_DELTA_FACTOR, + (double)control->y_shift / CONTROL_DELTA_FACTOR, ppems_buf); else s = sdscatprintf(s, "%ld %ld p %s x %.20g y %.20g @ %s", - deltas->font_idx, - deltas->glyph_idx, + control->font_idx, + control->glyph_idx, points_buf, - (double)deltas->x_shift / DELTA_FACTOR, - (double)deltas->y_shift / DELTA_FACTOR, + (double)control->x_shift / CONTROL_DELTA_FACTOR, + (double)control->y_shift / CONTROL_DELTA_FACTOR, ppems_buf); Exit: @@ -170,24 +170,24 @@ Exit: char* -TA_deltas_show(FONT* font) +TA_control_show(FONT* font) { sds s; size_t len; char* res; - Deltas* deltas = font->deltas; + Control* control = font->control; s = sdsempty(); - while (deltas) + while (control) { sds d; /* append current line to buffer, followed by a newline character */ - d = deltas_show_line(font, deltas); + d = control_show_line(font, control); if (!d) { sdsfree(s); @@ -197,7 +197,7 @@ TA_deltas_show(FONT* font) sdsfree(d); s = sdscat(s, "\n"); - deltas = deltas->next; + control = control->next; } if (!s) @@ -215,44 +215,44 @@ TA_deltas_show(FONT* font) } -/* Parse delta exceptions in `font->deltas_buf'. */ +/* Parse control instructions in `font->control_buf'. */ TA_Error -TA_deltas_parse_buffer(FONT* font, - char** error_string_p, - unsigned int* errlinenum_p, - char** errline_p, - char** errpos_p) +TA_control_parse_buffer(FONT* font, + char** error_string_p, + unsigned int* errlinenum_p, + char** errline_p, + char** errpos_p) { int bison_error; - Deltas_Context context; + Control_Context context; /* nothing to do if no data */ - if (!font->deltas_buf) + if (!font->control_buf) { - font->deltas = NULL; + font->control = NULL; return TA_Err_Ok; } - TA_deltas_scanner_init(&context, font); + TA_control_scanner_init(&context, font); if (context.error) goto Fail; /* this is `yyparse' in disguise */ - bison_error = TA_deltas_parse(&context); - TA_deltas_scanner_done(&context); + bison_error = TA_control_parse(&context); + TA_control_scanner_done(&context); if (bison_error) { if (bison_error == 2) - context.error = TA_Err_Deltas_Allocation_Error; + context.error = TA_Err_Control_Allocation_Error; Fail: - font->deltas = NULL; + font->control = NULL; - if (context.error == TA_Err_Deltas_Allocation_Error - || context.error == TA_Err_Deltas_Flex_Error) + if (context.error == TA_Err_Control_Allocation_Error + || context.error == TA_Err_Control_Flex_Error) { *errlinenum_p = 0; *errline_p = NULL; @@ -273,9 +273,9 @@ Fail: /* construct data for `errline_p' */ - buf_end = font->deltas_buf + font->deltas_len; + buf_end = font->control_buf + font->control_len; - p_start = font->deltas_buf; + p_start = font->control_buf; if (context.errline_num > 1) { i = 1; @@ -300,19 +300,19 @@ Fail: *errline_p = strndup(p_start, p_end - p_start); /* construct data for `error_string_p' */ - if (context.error == TA_Err_Deltas_Invalid_Font_Index) + if (context.error == TA_Err_Control_Invalid_Font_Index) sprintf(auxbuf, " (valid range is [%ld;%ld])", 0L, font->num_sfnts); - else if (context.error == TA_Err_Deltas_Invalid_Glyph_Index) + else if (context.error == TA_Err_Control_Invalid_Glyph_Index) sprintf(auxbuf, " (valid range is [%ld;%ld])", 0L, font->sfnts[context.font_idx].face->num_glyphs); - else if (context.error == TA_Err_Deltas_Invalid_Shift) + else if (context.error == TA_Err_Control_Invalid_Shift) sprintf(auxbuf, " (valid interval is [%g;%g])", - DELTA_SHIFT_MIN, - DELTA_SHIFT_MAX); - else if (context.error == TA_Err_Deltas_Invalid_Range) + CONTROL_DELTA_SHIFT_MIN, + CONTROL_DELTA_SHIFT_MAX); + else if (context.error == TA_Err_Control_Invalid_Range) sprintf(auxbuf, " (values must be within [%ld;%ld])", context.number_set_min, context.number_set_max); @@ -335,19 +335,19 @@ Fail: } } else - font->deltas = context.result; + font->control = context.result; return context.error; } -/* node structure for delta exception data */ +/* node structure for control instruction data */ typedef struct Node Node; struct Node { LLRB_ENTRY(Node) entry; - Delta delta; + Ctrl ctrl; }; @@ -361,22 +361,22 @@ nodecmp(Node* e1, /* sort by font index ... */ - diff = e1->delta.font_idx - e2->delta.font_idx; + diff = e1->ctrl.font_idx - e2->ctrl.font_idx; if (diff) goto Exit; /* ... then by glyph index ... */ - diff = e1->delta.glyph_idx - e2->delta.glyph_idx; + diff = e1->ctrl.glyph_idx - e2->ctrl.glyph_idx; if (diff) goto Exit; /* ... then by ppem ... */ - diff = e1->delta.ppem - e2->delta.ppem; + diff = e1->ctrl.ppem - e2->ctrl.ppem; if (diff) goto Exit; /* ... then by point index */ - diff = e1->delta.point_idx - e2->delta.point_idx; + diff = e1->ctrl.point_idx - e2->ctrl.point_idx; Exit: /* https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign */ @@ -385,72 +385,72 @@ Exit: /* the red-black tree function body */ -typedef struct deltas_data deltas_data; +typedef struct control_data control_data; -LLRB_HEAD(deltas_data, Node); +LLRB_HEAD(control_data, Node); /* no trailing semicolon in the next line */ -LLRB_GENERATE_STATIC(deltas_data, Node, entry, nodecmp) +LLRB_GENERATE_STATIC(control_data, Node, entry, nodecmp) void -TA_deltas_free_tree(FONT* font) +TA_control_free_tree(FONT* font) { - deltas_data* deltas_data_head = (deltas_data*)font->deltas_data_head; + control_data* control_data_head = (control_data*)font->control_data_head; Node* node; Node* next_node; - if (!deltas_data_head) + if (!control_data_head) return; - for (node = LLRB_MIN(deltas_data, deltas_data_head); + for (node = LLRB_MIN(control_data, control_data_head); node; node = next_node) { - next_node = LLRB_NEXT(deltas_data, deltas_data_head, node); - LLRB_REMOVE(deltas_data, deltas_data_head, node); + next_node = LLRB_NEXT(control_data, control_data_head, node); + LLRB_REMOVE(control_data, control_data_head, node); free(node); } - free(deltas_data_head); + free(control_data_head); } TA_Error -TA_deltas_build_tree(FONT* font) +TA_control_build_tree(FONT* font) { - Deltas* deltas = font->deltas; - deltas_data* deltas_data_head; + Control* control = font->control; + control_data* control_data_head; int emit_newline = 0; /* nothing to do if no data */ - if (!deltas) + if (!control) { - font->deltas_data_head = NULL; + font->control_data_head = NULL; return TA_Err_Ok; } - deltas_data_head = (deltas_data*)malloc(sizeof (deltas_data)); - if (!deltas_data_head) + control_data_head = (control_data*)malloc(sizeof (control_data)); + if (!control_data_head) return FT_Err_Out_Of_Memory; - LLRB_INIT(deltas_data_head); + LLRB_INIT(control_data_head); - while (deltas) + while (control) { - long font_idx = deltas->font_idx; - long glyph_idx = deltas->glyph_idx; - char x_shift = deltas->x_shift; - char y_shift = deltas->y_shift; + long font_idx = control->font_idx; + long glyph_idx = control->glyph_idx; + char x_shift = control->x_shift; + char y_shift = control->y_shift; number_set_iter ppems_iter; int ppem; - ppems_iter.range = deltas->ppems; + ppems_iter.range = control->ppems; ppem = number_set_get_first(&ppems_iter); while (ppems_iter.range) @@ -459,7 +459,7 @@ TA_deltas_build_tree(FONT* font) int point_idx; - points_iter.range = deltas->points; + points_iter.range = control->points; point_idx = number_set_get_first(&points_iter); while (points_iter.range) @@ -472,27 +472,27 @@ TA_deltas_build_tree(FONT* font) if (!node) return FT_Err_Out_Of_Memory; - node->delta.font_idx = font_idx; - node->delta.glyph_idx = glyph_idx; - node->delta.ppem = ppem; - node->delta.point_idx = point_idx; - node->delta.x_shift = x_shift; - node->delta.y_shift = y_shift; + node->ctrl.font_idx = font_idx; + node->ctrl.glyph_idx = glyph_idx; + node->ctrl.ppem = ppem; + node->ctrl.point_idx = point_idx; + node->ctrl.x_shift = x_shift; + node->ctrl.y_shift = y_shift; - val = LLRB_INSERT(deltas_data, deltas_data_head, node); + val = LLRB_INSERT(control_data, control_data_head, node); if (val) free(node); if (val && font->debug) { /* entry is already present; we ignore it */ - Deltas d; + Control d; number_range ppems; number_range points; sds s; - /* construct Deltas entry for debugging output */ + /* construct Control entry for debugging output */ ppems.start = ppem; ppems.end = ppem; ppems.next = NULL; @@ -508,10 +508,10 @@ TA_deltas_build_tree(FONT* font) d.ppems = &ppems; d.next = NULL; - s = deltas_show_line(font, &d); + s = control_show_line(font, &d); if (s) { - fprintf(stderr, "Delta exception %s ignored.\n", s); + fprintf(stderr, "Control instruction %s ignored.\n", s); sdsfree(s); } @@ -524,45 +524,45 @@ TA_deltas_build_tree(FONT* font) ppem = number_set_get_next(&ppems_iter); } - deltas = deltas->next; + control = control->next; } if (font->debug && emit_newline) fprintf(stderr, "\n"); - font->deltas_data_head = deltas_data_head; - font->deltas_data_cur = LLRB_MIN(deltas_data, deltas_data_head); + font->control_data_head = control_data_head; + font->control_data_cur = LLRB_MIN(control_data, control_data_head); return TA_Err_Ok; } /* the next functions are intended to restrict the use of LLRB stuff */ -/* related to delta exceptions to this file, */ +/* related to control instructions to this file, */ /* providing a means to access the data sequentially */ void -TA_deltas_get_next(FONT* font) +TA_control_get_next(FONT* font) { - Node* node = (Node*)font->deltas_data_cur; + Node* node = (Node*)font->control_data_cur; if (!node) return; - node = LLRB_NEXT(deltas_data, /* unused */, node); + node = LLRB_NEXT(control_data, /* unused */, node); - font->deltas_data_cur = node; + font->control_data_cur = node; } -const Delta* -TA_deltas_get_delta(FONT* font) +const Ctrl* +TA_control_get_ctrl(FONT* font) { - Node* node = (Node*)font->deltas_data_cur; + Node* node = (Node*)font->control_data_cur; - return node ? &node->delta : NULL; + return node ? &node->ctrl : NULL; } -/* end of tadeltas.c */ +/* end of tacontrol.c */ diff --git a/lib/tadeltas.flex b/lib/tacontrol.flex similarity index 82% rename from lib/tadeltas.flex rename to lib/tacontrol.flex index 629c45f..5166cf1 100644 --- a/lib/tadeltas.flex +++ b/lib/tacontrol.flex @@ -1,4 +1,4 @@ -/* tadeltas.flex */ +/* tacontrol.flex */ /* * Copyright (C) 2014 by Werner Lemberg. @@ -13,7 +13,7 @@ */ /* - * lexical analyzer for parsing delta exceptions + * lexical analyzer for parsing ttfautohint control instructions * * Lexing errors are indicated by setting `context->error' to an appropriate * value; fatal lexer errors return token `INTERNAL_FLEX_ERROR'. @@ -22,8 +22,8 @@ /* you should use flex version >= 2.5.39 to avoid various buglets */ /* that don't have work-arounds */ -%option outfile="tadeltas-flex.c" -%option header-file="tadeltas-flex.h" +%option outfile="tacontrol-flex.c" +%option header-file="tacontrol-flex.h" %option batch %option bison-bridge @@ -44,7 +44,7 @@ #include #include "ta.h" -#include "tadeltas-bison.h" +#include "tacontrol-bison.h" /* option `yylineno' resets `yycolumn' to 0 after a newline */ /* (since version 2.5.30, March 2003) before the next token gets read; */ @@ -57,9 +57,9 @@ yylloc->last_column = yycolumn + yyleng - 1; \ yycolumn += yyleng; -#define YY_EXTRA_TYPE Deltas_Context* +#define YY_EXTRA_TYPE Control_Context* -#define YY_FATAL_ERROR(msg) TA_deltas_scanner_fatal_error(msg, yyscanner) +#define YY_FATAL_ERROR(msg) TA_control_scanner_fatal_error(msg, yyscanner) /* by default, `yylex' simply calls `exit' (via YY_FATAL_ERROR) */ /* in case of a (more or less) fatal error -- */ @@ -72,7 +72,7 @@ if (setjmp(yyextra->jump_buffer) != 0) \ { \ /* error and error message in `context' already stored by */ \ - /* `TA_deltas_scanner_fatal_error' */ \ + /* `TA_control_scanner_fatal_error' */ \ return INTERNAL_FLEX_ERROR; \ } \ } while (0) @@ -83,8 +83,8 @@ #define YY_EXIT_FAILURE ((void)yyscanner, 2) void -TA_deltas_scanner_fatal_error(const char* msg, - yyscan_t yyscanner); +TA_control_scanner_fatal_error(const char* msg, + yyscan_t yyscanner); %} @@ -143,7 +143,7 @@ TA_deltas_scanner_fatal_error(const char* msg, if (errno == ERANGE) { /* overflow or underflow */ - yyextra->error = TA_Err_Deltas_Overflow; + yyextra->error = TA_Err_Control_Overflow; } return INTEGER; } @@ -158,7 +158,7 @@ TA_deltas_scanner_fatal_error(const char* msg, if (yylval->real && errno == ERANGE) { /* overflow */ - yyextra->error = TA_Err_Deltas_Overflow; + yyextra->error = TA_Err_Control_Overflow; } return REAL; } @@ -176,7 +176,7 @@ TA_deltas_scanner_fatal_error(const char* msg, if (!yylval->name) { /* allocation error */ - yyextra->error = TA_Err_Deltas_Allocation_Error; + yyextra->error = TA_Err_Control_Allocation_Error; } return NAME; } @@ -206,7 +206,7 @@ yyalloc(yy_size_t size, if (!p && yyscanner) { context = yyget_extra(yyscanner); - context->error = TA_Err_Deltas_Allocation_Error; + context->error = TA_Err_Control_Allocation_Error; } return p; } @@ -224,7 +224,7 @@ yyrealloc(void* ptr, if (!p && yyscanner) { context = yyget_extra(yyscanner); - context->error = TA_Err_Deltas_Allocation_Error; + context->error = TA_Err_Control_Allocation_Error; } return p; } @@ -242,15 +242,15 @@ yyfree(void* ptr, void -TA_deltas_scanner_fatal_error(const char* msg, - yyscan_t yyscanner) +TA_control_scanner_fatal_error(const char* msg, + yyscan_t yyscanner) { YY_EXTRA_TYPE context = yyget_extra(yyscanner); /* allocation routines set a different error value */ if (!context->error) - context->error = TA_Err_Deltas_Flex_Error; + context->error = TA_Err_Control_Flex_Error; strncpy(context->errmsg, msg, sizeof (context->errmsg)); longjmp(context->jump_buffer, 1); @@ -262,8 +262,8 @@ TA_deltas_scanner_fatal_error(const char* msg, void -TA_deltas_scanner_init(Deltas_Context* context, - FONT* font) +TA_control_scanner_init(Control_Context* context, + FONT* font) { int flex_error; @@ -296,11 +296,11 @@ TA_deltas_scanner_init(Deltas_Context* context, if (setjmp(context->jump_buffer) != 0) { /* error and error message in `context' already stored by */ - /* `TA_deltas_scanner_fatal_error' */ + /* `TA_control_scanner_fatal_error' */ return; } - b = yy_scan_bytes(font->deltas_buf, font->deltas_len, scanner); + b = yy_scan_bytes(font->control_buf, font->control_len, scanner); /* flex bug: these two fields are not initialized, */ /* causing zillions of valgrind errors; see */ @@ -311,7 +311,7 @@ TA_deltas_scanner_init(Deltas_Context* context, void -TA_deltas_scanner_done(Deltas_Context* context) +TA_control_scanner_done(Control_Context* context) { yylex_destroy(context->scanner); } @@ -334,17 +334,17 @@ main(void) int retval = 1; FONT font; - Deltas_Context context; + Control_Context context; YYSTYPE yylval_param; YYLTYPE yylloc_param; - /* we only need the delta exceptions buffer */ - font.deltas_buf = (char*)input; - font.deltas_len = strlen(input); + /* we only need the control instructions buffer */ + font.control_buf = (char*)input; + font.control_len = strlen(input); - TA_deltas_scanner_init(&context, &font); + TA_control_scanner_init(&context, &font); if (context.error) goto Exit; @@ -358,11 +358,11 @@ main(void) retval = 0; Exit: - TA_deltas_scanner_done(&context); + TA_control_scanner_done(&context); return retval; } #endif -/* end of tadeltas.flex */ +/* end of tacontrol.flex */ diff --git a/lib/tacontrol.h b/lib/tacontrol.h new file mode 100644 index 0000000..1062b49 --- /dev/null +++ b/lib/tacontrol.h @@ -0,0 +1,303 @@ +/* tacontrol.h */ + +/* + * 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. + */ + + +#ifndef __TACONTROL_H__ +#define __TACONTROL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include /* for flex error handling */ + + +/* see the section `Managing exceptions' in chapter 6 */ +/* (`The TrueType Instruction Set') of the OpenType reference */ +/* how `delta_shift' works */ + +#define CONTROL_DELTA_SHIFT 3 /* 1/8px */ +#define CONTROL_DELTA_FACTOR (1 << CONTROL_DELTA_SHIFT) + +#define CONTROL_DELTA_SHIFT_MAX ((1.0 / CONTROL_DELTA_FACTOR) * 8) +#define CONTROL_DELTA_SHIFT_MIN -CONTROL_DELTA_SHIFT_MAX + + +/* + * For the generated TrueType bytecode, we use + * + * delta_base = 6 , + * + * which gives us the following ppem ranges for the three delta + * instructions: + * + * DELTAP1 6-21ppem + * DELTAP2 22-37ppem + * DELTAP3 38-53ppem . + */ + +#define CONTROL_DELTA_PPEM_MIN 6 +#define CONTROL_DELTA_PPEM_MAX 53 + + +/* + * A structure to hold control instructions for a glyph. A linked list of it + * gets allocated by a successful call to `TA_control_parse_buffer'. Use + * `TA_control_free' to deallocate the list. + * + * `x_shift' and `y_shift' are always in the range [-8;8]. + * + * The `Control' typedef is in `ta.h'. + */ + +struct Control_ +{ + long font_idx; + long glyph_idx; + number_range* points; + char x_shift; + char y_shift; + number_range* ppems; + + struct Control_* next; +}; + + +/* + * A structure to hold a single control instruction. + */ + +typedef struct Ctrl_ +{ + long font_idx; + long glyph_idx; + int ppem; + int point_idx; + + char x_shift; + char y_shift; +} Ctrl; + + +/* + * This structure is used for communication with `TA_control_parse'. + */ + +typedef struct Control_Context_ +{ + /* The error code returned by the parser or lexer. */ + TA_Error error; + + /* If no error, this holds the parsing result. */ + Control* result; + + /* + * The parser's or lexer's error message in case of error; might be the + * empty string. + */ + char errmsg[256]; + + /* + * In case of error, `errline_num' gives the line number of the offending + * line in `font->control_buf', starting with value 1; `errline_pos_left' + * and `errline_pos_right' hold the left and right position of the + * offending token in this line, also starting with value 1. For + * allocation errors or internal parser or lexer errors those values are + * meaningless, though. + */ + int errline_num; + int errline_pos_left; + int errline_pos_right; + + /* + * The current font index, useful for `TA_Err_Control_Invalid_Font_Index'. + */ + long font_idx; + + /* + * The current glyph index, useful for + * `TA_Err_Control_Invalid_Glyph_Index'. + */ + long glyph_idx; + + /* + * If the returned error is `TA_Err_Control_Invalid_Range', these two + * values set up the allowed range. + */ + long number_set_min; + long number_set_max; + + /* private flex data */ + void* scanner; + int eof; + jmp_buf jump_buffer; + + /* private bison data */ + FONT* font; +} Control_Context; + + +/* + * Create and initialize a `Control' object. In case of an allocation error, + * the return value is NULL. `point_set' and `ppem_set' are expected to be + * in reverse list order; `TA_control_new' then reverts them to normal order. + */ + +Control* +TA_control_new(long font_idx, + long glyph_idx, + number_range* point_set, + double x_shift, + double y_shift, + number_range* ppem_set); + + +/* + * Prepend `element' to `list' of `Control' objects. If `element' is NULL, + * return `list. + */ + +Control* +TA_control_prepend(Control* list, + Control* element); + + +/* + * Reverse a list of `Control' objects. + */ + +Control* +TA_control_reverse(Control* list); + + +/* + * Initialize the scanner data within a `Control_Context' object. + * `font->control_buf' is the control instructions buffer to be parsed, + * `font->control_len' its length. + * + * This function is defined in `tacontrol.flex'. + */ + +void +TA_control_scanner_init(Control_Context* context, + FONT* font); + + +/* + * Free the scanner data within a `Control_Context' object. + * + * This function is defined in `tacontrol.flex'. + */ + +void +TA_control_scanner_done(Control_Context* context); + + +/* + * Parse buffer with ttfautohint control instructions, stored in + * `font->control_buf' with length `font->control_len'. + * + * The format of entries in such a control instructions buffer is given in + * `ttfautohint.h' (option `control-file'); the following describes more + * technical details, using the constants defined above. + * + * x shift and y shift values represent floating point numbers that get + * rounded to multiples of 1/(2^CONTROL_DELTA_SHIFT) pixels. + * + * Values for x and y shifts must be in the range + * [CONTROL_DELTA_SHIFT_MIN;CONTROL_DELTA_SHIFT_MAX]. Values for ppems must + * be in the range [CONTROL_DELTA_PPEM_MIN;CONTROL_DELTA_PPEM_MAX]. + * + * The returned error codes are 0 (TA_Err_Ok) or in the range 0x200-0x2FF; + * see `ttfautohint-errors.h' for all possible values. + * + * `TA_control_parse_buffer' stores the parsed result in `font->control', to + * be freed with `TA_control_free' after use. If there is no control + * instructions data (for example, an empty string or whitespace only) + * nothing gets allocated, and `font->control' is set to NULL. + * + * In case of error, `error_string_p' holds an error message, `errlinenum_p' + * gives the line number in the control instructions buffer where the error + * occurred, `errline_p' the corresponding line, and `errpos_p' the position + * in this line. After use, `error_string_p' and `errline_p' must be + * deallocated by the user. Note that `errline_p' and `errpos_p' can be + * NULL even in case of an error. If there is no error, those four values + * are undefined. + */ + +TA_Error +TA_control_parse_buffer(FONT* font, + char** error_string_p, + unsigned int* errlinenum_p, + char** errline_p, + char** errpos_p); + + +/* + * Free the allocated data in `control'. + */ + +void +TA_control_free(Control* control); + + +/* + * Return a string representation of `font->control'. After use, the string + * should be deallocated with a call to `free'. In case of an allocation + * error, the return value is NULL. + */ + +char* +TA_control_show(FONT* font); + + +/* + * Build a tree providing sequential access to the control instructions data + * in `font->control'. This also sets `font->control_data_cur' to the first + * element (or NULL if there isn't one). + */ + +TA_Error +TA_control_build_tree(FONT* font); + + +/* + * Free the control instructions data tree. + */ + +void +TA_control_free_tree(FONT* font); + + +/* + * Get next control instruction and store it in `font->control_data_cur'. + */ + +void +TA_control_get_next(FONT* font); + + +/* + * Access control instruction. Return NULL if there is no more data. + */ +const Ctrl* +TA_control_get_ctrl(FONT* font); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __TACONTROL_H__ */ + +/* end of control.h */ diff --git a/lib/tadeltas.h b/lib/tadeltas.h deleted file mode 100644 index 356d69d..0000000 --- a/lib/tadeltas.h +++ /dev/null @@ -1,303 +0,0 @@ -/* tadeltas.h */ - -/* - * 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. - */ - - -#ifndef __TADELTAS_H__ -#define __TADELTAS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include /* for flex error handling */ - - -/* see the section `Managing exceptions' in chapter 6 */ -/* (`The TrueType Instruction Set') of the OpenType reference */ -/* how `delta_shift' works */ - -#define DELTA_SHIFT 3 /* 1/8px */ -#define DELTA_FACTOR (1 << DELTA_SHIFT) - -#define DELTA_SHIFT_MAX ((1.0 / DELTA_FACTOR) * 8) -#define DELTA_SHIFT_MIN -DELTA_SHIFT_MAX - - -/* - * For the generated TrueType bytecode, we use - * - * delta_base = 6 , - * - * which gives us the following ppem ranges for the three delta - * instructions: - * - * DELTAP1 6-21ppem - * DELTAP2 22-37ppem - * DELTAP3 38-53ppem . - */ - -#define DELTA_PPEM_MIN 6 -#define DELTA_PPEM_MAX 53 - - -/* - * A structure to hold delta exceptions for a glyph. A linked list of it - * gets allocated by a successful call to `TA_deltas_parse_buffer'. Use - * `TA_deltas_free' to deallocate the list. - * - * `x_shift' and `y_shift' are always in the range [-8;8]. - * - * The `Deltas' typedef is in `ta.h'. - */ - -struct Deltas_ -{ - long font_idx; - long glyph_idx; - number_range* points; - char x_shift; - char y_shift; - number_range* ppems; - - struct Deltas_* next; -}; - - -/* - * A structure to hold a single delta exception. - */ - -typedef struct Delta_ -{ - long font_idx; - long glyph_idx; - int ppem; - int point_idx; - - char x_shift; - char y_shift; -} Delta; - - -/* - * This structure is used for communication with `TA_deltas_parse'. - */ - -typedef struct Deltas_Context_ -{ - /* The error code returned by the parser or lexer. */ - TA_Error error; - - /* If no error, this holds the parsing result. */ - Deltas* result; - - /* - * The parser's or lexer's error message in case of error; might be the - * empty string. - */ - char errmsg[256]; - - /* - * In case of error, `errline_num' gives the line number of the offending - * line in `font->delta_buf', starting with value 1; `errline_pos_left' - * and `errline_pos_right' hold the left and right position of the - * offending token in this line, also starting with value 1. For - * allocation errors or internal parser or lexer errors those values are - * meaningless, though. - */ - int errline_num; - int errline_pos_left; - int errline_pos_right; - - /* - * The current font index, useful for `TA_Err_Deltas_Invalid_Font_Index'. - */ - long font_idx; - - /* - * The current glyph index, useful for - * `TA_Err_Deltas_Invalid_Glyph_Index'. - */ - long glyph_idx; - - /* - * If the returned error is `TA_Err_Deltas_Invalid_Range', these two - * values set up the allowed range. - */ - long number_set_min; - long number_set_max; - - /* private flex data */ - void* scanner; - int eof; - jmp_buf jump_buffer; - - /* private bison data */ - FONT* font; -} Deltas_Context; - - -/* - * Create and initialize a `Deltas' object. In case of an allocation error, - * the return value is NULL. `point_set' and `ppem_set' are expected to be - * in reverse list order; `TA_deltas_new' then reverts them to normal order. - */ - -Deltas* -TA_deltas_new(long font_idx, - long glyph_idx, - number_range* point_set, - double x_shift, - double y_shift, - number_range* ppem_set); - - -/* - * Prepend `element' to `list' of `Deltas' objects. If `element' is NULL, - * return `list. - */ - -Deltas* -TA_deltas_prepend(Deltas* list, - Deltas* element); - - -/* - * Reverse a list of `Deltas' objects. - */ - -Deltas* -TA_deltas_reverse(Deltas* list); - - -/* - * Initialize the scanner data within a `Deltas_Context' object. - * `font->delta_buf' is the delta exceptions buffer to be parsed, - * `font->delta_len' its length. - * - * This function is defined in `tadeltas.l'. - */ - -void -TA_deltas_scanner_init(Deltas_Context* context, - FONT* font); - - -/* - * Free the scanner data within a `Deltas_Context' object. - * - * This function is defined in `tadeltas.l'. - */ - -void -TA_deltas_scanner_done(Deltas_Context* context); - - -/* - * Parse buffer with descriptions of delta exceptions, stored in - * `font->deltas_buf' with length `font->deltas_len'. - * - * The format of lines in such a delta exceptions buffer is given in - * `ttfautohint.h' (option `deltas-file'); the following describes more - * technical details, using the constants defined above. - * - * x shift and y shift values represent floating point numbers that get - * rounded to multiples of 1/(2^DELTA_SHIFT) pixels. - * - * Values for x and y shifts must be in the range - * [DELTA_SHIFT_MIN;DELTA_SHIFT_MAX]. Values for ppems must be in the range - * [DELTA_PPEM_MIN;DELTA_PPEM_MAX]. - * - * The returned error codes are 0 (TA_Err_Ok) or in the range 0x200-0x2FF; - * see `ttfautohint-errors.h' for all possible values. - * - * `TA_deltas_parse_buffer' stores the parsed result in `font->deltas', to - * be freed with `TA_deltas_free' after use. If there is no delta - * exceptions data (for example, an empty string or whitespace only) nothing - * gets allocated, and `font->deltas' is set to NULL. - * - * In case of error, `error_string_p' holds an error message, `errlinenum_p' - * gives the line number in the delta exceptions buffer where the error - * occurred, `errline_p' the corresponding line, and `errpos_p' the position - * in this line. After use, `error_string_p' and `errline_p' must be - * deallocated by the user. Note that `errline_p' and `errpos_p' can be - * NULL even in case of an error. If there is no error, those four values - * are undefined. - */ - -TA_Error -TA_deltas_parse_buffer(FONT* font, - char** error_string_p, - unsigned int* errlinenum_p, - char** errline_p, - char** errpos_p); - - -/* - * Free the allocated data in `deltas'. - */ - -void -TA_deltas_free(Deltas* deltas); - - -/* - * Return a string representation of `font->deltas'. After use, the string - * should be deallocated with a call to `free'. In case of an allocation - * error, the return value is NULL. - */ - -char* -TA_deltas_show(FONT* font); - - -/* - * Build a tree providing sequential access to the delta exceptions data in - * `font->deltas'. This also sets `font->deltas_data_cur' to the first - * element (or NULL if there isn't one). - */ - -TA_Error -TA_deltas_build_tree(FONT* font); - - -/* - * Free the delta exceptions data tree. - */ - -void -TA_deltas_free_tree(FONT* font); - - -/* - * Get next delta exception and store it in `font->deltas_data_cur'. - */ - -void -TA_deltas_get_next(FONT* font); - - -/* - * Access delta exception. Return NULL if there is no more data. - */ -const Delta* -TA_deltas_get_delta(FONT* font); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* __TADELTAS_H__ */ - -/* end of deltas.h */ diff --git a/lib/tadump.c b/lib/tadump.c index bddfd9a..a481804 100644 --- a/lib/tadump.c +++ b/lib/tadump.c @@ -121,7 +121,7 @@ TA_font_dump_parameters(FONT* font, DUMPSTR("x-height-snapping-exceptions", ns); - ds = TA_deltas_show(font); + ds = TA_control_show(font); if (!ds) { sdsfree(s); @@ -129,7 +129,7 @@ TA_font_dump_parameters(FONT* font, goto Exit; } - /* show delta exceptions data line by line */ + /* show control instructions line by line */ if (!format) { eol = ""; @@ -143,7 +143,7 @@ TA_font_dump_parameters(FONT* font, token = strtok_r(ds, "\n", &saveptr); - DUMPSTR("delta exceptions", token); + DUMPSTR("control instructions", token); for (;;) { @@ -155,7 +155,7 @@ TA_font_dump_parameters(FONT* font, } } else - DUMPSTR("delta exceptions", ""); + DUMPSTR("control instructions", ""); if (!format) s = sdscat(s, "\n"); diff --git a/lib/tafile.c b/lib/tafile.c index 193d9aa..adff99c 100644 --- a/lib/tafile.c +++ b/lib/tafile.c @@ -72,41 +72,41 @@ TA_font_file_write(FONT* font, FT_Error -TA_deltas_file_read(FONT* font, - FILE* deltas_file) +TA_control_file_read(FONT* font, + FILE* control_file) { char* buf[BUF_SIZE]; - size_t deltas_len = 0; + size_t control_len = 0; size_t read_bytes; - font->deltas_buf = (char*)malloc(BUF_SIZE); - if (!font->deltas_buf) + font->control_buf = (char*)malloc(BUF_SIZE); + if (!font->control_buf) return FT_Err_Out_Of_Memory; - while ((read_bytes = fread(buf, 1, BUF_SIZE, deltas_file)) > 0) + while ((read_bytes = fread(buf, 1, BUF_SIZE, control_file)) > 0) { - char* deltas_buf_new; + char* control_buf_new; /* we store the data as a C string, allocating one more byte */ - deltas_buf_new = (char*)realloc(font->deltas_buf, - deltas_len + read_bytes + 1); - if (!deltas_buf_new) + control_buf_new = (char*)realloc(font->control_buf, + control_len + read_bytes + 1); + if (!control_buf_new) return FT_Err_Out_Of_Memory; else - font->deltas_buf = deltas_buf_new; + font->control_buf = control_buf_new; - memcpy(font->deltas_buf + deltas_len, buf, read_bytes); + memcpy(font->control_buf + control_len, buf, read_bytes); - deltas_len += read_bytes; + control_len += read_bytes; } - if (ferror(deltas_file)) + if (ferror(control_file)) return FT_Err_Invalid_Stream_Read; - font->deltas_len = deltas_len; - font->deltas_buf[deltas_len] = '\0'; + font->control_len = control_len; + font->control_buf[control_len] = '\0'; return TA_Err_Ok; } diff --git a/lib/tafont.c b/lib/tafont.c index 868b378..b6cc377 100644 --- a/lib/tafont.c +++ b/lib/tafont.c @@ -53,7 +53,7 @@ void TA_font_unload(FONT* font, const char* in_buf, char** out_bufp, - const char* deltas_buf) + const char* control_buf) { /* in case of error it is expected that unallocated pointers */ /* are NULL (and counters are zero) */ @@ -118,8 +118,8 @@ TA_font_unload(FONT* font, free(font->in_buf); if (!out_bufp) free(font->out_buf); - if (!deltas_buf) - free(font->deltas_buf); + if (!control_buf) + free(font->control_buf); free(font); } diff --git a/lib/tafpgm.c b/lib/tafpgm.c index 2d05e88..8a32035 100644 --- a/lib/tafpgm.c +++ b/lib/tafpgm.c @@ -5692,7 +5692,7 @@ TA_table_build_fpgm(FT_Byte** fpgm, + sizeof (FPGM(bci_create_segments_a)) + 1 + sizeof (FPGM(bci_create_segments_b)) - + (font->deltas_data_head != 0 + + (font->control_data_head != 0 ? sizeof (FPGM(bci_create_segments_c)) : 0) + sizeof (FPGM(bci_create_segments_d)) @@ -5711,7 +5711,7 @@ TA_table_build_fpgm(FT_Byte** fpgm, + sizeof (FPGM(bci_create_segments_composite_a)) + 1 + sizeof (FPGM(bci_create_segments_composite_b)) - + (font->deltas_data_head != 0 + + (font->control_data_head != 0 ? sizeof (FPGM(bci_create_segments_composite_c)) : 0) + sizeof (FPGM(bci_create_segments_composite_d)) @@ -5736,7 +5736,7 @@ TA_table_build_fpgm(FT_Byte** fpgm, + sizeof (FPGM(bci_scale_composite_glyph)) + sizeof (FPGM(bci_shift_contour)) + sizeof (FPGM(bci_shift_subglyph_a)) - + (font->deltas_data_head != 0 + + (font->control_data_head != 0 ? sizeof (FPGM(bci_shift_subglyph_b)) : 0) + sizeof (FPGM(bci_shift_subglyph_c)) @@ -5872,7 +5872,7 @@ TA_table_build_fpgm(FT_Byte** fpgm, COPY_FPGM(bci_create_segments_a); *(bufp++) = (unsigned char)data->num_used_styles; COPY_FPGM(bci_create_segments_b); - if (font->deltas_data_head) + if (font->control_data_head) COPY_FPGM(bci_create_segments_c); COPY_FPGM(bci_create_segments_d); @@ -5890,7 +5890,7 @@ TA_table_build_fpgm(FT_Byte** fpgm, COPY_FPGM(bci_create_segments_composite_a); *(bufp++) = (unsigned char)data->num_used_styles; COPY_FPGM(bci_create_segments_composite_b); - if (font->deltas_data_head) + if (font->control_data_head) COPY_FPGM(bci_create_segments_composite_c); COPY_FPGM(bci_create_segments_composite_d); @@ -5914,7 +5914,7 @@ TA_table_build_fpgm(FT_Byte** fpgm, COPY_FPGM(bci_scale_composite_glyph); COPY_FPGM(bci_shift_contour); COPY_FPGM(bci_shift_subglyph_a); - if (font->deltas_data_head) + if (font->control_data_head) COPY_FPGM(bci_shift_subglyph_b); COPY_FPGM(bci_shift_subglyph_c); diff --git a/lib/taharfbuzz.c b/lib/taharfbuzz.c index 3f6f787..1838ef3 100644 --- a/lib/taharfbuzz.c +++ b/lib/taharfbuzz.c @@ -309,7 +309,7 @@ ta_get_coverage(TA_FaceGlobals globals, * out whether a glyph gets shifted vertically, but this is something I * would like to avoid if not really necessary. * - * Note that we don't follow this logic for the default coverage. + * Note that we don't follow this logic for the default coverage. * Complex scripts like Devanagari have mandatory GPOS features to * position many glyph elements, using mark-to-base or mark-to-ligature * tables; the number of glyphs missed due to condition (b) would be far diff --git a/lib/taprep.c b/lib/taprep.c index b9266ac..2bc0bb9 100644 --- a/lib/taprep.c +++ b/lib/taprep.c @@ -381,7 +381,7 @@ unsigned char PREP(adjust_delta_exceptions) [] = /* set delta base */ PUSHB_1, - DELTA_PPEM_MIN, + CONTROL_DELTA_PPEM_MIN, SDB, }; @@ -631,7 +631,7 @@ TA_table_build_prep(FT_Byte** prep, + sizeof (PREP(round_blues)); buf_new_len += sizeof (PREP(set_dropout_mode)); buf_new_len += sizeof (PREP(reset_component_counter)); - if (font->deltas_data_head) + if (font->control_data_head) buf_new_len += sizeof (PREP(adjust_delta_exceptions)); /* buffer length must be a multiple of four */ @@ -805,7 +805,7 @@ TA_table_build_prep(FT_Byte** prep, COPY_PREP(set_dropout_mode); COPY_PREP(reset_component_counter); - if (font->deltas_data_head) + if (font->control_data_head) COPY_PREP(adjust_delta_exceptions); *prep = buf; diff --git a/lib/tattfa.c b/lib/tattfa.c index 44d8aa8..1d14047 100644 --- a/lib/tattfa.c +++ b/lib/tattfa.c @@ -43,7 +43,7 @@ TA_table_build_TTFA(FT_Byte** TTFA, return FT_Err_Out_Of_Memory; } buf = buf_new; - + /* pad end of buffer with zeros */ p = buf + buf_len; switch (buf_len % 4) diff --git a/lib/ttfautohint-errors.h b/lib/ttfautohint-errors.h index 6b70251..8547221 100644 --- a/lib/ttfautohint-errors.h +++ b/lib/ttfautohint-errors.h @@ -83,31 +83,31 @@ TA_ERRORDEF_(XHeightSnapping_Not_Ascending, 0x105, TA_ERRORDEF_(XHeightSnapping_Allocation_Error, 0x106, "allocation error") -TA_ERRORDEF_(Deltas_Syntax_Error, 0x201, +TA_ERRORDEF_(Control_Syntax_Error, 0x201, "syntax error") -TA_ERRORDEF_(Deltas_Invalid_Font_Index, 0x202, +TA_ERRORDEF_(Control_Invalid_Font_Index, 0x202, "invalid font index") -TA_ERRORDEF_(Deltas_Invalid_Glyph_Index, 0x203, +TA_ERRORDEF_(Control_Invalid_Glyph_Index, 0x203, "invalid glyph index") -TA_ERRORDEF_(Deltas_Invalid_Glyph_Name, 0x204, +TA_ERRORDEF_(Control_Invalid_Glyph_Name, 0x204, "invalid glyph name") -TA_ERRORDEF_(Deltas_Invalid_Character, 0x205, +TA_ERRORDEF_(Control_Invalid_Character, 0x205, "invalid character") -TA_ERRORDEF_(Deltas_Invalid_Shift, 0x206, +TA_ERRORDEF_(Control_Invalid_Shift, 0x206, "invalid shift") -TA_ERRORDEF_(Deltas_Invalid_Range, 0x207, +TA_ERRORDEF_(Control_Invalid_Range, 0x207, "invalid range") -TA_ERRORDEF_(Deltas_Invalid_Glyph, 0x208, +TA_ERRORDEF_(Control_Invalid_Glyph, 0x208, "invalid glyph") -TA_ERRORDEF_(Deltas_Overflow, 0x209, +TA_ERRORDEF_(Control_Overflow, 0x209, "overflow") -TA_ERRORDEF_(Deltas_Overlapping_Ranges, 0x20A, +TA_ERRORDEF_(Control_Overlapping_Ranges, 0x20A, "overlapping ranges") -TA_ERRORDEF_(Deltas_Ranges_Not_Ascending, 0x20B, +TA_ERRORDEF_(Control_Ranges_Not_Ascending, 0x20B, "ranges not ascending") -TA_ERRORDEF_(Deltas_Allocation_Error, 0x20C, +TA_ERRORDEF_(Control_Allocation_Error, 0x20C, "allocation error") -TA_ERRORDEF_(Deltas_Flex_Error, 0x20D, +TA_ERRORDEF_(Control_Flex_Error, 0x20D, "internal flex error") #ifdef TA_ERROR_END_LIST diff --git a/lib/ttfautohint.c b/lib/ttfautohint.c index acbcec9..7772d88 100644 --- a/lib/ttfautohint.c +++ b/lib/ttfautohint.c @@ -58,14 +58,14 @@ TTF_autohint(const char* options, FILE* in_file = NULL; FILE* out_file = NULL; - FILE* deltas_file = NULL; + FILE* control_file = NULL; const char* in_buf = NULL; size_t in_len = 0; char** out_bufp = NULL; size_t* out_lenp = NULL; - const char* deltas_buf = NULL; - size_t deltas_len = 0; + const char* control_buf = NULL; + size_t control_len = 0; const unsigned char** error_stringp = NULL; @@ -151,21 +151,21 @@ TTF_autohint(const char* options, default_script_string = va_arg(ap, const char*); else if (COMPARE("dehint")) dehint = (FT_Bool)va_arg(ap, FT_Int); - else if (COMPARE("deltas-buffer")) + else if (COMPARE("control-buffer")) { - deltas_file = NULL; - deltas_buf = va_arg(ap, const char*); + control_file = NULL; + control_buf = va_arg(ap, const char*); } - else if (COMPARE("deltas-buffer-len")) + else if (COMPARE("control-buffer-len")) { - deltas_file = NULL; - deltas_len = va_arg(ap, size_t); + control_file = NULL; + control_len = va_arg(ap, size_t); } - else if (COMPARE("deltas-file")) + else if (COMPARE("control-file")) { - deltas_file = va_arg(ap, FILE*); - deltas_buf = NULL; - deltas_len = 0; + control_file = va_arg(ap, FILE*); + control_buf = NULL; + control_len = 0; } else if (COMPARE("dw-cleartype-strong-stem-width")) dw_cleartype_strong_stem_width = (FT_Bool)va_arg(ap, FT_Int); @@ -431,16 +431,16 @@ No_check: font->in_len = in_len; } - if (deltas_file) + if (control_file) { - error = TA_deltas_file_read(font, deltas_file); + error = TA_control_file_read(font, control_file); if (error) goto Err; } - else if (deltas_buf) + else if (control_buf) { - font->deltas_buf = (char*)deltas_buf; - font->deltas_len = deltas_len; + font->control_buf = (char*)control_buf; + font->control_len = control_len; } error = TA_font_init(font); @@ -477,10 +477,10 @@ No_check: goto Err; } - /* process delta exceptions data */ - error = TA_deltas_parse_buffer(font, - &error_string, - &errlinenum, &errline, &errpos); + /* process control instructions */ + error = TA_control_parse_buffer(font, + &error_string, + &errlinenum, &errline, &errpos); if (error) { free_errline = 1; @@ -505,7 +505,7 @@ No_check: free(s); } - error = TA_deltas_build_tree(font); + error = TA_control_build_tree(font); if (error) goto Err; @@ -683,9 +683,9 @@ No_check: error = TA_Err_Ok; Err: - TA_deltas_free(font->deltas); - TA_deltas_free_tree(font); - TA_font_unload(font, in_buf, out_bufp, deltas_buf); + TA_control_free(font->control); + TA_control_free_tree(font); + TA_font_unload(font, in_buf, out_bufp, control_buf); Err1: if (!error_string) diff --git a/lib/ttfautohint.h b/lib/ttfautohint.h index 3732393..1c2c9d4 100644 --- a/lib/ttfautohint.h +++ b/lib/ttfautohint.h @@ -249,12 +249,11 @@ typedef int * : A pointer of type `size_t*` to a value giving the length of the * output buffer. Needs `out-buffer`. * - * `deltas-file` - * : A pointer of type `FILE*` to the data stream of delta exceptions, - * opened for reading in *binary* mode. Mutually exclusive with - * `deltas-buffer`. + * `control-file` + * : A pointer of type `FILE*` to the data stream of control instructions. + * Mutually exclusive with `control-buffer`. * - * An entry in a delta exceptions file or buffer has the following + * An entry in a control instructions file or buffer has the following * syntax: * * > *\[* font-idx *\]* glyph-id *`p`* points *\[* *`x`* x-shift *\]* *\[* *`y`* y-shift *\]* *`@`* ppems @@ -283,7 +282,7 @@ typedef int * Values for *ppems* must be in the range [6;53]. Values for *points* * are limited by the number of points in the glyph. * - * Delta exceptions entries can be either separated with newlines or + * Control instruction entries can be either separated with newlines or * with character '`;`'. Additionally, a line can be continued on the * next line by ending it with backslash character ('`\`'). A backslash * followed by a newline gets treated similar to a whitespace character. @@ -294,14 +293,14 @@ typedef int * Note that only character '`.`' is recognized as a decimal point, and * a thousands separator is not accepted. * - * `deltas-buffer` - * : A pointer of type `const char*` to a buffer that contains delta - * exceptions. Needs `deltas-buffer-len`. Mutually exclusive with - * `deltas-file`. + * `control-buffer` + * : A pointer of type `const char*` to a buffer that contains control + * instructions. Needs `control-buffer-len`. Mutually exclusive with + * `control-file`. * - * `deltas-buffer-len` - * : A value of type `size_t`, giving the length of the delta exceptions - * buffer. Needs `deltas-buffer`. + * `control-buffer-len` + * : A value of type `size_t`, giving the length of the control + * instructions buffer. Needs `control-buffer`. * * * ### Messages and Callbacks -- 2.11.4.GIT