1/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#ifndef SkUnicode_DEFINED
8#define SkUnicode_DEFINED
9
10#include "include/core/SkTypes.h"
11#include "src/core/SkSpan.h"
12#include <vector>
13
14#if !defined(SKUNICODE_IMPLEMENTATION)
15 #define SKUNICODE_IMPLEMENTATION 0
16#endif
17
18#if !defined(SKUNICODE_API)
19 #if defined(SKSHAPER_DLL)
20 #if defined(_MSC_VER)
21 #if SKUNICODE_IMPLEMENTATION
22 #define SKUNICODE_API __declspec(dllexport)
23 #else
24 #define SKUNICODE_API __declspec(dllimport)
25 #endif
26 #else
27 #define SKUNICODE_API __attribute__((visibility("default")))
28 #endif
29 #else
30 #define SKUNICODE_API
31 #endif
32#endif
33
34namespace skia {
35
36enum class UtfFormat {
37 kUTF8,
38 kUTF16
39};
40// Bidi
41typedef size_t Position;
42typedef uint8_t BidiLevel;
43enum class Direction {
44 kLTR,
45 kRTL,
46};
47struct BidiRegion {
48 BidiRegion(Position start, Position end, BidiLevel level)
49 : start(start), end(end), level(level) { }
50 Position start;
51 Position end;
52 BidiLevel level;
53};
54// LineBreaks
55enum class LineBreakType {
56 kSoftLineBreak,
57 kHardLineBreak
58};
59struct LineBreakBefore {
60 LineBreakBefore(Position pos, LineBreakType breakType)
61 : pos(pos), breakType(breakType) { }
62 Position pos;
63 LineBreakType breakType;
64};
65// Other breaks
66enum class UBreakType {
67 kWords,
68 kGraphemes,
69 kLines
70};
71struct Range {
72 Position start;
73 Position end;
74};
75
76class SKUNICODE_API SkUnicode {
77 public:
78 typedef uint32_t ScriptID;
79 typedef uint32_t CombiningClass;
80 typedef uint32_t GeneralCategory;
81 virtual ~SkUnicode() = default;
82 // High level methods (that we actually use somewhere=SkParagraph)
83 virtual bool getBidiRegions
84 (const char utf8[], int utf8Units, Direction dir, std::vector<BidiRegion>* results) = 0;
85 virtual bool getLineBreaks
86 (const char utf8[], int utf8Units, std::vector<LineBreakBefore>* results) = 0;
87 virtual bool getWords
88 (const char utf8[], int utf8Units, std::vector<Position>* results) = 0;
89 virtual bool getGraphemes
90 (const char utf8[], int utf8Units, std::vector<Position>* results) = 0;
91 virtual bool getWhitespaces
92 (const char utf8[], int utf8Units, std::vector<Position>* results) = 0;
93
94 virtual void reorderVisual(const BidiLevel runLevels[], int levelsCount, int32_t logicalFromVisual[]) = 0;
95
96 static std::unique_ptr<SkUnicode> Make();
97};
98
99} // namespace skia
100
101#endif // SkUnicode_DEFINED
102