diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt
index bdaf2911c..005974617 100644
--- a/docs/harfbuzz-sections.txt
+++ b/docs/harfbuzz-sections.txt
@@ -338,6 +338,10 @@ hb_font_funcs_set_glyph_v_kerning_func
hb_font_get_glyph_shape
hb_font_get_glyph_shape_func_t
hb_font_funcs_set_glyph_shape_func
+hb_font_draw_glyph_func_t
+hb_font_funcs_set_draw_glyph_func
+hb_font_paint_glyph_func_t
+hb_font_funcs_set_paint_glyph_func
hb_font_get_glyph_v_kerning
hb_font_get_glyph_v_kerning_func_t
HB_AAT_LAYOUT_FEATURE_TYPE_CURISVE_CONNECTION
@@ -444,7 +448,9 @@ hb_font_get_glyph_v_origin
hb_font_get_glyph_origin_for_direction
hb_font_get_glyph_name
hb_font_draw_glyph
+hb_font_draw_glyph_or_fail
hb_font_paint_glyph
+hb_font_paint_glyph_or_fail
hb_font_get_nominal_glyph
hb_font_get_nominal_glyphs
hb_font_get_variation_glyph
@@ -513,10 +519,10 @@ hb_font_get_glyph_v_origin_func_t
hb_font_funcs_set_glyph_v_origin_func
hb_font_get_glyph_name_func_t
hb_font_funcs_set_glyph_name_func
-hb_font_draw_glyph_func_t
-hb_font_funcs_set_draw_glyph_func
-hb_font_paint_glyph_func_t
-hb_font_funcs_set_paint_glyph_func
+hb_font_draw_glyph_or_fail_func_t
+hb_font_funcs_set_draw_glyph_or_fail_func
+hb_font_paint_glyph_or_fail_func_t
+hb_font_funcs_set_paint_glyph_or_fail_func
hb_font_get_nominal_glyph_func_t
hb_font_funcs_set_nominal_glyph_func
hb_font_get_nominal_glyphs_func_t
diff --git a/docs/usermanual-fonts-and-faces.xml b/docs/usermanual-fonts-and-faces.xml
index 39233948b..1287a3508 100644
--- a/docs/usermanual-fonts-and-faces.xml
+++ b/docs/usermanual-fonts-and-faces.xml
@@ -260,13 +260,13 @@
- hb_font_draw_glyph_func_t: gets the outlines
+ hb_font_draw_glyph_or_fail_func_t: gets the outlines
of a glyph (by calling #hb_draw_funcs_t callbacks).
- hb_font_paint_glyph_func_t: paints a glyph
+ hb_font_paint_glyph_or_fail_func_t: paints a glyph
(by calling #hb_paint_funcs_t callbacks).
@@ -507,11 +507,12 @@
access glyph data in this form.
- In the general case, you have to use hb_font_paint_glyph()
+ In the general case, you have to use hb_font_paint_or_fail_glyph()
and pass a hb_paint_funcs_t struct with callbacks to obtain paint
- graphs for glyphs that have them. The hb_font_paint_glyph()
- API can handle outline and image glyphs as well, so it provides a unified API for
- access to glyph rendering information.
+ color glyphs, either graphs or image glyphs.
+ The hb_font_paint_glyph() API is higher level and can handle
+ outline glyphs as well, so it provides a unified API for access to glyph rendering
+ information.
diff --git a/src/hb-cairo.cc b/src/hb-cairo.cc
index f0c8bf7f3..47416c7e5 100644
--- a/src/hb-cairo.cc
+++ b/src/hb-cairo.cc
@@ -644,7 +644,7 @@ hb_cairo_render_color_glyph (cairo_scaled_font_t *scaled_font,
c.cr = cr;
c.color_cache = (hb_map_t *) cairo_scaled_font_get_user_data (scaled_font, &color_cache_key);
- if (!hb_font_paint_glyph (font, glyph, hb_cairo_paint_get_funcs (), &c, palette, color))
+ if (!hb_font_paint_glyph_or_fail (font, glyph, hb_cairo_paint_get_funcs (), &c, palette, color))
return CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED;
return CAIRO_STATUS_SUCCESS;
diff --git a/src/hb-deprecated.h b/src/hb-deprecated.h
index ad19f9a3e..62911bba7 100644
--- a/src/hb-deprecated.h
+++ b/src/hb-deprecated.h
@@ -275,6 +275,48 @@ typedef void (*hb_font_get_glyph_shape_func_t) (hb_font_t *font, void *font_data
hb_draw_funcs_t *draw_funcs, void *draw_data,
void *user_data);
+/**
+ * hb_font_draw_glyph_func_t:
+ * @font: #hb_font_t to work upon
+ * @font_data: @font user data pointer
+ * @glyph: The glyph ID to query
+ * @draw_funcs: The draw functions to send the shape data to
+ * @draw_data: The data accompanying the draw functions
+ * @user_data: User data pointer passed by the caller
+ *
+ * A virtual method for the #hb_font_funcs_t of an #hb_font_t object.
+ *
+ * Since: 7.0.0
+ * XDeprecated: REPLACEME: Use hb_font_draw_glyph_func_or_fail_t instead.
+ **/
+typedef void (*hb_font_draw_glyph_func_t) (hb_font_t *font, void *font_data,
+ hb_codepoint_t glyph,
+ hb_draw_funcs_t *draw_funcs, void *draw_data,
+ void *user_data);
+
+/**
+ * hb_font_paint_glyph_func_t:
+ * @font: #hb_font_t to work upon
+ * @font_data: @font user data pointer
+ * @glyph: The glyph ID to query
+ * @paint_funcs: The paint functions to use
+ * @paint_data: The data accompanying the paint functions
+ * @palette_index: The color palette to use
+ * @foreground: The foreground color
+ * @user_data: User data pointer passed by the caller
+ *
+ * A virtual method for the #hb_font_funcs_t of an #hb_font_t object.
+ *
+ * Since: 7.0.0
+ * XDeprecated: REPLACEME: Use hb_font_paint_glyph_or_fail_func_t instead.
+ */
+typedef hb_bool_t (*hb_font_paint_glyph_func_t) (hb_font_t *font, void *font_data,
+ hb_codepoint_t glyph,
+ hb_paint_funcs_t *paint_funcs, void *paint_data,
+ unsigned int palette_index,
+ hb_color_t foreground,
+ void *user_data);
+
/**
* hb_font_funcs_set_glyph_shape_func:
* @ffuncs: A font-function structure
@@ -288,13 +330,49 @@ typedef void (*hb_font_get_glyph_shape_func_t) (hb_font_t *font, void *font_data
* Since: 4.0.0
* Deprecated: 7.0.0: Use hb_font_funcs_set_draw_glyph_func() instead
**/
-HB_DEPRECATED_FOR (hb_font_funcs_set_draw_glyph_func)
+HB_DEPRECATED_FOR (hb_font_funcs_set_draw_glyph_or_fail_func)
HB_EXTERN void
hb_font_funcs_set_glyph_shape_func (hb_font_funcs_t *ffuncs,
hb_font_get_glyph_shape_func_t func,
void *user_data, hb_destroy_func_t destroy);
-HB_DEPRECATED_FOR (hb_font_draw_glyph)
+/**
+ * hb_font_funcs_set_draw_glyph_func:
+ * @ffuncs: A font-function structure
+ * @func: (closure user_data) (destroy destroy) (scope notified): The callback function to assign
+ * @user_data: Data to pass to @func
+ * @destroy: (nullable): The function to call when @user_data is not needed anymore
+ *
+ * Sets the implementation function for #hb_font_draw_glyph_func_t.
+ *
+ * Since: 7.0.0
+ * XDeprecated: REPLACEME: Use hb_font_funcs_set_draw_glyph_or_fail_func instead.
+ **/
+HB_DEPRECATED_FOR (hb_font_funcs_set_draw_glyph_or_fail_func)
+HB_EXTERN void
+hb_font_funcs_set_draw_glyph_func (hb_font_funcs_t *ffuncs,
+ hb_font_draw_glyph_func_t func,
+ void *user_data, hb_destroy_func_t destroy);
+
+/**
+ * hb_font_funcs_set_paint_glyph_func:
+ * @ffuncs: A font-function structure
+ * @func: (closure user_data) (destroy destroy) (scope notified): The callback function to assign
+ * @user_data: Data to pass to @func
+ * @destroy: (nullable): The function to call when @user_data is no longer needed
+ *
+ * Sets the implementation function for #hb_font_paint_glyph_func_t.
+ *
+ * Since: 7.0.0
+ * XDeprecated: REPLACEME: Use hb_font_funcs_set_paint_glyph_or_fail_func() instead.
+ */
+HB_DEPRECATED_FOR (hb_font_funcs_set_paint_glyph_or_fail_func)
+HB_EXTERN void
+hb_font_funcs_set_paint_glyph_func (hb_font_funcs_t *ffuncs,
+ hb_font_paint_glyph_func_t func,
+ void *user_data, hb_destroy_func_t destroy);
+
+HB_DEPRECATED_FOR (hb_font_draw_glyph_or_fail)
HB_EXTERN void
hb_font_get_glyph_shape (hb_font_t *font,
hb_codepoint_t glyph,
diff --git a/src/hb-font.cc b/src/hb-font.cc
index c0fd3da98..3a2b645b6 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -526,25 +526,26 @@ hb_font_get_glyph_from_name_default (hb_font_t *font,
return font->parent->get_glyph_from_name (name, len, glyph);
}
-static void
-hb_font_draw_glyph_nil (hb_font_t *font HB_UNUSED,
- void *font_data HB_UNUSED,
- hb_codepoint_t glyph,
- hb_draw_funcs_t *draw_funcs,
- void *draw_data,
- void *user_data HB_UNUSED)
+static hb_bool_t
+hb_font_draw_glyph_or_fail_nil (hb_font_t *font HB_UNUSED,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t glyph,
+ hb_draw_funcs_t *draw_funcs,
+ void *draw_data,
+ void *user_data HB_UNUSED)
{
+ return false;
}
static hb_bool_t
-hb_font_paint_glyph_nil (hb_font_t *font HB_UNUSED,
- void *font_data HB_UNUSED,
- hb_codepoint_t glyph HB_UNUSED,
- hb_paint_funcs_t *paint_funcs HB_UNUSED,
- void *paint_data HB_UNUSED,
- unsigned int palette HB_UNUSED,
- hb_color_t foreground HB_UNUSED,
- void *user_data HB_UNUSED)
+hb_font_paint_glyph_or_fail_nil (hb_font_t *font HB_UNUSED,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t glyph HB_UNUSED,
+ hb_paint_funcs_t *paint_funcs HB_UNUSED,
+ void *paint_data HB_UNUSED,
+ unsigned int palette HB_UNUSED,
+ hb_color_t foreground HB_UNUSED,
+ void *user_data HB_UNUSED)
{
return false;
}
@@ -648,13 +649,13 @@ static const hb_draw_funcs_t _hb_draw_funcs_default = {
}
};
-static void
-hb_font_draw_glyph_default (hb_font_t *font,
- void *font_data HB_UNUSED,
- hb_codepoint_t glyph,
- hb_draw_funcs_t *draw_funcs,
- void *draw_data,
- void *user_data HB_UNUSED)
+static hb_bool_t
+hb_font_draw_glyph_or_fail_default (hb_font_t *font,
+ void *font_data HB_UNUSED,
+ hb_codepoint_t glyph,
+ hb_draw_funcs_t *draw_funcs,
+ void *draw_data,
+ void *user_data HB_UNUSED)
{
hb_font_draw_glyph_default_adaptor_t adaptor = {
draw_funcs,
@@ -663,28 +664,28 @@ hb_font_draw_glyph_default (hb_font_t *font,
font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0.f
};
- font->parent->draw_glyph (glyph,
- const_cast (&_hb_draw_funcs_default),
- &adaptor,
- false);
+ return font->parent->draw_glyph_or_fail (glyph,
+ const_cast (&_hb_draw_funcs_default),
+ &adaptor,
+ false);
}
static hb_bool_t
-hb_font_paint_glyph_default (hb_font_t *font,
- void *font_data,
- hb_codepoint_t glyph,
- hb_paint_funcs_t *paint_funcs,
- void *paint_data,
- unsigned int palette,
- hb_color_t foreground,
- void *user_data)
+hb_font_paint_glyph_or_fail_default (hb_font_t *font,
+ void *font_data,
+ hb_codepoint_t glyph,
+ hb_paint_funcs_t *paint_funcs,
+ void *paint_data,
+ unsigned int palette,
+ hb_color_t foreground,
+ void *user_data)
{
paint_funcs->push_transform (paint_data,
font->parent->x_scale ? (float) font->x_scale / (float) font->parent->x_scale : 0, 0,
0, font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0,
0, 0);
- bool ret = font->parent->paint_glyph (glyph, paint_funcs, paint_data, palette, foreground);
+ bool ret = font->parent->paint_glyph_or_fail (glyph, paint_funcs, paint_data, palette, foreground);
paint_funcs->pop_transform (paint_data);
@@ -1426,7 +1427,7 @@ hb_font_get_glyph_shape (hb_font_t *font,
#endif
/**
- * hb_font_draw_glyph:
+ * hb_font_draw_glyph_or_fail:
* @font: #hb_font_t to work upon
* @glyph: The glyph ID
* @dfuncs: #hb_draw_funcs_t to draw to
@@ -1434,21 +1435,26 @@ hb_font_get_glyph_shape (hb_font_t *font,
*
* Draws the outline that corresponds to a glyph in the specified @font.
*
+ * This is a newer name for hb_font_draw_glyph(), that returns `false`
+ * if the font has no outlines for the glyph.
+ *
* The outline is returned by way of calls to the callbacks of the @dfuncs
* objects, with @draw_data passed to them.
*
- * Since: 7.0.0
+ * Return value: `true` if glyph was drawn, `false` otherwise
+ *
+ * XSince: REPLACEME
**/
-void
-hb_font_draw_glyph (hb_font_t *font,
- hb_codepoint_t glyph,
- hb_draw_funcs_t *dfuncs, void *draw_data)
+hb_bool_t
+hb_font_draw_glyph_or_fail (hb_font_t *font,
+ hb_codepoint_t glyph,
+ hb_draw_funcs_t *dfuncs, void *draw_data)
{
- font->draw_glyph (glyph, dfuncs, draw_data);
+ return font->draw_glyph_or_fail (glyph, dfuncs, draw_data);
}
/**
- * hb_font_paint_glyph:
+ * hb_font_paint_glyph_or_fail:
* @font: #hb_font_t to work upon
* @glyph: The glyph ID
* @pfuncs: #hb_paint_funcs_t to paint with
@@ -1456,7 +1462,13 @@ hb_font_draw_glyph (hb_font_t *font,
* @palette_index: The index of the font's color palette to use
* @foreground: The foreground color, unpremultipled
*
- * Paints the glyph.
+ * Paints a color glyph.
+ *
+ * This function is similar to, but lower-level than,
+ * hb_font_paint_glyph(). It is suitable for clients that
+ * need more control. If there are no color glyphs available,
+ * it will return `false`. The client can then fall back to
+ * hb_font_draw_glyph_or_fail() for the monochrome outline glyph.
*
* The painting instructions are returned by way of calls to
* the callbacks of the @funcs object, with @paint_data passed
@@ -1468,20 +1480,97 @@ hb_font_draw_glyph (hb_font_t *font,
*
* Return value: `true` if glyph was painted, `false` otherwise
*
- * Since: 7.0.0
+ * XSince: REPLACEME
*/
hb_bool_t
+hb_font_paint_glyph_or_fail (hb_font_t *font,
+ hb_codepoint_t glyph,
+ hb_paint_funcs_t *pfuncs, void *paint_data,
+ unsigned int palette_index,
+ hb_color_t foreground)
+{
+ return font->paint_glyph_or_fail (glyph, pfuncs, paint_data, palette_index, foreground);
+}
+
+/* A bit higher-level, and with fallback */
+
+void
+hb_font_t::paint_glyph (hb_codepoint_t glyph,
+ hb_paint_funcs_t *paint_funcs, void *paint_data,
+ unsigned int palette,
+ hb_color_t foreground)
+{
+ if (paint_glyph_or_fail (glyph,
+ paint_funcs, paint_data,
+ palette, foreground))
+ return;
+
+ /* Fallback for outline glyph. */
+ paint_funcs->push_clip_glyph (paint_data, glyph, this);
+ paint_funcs->color (paint_data, true, foreground);
+ paint_funcs->pop_clip (paint_data);
+}
+
+
+/**
+ * hb_font_draw_glyph:
+ * @font: #hb_font_t to work upon
+ * @glyph: The glyph ID
+ * @dfuncs: #hb_draw_funcs_t to draw to
+ * @draw_data: User data to pass to draw callbacks
+ *
+ * Draws the outline that corresponds to a glyph in the specified @font.
+ *
+ * This is an older name for hb_font_draw_glyph_or_fail(), with no
+ * return value.
+ *
+ * The outline is returned by way of calls to the callbacks of the @dfuncs
+ * objects, with @draw_data passed to them.
+ *
+ * Since: 7.0.0
+ **/
+void
+hb_font_draw_glyph (hb_font_t *font,
+ hb_codepoint_t glyph,
+ hb_draw_funcs_t *dfuncs, void *draw_data)
+{
+ (void) hb_font_draw_glyph_or_fail (font, glyph, dfuncs, draw_data);
+}
+
+/**
+ * hb_font_paint_glyph:
+ * @font: #hb_font_t to work upon
+ * @glyph: The glyph ID
+ * @pfuncs: #hb_paint_funcs_t to paint with
+ * @paint_data: User data to pass to paint callbacks
+ * @palette_index: The index of the font's color palette to use
+ * @foreground: The foreground color, unpremultipled
+ *
+ * Paints the glyph. This function is similar to
+ * hb_font_paint_glyph_or_fail(), but if painting a color glyph
+ * failed, it will fall back to painting an outline monochrome
+ * glyph.
+ *
+ * The painting instructions are returned by way of calls to
+ * the callbacks of the @funcs object, with @paint_data passed
+ * to them.
+ *
+ * If the font has color palettes (see hb_ot_color_has_palettes()),
+ * then @palette_index selects the palette to use. If the font only
+ * has one palette, this will be 0.
+ *
+ * Since: 7.0.0
+ */
+void
hb_font_paint_glyph (hb_font_t *font,
hb_codepoint_t glyph,
hb_paint_funcs_t *pfuncs, void *paint_data,
unsigned int palette_index,
hb_color_t foreground)
{
- return font->paint_glyph (glyph, pfuncs, paint_data, palette_index, foreground);
+ font->paint_glyph (glyph, pfuncs, paint_data, palette_index, foreground);
}
-/* A bit higher-level, and with fallback */
-
/**
* hb_font_get_extents_for_direction:
* @font: #hb_font_t to work upon
@@ -2640,7 +2729,7 @@ hb_font_is_synthetic (hb_font_t *font)
* points of the glyph shape.
*
* Synthetic boldness is applied when rendering a glyph via
- * hb_font_draw_glyph().
+ * hb_font_draw_glyph_or_fail().
*
* If @in_place is `false`, then glyph advance-widths are also
* adjusted, otherwise they are not. The in-place mode is
@@ -2704,7 +2793,7 @@ hb_font_get_synthetic_bold (hb_font_t *font,
* HarfBuzz needs to know this value to adjust shaping results,
* metrics, and style values to match the slanted rendering.
*
- * Note: The glyph shape fetched via the hb_font_draw_glyph()
+ * Note: The glyph shape fetched via the hb_font_draw_glyph_or_fail()
* function is slanted to reflect this value as well.
*
* Note: The slant value is a ratio. For example, a
@@ -3210,12 +3299,134 @@ hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
#ifndef HB_DISABLE_DEPRECATED
+
+struct hb_draw_glyph_closure_t
+{
+ hb_font_draw_glyph_func_t func;
+ void *user_data;
+ hb_destroy_func_t destroy;
+};
+static hb_bool_t
+hb_font_draw_glyph_trampoline (hb_font_t *font,
+ void *font_data,
+ hb_codepoint_t glyph,
+ hb_draw_funcs_t *draw_funcs,
+ void *draw_data,
+ void *user_data)
+{
+ hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) user_data;
+ closure->func (font, font_data, glyph, draw_funcs, draw_data, closure->user_data);
+ return true;
+}
+static void
+hb_font_draw_glyph_closure_destroy (void *user_data)
+{
+ hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) user_data;
+
+ if (closure->destroy)
+ closure->destroy (closure->user_data);
+ hb_free (closure);
+}
+static void
+_hb_font_funcs_set_draw_glyph_func (hb_font_funcs_t *ffuncs,
+ hb_font_draw_glyph_func_t func,
+ void *user_data,
+ hb_destroy_func_t destroy /* May be NULL. */)
+{
+ if (hb_object_is_immutable (ffuncs))
+ {
+ if (destroy)
+ destroy (user_data);
+ return;
+ }
+ hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) hb_calloc (1, sizeof (hb_draw_glyph_closure_t));
+ if (unlikely (!closure))
+ {
+ if (destroy)
+ destroy (user_data);
+ return;
+ }
+ closure->func = func;
+ closure->user_data = user_data;
+ closure->destroy = destroy;
+
+ hb_font_funcs_set_draw_glyph_or_fail_func (ffuncs,
+ hb_font_draw_glyph_trampoline,
+ closure,
+ hb_font_draw_glyph_closure_destroy);
+}
+void
+hb_font_funcs_set_draw_glyph_func (hb_font_funcs_t *ffuncs,
+ hb_font_draw_glyph_func_t func,
+ void *user_data,
+ hb_destroy_func_t destroy /* May be NULL. */)
+{
+ _hb_font_funcs_set_draw_glyph_func (ffuncs, func, user_data, destroy);
+}
void
hb_font_funcs_set_glyph_shape_func (hb_font_funcs_t *ffuncs,
hb_font_get_glyph_shape_func_t func,
void *user_data,
hb_destroy_func_t destroy /* May be NULL. */)
{
- hb_font_funcs_set_draw_glyph_func (ffuncs, func, user_data, destroy);
+ _hb_font_funcs_set_draw_glyph_func (ffuncs, func, user_data, destroy);
+}
+
+struct hb_paint_glyph_closure_t
+{
+ hb_font_paint_glyph_func_t func;
+ void *user_data;
+ hb_destroy_func_t destroy;
+};
+static hb_bool_t
+hb_font_paint_glyph_trampoline (hb_font_t *font,
+ void *font_data,
+ hb_codepoint_t glyph,
+ hb_paint_funcs_t *paint_funcs,
+ void *paint_data,
+ unsigned int palette,
+ hb_color_t foreground,
+ void *user_data)
+{
+ hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) user_data;
+ closure->func (font, font_data, glyph, paint_funcs, paint_data, palette, foreground, closure->user_data);
+ return true;
+}
+static void
+hb_font_paint_glyph_closure_destroy (void *user_data)
+{
+ hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) user_data;
+
+ if (closure->destroy)
+ closure->destroy (closure->user_data);
+ hb_free (closure);
+}
+void
+hb_font_funcs_set_paint_glyph_func (hb_font_funcs_t *ffuncs,
+ hb_font_paint_glyph_func_t func,
+ void *user_data,
+ hb_destroy_func_t destroy /* May be NULL. */)
+{
+ if (hb_object_is_immutable (ffuncs))
+ {
+ if (destroy)
+ destroy (user_data);
+ return;
+ }
+ hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) hb_calloc (1, sizeof (hb_paint_glyph_closure_t));
+ if (unlikely (!closure))
+ {
+ if (destroy)
+ destroy (user_data);
+ return;
+ }
+ closure->func = func;
+ closure->user_data = user_data;
+ closure->destroy = destroy;
+
+ hb_font_funcs_set_paint_glyph_or_fail_func (ffuncs,
+ hb_font_paint_glyph_trampoline,
+ closure,
+ hb_font_paint_glyph_closure_destroy);
}
#endif
diff --git a/src/hb-font.h b/src/hb-font.h
index 6e52eba6a..77178bf84 100644
--- a/src/hb-font.h
+++ b/src/hb-font.h
@@ -486,7 +486,7 @@ typedef hb_bool_t (*hb_font_get_glyph_from_name_func_t) (hb_font_t *font, void *
void *user_data);
/**
- * hb_font_draw_glyph_func_t:
+ * hb_font_draw_glyph_or_fail_func_t:
* @font: #hb_font_t to work upon
* @font_data: @font user data pointer
* @glyph: The glyph ID to query
@@ -496,16 +496,17 @@ typedef hb_bool_t (*hb_font_get_glyph_from_name_func_t) (hb_font_t *font, void *
*
* A virtual method for the #hb_font_funcs_t of an #hb_font_t object.
*
- * Since: 7.0.0
+ * Return value: `true` if glyph was drawn, `false` otherwise
*
+ * XSince: REPLACEME
**/
-typedef void (*hb_font_draw_glyph_func_t) (hb_font_t *font, void *font_data,
- hb_codepoint_t glyph,
- hb_draw_funcs_t *draw_funcs, void *draw_data,
- void *user_data);
+typedef hb_bool_t (*hb_font_draw_glyph_or_fail_func_t) (hb_font_t *font, void *font_data,
+ hb_codepoint_t glyph,
+ hb_draw_funcs_t *draw_funcs, void *draw_data,
+ void *user_data);
/**
- * hb_font_paint_glyph_func_t:
+ * hb_font_paint_glyph_or_fail_func_t:
* @font: #hb_font_t to work upon
* @font_data: @font user data pointer
* @glyph: The glyph ID to query
@@ -519,14 +520,14 @@ typedef void (*hb_font_draw_glyph_func_t) (hb_font_t *font, void *font_data,
*
* Return value: `true` if glyph was painted, `false` otherwise
*
- * Since: 7.0.0
+ * XSince: REPLACEME
*/
-typedef hb_bool_t (*hb_font_paint_glyph_func_t) (hb_font_t *font, void *font_data,
- hb_codepoint_t glyph,
- hb_paint_funcs_t *paint_funcs, void *paint_data,
- unsigned int palette_index,
- hb_color_t foreground,
- void *user_data);
+typedef hb_bool_t (*hb_font_paint_glyph_or_fail_func_t) (hb_font_t *font, void *font_data,
+ hb_codepoint_t glyph,
+ hb_paint_funcs_t *paint_funcs, void *paint_data,
+ unsigned int palette_index,
+ hb_color_t foreground,
+ void *user_data);
/* func setters */
@@ -787,36 +788,36 @@ hb_font_funcs_set_glyph_from_name_func (hb_font_funcs_t *ffuncs,
void *user_data, hb_destroy_func_t destroy);
/**
- * hb_font_funcs_set_draw_glyph_func:
+ * hb_font_funcs_set_draw_glyph_or_fail_func:
* @ffuncs: A font-function structure
* @func: (closure user_data) (destroy destroy) (scope notified): The callback function to assign
* @user_data: Data to pass to @func
* @destroy: (nullable): The function to call when @user_data is not needed anymore
*
- * Sets the implementation function for #hb_font_draw_glyph_func_t.
+ * Sets the implementation function for #hb_font_draw_glyph_or_fail_func_t.
*
- * Since: 7.0.0
+ * XSince: REPLACEME
**/
HB_EXTERN void
-hb_font_funcs_set_draw_glyph_func (hb_font_funcs_t *ffuncs,
- hb_font_draw_glyph_func_t func,
- void *user_data, hb_destroy_func_t destroy);
+hb_font_funcs_set_draw_glyph_or_fail_func (hb_font_funcs_t *ffuncs,
+ hb_font_draw_glyph_or_fail_func_t func,
+ void *user_data, hb_destroy_func_t destroy);
/**
- * hb_font_funcs_set_paint_glyph_func:
+ * hb_font_funcs_set_paint_glyph_or_fail_func:
* @ffuncs: A font-function structure
* @func: (closure user_data) (destroy destroy) (scope notified): The callback function to assign
* @user_data: Data to pass to @func
* @destroy: (nullable): The function to call when @user_data is no longer needed
*
- * Sets the implementation function for #hb_font_paint_glyph_func_t.
+ * Sets the implementation function for #hb_font_paint_glyph_or_fail_func_t.
*
- * Since: 7.0.0
+ * XSince: REPLACEME
*/
HB_EXTERN void
-hb_font_funcs_set_paint_glyph_func (hb_font_funcs_t *ffuncs,
- hb_font_paint_glyph_func_t func,
- void *user_data, hb_destroy_func_t destroy);
+hb_font_funcs_set_paint_glyph_or_fail_func (hb_font_funcs_t *ffuncs,
+ hb_font_paint_glyph_or_fail_func_t func,
+ void *user_data, hb_destroy_func_t destroy);
/* func dispatch */
@@ -898,17 +899,17 @@ hb_font_get_glyph_from_name (hb_font_t *font,
const char *name, int len, /* -1 means nul-terminated */
hb_codepoint_t *glyph);
-HB_EXTERN void
-hb_font_draw_glyph (hb_font_t *font,
- hb_codepoint_t glyph,
- hb_draw_funcs_t *dfuncs, void *draw_data);
+HB_EXTERN hb_bool_t
+hb_font_draw_glyph_or_fail (hb_font_t *font,
+ hb_codepoint_t glyph,
+ hb_draw_funcs_t *dfuncs, void *draw_data);
HB_EXTERN hb_bool_t
-hb_font_paint_glyph (hb_font_t *font,
- hb_codepoint_t glyph,
- hb_paint_funcs_t *pfuncs, void *paint_data,
- unsigned int palette_index,
- hb_color_t foreground);
+hb_font_paint_glyph_or_fail (hb_font_t *font,
+ hb_codepoint_t glyph,
+ hb_paint_funcs_t *pfuncs, void *paint_data,
+ unsigned int palette_index,
+ hb_color_t foreground);
/* high-level funcs, with fallback */
@@ -981,6 +982,19 @@ hb_font_glyph_from_string (hb_font_t *font,
const char *s, int len, /* -1 means nul-terminated */
hb_codepoint_t *glyph);
+/* Older alias for hb_font_draw_glyph_or_fail() with no return value. */
+HB_EXTERN void
+hb_font_draw_glyph (hb_font_t *font,
+ hb_codepoint_t glyph,
+ hb_draw_funcs_t *dfuncs, void *draw_data);
+
+/* Paints color glyph; if failed, draws outline glyph. */
+HB_EXTERN void
+hb_font_paint_glyph (hb_font_t *font,
+ hb_codepoint_t glyph,
+ hb_paint_funcs_t *pfuncs, void *paint_data,
+ unsigned int palette_index,
+ hb_color_t foreground);
/*
* hb_font_t
diff --git a/src/hb-font.hh b/src/hb-font.hh
index 7ab3b91d6..ef392885d 100644
--- a/src/hb-font.hh
+++ b/src/hb-font.hh
@@ -61,8 +61,8 @@
HB_FONT_FUNC_IMPLEMENT (get_,glyph_contour_point) \
HB_FONT_FUNC_IMPLEMENT (get_,glyph_name) \
HB_FONT_FUNC_IMPLEMENT (get_,glyph_from_name) \
- HB_FONT_FUNC_IMPLEMENT (,draw_glyph) \
- HB_FONT_FUNC_IMPLEMENT (,paint_glyph) \
+ HB_FONT_FUNC_IMPLEMENT (,draw_glyph_or_fail) \
+ HB_FONT_FUNC_IMPLEMENT (,paint_glyph_or_fail) \
/* ^--- Add new callbacks here */
struct hb_font_funcs_t
@@ -493,18 +493,17 @@ struct hb_font_t
* and apply synthetic settings in the last case. */
hb_paint_extents_context_t paint_extents;
- if (paint_glyph (glyph,
- hb_paint_extents_get_funcs (), &paint_extents,
- 0, 0))
+ if (paint_glyph_or_fail (glyph,
+ hb_paint_extents_get_funcs (), &paint_extents,
+ 0, 0))
{
*extents = paint_extents.get_extents ().to_glyph_extents ();
return true;
}
hb_extents_t draw_extents;
- draw_glyph (glyph,
- hb_draw_extents_get_funcs (), &draw_extents);
- if (!draw_extents.is_empty ())
+ if (draw_glyph_or_fail (glyph,
+ hb_draw_extents_get_funcs (), &draw_extents))
{
*extents = draw_extents.to_glyph_extents ();
return true;
@@ -568,9 +567,9 @@ struct hb_font_t
!klass->user_data ? nullptr : klass->user_data->glyph_from_name);
}
- void draw_glyph (hb_codepoint_t glyph,
- hb_draw_funcs_t *draw_funcs, void *draw_data,
- bool synthetic = true)
+ bool draw_glyph_or_fail (hb_codepoint_t glyph,
+ hb_draw_funcs_t *draw_funcs, void *draw_data,
+ bool synthetic = true)
{
#ifndef HB_NO_OUTLINE
bool embolden = x_strength || y_strength;
@@ -582,20 +581,20 @@ struct hb_font_t
if (!synthetic)
{
- klass->get.f.draw_glyph (this, user_data,
- glyph,
- draw_funcs, draw_data,
- !klass->user_data ? nullptr : klass->user_data->draw_glyph);
- return;
+ return klass->get.f.draw_glyph_or_fail (this, user_data,
+ glyph,
+ draw_funcs, draw_data,
+ !klass->user_data ? nullptr : klass->user_data->draw_glyph_or_fail);
}
#ifndef HB_NO_OUTLINE
hb_outline_t outline;
- klass->get.f.draw_glyph (this, user_data,
- glyph,
- hb_outline_recording_pen_get_funcs (), &outline,
- !klass->user_data ? nullptr : klass->user_data->draw_glyph);
+ if (!klass->get.f.draw_glyph_or_fail (this, user_data,
+ glyph,
+ hb_outline_recording_pen_get_funcs (), &outline,
+ !klass->user_data ? nullptr : klass->user_data->draw_glyph_or_fail))
+ return false;
// Slant before embolden; produces nicer results.
@@ -612,14 +611,16 @@ struct hb_font_t
}
outline.replay (draw_funcs, draw_data);
+
+ return true;
#endif
}
- bool paint_glyph (hb_codepoint_t glyph,
- hb_paint_funcs_t *paint_funcs, void *paint_data,
- unsigned int palette,
- hb_color_t foreground,
- bool synthetic = true)
+ bool paint_glyph_or_fail (hb_codepoint_t glyph,
+ hb_paint_funcs_t *paint_funcs, void *paint_data,
+ unsigned int palette,
+ hb_color_t foreground,
+ bool synthetic = true)
{
/* Slant */
if (synthetic && slant_xy)
@@ -628,11 +629,11 @@ struct hb_font_t
slant_xy, 1.f,
0.f, 0.f);
- bool ret = klass->get.f.paint_glyph (this, user_data,
- glyph,
- paint_funcs, paint_data,
- palette, foreground,
- !klass->user_data ? nullptr : klass->user_data->paint_glyph);
+ bool ret = klass->get.f.paint_glyph_or_fail (this, user_data,
+ glyph,
+ paint_funcs, paint_data,
+ palette, foreground,
+ !klass->user_data ? nullptr : klass->user_data->paint_glyph_or_fail);
if (synthetic && slant_xy)
hb_paint_pop_transform (paint_funcs, paint_data);
@@ -642,6 +643,12 @@ struct hb_font_t
/* A bit higher-level, and with fallback */
+ HB_INTERNAL
+ void paint_glyph (hb_codepoint_t glyph,
+ hb_paint_funcs_t *paint_funcs, void *paint_data,
+ unsigned int palette,
+ hb_color_t foreground);
+
void get_h_extents_with_fallback (hb_font_extents_t *extents)
{
if (!get_font_h_extents (extents))
diff --git a/src/hb-ot-var.cc b/src/hb-ot-var.cc
index f000f2726..45424f799 100644
--- a/src/hb-ot-var.cc
+++ b/src/hb-ot-var.cc
@@ -117,7 +117,7 @@ hb_ot_var_get_axes (hb_face_t *face,
* in the specified face.
*
* Since: 1.4.2
- * Deprecated: 2.2.0 - use hb_ot_var_find_axis_info() instead
+ * Deprecated: 2.2.0: use hb_ot_var_find_axis_info() instead
**/
hb_bool_t
hb_ot_var_find_axis (hb_face_t *face,
diff --git a/test/api/results-paint/test-165 b/test/api/results-paint/test-165
index e69de29bb..dd59b78c5 100644
--- a/test/api/results-paint/test-165
+++ b/test/api/results-paint/test-165
@@ -0,0 +1,3 @@
+start clip glyph 165
+ solid 0 0 0 255
+end clip
diff --git a/test/api/results-paint/test-175 b/test/api/results-paint/test-175
index e69de29bb..77ca1eead 100644
--- a/test/api/results-paint/test-175
+++ b/test/api/results-paint/test-175
@@ -0,0 +1,3 @@
+start clip glyph 175
+ solid 0 0 0 255
+end clip
diff --git a/test/api/results-paint/test-6 b/test/api/results-paint/test-6
index e69de29bb..ad5897b56 100644
--- a/test/api/results-paint/test-6
+++ b/test/api/results-paint/test-6
@@ -0,0 +1,3 @@
+start clip glyph 6
+ solid 0 0 0 255
+end clip
diff --git a/test/api/results-paint/testvf-165 b/test/api/results-paint/testvf-165
index e69de29bb..dd59b78c5 100644
--- a/test/api/results-paint/testvf-165
+++ b/test/api/results-paint/testvf-165
@@ -0,0 +1,3 @@
+start clip glyph 165
+ solid 0 0 0 255
+end clip
diff --git a/test/api/results-paint/testvf-175 b/test/api/results-paint/testvf-175
index e69de29bb..77ca1eead 100644
--- a/test/api/results-paint/testvf-175
+++ b/test/api/results-paint/testvf-175
@@ -0,0 +1,3 @@
+start clip glyph 175
+ solid 0 0 0 255
+end clip
diff --git a/test/api/results-paint/testvf-6 b/test/api/results-paint/testvf-6
index e69de29bb..ad5897b56 100644
--- a/test/api/results-paint/testvf-6
+++ b/test/api/results-paint/testvf-6
@@ -0,0 +1,3 @@
+start clip glyph 6
+ solid 0 0 0 255
+end clip