From 3eba288ec502e3711ad1aef92fb149d1707e4900 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 21 Jan 2022 23:25:45 -0500 Subject: Add a paragraph attribute This will be used to implement single-paragraph mode. --- pango/pango-attributes.c | 32 ++++++++++++++++++++++++++++++++ pango/pango-attributes.h | 4 ++++ pango/serializer.c | 7 +++++++ 3 files changed, 43 insertions(+) diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index a984e6f2..01b865bc 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -1421,6 +1421,31 @@ pango_attr_sentence_new (void) return pango_attr_int_new (&klass, 1); } +/** + * pango_attr_paragraph_new: + * + * Marks the range of the attribute as a single paragraph. + * + * Newlines and similar characters in the range of the attribute + * will not be treated as paragraph separators. + * + * Return value: (transfer full): the newly allocated + * `PangoAttribute`, which should be freed with + * [method@Pango.Attribute.destroy] + */ +PangoAttribute * +pango_attr_paragraph_new (void) +{ + static const PangoAttrClass klass = { + PANGO_ATTR_PARAGRAPH, + pango_attr_int_copy, + pango_attr_int_destroy, + pango_attr_int_equal, + }; + + return pango_attr_int_new (&klass, 1); +} + /** * pango_attr_overline_new: * @overline: the overline style @@ -1598,6 +1623,7 @@ pango_attribute_as_int (PangoAttribute *attr) case PANGO_ATTR_TEXT_TRANSFORM: case PANGO_ATTR_WORD: case PANGO_ATTR_SENTENCE: + case PANGO_ATTR_PARAGRAPH: case PANGO_ATTR_BASELINE_SHIFT: case PANGO_ATTR_FONT_SCALE: return (PangoAttrInt *)attr; @@ -3050,6 +3076,12 @@ pango_attr_list_from_string (const char *text) attr = pango_attr_sentence_new (); break; + case PANGO_ATTR_PARAGRAPH: + integer = g_ascii_strtoll (p, &endp, 10); + if (!is_valid_end_char (*endp)) goto fail; + attr = pango_attr_paragraph_new (); + break; + case PANGO_ATTR_BASELINE_SHIFT: ENUM_ATTR(baseline_shift, PangoBaselineShift, 0, G_MAXINT); break; diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h index 69ff9e52..1f32714b 100644 --- a/pango/pango-attributes.h +++ b/pango/pango-attributes.h @@ -79,6 +79,7 @@ typedef struct _PangoAttrFontFeatures PangoAttrFontFeatures; * @PANGO_ATTR_ABSOLUTE_LINE_HEIGHT: line height ([struct@Pango.AttrInt]). Since: 1.50 * @PANGO_ATTR_WORD: override segmentation to classify the range of the attribute as a single word ([struct@Pango.AttrInt]). Since 1.50 * @PANGO_ATTR_SENTENCE: override segmentation to classify the range of the attribute as a single sentence ([struct@Pango.AttrInt]). Since 1.50 + * @PANGO_ATTR_PARAGRAPH: override segmentation to classify the range of the attribute as a single paragraph ([struct@Pango.AttrInt]). * @PANGO_ATTR_BASELINE_SHIFT: baseline displacement ([struct@Pango.AttrInt]). Since 1.50 * @PANGO_ATTR_FONT_SCALE: font-relative size change ([struct@Pango.AttrInt]). Since 1.50 * @@ -129,6 +130,7 @@ typedef enum PANGO_ATTR_SENTENCE, /* PangoAttrInt */ PANGO_ATTR_BASELINE_SHIFT, /* PangoAttrSize */ PANGO_ATTR_FONT_SCALE, /* PangoAttrInt */ + PANGO_ATTR_PARAGRAPH, /* PangoAttrInt */ } PangoAttrType; /** @@ -592,6 +594,8 @@ PANGO_AVAILABLE_IN_1_50 PangoAttribute * pango_attr_word_new (void); PANGO_AVAILABLE_IN_1_50 PangoAttribute * pango_attr_sentence_new (void); +PANGO_AVAILABLE_IN_ALL +PangoAttribute * pango_attr_paragraph_new (void); PANGO_AVAILABLE_IN_1_44 PangoAttribute * pango_attr_insert_hyphens_new (gboolean insert_hyphens); diff --git a/pango/serializer.c b/pango/serializer.c index 2dab93b4..b3409550 100644 --- a/pango/serializer.c +++ b/pango/serializer.c @@ -201,6 +201,7 @@ static const char *attr_type_names[] = { "sentence", "baseline-shift", "font-scale", + "paragraph", NULL }; @@ -350,6 +351,7 @@ add_attribute (GtkJsonPrinter *printer, case PANGO_ATTR_SHOW: case PANGO_ATTR_WORD: case PANGO_ATTR_SENTENCE: + case PANGO_ATTR_PARAGRAPH: case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT: gtk_json_printer_add_integer (printer, "value", ((PangoAttrInt*)attr)->value); break; @@ -1077,6 +1079,11 @@ attr_for_type (GtkJsonParser *parser, case PANGO_ATTR_FONT_SCALE: attr = pango_attr_font_scale_new ((PangoFontScale) parser_select_string (parser, font_scale_names)); break; + + case PANGO_ATTR_PARAGRAPH: + attr = pango_attr_paragraph_new (); + break; + } attr->start_index = start; -- cgit v1.2.1