1 /*
2  * Copyright (C) 2014 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_GRAPHEME_BREAK_H
18 #define MINIKIN_GRAPHEME_BREAK_H
19 
20 #include <cstddef>
21 #include <cstdint>
22 
23 namespace minikin {
24 
25 class GraphemeBreak {
26 public:
27     // These values must be kept in sync with CURSOR_AFTER etc in Paint.java
28     enum MoveOpt { AFTER = 0, AT_OR_AFTER = 1, BEFORE = 2, AT_OR_BEFORE = 3, AT = 4 };
29 
30     // Determine whether the given offset is a grapheme break.
31     // This implementation generally follows Unicode's UTR #29 extended
32     // grapheme break, with various tweaks.
33     static bool isGraphemeBreak(const float* advances, const uint16_t* buf, size_t start,
34                                 size_t count, size_t offset);
35 
36     // Matches Android's Java API. Note, return (size_t)-1 for AT to
37     // signal non-break because unsigned return type.
38     static size_t getTextRunCursor(const float* advances, const uint16_t* buf, size_t start,
39                                    size_t count, size_t offset, MoveOpt opt);
40 };
41 
42 }  // namespace minikin
43 
44 #endif  // MINIKIN_GRAPHEME_BREAK_H
45