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