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