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(FeatureID
const& rID
, FeatureType eType
)
44 FeatureSetting::FeatureSetting(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
))
65 , m_pDescriptionID(nullptr)
69 FeatureParameter::FeatureParameter(uint32_t nCode
, const char* pDescriptionID
)
71 , m_pDescriptionID(pDescriptionID
)
75 OUString
FeatureParameter::getDescription() const
77 OUString aReturnString
;
80 aReturnString
= VclResId(m_pDescriptionID
);
81 else if (!m_sDescription
.isEmpty())
82 aReturnString
= m_sDescription
;
87 uint32_t FeatureParameter::getCode() const { return m_nCode
; }
91 FeatureDefinition::FeatureDefinition()
92 : m_pDescriptionID(nullptr)
95 , m_eType(FeatureParameterType::BOOL
)
99 FeatureDefinition::FeatureDefinition(uint32_t nCode
, OUString
const& rDescription
,
100 FeatureParameterType eType
,
101 std::vector
<FeatureParameter
> const& rEnumParameters
,
103 : m_sDescription(rDescription
)
104 , m_pDescriptionID(nullptr)
106 , m_nDefault(nDefault
)
108 , m_aEnumParameters(rEnumParameters
)
112 FeatureDefinition::FeatureDefinition(uint32_t nCode
, const char* pDescriptionID
,
113 OUString
const& rNumericPart
)
114 : m_pDescriptionID(pDescriptionID
)
115 , m_sNumericPart(rNumericPart
)
118 , m_eType(FeatureParameterType::BOOL
)
122 FeatureDefinition::FeatureDefinition(uint32_t nCode
, const char* pDescriptionID
,
123 std::vector
<FeatureParameter
> aEnumParameters
)
124 : m_pDescriptionID(pDescriptionID
)
127 , m_eType(FeatureParameterType::ENUM
)
128 , m_aEnumParameters(std::move(aEnumParameters
))
132 const std::vector
<FeatureParameter
>& FeatureDefinition::getEnumParameters() const
134 return m_aEnumParameters
;
137 OUString
FeatureDefinition::getDescription() const
139 if (m_pDescriptionID
)
141 OUString sTranslatedDescription
= VclResId(m_pDescriptionID
);
142 if (!m_sNumericPart
.isEmpty())
143 return sTranslatedDescription
.replaceFirst("%1", m_sNumericPart
);
144 return sTranslatedDescription
;
146 else if (!m_sDescription
.isEmpty())
148 return m_sDescription
;
152 return vcl::font::featureCodeAsString(m_nCode
);
156 uint32_t FeatureDefinition::getCode() const { return m_nCode
; }
158 FeatureParameterType
FeatureDefinition::getType() const { return m_eType
; }
160 FeatureDefinition::operator bool() const { return m_nCode
!= 0; }
162 uint32_t FeatureDefinition::getDefault() const { return m_nDefault
; }
163 } // end vcl::font namespace
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */