LibreOffice Module vcl (master) 1
OpenTypeFeatureDefinitionList.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 *
9 */
10
12#include <font/OpenTypeFeatureStrings.hrc>
13
14#include <rtl/character.hxx>
15
16#include <algorithm>
17
18namespace vcl::font
19{
21{
23 return SINGLETON;
24};
25
27
29{
31 { featureCode("aalt"), STR_FONT_FEATURE_ID_AALT },
32 { featureCode("afrc"), STR_FONT_FEATURE_ID_AFRC },
33 { featureCode("alig"), STR_FONT_FEATURE_ID_ALIG },
34 { featureCode("c2pc"), STR_FONT_FEATURE_ID_C2PC },
35 { featureCode("c2sc"), STR_FONT_FEATURE_ID_C2SC },
36 { featureCode("calt"), STR_FONT_FEATURE_ID_CALT },
37 { featureCode("case"), STR_FONT_FEATURE_ID_CASE },
38 { featureCode("clig"), STR_FONT_FEATURE_ID_CLIG },
39 { featureCode("cpct"), STR_FONT_FEATURE_ID_CPCT },
40 { featureCode("cpsp"), STR_FONT_FEATURE_ID_CPSP },
41 { featureCode("cswh"), STR_FONT_FEATURE_ID_CSWH },
42 { featureCode("dcap"), STR_FONT_FEATURE_ID_DCAP },
43 { featureCode("dlig"), STR_FONT_FEATURE_ID_DLIG },
44 { featureCode("dnom"), STR_FONT_FEATURE_ID_DNOM },
45 { featureCode("dpng"), STR_FONT_FEATURE_ID_DPNG },
46 { featureCode("expt"), STR_FONT_FEATURE_ID_EXPT },
47 { featureCode("falt"), STR_FONT_FEATURE_ID_FALT },
48 { featureCode("frac"), STR_FONT_FEATURE_ID_FRAC },
49 { featureCode("fwid"), STR_FONT_FEATURE_ID_FWID },
50 { featureCode("halt"), STR_FONT_FEATURE_ID_HALT },
51 { featureCode("hist"), STR_FONT_FEATURE_ID_HIST },
52 { featureCode("hkna"), STR_FONT_FEATURE_ID_HKNA },
53 { featureCode("hlig"), STR_FONT_FEATURE_ID_HLIG },
54 { featureCode("hngl"), STR_FONT_FEATURE_ID_HNGL },
55 { featureCode("hojo"), STR_FONT_FEATURE_ID_HOJO },
56 { featureCode("hwid"), STR_FONT_FEATURE_ID_HWID },
57 { featureCode("ital"), STR_FONT_FEATURE_ID_ITAL },
58 { featureCode("jalt"), STR_FONT_FEATURE_ID_JALT },
59 { featureCode("jp78"), STR_FONT_FEATURE_ID_JP78 },
60 { featureCode("jp83"), STR_FONT_FEATURE_ID_JP83 },
61 { featureCode("jp90"), STR_FONT_FEATURE_ID_JP90 },
62 { featureCode("jp04"), STR_FONT_FEATURE_ID_JP04 },
63 { featureCode("kern"), STR_FONT_FEATURE_ID_KERN },
64 { featureCode("lfbd"), STR_FONT_FEATURE_ID_LFBD },
65 { featureCode("liga"), STR_FONT_FEATURE_ID_LIGA },
66 { featureCode("lnum"), STR_FONT_FEATURE_ID_LNUM },
67 { featureCode("mgrk"), STR_FONT_FEATURE_ID_MGRK },
68 { featureCode("nalt"), STR_FONT_FEATURE_ID_NALT },
69 { featureCode("nlck"), STR_FONT_FEATURE_ID_NLCK },
70 { featureCode("numr"), STR_FONT_FEATURE_ID_NUMR },
71 { featureCode("onum"), STR_FONT_FEATURE_ID_ONUM },
72 { featureCode("opbd"), STR_FONT_FEATURE_ID_OPBD },
73 { featureCode("ordn"), STR_FONT_FEATURE_ID_ORDN },
74 { featureCode("ornm"), STR_FONT_FEATURE_ID_ORNM },
75 { featureCode("palt"), STR_FONT_FEATURE_ID_PALT },
76 { featureCode("pcap"), STR_FONT_FEATURE_ID_PCAP },
77 { featureCode("pkna"), STR_FONT_FEATURE_ID_PKNA },
78 { featureCode("pnum"), STR_FONT_FEATURE_ID_PNUM },
79 { featureCode("pwid"), STR_FONT_FEATURE_ID_PWID },
80 { featureCode("qwid"), STR_FONT_FEATURE_ID_QWID },
81 { featureCode("rtbd"), STR_FONT_FEATURE_ID_RTBD },
82 { featureCode("ruby"), STR_FONT_FEATURE_ID_RUBY },
83 { featureCode("salt"), STR_FONT_FEATURE_ID_SALT },
84 { featureCode("sinf"), STR_FONT_FEATURE_ID_SINF },
85 { featureCode("smcp"), STR_FONT_FEATURE_ID_SMCP },
86 { featureCode("smpl"), STR_FONT_FEATURE_ID_SMPL },
87 { featureCode("subs"), STR_FONT_FEATURE_ID_SUBS },
88 { featureCode("sups"), STR_FONT_FEATURE_ID_SUPS },
89 { featureCode("swsh"), STR_FONT_FEATURE_ID_SWSH },
90 { featureCode("titl"), STR_FONT_FEATURE_ID_TITL },
91 { featureCode("tnam"), STR_FONT_FEATURE_ID_TNAM },
92 { featureCode("tnum"), STR_FONT_FEATURE_ID_TNUM },
93 { featureCode("trad"), STR_FONT_FEATURE_ID_TRAD },
94 { featureCode("twid"), STR_FONT_FEATURE_ID_TWID },
95 { featureCode("unic"), STR_FONT_FEATURE_ID_UNIC },
96 { featureCode("valt"), STR_FONT_FEATURE_ID_VALT },
97 { featureCode("vhal"), STR_FONT_FEATURE_ID_VHAL },
98 { featureCode("vkna"), STR_FONT_FEATURE_ID_VKNA },
99 { featureCode("vkrn"), STR_FONT_FEATURE_ID_VKRN },
100 { featureCode("vpal"), STR_FONT_FEATURE_ID_VPAL },
101 { featureCode("vrt2"), STR_FONT_FEATURE_ID_VRT2 },
102 { featureCode("vrtr"), STR_FONT_FEATURE_ID_VRTR },
103 { featureCode("zero"), STR_FONT_FEATURE_ID_ZERO },
104 });
105
106 for (size_t i = 0; i < m_aFeatureDefinition.size(); ++i)
107 {
108 m_aCodeToIndex.emplace(m_aFeatureDefinition[i].getCode(), i);
109 }
110
111 m_aRequiredFeatures.assign({
112 featureCode("abvf"), featureCode("abvm"), featureCode("abvs"), featureCode("akhn"),
113 featureCode("blwf"), featureCode("blwm"), featureCode("blws"), featureCode("ccmp"),
114 featureCode("cfar"), featureCode("cjct"), featureCode("curs"), featureCode("dist"),
115 featureCode("dtls"), featureCode("fin2"), featureCode("fin3"), featureCode("fina"),
116 featureCode("flac"), featureCode("half"), featureCode("haln"), featureCode("init"),
117 featureCode("isol"), featureCode("ljmo"), featureCode("locl"), featureCode("ltra"),
118 featureCode("ltrm"), featureCode("mark"), featureCode("med2"), featureCode("medi"),
119 featureCode("mkmk"), featureCode("mset"), featureCode("nukt"), featureCode("pref"),
120 featureCode("pres"), featureCode("pstf"), featureCode("psts"), featureCode("rand"),
121 featureCode("rclt"), featureCode("rkrf"), featureCode("rlig"), featureCode("rphf"),
122 featureCode("rtla"), featureCode("rtlm"), featureCode("rvrn"), featureCode("size"),
123 featureCode("ssty"), featureCode("stch"), featureCode("tjmo"), featureCode("vatu"),
124 featureCode("vert"), featureCode("vjmo"),
125 });
126}
127
128namespace
129{
130bool isCharacterVariantCode(sal_uInt32 nFeatureCode)
131{
132 return ((sal_uInt32(nFeatureCode) >> 24) & 0xFF) == 'c'
133 && ((sal_uInt32(nFeatureCode) >> 16) & 0xFF) == 'v';
134}
135
136bool isStylisticSetCode(sal_uInt32 nFeatureCode)
137{
138 return ((sal_uInt32(nFeatureCode) >> 24) & 0xFF) == 's'
139 && ((sal_uInt32(nFeatureCode) >> 16) & 0xFF) == 's';
140}
141
142OUString getNumericLowerPart(sal_uInt32 nFeatureCode)
143{
144 char cChar1((sal_uInt32(nFeatureCode) >> 8) & 0xFF);
145 char cChar2((sal_uInt32(nFeatureCode) >> 0) & 0xFF);
146
147 if (rtl::isAsciiDigit(static_cast<unsigned char>(cChar1))
148 && rtl::isAsciiDigit(static_cast<unsigned char>(cChar2)))
149 {
150 return OUStringChar(cChar1) + OUStringChar(cChar2);
151 }
152 return OUString();
153}
154
155} // end anonymous namespace
156
158{
159 return isCharacterVariantCode(nFeatureCode) || isStylisticSetCode(nFeatureCode);
160}
161
164{
165 FeatureDefinition aFeatureDefinition;
166 OUString sNumericPart = getNumericLowerPart(nFeatureCode);
167 if (!sNumericPart.isEmpty())
168 {
169 if (isCharacterVariantCode(nFeatureCode))
170 aFeatureDefinition = { nFeatureCode, STR_FONT_FEATURE_ID_CVXX, sNumericPart };
171 else if (isStylisticSetCode(nFeatureCode))
172 aFeatureDefinition = { nFeatureCode, STR_FONT_FEATURE_ID_SSXX, sNumericPart };
173 }
174 return aFeatureDefinition;
175}
176
178{
179 if (isSpecialFeatureCode(nFeatureCode))
180 {
181 return handleSpecialFeatureCode(nFeatureCode);
182 }
183
184 if (m_aCodeToIndex.find(nFeatureCode) != m_aCodeToIndex.end())
185 {
186 size_t nIndex = m_aCodeToIndex.at(nFeatureCode);
188 }
189 return FeatureDefinition();
190}
191
193{
194 return std::find(m_aRequiredFeatures.begin(), m_aRequiredFeatures.end(), nFeatureCode)
195 != m_aRequiredFeatures.end();
196}
197
198} // end vcl::font namespace
199
200/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unordered_map< sal_uInt32, size_t > m_aCodeToIndex
FeatureDefinition getDefinition(sal_uInt32 nFeatureCode)
static FeatureDefinition handleSpecialFeatureCode(sal_uInt32 nFeatureCode)
sal_Int32 nIndex
int i
A PhysicalFontFaceCollection is created by a PhysicalFontCollection and becomes invalid when original...
constexpr uint32_t featureCode(const char sFeature[4])
Definition: Feature.hxx:20
OpenTypeFeatureDefinitionListPrivate & OpenTypeFeatureDefinitionList()