LibreOffice Module vcl (master)  1
Feature.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 
11 #include <utility>
12 #include <vcl/font/Feature.hxx>
13 #include <svdata.hxx>
14 
15 #include <hb.h>
16 
17 namespace vcl::font
18 {
19 OUString featureCodeAsString(uint32_t nFeature)
20 {
21  std::vector<char> aString(5, 0);
22  aString[0] = char(nFeature >> 24 & 0xff);
23  aString[1] = char(nFeature >> 16 & 0xff);
24  aString[2] = char(nFeature >> 8 & 0xff);
25  aString[3] = char(nFeature >> 0 & 0xff);
26 
27  return OStringToOUString(aString.data(), RTL_TEXTENCODING_ASCII_US);
28 }
29 
30 // Feature
32  : m_aID({ 0, 0, 0 })
34 {
35 }
36 
38  : m_aID(rID)
39  , m_eType(eType)
40 {
41 }
42 
43 // FeatureSetting
45  : m_nTag(0)
46  , m_nValue(0)
47  , m_nStart(0)
48  , m_nEnd(0)
49 {
50  hb_feature_t aFeat;
51  if (hb_feature_from_string(feature.getStr(), feature.getLength(), &aFeat))
52  {
53  m_nTag = aFeat.tag;
54  m_nValue = aFeat.value;
55  m_nStart = aFeat.start;
56  m_nEnd = aFeat.end;
57  }
58 }
59 
60 // FeatureParameter
61 
62 FeatureParameter::FeatureParameter(uint32_t nCode, OUString aDescription)
63  : m_nCode(nCode)
64  , m_sDescription(std::move(aDescription))
65  , m_pDescriptionID(nullptr)
66 {
67 }
68 
69 FeatureParameter::FeatureParameter(uint32_t nCode, const char* pDescriptionID)
70  : m_nCode(nCode)
71  , m_pDescriptionID(pDescriptionID)
72 {
73 }
74 
76 {
77  OUString aReturnString;
78 
79  if (m_pDescriptionID)
80  aReturnString = VclResId(m_pDescriptionID);
81  else if (!m_sDescription.isEmpty())
82  aReturnString = m_sDescription;
83 
84  return aReturnString;
85 }
86 
87 uint32_t FeatureParameter::getCode() const { return m_nCode; }
88 
89 // FeatureDefinition
90 
92  : m_pDescriptionID(nullptr)
93  , m_nCode(0)
94  , m_nDefault(0)
96 {
97 }
98 
99 FeatureDefinition::FeatureDefinition(uint32_t nCode, OUString const& rDescription,
100  FeatureParameterType eType,
101  std::vector<FeatureParameter> const& rEnumParameters,
102  uint32_t nDefault)
103  : m_sDescription(rDescription)
104  , m_pDescriptionID(nullptr)
105  , m_nCode(nCode)
106  , m_nDefault(nDefault)
107  , m_eType(eType)
108  , m_aEnumParameters(rEnumParameters)
109 {
110 }
111 
112 FeatureDefinition::FeatureDefinition(uint32_t nCode, const char* pDescriptionID,
113  OUString const& rNumericPart)
114  : m_pDescriptionID(pDescriptionID)
115  , m_sNumericPart(rNumericPart)
116  , m_nCode(nCode)
117  , m_nDefault(0)
119 {
120 }
121 
122 FeatureDefinition::FeatureDefinition(uint32_t nCode, const char* pDescriptionID,
123  std::vector<FeatureParameter> aEnumParameters)
124  : m_pDescriptionID(pDescriptionID)
125  , m_nCode(nCode)
126  , m_nDefault(0)
128  , m_aEnumParameters(std::move(aEnumParameters))
129 {
130 }
131 
132 const std::vector<FeatureParameter>& FeatureDefinition::getEnumParameters() const
133 {
134  return m_aEnumParameters;
135 }
136 
138 {
139  if (m_pDescriptionID)
140  {
141  OUString sTranslatedDescription = VclResId(m_pDescriptionID);
142  if (!m_sNumericPart.isEmpty())
143  return sTranslatedDescription.replaceFirst("%1", m_sNumericPart);
144  return sTranslatedDescription;
145  }
146  else if (!m_sDescription.isEmpty())
147  {
148  return m_sDescription;
149  }
150  else
151  {
153  }
154 }
155 
156 uint32_t FeatureDefinition::getCode() const { return m_nCode; }
157 
159 
160 FeatureDefinition::operator bool() const { return m_nCode != 0; }
161 
162 uint32_t FeatureDefinition::getDefault() const { return m_nDefault; }
163 } // end vcl::font namespace
164 
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString getDescription() const
Definition: Feature.cxx:137
OUString m_sDescription
OUString featureCodeAsString(uint32_t nFeature)
Definition: Feature.cxx:19
const std::vector< FeatureParameter > & getEnumParameters() const
Definition: Feature.cxx:132
uint32_t getDefault() const
Definition: Feature.cxx:162
const char * m_pDescriptionID
Definition: Feature.hxx:60
ENUM
FeatureSetting(OString feature)
Definition: Feature.cxx:44
const wchar_t *typedef BOOL
const char * m_pDescriptionID
Definition: Feature.hxx:46
FeatureParameterType getType() const
Definition: Feature.cxx:158
FeatureParameterType m_eType
Definition: Feature.hxx:64
std::vector< FeatureParameter > m_aEnumParameters
Definition: Feature.hxx:66
uint32_t getCode() const
Definition: Feature.cxx:87
OUString VclResId(const char *pId)
Definition: svdata.cxx:266
const EnumerationType m_eType
FeatureParameterType
Definition: Feature.hxx:29
FeatureParameter(uint32_t nCode, OUString aDescription)
Definition: Feature.cxx:62
OUString getDescription() const
Definition: Feature.cxx:75
uint32_t getCode() const
Definition: Feature.cxx:156