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 {
66 }
67 
68 FeatureParameter::FeatureParameter(uint32_t nCode, TranslateId pDescriptionID)
69  : m_nCode(nCode)
70  , m_pDescriptionID(pDescriptionID)
71 {
72 }
73 
75 {
76  OUString aReturnString;
77 
78  if (m_pDescriptionID)
79  aReturnString = VclResId(m_pDescriptionID);
80  else if (!m_sDescription.isEmpty())
81  aReturnString = m_sDescription;
82 
83  return aReturnString;
84 }
85 
86 uint32_t FeatureParameter::getCode() const { return m_nCode; }
87 
88 // FeatureDefinition
89 
91  : m_nCode(0)
92  , m_nDefault(0)
94 {
95 }
96 
97 FeatureDefinition::FeatureDefinition(uint32_t nCode, OUString const& rDescription,
99  std::vector<FeatureParameter>&& rEnumParameters,
100  uint32_t nDefault)
101  : m_sDescription(rDescription)
102  , m_nCode(nCode)
103  , m_nDefault(nDefault)
104  , m_eType(eType)
105  , m_aEnumParameters(std::move(rEnumParameters))
106 {
107 }
108 
109 FeatureDefinition::FeatureDefinition(uint32_t nCode, TranslateId pDescriptionID,
110  OUString const& rNumericPart)
111  : m_pDescriptionID(pDescriptionID)
112  , m_sNumericPart(rNumericPart)
113  , m_nCode(nCode)
114  , m_nDefault(0)
116 {
117 }
118 
119 FeatureDefinition::FeatureDefinition(uint32_t nCode, TranslateId pDescriptionID,
120  std::vector<FeatureParameter> aEnumParameters)
121  : m_pDescriptionID(pDescriptionID)
122  , m_nCode(nCode)
123  , m_nDefault(0)
125  , m_aEnumParameters(std::move(aEnumParameters))
126 {
127 }
128 
129 const std::vector<FeatureParameter>& FeatureDefinition::getEnumParameters() const
130 {
131  return m_aEnumParameters;
132 }
133 
135 {
136  if (m_pDescriptionID)
137  {
138  OUString sTranslatedDescription = VclResId(m_pDescriptionID);
139  if (!m_sNumericPart.isEmpty())
140  return sTranslatedDescription.replaceFirst("%1", m_sNumericPart);
141  return sTranslatedDescription;
142  }
143  else if (!m_sDescription.isEmpty())
144  {
145  return m_sDescription;
146  }
147  else
148  {
150  }
151 }
152 
153 uint32_t FeatureDefinition::getCode() const { return m_nCode; }
154 
156 
157 FeatureDefinition::operator bool() const { return m_nCode != 0; }
158 
159 uint32_t FeatureDefinition::getDefault() const { return m_nDefault; }
160 } // end vcl::font namespace
161 
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString getDescription() const
Definition: Feature.cxx:134
OUString m_sDescription
OUString featureCodeAsString(uint32_t nFeature)
Definition: Feature.cxx:19
const std::vector< FeatureParameter > & getEnumParameters() const
Definition: Feature.cxx:129
uint32_t getDefault() const
Definition: Feature.cxx:159
ENUM
TranslateId m_pDescriptionID
Definition: Feature.hxx:59
FeatureSetting(OString feature)
Definition: Feature.cxx:44
const wchar_t *typedef BOOL
OUString VclResId(TranslateId aId)
Definition: svdata.cxx:258
A PhysicalFontFaceCollection is created by a PhysicalFontCollection and becomes invalid when original...
FeatureParameterType getType() const
Definition: Feature.cxx:155
FeatureParameterType m_eType
Definition: Feature.hxx:63
TranslateId m_pDescriptionID
Definition: Feature.hxx:45
std::vector< FeatureParameter > m_aEnumParameters
Definition: Feature.hxx:65
uint32_t getCode() const
Definition: Feature.cxx:86
const EnumerationType m_eType
FeatureParameterType
Definition: Feature.hxx:28
FeatureParameter(uint32_t nCode, OUString aDescription)
Definition: Feature.cxx:62
OUString getDescription() const
Definition: Feature.cxx:74
uint32_t getCode() const
Definition: Feature.cxx:153