[varc] Add get_point_at to glyf/CFF2

This commit is contained in:
Behdad Esfahbod 2024-04-16 17:10:43 -06:00
parent 0d6f77e629
commit a94a5c6366
10 changed files with 43 additions and 14 deletions

View file

@ -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<const int> 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
{

View file

@ -352,7 +352,7 @@ struct Glyph
bool shift_points_hori = true,
bool use_my_metrics = true,
bool phantom_only = false,
hb_array_t<int> coords = hb_array_t<int> (),
hb_array_t<const int> coords = hb_array_t<const int> (),
hb_map_t *current_glyphs = nullptr,
unsigned int depth = 0,
unsigned *edge_count = nullptr) const

View file

@ -11,7 +11,7 @@ namespace glyf_impl {
struct coord_setter_t
{
coord_setter_t (hb_array_t<int> coords) :
coord_setter_t (hb_array_t<const int> coords) :
coords (coords) {}
int& operator [] (unsigned idx)

View file

@ -205,8 +205,12 @@ struct glyf_accelerator_t
protected:
template<typename T>
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<const int> coords = hb_array_t<const int> ()) 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<const int> 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

View file

@ -202,6 +202,11 @@ struct cff2_path_procs_path_t : path_procs_t<cff2_path_procs_path_t, cff2_cs_int
struct cff2_cs_opset_path_t : cff2_cs_opset_t<cff2_cs_opset_path_t, cff2_path_param_t, number_t, cff2_path_procs_path_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<const int> 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<number_t> env (str, *this, fd, font->coords, font->num_coords);
cff2_cs_interp_env_t<number_t> env (str, *this, fd, coords.arrayZ, coords.length);
cff2_cs_interpreter_t<cff2_cs_opset_path_t, cff2_path_param_t, number_t> interp (env);
cff2_path_param_t param (font, draw_session);
if (unlikely (!interp.interpret (param))) return false;

View file

@ -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<const int> coords) const;
};
struct accelerator_subset_t : accelerator_templ_t<cff2_private_dict_opset_subset_t, cff2_private_dict_values_subset_t>

View file

@ -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))

View file

@ -3235,7 +3235,7 @@ struct ItemVariationStore
return get_delta (outer, inner, coords, coord_count, cache);
}
float get_delta (unsigned int index,
hb_array_t<int> coords,
hb_array_t<const int> 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<int> coords,
hb_array_t<const int> coords,
hb_array_t<float> out,
VarRegionList::cache_t *cache = nullptr) const
{

View file

@ -225,8 +225,8 @@ struct DeltaSetIndexMap
struct ItemVarStoreInstancer
{
ItemVarStoreInstancer (const ItemVariationStore *varStore,
const DeltaSetIndexMap *varIdxMap,
hb_array_t<int> coords) :
const DeltaSetIndexMap *varIdxMap,
hb_array_t<const int> 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<int> coords;
hb_array_t<const int> 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<int> coords, unsigned int coord_count,
const hb_array_t<const F2DOT14> shared_tuples,
const hb_vector_t<hb_pair_t<int,int>> *shared_tuple_active_idx = nullptr) const
double calculate_scalar (hb_array_t<const int> coords, unsigned int coord_count,
const hb_array_t<const F2DOT14> shared_tuples,
const hb_vector_t<hb_pair_t<int,int>> *shared_tuple_active_idx = nullptr) const
{
const F2DOT14 *peak_tuple;

View file

@ -621,7 +621,7 @@ struct gvar
public:
bool apply_deltas_to_points (hb_codepoint_t glyph,
hb_array_t<int> coords,
hb_array_t<const int> coords,
const hb_array_t<contour_point_t> points,
bool phantom_only = false) const
{