diff options
Diffstat (limited to 'src/3rdparty/harfbuzz-ng/src/OT/glyf/glyf.hh')
-rw-r--r-- | src/3rdparty/harfbuzz-ng/src/OT/glyf/glyf.hh | 114 |
1 files changed, 70 insertions, 44 deletions
diff --git a/src/3rdparty/harfbuzz-ng/src/OT/glyf/glyf.hh b/src/3rdparty/harfbuzz-ng/src/OT/glyf/glyf.hh index e6e985c38c..29328c7627 100644 --- a/src/3rdparty/harfbuzz-ng/src/OT/glyf/glyf.hh +++ b/src/3rdparty/harfbuzz-ng/src/OT/glyf/glyf.hh @@ -7,6 +7,7 @@ #include "../../hb-ot-hmtx-table.hh" #include "../../hb-ot-var-gvar-table.hh" #include "../../hb-draw.hh" +#include "../../hb-paint.hh" #include "glyf-helpers.hh" #include "Glyph.hh" @@ -42,14 +43,13 @@ struct glyf bool serialize (hb_serialize_context_t *c, Iterator it, bool use_short_loca, - const hb_subset_plan_t *plan, - hb_font_t *font) + const hb_subset_plan_t *plan) { TRACE_SERIALIZE (this); unsigned init_len = c->length (); for (auto &_ : it) - if (unlikely (!_.serialize (c, use_short_loca, plan, font))) + if (unlikely (!_.serialize (c, use_short_loca, plan))) return false; /* As a special case when all glyph in the font are empty, add a zero byte @@ -75,59 +75,66 @@ struct glyf glyf *glyf_prime = c->serializer->start_embed <glyf> (); if (unlikely (!c->serializer->check_success (glyf_prime))) return_trace (false); - hb_vector_t<glyf_impl::SubsetGlyph> glyphs; - _populate_subset_glyphs (c->plan, glyphs); - hb_font_t *font = nullptr; - if (!c->plan->pinned_at_default) + if (c->plan->normalized_coords) { font = _create_font_for_instancing (c->plan); if (unlikely (!font)) return false; } - auto padded_offsets = - + hb_iter (glyphs) - | hb_map (&glyf_impl::SubsetGlyph::padded_size) - ; + hb_vector_t<unsigned> padded_offsets; + unsigned num_glyphs = c->plan->num_output_glyphs (); + if (unlikely (!padded_offsets.resize (num_glyphs))) + return false; + + hb_vector_t<glyf_impl::SubsetGlyph> glyphs; + if (!_populate_subset_glyphs (c->plan, font, glyphs)) + return false; + + if (font) + hb_font_destroy (font); + + unsigned max_offset = 0; + for (unsigned i = 0; i < num_glyphs; i++) + { + padded_offsets[i] = glyphs[i].padded_size (); + max_offset += padded_offsets[i]; + } bool use_short_loca = false; if (likely (!c->plan->force_long_loca)) - { - unsigned max_offset = + padded_offsets | hb_reduce (hb_add, 0); use_short_loca = max_offset < 0x1FFFF; - } - glyf_prime->serialize (c->serializer, glyphs.writer (), use_short_loca, c->plan, font); if (!use_short_loca) { - padded_offsets = - + hb_iter (glyphs) - | hb_map (&glyf_impl::SubsetGlyph::length) - ; + for (unsigned i = 0; i < num_glyphs; i++) + padded_offsets[i] = glyphs[i].length (); } - if (font) - { - _free_compiled_subset_glyphs (&glyphs); - hb_font_destroy (font); - } + bool result = glyf_prime->serialize (c->serializer, glyphs.writer (), use_short_loca, c->plan); + if (c->plan->normalized_coords && !c->plan->pinned_at_default) + _free_compiled_subset_glyphs (glyphs, glyphs.length - 1); + + if (!result) return false; if (unlikely (c->serializer->in_error ())) return_trace (false); + return_trace (c->serializer->check_success (glyf_impl::_add_loca_and_head (c->plan, - padded_offsets, + padded_offsets.iter (), use_short_loca))); } - void + bool _populate_subset_glyphs (const hb_subset_plan_t *plan, + hb_font_t *font, hb_vector_t<glyf_impl::SubsetGlyph> &glyphs /* OUT */) const; hb_font_t * _create_font_for_instancing (const hb_subset_plan_t *plan) const; - void _free_compiled_subset_glyphs (hb_vector_t<glyf_impl::SubsetGlyph> *glyphs) const + void _free_compiled_subset_glyphs (hb_vector_t<glyf_impl::SubsetGlyph> &glyphs, unsigned index) const { - for (auto _ : *glyphs) - _.free_compiled_bytes (); + for (unsigned i = 0; i <= index && i < glyphs.length; i++) + glyphs[i].free_compiled_bytes (); } protected: @@ -193,7 +200,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, true, true, phantom_only))) + if (unlikely (!glyph_for_gid (gid).get_points (font, *this, all_points, nullptr, nullptr, nullptr, true, true, phantom_only))) return false; if (consumer.is_consuming_contour_points ()) @@ -247,19 +254,14 @@ struct glyf_accelerator_t extents->y_bearing = 0; return; } - if (scaled) - { - extents->x_bearing = font->em_scalef_x (min_x); - extents->width = font->em_scalef_x (max_x) - extents->x_bearing; - extents->y_bearing = font->em_scalef_y (max_y); - extents->height = font->em_scalef_y (min_y) - extents->y_bearing; - } - else { extents->x_bearing = roundf (min_x); extents->width = roundf (max_x - extents->x_bearing); extents->y_bearing = roundf (max_y); extents->height = roundf (min_y - extents->y_bearing); + + if (scaled) + font->scale_glyph_extents (extents); } } @@ -337,6 +339,15 @@ 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, hb_color_t foreground) const + { + funcs->push_clip_glyph (data, gid, font); + funcs->color (data, true, foreground); + funcs->pop_clip (data); + + return true; + } + const glyf_impl::Glyph glyph_for_gid (hb_codepoint_t gid, bool needs_padding_removal = false) const { @@ -385,14 +396,16 @@ struct glyf_accelerator_t }; -inline void +inline bool glyf::_populate_subset_glyphs (const hb_subset_plan_t *plan, + hb_font_t *font, hb_vector_t<glyf_impl::SubsetGlyph>& glyphs /* OUT */) const { OT::glyf_accelerator_t glyf (plan->source); unsigned num_glyphs = plan->num_output_glyphs (); - if (!glyphs.resize (num_glyphs)) return; + if (!glyphs.resize (num_glyphs)) return false; + unsigned idx = 0; for (auto p : plan->glyph_map->iter ()) { unsigned new_gid = p.second; @@ -401,7 +414,7 @@ glyf::_populate_subset_glyphs (const hb_subset_plan_t *plan, if (unlikely (new_gid == 0 && !(plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE)) && - plan->pinned_at_default) + !plan->normalized_coords) subset_glyph.source_glyph = glyf_impl::Glyph (); else { @@ -414,7 +427,20 @@ glyf::_populate_subset_glyphs (const hb_subset_plan_t *plan, subset_glyph.drop_hints_bytes (); else subset_glyph.dest_start = subset_glyph.source_glyph.get_bytes (); + + if (font) + { + if (unlikely (!subset_glyph.compile_bytes_with_deltas (plan, font, glyf))) + { + // when pinned at default, only bounds are updated, thus no need to free + if (!plan->pinned_at_default && idx > 0) + _free_compiled_subset_glyphs (glyphs, idx - 1); + return false; + } + idx++; + } } + return true; } inline hb_font_t * @@ -424,10 +450,10 @@ glyf::_create_font_for_instancing (const hb_subset_plan_t *plan) const if (unlikely (font == hb_font_get_empty ())) return nullptr; hb_vector_t<hb_variation_t> vars; - if (unlikely (!vars.alloc (plan->user_axes_location->get_population ()))) + if (unlikely (!vars.alloc (plan->user_axes_location.get_population (), true))) return nullptr; - for (auto _ : *plan->user_axes_location) + for (auto _ : plan->user_axes_location) { hb_variation_t var; var.tag = _.first; @@ -436,7 +462,7 @@ glyf::_create_font_for_instancing (const hb_subset_plan_t *plan) const } #ifndef HB_NO_VAR - hb_font_set_variations (font, vars.arrayZ, plan->user_axes_location->get_population ()); + hb_font_set_variations (font, vars.arrayZ, plan->user_axes_location.get_population ()); #endif return font; } |