summaryrefslogtreecommitdiff
path: root/pango/pango-markup.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-07 10:37:07 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-08-08 21:35:55 -0400
commit623134f48ad998e1392839f7346c780228ddac45 (patch)
tree606d44e9f51b5a692b69e183999253e96080f06c /pango/pango-markup.c
parented13e662d1a327671fc9f1a3ec7d71c4bbfe1280 (diff)
downloadpango-623134f48ad998e1392839f7346c780228ddac45.tar.gz
Add line-height attributes
Add attributes for line-height, in a relative and absolute variant. This will be used to grow the logical extents of runs in a way that is compatible with CSS semantics. In markup, we support a new line_height attribute that will be interpreted as absolute if it is an integer > 1024, and as a relative factor otherwise.
Diffstat (limited to 'pango/pango-markup.c')
-rw-r--r--pango/pango-markup.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index 5394c772..00b16943 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -977,6 +977,29 @@ span_parse_int (const char *attr_name,
}
static gboolean
+span_parse_float (const char *attr_name,
+ const char *attr_val,
+ double *val,
+ int line_number,
+ GError **error)
+{
+ *val = g_ascii_strtod (attr_val, NULL);
+ if (errno != 0)
+ {
+ g_set_error (error,
+ G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ _("Value of '%s' attribute on <span> tag "
+ "on line %d could not be parsed; "
+ "should be a number, not '%s'"),
+ attr_name, line_number, attr_val);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
span_parse_boolean (const char *attr_name,
const char *attr_val,
gboolean *val,
@@ -1200,6 +1223,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
const char *allow_breaks = NULL;
const char *insert_hyphens = NULL;
const char *show = NULL;
+ const char *line_height = NULL;
g_markup_parse_context_get_position (context,
&line_number, &char_number);
@@ -1278,6 +1302,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
case 'l':
CHECK_ATTRIBUTE (lang);
CHECK_ATTRIBUTE (letter_spacing);
+ CHECK_ATTRIBUTE (line_height);
break;
case 'o':
CHECK_ATTRIBUTE (overline);
@@ -1639,6 +1664,19 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
add_attribute (tag, pango_attr_letter_spacing_new (n));
}
+ if (G_UNLIKELY (line_height))
+ {
+ double f = 0;
+
+ if (!span_parse_float ("line_height", line_height, &f, line_number, error))
+ goto error;
+
+ if (f > 1024.0 && strchr (line_height, ".") == 0)
+ add_attribute (tag, pango_attr_line_height_new_absolute ((int)f));
+ else
+ add_attribute (tag, pango_attr_line_height_new (f));
+ }
+
if (G_UNLIKELY (lang))
{
add_attribute (tag,