/src/libreoffice/vcl/source/font/FeatureParser.cxx
Line | Count | Source |
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 | | |
11 | | #include <vcl/font/FeatureParser.hxx> |
12 | | #include <vcl/font/Feature.hxx> |
13 | | #include <o3tl/string_view.hxx> |
14 | | |
15 | | namespace vcl::font |
16 | | { |
17 | | OUString trimFontNameFeatures(OUString const& rFontName) |
18 | 0 | { |
19 | 0 | const sal_Int32 nPrefixIdx{ rFontName.indexOf(vcl::font::FeaturePrefix) }; |
20 | |
|
21 | 0 | if (nPrefixIdx < 0) |
22 | 0 | return rFontName; |
23 | | |
24 | 0 | return rFontName.copy(0, nPrefixIdx); |
25 | 0 | } |
26 | | |
27 | | FeatureParser::FeatureParser(std::u16string_view rFontName) |
28 | 14.6M | { |
29 | 14.6M | size_t nPrefixIdx{ rFontName.find(vcl::font::FeaturePrefix) }; |
30 | | |
31 | 14.6M | if (nPrefixIdx == std::u16string_view::npos) |
32 | 14.4M | return; |
33 | | |
34 | 185k | std::u16string_view sName(rFontName.substr(++nPrefixIdx)); |
35 | 185k | sal_Int32 nIndex = 0; |
36 | 185k | do |
37 | 675k | { |
38 | 675k | std::u16string_view sToken = o3tl::getToken(sName, 0, vcl::font::FeatureSeparator, nIndex); |
39 | | |
40 | 675k | sal_Int32 nInnerIdx{ 0 }; |
41 | 675k | std::u16string_view sID = o3tl::getToken(sToken, 0, '=', nInnerIdx); |
42 | | |
43 | 675k | if (sID == u"lang") |
44 | 0 | { |
45 | 0 | m_sLanguage = o3tl::getToken(sToken, 0, '=', nInnerIdx); |
46 | 0 | } |
47 | 675k | else |
48 | 675k | { |
49 | 675k | FeatureSetting aFeature(OUStringToOString(sToken, RTL_TEXTENCODING_ASCII_US)); |
50 | 675k | if (aFeature.m_nTag != 0) |
51 | 357k | m_aFeatures.push_back(aFeature); |
52 | 675k | } |
53 | 675k | } while (nIndex >= 0); |
54 | 185k | } |
55 | | |
56 | | std::unordered_map<uint32_t, int32_t> FeatureParser::getFeaturesMap() const |
57 | 0 | { |
58 | 0 | std::unordered_map<uint32_t, int32_t> aResultMap; |
59 | 0 | for (auto const& rFeat : m_aFeatures) |
60 | 0 | aResultMap.emplace(rFeat.m_nTag, rFeat.m_nValue); |
61 | 0 | return aResultMap; |
62 | 0 | } |
63 | | |
64 | | } // end vcl::font namespace |
65 | | |
66 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |