[paint] Add slant to image() callback

And slant images in hb-view.
This commit is contained in:
Behdad Esfahbod 2022-12-22 08:12:47 -07:00
parent c221933977
commit 237955dffc
9 changed files with 17 additions and 5 deletions

View File

@ -948,7 +948,7 @@ struct CBDT
if (unlikely (!hb_font_get_glyph_extents (font, glyph, &extents)))
return false;
funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_PNG, &extents);
funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_PNG, font->slant_xy, &extents);
hb_blob_destroy (blob);
return true;

View File

@ -248,7 +248,7 @@ struct sbix
if (!hb_font_get_glyph_extents (font, glyph, &extents))
return false;
funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_PNG, &extents);
funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_PNG, font->slant_xy, &extents);
hb_blob_destroy (blob);
return true;

View File

@ -103,7 +103,7 @@ struct SVG
if (blob == hb_blob_get_empty ())
return false;
funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_SVG, nullptr);
funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_SVG, font->slant_xy, nullptr);
hb_blob_destroy (blob);
return true;

View File

@ -78,6 +78,7 @@ static void
hb_paint_image_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_blob_t *image,
hb_tag_t format,
float slant_xy,
hb_glyph_extents_t *extents,
void *user_data) {}

View File

@ -264,6 +264,7 @@ typedef void (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs,
void *paint_data,
hb_blob_t *image,
hb_tag_t format,
float slant,
hb_glyph_extents_t *extents,
void *user_data);

View File

@ -100,9 +100,10 @@ struct hb_paint_funcs_t
void image (void *paint_data,
hb_blob_t *image,
hb_tag_t format,
float slant,
hb_glyph_extents_t *extents)
{ func.image (this, paint_data,
image, format, extents,
image, format, slant, extents,
!user_data ? nullptr : user_data->image); }
void linear_gradient (void *paint_data,
hb_color_line_t *color_line,

View File

@ -100,6 +100,7 @@ void
hb_cairo_paint_glyph_image (cairo_t *cr,
hb_blob_t *blob,
hb_tag_t format,
float slant,
hb_glyph_extents_t *extents)
{
#ifdef CAIRO_HAS_PNG_FUNCTIONS
@ -119,6 +120,12 @@ hb_cairo_paint_glyph_image (cairo_t *cr,
cairo_matrix_t matrix = {(double) width, 0, 0, (double) height, 0, 0};
cairo_pattern_set_matrix (pattern, &matrix);
/* Undo slant in the extents and apply it in the context. */
extents->width -= extents->height * slant;
extents->x_bearing -= extents->y_bearing * slant;
cairo_matrix_t cairo_matrix = {1., 0., slant, 1., 0., 0.};
cairo_transform (cr, &cairo_matrix);
cairo_translate (cr, extents->x_bearing, extents->y_bearing);
cairo_scale (cr, extents->width, extents->height);
cairo_set_source (cr, pattern);

View File

@ -73,6 +73,7 @@ hb_paint_composite_mode_to_cairo (hb_paint_composite_mode_t mode)
void hb_cairo_paint_glyph_image (cairo_t *cr,
hb_blob_t *blob,
hb_tag_t format,
float slant,
hb_glyph_extents_t *extents);
void hb_cairo_paint_linear_gradient (cairo_t *cr,

View File

@ -222,12 +222,13 @@ paint_image (hb_paint_funcs_t *funcs,
void *paint_data,
hb_blob_t *blob,
hb_tag_t format,
float slant,
hb_glyph_extents_t *extents,
void *user_data)
{
cairo_t *cr = (cairo_t *)paint_data;
hb_cairo_paint_glyph_image (cr, blob, format, extents);
hb_cairo_paint_glyph_image (cr, blob, format, slant, extents);
}
static void