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