diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-06-15 19:32:15 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-06-16 18:04:31 +0200 |
commit | dc9ee533dc707cc10b99d537eaccc3ee5aa555fe (patch) | |
tree | bbe8c7547aac7b0440f874ed39945faa60a84276 /vcl/source/font | |
parent | 099eef24da24d638fdf2c747d28040c9b3a30780 (diff) |
vcl: parser of font features included in the font name
Change-Id: I7347410b4eb5e940d94c34aac4fdf344869541fa
Reviewed-on: https://gerrit.libreoffice.org/55893
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/source/font')
-rw-r--r-- | vcl/source/font/FeatureParser.cxx | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/vcl/source/font/FeatureParser.cxx b/vcl/source/font/FeatureParser.cxx new file mode 100644 index 000000000000..d61c0a89cfd6 --- /dev/null +++ b/vcl/source/font/FeatureParser.cxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <vcl/font/FeatureParser.hxx> + +namespace vcl +{ +namespace font +{ +OUString trimFontNameFeatures(OUString const& rFontName) +{ + OUString sResultName(rFontName); + + if (sResultName.indexOf(vcl::font::FeaturePrefix) < 0) + return sResultName; + + return sResultName.getToken(0, vcl::font::FeaturePrefix); +} + +FeatureParser::FeatureParser(OUString const& rFontName) +{ + if (rFontName.indexOf(vcl::font::FeaturePrefix) < 0) + return; + + OUString sName = rFontName.getToken(1, vcl::font::FeaturePrefix); + sal_Int32 nIndex = 0; + do + { + OUString sToken = sName.getToken(0, vcl::font::FeatureSeparator, nIndex); + + OUString sID = sToken.getToken(0, '='); + OUString sValue = sToken.getToken(1, '='); + + if (sID.getLength() == 4 && sValue != "0") + { + if (sID == "lang") + { + m_sLanguage = sValue; + } + else + { + OString sFeatureCodeAscii = OUStringToOString(sID, RTL_TEXTENCODING_ASCII_US); + sal_uInt32 nCode = vcl::font::featureCode(sFeatureCodeAscii.getStr()); + sal_uInt32 nValue = sValue.isEmpty() ? 1 : sValue.toUInt32(); + + if (nValue != 0) + m_aFeatures.emplace_back(nCode, nValue); + } + } + } while (nIndex >= 0); +} + +std::unordered_map<sal_uInt32, sal_uInt32> FeatureParser::getFeaturesMap() +{ + std::unordered_map<sal_uInt32, sal_uInt32> aResultMap; + for (auto const& rPair : m_aFeatures) + { + aResultMap.emplace(rPair); + } + return aResultMap; +} + +} // end font namespace + +} // end vcl namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |