Update git submodules
[LibreOffice.git] / vcl / source / font / FeatureParser.cxx
blob44b7d962429d4c6f3fa2fc2fa4f172993511c65d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #include <vcl/font/FeatureParser.hxx>
12 #include <vcl/font/Feature.hxx>
13 #include <o3tl/string_view.hxx>
15 namespace vcl::font
17 OUString trimFontNameFeatures(OUString const& rFontName)
19 const sal_Int32 nPrefixIdx{ rFontName.indexOf(vcl::font::FeaturePrefix) };
21 if (nPrefixIdx < 0)
22 return rFontName;
24 return rFontName.copy(0, nPrefixIdx);
27 FeatureParser::FeatureParser(std::u16string_view rFontName)
29 size_t nPrefixIdx{ rFontName.find(vcl::font::FeaturePrefix) };
31 if (nPrefixIdx == std::u16string_view::npos)
32 return;
34 std::u16string_view sName(rFontName.substr(++nPrefixIdx));
35 sal_Int32 nIndex = 0;
38 std::u16string_view sToken = o3tl::getToken(sName, 0, vcl::font::FeatureSeparator, nIndex);
40 sal_Int32 nInnerIdx{ 0 };
41 std::u16string_view sID = o3tl::getToken(sToken, 0, '=', nInnerIdx);
43 if (sID == u"lang")
45 m_sLanguage = o3tl::getToken(sToken, 0, '=', nInnerIdx);
47 else
49 FeatureSetting aFeature(OUStringToOString(sToken, RTL_TEXTENCODING_ASCII_US));
50 if (aFeature.m_nTag != 0)
51 m_aFeatures.push_back(aFeature);
53 } while (nIndex >= 0);
56 std::unordered_map<uint32_t, int32_t> FeatureParser::getFeaturesMap() const
58 std::unordered_map<uint32_t, int32_t> aResultMap;
59 for (auto const& rFeat : m_aFeatures)
60 aResultMap.emplace(rFeat.m_nTag, rFeat.m_nValue);
61 return aResultMap;
64 } // end vcl::font namespace
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */