[glyf] Move a few structs out of Glyph{}
This commit is contained in:
parent
ae75f066b5
commit
ef250eea7e
|
@ -212,22 +212,8 @@ enum phantom_point_index_t
|
||||||
PHANTOM_COUNT = 4
|
PHANTOM_COUNT = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Glyph
|
struct GlyphHeader
|
||||||
{
|
{
|
||||||
enum simple_glyph_flag_t
|
|
||||||
{
|
|
||||||
FLAG_ON_CURVE = 0x01,
|
|
||||||
FLAG_X_SHORT = 0x02,
|
|
||||||
FLAG_Y_SHORT = 0x04,
|
|
||||||
FLAG_REPEAT = 0x08,
|
|
||||||
FLAG_X_SAME = 0x10,
|
|
||||||
FLAG_Y_SAME = 0x20,
|
|
||||||
FLAG_OVERLAP_SIMPLE = 0x40,
|
|
||||||
FLAG_RESERVED2 = 0x80
|
|
||||||
};
|
|
||||||
|
|
||||||
struct GlyphHeader
|
|
||||||
{
|
|
||||||
bool has_data () const { return numberOfContours; }
|
bool has_data () const { return numberOfContours; }
|
||||||
|
|
||||||
template <typename accelerator_t>
|
template <typename accelerator_t>
|
||||||
|
@ -255,10 +241,22 @@ struct Glyph
|
||||||
FWORD yMax; /* Maximum y for coordinate data. */
|
FWORD yMax; /* Maximum y for coordinate data. */
|
||||||
public:
|
public:
|
||||||
DEFINE_SIZE_STATIC (10);
|
DEFINE_SIZE_STATIC (10);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SimpleGlyph
|
||||||
|
{
|
||||||
|
enum simple_glyph_flag_t
|
||||||
|
{
|
||||||
|
FLAG_ON_CURVE = 0x01,
|
||||||
|
FLAG_X_SHORT = 0x02,
|
||||||
|
FLAG_Y_SHORT = 0x04,
|
||||||
|
FLAG_REPEAT = 0x08,
|
||||||
|
FLAG_X_SAME = 0x10,
|
||||||
|
FLAG_Y_SAME = 0x20,
|
||||||
|
FLAG_OVERLAP_SIMPLE = 0x40,
|
||||||
|
FLAG_RESERVED2 = 0x80
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SimpleGlyph
|
|
||||||
{
|
|
||||||
const GlyphHeader &header;
|
const GlyphHeader &header;
|
||||||
hb_bytes_t bytes;
|
hb_bytes_t bytes;
|
||||||
SimpleGlyph (const GlyphHeader &header_, hb_bytes_t bytes_) :
|
SimpleGlyph (const GlyphHeader &header_, hb_bytes_t bytes_) :
|
||||||
|
@ -281,7 +279,7 @@ struct Glyph
|
||||||
return instructionLength;
|
return instructionLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Glyph trim_padding () const
|
const hb_bytes_t trim_padding () const
|
||||||
{
|
{
|
||||||
/* based on FontTools _g_l_y_f.py::trim */
|
/* based on FontTools _g_l_y_f.py::trim */
|
||||||
const uint8_t *glyph = (uint8_t*) bytes.arrayZ;
|
const uint8_t *glyph = (uint8_t*) bytes.arrayZ;
|
||||||
|
@ -289,7 +287,7 @@ struct Glyph
|
||||||
/* simple glyph w/contours, possibly trimmable */
|
/* simple glyph w/contours, possibly trimmable */
|
||||||
glyph += instruction_len_offset ();
|
glyph += instruction_len_offset ();
|
||||||
|
|
||||||
if (unlikely (glyph + 2 >= glyph_end)) return Glyph ();
|
if (unlikely (glyph + 2 >= glyph_end)) return hb_bytes_t ();
|
||||||
unsigned int num_coordinates = StructAtOffset<HBUINT16> (glyph - 2, 0) + 1;
|
unsigned int num_coordinates = StructAtOffset<HBUINT16> (glyph - 2, 0) + 1;
|
||||||
unsigned int num_instructions = StructAtOffset<HBUINT16> (glyph, 0);
|
unsigned int num_instructions = StructAtOffset<HBUINT16> (glyph, 0);
|
||||||
|
|
||||||
|
@ -305,7 +303,7 @@ struct Glyph
|
||||||
unsigned int repeat = 1;
|
unsigned int repeat = 1;
|
||||||
if (flag & FLAG_REPEAT)
|
if (flag & FLAG_REPEAT)
|
||||||
{
|
{
|
||||||
if (unlikely (glyph >= glyph_end)) return Glyph ();
|
if (unlikely (glyph >= glyph_end)) return hb_bytes_t ();
|
||||||
repeat = *glyph + 1;
|
repeat = *glyph + 1;
|
||||||
glyph++;
|
glyph++;
|
||||||
}
|
}
|
||||||
|
@ -323,8 +321,8 @@ struct Glyph
|
||||||
if (coords_with_flags >= num_coordinates) break;
|
if (coords_with_flags >= num_coordinates) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely (coords_with_flags != num_coordinates)) return Glyph ();
|
if (unlikely (coords_with_flags != num_coordinates)) return hb_bytes_t ();
|
||||||
return Glyph (bytes.sub_array (0, bytes.length + coord_bytes - (glyph_end - glyph)));
|
return bytes.sub_array (0, bytes.length + coord_bytes - (glyph_end - glyph));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* zero instruction length */
|
/* zero instruction length */
|
||||||
|
@ -426,10 +424,10 @@ struct Glyph
|
||||||
&& read_points (p, points_, bytes, [] (contour_point_t &p, float v) { p.y = v; },
|
&& read_points (p, points_, bytes, [] (contour_point_t &p, float v) { p.y = v; },
|
||||||
FLAG_Y_SHORT, FLAG_Y_SAME);
|
FLAG_Y_SHORT, FLAG_Y_SAME);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CompositeGlyph
|
struct CompositeGlyph
|
||||||
{
|
{
|
||||||
const GlyphHeader &header;
|
const GlyphHeader &header;
|
||||||
hb_bytes_t bytes;
|
hb_bytes_t bytes;
|
||||||
CompositeGlyph (const GlyphHeader &header_, hb_bytes_t bytes_) :
|
CompositeGlyph (const GlyphHeader &header_, hb_bytes_t bytes_) :
|
||||||
|
@ -455,7 +453,7 @@ struct Glyph
|
||||||
|
|
||||||
/* Trimming for composites not implemented.
|
/* Trimming for composites not implemented.
|
||||||
* If removing hints it falls out of that. */
|
* If removing hints it falls out of that. */
|
||||||
const Glyph trim_padding () const { return Glyph (bytes); }
|
const hb_bytes_t trim_padding () const { return bytes; }
|
||||||
|
|
||||||
void drop_hints ()
|
void drop_hints ()
|
||||||
{
|
{
|
||||||
|
@ -475,8 +473,11 @@ struct Glyph
|
||||||
return;
|
return;
|
||||||
glyph_chain.set_overlaps_flag ();
|
glyph_chain.set_overlaps_flag ();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct Glyph
|
||||||
|
{
|
||||||
enum glyph_type_t { EMPTY, SIMPLE, COMPOSITE };
|
enum glyph_type_t { EMPTY, SIMPLE, COMPOSITE };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -486,7 +487,7 @@ struct Glyph
|
||||||
return CompositeGlyph (*header, bytes).get_iterator ();
|
return CompositeGlyph (*header, bytes).get_iterator ();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Glyph trim_padding () const
|
const hb_bytes_t trim_padding () const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case COMPOSITE: return CompositeGlyph (*header, bytes).trim_padding ();
|
case COMPOSITE: return CompositeGlyph (*header, bytes).trim_padding ();
|
||||||
|
|
|
@ -391,7 +391,7 @@ struct glyf_accelerator_t
|
||||||
|
|
||||||
Glyph glyph (hb_bytes_t ((const char *) this->glyf_table + start_offset,
|
Glyph glyph (hb_bytes_t ((const char *) this->glyf_table + start_offset,
|
||||||
end_offset - start_offset), gid);
|
end_offset - start_offset), gid);
|
||||||
return needs_padding_removal ? glyph.trim_padding () : glyph;
|
return needs_padding_removal ? Glyph (glyph.trim_padding ()) : glyph;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct path_builder_t
|
struct path_builder_t
|
||||||
|
@ -425,7 +425,7 @@ struct glyf_accelerator_t
|
||||||
* https://stackoverflow.com/a/20772557 */
|
* https://stackoverflow.com/a/20772557 */
|
||||||
void consume_point (const contour_point_t &point)
|
void consume_point (const contour_point_t &point)
|
||||||
{
|
{
|
||||||
bool is_on_curve = point.flag & Glyph::FLAG_ON_CURVE;
|
bool is_on_curve = point.flag & SimpleGlyph::FLAG_ON_CURVE;
|
||||||
optional_point_t p (point.x, point.y);
|
optional_point_t p (point.x, point.y);
|
||||||
if (!first_oncurve.has_data)
|
if (!first_oncurve.has_data)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue