From 71d1b5c3eb2944b39c4d34cf36ba092e59cc0edf Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Fri, 26 Sep 2014 13:39:04 +0200 Subject: [PATCH] Add a type to `Control' so that we can extend it. --- lib/tabytecode.c | 11 ++++++-- lib/tacontrol.bison | 3 ++- lib/tacontrol.c | 77 +++++++++++++++++++++++++++++++++++++---------------- lib/tacontrol.h | 19 ++++++++++++- 4 files changed, 83 insertions(+), 27 deletions(-) diff --git a/lib/tabytecode.c b/lib/tabytecode.c index f1e92a9..33c14c9 100644 --- a/lib/tabytecode.c +++ b/lib/tabytecode.c @@ -702,10 +702,17 @@ TA_sfnt_build_delta_exceptions(SFNT* sfnt, { ctrl = TA_control_get_ctrl(font); + if (!ctrl) + break; + + /* check type */ + if (!(ctrl->type == Control_Delta_before_IUP + || ctrl->type == Control_Delta_after_IUP)) + break; + /* too large values of font and glyph indices in `ctrl' */ /* are handled by later calls of this function */ - if (!ctrl - || face->face_index < ctrl->font_idx + if (face->face_index < ctrl->font_idx || idx < ctrl->glyph_idx) break; diff --git a/lib/tacontrol.bison b/lib/tacontrol.bison index 37e9659..45cae05 100644 --- a/lib/tacontrol.bison +++ b/lib/tacontrol.bison @@ -154,7 +154,8 @@ entry: { $entry = NULL; } | font_idx glyph_idx point_set x_shift y_shift ppem_set EOE { - $entry = TA_control_new($font_idx, + $entry = TA_control_new(Control_Delta_after_IUP, + $font_idx, $glyph_idx, $point_set, $x_shift, diff --git a/lib/tacontrol.c b/lib/tacontrol.c index e2b6bbc..5f955f8 100644 --- a/lib/tacontrol.c +++ b/lib/tacontrol.c @@ -24,7 +24,8 @@ #include "tacontrol-bison.h" Control* -TA_control_new(long font_idx, +TA_control_new(Control_Type type, + long font_idx, long glyph_idx, number_range* point_set, double x_shift, @@ -38,15 +39,29 @@ TA_control_new(long font_idx, if (!control) return NULL; + control->type = type; + 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^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)); + switch (control->type) + { + case Control_Delta_before_IUP: + case Control_Delta_after_IUP: + /* 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)); + break; + + case Control_One_Point_Segment: + /* not implemented yet */ + control->x_shift = 0; + control->y_shift = 0; + break; + } control->ppems = number_set_reverse(ppem_set); control->next = NULL; @@ -143,23 +158,36 @@ control_show_line(FONT* font, 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", - control->font_idx, - glyph_name_buf, - points_buf, - (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", - control->font_idx, - control->glyph_idx, - points_buf, - (double)control->x_shift / CONTROL_DELTA_FACTOR, - (double)control->y_shift / CONTROL_DELTA_FACTOR, - ppems_buf); + switch (control->type) + { + case Control_Delta_before_IUP: + /* not implemented yet */ + break; + + case Control_Delta_after_IUP: + /* 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", + control->font_idx, + glyph_name_buf, + points_buf, + (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", + control->font_idx, + control->glyph_idx, + points_buf, + (double)control->x_shift / CONTROL_DELTA_FACTOR, + (double)control->y_shift / CONTROL_DELTA_FACTOR, + ppems_buf); + break; + + case Control_One_Point_Segment: + /* not implemented yet */ + break; + } Exit: free(points_buf); @@ -441,6 +469,7 @@ TA_control_build_tree(FONT* font) while (control) { + Control_Type type = control->type; long font_idx = control->font_idx; long glyph_idx = control->glyph_idx; char x_shift = control->x_shift; @@ -472,6 +501,7 @@ TA_control_build_tree(FONT* font) if (!node) return FT_Err_Out_Of_Memory; + node->ctrl.type = type; node->ctrl.font_idx = font_idx; node->ctrl.glyph_idx = glyph_idx; node->ctrl.ppem = ppem; @@ -500,6 +530,7 @@ TA_control_build_tree(FONT* font) points.end = point_idx; points.next = NULL; + d.type = type; d.font_idx = font_idx; d.glyph_idx = glyph_idx; d.points = &points; diff --git a/lib/tacontrol.h b/lib/tacontrol.h index 1062b49..61cb0f2 100644 --- a/lib/tacontrol.h +++ b/lib/tacontrol.h @@ -52,6 +52,18 @@ extern "C" { /* + * The control type. + */ + +typedef enum Control_Type_ +{ + Control_Delta_before_IUP, + Control_Delta_after_IUP, + Control_One_Point_Segment +} Control_Type; + + +/* * 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. @@ -63,6 +75,8 @@ extern "C" { struct Control_ { + Control_Type type; + long font_idx; long glyph_idx; number_range* points; @@ -80,6 +94,8 @@ struct Control_ typedef struct Ctrl_ { + Control_Type type; + long font_idx; long glyph_idx; int ppem; @@ -155,7 +171,8 @@ typedef struct Control_Context_ */ Control* -TA_control_new(long font_idx, +TA_control_new(Control_Type type, + long font_idx, long glyph_idx, number_range* point_set, double x_shift, -- 2.11.4.GIT