summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/pango_markup.md12
-rw-r--r--pango/pango-markup.c56
-rw-r--r--tests/markups/fail-19.expected1
-rw-r--r--tests/markups/fail-19.markup1
-rw-r--r--tests/markups/valid-20.expected14
-rw-r--r--tests/markups/valid-20.markup1
6 files changed, 58 insertions, 27 deletions
diff --git a/docs/pango_markup.md b/docs/pango_markup.md
index 8291dc3c..5f72dc98 100644
--- a/docs/pango_markup.md
+++ b/docs/pango_markup.md
@@ -77,11 +77,13 @@ face
font_size
size
-: Font size in 1024ths of a point, or one of the absolute sizes 'xx-small',
- 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large', or one of the
- relative sizes 'smaller' or 'larger'. If you want to specify a absolute size,
- it's usually easier to take advantage of the ability to specify a partial font
- description using 'font'; you can use font='12.5' rather than size='12800'.
+: Font size in 1024ths of a point, or in points (e.g. '12.5pt'), or one of the
+ absolute sizes 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large',
+ 'xx-large', or one of the relative sizes 'smaller' or 'larger'.
+ If you want to specify a absolute size, it's usually easier to take advantage
+ of the ability to specify a partial font description using 'font'; you can use
+ font='12.5' rather than size='12800' or size='12.5pt'.
+ Support for specifying font sizes in points was added in Pango 1.50.
font_style
style
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index 2828eab3..24de1fc6 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -1109,6 +1109,35 @@ span_parse_flags (const char *attr_name,
}
static gboolean
+parse_length (const char *attr_val,
+ int *result)
+{
+ const char *attr;
+ int n;
+
+ attr = attr_val;
+ if (_pango_scan_int (&attr, &n) && *attr == '\0')
+ {
+ *result = n;
+ return TRUE;
+ }
+ else
+ {
+ double val;
+ char *end;
+
+ val = g_ascii_strtod (attr_val, &end);
+ if (errno == 0 && strcmp (end, "pt") == 0)
+ {
+ *result = val * PANGO_SCALE;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static gboolean
span_parse_func (MarkupData *md G_GNUC_UNUSED,
OpenTag *tag,
const gchar **names,
@@ -1280,27 +1309,14 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED,
if (G_UNLIKELY (size))
{
- if (g_ascii_isdigit (*size))
- {
- const char *end;
- gint n;
-
- if ((end = size, !_pango_scan_int (&end, &n)) || *end != '\0' || n < 0)
- {
- g_set_error (error,
- G_MARKUP_ERROR,
- G_MARKUP_ERROR_INVALID_CONTENT,
- _("Value of 'size' attribute on <span> tag on line %d "
- "could not be parsed; should be an integer no more than %d,"
- " or a string such as 'small', not '%s'"),
- line_number, INT_MAX, size);
- goto error;
- }
+ int n;
- add_attribute (tag, pango_attr_size_new (n));
- if (tag)
- open_tag_set_absolute_font_size (tag, n);
- }
+ if (parse_length (size, &n) && n > 0)
+ {
+ add_attribute (tag, pango_attr_size_new (n));
+ if (tag)
+ open_tag_set_absolute_font_size (tag, n);
+ }
else if (strcmp (size, "smaller") == 0)
{
if (tag)
diff --git a/tests/markups/fail-19.expected b/tests/markups/fail-19.expected
deleted file mode 100644
index 2627110c..00000000
--- a/tests/markups/fail-19.expected
+++ /dev/null
@@ -1 +0,0 @@
-ERROR: Value of 'size' attribute on <span> tag on line 1 could not be parsed; should be an integer no more than 2147483647, or a string such as 'small', not '20px' \ No newline at end of file
diff --git a/tests/markups/fail-19.markup b/tests/markups/fail-19.markup
deleted file mode 100644
index 726022e1..00000000
--- a/tests/markups/fail-19.markup
+++ /dev/null
@@ -1 +0,0 @@
-<span size="20px">test</span>
diff --git a/tests/markups/valid-20.expected b/tests/markups/valid-20.expected
new file mode 100644
index 00000000..bd3ac65f
--- /dev/null
+++ b/tests/markups/valid-20.expected
@@ -0,0 +1,14 @@
+test
+
+
+---
+
+range 0 4
+[0,4]size=20480
+range 4 2147483647
+
+
+---
+
+[0:4] (null) Normal 20
+[4:2147483647] (null) Normal 20
diff --git a/tests/markups/valid-20.markup b/tests/markups/valid-20.markup
new file mode 100644
index 00000000..424b4c9c
--- /dev/null
+++ b/tests/markups/valid-20.markup
@@ -0,0 +1 @@
+<span size="20pt">test</span>