summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2017-08-16 15:02:36 +0800
committerMatthias Clasen <mclasen@redhat.com>2017-08-30 10:18:32 -0400
commit33c10cb0c40503630146e4d32de807728d99ab0c (patch)
tree57b5b47ed6baedaef5d93be98d8257e31a79bbfd
parent1377d3cf8219cf41e3bacd2eaa848a92009eaa1f (diff)
downloadpango-33c10cb0c40503630146e4d32de807728d99ab0c.tar.gz
Fix pango_default_break function for sentence start/end
Skip the space characters in sentence start/end. https://bugzilla.gnome.org/show_bug.cgi?id=785978
-rw-r--r--pango/break.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/pango/break.c b/pango/break.c
index b92e768f..34a7cd28 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -559,6 +559,7 @@ pango_default_break (const gchar *text,
gunichar base_character = 0;
gint last_sentence_start = -1;
+ gint last_non_space = -1;
gboolean almost_done = FALSE;
gboolean done = FALSE;
@@ -1660,19 +1661,37 @@ pango_default_break (const gchar *text,
}
/* ---- Sentence breaks ---- */
+ {
- /* default to not a sentence start/end */
- attrs[i].is_sentence_start = FALSE;
- attrs[i].is_sentence_end = FALSE;
+ /* default to not a sentence start/end */
+ attrs[i].is_sentence_start = FALSE;
+ attrs[i].is_sentence_end = FALSE;
- if (last_sentence_start == -1 && !is_sentence_boundary) {
- last_sentence_start = i - 1;
- attrs[i - 1].is_sentence_start = TRUE;
- }
+ /* maybe start sentence */
+ if (last_sentence_start == -1 && !is_sentence_boundary)
+ last_sentence_start = i - 1;
+
+ /* remember last non space character position */
+ if (i > 0 && !attrs[i - 1].is_white)
+ last_non_space = i;
+
+ /* meets sentence end, mark both sentence start and end */
+ if (last_sentence_start != -1 && is_sentence_boundary) {
+ if (last_non_space != -1) {
+ attrs[last_sentence_start].is_sentence_start = TRUE;
+ attrs[last_non_space].is_sentence_end = TRUE;
+ }
+
+ last_sentence_start = -1;
+ last_non_space = -1;
+ }
+
+ /* meets space character, move sentence start */
+ if (last_sentence_start != -1 &&
+ last_sentence_start == i - 1 &&
+ attrs[i - 1].is_white)
+ last_sentence_start++;
- if (last_sentence_start != -1 && is_sentence_boundary) {
- last_sentence_start = -1;
- attrs[i].is_sentence_end = TRUE;
}
prev_wc = wc;