1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
12 #include <vcl/font/Feature.hxx>
19 OUString
featureCodeAsString(uint32_t nFeature
)
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);
27 return OStringToOUString(aString
.data(), RTL_TEXTENCODING_ASCII_US
);
33 , m_eType(FeatureType::OpenType
)
37 Feature::Feature(uint32_t nCode
, FeatureType eType
)
44 FeatureSetting::FeatureSetting(const OString
& feature
)
51 if (hb_feature_from_string(feature
.getStr(), feature
.getLength(), &aFeat
))
54 m_nValue
= aFeat
.value
;
55 m_nStart
= aFeat
.start
;
62 FeatureParameter::FeatureParameter(uint32_t nCode
, OUString aDescription
)
64 , m_sDescription(std::move(aDescription
))
68 FeatureParameter::FeatureParameter(uint32_t nCode
, TranslateId pDescriptionID
)
70 , m_pDescriptionID(pDescriptionID
)
74 OUString
FeatureParameter::getDescription() const
76 OUString aReturnString
;
79 aReturnString
= VclResId(m_pDescriptionID
);
80 else if (!m_sDescription
.isEmpty())
81 aReturnString
= m_sDescription
;
86 uint32_t FeatureParameter::getCode() const { return m_nCode
; }
90 FeatureDefinition::FeatureDefinition()
93 , m_eType(FeatureParameterType::BOOL
)
97 FeatureDefinition::FeatureDefinition(uint32_t nCode
, OUString aDescription
,
98 FeatureParameterType eType
,
99 std::vector
<FeatureParameter
>&& rEnumParameters
,
101 : m_sDescription(std::move(aDescription
))
103 , m_nDefault(nDefault
)
105 , m_aEnumParameters(std::move(rEnumParameters
))
109 FeatureDefinition::FeatureDefinition(uint32_t nCode
, TranslateId pDescriptionID
,
110 OUString aNumericPart
)
111 : m_pDescriptionID(pDescriptionID
)
112 , m_sNumericPart(std::move(aNumericPart
))
115 , m_eType(FeatureParameterType::BOOL
)
119 FeatureDefinition::FeatureDefinition(uint32_t nCode
, TranslateId pDescriptionID
,
120 std::vector
<FeatureParameter
> aEnumParameters
)
121 : m_pDescriptionID(pDescriptionID
)
124 , m_eType(FeatureParameterType::ENUM
)
125 , m_aEnumParameters(std::move(aEnumParameters
))
129 const std::vector
<FeatureParameter
>& FeatureDefinition::getEnumParameters() const
131 return m_aEnumParameters
;
134 OUString
FeatureDefinition::getDescription() const
136 if (m_pDescriptionID
)
138 OUString sTranslatedDescription
= VclResId(m_pDescriptionID
);
139 if (!m_sNumericPart
.isEmpty())
140 return sTranslatedDescription
.replaceFirst("%1", m_sNumericPart
);
141 return sTranslatedDescription
;
143 else if (!m_sDescription
.isEmpty())
145 return m_sDescription
;
149 return vcl::font::featureCodeAsString(m_nCode
);
153 uint32_t FeatureDefinition::getCode() const { return m_nCode
; }
155 FeatureParameterType
FeatureDefinition::getType() const { return m_eType
; }
157 FeatureDefinition::operator bool() const { return m_nCode
!= 0; }
159 int32_t FeatureDefinition::getDefault() const { return m_nDefault
; }
160 } // end vcl::font namespace
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */