From 5ec96d30cad1592b5e468bd8ad1832dbaf0ad32b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 22 Jan 2017 18:52:00 -0800 Subject: [PATCH] [var] Adjust API in prep for 'avar' implementation The 'avar' table does not allow random access to axis maps, so change API to avoid quadratic-time implementation. Removed -hb_ot_var_normalize_axis_value(), added +hb_ot_var_normalize_variations() and +hb_ot_var_normalize_coords() instead. --- docs/harfbuzz-sections.txt | 3 ++- src/Makefile.sources | 1 + src/hb-font.cc | 20 +++++------------ src/hb-ot-var.cc | 45 +++++++++++++++++++++++++++++++++----- src/hb-ot-var.h | 16 ++++++++++---- 5 files changed, 59 insertions(+), 26 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index b4ae15dd5..fcf4e527e 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -448,7 +448,8 @@ hb_ot_var_has_data hb_ot_var_find_axis hb_ot_var_get_axis_count hb_ot_var_get_axes -hb_ot_var_normalize_axis_value +hb_ot_var_normalize_variations +hb_ot_var_normalize_coords
diff --git a/src/Makefile.sources b/src/Makefile.sources index 279bc46eb..c74147cb5 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -109,6 +109,7 @@ HB_OT_sources = \ hb-ot-shape-fallback.cc \ hb-ot-shape-private.hh \ hb-ot-var.cc \ + hb-ot-var-avar-table.hh \ hb-ot-var-fvar-table.hh \ $(NULL) diff --git a/src/hb-font.cc b/src/hb-font.cc index a3f250d50..ea4550126 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -1570,22 +1570,15 @@ hb_font_set_variations (hb_font_t *font, return; } - hb_face_t *face = font->face; - - unsigned int coords_length = hb_ot_var_get_axis_count (face); + unsigned int coords_length = hb_ot_var_get_axis_count (font->face); int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : NULL; if (unlikely (coords_length && !normalized)) return; - /* normalized is filled with zero already. */ - for (unsigned int i = 0; i < variations_length; i++) - { - unsigned int axis_index; - if (hb_ot_var_find_axis (face, variations[i].tag, &axis_index, NULL)) - normalized[axis_index] = hb_ot_var_normalize_axis_value (face, axis_index, variations[i].value); - } - + hb_ot_var_normalize_variations (font->face, + variations, variations_length, + normalized, coords_length); _hb_font_adopt_var_coords_normalized (font, normalized, coords_length); } @@ -1606,10 +1599,7 @@ hb_font_set_var_coords_design (hb_font_t *font, if (unlikely (coords_length && !normalized)) return; - hb_face_t *face = font->face; - for (unsigned int i = 0; i < coords_length; i++) - normalized[i] = hb_ot_var_normalize_axis_value (face, i, coords[i]); - + hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized); _hb_font_adopt_var_coords_normalized (font, normalized, coords_length); } diff --git a/src/hb-ot-var.cc b/src/hb-ot-var.cc index 508042477..76016e634 100644 --- a/src/hb-ot-var.cc +++ b/src/hb-ot-var.cc @@ -27,6 +27,7 @@ #include "hb-open-type-private.hh" #include "hb-ot-layout-private.hh" +#include "hb-ot-var-avar-table.hh" #include "hb-ot-var-fvar-table.hh" #include "hb-ot-var.h" @@ -105,16 +106,48 @@ hb_ot_var_find_axis (hb_face_t *face, return fvar.find_axis (axis_tag, axis_index, axis_info); } + /** - * hb_ot_var_normalize_axis_value: + * hb_ot_var_normalize_variations: * * Since: 1.4.2 **/ -int -hb_ot_var_normalize_axis_value (hb_face_t *face, - unsigned int axis_index, - float v) +void +hb_ot_var_normalize_variations (hb_face_t *face, + const hb_variation_t *variations, /* IN */ + unsigned int variations_length, + int *coords, /* OUT */ + unsigned int coords_length) +{ + for (unsigned int i = 0; i < coords_length; i++) + coords[i] = 0; + + const OT::fvar &fvar = _get_fvar (face); + for (unsigned int i = 0; i < variations_length; i++) + { + unsigned int axis_index; + if (hb_ot_var_find_axis (face, variations[i].tag, &axis_index, NULL) && + axis_index < coords_length) + coords[axis_index] = fvar.normalize_axis_value (axis_index, variations[i].value); + } + + /* TODO avar */ +} + +/** + * hb_ot_var_normalize_coords: + * + * Since: 1.4.2 + **/ +void +hb_ot_var_normalize_coords (hb_face_t *face, + unsigned int coords_length, + const float *design_coords, /* IN */ + int *normalized_coords /* OUT */) { const OT::fvar &fvar = _get_fvar (face); - return fvar.normalize_axis_value (axis_index, v); + for (unsigned int i = 0; i < coords_length; i++) + normalized_coords[i] = fvar.normalize_axis_value (i, design_coords[i]); + + /* TODO avar */ } diff --git a/src/hb-ot-var.h b/src/hb-ot-var.h index 652a78d07..bce7c7a0a 100644 --- a/src/hb-ot-var.h +++ b/src/hb-ot-var.h @@ -83,10 +83,18 @@ hb_ot_var_find_axis (hb_face_t *face, hb_ot_var_axis_t *axis_info); -HB_EXTERN int -hb_ot_var_normalize_axis_value (hb_face_t *face, - unsigned int axis_index, - float v); +HB_EXTERN void +hb_ot_var_normalize_variations (hb_face_t *face, + const hb_variation_t *variations, /* IN */ + unsigned int variations_length, + int *coords, /* OUT */ + unsigned int coords_length); + +HB_EXTERN void +hb_ot_var_normalize_coords (hb_face_t *face, + unsigned int coords_length, + const float *design_coords, /* IN */ + int *normalized_coords /* OUT */); HB_END_DECLS