Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / source / font / FeatureParser.cxx
blobb8afe2f36b06852d206c1327cda7177014a9ae28
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>
14 namespace vcl
16 namespace font
18 OUString trimFontNameFeatures(OUString const& rFontName)
20 const sal_Int32 nPrefixIdx{ rFontName.indexOf(vcl::font::FeaturePrefix) };
22 if (nPrefixIdx < 0)
23 return rFontName;
25 return rFontName.copy(0, nPrefixIdx);
28 FeatureParser::FeatureParser(OUString const& rFontName)
30 sal_Int32 nPrefixIdx{ rFontName.indexOf(vcl::font::FeaturePrefix) };
32 if (nPrefixIdx < 0)
33 return;
35 OUString sName = rFontName.copy(++nPrefixIdx);
36 sal_Int32 nIndex = 0;
39 OUString sToken = sName.getToken(0, vcl::font::FeatureSeparator, nIndex);
41 sal_Int32 nInnerIdx{ 0 };
42 OUString sID = sToken.getToken(0, '=', nInnerIdx);
44 if (sID == "lang")
46 m_sLanguage = sToken.getToken(0, '=', nInnerIdx);
48 else
50 OString sFeature = OUStringToOString(sToken, RTL_TEXTENCODING_ASCII_US);
51 FeatureSetting aFeature(sFeature);
52 if (aFeature.m_nTag != 0)
53 m_aFeatures.push_back(aFeature);
55 } while (nIndex >= 0);
58 std::unordered_map<uint32_t, uint32_t> FeatureParser::getFeaturesMap() const
60 std::unordered_map<uint32_t, uint32_t> aResultMap;
61 for (auto const& rFeat : m_aFeatures)
63 if (rFeat.m_nValue != 0)
64 aResultMap.emplace(rFeat.m_nTag, rFeat.m_nValue);
66 return aResultMap;
69 } // end font namespace
71 } // end vcl namespace
73 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */