LibreOffice Module vcl (master) 1
FeatureParser.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 */
10
12#include <vcl/font/Feature.hxx>
13#include <o3tl/string_view.hxx>
14
15namespace vcl::font
16{
17OUString trimFontNameFeatures(OUString const& rFontName)
18{
19 const sal_Int32 nPrefixIdx{ rFontName.indexOf(vcl::font::FeaturePrefix) };
20
21 if (nPrefixIdx < 0)
22 return rFontName;
23
24 return rFontName.copy(0, nPrefixIdx);
25}
26
27FeatureParser::FeatureParser(std::u16string_view rFontName)
28{
29 size_t nPrefixIdx{ rFontName.find(vcl::font::FeaturePrefix) };
30
31 if (nPrefixIdx == std::u16string_view::npos)
32 return;
33
34 std::u16string_view sName(rFontName.substr(++nPrefixIdx));
35 sal_Int32 nIndex = 0;
36 do
37 {
38 std::u16string_view sToken = o3tl::getToken(sName, 0, vcl::font::FeatureSeparator, nIndex);
39
40 sal_Int32 nInnerIdx{ 0 };
41 std::u16string_view sID = o3tl::getToken(sToken, 0, '=', nInnerIdx);
42
43 if (sID == u"lang")
44 {
45 m_sLanguage = o3tl::getToken(sToken, 0, '=', nInnerIdx);
46 }
47 else
48 {
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);
53 }
54 } while (nIndex >= 0);
55}
56
57std::unordered_map<uint32_t, uint32_t> FeatureParser::getFeaturesMap() const
58{
59 std::unordered_map<uint32_t, uint32_t> aResultMap;
60 for (auto const& rFeat : m_aFeatures)
61 {
62 if (rFeat.m_nValue != 0)
63 aResultMap.emplace(rFeat.m_nTag, rFeat.m_nValue);
64 }
65 return aResultMap;
66}
67
68} // end vcl::font namespace
69
70/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< FeatureSetting > m_aFeatures
FeatureParser(std::u16string_view sFontName)
std::unordered_map< uint32_t, uint32_t > getFeaturesMap() const
float u
sal_Int32 nIndex
const char * sName
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
A PhysicalFontFaceCollection is created by a PhysicalFontCollection and becomes invalid when original...
constexpr const char FeaturePrefix
OUString trimFontNameFeatures(OUString const &rFontName)
constexpr const char FeatureSeparator