• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 package android.graphics.text;
18 
19 /** @hide */
20 @android.ravenwood.annotation.RavenwoodKeepWholeClass
21 public class GraphemeBreak {
GraphemeBreak()22     private GraphemeBreak() { }
23 
24     /**
25      * Util method that checks if the offsets in given range are grapheme break.
26      *
27      * @param advances the advances of characters in the given text. It contains the font
28      *                information used by the algorithm to determine the grapheme break. It's useful
29      *                 when some character is missing in the font. For example, if the smile emoji
30      *                 "0xD83D 0xDE0A" is not found in the font and is displayed as 2 characters.
31      *                 We can't treat it as a single grapheme cluster.
32      * @param text the text to be processed.
33      * @param start the start offset of the queried range, inclusive.
34      * @param end the end offset of the queried range, exclusive.
35      * @param isGraphemeBreak the array to receive the result. The i-th element of the
36      *                       array will be set to true if the offset (start + i) is a grapheme
37      *                       break; otherwise, it will be set to false.
38      */
isGraphemeBreak(float[] advances, char[] text, int start, int end, boolean[] isGraphemeBreak)39     public static void isGraphemeBreak(float[] advances, char[] text, int start, int end,
40             boolean[] isGraphemeBreak) {
41         if (start > end) {
42             throw new IllegalArgumentException("start is greater than end: start = " + start
43                     + " end = " + end);
44         }
45         if (advances.length < end) {
46             throw new IllegalArgumentException("the length of advances is less than end"
47                     + "advances.length = " + advances.length
48                     + " end = " + end);
49         }
50         if (isGraphemeBreak.length < end - start) {
51             throw new IndexOutOfBoundsException("isGraphemeBreak doesn't have enough space to "
52                     + "receive the result, isGraphemeBreak.length: " + isGraphemeBreak.length
53                     + " needed space: " + (end - start));
54         }
55         nIsGraphemeBreak(advances, text, start, end, isGraphemeBreak);
56     }
57 
nIsGraphemeBreak(float[] advances, char[] text, int start, int end, boolean[] isGraphemeBreak)58     private static native void nIsGraphemeBreak(float[] advances, char[] text, int start, int end,
59             boolean[] isGraphemeBreak);
60 }
61