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