#ifndef HB_OT_VAR_AVAR_TABLE_HH
#define HB_OT_VAR_AVAR_TABLE_HH
-#include "hb-open-type-private.hh"
+#include "hb-open-type.hh"
/*
* avar -- Axis Variations
struct AxisValueMap
{
- inline bool sanitize (hb_sanitize_context_t *c) const
+ bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
return_trace (c->check_struct (this));
}
public:
- F2DOT14 fromCoord; /* A normalized coordinate value obtained using
- * default normalization. */
- F2DOT14 toCoord; /* The modified, normalized coordinate value. */
+ F2DOT14 coords[2];
+// F2DOT14 fromCoord; /* A normalized coordinate value obtained using
+// * default normalization. */
+// F2DOT14 toCoord; /* The modified, normalized coordinate value. */
public:
DEFINE_SIZE_STATIC (4);
struct SegmentMaps : ArrayOf<AxisValueMap>
{
- inline int map (int value) const
+ int map (int value, unsigned int from_offset = 0, unsigned int to_offset = 1) const
{
+#define fromCoord coords[from_offset]
+#define toCoord coords[to_offset]
/* The following special-cases are not part of OpenType, which requires
* that at least -1, 0, and +1 must be mapped. But we include these as
* part of a better error recovery scheme. */
-
if (len < 2)
{
if (!len)
return value - arrayZ[0].fromCoord + arrayZ[0].toCoord;
unsigned int i;
- unsigned int count = len;
+ unsigned int count = len - 1;
for (i = 1; i < count && value > arrayZ[i].fromCoord; i++)
;
return arrayZ[i-1].toCoord;
int denom = arrayZ[i].fromCoord - arrayZ[i-1].fromCoord;
- return arrayZ[i-1].toCoord +
- ((arrayZ[i].toCoord - arrayZ[i-1].toCoord) *
- (value - arrayZ[i-1].fromCoord) + denom/2) / denom;
+ return roundf (arrayZ[i-1].toCoord + ((float) (arrayZ[i].toCoord - arrayZ[i-1].toCoord) *
+ (value - arrayZ[i-1].fromCoord)) / denom);
+#undef toCoord
+#undef fromCoord
}
- DEFINE_SIZE_ARRAY (2, arrayZ);
+ int unmap (int value) const { return map (value, 1, 0); }
+
+ public:
+ DEFINE_SIZE_ARRAY (2, *this);
};
struct avar
{
- static const hb_tag_t tableTag = HB_OT_TAG_avar;
+ static constexpr hb_tag_t tableTag = HB_OT_TAG_avar;
- inline bool sanitize (hb_sanitize_context_t *c) const
+ bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
if (unlikely (!(version.sanitize (c) &&
c->check_struct (this))))
return_trace (false);
- const SegmentMaps *map = axisSegmentMapsZ;
+ const SegmentMaps *map = &firstAxisSegmentMaps;
unsigned int count = axisCount;
for (unsigned int i = 0; i < count; i++)
{
if (unlikely (!map->sanitize (c)))
- return_trace (false);
+ return_trace (false);
map = &StructAfter<SegmentMaps> (*map);
}
return_trace (true);
}
- inline void map_coords (int *coords, unsigned int coords_length) const
+ void map_coords (int *coords, unsigned int coords_length) const
{
- unsigned int count = MIN<unsigned int> (coords_length, axisCount);
+ unsigned int count = hb_min (coords_length, axisCount);
- const SegmentMaps *map = axisSegmentMapsZ;
+ const SegmentMaps *map = &firstAxisSegmentMaps;
for (unsigned int i = 0; i < count; i++)
{
coords[i] = map->map (coords[i]);
}
}
+ void unmap_coords (int *coords, unsigned int coords_length) const
+ {
+ unsigned int count = hb_min (coords_length, axisCount);
+
+ const SegmentMaps *map = &firstAxisSegmentMaps;
+ for (unsigned int i = 0; i < count; i++)
+ {
+ coords[i] = map->unmap (coords[i]);
+ map = &StructAfter<SegmentMaps> (*map);
+ }
+ }
+
protected:
FixedVersion<>version; /* Version of the avar table
* initially set to 0x00010000u */
HBUINT16 axisCount; /* The number of variation axes in the font. This
* must be the same number as axisCount in the
* 'fvar' table. */
- SegmentMaps axisSegmentMapsZ[VAR];
+ SegmentMaps firstAxisSegmentMaps;
public:
DEFINE_SIZE_MIN (8);