[GX] Add compact VariationDevice implementation

Add compact format that uses signed bytes instead of shorts.
This commit is contained in:
Behdad Esfahbod 2016-03-18 15:52:24 -07:00
parent 71b06fd392
commit baa329c6a1
2 changed files with 25 additions and 11 deletions

View File

@ -653,6 +653,7 @@ struct IntType
typedef IntType<int8_t , 1> CHAR; /* 8-bit signed integer. */ typedef IntType<int8_t , 1> CHAR; /* 8-bit signed integer. */
typedef IntType<uint8_t , 1> BYTE; /* 8-bit unsigned integer. */ typedef IntType<uint8_t , 1> BYTE; /* 8-bit unsigned integer. */
typedef IntType<int8_t , 1> INT8; /* 8-bit signed integer. */
typedef IntType<uint16_t, 2> USHORT; /* 16-bit unsigned integer. */ typedef IntType<uint16_t, 2> USHORT; /* 16-bit unsigned integer. */
typedef IntType<int16_t, 2> SHORT; /* 16-bit signed integer. */ typedef IntType<int16_t, 2> SHORT; /* 16-bit signed integer. */
typedef IntType<uint32_t, 4> ULONG; /* 32-bit unsigned integer. */ typedef IntType<uint32_t, 4> ULONG; /* 32-bit unsigned integer. */

View File

@ -1419,6 +1419,9 @@ struct VariationDevice
{ {
friend struct Device; friend struct Device;
static const unsigned short FORMAT_BYTES = 0x0100;
static const unsigned short FORMAT_SHORTS = 0x0101;
private: private:
inline hb_position_t get_x_delta (hb_font_t *font) const inline hb_position_t get_x_delta (hb_font_t *font) const
@ -1431,29 +1434,39 @@ struct VariationDevice
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (c->check_struct (this) && return_trace (c->check_struct (this) &&
c->check_array (&deltaValue, SHORT::static_size, deltaCount)); c->check_array (&deltaValue, get_item_size (), deltaCount));
} }
private: private:
inline unsigned int get_item_size (void) const
{ return deltaFormat == FORMAT_BYTES ? 1 : 2; }
inline float get_delta (int *coords, unsigned int coord_count) const inline float get_delta (int *coords, unsigned int coord_count) const
{ {
float v = 0; float v = 0;
const VariationMap &map = this+variationMap; const VariationMap &map = this+variationMap;
unsigned int count = MIN ((unsigned int) deltaCount, map.get_len ()); unsigned int count = MIN ((unsigned int) deltaCount, map.get_len ());
for (unsigned int i = 0; i < count; i++) if (get_item_size () == 1)
v += deltaValue[i] * map[i].evaluate (coords, coord_count); for (unsigned int i = 0; i < count; i++)
v += deltaValue.bytesZ[i] * map[i].evaluate (coords, coord_count);
else
for (unsigned int i = 0; i < count; i++)
v += deltaValue.shortsZ[i] * map[i].evaluate (coords, coord_count);
return v; return v;
} }
protected: protected:
OffsetTo<VariationMap> OffsetTo<VariationMap>
variationMap; /* Offset to variation mapping for this table. */ variationMap; /* Offset to variation mapping for this table. */
USHORT deltaCount; /* Number of deltas in this table. */ USHORT deltaCount; /* Number of deltas in this table. */
USHORT deltaFormat; /* Format identifier for this table: 0x10 */ USHORT deltaFormat; /* Format identifier for this table: 0x0100 or 0x0101 */
SHORT deltaValue[VAR]; /* Deltas as signed values in design space. */ union {
INT8 bytesZ[VAR]; /* Deltas as signed bytes in design space; format=0x0100 */
SHORT shortsZ[VAR]; /* Deltas as signed shorts in design space; format=0x0101 */
} deltaValue;
public: public:
DEFINE_SIZE_ARRAY (6, deltaValue); DEFINE_SIZE_ARRAY (6, deltaValue.shortsZ);
}; };
struct Device struct Device
@ -1464,7 +1477,7 @@ struct Device
{ {
case 1: case 2: case 3: case 1: case 2: case 3:
return u.hinting.get_x_delta (font); return u.hinting.get_x_delta (font);
case 0x10: case VariationDevice::FORMAT_BYTES: case VariationDevice::FORMAT_SHORTS:
return u.variation.get_x_delta (font); return u.variation.get_x_delta (font);
default: default:
return 0; return 0;
@ -1476,7 +1489,7 @@ struct Device
{ {
case 1: case 2: case 3: case 1: case 2: case 3:
return u.hinting.get_x_delta (font); return u.hinting.get_x_delta (font);
case 0x10: case VariationDevice::FORMAT_BYTES: case VariationDevice::FORMAT_SHORTS:
return u.variation.get_x_delta (font); return u.variation.get_x_delta (font);
default: default:
return 0; return 0;
@ -1490,7 +1503,7 @@ struct Device
switch (u.b.format) { switch (u.b.format) {
case 1: case 2: case 3: case 1: case 2: case 3:
return_trace (u.hinting.sanitize (c)); return_trace (u.hinting.sanitize (c));
case 0x10: case VariationDevice::FORMAT_BYTES: case VariationDevice::FORMAT_SHORTS:
return_trace (u.variation.sanitize (c)); return_trace (u.variation.sanitize (c));
default: default:
return_trace (true); return_trace (true);