[pango/pango2: 51/168] Add a paragraph attribute
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2: 51/168] Add a paragraph attribute
- Date: Wed, 8 Jun 2022 10:22:16 +0000 (UTC)
commit d4430a340d8e76fd60cee3c3b84ae915b061a928
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jan 21 23:25:45 2022 -0500
Add a paragraph attribute
This will be used to implement single-paragraph mode.
pango/pango-attributes.c | 32 ++++++++++++++++++++++++++++++++
pango/pango-attributes.h | 4 ++++
pango/pango-markup.c | 2 ++
pango/serializer.c | 7 +++++++
4 files changed, 45 insertions(+)
---
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index add15c1e..25f39b11 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;
@@ -3056,6 +3082,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/pango-markup.c b/pango/pango-markup.c
index 9a3bde55..7caf86f5 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -1771,6 +1771,8 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
add_attribute (tag, pango_attr_word_new ());
else if (strcmp (segment, "sentence") == 0)
add_attribute (tag, pango_attr_sentence_new ());
+ else if (strcmp (segment, "paragraph") == 0)
+ add_attribute (tag, pango_attr_paragraph_new ());
else
{
g_set_error (error,
diff --git a/pango/serializer.c b/pango/serializer.c
index bd47f364..a0885cab 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
};
@@ -342,6 +343,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;
@@ -1071,6 +1073,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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]