tdf#164627 docx export: consolidate getWordCompatibilityMode()
[LibreOffice.git] / vcl / source / font / Feature.cxx
blobf9f35682c15e1e84a785413c605ca368c8876f12
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_nCode(0)
33 , m_eType(FeatureType::OpenType)
37 Feature::Feature(uint32_t nCode, FeatureType eType)
38 : m_nCode(nCode)
39 , m_eType(eType)
43 // FeatureSetting
44 FeatureSetting::FeatureSetting(const 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))
68 FeatureParameter::FeatureParameter(uint32_t nCode, TranslateId pDescriptionID)
69 : m_nCode(nCode)
70 , m_pDescriptionID(pDescriptionID)
74 OUString FeatureParameter::getDescription() const
76 OUString aReturnString;
78 if (m_pDescriptionID)
79 aReturnString = VclResId(m_pDescriptionID);
80 else if (!m_sDescription.isEmpty())
81 aReturnString = m_sDescription;
83 return aReturnString;
86 uint32_t FeatureParameter::getCode() const { return m_nCode; }
88 // FeatureDefinition
90 FeatureDefinition::FeatureDefinition()
91 : m_nCode(0)
92 , m_nDefault(-1)
93 , m_eType(FeatureParameterType::BOOL)
97 FeatureDefinition::FeatureDefinition(uint32_t nCode, OUString aDescription,
98 FeatureParameterType eType,
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))
109 FeatureDefinition::FeatureDefinition(uint32_t nCode, TranslateId pDescriptionID,
110 OUString aNumericPart)
111 : m_pDescriptionID(pDescriptionID)
112 , m_sNumericPart(std::move(aNumericPart))
113 , m_nCode(nCode)
114 , m_nDefault(-1)
115 , m_eType(FeatureParameterType::BOOL)
119 FeatureDefinition::FeatureDefinition(uint32_t nCode, TranslateId pDescriptionID,
120 std::vector<FeatureParameter> aEnumParameters)
121 : m_pDescriptionID(pDescriptionID)
122 , m_nCode(nCode)
123 , m_nDefault(-1)
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;
147 else
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: */