bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / source / font / FeatureParser.cxx
blob697662032f752fbabdb337eed35f94a4a8382b3f
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 OString sFeature = OUStringToOString(sToken, RTL_TEXTENCODING_ASCII_US);
50 FeatureSetting aFeature(sFeature);
51 if (aFeature.m_nTag != 0)
52 m_aFeatures.push_back(aFeature);
54 } while (nIndex >= 0);
57 std::unordered_map<uint32_t, int32_t> FeatureParser::getFeaturesMap() const
59 std::unordered_map<uint32_t, int32_t> aResultMap;
60 for (auto const& rFeat : m_aFeatures)
61 aResultMap.emplace(rFeat.m_nTag, rFeat.m_nValue);
62 return aResultMap;
65 } // end vcl::font namespace
67 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */