From a69713b520eecfc3c2f28687a9d67fbb0466fca6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 22 Apr 2025 21:01:04 -0600 Subject: [PATCH] [color] Move slanting to font layer COLRv1 is still being double-slanted. Investigating. --- src/OT/Color/CBDT/CBDT.hh | 4 ++-- src/OT/Color/COLR/COLR.hh | 1 - src/OT/Color/sbix/sbix.hh | 4 ++-- src/OT/Color/svg/svg.hh | 2 +- src/hb-cairo-utils.cc | 8 +------- src/hb-font.hh | 17 ++++++++++++++--- src/hb-ft-colr.hh | 8 ++------ src/hb-ft.cc | 4 ++-- src/hb-paint.cc | 6 +++--- src/hb-paint.h | 2 +- src/hb-paint.hh | 10 ++++++---- 11 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/OT/Color/CBDT/CBDT.hh b/src/OT/Color/CBDT/CBDT.hh index 50550e811..a4072eec4 100644 --- a/src/OT/Color/CBDT/CBDT.hh +++ b/src/OT/Color/CBDT/CBDT.hh @@ -954,7 +954,7 @@ struct CBDT if (unlikely (blob == hb_blob_get_empty ())) return false; - if (unlikely (!hb_font_get_glyph_extents (font, glyph, &extents))) + if (unlikely (!font->get_glyph_extents (glyph, &extents, false))) return false; if (unlikely (!get_extents (font, glyph, &pixel_extents, false))) @@ -964,7 +964,7 @@ struct CBDT blob, pixel_extents.width, -pixel_extents.height, HB_PAINT_IMAGE_FORMAT_PNG, - font->slant_xy, + 0.f, &extents); hb_blob_destroy (blob); diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index 0a220466e..2ba16c02e 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -2634,7 +2634,6 @@ struct COLR } else { - // Ugh. We need to undo the synthetic slant here. Leave it for now. :-(. extents->x_bearing = e.xmin; extents->y_bearing = e.ymax; extents->width = e.xmax - e.xmin; diff --git a/src/OT/Color/sbix/sbix.hh b/src/OT/Color/sbix/sbix.hh index 51ae1a9c6..6b660711e 100644 --- a/src/OT/Color/sbix/sbix.hh +++ b/src/OT/Color/sbix/sbix.hh @@ -244,7 +244,7 @@ struct sbix if (blob == hb_blob_get_empty ()) return false; - if (!hb_font_get_glyph_extents (font, glyph, &extents)) + if (!font->get_glyph_extents (glyph, &extents, false)) return false; if (unlikely (!get_extents (font, glyph, &pixel_extents, false))) @@ -254,7 +254,7 @@ struct sbix blob, pixel_extents.width, -pixel_extents.height, HB_PAINT_IMAGE_FORMAT_PNG, - font->slant_xy, + 0.f, &extents); hb_blob_destroy (blob); diff --git a/src/OT/Color/svg/svg.hh b/src/OT/Color/svg/svg.hh index 2e1f93510..2c7576957 100644 --- a/src/OT/Color/svg/svg.hh +++ b/src/OT/Color/svg/svg.hh @@ -108,7 +108,7 @@ struct SVG blob, 0, 0, HB_PAINT_IMAGE_FORMAT_SVG, - font->slant_xy, + 0.f, nullptr); hb_blob_destroy (blob); diff --git a/src/hb-cairo-utils.cc b/src/hb-cairo-utils.cc index 85c62d39a..1fece8e96 100644 --- a/src/hb-cairo-utils.cc +++ b/src/hb-cairo-utils.cc @@ -101,7 +101,7 @@ _hb_cairo_paint_glyph_image (hb_cairo_context_t *c, unsigned width, unsigned height, hb_tag_t format, - float slant, + HB_UNUSED float slant_deprecated, hb_glyph_extents_t *extents) { cairo_t *cr = c->cr; @@ -186,12 +186,6 @@ _hb_cairo_paint_glyph_image (hb_cairo_context_t *c, 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., (double) 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/src/hb-font.hh b/src/hb-font.hh index b80e05d93..6094cd0e6 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -580,15 +580,26 @@ struct hb_font_t } void paint_glyph (hb_codepoint_t glyph, - hb_paint_funcs_t *paint_funcs, void *paint_data, - unsigned int palette, - hb_color_t foreground) + hb_paint_funcs_t *paint_funcs, void *paint_data, + unsigned int palette, + hb_color_t foreground, + bool synthetic = true) { + /* Slant */ + if (synthetic && slant_xy) + hb_paint_push_transform (paint_funcs, paint_data, + 1.f, 0.f, + 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); + + if (synthetic && slant_xy) + hb_paint_pop_transform (paint_funcs, paint_data); } /* A bit higher-level, and with fallback */ diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index 051201bd9..79d556121 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -518,13 +518,9 @@ hb_ft_paint_glyph_colr (hb_font_t *font, if (FT_Get_Color_Glyph_ClipBox (ft_face, gid, &clip_box)) { c.funcs->push_clip_rectangle (c.data, - clip_box.bottom_left.x + - roundf (hb_min (font->slant_xy * clip_box.bottom_left.y, - font->slant_xy * clip_box.top_left.y)), + clip_box.bottom_left.x, clip_box.bottom_left.y, - clip_box.top_right.x + - roundf (hb_max (font->slant_xy * clip_box.bottom_right.y, - font->slant_xy * clip_box.top_right.y)), + clip_box.top_right.x, clip_box.top_right.y); clip = true; is_bounded = true; diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 32d8b5153..46a18c6aa 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -951,7 +951,7 @@ hb_ft_paint_glyph (hb_font_t *font, nullptr, nullptr); hb_glyph_extents_t extents; - if (!hb_font_get_glyph_extents (font, gid, &extents)) + if (!font->get_glyph_extents (gid, &extents, false)) goto out; if (!paint_funcs->image (paint_data, @@ -959,7 +959,7 @@ hb_ft_paint_glyph (hb_font_t *font, bitmap.width, bitmap.rows, HB_PAINT_IMAGE_FORMAT_BGRA, - font->slant_xy, + 0.f, &extents)) { /* TODO Try a forced outline load and paint? */ diff --git a/src/hb-paint.cc b/src/hb-paint.cc index 755b18169..a90382689 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -615,7 +615,7 @@ hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data, * @width: width of the raster image in pixels, or 0 * @height: height of the raster image in pixels, or 0 * @format: the image format as a tag - * @slant: the synthetic slant ratio to be applied to the image during rendering + * @slant: Deprecated. set to 0.0 * @extents: (nullable): the extents of the glyph * * Perform a "image" paint operation. @@ -628,10 +628,10 @@ hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data, unsigned int width, unsigned int height, hb_tag_t format, - float slant, + HB_UNUSED float slant, hb_glyph_extents_t *extents) { - funcs->image (paint_data, image, width, height, format, slant, extents); + funcs->image (paint_data, image, width, height, format, 0.f, extents); } /** diff --git a/src/hb-paint.h b/src/hb-paint.h index 309213e2d..873210cb6 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -281,7 +281,7 @@ typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs, * @width: width of the raster image in pixels, or 0 * @height: height of the raster image in pixels, or 0 * @format: the image format as a tag - * @slant: the synthetic slant ratio to be applied to the image during rendering + * @slant: Deprecated. Always set to 0.0. * @extents: (nullable): glyph extents for desired rendering * @user_data: User data pointer passed to hb_paint_funcs_set_image_func() * diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 5a7b903a0..6ad365a79 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -162,10 +162,11 @@ struct hb_paint_funcs_t { float upem = font->face->get_upem (); int xscale = font->x_scale, yscale = font->y_scale; - float slant = font->slant_xy; push_transform (paint_data, - xscale/upem, 0, slant * yscale/upem, yscale/upem, 0, 0); + xscale/upem, 0, + 0, yscale/upem, + 0, 0); } void push_inverse_font_transform (void *paint_data, @@ -174,10 +175,11 @@ struct hb_paint_funcs_t float upem = font->face->get_upem (); int xscale = font->x_scale ? font->x_scale : upem; int yscale = font->y_scale ? font->y_scale : upem; - float slant = font->slant_xy; push_transform (paint_data, - upem/xscale, 0, -slant * upem/xscale, upem/yscale, 0, 0); + upem/xscale, 0, + 0, upem/yscale, + 0, 0); } HB_NODISCARD