summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-12-15 13:00:39 +0100
committerLars Knoll <lars.knoll@qt.io>2017-12-30 15:17:28 +0000
commit809200a83e366141d543336503635cf57c626434 (patch)
treefc3aa70aa67f69ea2247a7ef30819ff4e98ead1b /src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc
parent89b0364cded81457eaa264c1634af5d082da3c21 (diff)
Update bundled HarfBuzz-NG copy to 1.7.4
This is the latest released version, fixing a large amount of bugs and adding Unicode 10 support. [ChangeLog] Bundled HarfBuzz-NG copy updated to 1.7.4 Change-Id: Idc8092dfc4e593d64fff2fd51ff9e1b3d84049a7 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc')
-rw-r--r--src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc151
1 files changed, 102 insertions, 49 deletions
diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc b/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc
index ddd6662e84..2f28b5620d 100644
--- a/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc
+++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc
@@ -70,7 +70,7 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
hb_ot_map_builder_t *map = &planner->map;
map->add_global_bool_feature (HB_TAG('r','v','r','n'));
- map->add_gsub_pause (NULL);
+ map->add_gsub_pause (nullptr);
switch (props->direction) {
case HB_DIRECTION_LTR:
@@ -108,7 +108,7 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
/* We really want to find a 'vert' feature if there's any in the font, no
* matter which script/langsys it is listed (or not) under.
* See various bugs referenced from:
- * https://github.com/behdad/harfbuzz/issues/63 */
+ * https://github.com/harfbuzz/harfbuzz/issues/63 */
map->add_feature (HB_TAG ('v','e','r','t'), 1, F_GLOBAL | F_GLOBAL_SEARCH);
}
@@ -128,6 +128,8 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
* shaper face data
*/
+HB_SHAPER_DATA_ENSURE_DEFINE(ot, face)
+
hb_ot_shaper_face_data_t *
_hb_ot_shaper_face_data_create (hb_face_t *face)
{
@@ -145,6 +147,8 @@ _hb_ot_shaper_face_data_destroy (hb_ot_shaper_face_data_t *data)
* shaper font data
*/
+HB_SHAPER_DATA_ENSURE_DEFINE(ot, font)
+
struct hb_ot_shaper_font_data_t {};
hb_ot_shaper_font_data_t *
@@ -172,7 +176,7 @@ _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan,
{
hb_ot_shape_plan_t *plan = (hb_ot_shape_plan_t *) calloc (1, sizeof (hb_ot_shape_plan_t));
if (unlikely (!plan))
- return NULL;
+ return nullptr;
hb_ot_shape_planner_t planner (shape_plan);
@@ -186,7 +190,7 @@ _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan,
if (plan->shaper->data_create) {
plan->data = plan->shaper->data_create (plan);
if (unlikely (!plan->data))
- return NULL;
+ return nullptr;
}
return plan;
@@ -271,8 +275,7 @@ hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font)
static void
hb_form_clusters (hb_buffer_t *buffer)
{
- if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII) ||
- buffer->cluster_level != HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES)
+ if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII))
return;
/* Loop duplicated in hb_ensure_native_direction(), and in _hb-coretext.cc */
@@ -284,11 +287,17 @@ hb_form_clusters (hb_buffer_t *buffer)
if (likely (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i])) &&
!_hb_glyph_info_is_joiner (&info[i])))
{
- buffer->merge_clusters (base, i);
+ if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES)
+ buffer->merge_clusters (base, i);
+ else
+ buffer->unsafe_to_break (base, i);
base = i;
}
}
- buffer->merge_clusters (base, count);
+ if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES)
+ buffer->merge_clusters (base, count);
+ else
+ buffer->unsafe_to_break (base, count);
}
static void
@@ -362,7 +371,18 @@ hb_ot_shape_setup_masks_fraction (hb_ot_shape_context_t *c)
hb_buffer_t *buffer = c->buffer;
- /* TODO look in pre/post context text also. */
+ hb_mask_t pre_mask, post_mask;
+ if (HB_DIRECTION_IS_FORWARD (buffer->props.direction))
+ {
+ pre_mask = c->plan->numr_mask | c->plan->frac_mask;
+ post_mask = c->plan->frac_mask | c->plan->dnom_mask;
+ }
+ else
+ {
+ pre_mask = c->plan->frac_mask | c->plan->dnom_mask;
+ post_mask = c->plan->numr_mask | c->plan->frac_mask;
+ }
+
unsigned int count = buffer->len;
hb_glyph_info_t *info = buffer->info;
for (unsigned int i = 0; i < count; i++)
@@ -379,11 +399,13 @@ hb_ot_shape_setup_masks_fraction (hb_ot_shape_context_t *c)
HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER)
end++;
+ buffer->unsafe_to_break (start, end);
+
for (unsigned int j = start; j < i; j++)
- info[j].mask |= c->plan->numr_mask | c->plan->frac_mask;
+ info[j].mask |= pre_mask;
info[i].mask |= c->plan->frac_mask;
for (unsigned int j = i + 1; j < end; j++)
- info[j].mask |= c->plan->frac_mask | c->plan->dnom_mask;
+ info[j].mask |= post_mask;
i = end - 1;
}
@@ -494,9 +516,10 @@ hb_ot_hide_default_ignorables (hb_ot_shape_context_t *c)
/* Merge cluster backward. */
if (cluster < info[j - 1].cluster)
{
+ unsigned int mask = info[i].mask;
unsigned int old_cluster = info[j - 1].cluster;
for (unsigned k = j; k && info[k - 1].cluster == old_cluster; k--)
- info[k - 1].cluster = cluster;
+ buffer->set_cluster (info[k - 1], cluster, mask);
}
continue;
}
@@ -562,8 +585,6 @@ hb_ot_substitute_default (hb_ot_shape_context_t *c)
{
hb_buffer_t *buffer = c->buffer;
- hb_ot_shape_initialize_masks (c);
-
hb_ot_mirror_chars (c);
HB_BUFFER_ALLOCATE_VAR (buffer, glyph_index);
@@ -672,9 +693,9 @@ hb_ot_position_default (hb_ot_shape_context_t *c)
static inline void
hb_ot_position_complex (hb_ot_shape_context_t *c)
{
- hb_ot_layout_position_start (c->font, c->buffer);
-
unsigned int count = c->buffer->len;
+ hb_glyph_info_t *info = c->buffer->info;
+ hb_glyph_position_t *pos = c->buffer->pos;
/* If the font has no GPOS, AND, no fallback positioning will
* happen, AND, direction is forward, then when zeroing mark
@@ -689,6 +710,17 @@ hb_ot_position_complex (hb_ot_shape_context_t *c)
!c->plan->shaper->fallback_position &&
HB_DIRECTION_IS_FORWARD (c->buffer->props.direction);
+ /* We change glyph origin to what GPOS expects (horizontal), apply GPOS, change it back. */
+
+ /* The nil glyph_h_origin() func returns 0, so no need to apply it. */
+ if (c->font->has_glyph_h_origin_func ())
+ for (unsigned int i = 0; i < count; i++)
+ c->font->add_glyph_h_origin (info[i].codepoint,
+ &pos[i].x_offset,
+ &pos[i].y_offset);
+
+ hb_ot_layout_position_start (c->font, c->buffer);
+
switch (c->plan->shaper->zero_width_marks)
{
case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY:
@@ -702,30 +734,8 @@ hb_ot_position_complex (hb_ot_shape_context_t *c)
}
if (likely (!c->fallback_positioning))
- {
- hb_glyph_info_t *info = c->buffer->info;
- hb_glyph_position_t *pos = c->buffer->pos;
-
- /* Change glyph origin to what GPOS expects (horizontal), apply GPOS, change it back. */
-
- /* The nil glyph_h_origin() func returns 0, so no need to apply it. */
- if (c->font->has_glyph_h_origin_func ())
- for (unsigned int i = 0; i < count; i++)
- c->font->add_glyph_h_origin (info[i].codepoint,
- &pos[i].x_offset,
- &pos[i].y_offset);
-
c->plan->position (c->font, c->buffer);
- /* The nil glyph_h_origin() func returns 0, so no need to apply it. */
- if (c->font->has_glyph_h_origin_func ())
- for (unsigned int i = 0; i < count; i++)
- c->font->subtract_glyph_h_origin (info[i].codepoint,
- &pos[i].x_offset,
- &pos[i].y_offset);
-
- }
-
switch (c->plan->shaper->zero_width_marks)
{
case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE:
@@ -742,6 +752,13 @@ hb_ot_position_complex (hb_ot_shape_context_t *c)
hb_ot_layout_position_finish_advances (c->font, c->buffer);
hb_ot_zero_width_default_ignorables (c);
hb_ot_layout_position_finish_offsets (c->font, c->buffer);
+
+ /* The nil glyph_h_origin() func returns 0, so no need to apply it. */
+ if (c->font->has_glyph_h_origin_func ())
+ for (unsigned int i = 0; i < count; i++)
+ c->font->subtract_glyph_h_origin (info[i].codepoint,
+ &pos[i].x_offset,
+ &pos[i].y_offset);
}
static inline void
@@ -767,6 +784,31 @@ hb_ot_position (hb_ot_shape_context_t *c)
_hb_buffer_deallocate_gsubgpos_vars (c->buffer);
}
+static inline void
+hb_propagate_flags (hb_buffer_t *buffer)
+{
+ /* Propagate cluster-level glyph flags to be the same on all cluster glyphs.
+ * Simplifies using them. */
+
+ if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_UNSAFE_TO_BREAK))
+ return;
+
+ hb_glyph_info_t *info = buffer->info;
+
+ foreach_cluster (buffer, start, end)
+ {
+ unsigned int mask = 0;
+ for (unsigned int i = start; i < end; i++)
+ if (info[i].mask & HB_GLYPH_FLAG_UNSAFE_TO_BREAK)
+ {
+ mask = HB_GLYPH_FLAG_UNSAFE_TO_BREAK;
+ break;
+ }
+ if (mask)
+ for (unsigned int i = start; i < end; i++)
+ info[i].mask |= mask;
+ }
+}
/* Pull it all together! */
@@ -775,11 +817,16 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c)
{
c->buffer->deallocate_var_all ();
c->buffer->scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;
- if (likely (!_hb_unsigned_int_mul_overflows (c->buffer->len, HB_BUFFER_MAX_EXPANSION_FACTOR)))
+ if (likely (!_hb_unsigned_int_mul_overflows (c->buffer->len, HB_BUFFER_MAX_LEN_FACTOR)))
{
- c->buffer->max_len = MAX (c->buffer->len * HB_BUFFER_MAX_EXPANSION_FACTOR,
+ c->buffer->max_len = MAX (c->buffer->len * HB_BUFFER_MAX_LEN_FACTOR,
(unsigned) HB_BUFFER_MAX_LEN_MIN);
}
+ if (likely (!_hb_unsigned_int_mul_overflows (c->buffer->len, HB_BUFFER_MAX_OPS_FACTOR)))
+ {
+ c->buffer->max_ops = MAX (c->buffer->len * HB_BUFFER_MAX_OPS_FACTOR,
+ (unsigned) HB_BUFFER_MAX_OPS_MIN);
+ }
bool disable_otl = c->plan->shaper->disable_otl && c->plan->shaper->disable_otl (c->plan);
//c->fallback_substitute = disable_otl || !hb_ot_layout_has_substitution (c->face);
@@ -793,8 +840,10 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c)
c->buffer->clear_output ();
+ hb_ot_shape_initialize_masks (c);
hb_set_unicode_props (c->buffer);
hb_insert_dotted_circle (c->buffer, c->font);
+
hb_form_clusters (c->buffer);
hb_ensure_native_direction (c->buffer);
@@ -810,11 +859,14 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c)
if (c->plan->shaper->postprocess_glyphs)
c->plan->shaper->postprocess_glyphs (c->plan, c->buffer, c->font);
+ hb_propagate_flags (c->buffer);
+
_hb_buffer_deallocate_unicode_vars (c->buffer);
c->buffer->props.direction = c->target_direction;
c->buffer->max_len = HB_BUFFER_MAX_LEN_DEFAULT;
+ c->buffer->max_ops = HB_BUFFER_MAX_OPS_DEFAULT;
c->buffer->deallocate_var_all ();
}
@@ -882,7 +934,7 @@ hb_ot_shape_glyphs_closure (hb_font_t *font,
{
hb_ot_shape_plan_t plan;
- const char *shapers[] = {"ot", NULL};
+ const char *shapers[] = {"ot", nullptr};
hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face, &buffer->props,
features, num_features, shapers);
@@ -893,18 +945,19 @@ hb_ot_shape_glyphs_closure (hb_font_t *font,
for (unsigned int i = 0; i < count; i++)
add_char (font, buffer->unicode, mirror, info[i].codepoint, glyphs);
- hb_set_t lookups;
- lookups.init ();
- hb_ot_shape_plan_collect_lookups (shape_plan, HB_OT_TAG_GSUB, &lookups);
+ hb_set_t *lookups = hb_set_create ();
+ hb_ot_shape_plan_collect_lookups (shape_plan, HB_OT_TAG_GSUB, lookups);
/* And find transitive closure. */
- hb_set_t copy;
- copy.init ();
+ hb_set_t *copy = hb_set_create ();
do {
- copy.set (glyphs);
- for (hb_codepoint_t lookup_index = -1; hb_set_next (&lookups, &lookup_index);)
+ copy->set (glyphs);
+ for (hb_codepoint_t lookup_index = -1; hb_set_next (lookups, &lookup_index);)
hb_ot_layout_lookup_substitute_closure (font->face, lookup_index, glyphs);
- } while (!copy.is_equal (glyphs));
+ } while (!copy->is_equal (glyphs));
+ hb_set_destroy (copy);
+
+ hb_set_destroy (lookups);
hb_shape_plan_destroy (shape_plan);
}