From 071a2cbcddcbafae9458e674c21db5001b39518d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 11 Oct 2018 10:18:46 -0400 Subject: [PATCH] [trak] Clean up --- src/hb-aat-layout-trak-table.hh | 67 +++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/src/hb-aat-layout-trak-table.hh b/src/hb-aat-layout-trak-table.hh index 3b7d438..71f169c 100644 --- a/src/hb-aat-layout-trak-table.hh +++ b/src/hb-aat-layout-trak-table.hh @@ -46,28 +46,32 @@ struct TrackTableEntry { friend struct TrackData; - inline bool sanitize (hb_sanitize_context_t *c, const void *base, - unsigned int size) const + inline float get_track_value () const { - TRACE_SANITIZE (this); - return_trace (likely (c->check_struct (this) && - (valuesZ.sanitize (c, base, size)))); + return track.to_float (); } - private: - inline float get_track_value () const + inline int get_value (const void *base, + unsigned int index, + unsigned int nSizes) const { - return track.to_float (); + return hb_array_t ((base+valuesZ).arrayZ, nSizes)[index]; } - inline int get_value (const void *base, unsigned int index) const + public: + inline bool sanitize (hb_sanitize_context_t *c, const void *base, + unsigned int nSizes) const { - return (base+valuesZ)[index]; + TRACE_SANITIZE (this); + return_trace (likely (c->check_struct (this) && + (valuesZ.sanitize (c, base, nSizes)))); } protected: Fixed track; /* Track value for this record. */ - NameID trackNameID; /* The 'name' table index for this track */ + NameID trackNameID; /* The 'name' table index for this track. + * (a short word or phrase like "loose" + * or "very tight") */ OffsetTo, HBUINT16, false> valuesZ; /* Offset from start of tracking table to * per-size tracking values for this track. */ @@ -78,14 +82,6 @@ struct TrackTableEntry struct TrackData { - inline bool sanitize (hb_sanitize_context_t *c, const void *base) const - { - TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && - sizeTable.sanitize (c, base, nSizes) && - trackTable.sanitize (c, nTracks, base, nSizes)); - } - inline float get_tracking (const void *base, float ptem) const { /* CoreText points are CSS pixels (96 per inch), @@ -120,22 +116,31 @@ struct TrackData // TODO(ebraminio): We don't attempt to extrapolate to larger or // smaller values for now but we should do, per spec if (size_index == sizes) - return trackTableEntry->get_value (base, sizes - 1); + return trackTableEntry->get_value (base, sizes - 1, nSizes); if (size_index == 0 || size_table[size_index] == fixed_size) - return trackTableEntry->get_value (base, size_index); + return trackTableEntry->get_value (base, size_index, nSizes); float s0 = size_table[size_index - 1].to_float (); float s1 = size_table[size_index].to_float (); float t = (csspx - s0) / (s1 - s0); - return (float) t * trackTableEntry->get_value (base, size_index) + - ((float) 1.0 - t) * trackTableEntry->get_value (base, size_index - 1); + return (float) t * trackTableEntry->get_value (base, size_index, nSizes) + + ((float) 1.0 - t) * trackTableEntry->get_value (base, size_index - 1, nSizes); + } + + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + sizeTable.sanitize (c, base, nSizes) && + trackTable.sanitize (c, nTracks, base, nSizes)); } protected: HBUINT16 nTracks; /* Number of separate tracks included in this table. */ HBUINT16 nSizes; /* Number of point sizes included in this table. */ LOffsetTo, false> - sizeTable; /* Offset to array[nSizes] of size values. */ + sizeTable; /* Offset from start of the tracking table to + * Array[nSizes] of size values.. */ UnsizedArrayOf trackTable; /* Array[nTracks] of TrackTableEntry records. */ @@ -194,15 +199,17 @@ struct trak } protected: - FixedVersion<> version; /* Version of the tracking table--currently - * 0x00010000u for version 1.0. */ - HBUINT16 format; /* Format of the tracking table */ - OffsetTo horizData; /* TrackData for horizontal text */ - OffsetTo vertData; /* TrackData for vertical text */ + FixedVersion<> version; /* Version of the tracking table + * (0x00010000u for version 1.0). */ + HBUINT16 format; /* Format of the tracking table (set to 0). */ + OffsetTo horizData; /* Offset from start of tracking table to TrackData + * for horizontal text (or 0 if none). */ + OffsetTo vertData; /* Offset from start of tracking table to TrackData + * for vertical text (or 0 if none). */ HBUINT16 reserved; /* Reserved. Set to 0. */ public: - DEFINE_SIZE_MIN (12); + DEFINE_SIZE_STATIC (12); }; } /* namespace AAT */ -- 2.7.4