From bf5e07101758040025d1bc3a592c9dcd982c0edc Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 20 Aug 2021 17:16:52 -0400 Subject: markup: Add a text transform attribute Add a PangoTextTransform enum, a PangoAttribute to set it on runs of text, and support for parsing it out of markup. --- docs/pango_markup.md | 5 +++++ pango/pango-attributes.c | 26 ++++++++++++++++++++++++++ pango/pango-attributes.h | 22 ++++++++++++++++++++++ pango/pango-markup.c | 14 ++++++++++++++ tests/testattributes.c | 1 + 5 files changed, 68 insertions(+) diff --git a/docs/pango_markup.md b/docs/pango_markup.md index 03718907..3a1cc311 100644 --- a/docs/pango_markup.md +++ b/docs/pango_markup.md @@ -196,6 +196,11 @@ line_height of a point). Available since Pango 1.50. +text_transform +: Specifies how characters are transformed during shaping. The values can be + 'none', 'lowercase', 'uppercase' or 'capitalize'. Support for text transformation + was added in Pango 1.50. + ## Convenience Tags `` diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index 5690aeaa..f5d5104b 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -1411,6 +1411,32 @@ pango_attr_line_height_new_absolute (int height) return pango_attr_int_new (&klass, height); } + +/** + * pango_attr_text_transform_new: + * @transform: `PangoTextTransform` to apply + * + * Create a new attribute that influences how characters + * are transformed during shaping. + * + * Return value: (transfer full): the newly allocated + * `PangoAttribute`, which should be freed with + * [method@Pango.Attribute.destroy] + * + * Since: 1.50 + */ +PangoAttribute * +pango_attr_text_transform_new (PangoTextTransform transform) +{ + static const PangoAttrClass klass = { + PANGO_ATTR_TEXT_TRANSFORM, + pango_attr_int_copy, + pango_attr_int_destroy, + pango_attr_int_equal + }; + + return pango_attr_int_new (&klass, transform); +} /* }}} */ /* {{{ Binding helpers */ diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h index e3012008..ca0f74b8 100644 --- a/pango/pango-attributes.h +++ b/pango/pango-attributes.h @@ -120,6 +120,7 @@ typedef enum PANGO_ATTR_OVERLINE_COLOR, /* PangoAttrColor */ PANGO_ATTR_LINE_HEIGHT, /* PangoAttrFloat */ PANGO_ATTR_ABSOLUTE_LINE_HEIGHT, /* PangoAttrInt */ + PANGO_ATTR_TEXT_TRANSFORM, /* PangoAttrInt */ } PangoAttrType; /** @@ -202,6 +203,25 @@ typedef enum { PANGO_SHOW_IGNORABLES = 1 << 2 } PangoShowFlags; +/** + * PangoTextTransform: + * @PANGO_TEXT_TRANSFORM_NONE: Leave text unchanged + * @PANGO_TEXT_TRANSFORM_LOWERCASE: Display letters and numbers as lowercase + * @PANGO_TEXT_TRANSFORM_UPPERCASE: Display letters and numbers as uppercase + * @PANGO_TEXT_TRANSFORM_CAPITALIZE: Display the first character of a word + * in titlecase + * + * An enumeration that affects how Pango treats characters during shaping. + * + * Since: 1.50 + */ +typedef enum { + PANGO_TEXT_TRANSFORM_NONE, + PANGO_TEXT_TRANSFORM_LOWERCASE, + PANGO_TEXT_TRANSFORM_UPPERCASE, + PANGO_TEXT_TRANSFORM_CAPITALIZE, +} PangoTextTransform; + /** * PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING: * @@ -532,6 +552,8 @@ PANGO_AVAILABLE_IN_1_50 PangoAttribute * pango_attr_line_height_new (double factor); PANGO_AVAILABLE_IN_1_50 PangoAttribute * pango_attr_line_height_new_absolute (int height); +PANGO_AVAILABLE_IN_1_50 +PangoAttribute * pango_attr_text_transform_new (PangoTextTransform transform); PANGO_AVAILABLE_IN_1_50 PangoAttrString * pango_attribute_as_string (PangoAttribute *attr); diff --git a/pango/pango-markup.c b/pango/pango-markup.c index a897a52d..f82aacef 100644 --- a/pango/pango-markup.c +++ b/pango/pango-markup.c @@ -1226,6 +1226,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED, const char *insert_hyphens = NULL; const char *show = NULL; const char *line_height = NULL; + const char *text_transform = NULL; g_markup_parse_context_get_position (context, &line_number, &char_number); @@ -1294,6 +1295,9 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED, CHECK_ATTRIBUTE (strikethrough_color); CHECK_ATTRIBUTE (style); break; + case 't': + CHECK_ATTRIBUTE (text_transform); + break; case 'g': CHECK_ATTRIBUTE (gravity); CHECK_ATTRIBUTE (gravity_hint); @@ -1637,6 +1641,16 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED, add_attribute (tag, pango_attr_show_new (flags)); } + if (G_UNLIKELY (text_transform)) + { + PangoTextTransform tf; + + if (!span_parse_enum ("text_transform", text_transform, PANGO_TYPE_TEXT_TRANSFORM, (int*)(void*)&tf, line_number, error)) + goto error; + + add_attribute (tag, pango_attr_text_transform_new (tf)); + } + if (G_UNLIKELY (rise)) { gint n = 0; diff --git a/tests/testattributes.c b/tests/testattributes.c index aaf270f5..79caf7b8 100644 --- a/tests/testattributes.c +++ b/tests/testattributes.c @@ -69,6 +69,7 @@ test_attributes_basic (void) 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)); } static void -- cgit v1.2.1