diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-03-27 20:21:07 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-03-27 20:21:07 +0000 |
| commit | bec051c44f27e014e77506bbd2e59fb556e1268a (patch) | |
| tree | cb0cecf9f9a41a0bcca8126851930ad2ed39e011 /src/libnrtype | |
| parent | Minor cleanup of warnings. No functional change. (diff) | |
| download | inkscape-bec051c44f27e014e77506bbd2e59fb556e1268a.tar.gz inkscape-bec051c44f27e014e77506bbd2e59fb556e1268a.zip | |
Convert Pango font variations string to CSS format before saving to CSS.
Diffstat (limited to 'src/libnrtype')
| -rw-r--r-- | src/libnrtype/font-lister.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index 7e9b34fa1..90a323b1a 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -763,8 +763,30 @@ void FontLister::fill_css(SPCSSAttr *css, Glib::ustring fontspec) } #if PANGO_VERSION_CHECK(1,41,1) - const char* variations = pango_font_description_get_variations(desc); - sp_repr_css_set_property(css, "font-variation-settings", variations); + // Convert Pango variations string to CSS format + const char* str = pango_font_description_get_variations(desc); + + std::string variations; + + std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(",", str); + + Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create("(\\w{4})=([-+]?\\d*\\.?\\d+([eE][-+]?\\d+)?)"); + Glib::MatchInfo matchInfo; + for (auto token: tokens) { + regex->match(token, matchInfo); + if (matchInfo.matches()) { + variations += "'"; + variations += matchInfo.fetch(1); + variations += "' "; + variations += matchInfo.fetch(2); + variations += ", "; + } + } + if (variations.length() >= 2) { // Remove last comma/space + variations.pop_back(); + variations.pop_back(); + } + sp_repr_css_set_property(css, "font-variation-settings", variations.c_str()); #endif } |
