[pango/better-hyphens: 5/5] Make hyphen insertion more efficient
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/better-hyphens: 5/5] Make hyphen insertion more efficient
- Date: Tue, 16 Jul 2019 13:34:13 +0000 (UTC)
commit 3973a69c697649ea6fb6de97352a59c7daca7eab
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jul 15 23:48:34 2019 -0400
Make hyphen insertion more efficient
We can avoid copying the paragraph text,
and just pass a flag down to tell the
shaping code to append a hyphen to the buffer
that we pass to hb_shape.
pango/pango-item.h | 12 +++++++++++-
pango/pango-layout.c | 53 ++++++++++++++++-----------------------------------
pango/pangofc-shape.c | 2 ++
3 files changed, 29 insertions(+), 38 deletions(-)
---
diff --git a/pango/pango-item.h b/pango/pango-item.h
index 55be4c67..95bcd35e 100644
--- a/pango/pango-item.h
+++ b/pango/pango-item.h
@@ -50,6 +50,16 @@ typedef struct _PangoItem PangoItem;
*/
#define PANGO_ANALYSIS_FLAG_IS_ELLIPSIS (1 << 1)
+/**
+ * PANGO_ANALYSIS_FLAG_ADD_HYPHEN:
+ *
+ * This flag tells Pango to add a hyphen at the end of the
+ * run during shaping.
+ *
+ * Since: 1.44
+ */
+#define PANGO_ANALYSIS_FLAG_NEED_HYPHEN (1 << 2)
+
/**
* PangoAnalysis:
* @shape_engine: the engine for doing rendering-system-dependent processing.
@@ -57,7 +67,7 @@ typedef struct _PangoItem PangoItem;
* @font: the font for this segment.
* @level: the bidirectional level for this segment.
* @gravity: the glyph orientation for this segment (A #PangoGravity).
- * @flags: boolean flags for this segment (currently only one) (Since: 1.16).
+ * @flags: boolean flags for this segment (Since: 1.16).
* @script: the detected script for this segment (A #PangoScript) (Since: 1.18).
* @language: the detected language for this segment.
* @extra_attrs: extra attributes for this segment.
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index df2092fd..c6ce6472 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -3310,8 +3310,7 @@ should_ellipsize_current_line (PangoLayout *layout,
static PangoGlyphString *
shape_run (PangoLayoutLine *line,
ParaBreakState *state,
- PangoItem *item,
- gboolean with_hyphen)
+ PangoItem *item)
{
PangoLayout *layout = line->layout;
PangoGlyphString *glyphs = pango_glyph_string_new ();
@@ -3326,28 +3325,9 @@ shape_run (PangoLayoutLine *line,
glyphs);
else
{
-
- if (with_hyphen)
- {
- GString *s = g_string_new ("");
-
- g_string_append_len (s, layout->text, item->offset + item->length - 2);
- g_string_append (s, "-");
- g_string_append_len (s, layout->text + item->offset + item->length, layout->length -
(item->offset + item->length));
-
- pango_shape_full (s->str + item->offset, item->length - 1,
- s->str, s->len,
- &item->analysis, glyphs);
-
- g_string_free (s, TRUE);
-
- }
- else
- {
- pango_shape_full (layout->text + item->offset, item->length,
- layout->text, layout->length,
- &item->analysis, glyphs);
- }
+ pango_shape_full (layout->text + item->offset, item->length,
+ layout->text, layout->length,
+ &item->analysis, glyphs);
}
if (state->properties.letter_spacing)
@@ -3378,8 +3358,7 @@ static void
insert_run (PangoLayoutLine *line,
ParaBreakState *state,
PangoItem *run_item,
- gboolean last_run,
- gboolean with_hyphen)
+ gboolean last_run)
{
PangoLayoutRun *run = g_slice_new (PangoLayoutRun);
@@ -3388,7 +3367,7 @@ insert_run (PangoLayoutLine *line,
if (last_run && state->log_widths_offset == 0)
run->glyphs = state->glyphs;
else
- run->glyphs = shape_run (line, state, run_item, with_hyphen);
+ run->glyphs = shape_run (line, state, run_item);
if (last_run)
{
@@ -3602,7 +3581,7 @@ process_item (PangoLayout *layout,
if (!state->glyphs)
{
pango_layout_get_item_properties (item, &state->properties);
- state->glyphs = shape_run (line, state, item, FALSE);
+ state->glyphs = shape_run (line, state, item);
state->log_widths = NULL;
state->need_hyphen = NULL;
@@ -3615,7 +3594,7 @@ process_item (PangoLayout *layout,
g_utf8_get_char (layout->text + item->offset) == LINE_SEPARATOR &&
!should_ellipsize_current_line (layout, state))
{
- insert_run (line, state, item, TRUE, FALSE);
+ insert_run (line, state, item, TRUE);
state->log_widths_offset += item->num_chars;
return BREAK_LINE_SEPARATOR;
@@ -3623,7 +3602,7 @@ process_item (PangoLayout *layout,
if (state->remaining_width < 0 && !no_break_at_end) /* Wrapping off */
{
- insert_run (line, state, item, TRUE, FALSE);
+ insert_run (line, state, item, TRUE);
return BREAK_ALL_FIT;
}
@@ -3644,7 +3623,7 @@ process_item (PangoLayout *layout,
{
state->remaining_width -= width;
state->remaining_width = MAX (state->remaining_width, 0);
- insert_run (line, state, item, TRUE, FALSE);
+ insert_run (line, state, item, TRUE);
return BREAK_ALL_FIT;
}
@@ -3719,9 +3698,9 @@ process_item (PangoLayout *layout,
if (break_num_chars == item->num_chars)
{
- gboolean hyphen;
- hyphen = break_needs_hyphen (layout, state, break_num_chars);
- insert_run (line, state, item, TRUE, hyphen);
+ if (break_needs_hyphen (layout, state, break_num_chars))
+ item->analysis.flags |= PANGO_ANALYSIS_FLAG_NEED_HYPHEN;
+ insert_run (line, state, item, TRUE);
return BREAK_ALL_FIT;
}
@@ -3732,16 +3711,16 @@ process_item (PangoLayout *layout,
else
{
PangoItem *new_item;
- gboolean hyphen;
length = g_utf8_offset_to_pointer (layout->text + item->offset, break_num_chars) -
(layout->text + item->offset);
new_item = pango_item_split (item, length, break_num_chars);
- hyphen = break_needs_hyphen (layout, state, break_num_chars);
+ if (break_needs_hyphen (layout, state, break_num_chars))
+ new_item->analysis.flags |= PANGO_ANALYSIS_FLAG_NEED_HYPHEN;
/* Add the width back, to the line, reshape, subtract the new width */
state->remaining_width += break_width;
- insert_run (line, state, new_item, FALSE, hyphen);
+ insert_run (line, state, new_item, FALSE);
break_width = pango_glyph_string_get_width (((PangoGlyphItem *)(line->runs->data))->glyphs);
state->remaining_width -= break_width;
diff --git a/pango/pangofc-shape.c b/pango/pangofc-shape.c
index 9bedd28a..8bbd4c18 100644
--- a/pango/pangofc-shape.c
+++ b/pango/pangofc-shape.c
@@ -459,6 +459,8 @@ _pango_fc_shape (PangoFont *font,
hb_buffer_set_flags (hb_buffer, HB_BUFFER_FLAG_BOT | HB_BUFFER_FLAG_EOT);
hb_buffer_add_utf8 (hb_buffer, paragraph_text, paragraph_length, item_offset, item_length);
+ if (analysis->flags & PANGO_ANALYSIS_FLAG_NEED_HYPHEN)
+ hb_buffer_add (hb_buffer, '-', item_length);
pango_font_get_features (font, features, 32, &num_features);
apply_extra_attributes (analysis->extra_attrs, features, 32, &num_features);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]