diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-08-29 00:10:03 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-08-31 14:29:56 -0400 |
commit | 303b4fb73eb8848d18abbda4d151461bd86f1000 (patch) | |
tree | 44024e2ec8933eef1a7a3d62ffc2d35264104634 /pango/pango-markup.c | |
parent | e382a65301847bb432c1bf3f9774ef48e1ec4734 (diff) | |
download | pango-303b4fb73eb8848d18abbda4d151461bd86f1000.tar.gz |
Implement baseline shifts
Add a new baseline-shift attribute, which is similar to
rise, but accumulates. In addition, it supports font-
relative values such as superscript and subscript.
We implement support for this by computing baseline
shifts for run during line post-processing, and storing
them in the runs. The renderer now takes these shifts
into account when rendering layout lines.
Diffstat (limited to 'pango/pango-markup.c')
-rw-r--r-- | pango/pango-markup.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pango/pango-markup.c b/pango/pango-markup.c index a9df8ed0..65396547 100644 --- a/pango/pango-markup.c +++ b/pango/pango-markup.c @@ -1217,6 +1217,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED, const char *strikethrough = NULL; const char *strikethrough_color = NULL; const char *rise = NULL; + const char *baseline_shift = NULL; const char *letter_spacing = NULL; const char *lang = NULL; const char *fallback = NULL; @@ -1268,6 +1269,7 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED, CHECK_ATTRIBUTE2(background, "bgcolor"); CHECK_ATTRIBUTE (background_alpha); CHECK_ATTRIBUTE2(background_alpha, "bgalpha"); + CHECK_ATTRIBUTE(baseline_shift); break; case 'c': CHECK_ATTRIBUTE2(foreground, "color"); @@ -1675,6 +1677,28 @@ span_parse_func (MarkupData *md G_GNUC_UNUSED, add_attribute (tag, pango_attr_rise_new (n)); } + if (G_UNLIKELY (baseline_shift)) + { + gint shift = 0; + + if (span_parse_enum ("baseline_shift", baseline_shift, PANGO_TYPE_BASELINE_SHIFT, (int*)(void*)&shift, line_number, NULL)) + add_attribute (tag, pango_attr_baseline_shift_new (shift)); + else if (parse_length (baseline_shift, &shift) && (shift > 1024 || shift < -1024)) + add_attribute (tag, pango_attr_baseline_shift_new (shift)); + else + { + g_set_error (error, + G_MARKUP_ERROR, + G_MARKUP_ERROR_INVALID_CONTENT, + _("Value of 'baseline_shift' attribute on <span> tag on line %d " + "could not be parsed; should be 'superscript' or 'subscript' or " + "an integer, or a string such as '5.5pt', not '%s'"), + line_number, baseline_shift); + goto error; + } + + } + if (G_UNLIKELY (letter_spacing)) { gint n = 0; |