Add vector paint glyph convenience API and auto-extents

This commit is contained in:
Behdad Esfahbod committed 2026-02-24 09:19:04 -03:00
1 parent f108e8b349
commit 344c12ca15
5 files changed
+64 -12

No files matched your search

+14 -4
View File
@@ -1968,10 +1968,20 @@ hb_raster_paint_glyph (hb_raster_paint_t *paint,
float dx = paint->base_transform.x0;
float dy = paint->base_transform.y0;
hb_raster_paint_set_transform (paint,
xx, yx, xy, yy,
dx + xx * pen_x + xy * pen_y,
dy + yx * pen_x + yy * pen_y);
float tx = dx + xx * pen_x + xy * pen_y;
float ty = dy + yx * pen_x + yy * pen_y;
if (!paint->has_extents)
{
hb_glyph_extents_t ge;
if (hb_font_get_glyph_extents (font, glyph, &ge))
{
hb_raster_paint_set_transform (paint, xx, yx, xy, yy, tx, ty);
hb_raster_paint_set_glyph_extents (paint, &ge);
}
}
hb_raster_paint_set_transform (paint, xx, yx, xy, yy, tx, ty);
hb_bool_t ret = hb_font_paint_glyph_or_fail (font, glyph,
hb_raster_paint_get_funcs (), paint,
palette, foreground);
+4 -4
View File
@@ -41,9 +41,9 @@
* ```
* hb_raster_draw_t *draw = hb_raster_draw_create_or_fail ();
* hb_raster_draw_set_scale_factor (draw, 64.f, 64.f);
* hb_raster_draw_set_transform (draw, 1.f, 0.f, 0.f, 1.f, pen_x, pen_y);
* hb_raster_draw_set_transform (draw, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f);
* hb_raster_draw_set_glyph_extents (draw, &glyph_extents);
* hb_font_draw_glyph (font, gid, hb_raster_draw_get_funcs (), draw);
* hb_raster_draw_glyph (draw, font, gid, pen_x, pen_y);
* hb_raster_image_t *mask = hb_raster_draw_render (draw);
* ```
*
@@ -52,12 +52,12 @@
* ```
* hb_raster_paint_t *paint = hb_raster_paint_create_or_fail ();
* hb_raster_paint_set_scale_factor (paint, 64.f, 64.f);
* hb_raster_paint_set_transform (paint, 1.f, 0.f, 0.f, 1.f, pen_x, pen_y);
* hb_raster_paint_set_transform (paint, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f);
* hb_raster_paint_set_foreground (paint, foreground);
* hb_glyph_extents_t glyph_extents;
* hb_font_get_glyph_extents (font, gid, &glyph_extents);
* hb_raster_paint_set_glyph_extents (paint, &glyph_extents);
* hb_font_paint_glyph (font, gid, hb_raster_paint_get_funcs (), paint, 0, foreground);
* hb_raster_paint_glyph (paint, font, gid, pen_x, pen_y, 0, foreground);
* hb_raster_image_t *img = hb_raster_paint_render (paint);
* ```
*
+34
View File
@@ -1503,6 +1503,40 @@ hb_vector_paint_get_funcs (void)
return hb_vector_paint_funcs_singleton ();
}
hb_bool_t
hb_vector_paint_glyph (hb_vector_paint_t *paint,
hb_font_t *font,
hb_codepoint_t glyph,
float pen_x,
float pen_y,
unsigned palette,
hb_color_t foreground)
{
float xx = paint->transform.xx;
float yx = paint->transform.yx;
float xy = paint->transform.xy;
float yy = paint->transform.yy;
float dx = paint->transform.x0;
float dy = paint->transform.y0;
float tx = dx + xx * pen_x + xy * pen_y;
float ty = dy + yx * pen_x + yy * pen_y;
hb_vector_paint_set_transform (paint, xx, yx, xy, yy, tx, ty);
if (!paint->has_extents)
{
hb_glyph_extents_t ge;
if (hb_font_get_glyph_extents (font, glyph, &ge))
hb_vector_paint_set_glyph_extents (paint, &ge);
}
hb_bool_t ret = hb_font_paint_glyph_or_fail (font, glyph,
hb_vector_paint_get_funcs (), paint,
palette, foreground);
hb_vector_paint_set_transform (paint, xx, yx, xy, yy, dx, dy);
return ret;
}
void
hb_vector_svg_paint_set_flat (hb_vector_paint_t *paint,
hb_bool_t flat)
+9
View File
@@ -193,6 +193,15 @@ hb_vector_paint_set_palette (hb_vector_paint_t *paint,
HB_EXTERN hb_paint_funcs_t *
hb_vector_paint_get_funcs (void);
HB_EXTERN hb_bool_t
hb_vector_paint_glyph (hb_vector_paint_t *paint,
hb_font_t *font,
hb_codepoint_t glyph,
float pen_x,
float pen_y,
unsigned palette,
hb_color_t foreground);
HB_EXTERN void
hb_vector_svg_paint_set_flat (hb_vector_paint_t *paint,
hb_bool_t flat);
+3 -4
View File
@@ -213,10 +213,9 @@ struct vector_output_t : output_options_t<>
float pen_x = g.x + off_x;
float pen_y = g.y + off_y;
hb_vector_paint_set_transform (paint, 1.f, 0.f, 0.f, 1.f, pen_x, pen_y);
if (hb_font_paint_glyph_or_fail (upem_font, g.gid,
hb_vector_paint_get_funcs (), paint,
palette, foreground))
hb_vector_paint_set_transform (paint, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f);
if (hb_vector_paint_glyph (paint, upem_font, g.gid, pen_x, pen_y,
palette, foreground))
{
had_paint = true;
continue;