blob: 3facf8261747176a062f1e7d02e27627db6501f3 [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/**
18 * @file system_fonts.h
19 * @brief Provides the system font configurations.
20 *
21 * These APIs provides the list of system installed font files with additional metadata about the
22 * font.
23 *
24 * The ASystemFontIterator_open method will give you an iterator which can iterate all system
25 * installed font files as shown in the following example.
26 *
Seigo Nonakae9e637d2018-11-26 22:12:23 -080027 * \code{.cpp}
Seigo Nonaka667b69a2018-08-31 12:28:14 -070028 * ASystemFontIterator* iterator = ASystemFontIterator_open();
29 * ASystemFont* font = NULL;
30 *
31 * while ((font = ASystemFontIterator_next(iterator)) != nullptr) {
32 * // Look if the font is your desired one.
33 * if (ASystemFont_getWeight(font) == 400 && !ASystemFont_isItalic(font)
34 * && ASystemFont_getLocale(font) == NULL) {
35 * break;
36 * }
37 * ASystemFont_close(font);
38 * }
39 * ASystemFontIterator_close(iterator);
40 *
41 * int fd = open(ASystemFont_getFontFilePath(font), O_RDONLY);
42 * int collectionIndex = ASystemFont_getCollectionINdex(font);
43 * std::vector<std::pair<uint32_t, float>> variationSettings;
44 * for (size_t i = 0; i < ASystemFont_getAxisCount(font); ++i) {
45 * variationSettings.push_back(std::make_pair(
46 * ASystemFont_getAxisTag(font, i),
47 * ASystemFont_getAxisValue(font, i)));
48 * }
49 * ASystemFont_close(font);
50 *
51 * // Use this font for your text rendering engine.
52 *
Seigo Nonakae9e637d2018-11-26 22:12:23 -080053 * \endcode
Seigo Nonaka667b69a2018-08-31 12:28:14 -070054 *
55 * Available since API level 29.
56 */
57
58#ifndef ANDROID_SYSTEM_FONTS_H
59#define ANDROID_SYSTEM_FONTS_H
60
61#include <stdbool.h>
62#include <stddef.h>
63#include <sys/cdefs.h>
64
Seigo Nonakacb88a652019-03-29 14:22:49 -070065#include <android/font.h>
66
Seigo Nonaka667b69a2018-08-31 12:28:14 -070067/******************************************************************
68 *
69 * IMPORTANT NOTICE:
70 *
71 * This file is part of Android's set of stable system headers
72 * exposed by the Android NDK (Native Development Kit).
73 *
74 * Third-party source AND binary code relies on the definitions
75 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
76 *
77 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
78 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
79 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
80 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
81 */
82
83__BEGIN_DECLS
84
85#if __ANDROID_API__ >= 29
86
Seigo Nonaka667b69a2018-08-31 12:28:14 -070087/**
88 * ASystemFontIterator provides access to the system font configuration.
89 *
90 * ASystemFontIterator is an iterator for all available system font settings.
91 * This iterator is not a thread-safe object. Do not pass this iterator to other threads.
92 */
93struct ASystemFontIterator;
94
95/**
Seigo Nonaka667b69a2018-08-31 12:28:14 -070096 * Create a system font iterator.
97 *
98 * Use ASystemFont_close() to close the iterator.
99 *
100 * \return a pointer for a newly allocated iterator, nullptr on failure.
101 */
102ASystemFontIterator* _Nullable ASystemFontIterator_open() __INTRODUCED_IN(29);
103
104/**
105 * Close an opened system font iterator, freeing any related resources.
106 *
Seigo Nonakae9e637d2018-11-26 22:12:23 -0800107 * \param iterator a pointer of an iterator for the system fonts. Do nothing if NULL is passed.
Seigo Nonaka667b69a2018-08-31 12:28:14 -0700108 */
109void ASystemFontIterator_close(ASystemFontIterator* _Nullable iterator) __INTRODUCED_IN(29);
110
111/**
112 * Move to the next system font.
113 *
114 * \param iterator an iterator for the system fonts. Passing NULL is not allowed.
Seigo Nonaka77e562b2018-10-30 12:26:07 -0700115 * \return a font. If no more font is available, returns nullptr. You need to release the returned
116 * font by ASystemFont_close when it is no longer needed.
Seigo Nonaka667b69a2018-08-31 12:28:14 -0700117 */
Seigo Nonakacb88a652019-03-29 14:22:49 -0700118AFont* _Nullable ASystemFontIterator_next(ASystemFontIterator* _Nonnull iterator) __INTRODUCED_IN(29);
Seigo Nonaka667b69a2018-08-31 12:28:14 -0700119
120#endif // __ANDROID_API__ >= 29
121
122__END_DECLS
123
124#endif // ANDROID_SYSTEM_FONTS_H