nss: upgrade to release 3.73
[LibreOffice.git] / vcl / source / font / Feature.cxx
blob99a3910b81fb762c0f4a9989dc5d2a2254435388
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
11 #include <utility>
12 #include <vcl/font/Feature.hxx>
13 #include <svdata.hxx>
15 #include <hb.h>
17 namespace vcl::font
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);
30 // Feature
31 Feature::Feature()
32 : m_aID({ 0, 0, 0 })
33 , m_eType(FeatureType::OpenType)
37 Feature::Feature(FeatureID const& rID, FeatureType eType)
38 : m_aID(rID)
39 , m_eType(eType)
43 // FeatureSetting
44 FeatureSetting::FeatureSetting(OString feature)
45 : m_nTag(0)
46 , m_nValue(0)
47 , m_nStart(0)
48 , m_nEnd(0)
50 hb_feature_t aFeat;
51 if (hb_feature_from_string(feature.getStr(), feature.getLength(), &aFeat))
53 m_nTag = aFeat.tag;
54 m_nValue = aFeat.value;
55 m_nStart = aFeat.start;
56 m_nEnd = aFeat.end;
60 // FeatureParameter
62 FeatureParameter::FeatureParameter(uint32_t nCode, OUString aDescription)
63 : m_nCode(nCode)
64 , m_sDescription(std::move(aDescription))
65 , m_pDescriptionID(nullptr)
69 FeatureParameter::FeatureParameter(uint32_t nCode, const char* pDescriptionID)
70 : m_nCode(nCode)
71 , m_pDescriptionID(pDescriptionID)
75 OUString FeatureParameter::getDescription() const
77 OUString aReturnString;
79 if (m_pDescriptionID)
80 aReturnString = VclResId(m_pDescriptionID);
81 else if (!m_sDescription.isEmpty())
82 aReturnString = m_sDescription;
84 return aReturnString;
87 uint32_t FeatureParameter::getCode() const { return m_nCode; }
89 // FeatureDefinition
91 FeatureDefinition::FeatureDefinition()
92 : m_pDescriptionID(nullptr)
93 , m_nCode(0)
94 , m_nDefault(0)
95 , m_eType(FeatureParameterType::BOOL)
99 FeatureDefinition::FeatureDefinition(uint32_t nCode, OUString const& rDescription,
100 FeatureParameterType eType,
101 std::vector<FeatureParameter> const& rEnumParameters,
102 uint32_t nDefault)
103 : m_sDescription(rDescription)
104 , m_pDescriptionID(nullptr)
105 , m_nCode(nCode)
106 , m_nDefault(nDefault)
107 , m_eType(eType)
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)
116 , m_nCode(nCode)
117 , m_nDefault(0)
118 , m_eType(FeatureParameterType::BOOL)
122 FeatureDefinition::FeatureDefinition(uint32_t nCode, const char* pDescriptionID,
123 std::vector<FeatureParameter> aEnumParameters)
124 : m_pDescriptionID(pDescriptionID)
125 , m_nCode(nCode)
126 , m_nDefault(0)
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;
150 else
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: */