summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc')
-rw-r--r--src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc207
1 files changed, 148 insertions, 59 deletions
diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc b/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc
index 07adb04f67..40332d69f1 100644
--- a/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc
+++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc
@@ -59,10 +59,6 @@ static hb_tag_t horizontal_features[] = {
HB_TAG('r','c','l','t'),
};
-static hb_tag_t vertical_features[] = {
- HB_TAG('v','e','r','t'),
-};
-
static void
@@ -105,10 +101,13 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
(horizontal_features[i] == HB_TAG('k','e','r','n') ?
F_HAS_FALLBACK : F_NONE));
else
- for (unsigned int i = 0; i < ARRAY_LENGTH (vertical_features); i++)
- map->add_feature (vertical_features[i], 1, F_GLOBAL |
- (vertical_features[i] == HB_TAG('v','k','r','n') ?
- F_HAS_FALLBACK : F_NONE));
+ {
+ /* 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 */
+ map->add_feature (HB_TAG ('v','e','r','t'), 1, F_GLOBAL | F_GLOBAL_SEARCH);
+ }
if (planner->shaper->override_features)
planner->shaper->override_features (planner);
@@ -264,11 +263,22 @@ hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font)
static void
hb_form_clusters (hb_buffer_t *buffer)
{
+ if (buffer->cluster_level != HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES)
+ return;
+
+ /* Loop duplicated in hb_ensure_native_direction(). */
+ unsigned int base = 0;
unsigned int count = buffer->len;
hb_glyph_info_t *info = buffer->info;
for (unsigned int i = 1; i < count; i++)
- if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i])))
- buffer->merge_clusters (i - 1, i + 1);
+ {
+ if (likely (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i]))))
+ {
+ buffer->merge_clusters (base, i);
+ base = i;
+ }
+ }
+ buffer->merge_clusters (base, count);
}
static void
@@ -283,7 +293,28 @@ hb_ensure_native_direction (hb_buffer_t *buffer)
if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_horizontal_direction (buffer->props.script)) ||
(HB_DIRECTION_IS_VERTICAL (direction) && direction != HB_DIRECTION_TTB))
{
- hb_buffer_reverse_clusters (buffer);
+ /* Same loop as hb_form_clusters().
+ * Since form_clusters() merged clusters already, we don't merge. */
+ unsigned int base = 0;
+ unsigned int count = buffer->len;
+ hb_glyph_info_t *info = buffer->info;
+ for (unsigned int i = 1; i < count; i++)
+ {
+ if (likely (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i]))))
+ {
+ if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS)
+ buffer->merge_clusters (base, i);
+ buffer->reverse_range (base, i);
+
+ base = i;
+ }
+ }
+ if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS)
+ buffer->merge_clusters (base, count);
+ buffer->reverse_range (base, count);
+
+ buffer->reverse ();
+
buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction);
}
}
@@ -305,7 +336,7 @@ hb_ot_mirror_chars (hb_ot_shape_context_t *c)
hb_glyph_info_t *info = buffer->info;
for (unsigned int i = 0; i < count; i++) {
hb_codepoint_t codepoint = unicode->mirroring (info[i].codepoint);
- if (likely (codepoint == info[i].codepoint))
+ if (likely (codepoint == info[i].codepoint || !c->font->has_glyph (codepoint)))
info[i].mask |= rtlm_mask;
else
info[i].codepoint = codepoint;
@@ -380,6 +411,101 @@ hb_ot_shape_setup_masks (hb_ot_shape_context_t *c)
}
}
+static void
+hb_ot_zero_width_default_ignorables (hb_ot_shape_context_t *c)
+{
+ hb_buffer_t *buffer = c->buffer;
+
+ if (buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES)
+ return;
+
+ unsigned int count = buffer->len;
+ hb_glyph_info_t *info = buffer->info;
+ hb_glyph_position_t *pos = buffer->pos;
+ unsigned int i = 0;
+ for (i = 0; i < count; i++)
+ if (unlikely (_hb_glyph_info_is_default_ignorable (&info[i])))
+ pos[i].x_advance = pos[i].y_advance = pos[i].x_offset = pos[i].y_offset = 0;
+}
+
+static void
+hb_ot_hide_default_ignorables (hb_ot_shape_context_t *c)
+{
+ hb_buffer_t *buffer = c->buffer;
+
+ if (buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES)
+ return;
+
+ unsigned int count = buffer->len;
+ hb_glyph_info_t *info = buffer->info;
+ hb_glyph_position_t *pos = buffer->pos;
+ unsigned int i = 0;
+ for (i = 0; i < count; i++)
+ {
+ if (unlikely (_hb_glyph_info_is_default_ignorable (&info[i])))
+ break;
+ }
+
+ /* No default-ignorables found; return. */
+ if (i == count)
+ return;
+
+ hb_codepoint_t space;
+ if (c->font->get_glyph (' ', 0, &space))
+ {
+ /* Replace default-ignorables with a zero-advance space glyph. */
+ for (/*continue*/; i < count; i++)
+ {
+ if (_hb_glyph_info_is_default_ignorable (&info[i]))
+ info[i].codepoint = space;
+ }
+ }
+ else
+ {
+ /* Merge clusters and delete default-ignorables.
+ * NOTE! We can't use out-buffer as we have positioning data. */
+ unsigned int j = i;
+ for (; i < count; i++)
+ {
+ if (_hb_glyph_info_is_default_ignorable (&info[i]))
+ {
+ /* Merge clusters.
+ * Same logic as buffer->delete_glyph(), but for in-place removal. */
+
+ unsigned int cluster = info[i].cluster;
+ if (i + 1 < count && cluster == info[i + 1].cluster)
+ continue; /* Cluster survives; do nothing. */
+
+ if (j)
+ {
+ /* Merge cluster backward. */
+ if (cluster < info[j - 1].cluster)
+ {
+ 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;
+ }
+ continue;
+ }
+
+ if (i + 1 < count)
+ buffer->merge_clusters (i, i + 2); /* Merge cluster forward. */
+
+ continue;
+ }
+
+ if (j != i)
+ {
+ info[j] = info[i];
+ pos[j] = pos[i];
+ }
+ j++;
+ }
+ buffer->len = j;
+ }
+}
+
+
static inline void
hb_ot_map_glyphs_fast (hb_buffer_t *buffer)
{
@@ -388,6 +514,8 @@ hb_ot_map_glyphs_fast (hb_buffer_t *buffer)
hb_glyph_info_t *info = buffer->info;
for (unsigned int i = 0; i < count; i++)
info[i].codepoint = info[i].glyph_index();
+
+ buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS;
}
static inline void
@@ -625,6 +753,8 @@ hb_ot_position (hb_ot_shape_context_t *c)
hb_bool_t fallback = !hb_ot_position_complex (c);
+ hb_ot_zero_width_default_ignorables (c);
+
hb_ot_layout_position_finish (c->font, c->buffer);
if (fallback && c->plan->shaper->fallback_position)
@@ -642,53 +772,6 @@ hb_ot_position (hb_ot_shape_context_t *c)
}
-/* Post-process */
-
-static void
-hb_ot_hide_default_ignorables (hb_ot_shape_context_t *c)
-{
- if (c->buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES)
- return;
-
- hb_codepoint_t space;
- enum {
- SPACE_DONT_KNOW,
- SPACE_AVAILABLE,
- SPACE_UNAVAILABLE
- } space_status = SPACE_DONT_KNOW;
-
- unsigned int count = c->buffer->len;
- hb_glyph_info_t *info = c->buffer->info;
- hb_glyph_position_t *pos = c->buffer->pos;
- unsigned int j = 0;
- for (unsigned int i = 0; i < count; i++)
- {
- if (unlikely (!_hb_glyph_info_ligated (&info[i]) &&
- _hb_glyph_info_is_default_ignorable (&info[i])))
- {
- if (space_status == SPACE_DONT_KNOW)
- space_status = c->font->get_glyph (' ', 0, &space) ? SPACE_AVAILABLE : SPACE_UNAVAILABLE;
-
- if (space_status == SPACE_AVAILABLE)
- {
- info[i].codepoint = space;
- pos[i].x_advance = 0;
- pos[i].y_advance = 0;
- }
- else
- continue; /* Delete it. XXX Merge clusters? */
- }
- if (j != i)
- {
- info[j] = info[i];
- pos[j] = pos[i];
- }
- j++;
- }
- c->buffer->len = j;
-}
-
-
/* Pull it all together! */
static void
@@ -736,6 +819,9 @@ _hb_ot_shape (hb_shape_plan_t *shape_plan,
}
+/**
+ * Since: 0.9.7
+ **/
void
hb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan,
hb_tag_t table_tag,
@@ -766,6 +852,9 @@ add_char (hb_font_t *font,
}
+/**
+ * Since: 0.9.2
+ **/
void
hb_ot_shape_glyphs_closure (hb_font_t *font,
hb_buffer_t *buffer,