diff --git a/src/hb-aat-layout-trak-table.hh b/src/hb-aat-layout-trak-table.hh index 8d088576b..508606037 100644 --- a/src/hb-aat-layout-trak-table.hh +++ b/src/hb-aat-layout-trak-table.hh @@ -190,40 +190,15 @@ struct trak bool has_data () const { return version.to_int (); } - bool apply (hb_aat_apply_context_t *c) const + hb_position_t get_h_tracking (hb_font_t *font, float track = 0.f) const { - TRACE_APPLY (this); - - float ptem = c->font->ptem; - if (unlikely (ptem <= 0.f)) - { - /* https://developer.apple.com/documentation/coretext/1508745-ctfontcreatewithgraphicsfont */ - ptem = HB_CORETEXT_DEFAULT_FONT_SIZE; - } - - hb_buffer_t *buffer = c->buffer; - if (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction)) - { - const TrackData &trackData = this+horizData; - float tracking = trackData.get_tracking (this, ptem); - hb_position_t advance_to_add = c->font->em_scalef_x (tracking); - foreach_grapheme (buffer, start, end) - { - buffer->pos[start].x_advance += advance_to_add; - } - } - else - { - const TrackData &trackData = this+vertData; - float tracking = trackData.get_tracking (this, ptem); - hb_position_t advance_to_add = c->font->em_scalef_y (tracking); - foreach_grapheme (buffer, start, end) - { - buffer->pos[start].y_advance += advance_to_add; - } - } - - return_trace (true); + float ptem = font->ptem > 0.f ? font->ptem : HB_CORETEXT_DEFAULT_FONT_SIZE; + return font->em_scalef_x ((this+horizData).get_tracking (this, ptem, track)); + } + hb_position_t get_v_tracking (hb_font_t *font, float track = 0.f) const + { + float ptem = font->ptem > 0.f ? font->ptem : HB_CORETEXT_DEFAULT_FONT_SIZE; + return font->em_scalef_y ((this+vertData).get_tracking (this, ptem, track)); } bool sanitize (hb_sanitize_context_t *c) const diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 4ce1cca71..9fe77a575 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -34,7 +34,7 @@ #include "hb-aat-layout-just-table.hh" // Just so we compile it; unused otherwise. #include "hb-aat-layout-kerx-table.hh" #include "hb-aat-layout-morx-table.hh" -#include "hb-aat-layout-trak-table.hh" +#include "hb-aat-layout-trak-table.hh" // Just so we compile it; unused otherwise. #include "hb-aat-ltag-table.hh" #include "hb-ot-layout-gsub-table.hh" @@ -394,17 +394,6 @@ hb_aat_layout_has_tracking (hb_face_t *face) return face->table.trak->has_data (); } -void -hb_aat_layout_track (const hb_ot_shape_plan_t *plan, - hb_font_t *font, - hb_buffer_t *buffer) -{ - const AAT::trak& trak = *font->face->table.trak; - - AAT::hb_aat_apply_context_t c (plan, font, buffer); - trak.apply (&c); -} - /** * hb_aat_layout_get_feature_types: * @face: #hb_face_t to work upon diff --git a/src/hb-aat-layout.hh b/src/hb-aat-layout.hh index 2cf1047df..c5d6ecb10 100644 --- a/src/hb-aat-layout.hh +++ b/src/hb-aat-layout.hh @@ -71,10 +71,5 @@ hb_aat_layout_position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer); -HB_INTERNAL void -hb_aat_layout_track (const hb_ot_shape_plan_t *plan, - hb_font_t *font, - hb_buffer_t *buffer); - #endif /* HB_AAT_LAYOUT_HH */ diff --git a/src/hb-coretext-shape.cc b/src/hb-coretext-shape.cc index 43a919128..90d7116c4 100644 --- a/src/hb-coretext-shape.cc +++ b/src/hb-coretext-shape.cc @@ -430,7 +430,7 @@ _hb_coretext_shaper_font_data_create (hb_font_t *font) if (unlikely (!face_data)) return nullptr; CGFontRef cg_font = (CGFontRef) (const void *) face->data.coretext; - CGFloat font_size = (CGFloat) (font->ptem <= 0.f ? HB_CORETEXT_DEFAULT_FONT_SIZE : font->ptem); + CGFloat font_size = (CGFloat) (font->ptem > 0.f ? font->ptem : HB_CORETEXT_DEFAULT_FONT_SIZE); CTFontRef ct_font = create_ct_font (cg_font, font_size); if (unlikely (!ct_font)) diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 7b4724710..85a805471 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -36,6 +36,9 @@ #include "hb-ot-face.hh" #include "hb-outline.hh" +#ifndef HB_NO_AAT +#include "hb-aat-layout-trak-table.hh" +#endif #include "hb-ot-cmap-table.hh" #include "hb-ot-glyf-table.hh" #include "hb-ot-cff2-table.hh" @@ -73,6 +76,10 @@ struct hb_ot_font_t { const hb_ot_face_t *ot_face; +#ifndef HB_NO_AAT + bool apply_trak; +#endif + #ifndef HB_NO_OT_FONT_CMAP_CACHE hb_ot_font_cmap_cache_t *cmap_cache; #endif @@ -91,6 +98,11 @@ _hb_ot_font_create (hb_font_t *font) ot_font->ot_face = &font->face->table; +#ifndef HB_NO_AAT + /* According to Ned, trak is applied by default for "modern fonts", as detected by presence of STAT table. */ + ot_font->apply_trak = font->face->table.STAT->has_data () && font->face->table.trak->has_data (); +#endif + #ifndef HB_NO_OT_FONT_CMAP_CACHE // retry: auto *cmap_cache = (hb_ot_font_cmap_cache_t *) hb_face_get_user_data (font->face, @@ -200,7 +212,6 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data, unsigned advance_stride, void *user_data HB_UNUSED) { - const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_face_t *ot_face = ot_font->ot_face; const OT::hmtx_accelerator_t &hmtx = *ot_face->hmtx; @@ -292,6 +303,20 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data, first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } } + +#ifndef HB_NO_AAT + if (ot_font->apply_trak) + { + hb_position_t tracking = font->face->table.trak->get_h_tracking (font); + first_advance = orig_first_advance; + for (unsigned int i = 0; i < count; i++) + { + *first_advance += tracking; + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); + } + } +#endif } #ifndef HB_NO_VERTICAL @@ -356,6 +381,20 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data, first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } } + +#ifndef HB_NO_AAT + if (ot_font->apply_trak) + { + hb_position_t tracking = font->face->table.trak->get_v_tracking (font); + first_advance = orig_first_advance; + for (unsigned int i = 0; i < count; i++) + { + *first_advance += tracking; + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); + } + } +#endif } #endif diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index f353d1897..461e13558 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -205,14 +205,6 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan, https://github.com/harfbuzz/harfbuzz/issues/2967. */ if (plan.apply_morx) plan.adjust_mark_positioning_when_zeroing = false; - - /* According to Ned, trak is applied by default for "modern fonts", as detected by presence of STAT table. */ -#ifndef HB_NO_STYLE - plan.apply_trak = hb_aat_layout_has_tracking (face) && face->table.STAT->has_data (); -#else - plan.apply_trak = false; -#endif - #endif } @@ -277,11 +269,6 @@ hb_ot_shape_plan_t::position (hb_font_t *font, #endif else if (this->apply_fallback_kern) _hb_ot_shape_fallback_kern (this, font, buffer); - -#ifndef HB_NO_AAT_SHAPE - if (this->apply_trak) - hb_aat_layout_track (this, font, buffer); -#endif } diff --git a/src/hb-ot-shape.hh b/src/hb-ot-shape.hh index 41fcfe80d..791bc6896 100644 --- a/src/hb-ot-shape.hh +++ b/src/hb-ot-shape.hh @@ -108,11 +108,9 @@ struct hb_ot_shape_plan_t #ifndef HB_NO_AAT_SHAPE bool apply_kerx : 1; bool apply_morx : 1; - bool apply_trak : 1; #else static constexpr bool apply_kerx = false; static constexpr bool apply_morx = false; - static constexpr bool apply_trak = false; #endif void collect_lookups (hb_tag_t table_tag, hb_set_t *lookups) const