Index: third_party/harfbuzz-ng/src/hb-font.cc |
diff --git a/third_party/harfbuzz-ng/src/hb-font.cc b/third_party/harfbuzz-ng/src/hb-font.cc |
index 109caff3141e606cd1a60df802622a5b2bb2c07d..06270325698563035c0892e9a9ec553eb1da9586 100644 |
--- a/third_party/harfbuzz-ng/src/hb-font.cc |
+++ b/third_party/harfbuzz-ng/src/hb-font.cc |
@@ -1,5 +1,6 @@ |
/* |
* Copyright © 2009 Red Hat, Inc. |
+ * Copyright © 2012 Google, Inc. |
* |
* This is part of HarfBuzz, a text shaping library. |
* |
@@ -22,6 +23,7 @@ |
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
* |
* Red Hat Author(s): Behdad Esfahbod |
+ * Google Author(s): Behdad Esfahbod |
*/ |
#include "hb-private.hh" |
@@ -52,7 +54,7 @@ hb_font_get_glyph_nil (hb_font_t *font, |
void *user_data HB_UNUSED) |
{ |
if (font->parent) |
- return hb_font_get_glyph (font->parent, unicode, variation_selector, glyph); |
+ return font->parent->get_glyph (unicode, variation_selector, glyph); |
*glyph = 0; |
return false; |
@@ -65,7 +67,7 @@ hb_font_get_glyph_h_advance_nil (hb_font_t *font, |
void *user_data HB_UNUSED) |
{ |
if (font->parent) |
- return font->parent_scale_x_distance (hb_font_get_glyph_h_advance (font->parent, glyph)); |
+ return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph)); |
return font->x_scale; |
} |
@@ -77,7 +79,7 @@ hb_font_get_glyph_v_advance_nil (hb_font_t *font, |
void *user_data HB_UNUSED) |
{ |
if (font->parent) |
- return font->parent_scale_y_distance (hb_font_get_glyph_v_advance (font->parent, glyph)); |
+ return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph)); |
return font->y_scale; |
} |
@@ -91,7 +93,7 @@ hb_font_get_glyph_h_origin_nil (hb_font_t *font, |
void *user_data HB_UNUSED) |
{ |
if (font->parent) { |
- hb_bool_t ret = hb_font_get_glyph_h_origin (font->parent, glyph, x, y); |
+ hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y); |
if (ret) |
font->parent_scale_position (x, y); |
return ret; |
@@ -110,7 +112,7 @@ hb_font_get_glyph_v_origin_nil (hb_font_t *font, |
void *user_data HB_UNUSED) |
{ |
if (font->parent) { |
- hb_bool_t ret = hb_font_get_glyph_v_origin (font->parent, glyph, x, y); |
+ hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y); |
if (ret) |
font->parent_scale_position (x, y); |
return ret; |
@@ -128,7 +130,7 @@ hb_font_get_glyph_h_kerning_nil (hb_font_t *font, |
void *user_data HB_UNUSED) |
{ |
if (font->parent) |
- return font->parent_scale_x_distance (hb_font_get_glyph_h_kerning (font->parent, left_glyph, right_glyph)); |
+ return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph)); |
return 0; |
} |
@@ -141,7 +143,7 @@ hb_font_get_glyph_v_kerning_nil (hb_font_t *font, |
void *user_data HB_UNUSED) |
{ |
if (font->parent) |
- return font->parent_scale_y_distance (hb_font_get_glyph_v_kerning (font->parent, top_glyph, bottom_glyph)); |
+ return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph)); |
return 0; |
} |
@@ -154,9 +156,7 @@ hb_font_get_glyph_extents_nil (hb_font_t *font, |
void *user_data HB_UNUSED) |
{ |
if (font->parent) { |
- hb_bool_t ret = hb_font_get_glyph_extents (font->parent, |
- glyph, |
- extents); |
+ hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents); |
if (ret) { |
font->parent_scale_position (&extents->x_bearing, &extents->y_bearing); |
font->parent_scale_distance (&extents->width, &extents->height); |
@@ -178,7 +178,7 @@ hb_font_get_glyph_contour_point_nil (hb_font_t *font, |
void *user_data HB_UNUSED) |
{ |
if (font->parent) { |
- hb_bool_t ret = hb_font_get_glyph_contour_point (font->parent, glyph, point_index, x, y); |
+ hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y); |
if (ret) |
font->parent_scale_position (x, y); |
return ret; |
@@ -196,9 +196,9 @@ hb_font_get_glyph_name_nil (hb_font_t *font, |
void *user_data HB_UNUSED) |
{ |
if (font->parent) |
- return hb_font_get_glyph_name (font->parent, glyph, name, size); |
+ return font->parent->get_glyph_name (glyph, name, size); |
- snprintf (name, size, "gid%u", glyph); |
+ if (size) *name = '\0'; |
return false; |
} |
@@ -210,7 +210,7 @@ hb_font_get_glyph_from_name_nil (hb_font_t *font, |
void *user_data HB_UNUSED) |
{ |
if (font->parent) |
- return hb_font_get_glyph_from_name (font->parent, name, len, glyph); |
+ return font->parent->get_glyph_from_name (name, len, glyph); |
*glyph = 0; |
return false; |
@@ -334,33 +334,28 @@ HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
#undef HB_FONT_FUNC_IMPLEMENT |
+/* Public getters */ |
+ |
hb_bool_t |
hb_font_get_glyph (hb_font_t *font, |
hb_codepoint_t unicode, hb_codepoint_t variation_selector, |
hb_codepoint_t *glyph) |
{ |
- *glyph = 0; |
- return font->klass->get.glyph (font, font->user_data, |
- unicode, variation_selector, glyph, |
- font->klass->user_data.glyph); |
+ return font->get_glyph (unicode, variation_selector, glyph); |
} |
hb_position_t |
hb_font_get_glyph_h_advance (hb_font_t *font, |
hb_codepoint_t glyph) |
{ |
- return font->klass->get.glyph_h_advance (font, font->user_data, |
- glyph, |
- font->klass->user_data.glyph_h_advance); |
+ return font->get_glyph_h_advance (glyph); |
} |
hb_position_t |
hb_font_get_glyph_v_advance (hb_font_t *font, |
hb_codepoint_t glyph) |
{ |
- return font->klass->get.glyph_v_advance (font, font->user_data, |
- glyph, |
- font->klass->user_data.glyph_v_advance); |
+ return font->get_glyph_v_advance (glyph); |
} |
hb_bool_t |
@@ -368,10 +363,7 @@ hb_font_get_glyph_h_origin (hb_font_t *font, |
hb_codepoint_t glyph, |
hb_position_t *x, hb_position_t *y) |
{ |
- *x = *y = 0; |
- return font->klass->get.glyph_h_origin (font, font->user_data, |
- glyph, x, y, |
- font->klass->user_data.glyph_h_origin); |
+ return font->get_glyph_h_origin (glyph, x, y); |
} |
hb_bool_t |
@@ -379,28 +371,21 @@ hb_font_get_glyph_v_origin (hb_font_t *font, |
hb_codepoint_t glyph, |
hb_position_t *x, hb_position_t *y) |
{ |
- *x = *y = 0; |
- return font->klass->get.glyph_v_origin (font, font->user_data, |
- glyph, x, y, |
- font->klass->user_data.glyph_v_origin); |
+ return font->get_glyph_v_origin (glyph, x, y); |
} |
hb_position_t |
hb_font_get_glyph_h_kerning (hb_font_t *font, |
hb_codepoint_t left_glyph, hb_codepoint_t right_glyph) |
{ |
- return font->klass->get.glyph_h_kerning (font, font->user_data, |
- left_glyph, right_glyph, |
- font->klass->user_data.glyph_h_kerning); |
+ return font->get_glyph_h_kerning (left_glyph, right_glyph); |
} |
hb_position_t |
hb_font_get_glyph_v_kerning (hb_font_t *font, |
hb_codepoint_t left_glyph, hb_codepoint_t right_glyph) |
{ |
- return font->klass->get.glyph_v_kerning (font, font->user_data, |
- left_glyph, right_glyph, |
- font->klass->user_data.glyph_v_kerning); |
+ return font->get_glyph_v_kerning (left_glyph, right_glyph); |
} |
hb_bool_t |
@@ -408,11 +393,7 @@ hb_font_get_glyph_extents (hb_font_t *font, |
hb_codepoint_t glyph, |
hb_glyph_extents_t *extents) |
{ |
- memset (extents, 0, sizeof (*extents)); |
- return font->klass->get.glyph_extents (font, font->user_data, |
- glyph, |
- extents, |
- font->klass->user_data.glyph_extents); |
+ return font->get_glyph_extents (glyph, extents); |
} |
hb_bool_t |
@@ -420,11 +401,7 @@ hb_font_get_glyph_contour_point (hb_font_t *font, |
hb_codepoint_t glyph, unsigned int point_index, |
hb_position_t *x, hb_position_t *y) |
{ |
- *x = *y = 0; |
- return font->klass->get.glyph_contour_point (font, font->user_data, |
- glyph, point_index, |
- x, y, |
- font->klass->user_data.glyph_contour_point); |
+ return font->get_glyph_contour_point (glyph, point_index, x, y); |
} |
hb_bool_t |
@@ -432,10 +409,7 @@ hb_font_get_glyph_name (hb_font_t *font, |
hb_codepoint_t glyph, |
char *name, unsigned int size) |
{ |
- return font->klass->get.glyph_name (font, font->user_data, |
- glyph, |
- name, size, |
- font->klass->user_data.glyph_name); |
+ return font->get_glyph_name (glyph, name, size); |
} |
hb_bool_t |
@@ -443,10 +417,7 @@ hb_font_get_glyph_from_name (hb_font_t *font, |
const char *name, int len, /* -1 means nul-terminated */ |
hb_codepoint_t *glyph) |
{ |
- return font->klass->get.glyph_from_name (font, font->user_data, |
- name, len, |
- glyph, |
- font->klass->user_data.glyph_from_name); |
+ return font->get_glyph_from_name (name, len, glyph); |
} |
@@ -458,48 +429,16 @@ hb_font_get_glyph_advance_for_direction (hb_font_t *font, |
hb_direction_t direction, |
hb_position_t *x, hb_position_t *y) |
{ |
- if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { |
- *x = hb_font_get_glyph_h_advance (font, glyph); |
- *y = 0; |
- } else { |
- *x = 0; |
- *y = hb_font_get_glyph_v_advance (font, glyph); |
- } |
+ return font->get_glyph_advance_for_direction (glyph, direction, x, y); |
} |
-static void |
-guess_v_origin_minus_h_origin (hb_font_t *font, |
- hb_codepoint_t glyph, |
- hb_position_t *x, hb_position_t *y) |
-{ |
- *x = hb_font_get_glyph_h_advance (font, glyph) / 2; |
- |
- /* TODO use font_metics.ascent */ |
- *y = font->y_scale; |
-} |
- |
- |
void |
hb_font_get_glyph_origin_for_direction (hb_font_t *font, |
hb_codepoint_t glyph, |
hb_direction_t direction, |
hb_position_t *x, hb_position_t *y) |
{ |
- if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { |
- hb_bool_t ret = hb_font_get_glyph_h_origin (font, glyph, x, y); |
- if (!ret && (ret = hb_font_get_glyph_v_origin (font, glyph, x, y))) { |
- hb_position_t dx, dy; |
- guess_v_origin_minus_h_origin (font, glyph, &dx, &dy); |
- *x -= dx; *y -= dy; |
- } |
- } else { |
- hb_bool_t ret = hb_font_get_glyph_v_origin (font, glyph, x, y); |
- if (!ret && (ret = hb_font_get_glyph_h_origin (font, glyph, x, y))) { |
- hb_position_t dx, dy; |
- guess_v_origin_minus_h_origin (font, glyph, &dx, &dy); |
- *x += dx; *y += dy; |
- } |
- } |
+ return font->get_glyph_origin_for_direction (glyph, direction, x, y); |
} |
void |
@@ -508,12 +447,7 @@ hb_font_add_glyph_origin_for_direction (hb_font_t *font, |
hb_direction_t direction, |
hb_position_t *x, hb_position_t *y) |
{ |
- hb_position_t origin_x, origin_y; |
- |
- hb_font_get_glyph_origin_for_direction (font, glyph, direction, &origin_x, &origin_y); |
- |
- *x += origin_x; |
- *y += origin_y; |
+ return font->add_glyph_origin_for_direction (glyph, direction, x, y); |
} |
void |
@@ -522,12 +456,7 @@ hb_font_subtract_glyph_origin_for_direction (hb_font_t *font, |
hb_direction_t direction, |
hb_position_t *x, hb_position_t *y) |
{ |
- hb_position_t origin_x, origin_y; |
- |
- hb_font_get_glyph_origin_for_direction (font, glyph, direction, &origin_x, &origin_y); |
- |
- *x -= origin_x; |
- *y -= origin_y; |
+ return font->subtract_glyph_origin_for_direction (glyph, direction, x, y); |
} |
void |
@@ -536,13 +465,7 @@ hb_font_get_glyph_kerning_for_direction (hb_font_t *font, |
hb_direction_t direction, |
hb_position_t *x, hb_position_t *y) |
{ |
- if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { |
- *x = hb_font_get_glyph_h_kerning (font, first_glyph, second_glyph); |
- *y = 0; |
- } else { |
- *x = 0; |
- *y = hb_font_get_glyph_v_kerning (font, first_glyph, second_glyph); |
- } |
+ return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y); |
} |
hb_bool_t |
@@ -551,12 +474,7 @@ hb_font_get_glyph_extents_for_origin (hb_font_t *font, |
hb_direction_t direction, |
hb_glyph_extents_t *extents) |
{ |
- hb_bool_t ret = hb_font_get_glyph_extents (font, glyph, extents); |
- |
- if (ret) |
- hb_font_subtract_glyph_origin_for_direction (font, glyph, direction, &extents->x_bearing, &extents->y_bearing); |
- |
- return ret; |
+ return font->get_glyph_extents_for_origin (glyph, direction, extents); |
} |
hb_bool_t |
@@ -565,12 +483,25 @@ hb_font_get_glyph_contour_point_for_origin (hb_font_t *font, |
hb_direction_t direction, |
hb_position_t *x, hb_position_t *y) |
{ |
- hb_bool_t ret = hb_font_get_glyph_contour_point (font, glyph, point_index, x, y); |
+ return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y); |
+} |
- if (ret) |
- hb_font_subtract_glyph_origin_for_direction (font, glyph, direction, x, y); |
+/* Generates gidDDD if glyph has no name. */ |
+void |
+hb_font_glyph_to_string (hb_font_t *font, |
+ hb_codepoint_t glyph, |
+ char *s, unsigned int size) |
+{ |
+ font->glyph_to_string (glyph, s, size); |
+} |
- return ret; |
+/* Parses gidDDD and uniUUUU strings automatically. */ |
+hb_bool_t |
+hb_font_glyph_from_string (hb_font_t *font, |
+ const char *s, int len, /* -1 means nul-terminated */ |
+ hb_codepoint_t *glyph) |
+{ |
+ return font->glyph_from_string (s, len, glyph); |
} |
@@ -583,43 +514,47 @@ static const hb_face_t _hb_face_nil = { |
true, /* immutable */ |
- NULL, /* reference_table */ |
+ NULL, /* reference_table_func */ |
NULL, /* user_data */ |
NULL, /* destroy */ |
- NULL, /* ot_layout */ |
- |
0, /* index */ |
- 1000 /* upem */ |
+ 1000, /* upem */ |
+ |
+ { |
+#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, |
+#include "hb-shaper-list.hh" |
+#undef HB_SHAPER_IMPLEMENT |
+ }, |
+ |
+ NULL, /* shape_plans */ |
}; |
hb_face_t * |
-hb_face_create_for_tables (hb_reference_table_func_t reference_table, |
+hb_face_create_for_tables (hb_reference_table_func_t reference_table_func, |
void *user_data, |
hb_destroy_func_t destroy) |
{ |
hb_face_t *face; |
- if (!reference_table || !(face = hb_object_create<hb_face_t> ())) { |
+ if (!reference_table_func || !(face = hb_object_create<hb_face_t> ())) { |
if (destroy) |
destroy (user_data); |
return hb_face_get_empty (); |
} |
- face->reference_table = reference_table; |
+ face->reference_table_func = reference_table_func; |
face->user_data = user_data; |
face->destroy = destroy; |
- face->ot_layout = _hb_ot_layout_create (face); |
- |
face->upem = 0; |
return face; |
} |
-typedef struct _hb_face_for_data_closure_t { |
+typedef struct hb_face_for_data_closure_t { |
hb_blob_t *blob; |
unsigned int index; |
} hb_face_for_data_closure_t; |
@@ -654,10 +589,10 @@ _hb_face_for_data_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void |
if (tag == HB_TAG_NONE) |
return hb_blob_reference (data->blob); |
- const OpenTypeFontFile &ot_file = *Sanitizer<OpenTypeFontFile>::lock_instance (data->blob); |
- const OpenTypeFontFace &ot_face = ot_file.get_face (data->index); |
+ const OT::OpenTypeFontFile &ot_file = *OT::Sanitizer<OT::OpenTypeFontFile>::lock_instance (data->blob); |
+ const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index); |
- const OpenTypeTable &table = ot_face.get_table_by_tag (tag); |
+ const OT::OpenTypeTable &table = ot_face.get_table_by_tag (tag); |
hb_blob_t *blob = hb_blob_create_sub_blob (data->blob, table.offset, table.length); |
@@ -673,7 +608,7 @@ hb_face_create (hb_blob_t *blob, |
if (unlikely (!blob || !hb_blob_get_length (blob))) |
return hb_face_get_empty (); |
- hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (Sanitizer<OpenTypeFontFile>::sanitize (hb_blob_reference (blob)), index); |
+ hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (OT::Sanitizer<OT::OpenTypeFontFile>::sanitize (hb_blob_reference (blob)), index); |
if (unlikely (!closure)) |
return hb_face_get_empty (); |
@@ -705,7 +640,17 @@ hb_face_destroy (hb_face_t *face) |
{ |
if (!hb_object_destroy (face)) return; |
- _hb_ot_layout_destroy (face->ot_layout); |
+ for (hb_face_t::plan_node_t *node = face->shape_plans; node; ) |
+ { |
+ hb_face_t::plan_node_t *next = node->next; |
+ hb_shape_plan_destroy (node->shape_plan); |
+ free (node); |
+ node = next; |
+ } |
+ |
+#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, face); |
+#include "hb-shaper-list.hh" |
+#undef HB_SHAPER_IMPLEMENT |
if (face->destroy) |
face->destroy (face->user_data); |
@@ -750,22 +695,13 @@ hb_blob_t * |
hb_face_reference_table (hb_face_t *face, |
hb_tag_t tag) |
{ |
- hb_blob_t *blob; |
- |
- if (unlikely (!face || !face->reference_table)) |
- return hb_blob_get_empty (); |
- |
- blob = face->reference_table (face, tag, face->user_data); |
- if (unlikely (!blob)) |
- return hb_blob_get_empty (); |
- |
- return blob; |
+ return face->reference_table (tag); |
} |
hb_blob_t * |
hb_face_reference_blob (hb_face_t *face) |
{ |
- return hb_face_reference_table (face, HB_TAG_NONE); |
+ return face->reference_table (HB_TAG_NONE); |
} |
void |
@@ -797,13 +733,17 @@ hb_face_set_upem (hb_face_t *face, |
unsigned int |
hb_face_get_upem (hb_face_t *face) |
{ |
- if (unlikely (!face->upem)) { |
- hb_blob_t *head_blob = Sanitizer<head>::sanitize (hb_face_reference_table (face, HB_OT_TAG_head)); |
- const head *head_table = Sanitizer<head>::lock_instance (head_blob); |
- face->upem = head_table->get_upem (); |
- hb_blob_destroy (head_blob); |
- } |
- return face->upem; |
+ return face->get_upem (); |
+} |
+ |
+ |
+void |
+hb_face_t::load_upem (void) const |
+{ |
+ hb_blob_t *head_blob = OT::Sanitizer<OT::head>::sanitize (reference_table (HB_OT_TAG_head)); |
+ const OT::head *head_table = OT::Sanitizer<OT::head>::lock_instance (head_blob); |
+ upem = head_table->get_upem (); |
+ hb_blob_destroy (head_blob); |
} |
@@ -871,7 +811,13 @@ hb_font_get_empty (void) |
const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */ |
NULL, /* user_data */ |
- NULL /* destroy */ |
+ NULL, /* destroy */ |
+ |
+ { |
+#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, |
+#include "hb-shaper-list.hh" |
+#undef HB_SHAPER_IMPLEMENT |
+ } |
}; |
return const_cast<hb_font_t *> (&_hb_font_nil); |
@@ -888,11 +834,16 @@ hb_font_destroy (hb_font_t *font) |
{ |
if (!hb_object_destroy (font)) return; |
+#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font); |
+#include "hb-shaper-list.hh" |
+#undef HB_SHAPER_IMPLEMENT |
+ |
+ if (font->destroy) |
+ font->destroy (font->user_data); |
+ |
hb_font_destroy (font->parent); |
hb_face_destroy (font->face); |
hb_font_funcs_destroy (font->klass); |
- if (font->destroy) |
- font->destroy (font->user_data); |
free (font); |
} |
@@ -1028,5 +979,3 @@ hb_font_get_ppem (hb_font_t *font, |
if (x_ppem) *x_ppem = font->x_ppem; |
if (y_ppem) *y_ppem = font->y_ppem; |
} |
- |
- |