Seigo Nonaka | 667b69a | 2018-08-31 12:28:14 -0700 | [diff] [blame] | 1 | /* |
| 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 Nonaka | e9e637d | 2018-11-26 22:12:23 -0800 | [diff] [blame] | 27 | * \code{.cpp} |
Seigo Nonaka | 667b69a | 2018-08-31 12:28:14 -0700 | [diff] [blame] | 28 | * 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 Nonaka | e9e637d | 2018-11-26 22:12:23 -0800 | [diff] [blame] | 53 | * \endcode |
Seigo Nonaka | 667b69a | 2018-08-31 12:28:14 -0700 | [diff] [blame] | 54 | * |
| 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 Nonaka | cb88a65 | 2019-03-29 14:22:49 -0700 | [diff] [blame] | 65 | #include <android/font.h> |
| 66 | |
Seigo Nonaka | 667b69a | 2018-08-31 12:28:14 -0700 | [diff] [blame] | 67 | /****************************************************************** |
| 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 Nonaka | 667b69a | 2018-08-31 12:28:14 -0700 | [diff] [blame] | 87 | /** |
| 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 | */ |
| 93 | struct ASystemFontIterator; |
| 94 | |
| 95 | /** |
Seigo Nonaka | 667b69a | 2018-08-31 12:28:14 -0700 | [diff] [blame] | 96 | * 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 | */ |
| 102 | ASystemFontIterator* _Nullable ASystemFontIterator_open() __INTRODUCED_IN(29); |
| 103 | |
| 104 | /** |
| 105 | * Close an opened system font iterator, freeing any related resources. |
| 106 | * |
Seigo Nonaka | e9e637d | 2018-11-26 22:12:23 -0800 | [diff] [blame] | 107 | * \param iterator a pointer of an iterator for the system fonts. Do nothing if NULL is passed. |
Seigo Nonaka | 667b69a | 2018-08-31 12:28:14 -0700 | [diff] [blame] | 108 | */ |
| 109 | void 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 Nonaka | 77e562b | 2018-10-30 12:26:07 -0700 | [diff] [blame] | 115 | * \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 Nonaka | 667b69a | 2018-08-31 12:28:14 -0700 | [diff] [blame] | 117 | */ |
Seigo Nonaka | cb88a65 | 2019-03-29 14:22:49 -0700 | [diff] [blame] | 118 | AFont* _Nullable ASystemFontIterator_next(ASystemFontIterator* _Nonnull iterator) __INTRODUCED_IN(29); |
Seigo Nonaka | 667b69a | 2018-08-31 12:28:14 -0700 | [diff] [blame] | 119 | |
| 120 | #endif // __ANDROID_API__ >= 29 |
| 121 | |
| 122 | __END_DECLS |
| 123 | |
| 124 | #endif // ANDROID_SYSTEM_FONTS_H |