[pango] Fix pango_default_break function for sentence start/end
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango] Fix pango_default_break function for sentence start/end
- Date: Wed, 30 Aug 2017 14:19:12 +0000 (UTC)
commit 33c10cb0c40503630146e4d32de807728d99ab0c
Author: Peng Wu <alexepico gmail com>
Date: Wed Aug 16 15:02:36 2017 +0800
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
pango/break.c | 39 +++++++++++++++++++++++++++++----------
1 files changed, 29 insertions(+), 10 deletions(-)
---
diff --git a/pango/break.c b/pango/break.c
index b92e768..34a7cd2 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]