summaryrefslogtreecommitdiff
path: root/pango/pango-layout.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-24 22:42:07 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-08-24 23:27:54 -0400
commitbd48e5894d95ab00961d3b7466b08ce1307a5b6d (patch)
tree871c9d4efbf5ad3d5da76a7ac5c72fa321de3b6b /pango/pango-layout.c
parent70933101e4eb4dee9a29fe0992624ae9c58adf00 (diff)
downloadpango-bd48e5894d95ab00961d3b7466b08ce1307a5b6d.tar.gz
layout: Use need_hyphen from log attrs
Diffstat (limited to 'pango/pango-layout.c')
-rw-r--r--pango/pango-layout.c131
1 files changed, 1 insertions, 130 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index b6e0c217..4366450a 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -3502,7 +3502,6 @@ struct _ParaBreakState
int log_widths_offset; /* Offset into log_widths to the point corresponding
* to the remaining portion of the first item */
- int *need_hyphen; /* Insert a hyphen if breaking here ? */
int line_start_index; /* Start index (byte offset) of line in layout->text */
int line_start_offset; /* Character offset of line in layout->text */
@@ -3591,140 +3590,18 @@ insert_run (PangoLayoutLine *line,
state->glyphs = NULL;
g_free (state->log_widths);
state->log_widths = NULL;
- g_free (state->need_hyphen);
- state->need_hyphen = NULL;
}
line->runs = g_slist_prepend (line->runs, run);
line->length += run_item->length;
}
-static void
-get_need_hyphen (PangoItem *item,
- const char *text,
- int *need_hyphen)
-{
- int i;
- const char *p;
- gboolean prev_space;
- gboolean prev_hyphen;
- PangoAttrList attrs;
- PangoAttrIterator iter;
- GSList *l;
-
- _pango_attr_list_init (&attrs);
- for (l = item->analysis.extra_attrs; l; l = l->next)
- {
- PangoAttribute *attr = l->data;
- if (attr->klass->type == PANGO_ATTR_INSERT_HYPHENS)
- pango_attr_list_change (&attrs, pango_attribute_copy (attr));
- }
- _pango_attr_list_get_iterator (&attrs, &iter);
-
- prev_space = prev_hyphen = TRUE;
-
- for (i = 0, p = text + item->offset; i < item->num_chars; i++, p = g_utf8_next_char (p))
- {
- gunichar wc = g_utf8_get_char (p);
- gboolean space;
- gboolean hyphen;
- int start, end, pos;
- gboolean insert_hyphens = TRUE;
-
- pos = p - text;
- do {
- pango_attr_iterator_range (&iter, &start, &end);
- if (end > pos)
- break;
- } while (pango_attr_iterator_next (&iter));
-
- if (start <= pos && pos < end)
- {
- PangoAttribute *attr;
- attr = pango_attr_iterator_get (&iter, PANGO_ATTR_INSERT_HYPHENS);
- if (attr)
- insert_hyphens = ((PangoAttrInt*)attr)->value;
-
- /* Some scripts don't use hyphen.*/
- switch (item->analysis.script)
- {
- case PANGO_SCRIPT_COMMON:
- case PANGO_SCRIPT_HAN:
- case PANGO_SCRIPT_HANGUL:
- case PANGO_SCRIPT_HIRAGANA:
- case PANGO_SCRIPT_KATAKANA:
- insert_hyphens = FALSE;
- break;
- default:
- break;
- }
- }
-
- switch ((int)g_unichar_type (wc))
- {
- case G_UNICODE_SPACE_SEPARATOR:
- case G_UNICODE_LINE_SEPARATOR:
- case G_UNICODE_PARAGRAPH_SEPARATOR:
- space = TRUE;
- break;
- case G_UNICODE_CONTROL:
- if (wc == '\t' || wc == '\n' || wc == '\r' || wc == '\f')
- space = TRUE;
- else
- space = FALSE;
- break;
- default:
- space = FALSE;
- break;
- }
-
- if (wc == '-' || /* Hyphen-minus */
- wc == 0x058a || /* Armenian hyphen */
- wc == 0x1400 || /* Canadian syllabics hyphen */
- wc == 0x1806 || /* Mongolian todo hyphen */
- wc == 0x2010 || /* Hyphen */
- wc == 0x2027 || /* Hyphenation point */
- wc == 0x2e17 || /* Double oblique hyphen */
- wc == 0x2e40 || /* Double hyphen */
- wc == 0x30a0 || /* Katakana-Hiragana double hyphen */
- wc == 0xfe63 || /* Small hyphen-minus */
- wc == 0xff0d) /* Fullwidth hyphen-minus */
- hyphen = TRUE;
- else
- hyphen = FALSE;
-
- if (prev_space || space)
- need_hyphen[i] = FALSE;
- else if (prev_hyphen || hyphen)
- need_hyphen[i] = FALSE;
- else
- need_hyphen[i] = insert_hyphens;
-
- prev_space = space;
- prev_hyphen = hyphen;
- }
-
- need_hyphen[item->num_chars - 1] = FALSE;
-
- _pango_attr_iterator_destroy (&iter);
- _pango_attr_list_destroy (&attrs);
-}
-
static gboolean
break_needs_hyphen (PangoLayout *layout,
ParaBreakState *state,
int pos)
{
- if (state->log_widths_offset + pos == 0)
- return FALSE;
-
- if (layout->log_attrs[state->start_offset + pos].is_word_boundary)
- return FALSE;
-
- if (state->need_hyphen[state->log_widths_offset + pos - 1])
- return TRUE;
-
- return FALSE;
+ return layout->log_attrs[state->start_offset + pos].break_inserts_hyphen;
}
static int
@@ -3830,7 +3707,6 @@ process_item (PangoLayout *layout,
state->glyphs = shape_run (line, state, item);
state->log_widths = NULL;
- state->need_hyphen = NULL;
state->log_widths_offset = 0;
processing_new_item = TRUE;
@@ -3887,8 +3763,6 @@ process_item (PangoLayout *layout,
PangoGlyphItem glyph_item = {item, state->glyphs};
state->log_widths = g_new (int, item->num_chars);
pango_glyph_item_get_logical_widths (&glyph_item, layout->text, state->log_widths);
- state->need_hyphen = g_new (int, item->num_chars);
- get_need_hyphen (item, layout->text, state->need_hyphen);
}
retry_break:
@@ -3989,8 +3863,6 @@ process_item (PangoLayout *layout,
state->glyphs = NULL;
g_free (state->log_widths);
state->log_widths = NULL;
- g_free (state->need_hyphen);
- state->need_hyphen = NULL;
return BREAK_NONE_FIT;
}
@@ -4536,7 +4408,6 @@ pango_layout_check_lines (PangoLayout *layout)
state.glyphs = NULL;
state.log_widths = NULL;
- state.need_hyphen = NULL;
/* for deterministic bug hunting's sake set everything! */
state.line_width = -1;