blob: 94484eaf54cef1c06702137919aec78a5592cdd0 [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();
34 * ASystemFont* font = NULL;
35 *
36 * while ((font = ASystemFontIterator_next(iterator)) != nullptr) {
37 * // Look if the font is your desired one.
38 * if (ASystemFont_getWeight(font) == 400 && !ASystemFont_isItalic(font)
39 * && ASystemFont_getLocale(font) == NULL) {
40 * break;
41 * }
42 * ASystemFont_close(font);
43 * }
44 * ASystemFontIterator_close(iterator);
45 *
46 * int fd = open(ASystemFont_getFontFilePath(font), O_RDONLY);
47 * int collectionIndex = ASystemFont_getCollectionINdex(font);
48 * std::vector<std::pair<uint32_t, float>> variationSettings;
49 * for (size_t i = 0; i < ASystemFont_getAxisCount(font); ++i) {
50 * variationSettings.push_back(std::make_pair(
51 * ASystemFont_getAxisTag(font, i),
52 * ASystemFont_getAxisValue(font, i)));
53 * }
54 * ASystemFont_close(font);
55 *
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 *
102 * Use ASystemFont_close() to close the iterator.
103 *
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
126 * font by ASystemFont_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/** @} */