• 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 
8 namespace skia {
9 namespace textlayout {
10 
11 enum Affinity { kUpstream, kDownstream };
12 
13 enum class RectHeightStyle {
14     // Provide tight bounding boxes that fit heights per run.
15     kTight,
16 
17     // The height of the boxes will be the maximum height of all runs in the
18     // line. All rects in the same line will be the same height.
19     kMax,
20 
21     // Extends the top and/or bottom edge of the bounds to fully cover any line
22     // spacing. The top edge of each line should be the same as the bottom edge
23     // of the line above. There should be no gaps in vertical coverage given any
24     // ParagraphStyle line_height.
25     //
26     // The top and bottom of each rect will cover half of the
27     // space above and half of the space below the line.
28     kIncludeLineSpacingMiddle,
29     // The line spacing will be added to the top of the rect.
30     kIncludeLineSpacingTop,
31     // The line spacing will be added to the bottom of the rect.
32     kIncludeLineSpacingBottom,
33     //
34     kStrut
35 };
36 
37 enum class RectWidthStyle {
38     // Provide tight bounding boxes that fit widths to the runs of each line
39     // independently.
40     kTight,
41 
42     // Extends the width of the last rect of each line to match the position of
43     // the widest rect over all the lines.
44     kMax
45 };
46 
47 enum class TextAlign {
48     kLeft,
49     kRight,
50     kCenter,
51     kJustify,
52     kStart,
53     kEnd,
54 };
55 
56 enum class TextDirection {
57     kRtl,
58     kLtr,
59 };
60 
61 struct PositionWithAffinity {
62     int32_t position;
63     Affinity affinity;
64 
PositionWithAffinityPositionWithAffinity65     PositionWithAffinity(int32_t p, Affinity a) : position(p), affinity(a) {}
66 };
67 
68 struct TextBox {
69     SkRect rect;
70     TextDirection direction;
71 
TextBoxTextBox72     TextBox(SkRect r, TextDirection d) : rect(r), direction(d) {}
73 };
74 
75 const size_t EMPTY_INDEX = std::numeric_limits<size_t>::max();
76 template <typename T> struct SkRange {
SkRangeSkRange77     SkRange() : start(), end() {}
SkRangeSkRange78     SkRange(T s, T e) : start(s), end(e) {}
79 
80     T start, end;
81 
82     bool operator==(const SkRange<T>& other) const {
83         return start == other.start && end == other.end;
84     }
85 
widthSkRange86     T width() const { return end - start; }
87 
ShiftSkRange88     void Shift(T delta) {
89         start += delta;
90         end += delta;
91     }
92 
containsSkRange93     bool contains(SkRange<size_t> other) const {
94         return start <= other.start && end >= other.end;
95     }
96 
intersectsSkRange97     bool intersects(SkRange<size_t> other) const {
98         return SkTMax(start, other.start) <= SkTMin(end, other.end);
99     }
100 
emptySkRange101     bool empty() const {
102         return start == EMPTY_INDEX && end == EMPTY_INDEX;
103     }
104 };
105 
106 const SkRange<size_t> EMPTY_RANGE = SkRange<size_t>(EMPTY_INDEX, EMPTY_INDEX);
107 
108 
109 enum class TextBaseline {
110     kAlphabetic,
111     kIdeographic,
112 };
113 }  // namespace textlayout
114 }  // namespace skia
115 
116 #endif  // DartTypes_DEFINED
117