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