xref: /aosp_15_r20/frameworks/minikin/libs/minikin/LetterSpacingUtils.h (revision 834a2baab5fdfc28e9a428ee87c7ea8f6a06a53d)
1 /*
2  * Copyright (C) 2024 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 #ifndef MINIKIN_LETTER_SPACING_UTILS_H
18 #define MINIKIN_LETTER_SPACING_UTILS_H
19 
20 #include <hb.h>
21 
22 namespace minikin {
23 
24 /**
25  * Disable certain scripts (mostly those with cursive connection) from having letterspacing
26  * applied. See https://github.com/behdad/harfbuzz/issues/64 for more details.
27  */
isLetterSpacingCapableScript(hb_script_t script)28 inline bool isLetterSpacingCapableScript(hb_script_t script) {
29     return !(script == HB_SCRIPT_ARABIC || script == HB_SCRIPT_NKO ||
30              script == HB_SCRIPT_PSALTER_PAHLAVI || script == HB_SCRIPT_MANDAIC ||
31              script == HB_SCRIPT_MONGOLIAN || script == HB_SCRIPT_PHAGS_PA ||
32              script == HB_SCRIPT_DEVANAGARI || script == HB_SCRIPT_BENGALI ||
33              script == HB_SCRIPT_GURMUKHI || script == HB_SCRIPT_MODI ||
34              script == HB_SCRIPT_SHARADA || script == HB_SCRIPT_SYLOTI_NAGRI ||
35              script == HB_SCRIPT_TIRHUTA || script == HB_SCRIPT_OGHAM);
36 }
37 
isLetterSpacingCapableCodePoint(uint32_t cp)38 inline bool isLetterSpacingCapableCodePoint(uint32_t cp) {
39     hb_script_t script = hb_unicode_script(hb_unicode_funcs_get_default(), cp);
40     return isLetterSpacingCapableScript(script);
41 }
42 
43 }  // namespace minikin
44 
45 #endif  // MINIKIN_LETTER_SPACING_UTILS_H
46