diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /vcl/source/font/FeatureParser.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vcl/source/font/FeatureParser.cxx')
-rw-r--r-- | vcl/source/font/FeatureParser.cxx | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/vcl/source/font/FeatureParser.cxx b/vcl/source/font/FeatureParser.cxx new file mode 100644 index 000000000..c886482df --- /dev/null +++ b/vcl/source/font/FeatureParser.cxx @@ -0,0 +1,69 @@ +/* -*- 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> +#include <vcl/font/Feature.hxx> + +namespace vcl::font +{ +OUString trimFontNameFeatures(OUString const& rFontName) +{ + const sal_Int32 nPrefixIdx{ rFontName.indexOf(vcl::font::FeaturePrefix) }; + + if (nPrefixIdx < 0) + return rFontName; + + return rFontName.copy(0, nPrefixIdx); +} + +FeatureParser::FeatureParser(OUString const& rFontName) +{ + sal_Int32 nPrefixIdx{ rFontName.indexOf(vcl::font::FeaturePrefix) }; + + if (nPrefixIdx < 0) + return; + + OUString sName = rFontName.copy(++nPrefixIdx); + sal_Int32 nIndex = 0; + do + { + OUString sToken = sName.getToken(0, vcl::font::FeatureSeparator, nIndex); + + sal_Int32 nInnerIdx{ 0 }; + OUString sID = sToken.getToken(0, '=', nInnerIdx); + + if (sID == "lang") + { + m_sLanguage = sToken.getToken(0, '=', nInnerIdx); + } + else + { + OString sFeature = OUStringToOString(sToken, RTL_TEXTENCODING_ASCII_US); + FeatureSetting aFeature(sFeature); + if (aFeature.m_nTag != 0) + m_aFeatures.push_back(aFeature); + } + } while (nIndex >= 0); +} + +std::unordered_map<uint32_t, uint32_t> FeatureParser::getFeaturesMap() const +{ + std::unordered_map<uint32_t, uint32_t> aResultMap; + for (auto const& rFeat : m_aFeatures) + { + if (rFeat.m_nValue != 0) + aResultMap.emplace(rFeat.m_nTag, rFeat.m_nValue); + } + return aResultMap; +} + +} // end vcl::font namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |