• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
PositionWithAffinityPositionWithAffinity69     PositionWithAffinity() : position(0), affinity(kDownstream) {}
PositionWithAffinityPositionWithAffinity70     PositionWithAffinity(int32_t p, Affinity a) : position(p), affinity(a) {}
71 };
72 
73 struct TextBox {
74     SkRect rect;
75     TextDirection direction;
76 
TextBoxTextBox77     TextBox(SkRect r, TextDirection d) : rect(r), direction(d) {}
78 };
79 
80 // -------------------------------------------------------------------
81 // --- Reversed iterable
82 
83 template<typename C, typename UnaryFunction>
directional_for_each(C & c,bool forwards,UnaryFunction f)84 UnaryFunction directional_for_each(C& c, bool forwards, UnaryFunction f) {
85     return forwards
86               ? std::for_each(std::begin(c), std::end(c), f)
87               : std::for_each(std::rbegin(c), std::rend(c), f);
88 }
89 
90 const size_t EMPTY_INDEX = std::numeric_limits<size_t>::max();
91 template <typename T> struct SkRange {
SkRangeSkRange92     SkRange() : start(), end() {}
SkRangeSkRange93     SkRange(T s, T e) : start(s), end(e) {}
94 
95     T start, end;
96 
97     bool operator==(const SkRange<T>& other) const {
98         return start == other.start && end == other.end;
99     }
100 
widthSkRange101     T width() const { return end - start; }
102 
ShiftSkRange103     void Shift(T delta) {
104         start += delta;
105         end += delta;
106     }
107 
containsSkRange108     bool contains(SkRange<size_t> other) const {
109         return start <= other.start && end >= other.end;
110     }
111 
intersectsSkRange112     bool intersects(SkRange<size_t> other) const {
113         return std::max(start, other.start) <= std::min(end, other.end);
114     }
115 
intersectionSkRange116     SkRange<size_t> intersection(SkRange<size_t> other) const {
117         return SkRange<size_t>(std::max(start, other.start), std::min(end, other.end));
118     }
119 
emptySkRange120     bool empty() const {
121         return start == EMPTY_INDEX && end == EMPTY_INDEX;
122     }
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
157