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 
14 namespace vcl
15 {
16 namespace font
17 {
18 OUString trimFontNameFeatures(OUString const& rFontName)
19 {
20  const sal_Int32 nPrefixIdx{ rFontName.indexOf(vcl::font::FeaturePrefix) };
21 
22  if (nPrefixIdx < 0)
23  return rFontName;
24 
25  return rFontName.copy(0, nPrefixIdx);
26 }
27 
28 FeatureParser::FeatureParser(OUString const& rFontName)
29 {
30  sal_Int32 nPrefixIdx{ rFontName.indexOf(vcl::font::FeaturePrefix) };
31 
32  if (nPrefixIdx < 0)
33  return;
34 
35  OUString sName = rFontName.copy(++nPrefixIdx);
36  sal_Int32 nIndex = 0;
37  do
38  {
39  OUString sToken = sName.getToken(0, vcl::font::FeatureSeparator, nIndex);
40 
41  sal_Int32 nInnerIdx{ 0 };
42  OUString sID = sToken.getToken(0, '=', nInnerIdx);
43 
44  if (sID == "lang")
45  {
46  m_sLanguage = sToken.getToken(0, '=', nInnerIdx);
47  }
48  else
49  {
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);
54  }
55  } while (nIndex >= 0);
56 }
57 
58 std::unordered_map<uint32_t, uint32_t> FeatureParser::getFeaturesMap() const
59 {
60  std::unordered_map<uint32_t, uint32_t> aResultMap;
61  for (auto const& rFeat : m_aFeatures)
62  {
63  if (rFeat.m_nValue != 0)
64  aResultMap.emplace(rFeat.m_nTag, rFeat.m_nValue);
65  }
66  return aResultMap;
67 }
68 
69 } // end font namespace
70 
71 } // end vcl namespace
72 
73 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr const char FeaturePrefix
FeatureParser(OUString const &sFontName)
std::unordered_map< uint32_t, uint32_t > getFeaturesMap() const
OUString trimFontNameFeatures(OUString const &rFontName)
std::vector< FeatureSetting > m_aFeatures
constexpr const char FeatureSeparator
OUString sName
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)