summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-08 01:40:08 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-08-08 10:38:40 -0400
commit59d38cde20425696543d262c5329b14056915614 (patch)
tree8baccfcbf663d7431c6cab69f42f4fd3712b3f8d /pango
parent9d68eaf2d7366bc448f722d7638714fba9c34460 (diff)
downloadpango-59d38cde20425696543d262c5329b14056915614.tar.gz
markup: Allow specifying size as percentagemarkup-sizes
Accept values like 200%, in addition to other ways of specifying sizes in markup. Fixes: #23
Diffstat (limited to 'pango')
-rw-r--r--pango/pango-markup.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index a4bea3e5..5394c772 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -861,10 +861,28 @@ big_parse_func (MarkupData *md G_GNUC_UNUSED,
}
static gboolean
+parse_percentage (const char *input,
+ double *val)
+{
+ double v;
+ char *end;
+
+ v = g_ascii_strtod (input, &end);
+ if (errno == 0 && strcmp (end, "%") == 0 && v > 0)
+ {
+ *val = v;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
parse_absolute_size (OpenTag *tag,
- const char *size)
+ const char *size)
{
SizeLevel level = Medium;
+ double val;
double factor;
if (strcmp (size, "xx-small") == 0)
@@ -881,6 +899,11 @@ parse_absolute_size (OpenTag *tag,
level = XLarge;
else if (strcmp (size, "xx-large") == 0)
level = XXLarge;
+ else if (parse_percentage (size, &val))
+ {
+ factor = val / 100.0;
+ goto done;
+ }
else
return FALSE;
@@ -888,6 +911,8 @@ parse_absolute_size (OpenTag *tag,
* but not to sizes created by any other tags
*/
factor = scale_factor (level, 1.0);
+
+done:
add_attribute (tag, pango_attr_scale_new (factor));
if (tag)
open_tag_set_absolute_font_scale (tag, factor);