blob: ceab164aa324448ecab0617ad781907e1ec5bc90 [file] [log] [blame]
Seigo Nonaka50692ca2018-08-31 12:27:15 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <jni.h>
18
Seigo Nonaka01709c72019-10-24 18:50:51 -070019#define LOG_TAG "SystemFont"
20
Seigo Nonakab3a7bce2019-03-29 14:24:57 -070021#include <android/font.h>
22#include <android/font_matcher.h>
Seigo Nonaka50692ca2018-08-31 12:27:15 -070023#include <android/system_fonts.h>
Sadaf Ebrahimi81a4a532023-10-04 18:05:54 +000024#include <errno.h>
25#include <fcntl.h>
26#include <hwui/MinikinSkia.h>
27#include <libxml/parser.h>
28#include <log/log.h>
29#include <minikin/FontCollection.h>
30#include <minikin/LocaleList.h>
31#include <minikin/SystemFonts.h>
32#include <sys/stat.h>
33#include <unistd.h>
Seigo Nonaka50692ca2018-08-31 12:27:15 -070034
35#include <memory>
36#include <string>
37#include <vector>
38
Seigo Nonaka50692ca2018-08-31 12:27:15 -070039struct XmlCharDeleter {
40 void operator()(xmlChar* b) { xmlFree(b); }
41};
42
43struct XmlDocDeleter {
44 void operator()(xmlDoc* d) { xmlFreeDoc(d); }
45};
46
47using XmlCharUniquePtr = std::unique_ptr<xmlChar, XmlCharDeleter>;
48using XmlDocUniquePtr = std::unique_ptr<xmlDoc, XmlDocDeleter>;
49
Seigo Nonaka01709c72019-10-24 18:50:51 -070050struct ParserState {
51 xmlNode* mFontNode = nullptr;
52 XmlCharUniquePtr mLocale;
53};
54
Seigo Nonakab3a7bce2019-03-29 14:24:57 -070055struct AFont {
Seigo Nonaka50692ca2018-08-31 12:27:15 -070056 std::string mFilePath;
Seigo Nonakab950a1f2021-04-14 19:15:16 -070057 std::optional<std::string> mLocale;
Seigo Nonaka50692ca2018-08-31 12:27:15 -070058 uint16_t mWeight;
59 bool mItalic;
60 uint32_t mCollectionIndex;
61 std::vector<std::pair<uint32_t, float>> mAxes;
Seigo Nonakab950a1f2021-04-14 19:15:16 -070062
63 bool operator==(const AFont& o) const {
64 return mFilePath == o.mFilePath && mLocale == o.mLocale && mWeight == o.mWeight &&
65 mItalic == o.mItalic && mCollectionIndex == o.mCollectionIndex && mAxes == o.mAxes;
66 }
Seigo Nonakab950a1f2021-04-14 19:15:16 -070067};
68
69struct FontHasher {
70 std::size_t operator()(const AFont& font) const {
71 std::size_t r = std::hash<std::string>{}(font.mFilePath);
72 if (font.mLocale) {
73 r = combine(r, std::hash<std::string>{}(*font.mLocale));
74 }
75 r = combine(r, std::hash<uint16_t>{}(font.mWeight));
76 r = combine(r, std::hash<uint32_t>{}(font.mCollectionIndex));
77 for (const auto& [tag, value] : font.mAxes) {
78 r = combine(r, std::hash<uint32_t>{}(tag));
79 r = combine(r, std::hash<float>{}(value));
80 }
81 return r;
82 }
83
84 std::size_t combine(std::size_t l, std::size_t r) const { return l ^ (r << 1); }
85};
86
87struct ASystemFontIterator {
88 std::vector<AFont> fonts;
89 uint32_t index;
90
91 XmlDocUniquePtr mXmlDoc;
92
93 ParserState state;
94
95 // The OEM customization XML.
96 XmlDocUniquePtr mCustomizationXmlDoc;
Seigo Nonaka50692ca2018-08-31 12:27:15 -070097};
98
Seigo Nonakab3a7bce2019-03-29 14:24:57 -070099struct AFontMatcher {
100 minikin::FontStyle mFontStyle;
101 uint32_t mLocaleListId = 0; // 0 is reserved for empty locale ID.
102 bool mFamilyVariant = AFAMILY_VARIANT_DEFAULT;
103};
104
105static_assert(static_cast<uint32_t>(AFAMILY_VARIANT_DEFAULT) ==
106 static_cast<uint32_t>(minikin::FamilyVariant::DEFAULT));
107static_assert(static_cast<uint32_t>(AFAMILY_VARIANT_COMPACT) ==
108 static_cast<uint32_t>(minikin::FamilyVariant::COMPACT));
109static_assert(static_cast<uint32_t>(AFAMILY_VARIANT_ELEGANT) ==
110 static_cast<uint32_t>(minikin::FamilyVariant::ELEGANT));
111
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700112namespace {
113
114std::string xmlTrim(const std::string& in) {
115 if (in.empty()) {
116 return in;
117 }
118 const char XML_SPACES[] = "\u0020\u000D\u000A\u0009";
119 const size_t start = in.find_first_not_of(XML_SPACES); // inclusive
120 if (start == std::string::npos) {
121 return "";
122 }
123 const size_t end = in.find_last_not_of(XML_SPACES); // inclusive
124 if (end == std::string::npos) {
125 return "";
126 }
127 return in.substr(start, end - start + 1 /* +1 since end is inclusive */);
128}
129
130const xmlChar* FAMILY_TAG = BAD_CAST("family");
131const xmlChar* FONT_TAG = BAD_CAST("font");
Seigo Nonaka01709c72019-10-24 18:50:51 -0700132const xmlChar* LOCALE_ATTR_NAME = BAD_CAST("lang");
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700133
134xmlNode* firstElement(xmlNode* node, const xmlChar* tag) {
135 for (xmlNode* child = node->children; child; child = child->next) {
136 if (xmlStrEqual(child->name, tag)) {
137 return child;
138 }
139 }
140 return nullptr;
141}
142
143xmlNode* nextSibling(xmlNode* node, const xmlChar* tag) {
144 while ((node = node->next) != nullptr) {
145 if (xmlStrEqual(node->name, tag)) {
146 return node;
147 }
148 }
149 return nullptr;
150}
151
Seigo Nonaka01709c72019-10-24 18:50:51 -0700152void copyFont(const XmlDocUniquePtr& xmlDoc, const ParserState& state, AFont* out,
Seigo Nonaka36758982018-10-01 19:06:11 -0700153 const std::string& pathPrefix) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700154 xmlNode* fontNode = state.mFontNode;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700155 XmlCharUniquePtr filePathStr(
Seigo Nonaka36758982018-10-01 19:06:11 -0700156 xmlNodeListGetString(xmlDoc.get(), fontNode->xmlChildrenNode, 1));
157 out->mFilePath = pathPrefix + xmlTrim(
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700158 std::string(filePathStr.get(), filePathStr.get() + xmlStrlen(filePathStr.get())));
159
160 const xmlChar* WEIGHT_ATTR_NAME = BAD_CAST("weight");
Seigo Nonaka36758982018-10-01 19:06:11 -0700161 XmlCharUniquePtr weightStr(xmlGetProp(fontNode, WEIGHT_ATTR_NAME));
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700162 out->mWeight = weightStr ?
163 strtol(reinterpret_cast<const char*>(weightStr.get()), nullptr, 10) : 400;
164
165 const xmlChar* STYLE_ATTR_NAME = BAD_CAST("style");
166 const xmlChar* ITALIC_ATTR_VALUE = BAD_CAST("italic");
Seigo Nonaka36758982018-10-01 19:06:11 -0700167 XmlCharUniquePtr styleStr(xmlGetProp(fontNode, STYLE_ATTR_NAME));
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700168 out->mItalic = styleStr ? xmlStrEqual(styleStr.get(), ITALIC_ATTR_VALUE) : false;
169
170 const xmlChar* INDEX_ATTR_NAME = BAD_CAST("index");
Seigo Nonaka36758982018-10-01 19:06:11 -0700171 XmlCharUniquePtr indexStr(xmlGetProp(fontNode, INDEX_ATTR_NAME));
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700172 out->mCollectionIndex = indexStr ?
173 strtol(reinterpret_cast<const char*>(indexStr.get()), nullptr, 10) : 0;
174
Seigo Nonakab950a1f2021-04-14 19:15:16 -0700175 if (state.mLocale) {
176 out->mLocale.emplace(reinterpret_cast<const char*>(state.mLocale.get()));
177 }
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700178
179 const xmlChar* TAG_ATTR_NAME = BAD_CAST("tag");
180 const xmlChar* STYLEVALUE_ATTR_NAME = BAD_CAST("stylevalue");
181 const xmlChar* AXIS_TAG = BAD_CAST("axis");
182 out->mAxes.clear();
Seigo Nonaka36758982018-10-01 19:06:11 -0700183 for (xmlNode* axis = firstElement(fontNode, AXIS_TAG); axis;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700184 axis = nextSibling(axis, AXIS_TAG)) {
185 XmlCharUniquePtr tagStr(xmlGetProp(axis, TAG_ATTR_NAME));
186 if (!tagStr || xmlStrlen(tagStr.get()) != 4) {
187 continue; // Tag value must be 4 char string
188 }
189
190 XmlCharUniquePtr styleValueStr(xmlGetProp(axis, STYLEVALUE_ATTR_NAME));
191 if (!styleValueStr) {
192 continue;
193 }
194
195 uint32_t tag =
196 static_cast<uint32_t>(tagStr.get()[0] << 24) |
197 static_cast<uint32_t>(tagStr.get()[1] << 16) |
198 static_cast<uint32_t>(tagStr.get()[2] << 8) |
199 static_cast<uint32_t>(tagStr.get()[3]);
200 float styleValue = strtod(reinterpret_cast<const char*>(styleValueStr.get()), nullptr);
201 out->mAxes.push_back(std::make_pair(tag, styleValue));
202 }
203}
204
205bool isFontFileAvailable(const std::string& filePath) {
206 std::string fullPath = filePath;
207 struct stat st = {};
208 if (stat(fullPath.c_str(), &st) != 0) {
209 return false;
210 }
211 return S_ISREG(st.st_mode);
212}
213
Seigo Nonaka01709c72019-10-24 18:50:51 -0700214bool findFirstFontNode(const XmlDocUniquePtr& doc, ParserState* state) {
Seigo Nonaka36758982018-10-01 19:06:11 -0700215 xmlNode* familySet = xmlDocGetRootElement(doc.get());
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700216 if (familySet == nullptr) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700217 return false;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700218 }
219 xmlNode* family = firstElement(familySet, FAMILY_TAG);
220 if (family == nullptr) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700221 return false;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700222 }
Seigo Nonaka01709c72019-10-24 18:50:51 -0700223 state->mLocale.reset(xmlGetProp(family, LOCALE_ATTR_NAME));
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700224
225 xmlNode* font = firstElement(family, FONT_TAG);
226 while (font == nullptr) {
227 family = nextSibling(family, FAMILY_TAG);
228 if (family == nullptr) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700229 return false;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700230 }
231 font = firstElement(family, FONT_TAG);
232 }
Seigo Nonaka01709c72019-10-24 18:50:51 -0700233 state->mFontNode = font;
234 return font != nullptr;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700235}
236
237} // namespace
238
239ASystemFontIterator* ASystemFontIterator_open() {
240 std::unique_ptr<ASystemFontIterator> ite(new ASystemFontIterator());
Seigo Nonakab950a1f2021-04-14 19:15:16 -0700241
242 std::unordered_set<AFont, FontHasher> fonts;
Kohsuke Yatoh1e62e212022-08-18 00:16:44 +0000243 minikin::SystemFonts::getFontSet(
244 [&fonts](const std::vector<std::shared_ptr<minikin::Font>>& fontSet) {
245 for (const auto& font : fontSet) {
246 std::optional<std::string> locale;
247 uint32_t localeId = font->getLocaleListId();
248 if (localeId != minikin::kEmptyLocaleListId) {
249 locale.emplace(minikin::getLocaleString(localeId));
Seigo Nonakab950a1f2021-04-14 19:15:16 -0700250 }
Kohsuke Yatoh1e62e212022-08-18 00:16:44 +0000251 std::vector<std::pair<uint32_t, float>> axes;
252 for (const auto& [tag, value] : font->typeface()->GetAxes()) {
253 axes.push_back(std::make_pair(tag, value));
254 }
255
256 fonts.insert({font->typeface()->GetFontPath(), std::move(locale),
257 font->style().weight(),
258 font->style().slant() == minikin::FontStyle::Slant::ITALIC,
259 static_cast<uint32_t>(font->typeface()->GetFontIndex()), axes});
Seigo Nonakab950a1f2021-04-14 19:15:16 -0700260 }
261 });
262
263 if (fonts.empty()) {
264 ite->mXmlDoc.reset(xmlReadFile("/system/etc/fonts.xml", nullptr, 0));
265 ite->mCustomizationXmlDoc.reset(
266 xmlReadFile("/product/etc/fonts_customization.xml", nullptr, 0));
267 } else {
268 ite->index = 0;
269 ite->fonts.assign(fonts.begin(), fonts.end());
270 }
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700271 return ite.release();
272}
273
274void ASystemFontIterator_close(ASystemFontIterator* ite) {
275 delete ite;
276}
277
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700278AFontMatcher* _Nonnull AFontMatcher_create() {
279 return new AFontMatcher();
280}
281
282void AFontMatcher_destroy(AFontMatcher* matcher) {
283 delete matcher;
284}
285
286void AFontMatcher_setStyle(
287 AFontMatcher* _Nonnull matcher,
Seigo Nonaka75b841b2018-10-30 11:39:49 -0700288 uint16_t weight,
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700289 bool italic) {
290 matcher->mFontStyle = minikin::FontStyle(
291 weight, static_cast<minikin::FontStyle::Slant>(italic));
292}
293
294void AFontMatcher_setLocales(
295 AFontMatcher* _Nonnull matcher,
296 const char* _Nonnull languageTags) {
297 matcher->mLocaleListId = minikin::registerLocaleList(languageTags);
298}
299
300void AFontMatcher_setFamilyVariant(AFontMatcher* _Nonnull matcher, uint32_t familyVariant) {
301 matcher->mFamilyVariant = familyVariant;
302}
303
304AFont* _Nonnull AFontMatcher_match(
305 const AFontMatcher* _Nonnull matcher,
306 const char* _Nonnull familyName,
Seigo Nonaka75b841b2018-10-30 11:39:49 -0700307 const uint16_t* _Nonnull text,
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700308 const uint32_t textLength,
Seigo Nonaka75b841b2018-10-30 11:39:49 -0700309 uint32_t* _Nullable runLength) {
310 std::shared_ptr<minikin::FontCollection> fc =
311 minikin::SystemFonts::findFontCollection(familyName);
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700312 std::vector<minikin::FontCollection::Run> runs = fc->itemize(
313 minikin::U16StringPiece(text, textLength),
314 matcher->mFontStyle,
315 matcher->mLocaleListId,
Seigo Nonakaddc87732019-04-05 15:20:19 -0700316 static_cast<minikin::FamilyVariant>(matcher->mFamilyVariant),
317 1 /* maxRun */);
Seigo Nonaka75b841b2018-10-30 11:39:49 -0700318
Seigo Nonakade1e0192021-05-10 00:37:40 -0700319 const std::shared_ptr<minikin::Font>& font =
320 fc->getBestFont(minikin::U16StringPiece(text, textLength), runs[0], matcher->mFontStyle)
321 .font;
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700322 std::unique_ptr<AFont> result = std::make_unique<AFont>();
Seigo Nonaka75b841b2018-10-30 11:39:49 -0700323 const android::MinikinFontSkia* minikinFontSkia =
324 reinterpret_cast<android::MinikinFontSkia*>(font->typeface().get());
325 result->mFilePath = minikinFontSkia->getFilePath();
326 result->mWeight = font->style().weight();
327 result->mItalic = font->style().slant() == minikin::FontStyle::Slant::ITALIC;
328 result->mCollectionIndex = minikinFontSkia->GetFontIndex();
329 const std::vector<minikin::FontVariation>& axes = minikinFontSkia->GetAxes();
330 result->mAxes.reserve(axes.size());
331 for (auto axis : axes) {
332 result->mAxes.push_back(std::make_pair(axis.axisTag, axis.value));
333 }
334 if (runLength != nullptr) {
335 *runLength = runs[0].end;
336 }
337 return result.release();
338}
339
Seigo Nonaka01709c72019-10-24 18:50:51 -0700340bool findNextFontNode(const XmlDocUniquePtr& xmlDoc, ParserState* state) {
341 if (state->mFontNode == nullptr) {
Seigo Nonaka36758982018-10-01 19:06:11 -0700342 if (!xmlDoc) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700343 return false; // Already at the end.
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700344 } else {
345 // First time to query font.
Seigo Nonaka01709c72019-10-24 18:50:51 -0700346 return findFirstFontNode(xmlDoc, state);
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700347 }
348 } else {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700349 xmlNode* nextNode = nextSibling(state->mFontNode, FONT_TAG);
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700350 while (nextNode == nullptr) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700351 xmlNode* family = nextSibling(state->mFontNode->parent, FAMILY_TAG);
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700352 if (family == nullptr) {
353 break;
354 }
Seigo Nonaka01709c72019-10-24 18:50:51 -0700355 state->mLocale.reset(xmlGetProp(family, LOCALE_ATTR_NAME));
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700356 nextNode = firstElement(family, FONT_TAG);
357 }
Seigo Nonaka01709c72019-10-24 18:50:51 -0700358 state->mFontNode = nextNode;
359 return nextNode != nullptr;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700360 }
361}
362
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700363AFont* ASystemFontIterator_next(ASystemFontIterator* ite) {
Seigo Nonaka36758982018-10-01 19:06:11 -0700364 LOG_ALWAYS_FATAL_IF(ite == nullptr, "nullptr has passed as iterator argument");
Seigo Nonakab950a1f2021-04-14 19:15:16 -0700365 if (!ite->fonts.empty()) {
366 if (ite->index >= ite->fonts.size()) {
367 return nullptr;
368 }
369 return new AFont(ite->fonts[ite->index++]);
370 }
371
Seigo Nonaka36758982018-10-01 19:06:11 -0700372 if (ite->mXmlDoc) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700373 if (!findNextFontNode(ite->mXmlDoc, &ite->state)) {
Seigo Nonaka36758982018-10-01 19:06:11 -0700374 // Reached end of the XML file. Continue OEM customization.
375 ite->mXmlDoc.reset();
Seigo Nonaka36758982018-10-01 19:06:11 -0700376 } else {
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700377 std::unique_ptr<AFont> font = std::make_unique<AFont>();
Seigo Nonaka01709c72019-10-24 18:50:51 -0700378 copyFont(ite->mXmlDoc, ite->state, font.get(), "/system/fonts/");
Seigo Nonaka36758982018-10-01 19:06:11 -0700379 if (!isFontFileAvailable(font->mFilePath)) {
380 return ASystemFontIterator_next(ite);
381 }
382 return font.release();
383 }
384 }
385 if (ite->mCustomizationXmlDoc) {
386 // TODO: Filter only customizationType="new-named-family"
Seigo Nonaka01709c72019-10-24 18:50:51 -0700387 if (!findNextFontNode(ite->mCustomizationXmlDoc, &ite->state)) {
Seigo Nonaka36758982018-10-01 19:06:11 -0700388 // Reached end of the XML file. Finishing
389 ite->mCustomizationXmlDoc.reset();
Seigo Nonaka36758982018-10-01 19:06:11 -0700390 return nullptr;
391 } else {
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700392 std::unique_ptr<AFont> font = std::make_unique<AFont>();
Seigo Nonaka01709c72019-10-24 18:50:51 -0700393 copyFont(ite->mCustomizationXmlDoc, ite->state, font.get(), "/product/fonts/");
Seigo Nonaka36758982018-10-01 19:06:11 -0700394 if (!isFontFileAvailable(font->mFilePath)) {
395 return ASystemFontIterator_next(ite);
396 }
397 return font.release();
398 }
399 }
400 return nullptr;
401}
402
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700403void AFont_close(AFont* font) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700404 delete font;
405}
406
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700407const char* AFont_getFontFilePath(const AFont* font) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700408 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed as font argument");
409 return font->mFilePath.c_str();
410}
411
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700412uint16_t AFont_getWeight(const AFont* font) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700413 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed as font argument");
414 return font->mWeight;
415}
416
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700417bool AFont_isItalic(const AFont* font) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700418 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed as font argument");
419 return font->mItalic;
420}
421
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700422const char* AFont_getLocale(const AFont* font) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700423 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed to font argument");
Seigo Nonaka01709c72019-10-24 18:50:51 -0700424 return font->mLocale ? font->mLocale->c_str() : nullptr;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700425}
426
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700427size_t AFont_getCollectionIndex(const AFont* font) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700428 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed to font argument");
429 return font->mCollectionIndex;
430}
431
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700432size_t AFont_getAxisCount(const AFont* font) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700433 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed to font argument");
434 return font->mAxes.size();
435}
436
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700437uint32_t AFont_getAxisTag(const AFont* font, uint32_t axisIndex) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700438 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed to font argument");
439 LOG_ALWAYS_FATAL_IF(axisIndex >= font->mAxes.size(),
440 "given axis index is out of bounds. (< %zd", font->mAxes.size());
441 return font->mAxes[axisIndex].first;
442}
443
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700444float AFont_getAxisValue(const AFont* font, uint32_t axisIndex) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700445 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed to font argument");
446 LOG_ALWAYS_FATAL_IF(axisIndex >= font->mAxes.size(),
447 "given axis index is out of bounds. (< %zd", font->mAxes.size());
448 return font->mAxes[axisIndex].second;
449}