summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-07-20 10:34:15 -0700
committerMatthias Clasen <mclasen@redhat.com>2019-07-20 11:56:18 -0700
commit62580f2fa5e46d51bb2377d4028471926108bab3 (patch)
tree7472f8a4fb33d6822b4cb853e43e0b38124af542
parente8f20b6116cca605115b42d5e0a15112193a3bad (diff)
downloadpango-62580f2fa5e46d51bb2377d4028471926108bab3.tar.gz
Add an allow-breaks attribute
Add a new attribute type, and parse allow_breaks="false" in markup. This is useful to prevent hyphenation of words.
-rw-r--r--docs/pango-sections.txt1
-rw-r--r--pango/pango-attributes.c27
-rw-r--r--pango/pango-attributes.h6
-rw-r--r--pango/pango-markup.c17
4 files changed, 50 insertions, 1 deletions
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index f89debe6..c1a04e79 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -408,6 +408,7 @@ pango_attr_gravity_hint_new
pango_attr_font_features_new
pango_attr_foreground_alpha_new
pango_attr_background_alpha_new
+pango_attr_allow_breaks_new_
PangoColor
PANGO_TYPE_COLOR
pango_color_parse
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 54b13795..e522931b 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -1179,6 +1179,33 @@ pango_attr_background_alpha_new (guint16 alpha)
return pango_attr_int_new (&klass, (int)alpha);
}
+/**
+ * pango_attr_allow_breaks_new:
+ * @allow_breaks: %TRUE if we line breaks are allowed
+ *
+ * Create a new allow-breaks attribute.
+ *
+ * If breaks are disabled, the range will be kept in a
+ * single run, as far as possible.
+ *
+ * Return value: (transfer full): the newly allocated #PangoAttribute,
+ * which should be freed with pango_attribute_destroy()
+ *
+ * Since: 1.44
+ */
+PangoAttribute *
+pango_attr_allow_breaks_new (gboolean allow_breaks)
+{
+ static const PangoAttrClass klass = {
+ PANGO_ATTR_ALLOW_BREAKS,
+ pango_attr_int_copy,
+ pango_attr_int_destroy,
+ pango_attr_int_equal,
+ };
+
+ return pango_attr_int_new (&klass, (int)allow_breaks);
+}
+
/*
* Attribute List
*/
diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h
index cff495b2..4249f8f4 100644
--- a/pango/pango-attributes.h
+++ b/pango/pango-attributes.h
@@ -147,6 +147,7 @@ typedef struct _PangoAttrIterator PangoAttrIterator;
* @PANGO_ATTR_FONT_FEATURES: OpenType font features (#PangoAttrString). Since 1.38
* @PANGO_ATTR_FOREGROUND_ALPHA: foreground alpha (#PangoAttrInt). Since 1.38
* @PANGO_ATTR_BACKGROUND_ALPHA: background alpha (#PangoAttrInt). Since 1.38
+ * @PANGO_ATTR_ALLOW_BREAKS: whether breaks are allowed (#PangoAttrInt). Since 1.44
*
* The #PangoAttrType
* distinguishes between different types of attributes. Along with the
@@ -182,7 +183,8 @@ typedef enum
PANGO_ATTR_GRAVITY_HINT, /* PangoAttrInt */
PANGO_ATTR_FONT_FEATURES, /* PangoAttrString */
PANGO_ATTR_FOREGROUND_ALPHA, /* PangoAttrInt */
- PANGO_ATTR_BACKGROUND_ALPHA /* PangoAttrInt */
+ PANGO_ATTR_BACKGROUND_ALPHA, /* PangoAttrInt */
+ PANGO_ATTR_ALLOW_BREAKS /* PangoAttrInt */
} PangoAttrType;
/**
@@ -522,6 +524,8 @@ PANGO_AVAILABLE_IN_1_38
PangoAttribute *pango_attr_foreground_alpha_new (guint16 alpha);
PANGO_AVAILABLE_IN_1_38
PangoAttribute *pango_attr_background_alpha_new (guint16 alpha);
+PANGO_AVAILABLE_IN_1_44
+PangoAttribute *pango_attr_allow_breaks_new (gboolean allow_breaks);
PANGO_AVAILABLE_IN_ALL
GType pango_attr_list_get_type (void) G_GNUC_CONST;
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index 2c509dac..2b871584 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -153,6 +153,11 @@
* Fallback is enabled by default. Most applications should not
* disable fallback.
*
+ * allow_breaks
+ * : 'true' or 'false' whether to allow line breaks or not. If
+ * not allowed, the range will be kept in a single run as far
+ * as possible. Breaks are allowed by default.
+ *
* lang
* : A language code, indicating the text language
*
@@ -1297,6 +1302,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
const char *font_features = NULL;
const char *alpha = NULL;
const char *background_alpha = NULL;
+ const char *allow_breaks = NULL;
g_markup_parse_context_get_position (context,
&line_number, &char_number);
@@ -1326,6 +1332,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
switch (names[i][0]) {
case 'a':
+ CHECK_ATTRIBUTE (allow_breaks);
CHECK_ATTRIBUTE (alpha);
break;
case 'b':
@@ -1707,6 +1714,16 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
add_attribute (tag, pango_attr_font_features_new (font_features));
}
+ if (G_UNLIKELY (allow_breaks))
+ {
+ gboolean b = FALSE;
+
+ if (!span_parse_boolean ("allow_breaks", allow_breaks, &b, line_number, error))
+ goto error;
+
+ add_attribute (tag, pango_attr_allow_breaks_new (b));
+ }
+
return TRUE;
error: