parent
64fe92bf2d
commit
bb1e19268f
|
@ -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
|
static bool
|
||||||
parse_space (const char **pp, const char *end)
|
parse_space (const char **pp, const char *end)
|
||||||
|
@ -880,59 +880,59 @@ hb_feature_to_string (hb_feature_t *feature,
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hb_var_coord_t */
|
/* hb_variation_t */
|
||||||
|
|
||||||
static bool
|
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. */
|
parse_char (pp, end, '='); /* Optional. */
|
||||||
return parse_float (pp, end, &var_coord->value);
|
return parse_float (pp, end, &variation->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
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) &&
|
return parse_tag (pp, end, &variation->tag) &&
|
||||||
parse_var_coord_value (pp, end, var_coord) &&
|
parse_variation_value (pp, end, variation) &&
|
||||||
parse_space (pp, end) &&
|
parse_space (pp, end) &&
|
||||||
*pp == end;
|
*pp == end;
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_bool_t
|
hb_bool_t
|
||||||
hb_var_coord_from_string (const char *str, int len,
|
hb_variation_from_string (const char *str, int len,
|
||||||
hb_var_coord_t *var_coord)
|
hb_variation_t *variation)
|
||||||
{
|
{
|
||||||
hb_var_coord_t coord;
|
hb_variation_t var;
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = strlen (str);
|
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)
|
if (variation)
|
||||||
*var_coord = coord;
|
*variation = var;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var_coord)
|
if (variation)
|
||||||
memset (var_coord, 0, sizeof (*var_coord));
|
memset (variation, 0, sizeof (*variation));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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)
|
char *buf, unsigned int size)
|
||||||
{
|
{
|
||||||
if (unlikely (!size)) return;
|
if (unlikely (!size)) return;
|
||||||
|
|
||||||
char s[128];
|
char s[128];
|
||||||
unsigned int len = 0;
|
unsigned int len = 0;
|
||||||
hb_tag_to_string (var_coord->tag, s + len);
|
hb_tag_to_string (variation->tag, s + len);
|
||||||
len += 4;
|
len += 4;
|
||||||
while (len && s[len - 1] == ' ')
|
while (len && s[len - 1] == ' ')
|
||||||
len--;
|
len--;
|
||||||
s[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));
|
assert (len < ARRAY_LENGTH (s));
|
||||||
len = MIN (len, size - 1);
|
len = MIN (len, size - 1);
|
||||||
|
|
|
@ -379,17 +379,17 @@ HB_EXTERN void
|
||||||
hb_feature_to_string (hb_feature_t *feature,
|
hb_feature_to_string (hb_feature_t *feature,
|
||||||
char *buf, unsigned int size);
|
char *buf, unsigned int size);
|
||||||
|
|
||||||
typedef struct hb_var_coord_t {
|
typedef struct hb_variation_t {
|
||||||
hb_tag_t tag;
|
hb_tag_t tag;
|
||||||
float value;
|
float value;
|
||||||
} hb_var_coord_t;
|
} hb_variation_t;
|
||||||
|
|
||||||
HB_EXTERN hb_bool_t
|
HB_EXTERN hb_bool_t
|
||||||
hb_var_coord_from_string (const char *str, int len,
|
hb_variation_from_string (const char *str, int len,
|
||||||
hb_var_coord_t *var_coord);
|
hb_variation_t *variation);
|
||||||
|
|
||||||
HB_EXTERN void
|
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);
|
char *buf, unsigned int size);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1552,14 +1552,14 @@ _hb_font_adopt_var_coords_normalized (hb_font_t *font,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
hb_font_set_var_coords (hb_font_t *font,
|
hb_font_set_variations (hb_font_t *font,
|
||||||
const hb_var_coord_t *coords,
|
const hb_variation_t *variations,
|
||||||
unsigned int coords_length)
|
unsigned int variations_length)
|
||||||
{
|
{
|
||||||
if (font->immutable)
|
if (font->immutable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!coords_length)
|
if (!variations_length)
|
||||||
{
|
{
|
||||||
hb_font_set_var_coords_normalized (font, NULL, 0);
|
hb_font_set_var_coords_normalized (font, NULL, 0);
|
||||||
return;
|
return;
|
||||||
|
@ -1567,18 +1567,18 @@ hb_font_set_var_coords (hb_font_t *font,
|
||||||
|
|
||||||
hb_face_t *face = font->face;
|
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;
|
int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : NULL;
|
||||||
if (unlikely (length && !normalized))
|
if (unlikely (coords_length && !normalized))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* normalized is filled with zero already. */
|
/* 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;
|
unsigned int axis_index;
|
||||||
if (hb_ot_var_find_axis (face, coords[i].tag, &axis_index, NULL))
|
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, coords[i].value);
|
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);
|
_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);
|
unsigned int *y_ppem);
|
||||||
|
|
||||||
HB_EXTERN void
|
HB_EXTERN void
|
||||||
hb_font_set_var_coords (hb_font_t *font,
|
hb_font_set_variations (hb_font_t *font,
|
||||||
const hb_var_coord_t *coords,
|
const hb_variation_t *variations,
|
||||||
unsigned int coords_length);
|
unsigned int variations_length);
|
||||||
|
|
||||||
HB_EXTERN void
|
HB_EXTERN void
|
||||||
hb_font_set_var_coords_design (hb_font_t *font,
|
hb_font_set_var_coords_design (hb_font_t *font,
|
||||||
|
|
Loading…
Reference in New Issue