[glyf] minor

This commit is contained in:
Ebrahim Byagowi 2019-10-03 22:45:37 +03:30
parent ee7610181c
commit 88bd342c0f
2 changed files with 156 additions and 147 deletions

View File

@ -60,7 +60,8 @@ struct loca
} }
protected: protected:
UnsizedArrayOf<HBUINT8> dataZ; /* Location data. */ UnsizedArrayOf<HBUINT8>
dataZ; /* Location data. */
public: public:
DEFINE_SIZE_MIN (0); /* In reality, this is UNBOUNDED() type; but since we always DEFINE_SIZE_MIN (0); /* In reality, this is UNBOUNDED() type; but since we always
* check the size externally, allow Null() object of it by * check the size externally, allow Null() object of it by
@ -290,7 +291,8 @@ struct glyf
bool has_data () const { return numberOfContours; } bool has_data () const { return numberOfContours; }
HBINT16 numberOfContours; /* If the number of contours is HBINT16 numberOfContours;
/* If the number of contours is
* greater than or equal to zero, * greater than or equal to zero,
* this is a simple glyph; if negative, * this is a simple glyph; if negative,
* this is a composite glyph. */ * this is a composite glyph. */
@ -403,25 +405,28 @@ struct glyf
trans.init ((float) tx, (float) ty); trans.init ((float) tx, (float) ty);
{
const F2DOT14 *points = (const F2DOT14 *) p;
if (flags & WE_HAVE_A_SCALE) if (flags & WE_HAVE_A_SCALE)
{ {
matrix[0] = matrix[3] = ((const F2DOT14*)p)->to_float (); matrix[0] = matrix[3] = points[0].to_float ();
return true; return true;
} }
else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) else if (flags & WE_HAVE_AN_X_AND_Y_SCALE)
{ {
matrix[0] = ((const F2DOT14*)p)[0].to_float (); matrix[0] = points[0].to_float ();
matrix[3] = ((const F2DOT14*)p)[1].to_float (); matrix[3] = points[1].to_float ();
return true; return true;
} }
else if (flags & WE_HAVE_A_TWO_BY_TWO) else if (flags & WE_HAVE_A_TWO_BY_TWO)
{ {
matrix[0] = ((const F2DOT14*)p)[0].to_float (); matrix[0] = points[0].to_float ();
matrix[1] = ((const F2DOT14*)p)[1].to_float (); matrix[1] = points[1].to_float ();
matrix[2] = ((const F2DOT14*)p)[2].to_float (); matrix[2] = points[2].to_float ();
matrix[3] = ((const F2DOT14*)p)[3].to_float (); matrix[3] = points[3].to_float ();
return true; return true;
} }
}
return tx || ty; return tx || ty;
} }
@ -543,7 +548,8 @@ struct glyf
FLAG_RESERVED2 = 0x80 FLAG_RESERVED2 = 0x80
}; };
enum phantom_point_index_t { enum phantom_point_index_t
{
PHANTOM_LEFT = 0, PHANTOM_LEFT = 0,
PHANTOM_RIGHT = 1, PHANTOM_RIGHT = 1,
PHANTOM_TOP = 2, PHANTOM_TOP = 2,
@ -564,15 +570,15 @@ struct glyf
struct x_setter_t struct x_setter_t
{ {
void set (contour_point_t &point, float v) const { point.x = v; } void set (contour_point_t &point, float v) const { point.x = v; }
bool is_short (uint8_t flag) const { return (flag & FLAG_X_SHORT) != 0; } bool is_short (uint8_t flag) const { return flag & FLAG_X_SHORT; }
bool is_same (uint8_t flag) const { return (flag & FLAG_X_SAME) != 0; } bool is_same (uint8_t flag) const { return flag & FLAG_X_SAME; }
}; };
struct y_setter_t struct y_setter_t
{ {
void set (contour_point_t &point, float v) const { point.y = v; } void set (contour_point_t &point, float v) const { point.y = v; }
bool is_short (uint8_t flag) const { return (flag & FLAG_Y_SHORT) != 0; } bool is_short (uint8_t flag) const { return flag & FLAG_Y_SHORT; }
bool is_same (uint8_t flag) const { return (flag & FLAG_Y_SAME) != 0; } bool is_same (uint8_t flag) const { return flag & FLAG_Y_SAME; }
}; };
template <typename T> template <typename T>
@ -618,7 +624,7 @@ struct glyf
phantoms[PHANTOM_LEFT].x = h_delta; phantoms[PHANTOM_LEFT].x = h_delta;
phantoms[PHANTOM_RIGHT].x = h_adv + h_delta; phantoms[PHANTOM_RIGHT].x = h_adv + h_delta;
phantoms[PHANTOM_TOP].y = v_orig; phantoms[PHANTOM_TOP].y = v_orig;
phantoms[PHANTOM_BOTTOM].y = -(int)v_adv + v_orig; phantoms[PHANTOM_BOTTOM].y = v_orig - (int) v_adv;
} }
/* for a simple glyph, return contour end points, flags, along with coordinate points /* for a simple glyph, return contour end points, flags, along with coordinate points
@ -652,17 +658,17 @@ struct glyf
} }
const GlyphHeader &glyph_header = StructAtOffset<GlyphHeader> (glyf_table, start_offset); const GlyphHeader &glyph_header = StructAtOffset<GlyphHeader> (glyf_table, start_offset);
int16_t num_contours = (int16_t) glyph_header.numberOfContours; int num_contours = glyph_header.numberOfContours;
const HBUINT16 *end_pts = &StructAfter<HBUINT16, GlyphHeader> (glyph_header); const HBUINT16 *end_pts = &StructAfter<HBUINT16, GlyphHeader> (glyph_header);
range_checker_t checker (glyf_table, start_offset, end_offset); range_checker_t checker (glyf_table, start_offset, end_offset);
num_points = 0; num_points = 0;
if (num_contours > 0) if (glyph_header.is_simple_glyph ())
{ {
if (unlikely (!checker.in_range (&end_pts[num_contours + 1]))) return false; if (unlikely (!checker.in_range (&end_pts[num_contours + 1]))) return false;
num_points = end_pts[num_contours - 1] + 1; num_points = end_pts[glyph_header.numberOfContours - 1] + 1;
} }
else if (num_contours < 0) else if (glyph_header.is_composite_glyph ())
{ {
CompositeGlyphHeader::Iterator composite; CompositeGlyphHeader::Iterator composite;
if (unlikely (!get_composite (glyph, &composite))) return false; if (unlikely (!get_composite (glyph, &composite))) return false;
@ -674,16 +680,17 @@ struct glyf
points_.resize (num_points + PHANTOM_COUNT); points_.resize (num_points + PHANTOM_COUNT);
for (unsigned int i = 0; i < points_.length; i++) points_[i].init (); for (unsigned int i = 0; i < points_.length; i++) points_[i].init ();
if ((num_contours <= 0) || phantom_only) return true; if (!glyph_header.is_simple_glyph () || phantom_only) return true;
/* Read simple glyph points if !phantom_only */ /* Read simple glyph points if !phantom_only */
end_points_.resize (num_contours); end_points_.resize (num_contours);
for (int16_t i = 0; i < num_contours; i++) for (int i = 0; i < num_contours; i++)
end_points_[i] = end_pts[i]; end_points_[i] = end_pts[i];
/* Skip instructions */ /* Skip instructions */
const HBUINT8 *p = &StructAtOffset<HBUINT8> (&end_pts[num_contours+1], end_pts[num_contours]); const HBUINT8 *p = &StructAtOffset<HBUINT8> (&end_pts[num_contours+1],
end_pts[num_contours]);
/* Read flags */ /* Read flags */
for (unsigned int i = 0; i < num_points; i++) for (unsigned int i = 0; i < num_points; i++)
@ -821,8 +828,8 @@ struct glyf
} }
else else
{ {
extents->x_bearing = (int32_t)floorf (bounds.min.x); extents->x_bearing = (int) floor (bounds.min.x);
extents->width = (int32_t)ceilf (bounds.max.x) - extents->x_bearing; extents->width = (int) ceil (bounds.max.x) - extents->x_bearing;
} }
if (bounds.min.y > bounds.max.y) if (bounds.min.y > bounds.max.y)
{ {
@ -831,8 +838,8 @@ struct glyf
} }
else else
{ {
extents->y_bearing = (int32_t)ceilf (bounds.max.y); extents->y_bearing = (int) ceil (bounds.max.y);
extents->height = (int32_t)floorf (bounds.min.y) - extents->y_bearing; extents->height = (int) floor (bounds.min.y) - extents->y_bearing;
} }
} }
if (phantoms != nullptr) if (phantoms != nullptr)
@ -962,7 +969,7 @@ struct glyf
if (!glyph_header.has_data ()) if (!glyph_header.has_data ())
{ {
*length = 0; *length = 0;
// only 0 byte glyphs are healthy when missing GlyphHeader /* only 0 byte glyphs are healthy when missing GlyphHeader */
return glyph.length == 0; return glyph.length == 0;
} }
if (glyph_header.is_composite_glyph ()) if (glyph_header.is_composite_glyph ())
@ -1041,7 +1048,7 @@ struct glyf
if (unlikely (!get_var_extents_and_phantoms (glyph, coords, coord_count, &extents, &phantoms))) if (unlikely (!get_var_extents_and_phantoms (glyph, coords, coord_count, &extents, &phantoms)))
return vertical ? vmtx_accel.get_side_bearing (glyph) : hmtx_accel.get_side_bearing (glyph); return vertical ? vmtx_accel.get_side_bearing (glyph) : hmtx_accel.get_side_bearing (glyph);
return vertical? (int)ceilf (phantoms[PHANTOM_TOP].y) - extents.y_bearing: (int)floorf (phantoms[PHANTOM_LEFT].x); return vertical ? (int) ceil (phantoms[PHANTOM_TOP].y) - extents.y_bearing : (int)floorf (phantoms[PHANTOM_LEFT].x);
} }
bool get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const bool get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const

