From 237955dffca19bc320ca1b94808b52265ef653ed Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 22 Dec 2022 08:12:47 -0700 Subject: [PATCH] [paint] Add slant to image() callback And slant images in hb-view. --- src/hb-ot-color-cbdt-table.hh | 2 +- src/hb-ot-color-sbix-table.hh | 2 +- src/hb-ot-color-svg-table.hh | 2 +- src/hb-paint.cc | 1 + src/hb-paint.h | 1 + src/hb-paint.hh | 3 ++- util/hb-cairo-utils.c | 7 +++++++ util/hb-cairo-utils.h | 1 + util/helper-cairo-user.hh | 3 ++- 9 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index 63536aa92..beaee108d 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -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; diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index bafb45417..20f2b0444 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -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; diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index 3967a1196..f9990d44b 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -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; diff --git a/src/hb-paint.cc b/src/hb-paint.cc index f59266f8a..fdce759a1 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -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) {} diff --git a/src/hb-paint.h b/src/hb-paint.h index af36e36a0..e78462d72 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -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); diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 401c3016e..eaba99bce 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -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, diff --git a/util/hb-cairo-utils.c b/util/hb-cairo-utils.c index 8bfddde70..d40b56458 100644 --- a/util/hb-cairo-utils.c +++ b/util/hb-cairo-utils.c @@ -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); diff --git a/util/hb-cairo-utils.h b/util/hb-cairo-utils.h index 39cfa3ec4..fdc9de884 100644 --- a/util/hb-cairo-utils.h +++ b/util/hb-cairo-utils.h @@ -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, diff --git a/util/helper-cairo-user.hh b/util/helper-cairo-user.hh index d7edea2c6..8ad970a0b 100644 --- a/util/helper-cairo-user.hh +++ b/util/helper-cairo-user.hh @@ -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