[HarfBuzz] harfbuzz: Branch 'master' - 6 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Wed Oct 26 16:29:04 UTC 2016
src/hb-font-private.hh | 96 +++++-----
src/hb-ot-font.cc | 16 +
test/shaping/fonts/sha1sum/f9b1dd4dcb515e757789a22cb4241107746fd3d0.ttf |binary
test/shaping/tests/vertical.tests | 2
4 files changed, 69 insertions(+), 45 deletions(-)
New commits:
commit d163cd956246449e3e48b54ce6eb5cdb14e3a0a6
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Oct 26 18:27:48 2016 +0200
[tests] Add tests for vertical origin with ft and ot font-funcs
diff --git a/test/shaping/fonts/sha1sum/f9b1dd4dcb515e757789a22cb4241107746fd3d0.ttf b/test/shaping/fonts/sha1sum/f9b1dd4dcb515e757789a22cb4241107746fd3d0.ttf
new file mode 100644
index 0000000..ed2fab9
Binary files /dev/null and b/test/shaping/fonts/sha1sum/f9b1dd4dcb515e757789a22cb4241107746fd3d0.ttf differ
diff --git a/test/shaping/tests/vertical.tests b/test/shaping/tests/vertical.tests
index 8276890..3586080 100644
--- a/test/shaping/tests/vertical.tests
+++ b/test/shaping/tests/vertical.tests
@@ -1 +1,3 @@
fonts/sha1sum/191826b9643e3f124d865d617ae609db6a2ce203.ttf:--direction=t:U+300C:[uni300C.vert=0 at -512,-578+0,-1024]
+fonts/sha1sum/f9b1dd4dcb515e757789a22cb4241107746fd3d0.ttf:--direction=t --font-funcs=ft:U+0041,U+0042:[gid1=0 at -654,-2128+0,-2789|gid2=1 at -665,-2125+0,-2789]
+fonts/sha1sum/f9b1dd4dcb515e757789a22cb4241107746fd3d0.ttf:--direction=t --font-funcs=ot:U+0041,U+0042:[gid1=0 at -654,-2189+0,-2789|gid2=1 at -665,-2189+0,-2789]
commit 2b117720c03869c7714304fd7fbfb2b01199bb3a
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Oct 26 18:12:50 2016 +0200
Use horizontal ascent as fallback vertical origin
diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh
index 324cadc..cda97a6 100644
--- a/src/hb-font-private.hh
+++ b/src/hb-font-private.hh
@@ -337,14 +337,15 @@ struct hb_font_t {
}
}
- /* Internal only */
inline void guess_v_origin_minus_h_origin (hb_codepoint_t glyph,
hb_position_t *x, hb_position_t *y)
{
*x = get_glyph_h_advance (glyph) / 2;
- /* TODO use font_extents.ascender */
- *y = y_scale;
+ /* TODO cache this somehow?! */
+ hb_font_extents_t extents;
+ get_h_extents_with_fallback (&extents);
+ *y = extents.ascender;
}
inline void get_glyph_h_origin_with_fallback (hb_codepoint_t glyph,
commit a7b32f2057098012b3ab43121397766ae45b3559
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Oct 26 18:08:41 2016 +0200
Move code around
diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh
index 91d4a58..324cadc 100644
--- a/src/hb-font-private.hh
+++ b/src/hb-font-private.hh
@@ -296,24 +296,32 @@ struct hb_font_t {
/* A bit higher-level, and with fallback */
+ inline void get_h_extents_with_fallback (hb_font_extents_t *extents)
+ {
+ if (!get_font_h_extents (extents))
+ {
+ extents->ascender = y_scale * .8;
+ extents->descender = extents->ascender - y_scale;
+ extents->line_gap = 0;
+ }
+ }
+ inline void get_v_extents_with_fallback (hb_font_extents_t *extents)
+ {
+ if (!get_font_v_extents (extents))
+ {
+ extents->ascender = x_scale / 2;
+ extents->descender = extents->ascender - x_scale;
+ extents->line_gap = 0;
+ }
+ }
+
inline void get_extents_for_direction (hb_direction_t direction,
hb_font_extents_t *extents)
{
- if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) {
- if (!get_font_h_extents (extents))
- {
- extents->ascender = y_scale * .8;
- extents->descender = extents->ascender - y_scale;
- extents->line_gap = 0;
- }
- } else {
- if (!get_font_v_extents (extents))
- {
- extents->ascender = x_scale / 2;
- extents->descender = extents->ascender - x_scale;
- extents->line_gap = 0;
- }
- }
+ if (likely (HB_DIRECTION_IS_HORIZONTAL (direction)))
+ get_h_extents_with_fallback (extents);
+ else
+ get_v_extents_with_fallback (extents);
}
inline void get_glyph_advance_for_direction (hb_codepoint_t glyph,
commit 63635c763dd9393df236f49d491510cca18a1ccc
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Oct 26 17:54:04 2016 +0200
[hb-ot-font] Use ascent+descent as fallback vertical advance
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index 9fd8d05..20f2f89 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -55,9 +55,10 @@ struct hb_ot_face_metrics_accelerator_t
inline void init (hb_face_t *face,
hb_tag_t _hea_tag,
hb_tag_t _mtx_tag,
- hb_tag_t os2_tag)
+ hb_tag_t os2_tag,
+ unsigned int default_advance = 0)
{
- this->default_advance = face->get_upem ();
+ this->default_advance = default_advance ? default_advance : face->get_upem ();
bool got_font_extents = false;
if (os2_tag)
@@ -391,7 +392,8 @@ _hb_ot_font_create (hb_face_t *face)
ot_font->cmap.init (face);
ot_font->h_metrics.init (face, HB_OT_TAG_hhea, HB_OT_TAG_hmtx, HB_OT_TAG_os2);
- ot_font->v_metrics.init (face, HB_OT_TAG_vhea, HB_OT_TAG_vmtx, HB_TAG_NONE); /* TODO Can we do this lazily? */
+ ot_font->v_metrics.init (face, HB_OT_TAG_vhea, HB_OT_TAG_vmtx, HB_TAG_NONE,
+ ot_font->h_metrics.ascender - ot_font->h_metrics.descender); /* TODO Can we do this lazily? */
ot_font->glyf.init (face);
return ot_font;
commit 9ee23c49a7a7b2479ae0d36a64720e92eb8a36e7
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Oct 26 17:44:16 2016 +0200
Fix vertical glyph origin with hb-ot-font
diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh
index 99a8656..91d4a58 100644
--- a/src/hb-font-private.hh
+++ b/src/hb-font-private.hh
@@ -339,30 +339,37 @@ struct hb_font_t {
*y = y_scale;
}
+ inline void get_glyph_h_origin_with_fallback (hb_codepoint_t glyph,
+ hb_position_t *x, hb_position_t *y)
+ {
+ if (!get_glyph_h_origin (glyph, x, y) &&
+ get_glyph_v_origin (glyph, x, y))
+ {
+ hb_position_t dx, dy;
+ guess_v_origin_minus_h_origin (glyph, &dx, &dy);
+ *x -= dx; *y -= dy;
+ }
+ }
+ inline void get_glyph_v_origin_with_fallback (hb_codepoint_t glyph,
+ hb_position_t *x, hb_position_t *y)
+ {
+ if (!get_glyph_v_origin (glyph, x, y) &&
+ get_glyph_h_origin (glyph, x, y))
+ {
+ hb_position_t dx, dy;
+ guess_v_origin_minus_h_origin (glyph, &dx, &dy);
+ *x += dx; *y += dy;
+ }
+ }
+
inline void get_glyph_origin_for_direction (hb_codepoint_t glyph,
hb_direction_t direction,
hb_position_t *x, hb_position_t *y)
{
if (likely (HB_DIRECTION_IS_HORIZONTAL (direction)))
- {
- if (!get_glyph_h_origin (glyph, x, y) &&
- get_glyph_v_origin (glyph, x, y))
- {
- hb_position_t dx, dy;
- guess_v_origin_minus_h_origin (glyph, &dx, &dy);
- *x -= dx; *y -= dy;
- }
- }
+ get_glyph_h_origin_with_fallback (glyph, x, y);
else
- {
- if (!get_glyph_v_origin (glyph, x, y) &&
- get_glyph_h_origin (glyph, x, y))
- {
- hb_position_t dx, dy;
- guess_v_origin_minus_h_origin (glyph, &dx, &dy);
- *x += dx; *y += dy;
- }
- }
+ get_glyph_v_origin_with_fallback (glyph, x, y);
}
inline void add_glyph_h_origin (hb_codepoint_t glyph,
@@ -370,7 +377,7 @@ struct hb_font_t {
{
hb_position_t origin_x, origin_y;
- get_glyph_h_origin (glyph, &origin_x, &origin_y);
+ get_glyph_h_origin_with_fallback (glyph, &origin_x, &origin_y);
*x += origin_x;
*y += origin_y;
@@ -380,7 +387,7 @@ struct hb_font_t {
{
hb_position_t origin_x, origin_y;
- get_glyph_v_origin (glyph, &origin_x, &origin_y);
+ get_glyph_v_origin_with_fallback (glyph, &origin_x, &origin_y);
*x += origin_x;
*y += origin_y;
@@ -402,7 +409,7 @@ struct hb_font_t {
{
hb_position_t origin_x, origin_y;
- get_glyph_h_origin (glyph, &origin_x, &origin_y);
+ get_glyph_h_origin_with_fallback (glyph, &origin_x, &origin_y);
*x -= origin_x;
*y -= origin_y;
@@ -412,7 +419,7 @@ struct hb_font_t {
{
hb_position_t origin_x, origin_y;
- get_glyph_v_origin (glyph, &origin_x, &origin_y);
+ get_glyph_v_origin_with_fallback (glyph, &origin_x, &origin_y);
*x -= origin_x;
*y -= origin_y;
commit b3b0816d5fc00298621f738cf400de60f8a42c5d
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Oct 26 17:19:07 2016 +0200
Fix vertical font metrics
Ouch!
diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh
index 6d5012e..99a8656 100644
--- a/src/hb-font-private.hh
+++ b/src/hb-font-private.hh
@@ -303,14 +303,14 @@ struct hb_font_t {
if (!get_font_h_extents (extents))
{
extents->ascender = y_scale * .8;
- extents->descender = y_scale - extents->ascender;
+ extents->descender = extents->ascender - y_scale;
extents->line_gap = 0;
}
} else {
if (!get_font_v_extents (extents))
{
extents->ascender = x_scale / 2;
- extents->descender = x_scale - extents->ascender;
+ extents->descender = extents->ascender - x_scale;
extents->line_gap = 0;
}
}
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index 0b7e31b..9fd8d05 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -47,6 +47,7 @@ struct hb_ot_face_metrics_accelerator_t
unsigned short ascender;
unsigned short descender;
unsigned short line_gap;
+ bool has_font_extents;
const OT::_mtx *table;
hb_blob_t *blob;
@@ -82,9 +83,12 @@ struct hb_ot_face_metrics_accelerator_t
this->ascender = _hea->ascender;
this->descender = _hea->descender;
this->line_gap = _hea->lineGap;
+ got_font_extents = (this->ascender | this->descender) != 0;
}
hb_blob_destroy (_hea_blob);
+ this->has_font_extents = got_font_extents;
+
this->blob = OT::Sanitizer<OT::_mtx>::sanitize (face->reference_table (_mtx_tag));
/* Cap num_metrics() and num_advances() based on table length. */
@@ -475,7 +479,7 @@ hb_ot_get_font_h_extents (hb_font_t *font HB_UNUSED,
metrics->ascender = font->em_scale_y (ot_font->h_metrics.ascender);
metrics->descender = font->em_scale_y (ot_font->h_metrics.descender);
metrics->line_gap = font->em_scale_y (ot_font->h_metrics.line_gap);
- return true;
+ return ot_font->h_metrics.has_font_extents;
}
static hb_bool_t
@@ -488,7 +492,7 @@ hb_ot_get_font_v_extents (hb_font_t *font HB_UNUSED,
metrics->ascender = font->em_scale_x (ot_font->v_metrics.ascender);
metrics->descender = font->em_scale_x (ot_font->v_metrics.descender);
metrics->line_gap = font->em_scale_x (ot_font->v_metrics.line_gap);
- return true;
+ return ot_font->v_metrics.has_font_extents;
}
static hb_font_funcs_t *static_ot_funcs = NULL;
More information about the HarfBuzz
mailing list