diff --git a/src/fontations/lib.rs b/src/fontations/lib.rs index db085903a..045075c9f 100644 --- a/src/fontations/lib.rs +++ b/src/fontations/lib.rs @@ -911,7 +911,7 @@ extern "C" fn _hb_fontations_paint_glyph( palette_index: ::std::os::raw::c_uint, foreground: hb_color_t, _user_data: *mut ::std::os::raw::c_void, -) { +) -> hb_bool_t { let data = unsafe { &mut *(font_data as *mut FontationsData) }; data.check_for_updates(); @@ -921,7 +921,7 @@ extern "C" fn _hb_fontations_paint_glyph( let glyph_id = GlyphId::new(glyph); let Some(color_glyph) = color_glyphs.get(glyph_id) else { - return; + return false as hb_bool_t; }; let cpal = font_ref.cpal(); @@ -976,6 +976,7 @@ extern "C" fn _hb_fontations_paint_glyph( hb_paint_pop_transform(paint_funcs, paint_data); hb_font_destroy(font); } + true as hb_bool_t } extern "C" fn _hb_fontations_glyph_name( diff --git a/src/hb-cairo.cc b/src/hb-cairo.cc index c45b51f3f..f0c8bf7f3 100644 --- a/src/hb-cairo.cc +++ b/src/hb-cairo.cc @@ -644,8 +644,8 @@ 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); - hb_font_paint_glyph (font, glyph, hb_cairo_paint_get_funcs (), &c, palette, color); - + if (!hb_font_paint_glyph (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-font.cc b/src/hb-font.cc index 77fd68e53..c0fd3da98 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -536,7 +536,7 @@ hb_font_draw_glyph_nil (hb_font_t *font HB_UNUSED, { } -static void +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, @@ -546,6 +546,7 @@ hb_font_paint_glyph_nil (hb_font_t *font HB_UNUSED, hb_color_t foreground HB_UNUSED, void *user_data HB_UNUSED) { + return false; } typedef struct hb_font_draw_glyph_default_adaptor_t { @@ -668,7 +669,7 @@ hb_font_draw_glyph_default (hb_font_t *font, false); } -static void +static hb_bool_t hb_font_paint_glyph_default (hb_font_t *font, void *font_data, hb_codepoint_t glyph, @@ -683,9 +684,11 @@ hb_font_paint_glyph_default (hb_font_t *font, 0, font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0, 0, 0); - font->parent->paint_glyph (glyph, paint_funcs, paint_data, palette, foreground); + bool ret = font->parent->paint_glyph (glyph, paint_funcs, paint_data, palette, foreground); paint_funcs->pop_transform (paint_data); + + return ret; } DEFINE_NULL_INSTANCE (hb_font_funcs_t) = @@ -1463,16 +1466,18 @@ hb_font_draw_glyph (hb_font_t *font, * then @palette_index selects the palette to use. If the font only * has one palette, this will be 0. * + * Return value: `true` if glyph was painted, `false` otherwise + * * Since: 7.0.0 */ -void +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) { - font->paint_glyph (glyph, pfuncs, paint_data, palette_index, foreground); + return font->paint_glyph (glyph, pfuncs, paint_data, palette_index, foreground); } /* A bit higher-level, and with fallback */ diff --git a/src/hb-font.h b/src/hb-font.h index 7aaeb4ebd..6e52eba6a 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -517,14 +517,16 @@ typedef void (*hb_font_draw_glyph_func_t) (hb_font_t *font, void *font_data, * * A virtual method for the #hb_font_funcs_t of an #hb_font_t object. * + * Return value: `true` if glyph was painted, `false` otherwise + * * Since: 7.0.0 */ -typedef void (*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_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 */ @@ -901,7 +903,7 @@ hb_font_draw_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_draw_funcs_t *dfuncs, void *draw_data); -HB_EXTERN void +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, diff --git a/src/hb-font.hh b/src/hb-font.hh index c07af9829..047fc0558 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -579,7 +579,7 @@ struct hb_font_t #endif } - void paint_glyph (hb_codepoint_t glyph, + bool paint_glyph (hb_codepoint_t glyph, hb_paint_funcs_t *paint_funcs, void *paint_data, unsigned int palette, hb_color_t foreground, @@ -592,14 +592,16 @@ struct hb_font_t slant_xy, 1.f, 0.f, 0.f); - 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 (this, user_data, + glyph, + paint_funcs, paint_data, + palette, foreground, + !klass->user_data ? nullptr : klass->user_data->paint_glyph); if (synthetic && slant_xy) hb_paint_pop_transform (paint_funcs, paint_data); + + return ret; } /* A bit higher-level, and with fallback */ diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 85d0b0536..a763b90b3 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -929,7 +929,7 @@ hb_ft_draw_glyph (hb_font_t *font, #include "hb-ft-colr.hh" -static void +static hb_bool_t hb_ft_paint_glyph (hb_font_t *font, void *font_data, hb_codepoint_t gid, @@ -953,7 +953,7 @@ hb_ft_paint_glyph (hb_font_t *font, * eg. draw API can call back into the face.*/ if (unlikely (FT_Load_Glyph (ft_face, gid, load_flags))) - return; + return false; if (ft_face->glyph->format == FT_GLYPH_FORMAT_OUTLINE) { @@ -961,26 +961,21 @@ hb_ft_paint_glyph (hb_font_t *font, paint_funcs, paint_data, palette_index, foreground, user_data)) - return; + return true; - /* Simple outline. */ - ft_font->lock.unlock (); - paint_funcs->push_clip_glyph (paint_data, gid, font); - ft_font->lock.lock (); - paint_funcs->color (paint_data, true, foreground); - paint_funcs->pop_clip (paint_data); - - return; + // Outline glyph + return false; } auto *glyph = ft_face->glyph; if (glyph->format == FT_GLYPH_FORMAT_BITMAP) { + bool ret = false; auto &bitmap = glyph->bitmap; if (bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) { if (bitmap.pitch != (signed) bitmap.width * 4) - return; + return ret; ft_font->lock.unlock (); @@ -993,24 +988,23 @@ hb_ft_paint_glyph (hb_font_t *font, if (!font->get_glyph_extents (gid, &extents, false)) goto out; - if (!paint_funcs->image (paint_data, - blob, - bitmap.width, - bitmap.rows, - HB_PAINT_IMAGE_FORMAT_BGRA, - 0.f, - &extents)) - { - /* TODO Try a forced outline load and paint? */ - } + if (paint_funcs->image (paint_data, + blob, + bitmap.width, + bitmap.rows, + HB_PAINT_IMAGE_FORMAT_BGRA, + 0.f, + &extents)) + ret = true; out: hb_blob_destroy (blob); ft_font->lock.lock (); } - return; + return ret; } + return false; } #endif #endif diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index a0b8a83e2..1b7fa13c0 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -513,7 +513,7 @@ hb_ot_draw_glyph (hb_font_t *font, #endif #ifndef HB_NO_PAINT -static void +static hb_bool_t hb_ot_paint_glyph (hb_font_t *font, void *font_data, hb_codepoint_t glyph, @@ -523,18 +523,14 @@ hb_ot_paint_glyph (hb_font_t *font, void *user_data) { #ifndef HB_NO_COLOR - if (font->face->table.COLR->paint_glyph (font, glyph, paint_funcs, paint_data, palette, foreground)) return; - if (font->face->table.SVG->paint_glyph (font, glyph, paint_funcs, paint_data)) return; + if (font->face->table.COLR->paint_glyph (font, glyph, paint_funcs, paint_data, palette, foreground)) return true; + if (font->face->table.SVG->paint_glyph (font, glyph, paint_funcs, paint_data)) return true; #ifndef HB_NO_OT_FONT_BITMAP - if (font->face->table.CBDT->paint_glyph (font, glyph, paint_funcs, paint_data)) return; - if (font->face->table.sbix->paint_glyph (font, glyph, paint_funcs, paint_data)) return; + if (font->face->table.CBDT->paint_glyph (font, glyph, paint_funcs, paint_data)) return true; + if (font->face->table.sbix->paint_glyph (font, glyph, paint_funcs, paint_data)) return true; #endif #endif - - // Outline glyph - paint_funcs->push_clip_glyph (paint_data, glyph, font); - paint_funcs->color (paint_data, true, foreground); - paint_funcs->pop_clip (paint_data); + return false; } #endif diff --git a/test/api/results-paint/test-165 b/test/api/results-paint/test-165 index dd59b78c5..e69de29bb 100644 --- a/test/api/results-paint/test-165 +++ b/test/api/results-paint/test-165 @@ -1,3 +0,0 @@ -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 77ca1eead..e69de29bb 100644 --- a/test/api/results-paint/test-175 +++ b/test/api/results-paint/test-175 @@ -1,3 +0,0 @@ -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 ad5897b56..e69de29bb 100644 --- a/test/api/results-paint/test-6 +++ b/test/api/results-paint/test-6 @@ -1,3 +0,0 @@ -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 dd59b78c5..e69de29bb 100644 --- a/test/api/results-paint/testvf-165 +++ b/test/api/results-paint/testvf-165 @@ -1,3 +0,0 @@ -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 77ca1eead..e69de29bb 100644 --- a/test/api/results-paint/testvf-175 +++ b/test/api/results-paint/testvf-175 @@ -1,3 +0,0 @@ -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 ad5897b56..e69de29bb 100644 --- a/test/api/results-paint/testvf-6 +++ b/test/api/results-paint/testvf-6 @@ -1,3 +0,0 @@ -start clip glyph 6 - solid 0 0 0 255 -end clip