From a94a5c6366b08e57f688f8b4490e8368f272cb12 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 16 Apr 2024 17:10:43 -0600 Subject: [PATCH] [varc] Add get_point_at to glyf/CFF2 --- src/OT/Var/VARC/VARC.hh | 13 +++++++++++++ src/OT/glyf/Glyph.hh | 2 +- src/OT/glyf/coord-setter.hh | 2 +- src/OT/glyf/glyf.hh | 13 +++++++++++-- src/hb-ot-cff2-table.cc | 7 ++++++- src/hb-ot-cff2-table.hh | 1 + src/hb-ot-font.cc | 1 + src/hb-ot-layout-common.hh | 4 ++-- src/hb-ot-var-common.hh | 12 ++++++------ src/hb-ot-var-gvar-table.hh | 2 +- 10 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/OT/Var/VARC/VARC.hh b/src/OT/Var/VARC/VARC.hh index 64153c14c..119730256 100644 --- a/src/OT/Var/VARC/VARC.hh +++ b/src/OT/Var/VARC/VARC.hh @@ -16,6 +16,19 @@ struct VARC { static constexpr hb_tag_t tableTag = HB_TAG ('V', 'A', 'R', 'C'); + bool + get_path_at (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session, + hb_array_t coords) const + { + if (!font->face->table.glyf->get_path_at (font, glyph, draw_session, coords)) +#ifndef HB_NO_CFF + if (!font->face->table.cff2->get_path_at (font, glyph, draw_session, coords)) + if (!font->face->table.cff1->get_path (font, glyph, draw_session)) // Doesn't have variations +#endif + return false; + return true; + } + bool get_path (hb_font_t *font, hb_codepoint_t gid, hb_draw_session_t &draw_session) const { diff --git a/src/OT/glyf/Glyph.hh b/src/OT/glyf/Glyph.hh index 69a0b625c..aec0d915b 100644 --- a/src/OT/glyf/Glyph.hh +++ b/src/OT/glyf/Glyph.hh @@ -352,7 +352,7 @@ struct Glyph bool shift_points_hori = true, bool use_my_metrics = true, bool phantom_only = false, - hb_array_t coords = hb_array_t (), + hb_array_t coords = hb_array_t (), hb_map_t *current_glyphs = nullptr, unsigned int depth = 0, unsigned *edge_count = nullptr) const diff --git a/src/OT/glyf/coord-setter.hh b/src/OT/glyf/coord-setter.hh index cf0592936..bd694831e 100644 --- a/src/OT/glyf/coord-setter.hh +++ b/src/OT/glyf/coord-setter.hh @@ -11,7 +11,7 @@ namespace glyf_impl { struct coord_setter_t { - coord_setter_t (hb_array_t coords) : + coord_setter_t (hb_array_t coords) : coords (coords) {} int& operator [] (unsigned idx) diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index 6300cf4be..f346ae05d 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -205,8 +205,12 @@ struct glyf_accelerator_t protected: template - bool get_points (hb_font_t *font, hb_codepoint_t gid, T consumer) const + bool get_points (hb_font_t *font, hb_codepoint_t gid, T consumer, + hb_array_t coords = hb_array_t ()) const { + if (!coords) + coords = hb_array (font->coords, font->num_coords); + if (gid >= num_glyphs) return false; /* Making this allocfree is not that easy @@ -216,7 +220,7 @@ struct glyf_accelerator_t contour_point_vector_t all_points; bool phantom_only = !consumer.is_consuming_contour_points (); - if (unlikely (!glyph_for_gid (gid).get_points (font, *this, all_points, nullptr, nullptr, nullptr, true, true, phantom_only))) + if (unlikely (!glyph_for_gid (gid).get_points (font, *this, all_points, nullptr, nullptr, nullptr, true, true, phantom_only, coords))) return false; unsigned count = all_points.length; @@ -408,6 +412,11 @@ struct glyf_accelerator_t get_path (hb_font_t *font, hb_codepoint_t gid, hb_draw_session_t &draw_session) const { return get_points (font, gid, glyf_impl::path_builder_t (font, draw_session)); } + bool + get_path_at (hb_font_t *font, hb_codepoint_t gid, hb_draw_session_t &draw_session, + hb_array_t coords) const + { return get_points (font, gid, glyf_impl::path_builder_t (font, draw_session), coords); } + #ifndef HB_NO_VAR const gvar_accelerator_t *gvar; #endif diff --git a/src/hb-ot-cff2-table.cc b/src/hb-ot-cff2-table.cc index 795556555..e42217b4e 100644 --- a/src/hb-ot-cff2-table.cc +++ b/src/hb-ot-cff2-table.cc @@ -202,6 +202,11 @@ struct cff2_path_procs_path_t : path_procs_t {}; bool OT::cff2::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session) const +{ + return get_path_at (font, glyph, draw_session, hb_array (font->coords, font->num_coords)); +} + +bool OT::cff2::accelerator_t::get_path_at (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session, hb_array_t coords) const { #ifdef HB_NO_OT_FONT_CFF /* XXX Remove check when this code moves to .hh file. */ @@ -212,7 +217,7 @@ bool OT::cff2::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, h unsigned int fd = fdSelect->get_fd (glyph); const hb_ubytes_t str = (*charStrings)[glyph]; - cff2_cs_interp_env_t env (str, *this, fd, font->coords, font->num_coords); + cff2_cs_interp_env_t env (str, *this, fd, coords.arrayZ, coords.length); cff2_cs_interpreter_t interp (env); cff2_path_param_t param (font, draw_session); if (unlikely (!interp.interpret (param))) return false; diff --git a/src/hb-ot-cff2-table.hh b/src/hb-ot-cff2-table.hh index 849e202c6..2a7a466d6 100644 --- a/src/hb-ot-cff2-table.hh +++ b/src/hb-ot-cff2-table.hh @@ -519,6 +519,7 @@ struct cff2 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, 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; + HB_INTERNAL bool get_path_at (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session, hb_array_t coords) const; }; struct accelerator_subset_t : accelerator_templ_t diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 90cc15a45..5726949da 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -527,6 +527,7 @@ hb_ot_draw_glyph (hb_font_t *font, #ifndef HB_NO_VAR if (!font->face->table.VARC->get_path (font, glyph, draw_session)) #endif + // Keep the following in synch with VARC::get_path_at() if (!font->face->table.glyf->get_path (font, glyph, draw_session)) #ifndef HB_NO_CFF if (!font->face->table.cff2->get_path (font, glyph, draw_session)) diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 4ddcd3268..ac937f540 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -3235,7 +3235,7 @@ struct ItemVariationStore return get_delta (outer, inner, coords, coord_count, cache); } float get_delta (unsigned int index, - hb_array_t coords, + hb_array_t coords, VarRegionList::cache_t *cache = nullptr) const { return get_delta (index, @@ -3496,7 +3496,7 @@ struct MultiItemVariationStore get_delta (outer, inner, coords, coord_count, out, cache); } void get_delta (unsigned int index, - hb_array_t coords, + hb_array_t coords, hb_array_t out, VarRegionList::cache_t *cache = nullptr) const { diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index 302755103..15c1834f9 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -225,8 +225,8 @@ struct DeltaSetIndexMap struct ItemVarStoreInstancer { ItemVarStoreInstancer (const ItemVariationStore *varStore, - const DeltaSetIndexMap *varIdxMap, - hb_array_t coords) : + const DeltaSetIndexMap *varIdxMap, + hb_array_t coords) : varStore (varStore), varIdxMap (varIdxMap), coords (coords) {} operator bool () const { return varStore && bool (coords); } @@ -238,7 +238,7 @@ struct ItemVarStoreInstancer const ItemVariationStore *varStore; const DeltaSetIndexMap *varIdxMap; - hb_array_t coords; + hb_array_t coords; }; /* https://docs.microsoft.com/en-us/typography/opentype/spec/otvarcommonformats#tuplevariationheader */ @@ -305,9 +305,9 @@ struct TupleVariationHeader return true; } - double calculate_scalar (hb_array_t coords, unsigned int coord_count, - const hb_array_t shared_tuples, - const hb_vector_t> *shared_tuple_active_idx = nullptr) const + double calculate_scalar (hb_array_t coords, unsigned int coord_count, + const hb_array_t shared_tuples, + const hb_vector_t> *shared_tuple_active_idx = nullptr) const { const F2DOT14 *peak_tuple; diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 63acaac31..b4f1495d1 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -621,7 +621,7 @@ struct gvar public: bool apply_deltas_to_points (hb_codepoint_t glyph, - hb_array_t coords, + hb_array_t coords, const hb_array_t points, bool phantom_only = false) const {