[pango/break-tailoring: 2/4] break: Cosmetics
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/break-tailoring: 2/4] break: Cosmetics
- Date: Sat, 21 Aug 2021 17:35:02 +0000 (UTC)
commit 4a2abdd3ff2957939dc4dd4a565a1070b65fcf1d
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 21 10:04:14 2021 -0400
break: Cosmetics
Rearrange the code in break_attr() slightly, to prepare
for handling more attributes.
pango/break.c | 82 +++++++++++++++++++++++++++-----------------------
tests/testattributes.c | 2 +-
2 files changed, 45 insertions(+), 39 deletions(-)
---
diff --git a/pango/break.c b/pango/break.c
index 9eb4a291..9e0b4537 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -1832,56 +1832,62 @@ break_attrs (const char *text,
PangoLogAttr *log_attrs,
int log_attrs_len)
{
- PangoAttrList list;
- PangoAttrIterator iter;
+ PangoAttrList allow_breaks;
GSList *l;
+ gboolean tailored = FALSE;
+
+ _pango_attr_list_init (&allow_breaks);
- _pango_attr_list_init (&list);
for (l = attributes; l; l = l->next)
{
PangoAttribute *attr = l->data;
if (attr->klass->type == PANGO_ATTR_ALLOW_BREAKS)
- pango_attr_list_insert (&list, pango_attribute_copy (attr));
+ pango_attr_list_insert (&allow_breaks, pango_attribute_copy (attr));
}
- if (!_pango_attr_list_has_attributes (&list))
+ if (_pango_attr_list_has_attributes (&allow_breaks))
{
- _pango_attr_list_destroy (&list);
- return FALSE;
- }
+ PangoAttrIterator iter;
- _pango_attr_list_get_iterator (&list, &iter);
- do {
- const PangoAttribute *attr = pango_attr_iterator_get (&iter, PANGO_ATTR_ALLOW_BREAKS);
+ _pango_attr_list_get_iterator (&allow_breaks, &iter);
+ do
+ {
+ const PangoAttribute *attr = pango_attr_iterator_get (&iter, PANGO_ATTR_ALLOW_BREAKS);
+
+ if (attr && ((PangoAttrInt*)attr)->value == 0)
+ {
+ int start, end;
+ int start_pos, end_pos;
+ int pos;
+
+ start = attr->start_index;
+ end = attr->end_index;
+ if (start < offset)
+ start_pos = 0;
+ else
+ start_pos = g_utf8_pointer_to_offset (text, text + start - offset);
+ if (end >= offset + length)
+ end_pos = log_attrs_len;
+ else
+ end_pos = g_utf8_pointer_to_offset (text, text + end - offset);
+
+ for (pos = start_pos + 1; pos < end_pos; pos++)
+ {
+ log_attrs[pos].is_mandatory_break = FALSE;
+ log_attrs[pos].is_line_break = FALSE;
+ log_attrs[pos].is_char_break = FALSE;
+
+ tailored = TRUE;
+ }
+ }
+ }
+ while (pango_attr_iterator_next (&iter));
- if (attr && ((PangoAttrInt*)attr)->value == 0)
- {
- int start, end;
- int start_pos, end_pos;
- int pos;
-
- pango_attr_iterator_range (&iter, &start, &end);
- if (start < offset)
- start_pos = 0;
- else
- start_pos = g_utf8_pointer_to_offset (text, text + start - offset);
- if (end >= offset + length)
- end_pos = log_attrs_len;
- else
- end_pos = g_utf8_pointer_to_offset (text, text + end - offset);
-
- for (pos = start_pos + 1; pos < end_pos; pos++)
- {
- log_attrs[pos].is_mandatory_break = FALSE;
- log_attrs[pos].is_line_break = FALSE;
- log_attrs[pos].is_char_break = FALSE;
- }
- }
- } while (pango_attr_iterator_next (&iter));
+ _pango_attr_iterator_destroy (&iter);
+ }
- _pango_attr_iterator_destroy (&iter);
- _pango_attr_list_destroy (&list);
+ _pango_attr_list_destroy (&allow_breaks);
- return TRUE;
+ return tailored;
}
diff --git a/tests/testattributes.c b/tests/testattributes.c
index aaf270f5..ba4ba7dd 100644
--- a/tests/testattributes.c
+++ b/tests/testattributes.c
@@ -1,5 +1,5 @@
/* Pango
- * testiter.c: Test pango attributes
+ * testattributes.c: Test pango attributes
*
* Copyright (C) 2015 Red Hat, Inc.
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]