[HarfBuzz] harfbuzz: Branch 'master' - 2 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Mon Aug 6 16:51:55 UTC 2018
docs/harfbuzz-sections.txt | 6 +
src/hb-font-private.hh | 28 ++++
src/hb-font.cc | 262 ++++++++++++++++++++++++++++++---------------
src/hb-font.h | 42 +++++++
src/hb-ot-shape.cc | 7 -
5 files changed, 259 insertions(+), 86 deletions(-)
New commits:
commit 79e21984b13bdb879f3007ba9a97fde47df340d3
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Mon Aug 6 09:45:17 2018 -0700
Add batch advance width callback function
New API:
+hb_font_funcs_set_glyph_h_advances_func
+hb_font_funcs_set_glyph_v_advances_func
+hb_font_get_glyph_h_advances
+hb_font_get_glyph_h_advances_func_t
+hb_font_get_glyph_v_advances
+hb_font_get_glyph_v_advances_func_t
diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt
index 65ea1f90..f012fbdb 100644
--- a/docs/harfbuzz-sections.txt
+++ b/docs/harfbuzz-sections.txt
@@ -208,10 +208,12 @@ hb_font_funcs_set_glyph_contour_point_func
hb_font_funcs_set_glyph_extents_func
hb_font_funcs_set_glyph_from_name_func
hb_font_funcs_set_glyph_h_advance_func
+hb_font_funcs_set_glyph_h_advances_func
hb_font_funcs_set_glyph_h_kerning_func
hb_font_funcs_set_glyph_h_origin_func
hb_font_funcs_set_glyph_name_func
hb_font_funcs_set_glyph_v_advance_func
+hb_font_funcs_set_glyph_v_advances_func
hb_font_funcs_set_glyph_v_kerning_func
hb_font_funcs_set_glyph_v_origin_func
hb_font_funcs_set_nominal_glyph_func
@@ -233,6 +235,8 @@ hb_font_get_glyph_from_name
hb_font_get_glyph_from_name_func_t
hb_font_get_glyph_h_advance
hb_font_get_glyph_h_advance_func_t
+hb_font_get_glyph_h_advances
+hb_font_get_glyph_h_advances_func_t
hb_font_get_glyph_h_kerning
hb_font_get_glyph_h_kerning_func_t
hb_font_get_glyph_h_origin
@@ -245,6 +249,8 @@ hb_font_get_glyph_origin_for_direction
hb_font_get_glyph_origin_func_t
hb_font_get_glyph_v_advance
hb_font_get_glyph_v_advance_func_t
+hb_font_get_glyph_v_advances
+hb_font_get_glyph_v_advances_func_t
hb_font_get_glyph_v_kerning
hb_font_get_glyph_v_kerning_func_t
hb_font_get_glyph_v_origin
diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh
index 81ae4111..6862e062 100644
--- a/src/hb-font-private.hh
+++ b/src/hb-font-private.hh
@@ -46,6 +46,8 @@
HB_FONT_FUNC_IMPLEMENT (variation_glyph) \
HB_FONT_FUNC_IMPLEMENT (glyph_h_advance) \
HB_FONT_FUNC_IMPLEMENT (glyph_v_advance) \
+ HB_FONT_FUNC_IMPLEMENT (glyph_h_advances) \
+ HB_FONT_FUNC_IMPLEMENT (glyph_v_advances) \
HB_FONT_FUNC_IMPLEMENT (glyph_h_origin) \
HB_FONT_FUNC_IMPLEMENT (glyph_v_origin) \
HB_FONT_FUNC_IMPLEMENT (glyph_h_kerning) \
@@ -54,7 +56,6 @@
HB_FONT_FUNC_IMPLEMENT (glyph_contour_point) \
HB_FONT_FUNC_IMPLEMENT (glyph_name) \
HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \
- HB_FONT_FUNC_IMPLEMENT (glyph_h_advances) \
/* ^--- Add new callbacks here */
struct hb_font_funcs_t
@@ -228,18 +229,6 @@ struct hb_font_t
klass->user_data.glyph_h_advance);
}
- inline void get_glyph_h_advances(unsigned count,
- hb_codepoint_t* glyphs,
- unsigned glyph_struct_size,
- hb_position_t* advances,
- unsigned advance_struct_size) {
- return klass->get.f.glyph_h_advances (this, user_data,
- count,
- glyphs, glyph_struct_size,
- advances, advance_struct_size,
- klass->user_data.glyph_h_advances);
- }
-
inline hb_position_t get_glyph_v_advance (hb_codepoint_t glyph)
{
return klass->get.f.glyph_v_advance (this, user_data,
@@ -247,6 +236,32 @@ struct hb_font_t
klass->user_data.glyph_v_advance);
}
+ inline void get_glyph_h_advances (unsigned int count,
+ hb_codepoint_t *first_glyph,
+ unsigned int glyph_stride,
+ hb_position_t *first_advance,
+ unsigned int advance_stride)
+ {
+ return klass->get.f.glyph_h_advances (this, user_data,
+ count,
+ first_glyph, glyph_stride,
+ first_advance, advance_stride,
+ klass->user_data.glyph_h_advances);
+ }
+
+ inline void get_glyph_v_advances (unsigned int count,
+ hb_codepoint_t *first_glyph,
+ unsigned int glyph_stride,
+ hb_position_t *first_advance,
+ unsigned int advance_stride)
+ {
+ return klass->get.f.glyph_v_advances (this, user_data,
+ count,
+ first_glyph, glyph_stride,
+ first_advance, advance_stride,
+ klass->user_data.glyph_v_advances);
+ }
+
inline hb_bool_t get_glyph_h_origin (hb_codepoint_t glyph,
hb_position_t *x, hb_position_t *y)
{
diff --git a/src/hb-font.cc b/src/hb-font.cc
index a3f4d1a4..e29b80f4 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -29,6 +29,7 @@
#include "hb-private.hh"
#include "hb-font-private.hh"
+#include "hb-machinery-private.hh"
/*
@@ -45,10 +46,10 @@ hb_font_get_font_h_extents_nil (hb_font_t *font HB_UNUSED,
return false;
}
static hb_bool_t
-hb_font_get_font_h_extents_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_font_extents_t *metrics,
- void *user_data HB_UNUSED)
+hb_font_get_font_h_extents_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_font_extents_t *metrics,
+ void *user_data HB_UNUSED)
{
hb_bool_t ret = font->parent->get_font_h_extents (metrics);
if (ret) {
@@ -69,10 +70,10 @@ hb_font_get_font_v_extents_nil (hb_font_t *font HB_UNUSED,
return false;
}
static hb_bool_t
-hb_font_get_font_v_extents_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_font_extents_t *metrics,
- void *user_data HB_UNUSED)
+hb_font_get_font_v_extents_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_font_extents_t *metrics,
+ void *user_data HB_UNUSED)
{
hb_bool_t ret = font->parent->get_font_v_extents (metrics);
if (ret) {
@@ -94,11 +95,11 @@ hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED,
return false;
}
static hb_bool_t
-hb_font_get_nominal_glyph_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t unicode,
- hb_codepoint_t *glyph,
- void *user_data HB_UNUSED)
+hb_font_get_nominal_glyph_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t unicode,
+ hb_codepoint_t *glyph,
+ void *user_data HB_UNUSED)
{
return font->parent->get_nominal_glyph (unicode, glyph);
}
@@ -115,12 +116,12 @@ hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED,
return false;
}
static hb_bool_t
-hb_font_get_variation_glyph_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t unicode,
- hb_codepoint_t variation_selector,
- hb_codepoint_t *glyph,
- void *user_data HB_UNUSED)
+hb_font_get_variation_glyph_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t unicode,
+ hb_codepoint_t variation_selector,
+ hb_codepoint_t *glyph,
+ void *user_data HB_UNUSED)
{
return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
}
@@ -129,75 +130,134 @@ hb_font_get_variation_glyph_parent (hb_font_t *font,
static hb_position_t
hb_font_get_glyph_h_advance_nil (hb_font_t *font,
void *font_data HB_UNUSED,
- hb_codepoint_t glyph,
+ hb_codepoint_t glyph HB_UNUSED,
void *user_data HB_UNUSED)
{
return font->x_scale;
}
static hb_position_t
-hb_font_get_glyph_h_advance_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t glyph,
- void *user_data HB_UNUSED)
+hb_font_get_glyph_h_advance_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t glyph,
+ void *user_data HB_UNUSED)
{
return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
}
-template <class T>
-T* advance_by_byte_size(T* p, unsigned byte_size) {
- return reinterpret_cast<T*>(reinterpret_cast<uint8_t*>(p) + byte_size);
-}
-
-static void
-hb_font_get_glyph_h_advances_nil(hb_font_t *font,
- void *font_data HB_UNUSED,
- unsigned count,
- hb_codepoint_t* glyphs,
- unsigned glyph_struct_size,
- hb_position_t* advances,
- unsigned advance_struct_size,
- void *user_data HB_UNUSED) {
- for (; count--;
- glyphs = advance_by_byte_size(glyphs, glyph_struct_size),
- advances = advance_by_byte_size(advances, advance_struct_size)) {
- *advances = hb_font_get_glyph_h_advance_nil(font, font_data, *glyphs, user_data);
- }
-}
-
-static void
-hb_font_get_glyph_h_advances_parent(hb_font_t* font,
- void* font_data HB_UNUSED,
- unsigned count,
- hb_codepoint_t* glyphs,
- unsigned glyph_struct_size,
- hb_position_t* advances,
- unsigned advance_struct_size,
- void* user_data HB_UNUSED) {
- for (; count--;
- glyphs = advance_by_byte_size(glyphs, glyph_struct_size),
- advances = advance_by_byte_size(advances, advance_struct_size)) {
- *advances = hb_font_get_glyph_h_advance_parent(font, font_data, *glyphs, user_data);
- }
-}
-
static hb_position_t
hb_font_get_glyph_v_advance_nil (hb_font_t *font,
void *font_data HB_UNUSED,
- hb_codepoint_t glyph,
+ hb_codepoint_t glyph HB_UNUSED,
void *user_data HB_UNUSED)
{
/* TODO use font_extents.ascender+descender */
return font->y_scale;
}
static hb_position_t
-hb_font_get_glyph_v_advance_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t glyph,
- void *user_data HB_UNUSED)
+hb_font_get_glyph_v_advance_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t glyph,
+ void *user_data HB_UNUSED)
{
return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
}
+static void
+hb_font_get_glyph_h_advances_nil (hb_font_t* font,
+ void* font_data HB_UNUSED,
+ unsigned int count,
+ hb_codepoint_t *first_glyph HB_UNUSED,
+ unsigned int glyph_stride HB_UNUSED,
+ hb_position_t *first_advance,
+ unsigned int advance_stride,
+ void *user_data HB_UNUSED)
+{
+ for (unsigned int i = 0; i < count; i++)
+ {
+ *first_advance = font->get_glyph_h_advance (*first_glyph);
+ first_glyph = &StructAtOffset<hb_codepoint_t> (first_glyph, glyph_stride);
+ first_advance = &StructAtOffset<hb_position_t> (first_advance, advance_stride);
+ }
+}
+static void
+hb_font_get_glyph_h_advances_default (hb_font_t* font,
+ void* font_data HB_UNUSED,
+ unsigned int count,
+ hb_codepoint_t *first_glyph,
+ unsigned int glyph_stride,
+ hb_position_t *first_advance,
+ unsigned int advance_stride,
+ void *user_data HB_UNUSED)
+{
+ if (font->has_glyph_h_advance_func ())
+ {
+ for (unsigned int i = 0; i < count; i++)
+ {
+ *first_advance = font->get_glyph_h_advance (*first_glyph);
+ first_glyph = &StructAtOffset<hb_codepoint_t> (first_glyph, glyph_stride);
+ first_advance = &StructAtOffset<hb_position_t> (first_advance, advance_stride);
+ }
+ return;
+ }
+
+ font->parent->get_glyph_h_advances (count,
+ first_glyph, glyph_stride,
+ first_advance, advance_stride);
+ for (unsigned int i = 0; i < count; i++)
+ {
+ *first_advance = font->parent_scale_x_distance (*first_advance);
+ first_advance = &StructAtOffset<hb_position_t> (first_advance, advance_stride);
+ }
+}
+
+static void
+hb_font_get_glyph_v_advances_nil (hb_font_t* font,
+ void* font_data HB_UNUSED,
+ unsigned int count,
+ hb_codepoint_t *first_glyph HB_UNUSED,
+ unsigned int glyph_stride HB_UNUSED,
+ hb_position_t *first_advance,
+ unsigned int advance_stride,
+ void *user_data HB_UNUSED)
+{
+ for (unsigned int i = 0; i < count; i++)
+ {
+ *first_advance = font->get_glyph_v_advance (*first_glyph);
+ first_glyph = &StructAtOffset<hb_codepoint_t> (first_glyph, glyph_stride);
+ first_advance = &StructAtOffset<hb_position_t> (first_advance, advance_stride);
+ }
+}
+static void
+hb_font_get_glyph_v_advances_default (hb_font_t* font,
+ void* font_data HB_UNUSED,
+ unsigned int count,
+ hb_codepoint_t *first_glyph,
+ unsigned int glyph_stride,
+ hb_position_t *first_advance,
+ unsigned int advance_stride,
+ void *user_data HB_UNUSED)
+{
+ if (font->has_glyph_v_advance_func ())
+ {
+ for (unsigned int i = 0; i < count; i++)
+ {
+ *first_advance = font->get_glyph_v_advance (*first_glyph);
+ first_glyph = &StructAtOffset<hb_codepoint_t> (first_glyph, glyph_stride);
+ first_advance = &StructAtOffset<hb_position_t> (first_advance, advance_stride);
+ }
+ return;
+ }
+
+ font->parent->get_glyph_v_advances (count,
+ first_glyph, glyph_stride,
+ first_advance, advance_stride);
+ for (unsigned int i = 0; i < count; i++)
+ {
+ *first_advance = font->parent_scale_y_distance (*first_advance);
+ first_advance = &StructAtOffset<hb_position_t> (first_advance, advance_stride);
+ }
+}
+
static hb_bool_t
hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
void *font_data HB_UNUSED,
@@ -210,12 +270,12 @@ hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
return true;
}
static hb_bool_t
-hb_font_get_glyph_h_origin_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t glyph,
- hb_position_t *x,
- hb_position_t *y,
- void *user_data HB_UNUSED)
+hb_font_get_glyph_h_origin_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t glyph,
+ hb_position_t *x,
+ hb_position_t *y,
+ void *user_data HB_UNUSED)
{
hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
if (ret)
@@ -235,12 +295,12 @@ hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
return false;
}
static hb_bool_t
-hb_font_get_glyph_v_origin_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t glyph,
- hb_position_t *x,
- hb_position_t *y,
- void *user_data HB_UNUSED)
+hb_font_get_glyph_v_origin_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t glyph,
+ hb_position_t *x,
+ hb_position_t *y,
+ void *user_data HB_UNUSED)
{
hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
if (ret)
@@ -258,11 +318,11 @@ hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
return 0;
}
static hb_position_t
-hb_font_get_glyph_h_kerning_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t left_glyph,
- hb_codepoint_t right_glyph,
- void *user_data HB_UNUSED)
+hb_font_get_glyph_h_kerning_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t left_glyph,
+ hb_codepoint_t right_glyph,
+ void *user_data HB_UNUSED)
{
return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
}
@@ -277,11 +337,11 @@ hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
return 0;
}
static hb_position_t
-hb_font_get_glyph_v_kerning_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t top_glyph,
- hb_codepoint_t bottom_glyph,
- void *user_data HB_UNUSED)
+hb_font_get_glyph_v_kerning_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t top_glyph,
+ hb_codepoint_t bottom_glyph,
+ void *user_data HB_UNUSED)
{
return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
}
@@ -297,11 +357,11 @@ hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
return false;
}
static hb_bool_t
-hb_font_get_glyph_extents_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t glyph,
- hb_glyph_extents_t *extents,
- void *user_data HB_UNUSED)
+hb_font_get_glyph_extents_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t glyph,
+ hb_glyph_extents_t *extents,
+ void *user_data HB_UNUSED)
{
hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
if (ret) {
@@ -324,13 +384,13 @@ hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
return false;
}
static hb_bool_t
-hb_font_get_glyph_contour_point_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t glyph,
- unsigned int point_index,
- hb_position_t *x,
- hb_position_t *y,
- void *user_data HB_UNUSED)
+hb_font_get_glyph_contour_point_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t glyph,
+ unsigned int point_index,
+ hb_position_t *x,
+ hb_position_t *y,
+ void *user_data HB_UNUSED)
{
hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
if (ret)
@@ -349,11 +409,11 @@ hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
return false;
}
static hb_bool_t
-hb_font_get_glyph_name_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t glyph,
- char *name, unsigned int size,
- void *user_data HB_UNUSED)
+hb_font_get_glyph_name_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t glyph,
+ char *name, unsigned int size,
+ void *user_data HB_UNUSED)
{
return font->parent->get_glyph_name (glyph, name, size);
}
@@ -369,11 +429,11 @@ hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
return false;
}
static hb_bool_t
-hb_font_get_glyph_from_name_parent (hb_font_t *font,
- void *font_data HB_UNUSED,
- const char *name, int len, /* -1 means nul-terminated */
- hb_codepoint_t *glyph,
- void *user_data HB_UNUSED)
+hb_font_get_glyph_from_name_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ const char *name, int len, /* -1 means nul-terminated */
+ hb_codepoint_t *glyph,
+ void *user_data HB_UNUSED)
{
return font->parent->get_glyph_from_name (name, len, glyph);
}
@@ -403,7 +463,7 @@ DEFINE_NULL_INSTANCE (hb_font_funcs_t) =
}
};
-static const hb_font_funcs_t _hb_font_funcs_parent = {
+static const hb_font_funcs_t _hb_font_funcs_default = {
HB_OBJECT_HEADER_STATIC,
true, /* immutable */
@@ -420,7 +480,7 @@ static const hb_font_funcs_t _hb_font_funcs_parent = {
},
{
{
-#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_parent,
+#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_default,
HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
#undef HB_FONT_FUNC_IMPLEMENT
}
@@ -445,7 +505,7 @@ hb_font_funcs_create (void)
if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
return hb_font_funcs_get_empty ();
- ffuncs->get = _hb_font_funcs_parent.get;
+ ffuncs->get = _hb_font_funcs_default.get;
return ffuncs;
}
@@ -462,7 +522,7 @@ hb_font_funcs_create (void)
hb_font_funcs_t *
hb_font_funcs_get_empty (void)
{
- return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_parent);
+ return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_default);
}
/**
@@ -601,9 +661,9 @@ hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
ffuncs->user_data.name = user_data; \
ffuncs->destroy.name = destroy; \
} else { \
- ffuncs->get.f.name = hb_font_get_##name##_parent; \
- ffuncs->user_data.name = nullptr; \
- ffuncs->destroy.name = nullptr; \
+ ffuncs->get.f.name = hb_font_get_##name##_default; \
+ ffuncs->user_data.name = nullptr; \
+ ffuncs->destroy.name = nullptr; \
} \
}
@@ -613,9 +673,8 @@ HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
bool
hb_font_t::has_func (unsigned int i)
{
- if (parent && parent != hb_font_get_empty () && parent->has_func (i))
- return true;
- return this->klass->get.array[i] != _hb_font_funcs_parent.get.array[i];
+ return (this->klass->get.array[i] != _hb_font_funcs_default.get.array[i]) ||
+ (parent && parent != &_hb_Null_hb_font_t && parent->has_func (i));
}
/* Public getters */
diff --git a/src/hb-font.h b/src/hb-font.h
index 41e9b0b1..181d15ee 100644
--- a/src/hb-font.h
+++ b/src/hb-font.h
@@ -132,15 +132,15 @@ typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void
typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t;
typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t;
-typedef void (*hb_font_get_glyph_h_advances_func_t)(
- hb_font_t* font,
- void* font_data,
- unsigned count,
- hb_codepoint_t* glyphs,
- unsigned glyph_struct_size,
- hb_position_t* advances,
- unsigned advance_struct_size,
- void* user_data);
+typedef void (*hb_font_get_glyph_advances_func_t) (hb_font_t* font, void* font_data,
+ unsigned count,
+ hb_codepoint_t *first_glyph,
+ unsigned glyph_stride,
+ hb_position_t *first_advance,
+ unsigned advance_stride,
+ void *user_data);
+typedef hb_font_get_glyph_advances_func_t hb_font_get_glyph_h_advances_func_t;
+typedef hb_font_get_glyph_advances_func_t hb_font_get_glyph_v_advances_func_t;
typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *font_data,
hb_codepoint_t glyph,
@@ -258,13 +258,40 @@ hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs,
hb_font_get_glyph_h_advance_func_t func,
void *user_data, hb_destroy_func_t destroy);
+/**
+ * hb_font_funcs_set_glyph_v_advance_func:
+ * @ffuncs: font functions.
+ * @func: (closure user_data) (destroy destroy) (scope notified):
+ * @user_data:
+ * @destroy:
+ *
+ *
+ *
+ * Since: 0.9.2
+ **/
+HB_EXTERN void
+hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs,
+ hb_font_get_glyph_v_advance_func_t func,
+ void *user_data, hb_destroy_func_t destroy);
+
+/**
+ * hb_font_funcs_set_glyph_h_advances_func:
+ * @ffuncs: font functions.
+ * @func: (closure user_data) (destroy destroy) (scope notified):
+ * @user_data:
+ * @destroy:
+ *
+ *
+ *
+ * Since: REPLACEME
+ **/
HB_EXTERN void
hb_font_funcs_set_glyph_h_advances_func (hb_font_funcs_t *ffuncs,
hb_font_get_glyph_h_advances_func_t func,
void *user_data, hb_destroy_func_t destroy);
/**
- * hb_font_funcs_set_glyph_v_advance_func:
+ * hb_font_funcs_set_glyph_v_advances_func:
* @ffuncs: font functions.
* @func: (closure user_data) (destroy destroy) (scope notified):
* @user_data:
@@ -272,11 +299,11 @@ hb_font_funcs_set_glyph_h_advances_func (hb_font_funcs_t *ffuncs,
*
*
*
- * Since: 0.9.2
+ * Since: REPLACEME
**/
HB_EXTERN void
-hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs,
- hb_font_get_glyph_v_advance_func_t func,
+hb_font_funcs_set_glyph_v_advances_func (hb_font_funcs_t *ffuncs,
+ hb_font_get_glyph_v_advances_func_t func,
void *user_data, hb_destroy_func_t destroy);
/**
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index 71b448c1..71632b56 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -691,9 +691,10 @@ hb_ot_position_default (hb_ot_shape_context_t *c)
}
else
{
+ c->font->get_glyph_v_advances (count, &info[0].codepoint, sizeof(info[0]),
+ &pos[0].y_advance, sizeof(pos[0]));
for (unsigned int i = 0; i < count; i++)
{
- pos[i].y_advance = c->font->get_glyph_v_advance (info[i].codepoint);
c->font->subtract_glyph_v_origin (info[i].codepoint,
&pos[i].x_offset,
&pos[i].y_offset);
commit 9533364cc3a8cccbae793de1873a727de73f64d5
Author: Koji Ishii <kojii at chromium.org>
Date: Wed Aug 1 13:01:08 2018 +0900
batchwidth
diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh
index 4950e0bb..81ae4111 100644
--- a/src/hb-font-private.hh
+++ b/src/hb-font-private.hh
@@ -54,6 +54,7 @@
HB_FONT_FUNC_IMPLEMENT (glyph_contour_point) \
HB_FONT_FUNC_IMPLEMENT (glyph_name) \
HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \
+ HB_FONT_FUNC_IMPLEMENT (glyph_h_advances) \
/* ^--- Add new callbacks here */
struct hb_font_funcs_t
@@ -227,6 +228,18 @@ struct hb_font_t
klass->user_data.glyph_h_advance);
}
+ inline void get_glyph_h_advances(unsigned count,
+ hb_codepoint_t* glyphs,
+ unsigned glyph_struct_size,
+ hb_position_t* advances,
+ unsigned advance_struct_size) {
+ return klass->get.f.glyph_h_advances (this, user_data,
+ count,
+ glyphs, glyph_struct_size,
+ advances, advance_struct_size,
+ klass->user_data.glyph_h_advances);
+ }
+
inline hb_position_t get_glyph_v_advance (hb_codepoint_t glyph)
{
return klass->get.f.glyph_v_advance (this, user_data,
diff --git a/src/hb-font.cc b/src/hb-font.cc
index 7d8de6d0..a3f4d1a4 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -143,6 +143,43 @@ hb_font_get_glyph_h_advance_parent (hb_font_t *font,
return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
}
+template <class T>
+T* advance_by_byte_size(T* p, unsigned byte_size) {
+ return reinterpret_cast<T*>(reinterpret_cast<uint8_t*>(p) + byte_size);
+}
+
+static void
+hb_font_get_glyph_h_advances_nil(hb_font_t *font,
+ void *font_data HB_UNUSED,
+ unsigned count,
+ hb_codepoint_t* glyphs,
+ unsigned glyph_struct_size,
+ hb_position_t* advances,
+ unsigned advance_struct_size,
+ void *user_data HB_UNUSED) {
+ for (; count--;
+ glyphs = advance_by_byte_size(glyphs, glyph_struct_size),
+ advances = advance_by_byte_size(advances, advance_struct_size)) {
+ *advances = hb_font_get_glyph_h_advance_nil(font, font_data, *glyphs, user_data);
+ }
+}
+
+static void
+hb_font_get_glyph_h_advances_parent(hb_font_t* font,
+ void* font_data HB_UNUSED,
+ unsigned count,
+ hb_codepoint_t* glyphs,
+ unsigned glyph_struct_size,
+ hb_position_t* advances,
+ unsigned advance_struct_size,
+ void* user_data HB_UNUSED) {
+ for (; count--;
+ glyphs = advance_by_byte_size(glyphs, glyph_struct_size),
+ advances = advance_by_byte_size(advances, advance_struct_size)) {
+ *advances = hb_font_get_glyph_h_advance_parent(font, font_data, *glyphs, user_data);
+ }
+}
+
static hb_position_t
hb_font_get_glyph_v_advance_nil (hb_font_t *font,
void *font_data HB_UNUSED,
diff --git a/src/hb-font.h b/src/hb-font.h
index c95b61d2..41e9b0b1 100644
--- a/src/hb-font.h
+++ b/src/hb-font.h
@@ -132,6 +132,16 @@ typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void
typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t;
typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t;
+typedef void (*hb_font_get_glyph_h_advances_func_t)(
+ hb_font_t* font,
+ void* font_data,
+ unsigned count,
+ hb_codepoint_t* glyphs,
+ unsigned glyph_struct_size,
+ hb_position_t* advances,
+ unsigned advance_struct_size,
+ void* user_data);
+
typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *font_data,
hb_codepoint_t glyph,
hb_position_t *x, hb_position_t *y,
@@ -248,6 +258,11 @@ hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs,
hb_font_get_glyph_h_advance_func_t func,
void *user_data, hb_destroy_func_t destroy);
+HB_EXTERN void
+hb_font_funcs_set_glyph_h_advances_func (hb_font_funcs_t *ffuncs,
+ hb_font_get_glyph_h_advances_func_t func,
+ void *user_data, hb_destroy_func_t destroy);
+
/**
* hb_font_funcs_set_glyph_v_advance_func:
* @ffuncs: font functions.
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index d7f4afea..71b448c1 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -680,8 +680,8 @@ hb_ot_position_default (hb_ot_shape_context_t *c)
if (HB_DIRECTION_IS_HORIZONTAL (direction))
{
- for (unsigned int i = 0; i < count; i++)
- pos[i].x_advance = c->font->get_glyph_h_advance (info[i].codepoint);
+ c->font->get_glyph_h_advances (count, &info[0].codepoint, sizeof(info[0]),
+ &pos[0].x_advance, sizeof(pos[0]));
/* The nil glyph_h_origin() func returns 0, so no need to apply it. */
if (c->font->has_glyph_h_origin_func ())
for (unsigned int i = 0; i < count; i++)
More information about the HarfBuzz
mailing list