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