[HarfBuzz] harfbuzz-ng: Branch 'master' - 3 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Thu May 12 12:17:29 PDT 2011
src/hb-font.cc | 25 ++++++++++++++-----------
src/hb-font.h | 16 +++++++++-------
src/hb-ft.cc | 18 ++++++++++--------
src/hb-ot-shape.cc | 13 +++++++++----
test/test-font.c | 5 ++++-
test/test-shape.c | 35 ++++++++++++++++++++++++++---------
6 files changed, 72 insertions(+), 40 deletions(-)
New commits:
commit 0fd8c2f1be693616f19f2f1526369874763d6cf6
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Thu May 12 15:14:13 2011 -0400
[API] Make get_glyph() callback return a boolean
We need to know whether the glyph exists, so we can fallback to
composing / decomposing. Assuming that glyph==0 means "doesn't exist"
wouldn't work for applications like Pango that want to use different
"doesn't exist" glyph codes for different characters. An explicit
return value fixes that.
diff --git a/src/hb-font.cc b/src/hb-font.cc
index 6d974fe..6657718 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -99,17 +99,19 @@ hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
extents->width = extents->height = 0;
}
-static hb_codepoint_t
+static hb_bool_t
hb_font_get_glyph_nil (hb_font_t *font HB_UNUSED,
void *font_data HB_UNUSED,
hb_codepoint_t unicode,
hb_codepoint_t variation_selector,
+ hb_codepoint_t *glyph,
void *user_data HB_UNUSED)
{
if (font->parent)
- return hb_font_get_glyph (font->parent, unicode, variation_selector);
+ return hb_font_get_glyph (font->parent, unicode, variation_selector, glyph);
- return 0;
+ *glyph = 0;
+ return FALSE;
}
static void
@@ -287,12 +289,13 @@ hb_font_get_glyph_extents (hb_font_t *font,
font->klass->user_data.glyph_extents);
}
-hb_codepoint_t
+hb_bool_t
hb_font_get_glyph (hb_font_t *font,
- hb_codepoint_t unicode, hb_codepoint_t variation_selector)
+ hb_codepoint_t unicode, hb_codepoint_t variation_selector,
+ hb_codepoint_t *glyph)
{
return font->klass->get.glyph (font, font->user_data,
- unicode, variation_selector,
+ unicode, variation_selector, glyph,
font->klass->user_data.glyph);
}
diff --git a/src/hb-font.h b/src/hb-font.h
index c6f80c3..e38d3a7 100644
--- a/src/hb-font.h
+++ b/src/hb-font.h
@@ -140,9 +140,10 @@ typedef void (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, void *font_da
hb_codepoint_t glyph,
hb_glyph_extents_t *extents,
void *user_data);
-typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, void *font_data,
- hb_codepoint_t unicode, hb_codepoint_t variation_selector,
- void *user_data);
+typedef hb_bool_t (*hb_font_get_glyph_func_t) (hb_font_t *font, void *font_data,
+ hb_codepoint_t unicode, hb_codepoint_t variation_selector,
+ hb_codepoint_t *glyph,
+ void *user_data);
typedef void (*hb_font_get_kerning_func_t) (hb_font_t *font, void *font_data,
hb_codepoint_t left_glyph, hb_codepoint_t right_glyph,
hb_position_t *x_kern, hb_position_t *y_kern,
@@ -190,9 +191,10 @@ hb_font_get_glyph_extents (hb_font_t *font,
hb_codepoint_t glyph,
hb_glyph_extents_t *extents);
-hb_codepoint_t
+hb_bool_t
hb_font_get_glyph (hb_font_t *font,
- hb_codepoint_t unicode, hb_codepoint_t variation_selector);
+ hb_codepoint_t unicode, hb_codepoint_t variation_selector,
+ hb_codepoint_t *glyph);
void
hb_font_get_kerning (hb_font_t *font,
diff --git a/src/hb-ft.cc b/src/hb-ft.cc
index b3a5cd0..a9186f8 100644
--- a/src/hb-ft.cc
+++ b/src/hb-ft.cc
@@ -107,11 +107,12 @@ hb_ft_get_glyph_extents (hb_font_t *font HB_UNUSED,
}
}
-static hb_codepoint_t
+static hb_bool_t
hb_ft_get_glyph (hb_font_t *font HB_UNUSED,
void *font_data,
hb_codepoint_t unicode,
hb_codepoint_t variation_selector,
+ hb_codepoint_t *glyph,
void *user_data HB_UNUSED)
{
@@ -119,13 +120,14 @@ hb_ft_get_glyph (hb_font_t *font HB_UNUSED,
#ifdef HAVE_FT_FACE_GETCHARVARIANTINDEX
if (unlikely (variation_selector)) {
- hb_codepoint_t glyph = FT_Face_GetCharVariantIndex (ft_face, unicode, variation_selector);
- if (glyph)
- return glyph;
+ *glyph = FT_Face_GetCharVariantIndex (ft_face, unicode, variation_selector);
+ if (*glyph)
+ return TRUE;
}
#endif
- return FT_Get_Char_Index (ft_face, unicode);
+ *glyph = FT_Get_Char_Index (ft_face, unicode);
+ return *glyph != 0;
}
static void
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index 71eae42..ad6c2e2 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -216,18 +216,23 @@ hb_map_glyphs (hb_font_t *font,
if (unlikely (!buffer->len))
return;
+ hb_codepoint_t glyph;
buffer->clear_output ();
unsigned int count = buffer->len - 1;
for (buffer->i = 0; buffer->i < count;) {
if (unlikely (is_variation_selector (buffer->info[buffer->i + 1].codepoint))) {
- buffer->replace_glyph (hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, buffer->info[buffer->i + 1].codepoint));
+ hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, buffer->info[buffer->i + 1].codepoint, &glyph);
+ buffer->replace_glyph (glyph);
buffer->i++;
} else {
- buffer->replace_glyph (hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, 0));
+ hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, 0, &glyph);
+ buffer->replace_glyph (glyph);
}
}
- if (likely (buffer->i < buffer->len))
- buffer->replace_glyph (hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, 0));
+ if (likely (buffer->i < buffer->len)) {
+ hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, 0, &glyph);
+ buffer->replace_glyph (glyph);
+ }
buffer->swap ();
}
diff --git a/test/test-font.c b/test/test-font.c
index aa78a20..9c7d3e4 100644
--- a/test/test-font.c
+++ b/test/test-font.c
@@ -112,6 +112,7 @@ test_face_createfortables (void)
static void
_test_font_nil_funcs (hb_font_t *font)
{
+ hb_codepoint_t glyph;
hb_position_t x, y;
hb_glyph_extents_t extents;
@@ -133,7 +134,9 @@ _test_font_nil_funcs (hb_font_t *font)
g_assert_cmpint (extents.width, ==, 0);
g_assert_cmpint (extents.height, ==, 0);
- g_assert (0 == hb_font_get_glyph (font, 17, 2));
+ glyph = 3;
+ g_assert (!hb_font_get_glyph (font, 17, 2, &glyph));
+ g_assert_cmpint (glyph, ==, 0);
x = y = 13;
hb_font_get_kerning (font, 17, 19, &x, &y);
diff --git a/test/test-shape.c b/test/test-shape.c
index e40e9b2..ab3ddf1 100644
--- a/test/test-shape.c
+++ b/test/test-shape.c
@@ -44,17 +44,19 @@ glyph_advance_func (hb_font_t *font, void *font_data,
}
}
-static hb_codepoint_t
+static hb_bool_t
glyph_func (hb_font_t *font, void *font_data,
hb_codepoint_t unicode, hb_codepoint_t variant_selector,
+ hb_codepoint_t *glyph,
void *user_data)
{
switch (unicode) {
- case 'T': return 1;
- case 'e': return 2;
- case 's': return 3;
- default: return 0;
+ case 'T': *glyph = 1; return TRUE;
+ case 'e': *glyph = 2; return TRUE;
+ case 's': *glyph = 3; return TRUE;
}
+
+ return FALSE;
}
static void
commit 8e07f93ab4a3ef9adc7942727ef21f2f9a141d10
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Thu May 12 14:27:44 2011 -0400
[test/shape] Check shape output
diff --git a/test/test-shape.c b/test/test-shape.c
index cbdc064..e40e9b2 100644
--- a/test/test-shape.c
+++ b/test/test-shape.c
@@ -71,7 +71,7 @@ kerning_func (hb_font_t *font, void *font_data,
static const char TesT[] = "TesT";
static void
-test_shape_ltr (void)
+test_shape (void)
{
hb_blob_t *blob;
hb_face_t *face;
@@ -106,7 +106,23 @@ test_shape_ltr (void)
glyphs = hb_buffer_get_glyph_infos (buffer, NULL);
positions = hb_buffer_get_glyph_positions (buffer, NULL);
- /* XXX check glyph output and positions */
+ {
+ const hb_codepoint_t output_glyphs[] = {1, 2, 3, 1};
+ const hb_position_t output_x_advances[] = {9, 5, 5, 10};
+ const hb_position_t output_x_offsets[] = {0, -1, 0, 0};
+ unsigned int i;
+ g_assert_cmpint (len, ==, 4);
+ for (i = 0; i < len; i++) {
+ g_assert_cmphex (glyphs[i].codepoint, ==, output_glyphs[i]);
+ g_assert_cmphex (glyphs[i].cluster, ==, i);
+ }
+ for (i = 0; i < len; i++) {
+ g_assert_cmpint (output_x_advances[i], ==, positions[i].x_advance);
+ g_assert_cmpint (output_x_offsets [i], ==, positions[i].x_offset);
+ g_assert_cmpint (0, ==, positions[i].y_advance);
+ g_assert_cmpint (0, ==, positions[i].y_offset);
+ }
+ }
hb_buffer_destroy (buffer);
hb_font_destroy (font);
@@ -118,8 +134,7 @@ main (int argc, char **argv)
{
hb_test_init (&argc, &argv);
- //hb_test_add (test_shape_empty);
- hb_test_add (test_shape_ltr);
+ hb_test_add (test_shape);
return hb_test_run();
}
commit 805af72405a2f653f08de392d7172291ffe8e902
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Thu May 12 12:39:40 2011 -0400
Rename get_kernings() arguments from first/second_glyph to left/right_glyph
Makes it clear that kerning is in visual order.
diff --git a/src/hb-font.cc b/src/hb-font.cc
index 10f686e..6d974fe 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -115,14 +115,14 @@ hb_font_get_glyph_nil (hb_font_t *font HB_UNUSED,
static void
hb_font_get_kerning_nil (hb_font_t *font HB_UNUSED,
void *font_data HB_UNUSED,
- hb_codepoint_t first_glyph,
- hb_codepoint_t second_glyph,
+ hb_codepoint_t left_glyph,
+ hb_codepoint_t right_glyph,
hb_position_t *x_kern,
hb_position_t *y_kern,
void *user_data HB_UNUSED)
{
if (font->parent) {
- hb_font_get_kerning (font->parent, first_glyph, second_glyph, x_kern, y_kern);
+ hb_font_get_kerning (font->parent, left_glyph, right_glyph, x_kern, y_kern);
font->parent_scale_distance (x_kern, y_kern);
return;
}
@@ -298,12 +298,12 @@ hb_font_get_glyph (hb_font_t *font,
void
hb_font_get_kerning (hb_font_t *font,
- hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
+ hb_codepoint_t left_glyph, hb_codepoint_t right_glyph,
hb_position_t *x_kern, hb_position_t *y_kern)
{
*x_kern = *y_kern = 0;
return font->klass->get.kerning (font, font->user_data,
- first_glyph, second_glyph,
+ left_glyph, right_glyph,
x_kern, y_kern,
font->klass->user_data.kerning);
}
diff --git a/src/hb-font.h b/src/hb-font.h
index 97831ff..c6f80c3 100644
--- a/src/hb-font.h
+++ b/src/hb-font.h
@@ -144,7 +144,7 @@ typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, void *font_
hb_codepoint_t unicode, hb_codepoint_t variation_selector,
void *user_data);
typedef void (*hb_font_get_kerning_func_t) (hb_font_t *font, void *font_data,
- hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
+ hb_codepoint_t left_glyph, hb_codepoint_t right_glyph,
hb_position_t *x_kern, hb_position_t *y_kern,
void *user_data);
@@ -196,7 +196,7 @@ hb_font_get_glyph (hb_font_t *font,
void
hb_font_get_kerning (hb_font_t *font,
- hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
+ hb_codepoint_t left_glyph, hb_codepoint_t right_glyph,
hb_position_t *x_kern, hb_position_t *y_kern);
diff --git a/src/hb-ft.cc b/src/hb-ft.cc
index 9535ba1..b3a5cd0 100644
--- a/src/hb-ft.cc
+++ b/src/hb-ft.cc
@@ -131,8 +131,8 @@ hb_ft_get_glyph (hb_font_t *font HB_UNUSED,
static void
hb_ft_get_kerning (hb_font_t *font HB_UNUSED,
void *font_data,
- hb_codepoint_t first_glyph,
- hb_codepoint_t second_glyph,
+ hb_codepoint_t left_glyph,
+ hb_codepoint_t right_glyph,
hb_position_t *x_kern,
hb_position_t *y_kern,
void *user_data HB_UNUSED)
@@ -141,7 +141,7 @@ hb_ft_get_kerning (hb_font_t *font HB_UNUSED,
FT_Vector kerning;
/* TODO: Kern type? */
- if (FT_Get_Kerning (ft_face, first_glyph, second_glyph, FT_KERNING_DEFAULT, &kerning))
+ if (FT_Get_Kerning (ft_face, left_glyph, right_glyph, FT_KERNING_DEFAULT, &kerning))
return;
*x_kern = kerning.x;
More information about the HarfBuzz
mailing list