[HarfBuzz] harfbuzz: Branch 'master' - 2 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Thu Nov 2 01:42:23 UTC 2017
src/hb-ot-font.cc | 16 +++++++++-
src/hb-ot-kern-table.hh | 75 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 89 insertions(+), 2 deletions(-)
New commits:
commit 4b3278ef8dc71ad4f744d763068d9a2e02d3d75d
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Nov 1 19:41:29 2017 -0600
[ot] Hook up horizontal kerning to kern table
Seems to work. Yay!
Still to do: run kerning if GPOS doesn't have 'kern' feature.
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index 59f6a71b..d9896035 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -665,7 +665,7 @@ retry:
hb_font_funcs_set_glyph_v_advance_func (funcs, hb_ot_get_glyph_v_advance, nullptr, nullptr);
//hb_font_funcs_set_glyph_h_origin_func (funcs, hb_ot_get_glyph_h_origin, nullptr, nullptr);
//hb_font_funcs_set_glyph_v_origin_func (funcs, hb_ot_get_glyph_v_origin, nullptr, nullptr);
- //hb_font_funcs_set_glyph_h_kerning_func (funcs, hb_ot_get_glyph_h_kerning, nullptr, nullptr); TODO
+ hb_font_funcs_set_glyph_h_kerning_func (funcs, hb_ot_get_glyph_h_kerning, nullptr, nullptr);
//hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_ot_get_glyph_v_kerning, nullptr, nullptr);
hb_font_funcs_set_glyph_extents_func (funcs, hb_ot_get_glyph_extents, nullptr, nullptr);
//hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ot_get_glyph_contour_point, nullptr, nullptr); TODO
commit 77acc1106e6d984ee74ec606e145f455e6e55509
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Nov 1 19:33:09 2017 -0600
[kern] More...
Almost there.
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index 9d420eed..59f6a71b 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -471,6 +471,7 @@ struct hb_ot_font_t
OT::hb_lazy_loader_t<hb_ot_face_glyf_accelerator_t> glyf;
OT::hb_lazy_loader_t<hb_ot_face_cbdt_accelerator_t> cbdt;
OT::hb_lazy_loader_t<hb_ot_face_post_accelerator_t> post;
+ OT::hb_lazy_table_loader_t<OT::kern> kern;
};
@@ -489,6 +490,7 @@ _hb_ot_font_create (hb_face_t *face)
ot_font->glyf.init (face);
ot_font->cbdt.init (face);
ot_font->post.init (face);
+ ot_font->kern.init (face);
return ot_font;
}
@@ -504,6 +506,7 @@ _hb_ot_font_destroy (void *data)
ot_font->glyf.fini ();
ot_font->cbdt.fini ();
ot_font->post.fini ();
+ ot_font->kern.fini ();
free (ot_font);
}
@@ -553,6 +556,17 @@ hb_ot_get_glyph_v_advance (hb_font_t *font,
return font->em_scale_y (-(int) ot_font->v_metrics.get_advance (glyph, font));
}
+static hb_position_t
+hb_ot_get_glyph_h_kerning (hb_font_t *font,
+ void *font_data,
+ hb_codepoint_t left_glyph,
+ hb_codepoint_t right_glyph,
+ void *user_data HB_UNUSED)
+{
+ const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
+ return font->em_scale_x (ot_font->kern->get_h_kerning (left_glyph, right_glyph));
+}
+
static hb_bool_t
hb_ot_get_glyph_extents (hb_font_t *font HB_UNUSED,
void *font_data,
diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh
index d8b0b406..2cab5cc9 100644
--- a/src/hb-ot-kern-table.hh
+++ b/src/hb-ot-kern-table.hh
@@ -98,6 +98,12 @@ struct KernSubTableFormat0
struct KernSubTableFormat2
{
+ inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const
+ {
+ /* XXX */
+ return 0;
+ }
+
inline unsigned int get_size (void) const
{
/* XXX */
@@ -116,6 +122,15 @@ struct KernSubTableFormat2
struct KernSubTable
{
+ inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right, unsigned int format) const
+ {
+ switch (format) {
+ case 0: return u.format0.get_kerning (left, right);
+ case 2: return u.format2.get_kerning (left, right);
+ default:return 0;
+ }
+ }
+
inline unsigned int get_size (unsigned int format) const
{
switch (format) {
@@ -151,6 +166,18 @@ struct KernSubTableWrapper
/* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */
inline const T* thiz (void) const { return static_cast<const T *> (this); }
+ inline bool is_horizontal (void) const
+ { return (thiz()->coverage & T::COVERAGE_CHECK_FLAGS) == T::COVERAGE_CHECK_HORIZONTAL; }
+
+ inline bool is_override (void) const
+ { return bool (thiz()->coverage & T::COVERAGE_OVERRIDE_FLAG); }
+
+ inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const
+ { return thiz()->subtable.get_kerning (left, right, thiz()->format); }
+
+ inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const
+ { return is_horizontal () ? get_kerning (left, right) : 0; }
+
inline unsigned int get_size (void) const { return thiz()->length; }
inline bool sanitize (hb_sanitize_context_t *c) const
@@ -170,6 +197,21 @@ struct KernTable
/* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */
inline const T* thiz (void) const { return static_cast<const T *> (this); }
+ inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const
+ {
+ int v = 0;
+ const typename T::SubTableWrapper *st = CastP<typename T::SubTableWrapper> (thiz()->data);
+ unsigned int count = thiz()->nTables;
+ for (unsigned int i = 0; i < count; i++)
+ {
+ if (st->is_override ())
+ v = 0;
+ v += st->get_h_kerning (left, right);
+ st = &StructAfter<typename T::SubTableWrapper> (*st);
+ }
+ return v;
+ }
+
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
@@ -200,6 +242,18 @@ struct KernOT : KernTable<KernOT>
{
friend struct KernSubTableWrapper<SubTableWrapper>;
+ enum coverage_flags_t {
+ COVERAGE_DIRECTION_FLAG = 0x01u,
+ COVERAGE_MINIMUM_FLAG = 0x02u,
+ COVERAGE_CROSSSTREAM_FLAG = 0x04u,
+ COVERAGE_OVERRIDE_FLAG = 0x08u,
+
+ COVERAGE_VARIATION_FLAG = 0x00u, /* Not supported. */
+
+ COVERAGE_CHECK_FLAGS = 0x07u,
+ COVERAGE_CHECK_HORIZONTAL = 0x01u
+ };
+
protected:
USHORT versionZ; /* Unused. */
USHORT length; /* Length of the subtable (including this header). */
@@ -228,6 +282,17 @@ struct KernAAT : KernTable<KernAAT>
{
friend struct KernSubTableWrapper<SubTableWrapper>;
+ enum coverage_flags_t {
+ COVERAGE_DIRECTION_FLAG = 0x80u,
+ COVERAGE_CROSSSTREAM_FLAG = 0x40u,
+ COVERAGE_VARIATION_FLAG = 0x20u,
+
+ COVERAGE_OVERRIDE_FLAG = 0x00u, /* Not supported. */
+
+ COVERAGE_CHECK_FLAGS = 0xE0u,
+ COVERAGE_CHECK_HORIZONTAL = 0x00u
+ };
+
protected:
ULONG length; /* Length of the subtable (including this header). */
BYTE coverage; /* Coverage bits. */
@@ -251,7 +316,15 @@ struct kern
{
static const hb_tag_t tableTag = HB_OT_TAG_kern;
- private:
+ inline int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const
+ {
+ switch (u.major) {
+ case 0: return u.ot.get_h_kerning (left, right);
+ case 1: return u.aat.get_h_kerning (left, right);
+ default:return 0;
+ }
+ }
+
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
More information about the HarfBuzz
mailing list