xref: /aosp_15_r20/frameworks/native/include/android/system_fonts.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2018 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker /**
18*38e8c45fSAndroid Build Coastguard Worker  * @addtogroup Font
19*38e8c45fSAndroid Build Coastguard Worker  * @{
20*38e8c45fSAndroid Build Coastguard Worker  */
21*38e8c45fSAndroid Build Coastguard Worker 
22*38e8c45fSAndroid Build Coastguard Worker /**
23*38e8c45fSAndroid Build Coastguard Worker  * @file system_fonts.h
24*38e8c45fSAndroid Build Coastguard Worker  * @brief Provides the system font configurations.
25*38e8c45fSAndroid Build Coastguard Worker  *
26*38e8c45fSAndroid Build Coastguard Worker  * These APIs provides the list of system installed font files with additional metadata about the
27*38e8c45fSAndroid Build Coastguard Worker  * font.
28*38e8c45fSAndroid Build Coastguard Worker  *
29*38e8c45fSAndroid Build Coastguard Worker  * The ASystemFontIterator_open method will give you an iterator which can iterate all system
30*38e8c45fSAndroid Build Coastguard Worker  * installed font files as shown in the following example.
31*38e8c45fSAndroid Build Coastguard Worker  *
32*38e8c45fSAndroid Build Coastguard Worker  * \code{.cpp}
33*38e8c45fSAndroid Build Coastguard Worker  *   ASystemFontIterator* iterator = ASystemFontIterator_open();
34*38e8c45fSAndroid Build Coastguard Worker  *   AFont* font = NULL;
35*38e8c45fSAndroid Build Coastguard Worker  *
36*38e8c45fSAndroid Build Coastguard Worker  *   while ((font = ASystemFontIterator_next(iterator)) != nullptr) {
37*38e8c45fSAndroid Build Coastguard Worker  *       // Look if the font is your desired one.
38*38e8c45fSAndroid Build Coastguard Worker  *       if (AFont_getWeight(font) == 400 && !AFont_isItalic(font)
39*38e8c45fSAndroid Build Coastguard Worker  *           && AFont_getLocale(font) == NULL) {
40*38e8c45fSAndroid Build Coastguard Worker  *           break;
41*38e8c45fSAndroid Build Coastguard Worker  *       }
42*38e8c45fSAndroid Build Coastguard Worker  *       AFont_close(font);
43*38e8c45fSAndroid Build Coastguard Worker  *   }
44*38e8c45fSAndroid Build Coastguard Worker  *   ASystemFontIterator_close(iterator);
45*38e8c45fSAndroid Build Coastguard Worker  *
46*38e8c45fSAndroid Build Coastguard Worker  *   int fd = open(AFont_getFontFilePath(font), O_RDONLY | O_CLOEXEC);
47*38e8c45fSAndroid Build Coastguard Worker  *   int collectionIndex = AFont_getCollectionIndex(font);
48*38e8c45fSAndroid Build Coastguard Worker  *   std::vector<std::pair<uint32_t, float>> variationSettings;
49*38e8c45fSAndroid Build Coastguard Worker  *   for (size_t i = 0; i < AFont_getAxisCount(font); ++i) {
50*38e8c45fSAndroid Build Coastguard Worker  *       variationSettings.push_back(std::make_pair(
51*38e8c45fSAndroid Build Coastguard Worker  *           AFont_getAxisTag(font, i),
52*38e8c45fSAndroid Build Coastguard Worker  *           AFont_getAxisValue(font, i)));
53*38e8c45fSAndroid Build Coastguard Worker  *   }
54*38e8c45fSAndroid Build Coastguard Worker  *   AFont_close(font);
55*38e8c45fSAndroid Build Coastguard Worker  *
56*38e8c45fSAndroid Build Coastguard Worker  *   // Use this font for your text rendering engine.
57*38e8c45fSAndroid Build Coastguard Worker  *
58*38e8c45fSAndroid Build Coastguard Worker  * \endcode
59*38e8c45fSAndroid Build Coastguard Worker  *
60*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
61*38e8c45fSAndroid Build Coastguard Worker  */
62*38e8c45fSAndroid Build Coastguard Worker 
63*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_SYSTEM_FONTS_H
64*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_SYSTEM_FONTS_H
65*38e8c45fSAndroid Build Coastguard Worker 
66*38e8c45fSAndroid Build Coastguard Worker #include <stdbool.h>
67*38e8c45fSAndroid Build Coastguard Worker #include <stddef.h>
68*38e8c45fSAndroid Build Coastguard Worker #include <sys/cdefs.h>
69*38e8c45fSAndroid Build Coastguard Worker 
70*38e8c45fSAndroid Build Coastguard Worker #include <android/font.h>
71*38e8c45fSAndroid Build Coastguard Worker 
72*38e8c45fSAndroid Build Coastguard Worker /******************************************************************
73*38e8c45fSAndroid Build Coastguard Worker  *
74*38e8c45fSAndroid Build Coastguard Worker  * IMPORTANT NOTICE:
75*38e8c45fSAndroid Build Coastguard Worker  *
76*38e8c45fSAndroid Build Coastguard Worker  *   This file is part of Android's set of stable system headers
77*38e8c45fSAndroid Build Coastguard Worker  *   exposed by the Android NDK (Native Development Kit).
78*38e8c45fSAndroid Build Coastguard Worker  *
79*38e8c45fSAndroid Build Coastguard Worker  *   Third-party source AND binary code relies on the definitions
80*38e8c45fSAndroid Build Coastguard Worker  *   here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
81*38e8c45fSAndroid Build Coastguard Worker  *
82*38e8c45fSAndroid Build Coastguard Worker  *   - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
83*38e8c45fSAndroid Build Coastguard Worker  *   - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
84*38e8c45fSAndroid Build Coastguard Worker  *   - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
85*38e8c45fSAndroid Build Coastguard Worker  *   - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
86*38e8c45fSAndroid Build Coastguard Worker  */
87*38e8c45fSAndroid Build Coastguard Worker 
88*38e8c45fSAndroid Build Coastguard Worker __BEGIN_DECLS
89*38e8c45fSAndroid Build Coastguard Worker 
90*38e8c45fSAndroid Build Coastguard Worker struct ASystemFontIterator;
91*38e8c45fSAndroid Build Coastguard Worker /**
92*38e8c45fSAndroid Build Coastguard Worker  * ASystemFontIterator provides access to the system font configuration.
93*38e8c45fSAndroid Build Coastguard Worker  *
94*38e8c45fSAndroid Build Coastguard Worker  * ASystemFontIterator is an iterator for all available system font settings.
95*38e8c45fSAndroid Build Coastguard Worker  * This iterator is not a thread-safe object. Do not pass this iterator to other threads.
96*38e8c45fSAndroid Build Coastguard Worker  */
97*38e8c45fSAndroid Build Coastguard Worker typedef struct ASystemFontIterator ASystemFontIterator;
98*38e8c45fSAndroid Build Coastguard Worker 
99*38e8c45fSAndroid Build Coastguard Worker /**
100*38e8c45fSAndroid Build Coastguard Worker  * Create a system font iterator.
101*38e8c45fSAndroid Build Coastguard Worker  *
102*38e8c45fSAndroid Build Coastguard Worker  * Use ASystemFontIterator_close() to close the iterator.
103*38e8c45fSAndroid Build Coastguard Worker  *
104*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
105*38e8c45fSAndroid Build Coastguard Worker  *
106*38e8c45fSAndroid Build Coastguard Worker  * \return a pointer for a newly allocated iterator, nullptr on failure.
107*38e8c45fSAndroid Build Coastguard Worker  */
108*38e8c45fSAndroid Build Coastguard Worker ASystemFontIterator* _Nullable ASystemFontIterator_open() __INTRODUCED_IN(29);
109*38e8c45fSAndroid Build Coastguard Worker 
110*38e8c45fSAndroid Build Coastguard Worker /**
111*38e8c45fSAndroid Build Coastguard Worker  * Close an opened system font iterator, freeing any related resources.
112*38e8c45fSAndroid Build Coastguard Worker  *
113*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
114*38e8c45fSAndroid Build Coastguard Worker  *
115*38e8c45fSAndroid Build Coastguard Worker  * \param iterator a pointer of an iterator for the system fonts. Do nothing if NULL is passed.
116*38e8c45fSAndroid Build Coastguard Worker  */
117*38e8c45fSAndroid Build Coastguard Worker void ASystemFontIterator_close(ASystemFontIterator* _Nullable iterator) __INTRODUCED_IN(29);
118*38e8c45fSAndroid Build Coastguard Worker 
119*38e8c45fSAndroid Build Coastguard Worker /**
120*38e8c45fSAndroid Build Coastguard Worker  * Move to the next system font.
121*38e8c45fSAndroid Build Coastguard Worker  *
122*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
123*38e8c45fSAndroid Build Coastguard Worker  *
124*38e8c45fSAndroid Build Coastguard Worker  * \param iterator an iterator for the system fonts. Passing NULL is not allowed.
125*38e8c45fSAndroid Build Coastguard Worker  * \return a font. If no more font is available, returns nullptr. You need to release the returned
126*38e8c45fSAndroid Build Coastguard Worker  *         font with AFont_close() when it is no longer needed.
127*38e8c45fSAndroid Build Coastguard Worker  */
128*38e8c45fSAndroid Build Coastguard Worker AFont* _Nullable ASystemFontIterator_next(ASystemFontIterator* _Nonnull iterator) __INTRODUCED_IN(29);
129*38e8c45fSAndroid Build Coastguard Worker 
130*38e8c45fSAndroid Build Coastguard Worker __END_DECLS
131*38e8c45fSAndroid Build Coastguard Worker 
132*38e8c45fSAndroid Build Coastguard Worker #endif // ANDROID_SYSTEM_FONTS_H
133*38e8c45fSAndroid Build Coastguard Worker 
134*38e8c45fSAndroid Build Coastguard Worker /** @} */
135