[CompositeGlyph] Apply gvar deltas with component transform

This was being done wrong for one of the scaled_offsets() cases.
This commit is contained in:
Behdad Esfahbod 2023-04-21 15:46:36 -06:00
parent 33972b3bf6
commit 3520f528aa
2 changed files with 29 additions and 22 deletions

View File

@ -87,11 +87,9 @@ struct CompositeGlyphRecord
} }
} }
void transform_points (contour_point_vector_t &points) const void transform_points (contour_point_vector_t &points,
{ const float (&matrix)[4],
float matrix[4]; const contour_point_t &trans) const
contour_point_t trans;
if (get_transformation (matrix, trans))
{ {
if (scaled_offsets ()) if (scaled_offsets ())
{ {
@ -104,6 +102,15 @@ struct CompositeGlyphRecord
points.translate (trans); points.translate (trans);
} }
} }
bool get_points (contour_point_vector_t &points) const
{
float matrix[4];
contour_point_t trans;
get_transformation (matrix, trans);
if (unlikely (!points.resize (points.length + 1))) return false;
points[points.length - 1] = trans;
return true;
} }
unsigned compile_with_deltas (const contour_point_t &p_delta, unsigned compile_with_deltas (const contour_point_t &p_delta,
@ -171,6 +178,7 @@ struct CompositeGlyphRecord
bool scaled_offsets () const bool scaled_offsets () const
{ return (flags & (SCALED_COMPONENT_OFFSET | UNSCALED_COMPONENT_OFFSET)) == SCALED_COMPONENT_OFFSET; } { return (flags & (SCALED_COMPONENT_OFFSET | UNSCALED_COMPONENT_OFFSET)) == SCALED_COMPONENT_OFFSET; }
public:
bool get_transformation (float (&matrix)[4], contour_point_t &trans) const bool get_transformation (float (&matrix)[4], contour_point_t &trans) const
{ {
matrix[0] = matrix[3] = 1.f; matrix[0] = matrix[3] = 1.f;
@ -225,7 +233,6 @@ struct CompositeGlyphRecord
return tx || ty; return tx || ty;
} }
public:
hb_codepoint_t get_gid () const hb_codepoint_t get_gid () const
{ {
#ifndef HB_NO_BEYOND_64K #ifndef HB_NO_BEYOND_64K

View File

@ -320,9 +320,8 @@ struct Glyph
break; break;
case COMPOSITE: case COMPOSITE:
{ {
/* pseudo component points for each component in composite glyph */ for (auto &item : get_composite_iterator ())
unsigned num_points = hb_len (CompositeGlyph (*header, bytes).iter ()); if (unlikely (!item.get_points (points))) return false;
if (unlikely (!points.resize (num_points))) return false;
break; break;
} }
#ifndef HB_NO_VAR_COMPOSITES #ifndef HB_NO_VAR_COMPOSITES
@ -422,11 +421,12 @@ struct Glyph
for (unsigned int i = 0; i < PHANTOM_COUNT; i++) for (unsigned int i = 0; i < PHANTOM_COUNT; i++)
phantoms[i] = comp_points[comp_points.length - PHANTOM_COUNT + i]; phantoms[i] = comp_points[comp_points.length - PHANTOM_COUNT + i];
/* Apply component transformation & translation */ float matrix[4];
item.transform_points (comp_points); contour_point_t default_trans;
item.get_transformation (matrix, default_trans);
/* Apply translation from gvar */ /* Apply component transformation & translation (with deltas applied) */
comp_points.translate (points[comp_index]); item.transform_points (comp_points, matrix, points[comp_index]);
if (item.is_anchored ()) if (item.is_anchored ())
{ {