From 9be01b6bff054e3edb516ca680a1e33b05a74e9b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 21 Dec 2022 14:04:32 -0500 Subject: [PATCH] [paint] Pass hb_paint_context_t along Replace the font argument with a hb_paint_context_t that carries the font, the palette index and the foreground color. The hb_font_paint_glyph() api now takes the palette index and the foreground color as extra arguments. Update all callers and regenerate test results. --- src/OT/glyf/glyf.hh | 18 +++-- src/hb-font.cc | 24 +++++-- src/hb-font.h | 9 ++- src/hb-font.hh | 5 +- src/hb-ot-cff1-table.cc | 19 +++-- src/hb-ot-cff1-table.hh | 2 +- src/hb-ot-cff2-table.cc | 20 ++++-- src/hb-ot-cff2-table.hh | 2 +- src/hb-ot-color-cbdt-table.hh | 8 ++- src/hb-ot-color-colr-table.cc | 4 +- src/hb-ot-color-colr-table.hh | 119 ++++++++++++++++---------------- src/hb-ot-color-sbix-table.hh | 3 +- src/hb-ot-color-svg-table.hh | 4 +- src/hb-ot-font.cc | 10 +-- src/hb-paint.cc | 98 +++++++++++++------------- src/hb-paint.h | 95 +++++++++++++++---------- src/hb-paint.hh | 66 +++++++++--------- test/api/results/hand-20-0-10 | 18 ++--- test/api/results/hand-20-0.2-10 | 18 ++--- test/api/results/test-20-0-10 | 2 +- test/api/results/test-20-0-106 | 4 +- test/api/results/test-20-0-116 | 4 +- test/api/results/test-20-0-123 | 6 +- test/api/results/test-20-0-165 | 2 +- test/api/results/test-20-0-175 | 4 +- test/api/results/test-20-0-6 | 2 +- test/api/results/test-20-0-92 | 2 +- test/api/test-ot-color.c | 26 +++---- util/hb-cairo-utils.c | 51 ++++++-------- util/hb-cairo-utils.h | 17 +++-- util/helper-cairo-user.hh | 38 +++++----- 31 files changed, 384 insertions(+), 316 deletions(-) diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index fa9f90d86..084a73c2e 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -333,15 +333,21 @@ struct glyf_accelerator_t return glyph_for_gid (gid).get_extents_without_var_scaled (font, *this, extents); } - bool paint_glyph (hb_font_t *font, hb_codepoint_t gid, hb_paint_funcs_t *funcs, void *data) const + bool paint_glyph (hb_font_t *font, hb_codepoint_t gid, hb_paint_funcs_t *funcs, void *data, hb_color_t foreground) const { - funcs->push_root_transform (data, font); + hb_paint_context_t ctx; - funcs->push_clip_glyph (data, gid, font); - funcs->color (data, 0xffff, 1., font); - funcs->pop_clip (data, font); + ctx.font = font; + ctx.palette = 0; + ctx.foreground = foreground; - funcs->pop_root_transform (data, font); + funcs->push_root_transform (data, &ctx); + + funcs->push_clip_glyph (data, gid, &ctx); + funcs->color (data, 0xffff, 1., &ctx); + funcs->pop_clip (data, &ctx); + + funcs->pop_root_transform (data, &ctx); return false; } diff --git a/src/hb-font.cc b/src/hb-font.cc index cbf323a1c..cd32aa1b6 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -519,6 +519,8 @@ hb_font_paint_glyph_nil (hb_font_t *font HB_UNUSED, hb_codepoint_t glyph HB_UNUSED, hb_paint_funcs_t *paint_funcs HB_UNUSED, void *paint_data HB_UNUSED, + unsigned int palette HB_UNUSED, + hb_color_t foreground HB_UNUSED, void *user_data HB_UNUSED) { } @@ -655,8 +657,16 @@ hb_font_paint_glyph_default (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *paint_funcs, void *paint_data, + unsigned int palette, + hb_color_t foreground, void *user_data) { + hb_paint_context_t ctx; + + ctx.font = font; + ctx.palette = palette; + ctx.foreground = foreground; + paint_funcs->push_transform (paint_data, font->parent->x_scale ? (float) font->x_scale / (float) font->parent->x_scale : 0.f, font->parent->y_scale ? (font->slant - font->parent->slant) * @@ -665,11 +675,11 @@ hb_font_paint_glyph_default (hb_font_t *font, font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0.f, 0.f, 0.f, - font); + &ctx); - font->parent->paint_glyph (glyph, paint_funcs, paint_data); + font->parent->paint_glyph (glyph, paint_funcs, paint_data, palette, foreground); - paint_funcs->pop_transform (paint_data, font); + paint_funcs->pop_transform (paint_data, &ctx); } DEFINE_NULL_INSTANCE (hb_font_funcs_t) = @@ -1427,6 +1437,8 @@ hb_font_draw_glyph (hb_font_t *font, * @glyph: The glyph ID * @pfuncs: #hb_paint_funcs_t to paint with * @paint_data: User data to pass to paint callbacks + * @palette: The palette index to use + * @foreground: The foreground color * * Paints the glyph. * @@ -1442,9 +1454,11 @@ hb_font_draw_glyph (hb_font_t *font, void hb_font_paint_glyph (hb_font_t *font, hb_codepoint_t glyph, - hb_paint_funcs_t *pfuncs, void *paint_data) + hb_paint_funcs_t *pfuncs, void *paint_data, + unsigned int palette, + hb_color_t foreground) { - font->paint_glyph (glyph, pfuncs, paint_data); + font->paint_glyph (glyph, pfuncs, paint_data, palette, foreground); } /* A bit higher-level, and with fallback */ diff --git a/src/hb-font.h b/src/hb-font.h index 4574a5769..1978b57cd 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -529,6 +529,8 @@ typedef void (*hb_font_draw_glyph_func_t) (hb_font_t *font, void *font_data, * @glyph: The glyph ID to query * @paint_funcs: The paint functions to use * @paint_data: The data accompanying the paint functions + * @palette: The color palette to use + * @foreground: The foreground color * @user_data: User data pointer passed by the caller * * A virtual method for the #hb_font_funcs_t of an #hb_font_t object. @@ -538,6 +540,8 @@ typedef void (*hb_font_draw_glyph_func_t) (hb_font_t *font, void *font_data, 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, + hb_color_t foreground, void *user_data); /* func setters */ @@ -941,8 +945,9 @@ hb_font_draw_glyph (hb_font_t *font, HB_EXTERN void hb_font_paint_glyph (hb_font_t *font, hb_codepoint_t glyph, - hb_paint_funcs_t *pfuncs, void *paint_data); - + hb_paint_funcs_t *pfuncs, void *paint_data, + unsigned int palette, + hb_color_t foreground); /* high-level funcs, with fallback */ diff --git a/src/hb-font.hh b/src/hb-font.hh index 60fc53238..83f0d8701 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -403,11 +403,14 @@ struct hb_font_t } void paint_glyph (hb_codepoint_t glyph, - hb_paint_funcs_t *paint_funcs, void *paint_data) + hb_paint_funcs_t *paint_funcs, void *paint_data, + unsigned int palette, + hb_color_t foreground) { klass->get.f.paint_glyph (this, user_data, glyph, paint_funcs, paint_data, + palette, foreground, !klass->user_data ? nullptr : klass->user_data->paint_glyph); } diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index c6cb48eb2..61e2cb177 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -553,17 +553,22 @@ bool _get_path (const OT::cff1::accelerator_t *cff, hb_font_t *font, hb_codepoin return true; } -bool OT::cff1::accelerator_t::paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const +bool OT::cff1::accelerator_t::paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data, hb_color_t foreground) const { - funcs->push_root_transform (data, font); + hb_paint_context_t ctx; - funcs->push_clip_glyph (data, glyph, font); - funcs->color (data, 0xffff, 1., font); - funcs->pop_clip (data, font); + ctx.font = font; + ctx.palette = 0; + ctx.foreground = foreground; + funcs->push_root_transform (data, &ctx); - funcs->pop_root_transform (data, font); + funcs->push_clip_glyph (data, glyph, &ctx); + funcs->color (data, 0xffff, 1., &ctx); + funcs->pop_clip (data, &ctx); - return false; + funcs->pop_root_transform (data, &ctx); + + return false; } bool OT::cff1::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session) const diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index 3bc37d9bb..c68763fe4 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -1427,7 +1427,7 @@ struct cff1 } HB_INTERNAL bool get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const; - HB_INTERNAL bool paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const; + HB_INTERNAL bool paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data, hb_color_t foreground) const; HB_INTERNAL bool get_seac_components (hb_codepoint_t glyph, hb_codepoint_t *base, hb_codepoint_t *accent) const; HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session) const; diff --git a/src/hb-ot-cff2-table.cc b/src/hb-ot-cff2-table.cc index 97e8100b6..991693811 100644 --- a/src/hb-ot-cff2-table.cc +++ b/src/hb-ot-cff2-table.cc @@ -143,17 +143,23 @@ bool OT::cff2::accelerator_t::get_extents (hb_font_t *font, return true; } -bool OT::cff2::accelerator_t::paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const +bool OT::cff2::accelerator_t::paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data, hb_color_t foreground) const { - funcs->push_root_transform (data, font); + hb_paint_context_t ctx; - funcs->push_clip_glyph (data, glyph, font); - funcs->color (data, 0xffff, 1., font); - funcs->pop_clip (data, font); + ctx.font = font; + ctx.palette = 0; + ctx.foreground = foreground; - funcs->pop_root_transform (data, font); + funcs->push_root_transform (data, &ctx); - return false; + funcs->push_clip_glyph (data, glyph, &ctx); + funcs->color (data, 0xffff, 1., &ctx); + funcs->pop_clip (data, &ctx); + + funcs->pop_root_transform (data, &ctx); + + return false; } struct cff2_path_param_t diff --git a/src/hb-ot-cff2-table.hh b/src/hb-ot-cff2-table.hh index ddfe2d7c9..9a3d2d013 100644 --- a/src/hb-ot-cff2-table.hh +++ b/src/hb-ot-cff2-table.hh @@ -517,7 +517,7 @@ struct cff2 HB_INTERNAL bool get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const; - HB_INTERNAL bool paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const; + HB_INTERNAL bool paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data, hb_color_t foreground) const; HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session) const; }; diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index f32406daa..3fe8fa943 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -939,15 +939,21 @@ struct CBDT bool paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const { + hb_paint_context_t ctx; hb_glyph_extents_t extents; hb_blob_t *blob = reference_png (font, glyph); + if (unlikely (blob == hb_blob_get_empty ())) return false; if (unlikely (!hb_font_get_glyph_extents (font, glyph, &extents))) return false; - funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_PNG, &extents, font); + ctx.font = font; + ctx.palette = 0; + ctx.foreground = HB_COLOR (0, 0, 0, 255); + + funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_PNG, &extents, &ctx); hb_blob_destroy (blob); return true; diff --git a/src/hb-ot-color-colr-table.cc b/src/hb-ot-color-colr-table.cc index 3f1e9f474..99b0d927c 100644 --- a/src/hb-ot-color-colr-table.cc +++ b/src/hb-ot-color-colr-table.cc @@ -8,9 +8,9 @@ void PaintColrLayers::paint_glyph (hb_ot_paint_context_t *c) const for (unsigned i = firstLayerIndex; i < firstLayerIndex + numLayers; i++) { const Paint &paint = paint_offset_lists.get_paint (i); - c->funcs->push_group (c->data, c->font); + c->funcs->push_group (c->data, &c->ctx); c->recurse (paint); - c->funcs->pop_group (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER, c->font); + c->funcs->pop_group (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER, &c->ctx); } } diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index 5c5bf4902..29404eb77 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -75,7 +75,7 @@ public: const void *base; hb_paint_funcs_t *funcs; void *data; - hb_font_t *font; + hb_paint_context_t ctx; VarStoreInstancer &instancer; int depth_left = HB_COLRV1_MAX_NESTING_LEVEL; @@ -83,13 +83,16 @@ public: hb_paint_funcs_t *funcs_, void *data_, hb_font_t *font_, + unsigned int palette, + hb_color_t foreground, VarStoreInstancer &instancer_) : base (base_), funcs (funcs_), data (data_), - font (font_), instancer (instancer_) - {} + { ctx.font = font_; + ctx.palette = palette; + ctx.foreground = foreground; } inline void recurse (const Paint &paint); }; @@ -486,7 +489,7 @@ struct Affine2x3 yy.to_float (c->instancer (varIdxBase, 3)), dx.to_float (c->instancer (varIdxBase, 4)), dy.to_float (c->instancer (varIdxBase, 5)), - c->font); + &c->ctx); } F16DOT16 xx; @@ -554,7 +557,7 @@ struct PaintSolid c->funcs->color (c->data, paletteIndex, alpha.to_float (c->instancer (varIdxBase, 0)), - c->font); + &c->ctx); } HBUINT8 format; /* format = 2(noVar) or 3(Var)*/ @@ -596,7 +599,7 @@ struct PaintLinearGradient y1 + c->instancer (varIdxBase, 3), x2 + c->instancer (varIdxBase, 4), y2 + c->instancer (varIdxBase, 5), - c->font); + &c->ctx); } HBUINT8 format; /* format = 4(noVar) or 5 (Var) */ @@ -644,7 +647,7 @@ struct PaintRadialGradient x1 + c->instancer (varIdxBase, 3), y1 + c->instancer (varIdxBase, 4), radius1 + c->instancer (varIdxBase, 5), - c->font); + &c->ctx); } HBUINT8 format; /* format = 6(noVar) or 7 (Var) */ @@ -690,7 +693,7 @@ struct PaintSweepGradient centerY + c->instancer (varIdxBase, 1), (startAngle.to_float (c->instancer (varIdxBase, 2)) + 1) * (float) M_PI, (endAngle.to_float (c->instancer (varIdxBase, 3)) + 1) * (float) M_PI, - c->font); + &c->ctx); } HBUINT8 format; /* format = 8(noVar) or 9 (Var) */ @@ -730,11 +733,11 @@ struct PaintGlyph void paint_glyph (hb_ot_paint_context_t *c) const { - c->funcs->push_inverse_root_transform (c->data, c->font); - c->funcs->push_clip_glyph (c->data, gid, c->font); + c->funcs->push_inverse_root_transform (c->data, &c->ctx); + c->funcs->push_clip_glyph (c->data, gid, &c->ctx); c->recurse (this+paint); - c->funcs->pop_clip (c->data, c->font); - c->funcs->pop_inverse_root_transform (c->data, c->font); + c->funcs->pop_clip (c->data, &c->ctx); + c->funcs->pop_inverse_root_transform (c->data, &c->ctx); } HBUINT8 format; /* format = 10 */ @@ -798,7 +801,7 @@ struct PaintTransform { (this+transform).paint_glyph (c); c->recurse (this+src); - c->funcs->pop_transform (c->data, c->font); + c->funcs->pop_transform (c->data, &c->ctx); } HBUINT8 format; /* format = 12(noVar) or 13 (Var) */ @@ -833,9 +836,9 @@ struct PaintTranslate 1., 0., 0., 1., dx + c->instancer (varIdxBase, 0), dy + c->instancer (varIdxBase, 0), - c->font); + &c->ctx); c->recurse (this+src); - c->funcs->pop_transform (c->data, c->font); + c->funcs->pop_transform (c->data, &c->ctx); } HBUINT8 format; /* format = 14(noVar) or 15 (Var) */ @@ -872,9 +875,9 @@ struct PaintScale 0., 0., scaleY.to_float (c->instancer (varIdxBase, 1)), 0., 0., - c->font); + &c->ctx); c->recurse (this+src); - c->funcs->pop_transform (c->data, c->font); + c->funcs->pop_transform (c->data, &c->ctx); } HBUINT8 format; /* format = 16 (noVar) or 17(Var) */ @@ -909,19 +912,19 @@ struct PaintScaleAroundCenter float tCenterX = centerX + c->instancer (varIdxBase, 2); float tCenterY = centerY + c->instancer (varIdxBase, 3); c->funcs->push_transform (c->data, 0., 0., 0., 0., +tCenterX, +tCenterY, - c->font); + &c->ctx); c->funcs->push_transform (c->data, scaleX.to_float (c->instancer (varIdxBase, 0)), 0., 0., scaleY.to_float (c->instancer (varIdxBase, 1)), 0., 0., - c->font); + &c->ctx); c->funcs->push_transform (c->data, 0., 0., 0., 0., -tCenterX, -tCenterY, - c->font); + &c->ctx); c->recurse (this+src); - c->funcs->pop_transform (c->data, c->font); - c->funcs->pop_transform (c->data, c->font); - c->funcs->pop_transform (c->data, c->font); + c->funcs->pop_transform (c->data, &c->ctx); + c->funcs->pop_transform (c->data, &c->ctx); + c->funcs->pop_transform (c->data, &c->ctx); } HBUINT8 format; /* format = 18 (noVar) or 19(Var) */ @@ -957,9 +960,9 @@ struct PaintScaleUniform { float s = scale + c->instancer (varIdxBase, 0); c->funcs->push_transform (c->data, s, 0., 0., s, 0., 0., - c->font); + &c->ctx); c->recurse (this+src); - c->funcs->pop_transform (c->data, c->font); + c->funcs->pop_transform (c->data, &c->ctx); } HBUINT8 format; /* format = 20 (noVar) or 21(Var) */ @@ -994,15 +997,15 @@ struct PaintScaleUniformAroundCenter float tCenterX = centerX + c->instancer (varIdxBase, 1); float tCenterY = centerY + c->instancer (varIdxBase, 2); c->funcs->push_transform (c->data, 0., 0., 0., 0., +tCenterX, +tCenterY, - c->font); + &c->ctx); c->funcs->push_transform (c->data, s, 0., 0., s, 0., 0., - c->font); + &c->ctx); c->funcs->push_transform (c->data, 0., 0., 0., 0., -tCenterX, -tCenterY, - c->font); + &c->ctx); c->recurse (this+src); - c->funcs->pop_transform (c->data, c->font); - c->funcs->pop_transform (c->data, c->font); - c->funcs->pop_transform (c->data, c->font); + c->funcs->pop_transform (c->data, &c->ctx); + c->funcs->pop_transform (c->data, &c->ctx); + c->funcs->pop_transform (c->data, &c->ctx); } HBUINT8 format; /* format = 22 (noVar) or 23(Var) */ @@ -1039,9 +1042,9 @@ struct PaintRotate float cc = cosf (a * (float) M_PI); float ss = sinf (a * (float) M_PI); c->funcs->push_transform (c->data, cc, ss, -ss, cc, 0., 0., - c->font); + &c->ctx); c->recurse (this+src); - c->funcs->pop_transform (c->data, c->font); + c->funcs->pop_transform (c->data, &c->ctx); } HBUINT8 format; /* format = 24 (noVar) or 25(Var) */ @@ -1078,15 +1081,15 @@ struct PaintRotateAroundCenter float tCenterX = centerX + c->instancer (varIdxBase, 1); float tCenterY = centerY + c->instancer (varIdxBase, 2); c->funcs->push_transform (c->data, 0., 0., 0., 0., +tCenterX, +tCenterY, - c->font); + &c->ctx); c->funcs->push_transform (c->data, cc, ss, -ss, cc, 0., 0., - c->font); + &c->ctx); c->funcs->push_transform (c->data, 0., 0., 0., 0., -tCenterX, -tCenterY, - c->font); + &c->ctx); c->recurse (this+src); - c->funcs->pop_transform (c->data, c->font); - c->funcs->pop_transform (c->data, c->font); - c->funcs->pop_transform (c->data, c->font); + c->funcs->pop_transform (c->data, &c->ctx); + c->funcs->pop_transform (c->data, &c->ctx); + c->funcs->pop_transform (c->data, &c->ctx); } HBUINT8 format; /* format = 26 (noVar) or 27(Var) */ @@ -1122,9 +1125,9 @@ struct PaintSkew float x = +tanf (xSkewAngle.to_float(c->instancer (varIdxBase, 0)) * (float) M_PI); float y = -tanf (ySkewAngle.to_float(c->instancer (varIdxBase, 1)) * (float) M_PI); c->funcs->push_transform (c->data, 1., y, x, 1., 0., 0., - c->font); + &c->ctx); c->recurse (this+src); - c->funcs->pop_transform (c->data, c->font); + c->funcs->pop_transform (c->data, &c->ctx); } HBUINT8 format; /* format = 28(noVar) or 29 (Var) */ @@ -1161,15 +1164,15 @@ struct PaintSkewAroundCenter float tCenterX = centerX + c->instancer (varIdxBase, 2); float tCenterY = centerY + c->instancer (varIdxBase, 3); c->funcs->push_transform (c->data, 0., 0., 0., 0., +tCenterX, +tCenterY, - c->font); + &c->ctx); c->funcs->push_transform (c->data, 1., y, x, 1., 0., 0., - c->font); + &c->ctx); c->funcs->push_transform (c->data, 0., 0., 0., 0., -tCenterX, -tCenterY, - c->font); + &c->ctx); c->recurse (this+src); - c->funcs->pop_transform (c->data, c->font); - c->funcs->pop_transform (c->data, c->font); - c->funcs->pop_transform (c->data, c->font); + c->funcs->pop_transform (c->data, &c->ctx); + c->funcs->pop_transform (c->data, &c->ctx); + c->funcs->pop_transform (c->data, &c->ctx); } HBUINT8 format; /* format = 30(noVar) or 31 (Var) */ @@ -1206,12 +1209,12 @@ struct PaintComposite void paint_glyph (hb_ot_paint_context_t *c) const { - c->funcs->push_group (c->data, c->font); + c->funcs->push_group (c->data, &c->ctx); c->recurse (this+backdrop); - c->funcs->push_group (c->data, c->font); + c->funcs->push_group (c->data, &c->ctx); c->recurse (this+src); - c->funcs->pop_group (c->data, (hb_paint_composite_mode_t) (int) mode, c->font); - c->funcs->pop_group (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER, c->font); + c->funcs->pop_group (c->data, (hb_paint_composite_mode_t) (int) mode, &c->ctx); + c->funcs->pop_group (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER, &c->ctx); } HBUINT8 format; /* format = 32 */ @@ -1960,23 +1963,23 @@ struct COLR } bool - paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const + paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data, unsigned int palette, hb_color_t foreground) const { VarStoreInstancer instancer (this+varStore, this+varIdxMap, hb_array (font->coords, font->num_coords)); - hb_ot_paint_context_t c (this, funcs, data, font, instancer); + hb_ot_paint_context_t c (this, funcs, data, font, palette, foreground, instancer); const Paint *paint = get_base_glyph_paint (glyph); if (paint) { // COLRv1 glyph - c.funcs->push_root_transform (c.data, c.font); + c.funcs->push_root_transform (c.data, &c.ctx); c.recurse (*paint); - c.funcs->pop_root_transform (c.data, c.font); + c.funcs->pop_root_transform (c.data, &c.ctx); return true; } @@ -1988,9 +1991,9 @@ struct COLR for (const auto &r : (this+layersZ).as_array (numLayers) .sub_array (record->firstLayerIdx, record->numLayers)) { - c.funcs->push_clip_glyph (c.data, r.glyphId, c.font); - c.funcs->color (c.data, r.colorIdx, 1., c.font); - c.funcs->pop_clip (c.data, c.font); + c.funcs->push_clip_glyph (c.data, r.glyphId, &c.ctx); + c.funcs->color (c.data, r.colorIdx, 1., &c.ctx); + c.funcs->pop_clip (c.data, &c.ctx); } return true; diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 0a93c488e..d1737501b 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -234,6 +234,7 @@ struct sbix bool paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const { + hb_paint_context_t ctx = { font, 0, HB_COLOR (0, 0, 0, 255) }; if (!has_data ()) return false; @@ -248,7 +249,7 @@ struct sbix if (!hb_font_get_glyph_extents (font, glyph, &extents)) return false; - funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_PNG, &extents, font); + funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_PNG, &extents, &ctx); 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 d5a55133d..dae4419bd 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -95,6 +95,8 @@ struct SVG bool paint_glyph (hb_font_t *font HB_UNUSED, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const { + hb_paint_context_t ctx = { font, 0, HB_COLOR (0, 0, 0, 255) }; + if (!has_data ()) return false; @@ -103,7 +105,7 @@ struct SVG if (blob == hb_blob_get_empty ()) return false; - funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_SVG, nullptr, font); + funcs->image (data, blob, HB_PAINT_IMAGE_FORMAT_SVG, nullptr, &ctx); hb_blob_destroy (blob); return true; diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 86b1fb665..270710993 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -446,20 +446,22 @@ hb_ot_paint_glyph (hb_font_t *font, void *font_data, hb_codepoint_t glyph, hb_paint_funcs_t *paint_funcs, void *paint_data, + unsigned int palette, + hb_color_t foreground, void *user_data) { #ifndef HB_NO_COLOR - if (font->face->table.COLR->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; if (font->face->table.SVG->paint_glyph (font, glyph, paint_funcs, paint_data)) return; #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; #endif #endif - if (font->face->table.glyf->paint_glyph (font, glyph, paint_funcs, paint_data)) return; + if (font->face->table.glyf->paint_glyph (font, glyph, paint_funcs, paint_data, foreground)) return; #ifndef HB_NO_CFF - if (font->face->table.cff1->paint_glyph (font, glyph, paint_funcs, paint_data)) return; - if (font->face->table.cff2->paint_glyph (font, glyph, paint_funcs, paint_data)) return; + if (font->face->table.cff1->paint_glyph (font, glyph, paint_funcs, paint_data, foreground)) return; + if (font->face->table.cff2->paint_glyph (font, glyph, paint_funcs, paint_data, foreground)) return; #endif } #endif diff --git a/src/hb-paint.cc b/src/hb-paint.cc index 5fa39a451..b7d09ab44 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -47,36 +47,36 @@ hb_paint_push_transform_nil (hb_paint_funcs_t *funcs, void *paint_data, float xx, float yx, float xy, float yy, float dx, float dy, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static void hb_paint_pop_transform_nil (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static void hb_paint_push_clip_glyph_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static void hb_paint_push_clip_rectangle_nil (hb_paint_funcs_t *funcs, void *paint_data, float xmin, float ymin, float xmax, float ymax, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static void hb_paint_pop_clip_nil (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static void hb_paint_color_nil (hb_paint_funcs_t *funcs, void *paint_data, unsigned int color_index, float alpha, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static void @@ -84,7 +84,7 @@ hb_paint_image_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_blob_t *image, hb_tag_t format, hb_glyph_extents_t *extents, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static void @@ -93,7 +93,7 @@ hb_paint_linear_gradient_nil (hb_paint_funcs_t *funcs, void *paint_data, float x0, float y0, float x1, float y1, float x2, float y2, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static void @@ -101,7 +101,7 @@ hb_paint_radial_gradient_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_color_line_t *color_line, float x0, float y0, float r0, float x1, float y1, float r1, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static void @@ -110,18 +110,18 @@ hb_paint_sweep_gradient_nil (hb_paint_funcs_t *funcs, void *paint_data, float x0, float y0, float start_angle, float end_angle, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static void hb_paint_push_group_nil (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static void hb_paint_pop_group_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_composite_mode_t mode, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) {} static bool @@ -394,7 +394,7 @@ hb_paint_funcs_is_immutable (hb_paint_funcs_t *funcs) * @yy: yy component of the transform matrix * @dx: dx component of the transform matrix * @dy: dy component of the transform matrix - * @font: the font + * @ctx: the paint context * * Perform a "push-transform" paint operation. * @@ -405,16 +405,16 @@ hb_paint_push_transform (hb_paint_funcs_t *funcs, void *paint_data, float xx, float yx, float xy, float yy, float dx, float dy, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->push_transform (paint_data, xx, yx, xy, yy, dx, dy, font); + funcs->push_transform (paint_data, xx, yx, xy, yy, dx, dy, ctx); } /** * hb_paint_pop_transform: * @funcs: paint functions * @paint_data: associated data passed by the caller - * @font: the font + * @ctx: the paint context * * Perform a "pop-transform" paint operation. * @@ -422,9 +422,9 @@ hb_paint_push_transform (hb_paint_funcs_t *funcs, void *paint_data, */ void hb_paint_pop_transform (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->pop_transform (paint_data, font); + funcs->pop_transform (paint_data, ctx); } /** @@ -432,7 +432,7 @@ hb_paint_pop_transform (hb_paint_funcs_t *funcs, void *paint_data, * @funcs: paint functions * @paint_data: associated data passed by the caller * @glyph: the glyph ID - * @font: the font + * @ctx: the paint context * * Perform a "push-clip-glyph" paint operation. * @@ -441,9 +441,9 @@ hb_paint_pop_transform (hb_paint_funcs_t *funcs, void *paint_data, void hb_paint_push_clip_glyph (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->push_clip_glyph (paint_data, glyph, font); + funcs->push_clip_glyph (paint_data, glyph, ctx); } /** @@ -454,7 +454,7 @@ hb_paint_push_clip_glyph (hb_paint_funcs_t *funcs, void *paint_data, * @ymin: min Y for the rectangle * @xmax: max X for the rectangle * @ymax: max Y for the rectangle - * @font: the font + * @ctx: the paint context * * Perform a "push-clip-rect" paint operation. * @@ -463,16 +463,16 @@ hb_paint_push_clip_glyph (hb_paint_funcs_t *funcs, void *paint_data, void hb_paint_push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data, float xmin, float ymin, float xmax, float ymax, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->push_clip_rectangle (paint_data, xmin, ymin, xmax, ymax, font); + funcs->push_clip_rectangle (paint_data, xmin, ymin, xmax, ymax, ctx); } /** * hb_paint_pop_clip: * @funcs: paint functions * @paint_data: associated data passed by the caller - * @font: the font + * @ctx: the paint context * * Perform a "pop-clip" paint operation. * @@ -480,18 +480,18 @@ hb_paint_push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data, */ void hb_paint_pop_clip (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->pop_clip (paint_data, font); + funcs->pop_clip (paint_data, ctx); } /** * hb_paint_color: * @funcs: paint functions * @paint_data: associated data passed by the caller - * @color_index: Index of a color in the fonts selected color palette + * @color_index: Index of a color in the color palette * @alpha: Alpha to apply in addition - * @font: the font + * @ctx: the paint context * * Perform a "color" paint operation. * @@ -501,9 +501,9 @@ void hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data, unsigned int color_index, float alpha, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->color (paint_data, color_index, alpha, font); + funcs->color (paint_data, color_index, alpha, ctx); } /** @@ -513,7 +513,7 @@ hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data, * @image: image data * @format: tag describing the image data format * @extents: (nullable): the extents of the glyph - * @font: the font + * @ctx: the paint context * * Perform a "image" paint operation. * @@ -524,9 +524,9 @@ hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data, hb_blob_t *image, hb_tag_t format, hb_glyph_extents_t *extents, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->image (paint_data, image, format, extents, font); + funcs->image (paint_data, image, format, extents, ctx); } /** @@ -540,7 +540,7 @@ hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data, * @y1: Y coordinate of the second point * @x2: X coordinate of the third point * @y2: Y coordinate of the third point - * @font: the font + * @ctx: the paint context * * Perform a "linear-gradient" paint operation. * @@ -552,9 +552,9 @@ hb_paint_linear_gradient (hb_paint_funcs_t *funcs, void *paint_data, float x0, float y0, float x1, float y1, float x2, float y2, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->linear_gradient (paint_data, color_line, x0, y0, x1, y1, x2, y2, font); + funcs->linear_gradient (paint_data, color_line, x0, y0, x1, y1, x2, y2, ctx); } /** @@ -568,7 +568,7 @@ hb_paint_linear_gradient (hb_paint_funcs_t *funcs, void *paint_data, * @x1: X coordinate of the second circle's center * @y1: Y coordinate of the second circle's center * @r1: radius of the second circle - * @font: the font + * @ctx: the paint context * * Perform a "radial-gradient" paint operation. * @@ -579,9 +579,9 @@ hb_paint_radial_gradient (hb_paint_funcs_t *funcs, void *paint_data, hb_color_line_t *color_line, float x0, float y0, float r0, float x1, float y1, float r1, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->radial_gradient (paint_data, color_line, x0, y0, r0, y1, x1, r1, font); + funcs->radial_gradient (paint_data, color_line, x0, y0, r0, y1, x1, r1, ctx); } /** @@ -593,7 +593,7 @@ hb_paint_radial_gradient (hb_paint_funcs_t *funcs, void *paint_data, * @y0: Y coordinate of the circle's center * @start_angle: the start angle * @end_angle: the end angle - * @font: the font + * @ctx: the paint context * * Perform a "sweep-gradient" paint operation. * @@ -604,16 +604,16 @@ hb_paint_sweep_gradient (hb_paint_funcs_t *funcs, void *paint_data, hb_color_line_t *color_line, float x0, float y0, float start_angle, float end_angle, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->sweep_gradient (paint_data, color_line, x0, y0, start_angle, end_angle, font); + funcs->sweep_gradient (paint_data, color_line, x0, y0, start_angle, end_angle, ctx); } /** * hb_paint_push_group: * @funcs: paint functions * @paint_data: associated data passed by the caller - * @font: the font + * @ctx: the paint context * * Perform a "push-group" paint operation. * @@ -621,9 +621,9 @@ hb_paint_sweep_gradient (hb_paint_funcs_t *funcs, void *paint_data, */ void hb_paint_push_group (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->push_group (paint_data, font); + funcs->push_group (paint_data, ctx); } /** @@ -631,7 +631,7 @@ hb_paint_push_group (hb_paint_funcs_t *funcs, void *paint_data, * @funcs: paint functions * @paint_data: associated data passed by the caller * @mode: the compositing mode to use - * @font: the font + * @ctx: the paint context * * Perform a "pop-group" paint operation. * @@ -640,9 +640,9 @@ hb_paint_push_group (hb_paint_funcs_t *funcs, void *paint_data, void hb_paint_pop_group (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_composite_mode_t mode, - hb_font_t *font) + const hb_paint_context_t *ctx) { - funcs->pop_group (paint_data, mode, font); + funcs->pop_group (paint_data, mode, ctx); } #endif diff --git a/src/hb-paint.h b/src/hb-paint.h index 8db53b324..ccbc33bbb 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -91,6 +91,29 @@ hb_paint_funcs_make_immutable (hb_paint_funcs_t *funcs); HB_EXTERN hb_bool_t hb_paint_funcs_is_immutable (hb_paint_funcs_t *funcs); +/** + * hb_paint_context_t: + * @font: the font that is painted with + * @palette: the palette index + * @foreground: the foreground color + * + * Context information that is passed to paint functions. + */ +typedef struct hb_paint_context_t { + hb_font_t *font; + unsigned int palette; + hb_color_t foreground; + + /*< private >*/ + hb_var_num_t reserved1; + hb_var_num_t reserved2; + hb_var_num_t reserved3; + hb_var_num_t reserved4; + hb_var_num_t reserved5; + hb_var_num_t reserved6; + hb_var_num_t reserved7; +} hb_paint_context_t; + /** * hb_paint_push_transform_func_t: * @funcs: paint functions object @@ -101,7 +124,7 @@ hb_paint_funcs_is_immutable (hb_paint_funcs_t *funcs); * @yy: yy component of the transform matrix * @dx: dx component of the transform matrix * @dy: dy component of the transform matrix - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_push_transform_func() * * A virtual method for the #hb_paint_funcs_t to apply @@ -118,14 +141,14 @@ typedef void (*hb_paint_push_transform_func_t) (hb_paint_funcs_t *funcs, float xx, float yx, float xy, float yy, float dx, float dy, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** * hb_paint_pop_transform_func_t: * @funcs: paint functions object * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_pop_transform_func() * * A virtual method for the #hb_paint_funcs_t to undo @@ -136,7 +159,7 @@ typedef void (*hb_paint_push_transform_func_t) (hb_paint_funcs_t *funcs, */ typedef void (*hb_paint_pop_transform_func_t) (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** @@ -144,7 +167,7 @@ typedef void (*hb_paint_pop_transform_func_t) (hb_paint_funcs_t *funcs, * @funcs: paint functions object * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() * @glyph: the glyph ID - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_push_clip_glyph_func() * * A virtual method for the #hb_paint_funcs_t to clip @@ -162,7 +185,7 @@ typedef void (*hb_paint_pop_transform_func_t) (hb_paint_funcs_t *funcs, typedef void (*hb_paint_push_clip_glyph_func_t) (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** @@ -173,7 +196,7 @@ typedef void (*hb_paint_push_clip_glyph_func_t) (hb_paint_funcs_t *funcs, * @ymin: min Y for the rectangle * @xmax: max X for the rectangle * @ymax: max Y for the rectangle - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_push_clip_rectangle_func() * * A virtual method for the #hb_paint_funcs_t to clip @@ -192,14 +215,14 @@ typedef void (*hb_paint_push_clip_rectangle_func_t) (hb_paint_funcs_t *funcs, void *paint_data, float xmin, float ymin, float xmax, float ymax, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** * hb_paint_pop_clip_func_t: * @funcs: paint functions object * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_pop_clip_func() * * A virtual method for the #hb_paint_funcs_t to undo @@ -210,7 +233,7 @@ typedef void (*hb_paint_push_clip_rectangle_func_t) (hb_paint_funcs_t *funcs, */ typedef void (*hb_paint_pop_clip_func_t) (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** @@ -219,7 +242,7 @@ typedef void (*hb_paint_pop_clip_func_t) (hb_paint_funcs_t *funcs, * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() * @color_index: Index of a color in the fonts selected color palette * @alpha: alpha to apply in addition - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_color_func() * * A virtual method for the #hb_paint_funcs_t to paint a @@ -238,7 +261,7 @@ typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs, void *paint_data, unsigned int color_index, float alpha, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** @@ -262,7 +285,7 @@ typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs, * @image: the image data * @format: the image format as a tag * @extents: (nullable): glyph extents - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_image_func() * * A virtual method for the #hb_paint_funcs_t to paint the @@ -283,7 +306,7 @@ typedef void (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs, hb_blob_t *image, hb_tag_t format, hb_glyph_extents_t *extents, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** @@ -357,7 +380,7 @@ hb_color_line_get_extend (hb_color_line_t *color_line); * @y1: Y coordinate of the second point * @x2: X coordinate of the third point * @y2: Y coordinate of the third point - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_linear_gradient_func() * * A virtual method for the #hb_paint_funcs_t to paint a linear @@ -378,7 +401,7 @@ typedef void (*hb_paint_linear_gradient_func_t) (hb_paint_funcs_t *funcs, float x0, float y0, float x1, float y1, float x2, float y2, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** @@ -392,7 +415,7 @@ typedef void (*hb_paint_linear_gradient_func_t) (hb_paint_funcs_t *funcs, * @x1: X coordinate of the second circle's center * @y1: Y coordinate of the second circle's center * @r1: radius of the second circle - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_radial_gradient_func() * * A virtual method for the #hb_paint_funcs_t to paint a radial @@ -412,7 +435,7 @@ typedef void (*hb_paint_radial_gradient_func_t) (hb_paint_funcs_t *funcs, hb_color_line_t *color_line, float x0, float y0, float r0, float x1, float y1, float r1, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** @@ -424,7 +447,7 @@ typedef void (*hb_paint_radial_gradient_func_t) (hb_paint_funcs_t *funcs, * @y0: Y coordinate of the circle's center * @start_angle: the start angle, in radians * @end_angle: the end angle, in radians - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_sweep_gradient_func() * * A virtual method for the #hb_paint_funcs_t to paint a sweep @@ -445,7 +468,7 @@ typedef void (*hb_paint_sweep_gradient_func_t) (hb_paint_funcs_t *funcs, float x0, float y0, float start_angle, float end_angle, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** @@ -493,7 +516,7 @@ typedef enum { * hb_paint_push_group_func_t: * @funcs: paint functions object * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_push_group_func() * * A virtual method for the #hb_paint_funcs_t to use @@ -507,7 +530,7 @@ typedef enum { */ typedef void (*hb_paint_push_group_func_t) (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** @@ -515,7 +538,7 @@ typedef void (*hb_paint_push_group_func_t) (hb_paint_funcs_t *funcs, * @funcs: paint functions object * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() * @mode: the compositing mode to use - * @font: the font that is being painted + * @ctx: the paint context * @user_data: User data pointer passed to hb_paint_funcs_set_pop_group_func() * * A virtual method for the #hb_paint_funcs_t to undo @@ -531,7 +554,7 @@ typedef void (*hb_paint_push_group_func_t) (hb_paint_funcs_t *funcs, typedef void (*hb_paint_pop_group_func_t) (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_composite_mode_t mode, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data); /** @@ -743,39 +766,39 @@ hb_paint_push_transform (hb_paint_funcs_t *funcs, void *paint_data, float xx, float yx, float xy, float yy, float dx, float dy, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_EXTERN void hb_paint_pop_transform (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_EXTERN void hb_paint_push_clip_glyph (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_EXTERN void hb_paint_push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data, float xmin, float ymin, float xmax, float ymax, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_EXTERN void hb_paint_pop_clip (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_EXTERN void hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data, unsigned int color_index, float alpha, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_EXTERN void hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data, hb_blob_t *image, hb_tag_t format, hb_glyph_extents_t *extents, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_EXTERN void hb_paint_linear_gradient (hb_paint_funcs_t *funcs, void *paint_data, @@ -783,7 +806,7 @@ hb_paint_linear_gradient (hb_paint_funcs_t *funcs, void *paint_data, float x0, float y0, float x1, float y1, float x2, float y2, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_EXTERN void hb_paint_radial_gradient (hb_paint_funcs_t *funcs, void *paint_data, @@ -792,23 +815,23 @@ hb_paint_radial_gradient (hb_paint_funcs_t *funcs, void *paint_data, float r0, float x1, float y1, float r1, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_EXTERN void hb_paint_sweep_gradient (hb_paint_funcs_t *funcs, void *paint_data, hb_color_line_t *color_line, float x0, float y0, float start_angle, float end_angle, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_EXTERN void hb_paint_push_group (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_EXTERN void hb_paint_pop_group (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_composite_mode_t mode, - hb_font_t *font); + const hb_paint_context_t *ctx); HB_END_DECLS diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 7e301c00f..4412d81d3 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -70,126 +70,128 @@ struct hb_paint_funcs_t float xx, float yx, float xy, float yy, float dx, float dy, - hb_font_t *font) + const hb_paint_context_t *ctx) { func.push_transform (this, paint_data, xx, yx, xy, yy, dx, dy, - font, + ctx, !user_data ? nullptr : user_data->push_transform); } void pop_transform (void *paint_data, - hb_font_t *font) - { func.pop_transform (this, paint_data, font, + const hb_paint_context_t *ctx) + { func.pop_transform (this, paint_data, ctx, !user_data ? nullptr : user_data->pop_transform); } void push_clip_glyph (void *paint_data, hb_codepoint_t glyph, - hb_font_t *font) + const hb_paint_context_t *ctx) { func.push_clip_glyph (this, paint_data, glyph, - font, + ctx, !user_data ? nullptr : user_data->push_clip_glyph); } void push_clip_rectangle (void *paint_data, float xmin, float ymin, float xmax, float ymax, - hb_font_t *font) + const hb_paint_context_t *ctx) { func.push_clip_rectangle (this, paint_data, xmin, ymin, xmax, ymax, - font, + ctx, !user_data ? nullptr : user_data->push_clip_rectangle); } void pop_clip (void *paint_data, - hb_font_t *font) - { func.pop_clip (this, paint_data, font, + const hb_paint_context_t *ctx) + { func.pop_clip (this, paint_data, ctx, !user_data ? nullptr : user_data->pop_clip); } void color (void *paint_data, unsigned int color_index, float alpha, - hb_font_t *font) + const hb_paint_context_t *ctx) { func.color (this, paint_data, color_index, alpha, - font, + ctx, !user_data ? nullptr : user_data->color); } void image (void *paint_data, hb_blob_t *image, hb_tag_t format, hb_glyph_extents_t *extents, - hb_font_t *font) + const hb_paint_context_t *ctx) { func.image (this, paint_data, image, format, extents, - font, + ctx, !user_data ? nullptr : user_data->image); } void linear_gradient (void *paint_data, hb_color_line_t *color_line, float x0, float y0, float x1, float y1, float x2, float y2, - hb_font_t *font) + const hb_paint_context_t *ctx) { func.linear_gradient (this, paint_data, color_line, x0, y0, x1, y1, x2, y2, - font, + ctx, !user_data ? nullptr : user_data->linear_gradient); } void radial_gradient (void *paint_data, hb_color_line_t *color_line, float x0, float y0, float r0, float x1, float y1, float r1, - hb_font_t *font) + const hb_paint_context_t *ctx) { func.radial_gradient (this, paint_data, color_line, x0, y0, r0, x1, y1, r1, - font, + ctx, !user_data ? nullptr : user_data->radial_gradient); } void sweep_gradient (void *paint_data, hb_color_line_t *color_line, float x0, float y0, float start_angle, float end_angle, - hb_font_t *font) + const hb_paint_context_t *ctx) { func.sweep_gradient (this, paint_data, color_line, x0, y0, start_angle, end_angle, - font, + ctx, !user_data ? nullptr : user_data->sweep_gradient); } void push_group (void *paint_data, - hb_font_t *font) - { func.push_group (this, paint_data, font, + const hb_paint_context_t *ctx) + { func.push_group (this, paint_data, ctx, !user_data ? nullptr : user_data->push_group); } void pop_group (void *paint_data, hb_paint_composite_mode_t mode, - hb_font_t *font) + const hb_paint_context_t *ctx) { func.pop_group (this, paint_data, mode, - font, + ctx, !user_data ? nullptr : user_data->pop_group); } void push_root_transform (void *paint_data, - hb_font_t *font) + const hb_paint_context_t *ctx) { + hb_font_t *font = ctx->font; int xscale = font->x_scale, yscale = font->y_scale; float upem = font->face->get_upem (); float slant = font->slant_xy; func.push_transform (this, paint_data, xscale/upem, 0, slant * yscale/upem, yscale/upem, 0, 0, - font, + ctx, !user_data ? nullptr : user_data->push_transform); } void pop_root_transform (void *paint_data, - hb_font_t *font) + const hb_paint_context_t *ctx) { - func.pop_transform (this, paint_data, font, + func.pop_transform (this, paint_data, ctx, !user_data ? nullptr : user_data->pop_transform); } void push_inverse_root_transform (void *paint_data, - hb_font_t *font) + const hb_paint_context_t *ctx) { + hb_font_t *font = ctx->font; int xscale = font->x_scale, yscale = font->y_scale; float upem = font->face->get_upem (); float slant = font->slant_xy; func.push_transform (this, paint_data, upem/xscale, 0, -slant * upem/xscale, upem/yscale, 0, 0, - font, + ctx, !user_data ? nullptr : user_data->push_transform); } void pop_inverse_root_transform (void *paint_data, - hb_font_t *font) + const hb_paint_context_t *ctx) { - func.pop_transform (this, paint_data, font, + func.pop_transform (this, paint_data, ctx, !user_data ? nullptr : user_data->pop_transform); } }; diff --git a/test/api/results/hand-20-0-10 b/test/api/results/hand-20-0-10 index 42160b529..dc022ef00 100644 --- a/test/api/results/hand-20-0-10 +++ b/test/api/results/hand-20-0-10 @@ -1,6 +1,6 @@ start transform 0.019531 0.000000 0.000000 0.019531 0.000000 0.000000 push group - start transform 51.200001 0.000000 0.000000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -0.000000 51.200001 0.000000 0.000000 start clip glyph 13 start transform 1.000000 0.000000 0.000000 0.976807 0.000000 0.000000 radial gradient @@ -16,7 +16,7 @@ start transform 0.019531 0.000000 0.000000 0.019531 0.000000 0.000000 end transform pop group mode 3 push group - start transform 51.200001 0.000000 0.000000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -0.000000 51.200001 0.000000 0.000000 start clip glyph 14 linear gradient p0 231.000000 -27.000000 @@ -29,21 +29,21 @@ start transform 0.019531 0.000000 0.000000 0.019531 0.000000 0.000000 end transform pop group mode 3 push group - start transform 51.200001 0.000000 0.000000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -0.000000 51.200001 0.000000 0.000000 start clip glyph 15 solid 9 1.000000 end clip end transform pop group mode 3 push group - start transform 51.200001 0.000000 0.000000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -0.000000 51.200001 0.000000 0.000000 start clip glyph 16 solid 0 1.000000 end clip end transform pop group mode 3 push group - start transform 51.200001 0.000000 0.000000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -0.000000 51.200001 0.000000 0.000000 start clip glyph 21 solid 9 1.000000 end clip @@ -51,7 +51,7 @@ start transform 0.019531 0.000000 0.000000 0.019531 0.000000 0.000000 pop group mode 3 push group push group - start transform 51.200001 0.000000 0.000000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -0.000000 51.200001 0.000000 0.000000 start clip glyph 16 linear gradient p0 669.000000 776.000000 @@ -64,7 +64,7 @@ start transform 0.019531 0.000000 0.000000 0.019531 0.000000 0.000000 end transform pop group mode 3 push group - start transform 51.200001 0.000000 0.000000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -0.000000 51.200001 0.000000 0.000000 start clip glyph 18 solid 2 0.200012 end clip @@ -72,7 +72,7 @@ start transform 0.019531 0.000000 0.000000 0.019531 0.000000 0.000000 pop group mode 3 pop group mode 3 push group - start transform 51.200001 0.000000 0.000000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -0.000000 51.200001 0.000000 0.000000 start clip glyph 19 start transform 1.000000 0.000000 0.000000 0.969116 0.000000 0.000000 radial gradient @@ -88,7 +88,7 @@ start transform 0.019531 0.000000 0.000000 0.019531 0.000000 0.000000 end transform pop group mode 3 push group - start transform 51.200001 0.000000 0.000000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -0.000000 51.200001 0.000000 0.000000 start clip glyph 20 solid 9 1.000000 end clip diff --git a/test/api/results/hand-20-0.2-10 b/test/api/results/hand-20-0.2-10 index 569bd24db..536cd0c1b 100644 --- a/test/api/results/hand-20-0.2-10 +++ b/test/api/results/hand-20-0.2-10 @@ -1,6 +1,6 @@ start transform 0.019531 0.000000 0.003906 0.019531 0.000000 0.000000 push group - start transform 51.200001 0.000000 10.240000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -10.240000 51.200001 0.000000 0.000000 start clip glyph 13 start transform 1.000000 0.000000 0.000000 0.976807 0.000000 0.000000 radial gradient @@ -16,7 +16,7 @@ start transform 0.019531 0.000000 0.003906 0.019531 0.000000 0.000000 end transform pop group mode 3 push group - start transform 51.200001 0.000000 10.240000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -10.240000 51.200001 0.000000 0.000000 start clip glyph 14 linear gradient p0 231.000000 -27.000000 @@ -29,21 +29,21 @@ start transform 0.019531 0.000000 0.003906 0.019531 0.000000 0.000000 end transform pop group mode 3 push group - start transform 51.200001 0.000000 10.240000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -10.240000 51.200001 0.000000 0.000000 start clip glyph 15 solid 9 1.000000 end clip end transform pop group mode 3 push group - start transform 51.200001 0.000000 10.240000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -10.240000 51.200001 0.000000 0.000000 start clip glyph 16 solid 0 1.000000 end clip end transform pop group mode 3 push group - start transform 51.200001 0.000000 10.240000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -10.240000 51.200001 0.000000 0.000000 start clip glyph 21 solid 9 1.000000 end clip @@ -51,7 +51,7 @@ start transform 0.019531 0.000000 0.003906 0.019531 0.000000 0.000000 pop group mode 3 push group push group - start transform 51.200001 0.000000 10.240000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -10.240000 51.200001 0.000000 0.000000 start clip glyph 16 linear gradient p0 669.000000 776.000000 @@ -64,7 +64,7 @@ start transform 0.019531 0.000000 0.003906 0.019531 0.000000 0.000000 end transform pop group mode 3 push group - start transform 51.200001 0.000000 10.240000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -10.240000 51.200001 0.000000 0.000000 start clip glyph 18 solid 2 0.200012 end clip @@ -72,7 +72,7 @@ start transform 0.019531 0.000000 0.003906 0.019531 0.000000 0.000000 pop group mode 3 pop group mode 3 push group - start transform 51.200001 0.000000 10.240000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -10.240000 51.200001 0.000000 0.000000 start clip glyph 19 start transform 1.000000 0.000000 0.000000 0.969116 0.000000 0.000000 radial gradient @@ -88,7 +88,7 @@ start transform 0.019531 0.000000 0.003906 0.019531 0.000000 0.000000 end transform pop group mode 3 push group - start transform 51.200001 0.000000 10.240000 51.200001 0.000000 0.000000 + start transform 51.200001 0.000000 -10.240000 51.200001 0.000000 0.000000 start clip glyph 20 solid 9 1.000000 end clip diff --git a/test/api/results/test-20-0-10 b/test/api/results/test-20-0-10 index e3238328a..1c34a136f 100644 --- a/test/api/results/test-20-0-10 +++ b/test/api/results/test-20-0-10 @@ -1,5 +1,5 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 174 sweep gradient center 500.000000 600.000000 diff --git a/test/api/results/test-20-0-106 b/test/api/results/test-20-0-106 index e16d01c71..323940afe 100644 --- a/test/api/results/test-20-0-106 +++ b/test/api/results/test-20-0-106 @@ -1,6 +1,6 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 push group - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 3 solid 4 0.500000 end clip @@ -9,7 +9,7 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 start transform 0.000000 0.000000 0.000000 0.000000 1000.000000 1000.000000 start transform 1.000000 -0.363874 -0.176283 1.000000 0.000000 0.000000 start transform 0.000000 0.000000 0.000000 0.000000 -1000.000000 -1000.000000 - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 3 solid 1 0.700012 end clip diff --git a/test/api/results/test-20-0-116 b/test/api/results/test-20-0-116 index 751b8e8a8..6c7ffd355 100644 --- a/test/api/results/test-20-0-116 +++ b/test/api/results/test-20-0-116 @@ -1,13 +1,13 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 push group - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 3 solid 4 0.500000 end clip end transform push group start transform 1.000000 0.000000 0.000000 1.000000 200.000000 200.000000 - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 3 solid 1 0.700012 end clip diff --git a/test/api/results/test-20-0-123 b/test/api/results/test-20-0-123 index b97987fc7..296c3eebb 100644 --- a/test/api/results/test-20-0-123 +++ b/test/api/results/test-20-0-123 @@ -1,6 +1,6 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 push group - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 3 solid 10 1.000000 end clip @@ -11,7 +11,7 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 start transform 0.000000 0.000000 0.000000 0.000000 333.000000 667.000000 start transform 8192.000000 0.000000 0.000000 8192.000000 0.000000 0.000000 start transform 0.000000 0.000000 0.000000 0.000000 -333.000000 -667.000000 - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 2 solid 12 1.000000 end clip @@ -23,7 +23,7 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 start transform 0.000000 0.000000 0.000000 0.000000 667.000000 333.000000 start transform 8192.000000 0.000000 0.000000 8192.000000 0.000000 0.000000 start transform 0.000000 0.000000 0.000000 0.000000 -667.000000 -333.000000 - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 2 solid 11 1.000000 end clip diff --git a/test/api/results/test-20-0-165 b/test/api/results/test-20-0-165 index 2fade5352..cea5dd9ce 100644 --- a/test/api/results/test-20-0-165 +++ b/test/api/results/test-20-0-165 @@ -1,5 +1,5 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 165 linear gradient p0 100.000000 950.000000 diff --git a/test/api/results/test-20-0-175 b/test/api/results/test-20-0-175 index 1b13c45f3..83dac5ee3 100644 --- a/test/api/results/test-20-0-175 +++ b/test/api/results/test-20-0-175 @@ -1,7 +1,7 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 push group start transform 1.000000 0.000000 0.000000 1.000000 150.000000 0.000000 - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 174 solid 3 1.000000 end clip @@ -10,7 +10,7 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 pop group mode 3 push group start transform 1.000000 0.000000 0.000000 1.000000 -150.000000 0.000000 - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 174 linear gradient p0 500.000000 250.000000 diff --git a/test/api/results/test-20-0-6 b/test/api/results/test-20-0-6 index 4bd5c8f0a..c165e62d4 100644 --- a/test/api/results/test-20-0-6 +++ b/test/api/results/test-20-0-6 @@ -1,5 +1,5 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 6 linear gradient p0 100.000000 250.000000 diff --git a/test/api/results/test-20-0-92 b/test/api/results/test-20-0-92 index 40bd05742..51d5b2fa2 100644 --- a/test/api/results/test-20-0-92 +++ b/test/api/results/test-20-0-92 @@ -1,5 +1,5 @@ start transform 0.020000 0.000000 0.000000 0.020000 0.000000 0.000000 - start transform 50.000000 0.000000 0.000000 50.000000 0.000000 0.000000 + start transform 50.000000 0.000000 -0.000000 50.000000 0.000000 0.000000 start clip glyph 2 radial gradient p0 166.000000 768.000000 radius 0.000000 diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c index de5d81b26..a63ecc9da 100644 --- a/test/api/test-ot-color.c +++ b/test/api/test-ot-color.c @@ -484,7 +484,7 @@ push_transform (hb_paint_funcs_t *funcs, float xx, float yx, float xy, float yy, float dx, float dy, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -496,7 +496,7 @@ push_transform (hb_paint_funcs_t *funcs, static void pop_transform (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -509,7 +509,7 @@ static void push_clip_glyph (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -522,7 +522,7 @@ static void push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data, float xmin, float ymin, float xmax, float ymax, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -534,7 +534,7 @@ push_clip_rectangle (hb_paint_funcs_t *funcs, static void pop_clip (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -548,7 +548,7 @@ paint_color (hb_paint_funcs_t *funcs, void *paint_data, unsigned int color_index, float alpha, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -562,7 +562,7 @@ paint_image (hb_paint_funcs_t *funcs, hb_blob_t *blob, hb_tag_t format, hb_glyph_extents_t *extents, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -598,7 +598,7 @@ paint_linear_gradient (hb_paint_funcs_t *funcs, float x0, float y0, float x1, float y1, float x2, float y2, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -619,7 +619,7 @@ paint_radial_gradient (hb_paint_funcs_t *funcs, hb_color_line_t *color_line, float x0, float y0, float r0, float x1, float y1, float r1, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -640,7 +640,7 @@ paint_sweep_gradient (hb_paint_funcs_t *funcs, float cx, float cy, float start_angle, float end_angle, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -657,7 +657,7 @@ paint_sweep_gradient (hb_paint_funcs_t *funcs, static void push_group (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -669,7 +669,7 @@ static void pop_group (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_composite_mode_t mode, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { paint_data_t *data = user_data; @@ -736,7 +736,7 @@ test_hb_ot_color_colr_v1 (gconstpointer d) data.string = g_string_new (""); data.level = 0; - hb_font_paint_glyph (font, test->glyph, funcs, &data); + hb_font_paint_glyph (font, test->glyph, funcs, &data, 0, HB_COLOR (0, 0, 0, 255)); /* Run * diff --git a/util/hb-cairo-utils.c b/util/hb-cairo-utils.c index 95b2feca5..f3eb69435 100644 --- a/util/hb-cairo-utils.c +++ b/util/hb-cairo-utils.c @@ -70,35 +70,26 @@ cairo_extend (hb_paint_extend_t extend) return CAIRO_EXTEND_PAD; } -hb_bool_t -hb_cairo_get_font_color (hb_font_t *font, - unsigned int palette_index, +void +hb_cairo_get_font_color (const hb_paint_context_t *ctx, unsigned int color_index, float alpha, float *r, float *g, float *b, float *a) { + hb_color_t color = ctx->foreground; + if (color_index != 0xffff) { - hb_color_t color; unsigned int clen = 1; - hb_face_t *face = hb_font_get_face (font); + hb_face_t *face = hb_font_get_face (ctx->font); - if (hb_ot_color_palette_get_colors (face, palette_index, color_index, &clen, &color)) - { - *r = hb_color_get_red (color) / 255.f; - *g = hb_color_get_green (color) / 255.f; - *b = hb_color_get_blue (color) / 255.f; - *a = (hb_color_get_alpha (color) / 255.f) * alpha; - - return TRUE; - } + hb_ot_color_palette_get_colors (face, ctx->palette, color_index, &clen, &color); } - /* foreground color */ - *r = *g = *b = 0; - *a = alpha; - - return FALSE; + *r = hb_color_get_red (color) / 255.f; + *g = hb_color_get_green (color) / 255.f; + *b = hb_color_get_blue (color) / 255.f; + *a = (hb_color_get_alpha (color) / 255.f) * alpha; } typedef struct @@ -129,7 +120,7 @@ read_blob (void *closure, void hb_cairo_paint_glyph_image (cairo_t *cr, - hb_font_t *font, + const hb_paint_context_t *ctx, hb_blob_t *blob, hb_tag_t format, hb_glyph_extents_t *extents) @@ -237,7 +228,7 @@ normalize_color_line (hb_color_stop_t *stops, void hb_cairo_paint_linear_gradient (cairo_t *cr, - hb_font_t *font, + const hb_paint_context_t *ctx, hb_color_line_t *color_line, float x0, float y0, float x1, float y1, @@ -269,7 +260,7 @@ hb_cairo_paint_linear_gradient (cairo_t *cr, for (unsigned int i = 0; i < len; i++) { float r, g, b, a; - hb_cairo_get_font_color (font, 0, stops[i].color_index, stops[i].alpha, &r, &g, &b, &a); + hb_cairo_get_font_color (ctx, stops[i].color_index, stops[i].alpha, &r, &g, &b, &a); cairo_pattern_add_color_stop_rgba (pattern, stops[i].offset, r, g, b, a); } @@ -284,7 +275,7 @@ hb_cairo_paint_linear_gradient (cairo_t *cr, void hb_cairo_paint_radial_gradient (cairo_t *cr, - hb_font_t *font, + const hb_paint_context_t *ctx, hb_color_line_t *color_line, float x0, float y0, float r0, float x1, float y1, float r1) @@ -317,7 +308,7 @@ hb_cairo_paint_radial_gradient (cairo_t *cr, for (unsigned int i = 0; i < len; i++) { float r, g, b, a; - hb_cairo_get_font_color (font, 0, stops[i].color_index, stops[i].alpha, &r, &g, &b, &a); + hb_cairo_get_font_color (ctx, stops[i].color_index, stops[i].alpha, &r, &g, &b, &a); cairo_pattern_add_color_stop_rgba (pattern, stops[i].offset, r, g, b, a); } @@ -472,7 +463,7 @@ add_sweep_gradient_patches1 (float cx, float cy, float radius, } static void -add_sweep_gradient_patches (hb_font_t *font, +add_sweep_gradient_patches (const hb_paint_context_t *ctx, hb_color_stop_t *stops, unsigned int n_stops, cairo_extend_t extend, @@ -495,7 +486,7 @@ add_sweep_gradient_patches (hb_font_t *font, color_t c; if (start_angle > 0) { - hb_cairo_get_font_color (font, 0, stops[0].color_index, stops[0].alpha, &c.r, &c.g, &c.b, &c.a); + hb_cairo_get_font_color (ctx, stops[0].color_index, stops[0].alpha, &c.r, &c.g, &c.b, &c.a); add_sweep_gradient_patches1 (cx, cy, radius, 0., &c, start_angle, &c, @@ -503,7 +494,7 @@ add_sweep_gradient_patches (hb_font_t *font, } if (end_angle < 2 * M_PI) { - hb_cairo_get_font_color (font, 0, stops[n_stops-1].color_index, stops[n_stops-1].alpha, &c.r, &c.g, &c.b, &c.a); + hb_cairo_get_font_color (ctx, stops[n_stops-1].color_index, stops[n_stops-1].alpha, &c.r, &c.g, &c.b, &c.a); add_sweep_gradient_patches1 (cx, cy, radius, end_angle, &c, 2 * M_PI, &c, @@ -539,7 +530,7 @@ add_sweep_gradient_patches (hb_font_t *font, for (unsigned i = 0; i < n_stops; i++) { angles[i] = start_angle + stops[i].offset * (end_angle - start_angle); - hb_cairo_get_font_color (font, 0, stops[i].color_index, stops[i].alpha, &colors[i].r, &colors[i].g, &colors[i].b, &colors[i].a); + hb_cairo_get_font_color (ctx, stops[i].color_index, stops[i].alpha, &colors[i].r, &colors[i].g, &colors[i].b, &colors[i].a); } if (extend == CAIRO_EXTEND_PAD) @@ -717,7 +708,7 @@ done: void hb_cairo_paint_sweep_gradient (cairo_t *cr, - hb_font_t *font, + const hb_paint_context_t *ctx, hb_color_line_t *color_line, float cx, float cy, float start_angle, @@ -746,7 +737,7 @@ hb_cairo_paint_sweep_gradient (cairo_t *cr, extend = cairo_extend (hb_color_line_get_extend (color_line)); pattern = cairo_pattern_create_mesh (); - add_sweep_gradient_patches (font, stops, len, extend, cx, cy, + add_sweep_gradient_patches (ctx, stops, len, extend, cx, cy, radius, start_angle, end_angle, pattern); cairo_set_source (cr, pattern); diff --git a/util/hb-cairo-utils.h b/util/hb-cairo-utils.h index 359616658..e372336c1 100644 --- a/util/hb-cairo-utils.h +++ b/util/hb-cairo-utils.h @@ -70,33 +70,32 @@ hb_paint_composite_mode_to_cairo (hb_paint_composite_mode_t mode) return CAIRO_OPERATOR_SOURCE; } -hb_bool_t hb_cairo_get_font_color (hb_font_t *font, - unsigned int palette_index, - unsigned int color_index, - float alpha, - float *r, float *g, float *b, float *a); +void hb_cairo_get_font_color (const hb_paint_context_t *ctx, + unsigned int color_index, + float alpha, + float *r, float *g, float *b, float *a); void hb_cairo_paint_glyph_image (cairo_t *cr, - hb_font_t *font, + const hb_paint_context_t *ctx, hb_blob_t *blob, hb_tag_t format, hb_glyph_extents_t *extents); void hb_cairo_paint_linear_gradient (cairo_t *cr, - hb_font_t *font, + const hb_paint_context_t *ctx, hb_color_line_t *color_line, float x0, float y0, float x1, float y1, float x2, float y2); void hb_cairo_paint_radial_gradient (cairo_t *cr, - hb_font_t *font, + const hb_paint_context_t *ctx, hb_color_line_t *color_line, float x0, float y0, float r0, float x1, float y1, float r1); void hb_cairo_paint_sweep_gradient (cairo_t *cr, - hb_font_t *font, + const hb_paint_context_t *ctx, hb_color_line_t *color_line, float x0, float y0, float start_angle, float end_angle); diff --git a/util/helper-cairo-user.hh b/util/helper-cairo-user.hh index ce5ebda46..b4ca8f9e2 100644 --- a/util/helper-cairo-user.hh +++ b/util/helper-cairo-user.hh @@ -111,7 +111,7 @@ push_transform (hb_paint_funcs_t *funcs, float xx, float yx, float xy, float yy, float dx, float dy, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; @@ -127,7 +127,7 @@ push_transform (hb_paint_funcs_t *funcs, static void pop_transform (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; @@ -139,14 +139,14 @@ static void push_clip_glyph (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; cairo_save (cr); cairo_new_path (cr); - hb_font_draw_glyph (font, glyph, get_cairo_draw_funcs (), cr); + hb_font_draw_glyph (ctx->font, glyph, get_cairo_draw_funcs (), cr); cairo_close_path (cr); cairo_clip (cr); } @@ -155,7 +155,7 @@ static void push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data, float xmin, float ymin, float xmax, float ymax, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; @@ -170,7 +170,7 @@ push_clip_rectangle (hb_paint_funcs_t *funcs, static void pop_clip (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; @@ -181,7 +181,7 @@ pop_clip (hb_paint_funcs_t *funcs, static void push_group (hb_paint_funcs_t *funcs, void *paint_data, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; @@ -194,7 +194,7 @@ static void pop_group (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_composite_mode_t mode, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; @@ -211,13 +211,13 @@ paint_color (hb_paint_funcs_t *funcs, void *paint_data, unsigned int color_index, float alpha, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; float r, g, b, a; - hb_cairo_get_font_color (font, 0, color_index, alpha, &r, &g, &b, &a); + hb_cairo_get_font_color (ctx, color_index, alpha, &r, &g, &b, &a); cairo_set_source_rgba (cr, (double)r, (double)g, (double)b, (double)a); cairo_paint (cr); } @@ -228,12 +228,12 @@ paint_image (hb_paint_funcs_t *funcs, hb_blob_t *blob, hb_tag_t format, hb_glyph_extents_t *extents, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; - hb_cairo_paint_glyph_image (cr, font, blob, format, extents); + hb_cairo_paint_glyph_image (cr, ctx, blob, format, extents); } static void @@ -243,12 +243,12 @@ paint_linear_gradient (hb_paint_funcs_t *funcs, float x0, float y0, float x1, float y1, float x2, float y2, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; - hb_cairo_paint_linear_gradient (cr, font, color_line, x0, y0, x1, y1, x2, y2); + hb_cairo_paint_linear_gradient (cr, ctx, color_line, x0, y0, x1, y1, x2, y2); } static void @@ -257,12 +257,12 @@ paint_radial_gradient (hb_paint_funcs_t *funcs, hb_color_line_t *color_line, float x0, float y0, float r0, float x1, float y1, float r1, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; - hb_cairo_paint_radial_gradient (cr, font, color_line, x0, y0, r0, x1, y1, r1); + hb_cairo_paint_radial_gradient (cr, ctx, color_line, x0, y0, r0, x1, y1, r1); } static void @@ -271,12 +271,12 @@ paint_sweep_gradient (hb_paint_funcs_t *funcs, hb_color_line_t *color_line, float x0, float y0, float start_angle, float end_angle, - hb_font_t *font, + const hb_paint_context_t *ctx, void *user_data) { cairo_t *cr = (cairo_t *)paint_data; - hb_cairo_paint_sweep_gradient (cr, font, color_line, x0, y0, start_angle, end_angle); + hb_cairo_paint_sweep_gradient (cr, ctx, color_line, x0, y0, start_angle, end_angle); } static hb_paint_funcs_t * @@ -355,7 +355,7 @@ render_color_glyph (cairo_scaled_font_t *scaled_font, hb_font_get_scale (font, &x_scale, &y_scale); cairo_scale (cr, +1./x_scale, -1./y_scale); - hb_font_paint_glyph (font, glyph, get_cairo_paint_funcs (), cr); + hb_font_paint_glyph (font, glyph, get_cairo_paint_funcs (), cr, 0, HB_COLOR (0, 0, 0, 255)); hb_glyph_extents_t hb_extents; hb_font_get_glyph_extents (font, glyph, &hb_extents);