[var] Rename var_coord to variation

Looks much better.
pull/407/head
Behdad Esfahbod 8 years ago
parent 64fe92bf2d
commit bb1e19268f
  1. 36
      src/hb-common.cc
  2. 10
      src/hb-common.h
  3. 20
      src/hb-font.cc
  4. 6
      src/hb-font.h

@ -608,7 +608,7 @@ hb_version_atleast (unsigned int major,
/* hb_feature_t and hb_var_coord_t */
/* hb_feature_t and hb_variation_t */
static bool
parse_space (const char **pp, const char *end)
@ -880,59 +880,59 @@ hb_feature_to_string (hb_feature_t *feature,
buf[len] = '\0';
}
/* hb_var_coord_t */
/* hb_variation_t */
static bool
parse_var_coord_value (const char **pp, const char *end, hb_var_coord_t *var_coord)
parse_variation_value (const char **pp, const char *end, hb_variation_t *variation)
{
parse_char (pp, end, '='); /* Optional. */
return parse_float (pp, end, &var_coord->value);
return parse_float (pp, end, &variation->value);
}
static bool
parse_one_var_coord (const char **pp, const char *end, hb_var_coord_t *var_coord)
parse_one_variation (const char **pp, const char *end, hb_variation_t *variation)
{
return parse_tag (pp, end, &var_coord->tag) &&
parse_var_coord_value (pp, end, var_coord) &&
return parse_tag (pp, end, &variation->tag) &&
parse_variation_value (pp, end, variation) &&
parse_space (pp, end) &&
*pp == end;
}
hb_bool_t
hb_var_coord_from_string (const char *str, int len,
hb_var_coord_t *var_coord)
hb_variation_from_string (const char *str, int len,
hb_variation_t *variation)
{
hb_var_coord_t coord;
hb_variation_t var;
if (len < 0)
len = strlen (str);
if (likely (parse_one_var_coord (&str, str + len, &coord)))
if (likely (parse_one_variation (&str, str + len, &var)))
{
if (var_coord)
*var_coord = coord;
if (variation)
*variation = var;
return true;
}
if (var_coord)
memset (var_coord, 0, sizeof (*var_coord));
if (variation)
memset (variation, 0, sizeof (*variation));
return false;
}
void
hb_var_coord_to_string (hb_var_coord_t *var_coord,
hb_variation_to_string (hb_variation_t *variation,
char *buf, unsigned int size)
{
if (unlikely (!size)) return;
char s[128];
unsigned int len = 0;
hb_tag_to_string (var_coord->tag, s + len);
hb_tag_to_string (variation->tag, s + len);
len += 4;
while (len && s[len - 1] == ' ')
len--;
s[len++] = '=';
len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%g", var_coord->value));
len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%g", variation->value));
assert (len < ARRAY_LENGTH (s));
len = MIN (len, size - 1);

@ -379,17 +379,17 @@ HB_EXTERN void
hb_feature_to_string (hb_feature_t *feature,
char *buf, unsigned int size);
typedef struct hb_var_coord_t {
typedef struct hb_variation_t {
hb_tag_t tag;
float value;
} hb_var_coord_t;
} hb_variation_t;
HB_EXTERN hb_bool_t
hb_var_coord_from_string (const char *str, int len,
hb_var_coord_t *var_coord);
hb_variation_from_string (const char *str, int len,
hb_variation_t *variation);
HB_EXTERN void
hb_var_coord_to_string (hb_var_coord_t *var_coord,
hb_variation_to_string (hb_variation_t *variation,
char *buf, unsigned int size);

@ -1552,14 +1552,14 @@ _hb_font_adopt_var_coords_normalized (hb_font_t *font,
}
void
hb_font_set_var_coords (hb_font_t *font,
const hb_var_coord_t *coords,
unsigned int coords_length)
hb_font_set_variations (hb_font_t *font,
const hb_variation_t *variations,
unsigned int variations_length)
{
if (font->immutable)
return;
if (!coords_length)
if (!variations_length)
{
hb_font_set_var_coords_normalized (font, NULL, 0);
return;
@ -1567,18 +1567,18 @@ hb_font_set_var_coords (hb_font_t *font,
hb_face_t *face = font->face;
unsigned int length = hb_ot_var_get_axis_count (face);
unsigned int coords_length = hb_ot_var_get_axis_count (face);
int *normalized = length ? (int *) calloc (length, sizeof (int)) : NULL;
if (unlikely (length && !normalized))
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 < coords_length; i++)
for (unsigned int i = 0; i < variations_length; i++)
{
unsigned int axis_index;
if (hb_ot_var_find_axis (face, coords[i].tag, &axis_index, NULL))
normalized[axis_index] = hb_ot_var_normalize_axis_value (face, axis_index, coords[i].value);
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_font_adopt_var_coords_normalized (font, normalized, coords_length);

@ -604,9 +604,9 @@ hb_font_get_ppem (hb_font_t *font,
unsigned int *y_ppem);
HB_EXTERN void
hb_font_set_var_coords (hb_font_t *font,
const hb_var_coord_t *coords,
unsigned int coords_length);
hb_font_set_variations (hb_font_t *font,
const hb_variation_t *variations,
unsigned int variations_length);
HB_EXTERN void
hb_font_set_var_coords_design (hb_font_t *font,

Loading…
Cancel
Save