From 3199d1c1f5a3eecc9f64c7bf79d649f1950e38d2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 2 Mar 2025 18:35:46 -0700 Subject: [PATCH] [VARC] Use a context object to pass arguments around --- src/OT/Var/VARC/VARC.cc | 78 ++++++++++++++------------------- src/OT/Var/VARC/VARC.hh | 95 +++++++++++++++++------------------------ 2 files changed, 71 insertions(+), 102 deletions(-) diff --git a/src/OT/Var/VARC/VARC.cc b/src/OT/Var/VARC/VARC.cc index dacad44cf..27a26927b 100644 --- a/src/OT/Var/VARC/VARC.cc +++ b/src/OT/Var/VARC/VARC.cc @@ -126,25 +126,18 @@ hb_transforming_pen_get_funcs () return static_transforming_pen_funcs.get_unconst (); } - hb_ubytes_t -VarComponent::get_path_at (hb_font_t *font, +VarComponent::get_path_at (const hb_varc_context_t &c, hb_codepoint_t parent_gid, - hb_draw_session_t *draw_session, - hb_extents_t *extents, hb_array_t coords, hb_transform_t total_transform, hb_ubytes_t total_record, - hb_decycler_t *decycler, - signed *edges_left, - signed depth_left, - hb_glyf_scratch_t &scratch, VarRegionList::cache_t *cache) const { const unsigned char *end = total_record.arrayZ + total_record.length; const unsigned char *record = total_record.arrayZ; - auto &VARC = *font->face->table.VARC->table; + auto &VARC = *c.font->face->table.VARC->table; auto &varStore = &VARC+VARC.varStore; #define READ_UINT32VAR(name) \ @@ -194,9 +187,9 @@ VarComponent::get_path_at (hb_font_t *font, // Axis values - auto &axisIndices = scratch.axisIndices; + auto &axisIndices = c.scratch.axisIndices; axisIndices.clear (); - auto &axisValues = scratch.axisValues; + auto &axisValues = c.scratch.axisValues; axisValues.clear (); if (flags & (unsigned) flags_t::HAVE_AXES) { @@ -223,7 +216,7 @@ VarComponent::get_path_at (hb_font_t *font, * limit on the max number of coords for now. */ if ((flags & (unsigned) flags_t::RESET_UNSPECIFIED_AXES) || coords.length > HB_VAR_COMPOSITE_MAX_AXES) - component_coords = hb_array (font->coords, font->num_coords); + component_coords = hb_array (c.font->coords, c.font->num_coords); // Transform @@ -317,19 +310,18 @@ VarComponent::get_path_at (hb_font_t *font, transform.scaleY = transform.scaleX; total_transform.transform (transform.to_transform ()); - total_transform.scale (font->x_mult ? 1.f / font->x_multf : 0.f, - font->y_mult ? 1.f / font->y_multf : 0.f); + total_transform.scale (c.font->x_mult ? 1.f / c.font->x_multf : 0.f, + c.font->y_mult ? 1.f / c.font->y_multf : 0.f); bool same_coords = component_coords.length == coords.length && component_coords.arrayZ == coords.arrayZ; - VARC.get_path_at (font, gid, - draw_session, extents, + c.depth_left--; + VARC.get_path_at (c, gid, component_coords, total_transform, parent_gid, - decycler, edges_left, depth_left - 1, - scratch, same_coords ? cache : nullptr); + c.depth_left++; } #undef PROCESS_TRANSFORM_COMPONENTS @@ -339,17 +331,11 @@ VarComponent::get_path_at (hb_font_t *font, } bool -VARC::get_path_at (hb_font_t *font, +VARC::get_path_at (const hb_varc_context_t &c, hb_codepoint_t glyph, - hb_draw_session_t *draw_session, - hb_extents_t *extents, hb_array_t coords, hb_transform_t transform, hb_codepoint_t parent_glyph, - hb_decycler_t *decycler, - signed *edges_left, - signed depth_left, - hb_glyf_scratch_t &scratch, VarRegionList::cache_t *parent_cache) const { // Don't recurse on the same glyph. @@ -358,49 +344,49 @@ VARC::get_path_at (hb_font_t *font, (this+coverage).get_coverage (glyph); if (idx == NOT_COVERED) { - if (draw_session) + if (c.draw_session) { // Build a transforming pen to apply the transform. hb_draw_funcs_t *transformer_funcs = hb_transforming_pen_get_funcs (); hb_transforming_pen_context_t context {transform, - draw_session->funcs, - draw_session->draw_data, - &draw_session->st}; + c.draw_session->funcs, + c.draw_session->draw_data, + &c.draw_session->st}; hb_draw_session_t transformer_session {transformer_funcs, &context}; - hb_draw_session_t &shape_draw_session = transform.is_identity () ? *draw_session : transformer_session; + hb_draw_session_t &shape_draw_session = transform.is_identity () ? *c.draw_session : transformer_session; - if (!font->face->table.glyf->get_path_at (font, glyph, shape_draw_session, coords, scratch)) + if (!c.font->face->table.glyf->get_path_at (c.font, glyph, shape_draw_session, coords, c.scratch)) #ifndef HB_NO_CFF - if (!font->face->table.cff2->get_path_at (font, glyph, shape_draw_session, coords)) - if (!font->face->table.cff1->get_path (font, glyph, shape_draw_session)) // Doesn't have variations + if (!c.font->face->table.cff2->get_path_at (c.font, glyph, shape_draw_session, coords)) + if (!c.font->face->table.cff1->get_path (c.font, glyph, shape_draw_session)) // Doesn't have variations #endif return false; } - if (extents) + else if (c.extents) { hb_glyph_extents_t glyph_extents; - if (!font->face->table.glyf->get_extents_at (font, glyph, &glyph_extents, coords)) + if (!c.font->face->table.glyf->get_extents_at (c.font, glyph, &glyph_extents, coords)) #ifndef HB_NO_CFF - if (!font->face->table.cff2->get_extents_at (font, glyph, &glyph_extents, coords)) - if (!font->face->table.cff1->get_extents (font, glyph, &glyph_extents)) // Doesn't have variations + if (!c.font->face->table.cff2->get_extents_at (c.font, glyph, &glyph_extents, coords)) + if (!c.font->face->table.cff1->get_extents (c.font, glyph, &glyph_extents)) // Doesn't have variations #endif return false; hb_extents_t comp_extents (glyph_extents); transform.transform_extents (comp_extents); - extents->union_ (comp_extents); + c.extents->union_ (comp_extents); } return true; } - if (depth_left <= 0) + if (c.depth_left <= 0) return true; - if (*edges_left <= 0) + if (c.edges_left <= 0) return true; - (*edges_left)--; + (c.edges_left)--; - hb_decycler_node_t node (*decycler); + hb_decycler_node_t node (c.decycler); if (unlikely (!node.visit (glyph))) return true; @@ -411,14 +397,12 @@ VARC::get_path_at (hb_font_t *font, parent_cache : (this+varStore).create_cache (hb_array (static_cache)); - transform.scale (font->x_multf, font->y_multf); + transform.scale (c.font->x_multf, c.font->y_multf); - VarCompositeGlyph::get_path_at (font, glyph, - draw_session, extents, + VarCompositeGlyph::get_path_at (c, + glyph, coords, transform, record, - decycler, edges_left, depth_left, - scratch, cache); if (cache != parent_cache) diff --git a/src/OT/Var/VARC/VARC.hh b/src/OT/Var/VARC/VARC.hh index 8678195cd..808db0201 100644 --- a/src/OT/Var/VARC/VARC.hh +++ b/src/OT/Var/VARC/VARC.hh @@ -21,6 +21,17 @@ namespace OT { #ifndef HB_NO_VAR_COMPOSITES +struct hb_varc_context_t +{ + hb_font_t *font; + hb_draw_session_t *draw_session; + hb_extents_t *extents; + mutable hb_decycler_t decycler; + mutable signed edges_left; + mutable signed depth_left; + hb_glyf_scratch_t &scratch; +}; + struct VarComponent { enum class flags_t : uint32_t @@ -44,44 +55,32 @@ struct VarComponent }; HB_INTERNAL hb_ubytes_t - get_path_at (hb_font_t *font, + get_path_at (const hb_varc_context_t &c, hb_codepoint_t parent_gid, - hb_draw_session_t *draw_session, - hb_extents_t *extents, hb_array_t coords, hb_transform_t transform, hb_ubytes_t record, - hb_decycler_t *decycler, - signed *edges_left, - signed depth_left, - hb_glyf_scratch_t &scratch, VarRegionList::cache_t *cache = nullptr) const; }; struct VarCompositeGlyph { static void - get_path_at (hb_font_t *font, - hb_codepoint_t glyph, - hb_draw_session_t *draw_session, - hb_extents_t *extents, + get_path_at (const hb_varc_context_t &c, + hb_codepoint_t gid, hb_array_t coords, hb_transform_t transform, hb_ubytes_t record, - hb_decycler_t *decycler, - signed *edges_left, - signed depth_left, - hb_glyf_scratch_t &scratch, - VarRegionList::cache_t *cache = nullptr) + VarRegionList::cache_t *cache) { while (record) { const VarComponent &comp = * (const VarComponent *) (record.arrayZ); - record = comp.get_path_at (font, glyph, - draw_session, extents, + record = comp.get_path_at (c, + gid, coords, transform, record, - decycler, edges_left, depth_left, scratch, cache); + cache); } } }; @@ -95,17 +94,11 @@ struct VARC static constexpr hb_tag_t tableTag = HB_TAG ('V', 'A', 'R', 'C'); HB_INTERNAL bool - get_path_at (hb_font_t *font, - hb_codepoint_t glyph, - hb_draw_session_t *draw_session, - hb_extents_t *extents, + get_path_at (const hb_varc_context_t &c, + hb_codepoint_t gid, hb_array_t coords, - hb_transform_t transform, - hb_codepoint_t parent_glyph, - hb_decycler_t *decycler, - signed *edges_left, - signed depth_left, - hb_glyf_scratch_t &scratch, + hb_transform_t transform = HB_TRANSFORM_IDENTITY, + hb_codepoint_t parent_gid = HB_CODEPOINT_INVALID, VarRegionList::cache_t *parent_cache = nullptr) const; bool @@ -114,20 +107,16 @@ struct VARC hb_draw_session_t &draw_session, hb_glyf_scratch_t &scratch) const { - hb_decycler_t decycler; - signed edges = HB_MAX_GRAPH_EDGE_COUNT; + hb_varc_context_t c {font, + &draw_session, + nullptr, + hb_decycler_t {}, + HB_MAX_GRAPH_EDGE_COUNT, + HB_MAX_NESTING_LEVEL, + scratch}; - return get_path_at (font, - gid, - &draw_session, - nullptr, - hb_array (font->coords, font->num_coords), - HB_TRANSFORM_IDENTITY, - HB_CODEPOINT_INVALID, - &decycler, - &edges, - HB_MAX_NESTING_LEVEL, - scratch); + return get_path_at (c, gid, + hb_array (font->coords, font->num_coords)); } bool @@ -136,20 +125,16 @@ struct VARC hb_extents_t *extents, hb_glyf_scratch_t &scratch) const { - hb_decycler_t decycler; - signed edges = HB_MAX_GRAPH_EDGE_COUNT; + hb_varc_context_t c {font, + nullptr, + extents, + hb_decycler_t {}, + HB_MAX_GRAPH_EDGE_COUNT, + HB_MAX_NESTING_LEVEL, + scratch}; - return get_path_at (font, - gid, - nullptr, - extents, - hb_array (font->coords, font->num_coords), - HB_TRANSFORM_IDENTITY, - HB_CODEPOINT_INVALID, - &decycler, - &edges, - HB_MAX_NESTING_LEVEL, - scratch); + return get_path_at (c, gid, + hb_array (font->coords, font->num_coords)); } bool sanitize (hb_sanitize_context_t *c) const