blob: 45eb81a533d546938e926f7afe75830f8e542d65 [file] [log] [blame]
Seigo Nonakacb88a652019-03-29 14:22:49 -07001/*
2 * Copyright (C) 2019 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 Alberte4a1cab2019-06-14 14:01:20 -070019 * @{
Dan Albertc0416092019-04-16 13:20:26 -070020 */
21
22/**
Seigo Nonakacb88a652019-03-29 14:22:49 -070023 * @file font.h
24 * @brief Provides some constants used in system_fonts.h or fonts_matcher.h
25 *
26 * Available since API level 29.
27 */
28
29#ifndef ANDROID_FONT_H
30#define ANDROID_FONT_H
31
32#include <stdbool.h>
33#include <stddef.h>
Ben Wagnerffcf5b12022-10-26 21:30:12 +000034#include <stdint.h>
Seigo Nonakacb88a652019-03-29 14:22:49 -070035#include <sys/cdefs.h>
36
37/******************************************************************
38 *
39 * IMPORTANT NOTICE:
40 *
41 * This file is part of Android's set of stable system headers
42 * exposed by the Android NDK (Native Development Kit).
43 *
44 * Third-party source AND binary code relies on the definitions
45 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
46 *
47 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
48 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
49 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
50 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
51 */
52
53__BEGIN_DECLS
54
Seigo Nonakacb88a652019-03-29 14:22:49 -070055enum {
56 /** The minimum value fot the font weight value. */
57 AFONT_WEIGHT_MIN = 0,
58
59 /** A font weight value for the thin weight. */
60 AFONT_WEIGHT_THIN = 100,
61
62 /** A font weight value for the extra-light weight. */
63 AFONT_WEIGHT_EXTRA_LIGHT = 200,
64
65 /** A font weight value for the light weight. */
66 AFONT_WEIGHT_LIGHT = 300,
67
68 /** A font weight value for the normal weight. */
69 AFONT_WEIGHT_NORMAL = 400,
70
71 /** A font weight value for the medium weight. */
72 AFONT_WEIGHT_MEDIUM = 500,
73
74 /** A font weight value for the semi-bold weight. */
75 AFONT_WEIGHT_SEMI_BOLD = 600,
76
77 /** A font weight value for the bold weight. */
78 AFONT_WEIGHT_BOLD = 700,
79
80 /** A font weight value for the extra-bold weight. */
81 AFONT_WEIGHT_EXTRA_BOLD = 800,
82
83 /** A font weight value for the black weight. */
84 AFONT_WEIGHT_BLACK = 900,
85
86 /** The maximum value for the font weight value. */
87 AFONT_WEIGHT_MAX = 1000
88};
89
90/**
91 * AFont provides information of the single font configuration.
92 */
93struct AFont;
94
95/**
96 * Close an AFont.
97 *
Elliott Hughes3d70e532019-10-29 08:59:39 -070098 * Available since API level 29.
99 *
Seigo Nonakacb88a652019-03-29 14:22:49 -0700100 * \param font a font returned by ASystemFontIterator_next or AFontMatchert_match.
101 * Do nothing if NULL is passed.
102 */
103void AFont_close(AFont* _Nullable font) __INTRODUCED_IN(29);
104
105/**
106 * Return an absolute path to the current font file.
107 *
108 * Here is a list of font formats returned by this method:
109 * <ul>
110 * <li>OpenType</li>
111 * <li>OpenType Font Collection</li>
112 * <li>TrueType</li>
113 * <li>TrueType Collection</li>
114 * </ul>
115 * The file extension could be one of *.otf, *.ttf, *.otc or *.ttc.
116 *
117 * The font file returned is guaranteed to be opend with O_RDONLY.
118 * Note that the returned pointer is valid until AFont_close() is called for the given font.
119 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700120 * Available since API level 29.
121 *
Seigo Nonakacb88a652019-03-29 14:22:49 -0700122 * \param font a font object. Passing NULL is not allowed.
123 * \return a string of the font file path.
124 */
125const char* _Nonnull AFont_getFontFilePath(const AFont* _Nonnull font) __INTRODUCED_IN(29);
126
127/**
128 * Return a weight value associated with the current font.
129 *
130 * The weight values are positive and less than or equal to 1000.
131 * Here are pairs of the common names and their values.
132 * <p>
133 * <table>
134 * <tr>
135 * <th align="center">Value</th>
136 * <th align="center">Name</th>
137 * <th align="center">NDK Definition</th>
138 * </tr>
139 * <tr>
140 * <td align="center">100</td>
141 * <td align="center">Thin</td>
142 * <td align="center">{@link AFONT_WEIGHT_THIN}</td>
143 * </tr>
144 * <tr>
145 * <td align="center">200</td>
146 * <td align="center">Extra Light (Ultra Light)</td>
147 * <td align="center">{@link AFONT_WEIGHT_EXTRA_LIGHT}</td>
148 * </tr>
149 * <tr>
150 * <td align="center">300</td>
151 * <td align="center">Light</td>
152 * <td align="center">{@link AFONT_WEIGHT_LIGHT}</td>
153 * </tr>
154 * <tr>
155 * <td align="center">400</td>
156 * <td align="center">Normal (Regular)</td>
157 * <td align="center">{@link AFONT_WEIGHT_NORMAL}</td>
158 * </tr>
159 * <tr>
160 * <td align="center">500</td>
161 * <td align="center">Medium</td>
162 * <td align="center">{@link AFONT_WEIGHT_MEDIUM}</td>
163 * </tr>
164 * <tr>
165 * <td align="center">600</td>
166 * <td align="center">Semi Bold (Demi Bold)</td>
167 * <td align="center">{@link AFONT_WEIGHT_SEMI_BOLD}</td>
168 * </tr>
169 * <tr>
170 * <td align="center">700</td>
171 * <td align="center">Bold</td>
172 * <td align="center">{@link AFONT_WEIGHT_BOLD}</td>
173 * </tr>
174 * <tr>
175 * <td align="center">800</td>
176 * <td align="center">Extra Bold (Ultra Bold)</td>
177 * <td align="center">{@link AFONT_WEIGHT_EXTRA_BOLD}</td>
178 * </tr>
179 * <tr>
180 * <td align="center">900</td>
181 * <td align="center">Black (Heavy)</td>
182 * <td align="center">{@link AFONT_WEIGHT_BLACK}</td>
183 * </tr>
184 * </table>
185 * </p>
186 * Note that the weight value may fall in between above values, e.g. 250 weight.
187 *
188 * For more information about font weight, read [OpenType usWeightClass](https://docs.microsoft.com/en-us/typography/opentype/spec/os2#usweightclass)
189 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700190 * Available since API level 29.
191 *
Seigo Nonakacb88a652019-03-29 14:22:49 -0700192 * \param font a font object. Passing NULL is not allowed.
gfan7fed43d2021-04-06 18:50:06 -0700193 * \return a positive integer less than or equal to {@link AFONT_WEIGHT_MAX} is returned.
Seigo Nonakacb88a652019-03-29 14:22:49 -0700194 */
195uint16_t AFont_getWeight(const AFont* _Nonnull font) __INTRODUCED_IN(29);
196
197/**
198 * Return true if the current font is italic, otherwise returns false.
199 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700200 * Available since API level 29.
201 *
Seigo Nonakacb88a652019-03-29 14:22:49 -0700202 * \param font a font object. Passing NULL is not allowed.
203 * \return true if italic, otherwise false.
204 */
205bool AFont_isItalic(const AFont* _Nonnull font) __INTRODUCED_IN(29);
206
207/**
208 * Return a IETF BCP47 compliant language tag associated with the current font.
209 *
210 * For information about IETF BCP47, read [Locale.forLanguageTag(java.lang.String)](https://developer.android.com/reference/java/util/Locale.html#forLanguageTag(java.lang.String)")
211 *
212 * Note that the returned pointer is valid until AFont_close() is called.
213 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700214 * Available since API level 29.
215 *
Seigo Nonakacb88a652019-03-29 14:22:49 -0700216 * \param font a font object. Passing NULL is not allowed.
217 * \return a IETF BCP47 compliant language tag or nullptr if not available.
218 */
219const char* _Nullable AFont_getLocale(const AFont* _Nonnull font) __INTRODUCED_IN(29);
220
221/**
222 * Return a font collection index value associated with the current font.
223 *
224 * In case the target font file is a font collection (e.g. .ttc or .otc), this
225 * returns a non-negative value as an font offset in the collection. This
226 * always returns 0 if the target font file is a regular font.
227 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700228 * Available since API level 29.
229 *
Seigo Nonakacb88a652019-03-29 14:22:49 -0700230 * \param font a font object. Passing NULL is not allowed.
231 * \return a font collection index.
232 */
233size_t AFont_getCollectionIndex(const AFont* _Nonnull font) __INTRODUCED_IN(29);
234
235/**
236 * Return a count of font variation settings associated with the current font
237 *
238 * The font variation settings are provided as multiple tag-values pairs.
239 *
240 * For example, bold italic font may have following font variation settings:
241 * 'wght' 700, 'slnt' -12
242 * In this case, AFont_getAxisCount returns 2 and AFont_getAxisTag
243 * and AFont_getAxisValue will return following values.
244 * \code{.cpp}
gfan7fed43d2021-04-06 18:50:06 -0700245 * AFont* font = ASystemFontIterator_next(ite);
Seigo Nonakacb88a652019-03-29 14:22:49 -0700246 *
247 * // Returns the number of axes
248 * AFont_getAxisCount(font); // Returns 2
249 *
250 * // Returns the tag-value pair for the first axis.
251 * AFont_getAxisTag(font, 0); // Returns 'wght'(0x77676874)
252 * AFont_getAxisValue(font, 0); // Returns 700.0
253 *
254 * // Returns the tag-value pair for the second axis.
255 * AFont_getAxisTag(font, 1); // Returns 'slnt'(0x736c6e74)
256 * AFont_getAxisValue(font, 1); // Returns -12.0
257 * \endcode
258 *
259 * For more information about font variation settings, read [Font Variations Table](https://docs.microsoft.com/en-us/typography/opentype/spec/fvar)
260 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700261 * Available since API level 29.
262 *
Seigo Nonakacb88a652019-03-29 14:22:49 -0700263 * \param font a font object. Passing NULL is not allowed.
264 * \return a number of font variation settings.
265 */
266size_t AFont_getAxisCount(const AFont* _Nonnull font) __INTRODUCED_IN(29);
267
268
269/**
270 * Return an OpenType axis tag associated with the current font.
271 *
272 * See AFont_getAxisCount for more details.
273 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700274 * Available since API level 29.
275 *
Seigo Nonakacb88a652019-03-29 14:22:49 -0700276 * \param font a font object. Passing NULL is not allowed.
277 * \param axisIndex an index to the font variation settings. Passing value larger than or
278 * equal to {@link AFont_getAxisCount} is not allowed.
279 * \return an OpenType axis tag value for the given font variation setting.
280 */
281uint32_t AFont_getAxisTag(const AFont* _Nonnull font, uint32_t axisIndex)
282 __INTRODUCED_IN(29);
283
284/**
285 * Return an OpenType axis value associated with the current font.
286 *
287 * See AFont_getAxisCount for more details.
288 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700289 * Available since API level 29.
290 *
Seigo Nonakacb88a652019-03-29 14:22:49 -0700291 * \param font a font object. Passing NULL is not allowed.
292 * \param axisIndex an index to the font variation settings. Passing value larger than or
gfan7fed43d2021-04-06 18:50:06 -0700293 * equal to {@link AFont_getAxisCount} is not allowed.
Seigo Nonakacb88a652019-03-29 14:22:49 -0700294 * \return a float value for the given font variation setting.
295 */
296float AFont_getAxisValue(const AFont* _Nonnull font, uint32_t axisIndex)
297 __INTRODUCED_IN(29);
298
Seigo Nonakacb88a652019-03-29 14:22:49 -0700299__END_DECLS
300
301#endif // ANDROID_FONT_H
Dan Albertc0416092019-04-16 13:20:26 -0700302
303/** @} */