aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2017-01-20 19:57:27 -0800
committerBehdad Esfahbod <behdad@behdad.org>2017-01-20 20:05:45 -0800
commit785982bf830723552270db5649abcb9f9f0b46b1 (patch)
tree45b04622c0bfe75d818bd0c102d40578e937516f
parent422c0c36c80145a2d993f80d5c7d3265e3d8357a (diff)
downloadharfbuzz_ng-785982bf830723552270db5649abcb9f9f0b46b1.tar.gz
[var] Flesh out some more
-rw-r--r--src/Makefile.am2
-rw-r--r--src/hb-ot-var-fvar-table.hh69
-rw-r--r--src/hb-ot-var.cc39
-rw-r--r--src/hb-ot-var.h21
4 files changed, 104 insertions, 27 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8cfe4ac7c..d7420a090 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -299,6 +299,8 @@ test_buffer_serialize_SOURCES = test-buffer-serialize.cc
test_buffer_serialize_CPPFLAGS = $(HBCFLAGS)
test_buffer_serialize_LDADD = libharfbuzz.la $(HBLIBS)
+check: harfbuzz.def # For check-defs.sh
+
dist_check_SCRIPTS = \
check-c-linkage-decls.sh \
check-defs.sh \
diff --git a/src/hb-ot-var-fvar-table.hh b/src/hb-ot-var-fvar-table.hh
index 39015b331..cb88de883 100644
--- a/src/hb-ot-var-fvar-table.hh
+++ b/src/hb-ot-var-fvar-table.hh
@@ -99,15 +99,49 @@ struct fvar
axisCount * axisSize + instanceCount * instanceSize));
}
- inline const AxisRecord * get_axes (void) const
- { return &StructAtOffset<AxisRecord> (this, things); }
-
- inline const InstanceRecord * get_instances (void) const
- { return &StructAtOffset<InstanceRecord> (get_axes () + axisCount, 0); }
-
inline unsigned int get_axis_count (void) const
{ return axisCount; }
+ inline bool get_axis (unsigned int index, hb_ot_var_axis_t *info) const
+ {
+ if (unlikely (index >= axisCount))
+ return false;
+
+ if (info)
+ {
+ const AxisRecord &axis = get_axes ()[index];
+ info->tag = axis.axisTag;
+ info->name_id = axis.axisNameID;
+ info->default_value = axis.defaultValue / 65536.;
+ /* Ensure order, to simplify client math. */
+ info->min_value = MIN<float> (info->default_value, axis.minValue / 65536.);
+ info->max_value = MAX<float> (info->default_value, axis.maxValue / 65536.);
+ }
+
+ return true;
+ }
+
+ inline unsigned int get_axis_infos (unsigned int start_offset,
+ unsigned int *axes_count /* IN/OUT */,
+ hb_ot_var_axis_t *axes_array /* OUT */) const
+ {
+ if (axes_count)
+ {
+ unsigned int count = axisCount;
+ start_offset = MIN (start_offset, count);
+
+ count -= start_offset;
+ axes_array += start_offset;
+
+ count = MIN (count, *axes_count);
+ *axes_count = count;
+
+ for (unsigned int i = 0; i < count; i++)
+ get_axis (start_offset + i, axes_array + i);
+ }
+ return axisCount;
+ }
+
inline bool find_axis (hb_tag_t tag, unsigned int *index, hb_ot_var_axis_t *info) const
{
const AxisRecord *axes = get_axes ();
@@ -117,27 +151,17 @@ struct fvar
{
if (index)
*index = i;
- if (info)
- {
- const AxisRecord &axis = axes[i];
- info->tag = axis.axisTag;
- info->name_id = axis.axisNameID;
- info->default_value = axis.defaultValue / 65536.;
- /* Ensure order, to simplify client math. */
- info->min_value = MIN<float> (info->default_value, axis.minValue / 65536.);
- info->max_value = MAX<float> (info->default_value, axis.maxValue / 65536.);
- }
- return true;
+ return get_axis (i, info);
}
if (index)
*index = HB_OT_VAR_NO_AXIS_INDEX;
return false;
}
- inline int normalize_axis_value (hb_tag_t tag, float v, unsigned int *axis_index) const
+ inline int normalize_axis_value (unsigned int axis_index, float v) const
{
hb_ot_var_axis_t axis;
- if (!find_axis (tag, axis_index, &axis))
+ if (!get_axis (axis_index, &axis))
return 0;
v = MAX (MIN (v, axis.max_value), axis.min_value); /* Clamp. */
@@ -152,6 +176,13 @@ struct fvar
}
protected:
+ inline const AxisRecord * get_axes (void) const
+ { return &StructAtOffset<AxisRecord> (this, things); }
+
+ inline const InstanceRecord * get_instances (void) const
+ { return &StructAtOffset<InstanceRecord> (get_axes () + axisCount, 0); }
+
+ protected:
FixedVersion<>version; /* Version of the fvar table
* initially set to 0x00010000u */
Offset<> things; /* Offset in bytes from the beginning of the table
diff --git a/src/hb-ot-var.cc b/src/hb-ot-var.cc
index c9dcb1f7b..d1e97257c 100644
--- a/src/hb-ot-var.cc
+++ b/src/hb-ot-var.cc
@@ -43,7 +43,7 @@ _get_fvar (hb_face_t *face)
}
/*
- * OT::fvar
+ * fvar/avar
*/
/**
@@ -51,6 +51,7 @@ _get_fvar (hb_face_t *face)
* @face: #hb_face_t to test
*
* This function allows to verify the presence of OpenType variation data on the face.
+ * Alternatively, use hb_ot_var_get_axis_count().
*
* Return value: true if face has a `fvar' table and false otherwise
*
@@ -61,3 +62,39 @@ hb_ot_var_has_data (hb_face_t *face)
{
return &_get_fvar (face) != &OT::Null(OT::fvar);
}
+
+unsigned int
+hb_ot_var_get_axis_count (hb_face_t *face)
+{
+ const OT::fvar &fvar = _get_fvar (face);
+ return fvar.get_axis_count ();
+}
+
+unsigned int
+hb_ot_var_get_axes (hb_face_t *face,
+ unsigned int start_offset,
+ unsigned int *axes_count /* IN/OUT */,
+ hb_ot_var_axis_t *axes_array /* OUT */)
+{
+ const OT::fvar &fvar = _get_fvar (face);
+ return fvar.get_axis_infos (start_offset, axes_count, axes_array);
+}
+
+HB_EXTERN hb_bool_t
+hb_ot_var_find_axis (hb_face_t *face,
+ hb_tag_t axis_tag,
+ unsigned int *axis_index,
+ hb_ot_var_axis_t *axis_info)
+{
+ const OT::fvar &fvar = _get_fvar (face);
+ return fvar.find_axis (axis_tag, axis_index, axis_info);
+}
+
+HB_EXTERN int
+hb_ot_var_normalize_axis_value (hb_face_t *face,
+ unsigned int axis_index,
+ float v)
+{
+ const OT::fvar &fvar = _get_fvar (face);
+ return fvar.normalize_axis_value (axis_index, v);
+}
diff --git a/src/hb-ot-var.h b/src/hb-ot-var.h
index fd7a5aaf0..4023b29f4 100644
--- a/src/hb-ot-var.h
+++ b/src/hb-ot-var.h
@@ -62,7 +62,14 @@ hb_ot_var_has_data (hb_face_t *face);
#define HB_OT_VAR_NO_AXIS_INDEX 0xFFFFFFFFu
-#if 0
+HB_EXTERN unsigned int
+hb_ot_var_get_axis_count (hb_face_t *face);
+
+HB_EXTERN unsigned int
+hb_ot_var_get_axes (hb_face_t *face,
+ unsigned int start_offset,
+ unsigned int *axes_count /* IN/OUT */,
+ hb_ot_var_axis_t *axes_array /* OUT */);
HB_EXTERN hb_bool_t
hb_ot_var_find_axis (hb_face_t *face,
@@ -70,13 +77,13 @@ hb_ot_var_find_axis (hb_face_t *face,
unsigned int *axis_index,
hb_ot_var_axis_t *axis_info);
-HB_EXTERN unsigned int
-Xhb_ot_var_get_axes (hb_face_t *face,
- unsigned int start_offset,
- unsigned int *axes_count /* IN/OUT */,
- hb_ot_var_axis_t *axes_array /* OUT */);
-/* TODO Add "find_axis", etc API? Are they needed at all? */
+HB_EXTERN int
+hb_ot_var_normalize_axis_value (hb_face_t *face,
+ unsigned int axis_index,
+ float v);
+
+#if 0
HB_EXTERN unsigned int
Xhb_ot_var_get_named_instances (hb_face_t *face, ... );