blob: 2d3a2148ae3797025f1bd7108ca60aa8db441fd9 [file] [log] [blame]
Seigo Nonaka667b69a2018-08-31 12:28:14 -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/**
Dan Albertc0416092019-04-16 13:20:26 -070018 * @addtogroup Font
Dan Albert12abc192019-06-18 15:13:05 -070019 * @{
Dan Albertc0416092019-04-16 13:20:26 -070020 */
21
22/**
Seigo Nonaka667b69a2018-08-31 12:28:14 -070023 * @file system_fonts.h
24 * @brief Provides the system font configurations.
25 *
26 * These APIs provides the list of system installed font files with additional metadata about the
27 * font.
28 *
29 * The ASystemFontIterator_open method will give you an iterator which can iterate all system
30 * installed font files as shown in the following example.
31 *
Seigo Nonakae9e637d2018-11-26 22:12:23 -080032 * \code{.cpp}
Seigo Nonaka667b69a2018-08-31 12:28:14 -070033 * ASystemFontIterator* iterator = ASystemFontIterator_open();
Elliott Hughes7cbcabf2024-06-24 12:25:40 +000034 * AFont* font = NULL;
Seigo Nonaka667b69a2018-08-31 12:28:14 -070035 *
36 * while ((font = ASystemFontIterator_next(iterator)) != nullptr) {
37 * // Look if the font is your desired one.
Elliott Hughes7cbcabf2024-06-24 12:25:40 +000038 * if (AFont_getWeight(font) == 400 && !AFont_isItalic(font)
39 * && AFont_getLocale(font) == NULL) {
Seigo Nonaka667b69a2018-08-31 12:28:14 -070040 * break;
41 * }
Elliott Hughes7cbcabf2024-06-24 12:25:40 +000042 * AFont_close(font);
Seigo Nonaka667b69a2018-08-31 12:28:14 -070043 * }
44 * ASystemFontIterator_close(iterator);
45 *
Elliott Hughes7cbcabf2024-06-24 12:25:40 +000046 * int fd = open(AFont_getFontFilePath(font), O_RDONLY | O_CLOEXEC);
47 * int collectionIndex = AFont_getCollectionIndex(font);
Seigo Nonaka667b69a2018-08-31 12:28:14 -070048 * std::vector<std::pair<uint32_t, float>> variationSettings;
Elliott Hughes7cbcabf2024-06-24 12:25:40 +000049 * for (size_t i = 0; i < AFont_getAxisCount(font); ++i) {
Seigo Nonaka667b69a2018-08-31 12:28:14 -070050 * variationSettings.push_back(std::make_pair(
Elliott Hughes7cbcabf2024-06-24 12:25:40 +000051 * AFont_getAxisTag(font, i),
52 * AFont_getAxisValue(font, i)));
Seigo Nonaka667b69a2018-08-31 12:28:14 -070053 * }
Elliott Hughes7cbcabf2024-06-24 12:25:40 +000054 * AFont_close(font);
Seigo Nonaka667b69a2018-08-31 12:28:14 -070055 *
56 * // Use this font for your text rendering engine.
57 *
Seigo Nonakae9e637d2018-11-26 22:12:23 -080058 * \endcode
Seigo Nonaka667b69a2018-08-31 12:28:14 -070059 *
60 * Available since API level 29.
61 */
62
63#ifndef ANDROID_SYSTEM_FONTS_H
64#define ANDROID_SYSTEM_FONTS_H
65
66#include <stdbool.h>
67#include <stddef.h>
68#include <sys/cdefs.h>
69
Seigo Nonakacb88a652019-03-29 14:22:49 -070070#include <android/font.h>
71
Seigo Nonaka667b69a2018-08-31 12:28:14 -070072/******************************************************************
73 *
74 * IMPORTANT NOTICE:
75 *
76 * This file is part of Android's set of stable system headers
77 * exposed by the Android NDK (Native Development Kit).
78 *
79 * Third-party source AND binary code relies on the definitions
80 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
81 *
82 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
83 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
84 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
85 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
86 */
87
88__BEGIN_DECLS
89
Ben Wagner25580412022-10-31 19:18:31 +000090struct ASystemFontIterator;
Seigo Nonaka667b69a2018-08-31 12:28:14 -070091/**
92 * ASystemFontIterator provides access to the system font configuration.
93 *
94 * ASystemFontIterator is an iterator for all available system font settings.
95 * This iterator is not a thread-safe object. Do not pass this iterator to other threads.
96 */
Ben Wagner25580412022-10-31 19:18:31 +000097typedef struct ASystemFontIterator ASystemFontIterator;
Seigo Nonaka667b69a2018-08-31 12:28:14 -070098
99/**
Seigo Nonaka667b69a2018-08-31 12:28:14 -0700100 * Create a system font iterator.
101 *
Elliott Hughes7cbcabf2024-06-24 12:25:40 +0000102 * Use ASystemFontIterator_close() to close the iterator.
Seigo Nonaka667b69a2018-08-31 12:28:14 -0700103 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700104 * Available since API level 29.
105 *
Seigo Nonaka667b69a2018-08-31 12:28:14 -0700106 * \return a pointer for a newly allocated iterator, nullptr on failure.
107 */
108ASystemFontIterator* _Nullable ASystemFontIterator_open() __INTRODUCED_IN(29);
109
110/**
111 * Close an opened system font iterator, freeing any related resources.
112 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700113 * Available since API level 29.
114 *
Seigo Nonakae9e637d2018-11-26 22:12:23 -0800115 * \param iterator a pointer of an iterator for the system fonts. Do nothing if NULL is passed.
Seigo Nonaka667b69a2018-08-31 12:28:14 -0700116 */
117void ASystemFontIterator_close(ASystemFontIterator* _Nullable iterator) __INTRODUCED_IN(29);
118
119/**
120 * Move to the next system font.
121 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700122 * Available since API level 29.
123 *
Seigo Nonaka667b69a2018-08-31 12:28:14 -0700124 * \param iterator an iterator for the system fonts. Passing NULL is not allowed.
Seigo Nonaka77e562b2018-10-30 12:26:07 -0700125 * \return a font. If no more font is available, returns nullptr. You need to release the returned
Elliott Hughes7cbcabf2024-06-24 12:25:40 +0000126 * font with AFont_close() when it is no longer needed.
Seigo Nonaka667b69a2018-08-31 12:28:14 -0700127 */
Seigo Nonakacb88a652019-03-29 14:22:49 -0700128AFont* _Nullable ASystemFontIterator_next(ASystemFontIterator* _Nonnull iterator) __INTRODUCED_IN(29);
Seigo Nonaka667b69a2018-08-31 12:28:14 -0700129
Seigo Nonaka667b69a2018-08-31 12:28:14 -0700130__END_DECLS
131
132#endif // ANDROID_SYSTEM_FONTS_H
Dan Albertc0416092019-04-16 13:20:26 -0700133
134/** @} */