blob: 30d0c35bcbb02a2bda4e952746f9706bea6e396c [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>
24
25#include <memory>
26#include <string>
27#include <vector>
28
29#include <errno.h>
30#include <fcntl.h>
31#include <libxml/tree.h>
32#include <log/log.h>
33#include <sys/stat.h>
34#include <unistd.h>
35
Seigo Nonaka75b841b2018-10-30 11:39:49 -070036#include <hwui/MinikinSkia.h>
37#include <minikin/FontCollection.h>
38#include <minikin/LocaleList.h>
39#include <minikin/SystemFonts.h>
40
Seigo Nonaka50692ca2018-08-31 12:27:15 -070041struct XmlCharDeleter {
42 void operator()(xmlChar* b) { xmlFree(b); }
43};
44
45struct XmlDocDeleter {
46 void operator()(xmlDoc* d) { xmlFreeDoc(d); }
47};
48
49using XmlCharUniquePtr = std::unique_ptr<xmlChar, XmlCharDeleter>;
50using XmlDocUniquePtr = std::unique_ptr<xmlDoc, XmlDocDeleter>;
51
Seigo Nonaka01709c72019-10-24 18:50:51 -070052struct ParserState {
53 xmlNode* mFontNode = nullptr;
54 XmlCharUniquePtr mLocale;
55};
56
Seigo Nonakab3a7bce2019-03-29 14:24:57 -070057struct AFont {
Seigo Nonaka50692ca2018-08-31 12:27:15 -070058 std::string mFilePath;
Seigo Nonakab950a1f2021-04-14 19:15:16 -070059 std::optional<std::string> mLocale;
Seigo Nonaka50692ca2018-08-31 12:27:15 -070060 uint16_t mWeight;
61 bool mItalic;
62 uint32_t mCollectionIndex;
63 std::vector<std::pair<uint32_t, float>> mAxes;
Seigo Nonakab950a1f2021-04-14 19:15:16 -070064
65 bool operator==(const AFont& o) const {
66 return mFilePath == o.mFilePath && mLocale == o.mLocale && mWeight == o.mWeight &&
67 mItalic == o.mItalic && mCollectionIndex == o.mCollectionIndex && mAxes == o.mAxes;
68 }
69
70 AFont() = default;
71 AFont(const AFont&) = default;
72};
73
74struct FontHasher {
75 std::size_t operator()(const AFont& font) const {
76 std::size_t r = std::hash<std::string>{}(font.mFilePath);
77 if (font.mLocale) {
78 r = combine(r, std::hash<std::string>{}(*font.mLocale));
79 }
80 r = combine(r, std::hash<uint16_t>{}(font.mWeight));
81 r = combine(r, std::hash<uint32_t>{}(font.mCollectionIndex));
82 for (const auto& [tag, value] : font.mAxes) {
83 r = combine(r, std::hash<uint32_t>{}(tag));
84 r = combine(r, std::hash<float>{}(value));
85 }
86 return r;
87 }
88
89 std::size_t combine(std::size_t l, std::size_t r) const { return l ^ (r << 1); }
90};
91
92struct ASystemFontIterator {
93 std::vector<AFont> fonts;
94 uint32_t index;
95
96 XmlDocUniquePtr mXmlDoc;
97
98 ParserState state;
99
100 // The OEM customization XML.
101 XmlDocUniquePtr mCustomizationXmlDoc;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700102};
103
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700104struct AFontMatcher {
105 minikin::FontStyle mFontStyle;
106 uint32_t mLocaleListId = 0; // 0 is reserved for empty locale ID.
107 bool mFamilyVariant = AFAMILY_VARIANT_DEFAULT;
108};
109
110static_assert(static_cast<uint32_t>(AFAMILY_VARIANT_DEFAULT) ==
111 static_cast<uint32_t>(minikin::FamilyVariant::DEFAULT));
112static_assert(static_cast<uint32_t>(AFAMILY_VARIANT_COMPACT) ==
113 static_cast<uint32_t>(minikin::FamilyVariant::COMPACT));
114static_assert(static_cast<uint32_t>(AFAMILY_VARIANT_ELEGANT) ==
115 static_cast<uint32_t>(minikin::FamilyVariant::ELEGANT));
116
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700117namespace {
118
119std::string xmlTrim(const std::string& in) {
120 if (in.empty()) {
121 return in;
122 }
123 const char XML_SPACES[] = "\u0020\u000D\u000A\u0009";
124 const size_t start = in.find_first_not_of(XML_SPACES); // inclusive
125 if (start == std::string::npos) {
126 return "";
127 }
128 const size_t end = in.find_last_not_of(XML_SPACES); // inclusive
129 if (end == std::string::npos) {
130 return "";
131 }
132 return in.substr(start, end - start + 1 /* +1 since end is inclusive */);
133}
134
135const xmlChar* FAMILY_TAG = BAD_CAST("family");
136const xmlChar* FONT_TAG = BAD_CAST("font");
Seigo Nonaka01709c72019-10-24 18:50:51 -0700137const xmlChar* LOCALE_ATTR_NAME = BAD_CAST("lang");
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700138
139xmlNode* firstElement(xmlNode* node, const xmlChar* tag) {
140 for (xmlNode* child = node->children; child; child = child->next) {
141 if (xmlStrEqual(child->name, tag)) {
142 return child;
143 }
144 }
145 return nullptr;
146}
147
148xmlNode* nextSibling(xmlNode* node, const xmlChar* tag) {
149 while ((node = node->next) != nullptr) {
150 if (xmlStrEqual(node->name, tag)) {
151 return node;
152 }
153 }
154 return nullptr;
155}
156
Seigo Nonaka01709c72019-10-24 18:50:51 -0700157void copyFont(const XmlDocUniquePtr& xmlDoc, const ParserState& state, AFont* out,
Seigo Nonaka36758982018-10-01 19:06:11 -0700158 const std::string& pathPrefix) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700159 xmlNode* fontNode = state.mFontNode;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700160 XmlCharUniquePtr filePathStr(
Seigo Nonaka36758982018-10-01 19:06:11 -0700161 xmlNodeListGetString(xmlDoc.get(), fontNode->xmlChildrenNode, 1));
162 out->mFilePath = pathPrefix + xmlTrim(
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700163 std::string(filePathStr.get(), filePathStr.get() + xmlStrlen(filePathStr.get())));
164
165 const xmlChar* WEIGHT_ATTR_NAME = BAD_CAST("weight");
Seigo Nonaka36758982018-10-01 19:06:11 -0700166 XmlCharUniquePtr weightStr(xmlGetProp(fontNode, WEIGHT_ATTR_NAME));
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700167 out->mWeight = weightStr ?
168 strtol(reinterpret_cast<const char*>(weightStr.get()), nullptr, 10) : 400;
169
170 const xmlChar* STYLE_ATTR_NAME = BAD_CAST("style");
171 const xmlChar* ITALIC_ATTR_VALUE = BAD_CAST("italic");
Seigo Nonaka36758982018-10-01 19:06:11 -0700172 XmlCharUniquePtr styleStr(xmlGetProp(fontNode, STYLE_ATTR_NAME));
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700173 out->mItalic = styleStr ? xmlStrEqual(styleStr.get(), ITALIC_ATTR_VALUE) : false;
174
175 const xmlChar* INDEX_ATTR_NAME = BAD_CAST("index");
Seigo Nonaka36758982018-10-01 19:06:11 -0700176 XmlCharUniquePtr indexStr(xmlGetProp(fontNode, INDEX_ATTR_NAME));
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700177 out->mCollectionIndex = indexStr ?
178 strtol(reinterpret_cast<const char*>(indexStr.get()), nullptr, 10) : 0;
179
Seigo Nonakab950a1f2021-04-14 19:15:16 -0700180 if (state.mLocale) {
181 out->mLocale.emplace(reinterpret_cast<const char*>(state.mLocale.get()));
182 }
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700183
184 const xmlChar* TAG_ATTR_NAME = BAD_CAST("tag");
185 const xmlChar* STYLEVALUE_ATTR_NAME = BAD_CAST("stylevalue");
186 const xmlChar* AXIS_TAG = BAD_CAST("axis");
187 out->mAxes.clear();
Seigo Nonaka36758982018-10-01 19:06:11 -0700188 for (xmlNode* axis = firstElement(fontNode, AXIS_TAG); axis;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700189 axis = nextSibling(axis, AXIS_TAG)) {
190 XmlCharUniquePtr tagStr(xmlGetProp(axis, TAG_ATTR_NAME));
191 if (!tagStr || xmlStrlen(tagStr.get()) != 4) {
192 continue; // Tag value must be 4 char string
193 }
194
195 XmlCharUniquePtr styleValueStr(xmlGetProp(axis, STYLEVALUE_ATTR_NAME));
196 if (!styleValueStr) {
197 continue;
198 }
199
200 uint32_t tag =
201 static_cast<uint32_t>(tagStr.get()[0] << 24) |
202 static_cast<uint32_t>(tagStr.get()[1] << 16) |
203 static_cast<uint32_t>(tagStr.get()[2] << 8) |
204 static_cast<uint32_t>(tagStr.get()[3]);
205 float styleValue = strtod(reinterpret_cast<const char*>(styleValueStr.get()), nullptr);
206 out->mAxes.push_back(std::make_pair(tag, styleValue));
207 }
208}
209
210bool isFontFileAvailable(const std::string& filePath) {
211 std::string fullPath = filePath;
212 struct stat st = {};
213 if (stat(fullPath.c_str(), &st) != 0) {
214 return false;
215 }
216 return S_ISREG(st.st_mode);
217}
218
Seigo Nonaka01709c72019-10-24 18:50:51 -0700219bool findFirstFontNode(const XmlDocUniquePtr& doc, ParserState* state) {
Seigo Nonaka36758982018-10-01 19:06:11 -0700220 xmlNode* familySet = xmlDocGetRootElement(doc.get());
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700221 if (familySet == nullptr) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700222 return false;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700223 }
224 xmlNode* family = firstElement(familySet, FAMILY_TAG);
225 if (family == nullptr) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700226 return false;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700227 }
Seigo Nonaka01709c72019-10-24 18:50:51 -0700228 state->mLocale.reset(xmlGetProp(family, LOCALE_ATTR_NAME));
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700229
230 xmlNode* font = firstElement(family, FONT_TAG);
231 while (font == nullptr) {
232 family = nextSibling(family, FAMILY_TAG);
233 if (family == nullptr) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700234 return false;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700235 }
236 font = firstElement(family, FONT_TAG);
237 }
Seigo Nonaka01709c72019-10-24 18:50:51 -0700238 state->mFontNode = font;
239 return font != nullptr;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700240}
241
242} // namespace
243
244ASystemFontIterator* ASystemFontIterator_open() {
245 std::unique_ptr<ASystemFontIterator> ite(new ASystemFontIterator());
Seigo Nonakab950a1f2021-04-14 19:15:16 -0700246
247 std::unordered_set<AFont, FontHasher> fonts;
Kohsuke Yatoh1e62e212022-08-18 00:16:44 +0000248 minikin::SystemFonts::getFontSet(
249 [&fonts](const std::vector<std::shared_ptr<minikin::Font>>& fontSet) {
250 for (const auto& font : fontSet) {
251 std::optional<std::string> locale;
252 uint32_t localeId = font->getLocaleListId();
253 if (localeId != minikin::kEmptyLocaleListId) {
254 locale.emplace(minikin::getLocaleString(localeId));
Seigo Nonakab950a1f2021-04-14 19:15:16 -0700255 }
Kohsuke Yatoh1e62e212022-08-18 00:16:44 +0000256 std::vector<std::pair<uint32_t, float>> axes;
257 for (const auto& [tag, value] : font->typeface()->GetAxes()) {
258 axes.push_back(std::make_pair(tag, value));
259 }
260
261 fonts.insert({font->typeface()->GetFontPath(), std::move(locale),
262 font->style().weight(),
263 font->style().slant() == minikin::FontStyle::Slant::ITALIC,
264 static_cast<uint32_t>(font->typeface()->GetFontIndex()), axes});
Seigo Nonakab950a1f2021-04-14 19:15:16 -0700265 }
266 });
267
268 if (fonts.empty()) {
269 ite->mXmlDoc.reset(xmlReadFile("/system/etc/fonts.xml", nullptr, 0));
270 ite->mCustomizationXmlDoc.reset(
271 xmlReadFile("/product/etc/fonts_customization.xml", nullptr, 0));
272 } else {
273 ite->index = 0;
274 ite->fonts.assign(fonts.begin(), fonts.end());
275 }
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700276 return ite.release();
277}
278
279void ASystemFontIterator_close(ASystemFontIterator* ite) {
280 delete ite;
281}
282
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700283AFontMatcher* _Nonnull AFontMatcher_create() {
284 return new AFontMatcher();
285}
286
287void AFontMatcher_destroy(AFontMatcher* matcher) {
288 delete matcher;
289}
290
291void AFontMatcher_setStyle(
292 AFontMatcher* _Nonnull matcher,
Seigo Nonaka75b841b2018-10-30 11:39:49 -0700293 uint16_t weight,
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700294 bool italic) {
295 matcher->mFontStyle = minikin::FontStyle(
296 weight, static_cast<minikin::FontStyle::Slant>(italic));
297}
298
299void AFontMatcher_setLocales(
300 AFontMatcher* _Nonnull matcher,
301 const char* _Nonnull languageTags) {
302 matcher->mLocaleListId = minikin::registerLocaleList(languageTags);
303}
304
305void AFontMatcher_setFamilyVariant(AFontMatcher* _Nonnull matcher, uint32_t familyVariant) {
306 matcher->mFamilyVariant = familyVariant;
307}
308
309AFont* _Nonnull AFontMatcher_match(
310 const AFontMatcher* _Nonnull matcher,
311 const char* _Nonnull familyName,
Seigo Nonaka75b841b2018-10-30 11:39:49 -0700312 const uint16_t* _Nonnull text,
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700313 const uint32_t textLength,
Seigo Nonaka75b841b2018-10-30 11:39:49 -0700314 uint32_t* _Nullable runLength) {
315 std::shared_ptr<minikin::FontCollection> fc =
316 minikin::SystemFonts::findFontCollection(familyName);
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700317 std::vector<minikin::FontCollection::Run> runs = fc->itemize(
318 minikin::U16StringPiece(text, textLength),
319 matcher->mFontStyle,
320 matcher->mLocaleListId,
Seigo Nonakaddc87732019-04-05 15:20:19 -0700321 static_cast<minikin::FamilyVariant>(matcher->mFamilyVariant),
322 1 /* maxRun */);
Seigo Nonaka75b841b2018-10-30 11:39:49 -0700323
Seigo Nonakade1e0192021-05-10 00:37:40 -0700324 const std::shared_ptr<minikin::Font>& font =
325 fc->getBestFont(minikin::U16StringPiece(text, textLength), runs[0], matcher->mFontStyle)
326 .font;
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700327 std::unique_ptr<AFont> result = std::make_unique<AFont>();
Seigo Nonaka75b841b2018-10-30 11:39:49 -0700328 const android::MinikinFontSkia* minikinFontSkia =
329 reinterpret_cast<android::MinikinFontSkia*>(font->typeface().get());
330 result->mFilePath = minikinFontSkia->getFilePath();
331 result->mWeight = font->style().weight();
332 result->mItalic = font->style().slant() == minikin::FontStyle::Slant::ITALIC;
333 result->mCollectionIndex = minikinFontSkia->GetFontIndex();
334 const std::vector<minikin::FontVariation>& axes = minikinFontSkia->GetAxes();
335 result->mAxes.reserve(axes.size());
336 for (auto axis : axes) {
337 result->mAxes.push_back(std::make_pair(axis.axisTag, axis.value));
338 }
339 if (runLength != nullptr) {
340 *runLength = runs[0].end;
341 }
342 return result.release();
343}
344
Seigo Nonaka01709c72019-10-24 18:50:51 -0700345bool findNextFontNode(const XmlDocUniquePtr& xmlDoc, ParserState* state) {
346 if (state->mFontNode == nullptr) {
Seigo Nonaka36758982018-10-01 19:06:11 -0700347 if (!xmlDoc) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700348 return false; // Already at the end.
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700349 } else {
350 // First time to query font.
Seigo Nonaka01709c72019-10-24 18:50:51 -0700351 return findFirstFontNode(xmlDoc, state);
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700352 }
353 } else {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700354 xmlNode* nextNode = nextSibling(state->mFontNode, FONT_TAG);
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700355 while (nextNode == nullptr) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700356 xmlNode* family = nextSibling(state->mFontNode->parent, FAMILY_TAG);
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700357 if (family == nullptr) {
358 break;
359 }
Seigo Nonaka01709c72019-10-24 18:50:51 -0700360 state->mLocale.reset(xmlGetProp(family, LOCALE_ATTR_NAME));
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700361 nextNode = firstElement(family, FONT_TAG);
362 }
Seigo Nonaka01709c72019-10-24 18:50:51 -0700363 state->mFontNode = nextNode;
364 return nextNode != nullptr;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700365 }
366}
367
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700368AFont* ASystemFontIterator_next(ASystemFontIterator* ite) {
Seigo Nonaka36758982018-10-01 19:06:11 -0700369 LOG_ALWAYS_FATAL_IF(ite == nullptr, "nullptr has passed as iterator argument");
Seigo Nonakab950a1f2021-04-14 19:15:16 -0700370 if (!ite->fonts.empty()) {
371 if (ite->index >= ite->fonts.size()) {
372 return nullptr;
373 }
374 return new AFont(ite->fonts[ite->index++]);
375 }
376
Seigo Nonaka36758982018-10-01 19:06:11 -0700377 if (ite->mXmlDoc) {
Seigo Nonaka01709c72019-10-24 18:50:51 -0700378 if (!findNextFontNode(ite->mXmlDoc, &ite->state)) {
Seigo Nonaka36758982018-10-01 19:06:11 -0700379 // Reached end of the XML file. Continue OEM customization.
380 ite->mXmlDoc.reset();
Seigo Nonaka36758982018-10-01 19:06:11 -0700381 } else {
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700382 std::unique_ptr<AFont> font = std::make_unique<AFont>();
Seigo Nonaka01709c72019-10-24 18:50:51 -0700383 copyFont(ite->mXmlDoc, ite->state, font.get(), "/system/fonts/");
Seigo Nonaka36758982018-10-01 19:06:11 -0700384 if (!isFontFileAvailable(font->mFilePath)) {
385 return ASystemFontIterator_next(ite);
386 }
387 return font.release();
388 }
389 }
390 if (ite->mCustomizationXmlDoc) {
391 // TODO: Filter only customizationType="new-named-family"
Seigo Nonaka01709c72019-10-24 18:50:51 -0700392 if (!findNextFontNode(ite->mCustomizationXmlDoc, &ite->state)) {
Seigo Nonaka36758982018-10-01 19:06:11 -0700393 // Reached end of the XML file. Finishing
394 ite->mCustomizationXmlDoc.reset();
Seigo Nonaka36758982018-10-01 19:06:11 -0700395 return nullptr;
396 } else {
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700397 std::unique_ptr<AFont> font = std::make_unique<AFont>();
Seigo Nonaka01709c72019-10-24 18:50:51 -0700398 copyFont(ite->mCustomizationXmlDoc, ite->state, font.get(), "/product/fonts/");
Seigo Nonaka36758982018-10-01 19:06:11 -0700399 if (!isFontFileAvailable(font->mFilePath)) {
400 return ASystemFontIterator_next(ite);
401 }
402 return font.release();
403 }
404 }
405 return nullptr;
406}
407
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700408void AFont_close(AFont* font) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700409 delete font;
410}
411
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700412const char* AFont_getFontFilePath(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->mFilePath.c_str();
415}
416
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700417uint16_t AFont_getWeight(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->mWeight;
420}
421
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700422bool AFont_isItalic(const AFont* font) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700423 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed as font argument");
424 return font->mItalic;
425}
426
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700427const char* AFont_getLocale(const AFont* font) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700428 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed to font argument");
Seigo Nonaka01709c72019-10-24 18:50:51 -0700429 return font->mLocale ? font->mLocale->c_str() : nullptr;
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700430}
431
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700432size_t AFont_getCollectionIndex(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->mCollectionIndex;
435}
436
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700437size_t AFont_getAxisCount(const AFont* font) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700438 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed to font argument");
439 return font->mAxes.size();
440}
441
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700442uint32_t AFont_getAxisTag(const AFont* font, uint32_t axisIndex) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700443 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed to font argument");
444 LOG_ALWAYS_FATAL_IF(axisIndex >= font->mAxes.size(),
445 "given axis index is out of bounds. (< %zd", font->mAxes.size());
446 return font->mAxes[axisIndex].first;
447}
448
Seigo Nonakab3a7bce2019-03-29 14:24:57 -0700449float AFont_getAxisValue(const AFont* font, uint32_t axisIndex) {
Seigo Nonaka50692ca2018-08-31 12:27:15 -0700450 LOG_ALWAYS_FATAL_IF(font == nullptr, "nullptr has passed to font argument");
451 LOG_ALWAYS_FATAL_IF(axisIndex >= font->mAxes.size(),
452 "given axis index is out of bounds. (< %zd", font->mAxes.size());
453 return font->mAxes[axisIndex].second;
454}