summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-07-09 22:00:59 +0000
committerMatthias Clasen <mclasen@redhat.com>2019-07-09 22:00:59 +0000
commit56ff2776f61d25c1cdf9701768c88378fd6dda73 (patch)
treebbf6ee2c0270b206ce3d0aa89247c3a78e364d7f
parent95392a13902209552095fc945b67262f4e10c2e6 (diff)
parentb737fc42f760ad5918c40210e815eaac50306734 (diff)
downloadpango-56ff2776f61d25c1cdf9701768c88378fd6dda73.tar.gz
Merge branch 'soft-hyphen-cleanup' into 'master'
Soft hyphen cleanup See merge request GNOME/pango!72
-rw-r--r--pango/break.c9
-rw-r--r--pango/pango-break.h5
-rw-r--r--pango/pango-layout.c97
-rw-r--r--tests/breaks/one.expected10
-rw-r--r--tests/test-break.c5
5 files changed, 75 insertions, 51 deletions
diff --git a/pango/break.c b/pango/break.c
index 13ccbdaf..11f4079e 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -984,7 +984,6 @@ pango_default_break (const gchar *text,
attrs[i].is_char_break = FALSE;
attrs[i].is_line_break = FALSE;
attrs[i].is_mandatory_break = FALSE;
- attrs[i].is_soft_hyphen = FALSE;
/* Rule LB1:
assign a line breaking class to each code point of the input. */
@@ -1365,15 +1364,9 @@ pango_default_break (const gchar *text,
case BREAK_ALLOWED:
attrs[i].is_line_break = TRUE;
- /* fall through */
+ break;
case BREAK_ALREADY_HANDLED:
- if (attrs[i].is_line_break)
- {
- /* After Soft Hyphen */
- if (prev_wc == 0x00AD)
- attrs[i].is_soft_hyphen = TRUE;
- }
break;
default:
diff --git a/pango/pango-break.h b/pango/pango-break.h
index 66d81631..92af390b 100644
--- a/pango/pango-break.h
+++ b/pango/pango-break.h
@@ -79,9 +79,6 @@ G_BEGIN_DECLS
* This flag implements Unicode's
* <ulink url="http://www.unicode.org/reports/tr29/">Word
* Boundaries</ulink> semantics. (Since: 1.22)
- * @is_soft_hyphen: is a line break due to a Soft Hyphen (0x00AD).
- * This indicates a position where a hyphen should be inserted
- * if the break is taken.
*
* The #PangoLogAttr structure stores information
* about the attributes of a single character.
@@ -89,6 +86,7 @@ G_BEGIN_DECLS
struct _PangoLogAttr
{
guint is_line_break : 1; /* Can break line in front of character */
+
guint is_mandatory_break : 1; /* Must break line in front of character */
guint is_char_break : 1; /* Can break here when doing char wrap */
@@ -132,7 +130,6 @@ struct _PangoLogAttr
/* Word boundary as defined by UAX#29 */
guint is_word_boundary : 1; /* is NOT in the middle of a word */
- guint is_soft_hyphen : 1; /* line break due to a soft hyphen */
};
/* Determine information about cluster/word/line breaks in a string
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index baf81bd4..b6e6ac89 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -3297,6 +3297,8 @@ struct _ParaBreakState
/* maintained per line */
int line_width; /* Goal width of line currently processing; < 0 is infinite */
int remaining_width; /* Amount of space remaining on line; < 0 is infinite */
+
+ int hyphen_width; /* How much space a hyphen will take */
};
static gboolean
@@ -3436,6 +3438,64 @@ create_hyphen_run (PangoLayout *layout,
return hyphen;
}
+static gboolean
+break_needs_hyphen (PangoLayout *layout,
+ ParaBreakState *state,
+ int num_chars)
+{
+ gunichar *ch;
+
+ if (state->start_offset + num_chars == 0)
+ return FALSE;
+
+ ch = g_utf8_get_char (layout->text + state->start_offset + num_chars - 1);
+
+ /* Just look for soft hyphen, for now */
+ if (ch == 0xAD)
+ return TRUE;
+
+ return FALSE;
+}
+
+static int
+find_break_extra_width (PangoLayout *layout,
+ ParaBreakState *state,
+ int num_chars)
+{
+ PangoItem *item = state->items->data;
+
+ /* Check whether to insert a hyphen */
+ if (break_needs_hyphen (layout, state, num_chars))
+ {
+ if (state->hyphen_width < 0)
+ {
+ PangoLayoutRun *run;
+
+ run = create_hyphen_run (layout, item, state->start_offset);
+ state->hyphen_width = pango_glyph_string_get_width (run->glyphs);
+ pango_glyph_item_free (run);
+ }
+
+ return state->hyphen_width;
+ }
+ else
+ return 0;
+}
+
+static void
+insert_hyphen (PangoLayoutLine *line,
+ ParaBreakState *state,
+ PangoItem *item,
+ int num_chars)
+{
+ PangoLayout *layout = line->layout;
+ PangoLayoutRun *run;
+
+ run = create_hyphen_run (layout, item, state->start_offset + num_chars);
+ line->runs = g_slist_prepend (line->runs, run);
+ state->remaining_width -= pango_glyph_string_get_width (run->glyphs);
+}
+
#if 0
# define DEBUG debug
void
@@ -3507,6 +3567,7 @@ process_item (PangoLayout *layout,
{
insert_run (line, state, item, TRUE);
state->log_widths_offset += item->num_chars;
+
return BREAK_LINE_SEPARATOR;
}
@@ -3554,14 +3615,6 @@ process_item (PangoLayout *layout,
pango_glyph_item_get_logical_widths (&glyph_item, layout->text, state->log_widths);
}
- {
- PangoLayoutRun *run;
-
- run = create_hyphen_run (layout, item, state->start_offset);
- hyphen_width = pango_glyph_string_get_width (run->glyphs);
- pango_glyph_item_free (run);
- }
-
retry_break:
/* See how much of the item we can stuff in the line. */
@@ -3579,11 +3632,7 @@ process_item (PangoLayout *layout,
break_num_chars = num_chars;
break_width = width;
- /* Check whether to insert a hyphen */
- if (layout->log_attrs[state->start_offset + num_chars].is_soft_hyphen)
- break_extra_width = hyphen_width;
- else
- break_extra_width = 0;
+ break_extra_width = find_break_extra_width (layout, state, num_chars);
}
width += state->log_widths[state->log_widths_offset + num_chars];
@@ -3620,14 +3669,8 @@ process_item (PangoLayout *layout,
if (break_num_chars == item->num_chars)
{
insert_run (line, state, item, TRUE);
- if (layout->log_attrs[state->start_offset + break_num_chars].is_soft_hyphen)
- {
- PangoLayoutRun *run;
-
- run = create_hyphen_run (layout, item, state->start_offset + break_num_chars);
- line->runs = g_slist_prepend (line->runs, run);
- state->remaining_width -= pango_glyph_string_get_width (run->glyphs);
- }
+ if (break_needs_hyphen (layout, state, break_num_chars))
+ insert_hyphen (line, state, item, break_num_chars);
return BREAK_ALL_FIT;
}
@@ -3654,14 +3697,8 @@ process_item (PangoLayout *layout,
/* Shaped items should never be broken */
g_assert (!shape_set);
- if (layout->log_attrs[state->start_offset + break_num_chars].is_soft_hyphen)
- {
- PangoLayoutRun *run;
-
- run = create_hyphen_run (layout, item, state->start_offset + break_num_chars);
- line->runs = g_slist_prepend (line->runs, run);
- state->remaining_width -= pango_glyph_string_get_width (run->glyphs);
- }
+ if (break_needs_hyphen (layout, state, break_num_chars))
+ insert_hyphen (line, state, new_item, break_num_chars);
return BREAK_SOME_FIT;
}
@@ -4154,6 +4191,8 @@ pango_layout_check_lines (PangoLayout *layout)
state.remaining_width = -1;
state.log_widths_offset = 0;
+ state.hyphen_width = -1;
+
if (state.items)
{
while (state.items)
diff --git a/tests/breaks/one.expected b/tests/breaks/one.expected
index 7fb600e6..d474c6e4 100644
--- a/tests/breaks/one.expected
+++ b/tests/breaks/one.expected
@@ -1,5 +1,5 @@
-Text: a b c / d e f [ ] g h i [0xad] j k l . [ ] B l a [0x0a]
-Breaks: c c c c lc c c c lc c c c lhc c c c c lc c c c Lc
-Whitespace: x x w w
-Words: bs be bs be bs be b bs be b
-Sentences: bs e bs e b
+Text: a b c / d e f [ ] g h i [0xad] j k l . [ ] B l a [0x0a]
+Breaks: c c c c lc c c c lc c c c lc c c c c lc c c c Lc
+Whitespace: x x w w
+Words: bs be bs be bs be b bs be b
+Sentences: bs e bs e b
diff --git a/tests/test-break.c b/tests/test-break.c
index e4c5bd28..00bc7be0 100644
--- a/tests/test-break.c
+++ b/tests/test-break.c
@@ -103,11 +103,6 @@ test_file (const gchar *filename, GString *string)
g_string_append (s1, "l");
b++;
}
- if (log.is_soft_hyphen)
- {
- g_string_append (s1, "h");
- b++;
- }
if (log.is_char_break)
{
g_string_append (s1, "c");