[paint] Change return type to bool, and return false for outline glyphs

It was impossible to get synthetic bold/slant correctly with the
previous API. This is a minor API break, but one I'm willing to take.
This commit is contained in:
Behdad Esfahbod committed 2025-04-23 01:02:15 -06:00
1 parent a23021e168
commit e78310bfaa
13 files changed
+55 -73

No files matched your search

+3 -2
View File
@@ -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(
+2 -2
View File
@@ -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;
}
+10 -5
View File
@@ -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 */
+9 -7
View File
@@ -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,
+8 -6
View File
@@ -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 */
+17 -23
View File
@@ -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
+6 -10
View File
@@ -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
-3
View File
@@ -1,3 +0,0 @@
start clip glyph 165
solid 0 0 0 255
end clip
-3
View File
@@ -1,3 +0,0 @@
start clip glyph 175
solid 0 0 0 255
end clip
-3
View File
@@ -1,3 +0,0 @@
start clip glyph 6
solid 0 0 0 255
end clip
-3
View File
@@ -1,3 +0,0 @@
start clip glyph 165
solid 0 0 0 255
end clip
-3
View File
@@ -1,3 +0,0 @@
start clip glyph 175
solid 0 0 0 255
end clip
-3
View File
@@ -1,3 +0,0 @@
start clip glyph 6
solid 0 0 0 255
end clip