View File

@ -202,7 +202,8 @@ struct TupleVarCount : HBUINT16
unsigned int get_count () const { return (*this) & CountMask; } unsigned int get_count () const { return (*this) & CountMask; }
protected: protected:
enum Flags { enum Flags
{
SharedPointNumbers = 0x8000u, SharedPointNumbers = 0x8000u,
CountMask = 0x0FFFu CountMask = 0x0FFFu
}; };
@ -299,7 +300,8 @@ struct GlyphVarData
POINT_RUN_COUNT_MASK = 0x7F POINT_RUN_COUNT_MASK = 0x7F
}; };
if (!check.in_range (p)) return false; if (unlikely (!check.in_range (p))) return false;
uint16_t count = *p++; uint16_t count = *p++;
if (count & POINTS_ARE_WORDS) if (count & POINTS_ARE_WORDS)
{ {
@ -393,7 +395,6 @@ struct GlyphVarData
TupleVarCount tupleVarCount; TupleVarCount tupleVarCount;
OffsetTo<HBUINT8> data; OffsetTo<HBUINT8> data;
/* TupleVarHeader tupleVarHeaders[] */ /* TupleVarHeader tupleVarHeaders[] */
public: public:
DEFINE_SIZE_MIN (4); DEFINE_SIZE_MIN (4);
}; };
@ -608,7 +609,8 @@ struct gvar
contour_point_vector_t deltas; /* flag is used to indicate referenced point */ contour_point_vector_t deltas; /* flag is used to indicate referenced point */
deltas.resize (points.length); deltas.resize (points.length);
do { do
{
float scalar = iterator.current_tuple->calculate_scalar (coords, coord_count, shared_tuples.as_array ()); float scalar = iterator.current_tuple->calculate_scalar (coords, coord_count, shared_tuples.as_array ());
if (scalar == 0.f) continue; if (scalar == 0.f) continue;
const HBUINT8 *p = iterator.get_serialized_data (); const HBUINT8 *p = iterator.get_serialized_data ();