[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.
This commit is contained in:
Behdad Esfahbod 2017-01-22 18:52:00 -08:00
parent 8a577aaa0d
commit 5ec96d30ca
5 changed files with 59 additions and 26 deletions

View File

@ -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
</SECTION>
<SECTION>

View File

@ -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)

View File

@ -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);
}

View File

@ -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 */
}

View File

@ -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