summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-22 04:42:51 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-08-22 04:42:51 +0000
commit701d7435d7b0dff8d106107288f1992bb2ea9de4 (patch)
treeccf71374dfbbf961b86196910ea03167eaf9829b
parentc13ec6590099dddb7145e1d4cddf5772f6d20d71 (diff)
parentb9d6e8943b2049e544bf4c08abe4e7573c6a1493 (diff)
downloadpango-701d7435d7b0dff8d106107288f1992bb2ea9de4.tar.gz
Merge branch 'matthiasc/for-main' into 'main'
break: Some code reorg See merge request GNOME/pango!427
-rw-r--r--pango/break.c271
-rw-r--r--pango/pango-attributes.c2
-rw-r--r--pango/pango-attributes.h4
-rw-r--r--tests/breaks/eleven.expected2
-rw-r--r--tests/breaks/four.expected2
-rw-r--r--tests/breaks/nine.expected2
-rw-r--r--tests/breaks/one.expected2
-rw-r--r--tests/breaks/ten.expected2
-rw-r--r--tests/breaks/three.expected2
-rw-r--r--tests/breaks/two.expected2
-rw-r--r--tests/test-break.c33
-rw-r--r--tests/test-common.c3
-rw-r--r--tests/test-itemize.c6
-rw-r--r--tests/testattributes.c109
14 files changed, 272 insertions, 170 deletions
diff --git a/pango/break.c b/pango/break.c
index 9eb4a291..b8f70855 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -29,6 +29,8 @@
#include "pango-impl-utils.h"
#include <string.h>
+/* {{{ Unicode line breaking and segmentation */
+
#define PARAGRAPH_SEPARATOR 0x2029
/* See http://www.unicode.org/unicode/reports/tr14/ if you hope
@@ -1584,20 +1586,116 @@ pango_default_break (const gchar *text,
attrs[0].is_line_break = FALSE; /* Rule LB2 */
}
+/* }}} */
+/* {{{ Tailoring */
+/* {{{ Script-specific tailoring */
+
+#include "break-arabic.c"
+#include "break-indic.c"
+#include "break-thai.c"
+
static gboolean
break_script (const char *item_text,
unsigned int item_length,
const PangoAnalysis *analysis,
PangoLogAttr *attrs,
- int attrs_len);
+ int attrs_len)
+{
+ switch (analysis->script)
+ {
+ case PANGO_SCRIPT_ARABIC:
+ break_arabic (item_text, item_length, analysis, attrs, attrs_len);
+ break;
+
+ case PANGO_SCRIPT_DEVANAGARI:
+ case PANGO_SCRIPT_BENGALI:
+ case PANGO_SCRIPT_GURMUKHI:
+ case PANGO_SCRIPT_GUJARATI:
+ case PANGO_SCRIPT_ORIYA:
+ case PANGO_SCRIPT_TAMIL:
+ case PANGO_SCRIPT_TELUGU:
+ case PANGO_SCRIPT_KANNADA:
+ case PANGO_SCRIPT_MALAYALAM:
+ case PANGO_SCRIPT_SINHALA:
+ break_indic (item_text, item_length, analysis, attrs, attrs_len);
+ break;
+
+ case PANGO_SCRIPT_THAI:
+ break_thai (item_text, item_length, analysis, attrs, attrs_len);
+ break;
+ default:
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* }}} */
+/* {{{ Attribute-based tailoring */
static gboolean
break_attrs (const char *text,
- int length,
+ int length,
GSList *attributes,
- int item_offset,
- PangoLogAttr *attrs,
- int attrs_len);
+ int offset,
+ PangoLogAttr *log_attrs,
+ int log_attrs_len)
+{
+ PangoAttrList list;
+ PangoAttrIterator iter;
+ GSList *l;
+
+ _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));
+ }
+
+ if (!_pango_attr_list_has_attributes (&list))
+ {
+ _pango_attr_list_destroy (&list);
+ return FALSE;
+ }
+
+ _pango_attr_list_get_iterator (&list, &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;
+
+ 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_list_destroy (&list);
+
+ return TRUE;
+}
+
+/* }}} */
static gboolean
tailor_break (const char *text,
@@ -1622,6 +1720,9 @@ tailor_break (const char *text,
return res;
}
+/* }}} */
+/* {{{ Public API */
+
/**
* pango_break:
* @text: the text to process. Must be valid UTF-8
@@ -1641,16 +1742,16 @@ tailor_break (const char *text,
*/
void
pango_break (const gchar *text,
- gint length,
- PangoAnalysis *analysis,
- PangoLogAttr *attrs,
- int attrs_len)
+ gint length,
+ PangoAnalysis *analysis,
+ PangoLogAttr *attrs,
+ int attrs_len)
{
g_return_if_fail (analysis != NULL);
g_return_if_fail (attrs != NULL);
pango_default_break (text, length, analysis, attrs, attrs_len);
- tailor_break (text, length, analysis, -1, attrs, attrs_len);
+ tailor_break (text, length, analysis, -1, attrs, attrs_len);
}
/**
@@ -1700,28 +1801,6 @@ pango_tailor_break (const char *text,
}
}
-static int
-tailor_segment (const char *range_start,
- const char *range_end,
- int chars_broken,
- PangoAnalysis *analysis,
- PangoLogAttr *log_attrs)
-{
- int chars_in_range;
- PangoLogAttr *start = log_attrs + chars_broken;
-
- chars_in_range = pango_utf8_strlen (range_start, range_end - range_start);
-
- pango_tailor_break (range_start,
- range_end - range_start,
- analysis,
- -1,
- start,
- chars_in_range + 1);
-
- return chars_in_range;
-}
-
/**
* pango_get_log_attrs:
* @text: text to process. Must be valid UTF-8
@@ -1744,11 +1823,11 @@ tailor_segment (const char *range_start,
*/
void
pango_get_log_attrs (const char *text,
- int length,
- int level,
- PangoLanguage *language,
- PangoLogAttr *log_attrs,
- int attrs_len)
+ int length,
+ int level,
+ PangoLanguage *language,
+ PangoLogAttr *log_attrs,
+ int attrs_len)
{
int chars_broken;
PangoAnalysis analysis = { NULL };
@@ -1769,119 +1848,29 @@ pango_get_log_attrs (const char *text,
{
const char *run_start, *run_end;
PangoScript script;
+ int chars_in_range;
pango_script_iter_get_range (&iter, &run_start, &run_end, &script);
analysis.script = script;
- chars_broken += tailor_segment (run_start, run_end, chars_broken, &analysis, log_attrs);
+ chars_in_range = pango_utf8_strlen (run_start, run_end - run_start);
+
+ pango_tailor_break (run_start,
+ run_end - run_start,
+ &analysis,
+ -1,
+ log_attrs + chars_broken,
+ chars_in_range + 1);
+
+ chars_broken += chars_in_range;
}
while (pango_script_iter_next (&iter));
_pango_script_iter_fini (&iter);
if (chars_broken + 1 > attrs_len)
g_warning ("pango_get_log_attrs: attrs_len should have been at least %d, but was %d. Expect corrupted memory.",
- chars_broken + 1,
- attrs_len);
-}
-
-#include "break-arabic.c"
-#include "break-indic.c"
-#include "break-thai.c"
-
-static gboolean
-break_script (const char *item_text,
- unsigned int item_length,
- const PangoAnalysis *analysis,
- PangoLogAttr *attrs,
- int attrs_len)
-{
- switch (analysis->script)
- {
- case PANGO_SCRIPT_ARABIC:
- break_arabic (item_text, item_length, analysis, attrs, attrs_len);
- break;
-
- case PANGO_SCRIPT_DEVANAGARI:
- case PANGO_SCRIPT_BENGALI:
- case PANGO_SCRIPT_GURMUKHI:
- case PANGO_SCRIPT_GUJARATI:
- case PANGO_SCRIPT_ORIYA:
- case PANGO_SCRIPT_TAMIL:
- case PANGO_SCRIPT_TELUGU:
- case PANGO_SCRIPT_KANNADA:
- case PANGO_SCRIPT_MALAYALAM:
- case PANGO_SCRIPT_SINHALA:
- break_indic (item_text, item_length, analysis, attrs, attrs_len);
- break;
-
- case PANGO_SCRIPT_THAI:
- break_thai (item_text, item_length, analysis, attrs, attrs_len);
- break;
- default:
- return FALSE;
- }
-
- return TRUE;
+ chars_broken + 1,
+ attrs_len);
}
-static gboolean
-break_attrs (const char *text,
- int length,
- GSList *attributes,
- int offset,
- PangoLogAttr *log_attrs,
- int log_attrs_len)
-{
- PangoAttrList list;
- PangoAttrIterator iter;
- GSList *l;
-
- _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));
- }
-
- if (!_pango_attr_list_has_attributes (&list))
- {
- _pango_attr_list_destroy (&list);
- return FALSE;
- }
-
- _pango_attr_list_get_iterator (&list, &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;
-
- 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_list_destroy (&list);
-
- return TRUE;
-}
+/* }}} */
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index f5d5104b..15814e38 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -1475,6 +1475,8 @@ pango_attribute_as_int (PangoAttribute *attr)
case PANGO_ATTR_SHOW:
case PANGO_ATTR_INSERT_HYPHENS:
case PANGO_ATTR_OVERLINE:
+ case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
+ case PANGO_ATTR_TEXT_TRANSFORM:
return (PangoAttrInt *)attr;
default:
diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h
index ca0f74b8..86826b62 100644
--- a/pango/pango-attributes.h
+++ b/pango/pango-attributes.h
@@ -67,7 +67,7 @@ typedef struct _PangoAttrFontFeatures PangoAttrFontFeatures;
* @PANGO_ATTR_ABSOLUTE_SIZE: font size in pixels scaled by %PANGO_SCALE ([struct@Pango.AttrInt])
* @PANGO_ATTR_GRAVITY: base text gravity ([struct@Pango.AttrInt])
* @PANGO_ATTR_GRAVITY_HINT: gravity hint ([struct@Pango.AttrInt])
- * @PANGO_ATTR_FONT_FEATURES: OpenType font features ([struct@Pango.AttrString]). Since 1.38
+ * @PANGO_ATTR_FONT_FEATURES: OpenType font features ([struct@Pango.AttrFontFeatures]). Since 1.38
* @PANGO_ATTR_FOREGROUND_ALPHA: foreground alpha ([struct@Pango.AttrInt]). Since 1.38
* @PANGO_ATTR_BACKGROUND_ALPHA: background alpha ([struct@Pango.AttrInt]). Since 1.38
* @PANGO_ATTR_ALLOW_BREAKS: whether breaks are allowed ([struct@Pango.AttrInt]). Since 1.44
@@ -110,7 +110,7 @@ typedef enum
PANGO_ATTR_ABSOLUTE_SIZE, /* PangoAttrSize */
PANGO_ATTR_GRAVITY, /* PangoAttrInt */
PANGO_ATTR_GRAVITY_HINT, /* PangoAttrInt */
- PANGO_ATTR_FONT_FEATURES, /* PangoAttrString */
+ PANGO_ATTR_FONT_FEATURES, /* PangoAttrFontFeatures */
PANGO_ATTR_FOREGROUND_ALPHA, /* PangoAttrInt */
PANGO_ATTR_BACKGROUND_ALPHA, /* PangoAttrInt */
PANGO_ATTR_ALLOW_BREAKS, /* PangoAttrInt */
diff --git a/tests/breaks/eleven.expected b/tests/breaks/eleven.expected
index 5f45affe..45c7ad01 100644
--- a/tests/breaks/eleven.expected
+++ b/tests/breaks/eleven.expected
@@ -1,6 +1,6 @@
Text: ⁦❤⁩⁦️⁩⁦︎⁩⁦︎⁩ ⁦👨⁩[0x200d]⁦🦰⁩ ⁦👨⁩⁦🏿⁩[0x200d]⁦🦱⁩ ⁦0⁩⁦️⁩⁦⃣⁩ ⁦🏴⁩[0xe0075][0xe0073][0xe0063][0xe0061][0xe007f] ⁦🇩⁩⁦🇪⁩⁦️⁩ [0x0a]
Breaks: c lc lc lc lc lc c c
Whitespace: w w
-Words: b b b bs be b b b
Sentences: bs e b
+Words: b b b bs be b b b
Graphemes: b b b b b b b b
diff --git a/tests/breaks/four.expected b/tests/breaks/four.expected
index b7f1a86c..ce58e10b 100644
--- a/tests/breaks/four.expected
+++ b/tests/breaks/four.expected
@@ -1,6 +1,6 @@
Text: ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦ไ⁩ ⁦ท⁩ ⁦ย⁩ [ ] ⁦ห⁩ ⁦ร⁩⁦ื⁩ ⁦อ⁩ [ ] ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦ไ⁩ ⁦ท⁩ ⁦ย⁩ ⁦ก⁩ ⁦ล⁩ ⁦า⁩ ⁦ง⁩ [ ] ⁦เ⁩ ⁦ป⁩⁦็⁩ ⁦น⁩ ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦ร⁩ ⁦า⁩ ⁦ช⁩ ⁦ก⁩ ⁦า⁩ ⁦ร⁩ ⁦แ⁩ ⁦ล⁩ ⁦ะ⁩ ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦ป⁩ ⁦ร⁩ ⁦ะ⁩ ⁦จ⁩ ⁦ำ⁩ ⁦ช⁩ ⁦า⁩ ⁦ต⁩⁦ิ⁩ ⁦ข⁩ ⁦อ⁩ ⁦ง⁩ ⁦ป⁩ ⁦ร⁩ ⁦ะ⁩ ⁦เ⁩ ⁦ท⁩ ⁦ศ⁩ ⁦ไ⁩ ⁦ท⁩ ⁦ย⁩ [ ] ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦ไ⁩ ⁦ท⁩ ⁦ย⁩ ⁦เ⁩ ⁦ป⁩⁦็⁩ ⁦น⁩ ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦ใ⁩ ⁦น⁩ ⁦ก⁩ ⁦ล⁩⁦ุ⁩⁦่⁩ ⁦ม⁩ ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦ไ⁩ ⁦ท⁩ ⁦ซ⁩⁦ึ⁩⁦่⁩ ⁦ง⁩ ⁦เ⁩ ⁦ป⁩⁦็⁩ ⁦น⁩ ⁦ก⁩ ⁦ล⁩⁦ุ⁩⁦่⁩ ⁦ม⁩ ⁦ย⁩⁦่⁩ ⁦อ⁩ ⁦ย⁩ ⁦ข⁩ ⁦อ⁩ ⁦ง⁩ ⁦ต⁩ ⁦ร⁩ ⁦ะ⁩ ⁦ก⁩⁦ู⁩ ⁦ล⁩ ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦ข⁩ ⁦ร⁩⁦้⁩ ⁦า⁩ [ ] ⁦ไ⁩ ⁦ท⁩ [ ] ⁦ส⁩⁦ั⁩ ⁦น⁩ ⁦น⁩⁦ิ⁩ ⁦ษ⁩ ⁦ฐ⁩ ⁦า⁩ ⁦น⁩ ⁦ว⁩⁦่⁩ ⁦า⁩ [ ] ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦ใ⁩ ⁦น⁩ ⁦ต⁩ ⁦ร⁩ ⁦ะ⁩ ⁦ก⁩⁦ู⁩ ⁦ล⁩ ⁦น⁩⁦ี⁩⁦้⁩ ⁦ม⁩⁦ี⁩ ⁦ถ⁩⁦ิ⁩⁦่⁩ ⁦น⁩ ⁦ก⁩ ⁦ำ⁩ ⁦เ⁩ ⁦น⁩⁦ิ⁩ ⁦ด⁩ ⁦จ⁩ ⁦า⁩ ⁦ก⁩ ⁦ท⁩ ⁦า⁩ ⁦ง⁩ ⁦ต⁩ ⁦อ⁩ ⁦น⁩ ⁦ใ⁩ ⁦ต⁩⁦้⁩ ⁦ข⁩ ⁦อ⁩ ⁦ง⁩ ⁦ป⁩ ⁦ร⁩ ⁦ะ⁩ ⁦เ⁩ ⁦ท⁩ ⁦ศ⁩ ⁦จ⁩⁦ี⁩ ⁦น⁩ [ ] ⁦แ⁩ ⁦ล⁩ ⁦ะ⁩ ⁦น⁩⁦ั⁩ ⁦ก⁩ ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦ศ⁩ ⁦า⁩ ⁦ส⁩ ⁦ต⁩ ⁦ร⁩⁦์⁩ ⁦บ⁩ ⁦า⁩ ⁦ง⁩ ⁦ส⁩⁦่⁩ ⁦ว⁩ ⁦น⁩ ⁦เ⁩ ⁦ส⁩ ⁦น⁩ ⁦อ⁩ ⁦ว⁩⁦่⁩ ⁦า⁩ [ ] ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦ไ⁩ ⁦ท⁩ ⁦ย⁩ ⁦น⁩⁦่⁩ ⁦า⁩ ⁦จ⁩ ⁦ะ⁩ ⁦ม⁩⁦ี⁩ ⁦ค⁩ ⁦ว⁩ ⁦า⁩ ⁦ม⁩ ⁦เ⁩ ⁦ช⁩⁦ื⁩⁦่⁩ ⁦อ⁩ ⁦ม⁩ ⁦โ⁩ ⁦ย⁩ ⁦ง⁩ ⁦ก⁩⁦ั⁩ ⁦บ⁩ ⁦ต⁩ ⁦ร⁩ ⁦ะ⁩ ⁦ก⁩⁦ู⁩ ⁦ล⁩ ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦อ⁩ ⁦อ⁩ ⁦ส⁩ ⁦โ⁩ ⁦ต⁩ ⁦ร⁩ [ ] ⁦เ⁩ ⁦อ⁩ ⁦เ⁩ ⁦ช⁩⁦ี⁩ ⁦ย⁩ ⁦ต⁩⁦ิ⁩ ⁦ก⁩ [ ] ⁦ต⁩ ⁦ร⁩ ⁦ะ⁩ ⁦ก⁩⁦ู⁩ ⁦ล⁩ ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦อ⁩ ⁦อ⁩ ⁦ส⁩ ⁦โ⁩ ⁦ต⁩ ⁦ร⁩ ⁦น⁩⁦ี⁩ ⁦เ⁩ ⁦ซ⁩⁦ี⁩ ⁦ย⁩ ⁦น⁩ [ ] ⁦แ⁩ ⁦ล⁩ ⁦ะ⁩ ⁦ต⁩ ⁦ร⁩ ⁦ะ⁩ ⁦ก⁩⁦ู⁩ ⁦ล⁩ ⁦ภ⁩ ⁦า⁩ ⁦ษ⁩ ⁦า⁩ ⁦จ⁩⁦ี⁩ ⁦น⁩ [ ] ⁦ท⁩⁦ิ⁩ ⁦เ⁩ ⁦บ⁩ ⁦ต⁩ [0x0a]
Breaks: c c c c lc c c c lc c c c lc c c c lc c c lc c c c c lc c c lc c c c lc c c c c c lc c c lc c c c lc c c c c lc c c lc c c lc c c c c c lc c c c lc c c c lc c c lc c c lc c c c lc c lc c c lc c c c lc c lc c lc c c lc c c lc c c lc c c lc c c c c lc c c c lc c c c lc c c lc c c c c c c lc c c lc c c c lc c lc c c c c lc lc lc c lc c c c c lc c c lc c c lc c c lc c lc c c lc c c c c c lc c c lc c c lc c lc c c c c c c c c lc c c lc c c lc c c c lc c c lc c c c lc c c lc c lc c lc lc c c c lc c c c lc c c lc c lc c c c c lc c c c lc c lc c c c c lc c c c c lc c c lc c c c c lc c c c lc c lc c c c c c c c c c lc c c lc c c c c lc c c c lc c c lc c c c c c
Whitespace: x x x x x x x x x x x x x w w
-Words: bs b b b bse b b be bse b b be bse b b b bse b b bse b b b be bse b b bse b b b bse b b b b b bse b b bse b b b bse b b b b bse b b bse b b bse b b b b b bse b b be bse b b b bse b b bse b b bse b b b bse b bse b b bse b b b bse b bse b bse b b bse b b bse b b bse b b bse b b b b bse b b b bse b b be bse b be bse b b b b b b bse b be bse b b b bse b bse b b b b bse bse bse b bse b b b b bse b b bse b b bse b b bse b bse b b bse b b b b b bse b be bse b b bse b bse b b b b b b b b bse b b bse b b bse b b b bse b be bse b b b bse b b bse b bse b bse bse b b b bse b b b bse b b bse b bse b b b b bse b b b bse b bse b b b be bse b b b b bse b be bse b b b b bse b b b bse b bse b b b b b b b b be bse b b bse b b b b bse b b b bse b be bse b b b be b
Sentences: bs e b
+Words: bs b b b bse b b be bse b b be bse b b b bse b b bse b b b be bse b b bse b b b bse b b b b b bse b b bse b b b bse b b b b bse b b bse b b bse b b b b b bse b b be bse b b b bse b b bse b b bse b b b bse b bse b b bse b b b bse b bse b bse b b bse b b bse b b bse b b bse b b b b bse b b b bse b b be bse b be bse b b b b b b bse b be bse b b b bse b bse b b b b bse bse bse b bse b b b b bse b b bse b b bse b b bse b bse b b bse b b b b b bse b be bse b b bse b bse b b b b b b b b bse b b bse b b bse b b b bse b be bse b b b bse b b bse b bse b bse bse b b b bse b b b bse b b bse b bse b b b b bse b b b bse b bse b b b be bse b b b b bse b be bse b b b b bse b b b bse b bse b b b b b b b b be bse b b bse b b b b bse b b b bse b be bse b b b be b
Graphemes: b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b
diff --git a/tests/breaks/nine.expected b/tests/breaks/nine.expected
index 4f6f95a3..957f67e5 100644
--- a/tests/breaks/nine.expected
+++ b/tests/breaks/nine.expected
@@ -1,6 +1,6 @@
Text: ⁦म⁩⁦ी⁩ [ ] ⁦क⁩⁦ा⁩ ⁦च⁩ [ ] ⁦ख⁩⁦ा⁩ ⁦ऊ⁩ [ ] ⁦श⁩ ⁦क⁩ ⁦त⁩⁦ो⁩ ⁦,⁩ [ ] ⁦म⁩ ⁦ल⁩⁦ा⁩ [ ] ⁦त⁩⁦े⁩ [ ] ⁦द⁩⁦ु⁩ ⁦ख⁩ ⁦त⁩ [ ] ⁦न⁩⁦ा⁩ ⁦ह⁩ [0x0a] ⁦म⁩⁦ै⁩⁦ं⁩ [ ] ⁦क⁩⁦ा⁩⁦ँ⁩ ⁦च⁩ [ ] ⁦ख⁩⁦ा⁩ [ ] ⁦स⁩ ⁦क⁩ ⁦त⁩⁦ा⁩ [ ] ⁦ह⁩⁦ू⁩⁦ँ⁩ ⁦,⁩ [ ] ⁦म⁩⁦ु⁩ ⁦झ⁩⁦े⁩ [ ] ⁦उ⁩ ⁦स⁩ [ ] ⁦स⁩⁦े⁩ [ ] ⁦क⁩⁦ो⁩ ⁦ई⁩ [ ] ⁦प⁩⁦ी⁩ ⁦ड⁩⁦ा⁩ [ ] ⁦न⁩ ⁦ह⁩⁦ी⁩⁦ं⁩ [ ] ⁦ह⁩⁦ो⁩ ⁦त⁩ [0x0a] ⁦ந⁩⁦ா⁩ ⁦ன⁩⁦்⁩ [ ] ⁦க⁩ ⁦ண⁩⁦்⁩ ⁦ண⁩⁦ா⁩ ⁦ட⁩⁦ி⁩ [ ] ⁦ச⁩⁦ா⁩ ⁦ப⁩⁦்⁩ ⁦ப⁩⁦ி⁩ ⁦ட⁩⁦ு⁩ ⁦வ⁩⁦ே⁩ ⁦ன⁩⁦்⁩ ⁦,⁩ [ ] ⁦அ⁩ ⁦த⁩ ⁦ன⁩⁦ா⁩ ⁦ல⁩⁦்⁩ [ ] ⁦எ⁩ ⁦ன⁩ ⁦க⁩⁦்⁩ ⁦க⁩⁦ு⁩ [ ] ⁦ஒ⁩ ⁦ர⁩⁦ு⁩ [ ] ⁦க⁩⁦ே⁩ ⁦ட⁩⁦ு⁩ ⁦ம⁩⁦்⁩ [ ] ⁦வ⁩ ⁦ர⁩⁦ா⁩ ⁦த⁩ [0x0a] ⁦ﻢ⁩ ⁦ﯾ⁩ ⁦ں⁩ [ ] ⁦ﮎ⁩ ⁦ﺎ⁩ ⁦ﻨ⁩ ⁦ﭼ⁩ [ ] ⁦ﮎ⁩ ⁦ھ⁩ ⁦ﺍ⁩ [ ] ⁦ﺲ⁩ ⁦ﮑ⁩ ⁦ﺗ⁩ ⁦ﺍ⁩ [ ] ⁦ہ⁩ ⁦ﻭ⁩ ⁦ں⁩ [ ] ⁦ﺍ⁩ ⁦ﻭ⁩ ⁦ﺭ⁩ [ ] ⁦ﻢ⁩ ⁦ﺟ⁩ ⁦ھ⁩ ⁦ے⁩ [ ] ⁦ﺖ⁩ ⁦ﮑ⁩ ⁦ﻠ⁩ ⁦ﯿ⁩ ⁦ﻓ⁩ [ ] ⁦ﻥ⁩ ⁦ہ⁩ ⁦ﯼ⁩ ⁦ں⁩ [ ] ⁦ہ⁩ ⁦ﻮ⁩ ⁦ﺘ⁩ ⁦ﯾ⁩ [ ] [0x0a] ⁦ﺰ⁩ ⁦ﻫ⁩ [ ] ⁦ﺶ⁩ ⁦ﻴ⁩ ⁦ﺸ⁩ ⁦ﻫ⁩ [ ] ⁦ﺥ⁩ ⁦ﻭ⁩ ⁦ړ⁩ ⁦ﻝ⁩ ⁦ې⁩ [ ] ⁦ﺶ⁩ ⁦ﻣ⁩ ⁦،⁩ [ ] ⁦ﻪ⁩ ⁦ﻐ⁩ ⁦ﻫ⁩ [ ] ⁦ﻡ⁩ ⁦ﺍ⁩ [ ] ⁦ﻦ⁩ ⁦ﻫ⁩ [ ] ⁦ﺥ⁩ ⁦ﻭ⁩ ⁦ږ⁩ ⁦ﻮ⁩ ⁦ﻳ⁩ [0x0a]
Breaks: c c lc c c lc c c lc c c c c lc c c lc c lc c c c lc c c c c lc c c lc c lc c c c lc c c lc c c lc c c lc c lc c c lc c c lc c c lc c c c c c lc c c c c lc c c c c c c c lc c c c c lc c c c c lc c c lc c c c lc c c c c c c c lc c c c c lc c c c lc c c c c lc c c c lc c c c lc c c c c lc c c c c c lc c c c c lc c c c c c c c c lc c c c c lc c c c c c lc c c c lc c c c lc c c lc c c lc c c c c c c
Whitespace: x x x x x x x w x x x x x x x x x x x w x x x x x x x w x x x x x x x x x x w x x x x x x x w w
-Words: bs be bs be bs be bs be b bs be bs be bs be bs be bs be bs be bs be bs be bs be b bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be b bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be b bs be bs be bs be bs be b bs be bs be bs be bs be b
Sentences: bs e bs e bs e bs e bs e b
+Words: bs be bs be bs be bs be b bs be bs be bs be bs be bs be bs be bs be bs be bs be b bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be b bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be bs be b bs be bs be bs be bs be b bs be bs be bs be bs be b
Graphemes: b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b
diff --git a/tests/breaks/one.expected b/tests/breaks/one.expected
index f3ab2612..bbae494d 100644
--- a/tests/breaks/one.expected
+++ b/tests/breaks/one.expected
@@ -1,6 +1,6 @@
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 c
Whitespace: x x w w
-Words: bs be bs be bs be b bs be b
Sentences: bs e bs e b
+Words: bs be bs be bs be b bs be b
Graphemes: b b b b b b b b b b b b b b b b b b b b b b
diff --git a/tests/breaks/ten.expected b/tests/breaks/ten.expected
index a83252da..c1f8cc35 100644
--- a/tests/breaks/ten.expected
+++ b/tests/breaks/ten.expected
@@ -1,6 +1,6 @@
Text: ⁦i⁩ ⁦ක⁩⁦්⁩[0x200d]⁦ක⁩ [ ] ⁦a⁩[0x200c] ⁦a⁩⁦்⁩ [0x0a]
Breaks: c c c lc c c c
Whitespace: x w w
-Words: bs be bs be b
Sentences: bs e b
+Words: bs be bs be b
Graphemes: b b b b b b b
diff --git a/tests/breaks/three.expected b/tests/breaks/three.expected
index 72e6fbe2..7f078f4f 100644
--- a/tests/breaks/three.expected
+++ b/tests/breaks/three.expected
@@ -1,6 +1,6 @@
Text: ⁦o⁩ ⁦n⁩ ⁦e⁩ [ ] ⁦t⁩ ⁦w⁩ ⁦o⁩ [0x2028] ⁦r⁩ ⁦e⁩ ⁦d⁩ [ ] ⁦b⁩ ⁦l⁩ ⁦u⁩ ⁦e⁩[0x200d] ⁦g⁩ ⁦r⁩ ⁦e⁩ ⁦e⁩ ⁦n⁩ [0x0a]
Breaks: c c c c lc c c c Lc c c c lc c c c c c c c c c c
Whitespace: x w x w w
-Words: bs be bs be bs be bs be b
Sentences: bs e bs e b
+Words: bs be bs be bs be bs be b
Graphemes: b b b b b b b b b b b b b b b b b b b b b b b
diff --git a/tests/breaks/two.expected b/tests/breaks/two.expected
index 9bea7f7d..3ec2d948 100644
--- a/tests/breaks/two.expected
+++ b/tests/breaks/two.expected
@@ -1,6 +1,6 @@
Text: ⁦g⁩ ⁦o⁩ ⁦r⁩ ⁦i⁩ ⁦l⁩ ⁦·⁩ ⁦l⁩ ⁦e⁩ ⁦s⁩ [0x0a]
Breaks: c c c c c c c c c c c
Whitespace: w w
-Words: bs e s be b
Sentences: bs e b
+Words: bs e s be b
Graphemes: b b b b b b b b b b b
diff --git a/tests/test-break.c b/tests/test-break.c
index d59971a0..3fb5cdcd 100644
--- a/tests/test-break.c
+++ b/tests/test-break.c
@@ -106,8 +106,8 @@ test_file (const gchar *filename, GString *string)
s1 = g_string_new ("Breaks: ");
s2 = g_string_new ("Whitespace: ");
- s3 = g_string_new ("Words:");
- s4 = g_string_new ("Sentences:");
+ s3 = g_string_new ("Sentences:");
+ s4 = g_string_new ("Words:");
s5 = g_string_new ("Graphemes:");
g_string_append (string, "Text: ");
@@ -157,37 +157,38 @@ test_file (const gchar *filename, GString *string)
w++;
}
- if (log.is_word_boundary)
+ if (log.is_sentence_boundary)
{
g_string_append (s3, "b");
- o++;
+ s++;
}
- if (log.is_word_start)
+ if (log.is_sentence_start)
{
g_string_append (s3, "s");
- o++;
+ s++;
}
- if (log.is_word_end)
+ if (log.is_sentence_end)
{
g_string_append (s3, "e");
- o++;
+ s++;
}
- if (log.is_sentence_boundary)
+ if (log.is_word_boundary)
{
g_string_append (s4, "b");
- s++;
+ o++;
}
- if (log.is_sentence_start)
+ if (log.is_word_start)
{
g_string_append (s4, "s");
- s++;
+ o++;
}
- if (log.is_sentence_end)
+ if (log.is_word_end)
{
g_string_append (s4, "e");
- s++;
+ o++;
}
+
if (log.is_cursor_position)
{
g_string_append (s5, "b");
@@ -199,8 +200,8 @@ test_file (const gchar *filename, GString *string)
g_string_append_printf (string, "%*s", m, "");
g_string_append_printf (s1, "%*s", m - b, "");
g_string_append_printf (s2, "%*s", m - w, "");
- g_string_append_printf (s3, "%*s", m - o, "");
- g_string_append_printf (s4, "%*s", m - s, "");
+ g_string_append_printf (s3, "%*s", m - s, "");
+ g_string_append_printf (s4, "%*s", m - o, "");
g_string_append_printf (s5, "%*s", m - g, "");
if (i < len - 1)
diff --git a/tests/test-common.c b/tests/test-common.c
index 3df4015c..011b2eef 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -143,6 +143,7 @@ print_attribute (PangoAttribute *attr, GString *string)
case PANGO_ATTR_INSERT_HYPHENS:
case PANGO_ATTR_SHOW:
case PANGO_ATTR_TEXT_TRANSFORM:
+ case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
g_string_append_printf (string, "%d", ((PangoAttrInt *)attr)->value);
break;
case PANGO_ATTR_FONT_DESC:
@@ -167,6 +168,7 @@ print_attribute (PangoAttribute *attr, GString *string)
g_string_append_printf (string, "shape");
break;
case PANGO_ATTR_SCALE:
+ case PANGO_ATTR_LINE_HEIGHT:
{
char val[20];
@@ -174,6 +176,7 @@ print_attribute (PangoAttribute *attr, GString *string)
g_string_append (string, val);
}
break;
+ case PANGO_ATTR_INVALID:
default:
g_assert_not_reached ();
break;
diff --git a/tests/test-itemize.c b/tests/test-itemize.c
index 0a8515b8..926eb3ae 100644
--- a/tests/test-itemize.c
+++ b/tests/test-itemize.c
@@ -251,8 +251,6 @@ test_itemize (gconstpointer d)
return;
}
- context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
-
found_cantarell = FALSE;
pango_context_list_families (context, &families, &n_families);
for (int i = 0; i < n_families; i++)
@@ -305,7 +303,6 @@ test_itemize (gconstpointer d)
g_free (diff);
g_string_free (dump, TRUE);
g_free (expected_file);
- g_object_unref (context);
}
int
@@ -318,6 +315,9 @@ main (int argc, char *argv[])
g_test_init (&argc, &argv, NULL);
+ context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
+ pango_context_set_language (context, pango_language_from_string ("en-us"));
+
/* allow to easily generate expected output for new test cases */
if (argc > 1)
{
diff --git a/tests/testattributes.c b/tests/testattributes.c
index 79caf7b8..662a6142 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.
*
@@ -66,10 +66,15 @@ test_attributes_basic (void)
test_copy (pango_attr_shape_new (&rect, &rect));
test_copy (pango_attr_gravity_new (PANGO_GRAVITY_SOUTH));
test_copy (pango_attr_gravity_hint_new (PANGO_GRAVITY_HINT_STRONG));
+ test_copy (pango_attr_font_features_new ("csc=1"));
+ test_copy (pango_attr_foreground_alpha_new (8000));
+ test_copy (pango_attr_background_alpha_new (8000));
test_copy (pango_attr_allow_breaks_new (FALSE));
test_copy (pango_attr_show_new (PANGO_SHOW_SPACES));
test_copy (pango_attr_insert_hyphens_new (FALSE));
test_copy (pango_attr_text_transform_new (PANGO_TEXT_TRANSFORM_UPPERCASE));
+ test_copy (pango_attr_line_height_new (1.5));
+ test_copy (pango_attr_line_height_new_absolute (3000));
}
static void
@@ -111,6 +116,107 @@ test_attributes_register (void)
g_type_class_unref (class);
}
+#define g_assert_as(x, y) \
+ if (x == NULL) \
+ { \
+ GString *s = g_string_new (""); \
+ print_attribute (y, s); \
+ g_print ("failed to convert: %s\n", s->str); \
+ g_string_free (s, TRUE); \
+ }
+
+static void
+test_binding (PangoAttribute *attr)
+{
+ enum {
+ INVALID, INT, LANGUAGE, STRING, SIZE, FONT_DESC, COLOR, SHAPE, FLOAT, FONT_FEATURES,
+ } attr_base[] = {
+ INVALID, LANGUAGE, STRING, INT, INT, INT, INT, SIZE, FONT_DESC, COLOR,
+ COLOR, INT, INT, INT, SHAPE, FLOAT, INT, INT, COLOR, COLOR, SIZE,
+ INT, INT, FONT_FEATURES, INT, INT, INT, INT, INT, INT, COLOR, FLOAT,
+ INT, INT, INT, INT
+ };
+
+ switch (attr_base[attr->klass->type])
+ {
+ case INT:
+ g_assert_as (pango_attribute_as_int (attr), attr);
+ break;
+ case LANGUAGE:
+ g_assert_as (pango_attribute_as_language (attr), attr);
+ break;
+ case STRING:
+ g_assert_as (pango_attribute_as_string (attr), attr);
+ break;
+ case SIZE:
+ g_assert_as (pango_attribute_as_size (attr), attr);
+ break;
+ case FONT_DESC:
+ g_assert_as (pango_attribute_as_font_desc (attr), attr);
+ break;
+ case COLOR:
+ g_assert_as (pango_attribute_as_color (attr), attr);
+ break;
+ case SHAPE:
+ g_assert_as (pango_attribute_as_shape (attr), attr);
+ break;
+ case FLOAT:
+ g_assert_as (pango_attribute_as_float (attr), attr);
+ break;
+ case FONT_FEATURES:
+ g_assert_as (pango_attribute_as_font_features (attr), attr);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ pango_attribute_destroy (attr);
+}
+
+static void
+test_binding_helpers (void)
+{
+ PangoFontDescription *desc;
+ PangoRectangle rect = { 0, 0, 10, 10 };
+
+ test_binding (pango_attr_language_new (pango_language_from_string ("ja-JP")));
+ test_binding (pango_attr_family_new ("Times"));
+ test_binding (pango_attr_foreground_new (100, 200, 300));
+ test_binding (pango_attr_background_new (100, 200, 300));
+ test_binding (pango_attr_size_new (1024));
+ test_binding (pango_attr_size_new_absolute (1024));
+ test_binding (pango_attr_style_new (PANGO_STYLE_ITALIC));
+ test_binding (pango_attr_weight_new (PANGO_WEIGHT_ULTRALIGHT));
+ test_binding (pango_attr_variant_new (PANGO_VARIANT_SMALL_CAPS));
+ test_binding (pango_attr_stretch_new (PANGO_STRETCH_SEMI_EXPANDED));
+ desc = pango_font_description_from_string ("Computer Modern 12");
+ test_binding (pango_attr_font_desc_new (desc));
+ pango_font_description_free (desc);
+ test_binding (pango_attr_underline_new (PANGO_UNDERLINE_LOW));
+ test_binding (pango_attr_underline_new (PANGO_UNDERLINE_ERROR_LINE));
+ test_binding (pango_attr_underline_color_new (100, 200, 300));
+ test_binding (pango_attr_overline_new (PANGO_OVERLINE_SINGLE));
+ test_binding (pango_attr_overline_color_new (100, 200, 300));
+ test_binding (pango_attr_strikethrough_new (TRUE));
+ test_binding (pango_attr_strikethrough_color_new (100, 200, 300));
+ test_binding (pango_attr_rise_new (256));
+ test_binding (pango_attr_scale_new (2.56));
+ test_binding (pango_attr_fallback_new (FALSE));
+ test_binding (pango_attr_letter_spacing_new (1024));
+ test_binding (pango_attr_shape_new (&rect, &rect));
+ test_binding (pango_attr_gravity_new (PANGO_GRAVITY_SOUTH));
+ test_binding (pango_attr_gravity_hint_new (PANGO_GRAVITY_HINT_STRONG));
+ test_binding (pango_attr_font_features_new ("csc=1"));
+ test_binding (pango_attr_foreground_alpha_new (8000));
+ test_binding (pango_attr_background_alpha_new (8000));
+ test_binding (pango_attr_allow_breaks_new (FALSE));
+ test_binding (pango_attr_show_new (PANGO_SHOW_SPACES));
+ test_binding (pango_attr_insert_hyphens_new (FALSE));
+ test_binding (pango_attr_text_transform_new (PANGO_TEXT_TRANSFORM_UPPERCASE));
+ test_binding (pango_attr_line_height_new (1.5));
+ test_binding (pango_attr_line_height_new_absolute (3000));
+}
+
static void
assert_attributes (GSList *attrs,
const char *expected)
@@ -1211,6 +1317,7 @@ main (int argc, char *argv[])
g_test_add_func ("/attributes/basic", test_attributes_basic);
g_test_add_func ("/attributes/equal", test_attributes_equal);
g_test_add_func ("/attributes/register", test_attributes_register);
+ g_test_add_func ("/attributes/binding-helpers", test_binding_helpers);
g_test_add_func ("/attributes/list/basic", test_list);
g_test_add_func ("/attributes/list/change", test_list_change);
g_test_add_func ("/attributes/list/change2", test_list_change2);