/src/skia/modules/skparagraph/include/DartTypes.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2019 Google LLC. |
2 | | |
3 | | #ifndef DartTypes_DEFINED |
4 | | #define DartTypes_DEFINED |
5 | | |
6 | | #include "include/core/SkRect.h" |
7 | | #include "include/core/SkTypes.h" |
8 | | |
9 | | #include <iterator> |
10 | | #include <limits> |
11 | | |
12 | | namespace skia { |
13 | | namespace textlayout { |
14 | | |
15 | | enum Affinity { kUpstream, kDownstream }; |
16 | | |
17 | | enum class RectHeightStyle { |
18 | | // Provide tight bounding boxes that fit heights per run. |
19 | | kTight, |
20 | | |
21 | | // The height of the boxes will be the maximum height of all runs in the |
22 | | // line. All rects in the same line will be the same height. |
23 | | kMax, |
24 | | |
25 | | // Extends the top and/or bottom edge of the bounds to fully cover any line |
26 | | // spacing. The top edge of each line should be the same as the bottom edge |
27 | | // of the line above. There should be no gaps in vertical coverage given any |
28 | | // ParagraphStyle line_height. |
29 | | // |
30 | | // The top and bottom of each rect will cover half of the |
31 | | // space above and half of the space below the line. |
32 | | kIncludeLineSpacingMiddle, |
33 | | // The line spacing will be added to the top of the rect. |
34 | | kIncludeLineSpacingTop, |
35 | | // The line spacing will be added to the bottom of the rect. |
36 | | kIncludeLineSpacingBottom, |
37 | | // |
38 | | kStrut |
39 | | }; |
40 | | |
41 | | enum class RectWidthStyle { |
42 | | // Provide tight bounding boxes that fit widths to the runs of each line |
43 | | // independently. |
44 | | kTight, |
45 | | |
46 | | // Extends the width of the last rect of each line to match the position of |
47 | | // the widest rect over all the lines. |
48 | | kMax |
49 | | }; |
50 | | |
51 | | enum class TextAlign { |
52 | | kLeft, |
53 | | kRight, |
54 | | kCenter, |
55 | | kJustify, |
56 | | kStart, |
57 | | kEnd, |
58 | | }; |
59 | | |
60 | | enum class TextDirection { |
61 | | kRtl, |
62 | | kLtr, |
63 | | }; |
64 | | |
65 | | struct PositionWithAffinity { |
66 | | int32_t position; |
67 | | Affinity affinity; |
68 | | |
69 | 0 | PositionWithAffinity() : position(0), affinity(kDownstream) {} |
70 | 0 | PositionWithAffinity(int32_t p, Affinity a) : position(p), affinity(a) {} |
71 | | }; |
72 | | |
73 | | struct TextBox { |
74 | | SkRect rect; |
75 | | TextDirection direction; |
76 | | |
77 | 0 | TextBox(SkRect r, TextDirection d) : rect(r), direction(d) {} |
78 | | }; |
79 | | |
80 | | // ------------------------------------------------------------------- |
81 | | // --- Reversed iterable |
82 | | |
83 | | template<typename C, typename UnaryFunction> |
84 | 0 | UnaryFunction directional_for_each(C& c, bool forwards, UnaryFunction f) { |
85 | 0 | return forwards |
86 | 0 | ? std::for_each(std::begin(c), std::end(c), f) |
87 | 0 | : std::for_each(std::rbegin(c), std::rend(c), f); |
88 | 0 | } Unexecuted instantiation: TextLine.cpp:skia::textlayout::TextLine::iterateThroughClustersInGlyphsOrder(bool, bool, std::__1::function<bool (skia::textlayout::Cluster const*, bool)> const&) const::$_11 skia::textlayout::directional_for_each<SkSpan<unsigned long const>, skia::textlayout::TextLine::iterateThroughClustersInGlyphsOrder(bool, bool, std::__1::function<bool (skia::textlayout::Cluster const*, bool)> const&) const::$_11>(SkSpan<unsigned long const>&, bool, skia::textlayout::TextLine::iterateThroughClustersInGlyphsOrder(bool, bool, std::__1::function<bool (skia::textlayout::Cluster const*, bool)> const&) const::$_11) Unexecuted instantiation: TextLine.cpp:skia::textlayout::TextLine::iterateThroughClustersInGlyphsOrder(bool, bool, std::__1::function<bool (skia::textlayout::Cluster const*, bool)> const&) const::$_11::operator()(unsigned long const&) const::{lambda(skia::textlayout::Cluster&)#1} skia::textlayout::directional_for_each<SkSpan<skia::textlayout::Cluster>, skia::textlayout::TextLine::iterateThroughClustersInGlyphsOrder(bool, bool, std::__1::function<bool (skia::textlayout::Cluster const*, bool)> const&) const::$_11::operator()(unsigned long const&) const::{lambda(skia::textlayout::Cluster&)#1}>(SkSpan<skia::textlayout::Cluster>&, bool, skia::textlayout::TextLine::iterateThroughClustersInGlyphsOrder(bool, bool, std::__1::function<bool (skia::textlayout::Cluster const*, bool)> const&) const::$_11::operator()(unsigned long const&) const::{lambda(skia::textlayout::Cluster&)#1}) |
89 | | |
90 | | const size_t EMPTY_INDEX = std::numeric_limits<size_t>::max(); |
91 | | template <typename T> struct SkRange { |
92 | 61.4k | SkRange() : start(), end() {} |
93 | 205k | SkRange(T s, T e) : start(s), end(e) {} |
94 | | |
95 | | T start, end; |
96 | | |
97 | 0 | bool operator==(const SkRange<T>& other) const { |
98 | 0 | return start == other.start && end == other.end; |
99 | 0 | } |
100 | | |
101 | 282k | T width() const { return end - start; } |
102 | | |
103 | | void Shift(T delta) { |
104 | | start += delta; |
105 | | end += delta; |
106 | | } |
107 | | |
108 | 0 | bool contains(SkRange<size_t> other) const { |
109 | 0 | return start <= other.start && end >= other.end; |
110 | 0 | } |
111 | | |
112 | 0 | bool intersects(SkRange<size_t> other) const { |
113 | 0 | return std::max(start, other.start) <= std::min(end, other.end); |
114 | 0 | } |
115 | | |
116 | 0 | SkRange<size_t> intersection(SkRange<size_t> other) const { |
117 | 0 | return SkRange<size_t>(std::max(start, other.start), std::min(end, other.end)); |
118 | 0 | } |
119 | | |
120 | 115k | bool empty() const { |
121 | 115k | return start == EMPTY_INDEX && end == EMPTY_INDEX; |
122 | 115k | } |
123 | | }; |
124 | | |
125 | | const SkRange<size_t> EMPTY_RANGE = SkRange<size_t>(EMPTY_INDEX, EMPTY_INDEX); |
126 | | |
127 | | |
128 | | enum class TextBaseline { |
129 | | kAlphabetic, |
130 | | kIdeographic, |
131 | | }; |
132 | | |
133 | | enum TextHeightBehavior { |
134 | | kAll = 0x0, |
135 | | kDisableFirstAscent = 0x1, |
136 | | kDisableLastDescent = 0x2, |
137 | | kDisableAll = 0x1 | 0x2, |
138 | | }; |
139 | | |
140 | | enum class LineMetricStyle : uint8_t { |
141 | | // Use ascent, descent, etc from a fixed baseline. |
142 | | Typographic, |
143 | | // Use ascent, descent, etc like css with the leading split and with height adjustments |
144 | | CSS |
145 | | }; |
146 | | |
147 | | enum class DrawOptions { |
148 | | kRecord, |
149 | | kReplay, |
150 | | kDirect |
151 | | }; |
152 | | |
153 | | } // namespace textlayout |
154 | | } // namespace skia |
155 | | |
156 | | #endif // DartTypes_DEFINED |