Get the style color and number just once
[LibreOffice.git] / include / vcl / font / Feature.hxx
blob67c24dd44f907656dbed57893b9ea3e1aa02ffd6
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/.
8 */
10 #ifndef INCLUDED_VCL_FONT_FEATURE_HXX
11 #define INCLUDED_VCL_FONT_FEATURE_HXX
13 #include <vcl/dllapi.h>
14 #include <rtl/character.hxx>
15 #include <rtl/ustring.hxx>
16 #include <unotools/resmgr.hxx>
17 #include <vector>
19 namespace vcl::font
21 constexpr uint32_t featureCode(const char sFeature[4])
23 return static_cast<uint32_t>(sFeature[0]) << 24U | static_cast<uint32_t>(sFeature[1]) << 16U
24 | static_cast<uint32_t>(sFeature[2]) << 8U | static_cast<uint32_t>(sFeature[3]);
27 VCL_DLLPUBLIC OUString featureCodeAsString(uint32_t nFeature);
29 enum class FeatureParameterType
31 BOOL,
32 ENUM
35 enum class FeatureType
37 OpenType,
38 Graphite
41 struct VCL_DLLPUBLIC FeatureParameter
43 private:
44 uint32_t m_nCode;
45 OUString m_sDescription;
46 TranslateId m_pDescriptionID;
48 public:
49 FeatureParameter(uint32_t nCode, OUString aDescription);
50 FeatureParameter(uint32_t nCode, TranslateId pDescriptionID);
52 uint32_t getCode() const;
53 OUString getDescription() const;
56 class VCL_DLLPUBLIC FeatureDefinition
58 private:
59 OUString m_sDescription;
60 TranslateId m_pDescriptionID;
61 OUString m_sNumericPart;
62 uint32_t m_nCode;
63 int32_t m_nDefault;
64 FeatureParameterType m_eType;
65 // the index of the parameter defines the enum value, string is the description
66 std::vector<FeatureParameter> m_aEnumParameters;
68 public:
69 FeatureDefinition();
70 FeatureDefinition(uint32_t nCode, OUString aDescription,
71 FeatureParameterType eType = FeatureParameterType::BOOL,
72 std::vector<FeatureParameter>&& rEnumParameters
73 = std::vector<FeatureParameter>{},
74 int32_t nDefault = -1);
75 FeatureDefinition(uint32_t nCode, TranslateId pDescriptionID,
76 OUString aNumericPart = OUString());
77 FeatureDefinition(uint32_t nCode, TranslateId pDescriptionID,
78 std::vector<FeatureParameter> aEnumParameters);
80 const std::vector<FeatureParameter>& getEnumParameters() const;
81 uint32_t getCode() const;
82 OUString getDescription() const;
83 FeatureParameterType getType() const;
84 int32_t getDefault() const;
86 operator bool() const;
89 struct Feature
91 Feature();
92 Feature(uint32_t const nCode, FeatureType eType);
94 bool isCharacterVariant() const
96 return ((m_nCode >> 24) & 0xFF) == 'c' && ((m_nCode >> 16) & 0xFF) == 'v'
97 && rtl::isAsciiDigit((m_nCode >> 8) & 0xFF)
98 && rtl::isAsciiDigit((m_nCode >> 0) & 0xFF);
101 bool isStylisticSet() const
103 return ((m_nCode >> 24) & 0xFF) == 's' && ((m_nCode >> 16) & 0xFF) == 's'
104 && rtl::isAsciiDigit((m_nCode >> 8) & 0xFF)
105 && rtl::isAsciiDigit((m_nCode >> 0) & 0xFF);
108 uint32_t m_nCode;
109 FeatureType m_eType;
110 FeatureDefinition m_aDefinition;
113 // This is basically duplicates hb_feature_t to avoid including HarfBuzz
114 // headers here, so the member types should remain compatible.
115 struct FeatureSetting
117 FeatureSetting(const OString& feature);
119 uint32_t m_nTag;
120 uint32_t m_nValue;
121 unsigned int m_nStart;
122 unsigned int m_nEnd;
125 } // namespace vcl::font
127 #endif // INCLUDED_VCL_FONT_FEATURE_HXX
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */