Flutter Engine
The Flutter Engine
DartTypes.h
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2
3#ifndef DartTypes_DEFINED
4#define DartTypes_DEFINED
5
8
9#include <algorithm>
10#include <iterator>
11#include <limits>
12
13namespace skia {
14namespace textlayout {
15
17
18enum class RectHeightStyle {
19 // Provide tight bounding boxes that fit heights per run.
20 kTight,
21
22 // The height of the boxes will be the maximum height of all runs in the
23 // line. All rects in the same line will be the same height.
24 kMax,
25
26 // Extends the top and/or bottom edge of the bounds to fully cover any line
27 // spacing. The top edge of each line should be the same as the bottom edge
28 // of the line above. There should be no gaps in vertical coverage given any
29 // ParagraphStyle line_height.
30 //
31 // The top and bottom of each rect will cover half of the
32 // space above and half of the space below the line.
34 // The line spacing will be added to the top of the rect.
36 // The line spacing will be added to the bottom of the rect.
38 //
39 kStrut
40};
41
42enum class RectWidthStyle {
43 // Provide tight bounding boxes that fit widths to the runs of each line
44 // independently.
45 kTight,
46
47 // Extends the width of the last rect of each line to match the position of
48 // the widest rect over all the lines.
49 kMax
50};
51
52enum class TextAlign {
53 kLeft,
54 kRight,
55 kCenter,
56 kJustify,
57 kStart,
58 kEnd,
59};
60
61enum class TextDirection {
62 kRtl,
63 kLtr,
64};
65
67 int32_t position;
69
72};
73
74struct TextBox {
77
79};
80
81// -------------------------------------------------------------------
82// --- Reversed iterable
83
84template<typename C, typename UnaryFunction>
85UnaryFunction directional_for_each(C& c, bool forwards, UnaryFunction f) {
86 return forwards
87 ? std::for_each(std::begin(c), std::end(c), f)
88 : std::for_each(std::rbegin(c), std::rend(c), f);
89}
90
92template <typename T> struct SkRange {
93 SkRange() : start(), end() {}
94 SkRange(T s, T e) : start(s), end(e) {}
95
96 using SignedT = std::make_signed_t<T>;
97
99
100 bool operator==(const SkRange<T>& other) const {
101 return start == other.start && end == other.end;
102 }
103
104 T width() const { return end - start; }
105
107 start += delta;
108 end += delta;
109 }
110
111 bool contains(SkRange<size_t> other) const {
112 return start <= other.start && end >= other.end;
113 }
114
115 bool intersects(SkRange<size_t> other) const {
116 return std::max(start, other.start) <= std::min(end, other.end);
117 }
118
120 return SkRange<size_t>(std::max(start, other.start), std::min(end, other.end));
121 }
122
123 bool empty() const {
124 return start == EMPTY_INDEX && end == EMPTY_INDEX;
125 }
126};
127
129
130
131enum class TextBaseline {
132 kAlphabetic,
133 kIdeographic,
134};
135
137 kAll = 0x0,
140 kDisableAll = 0x1 | 0x2,
141};
142
143enum class LineMetricStyle : uint8_t {
144 // Use ascent, descent, etc from a fixed baseline.
146 // Use ascent, descent, etc like css with the leading split and with height adjustments
147 CSS
148};
149
150} // namespace textlayout
151} // namespace skia
152
153#endif // DartTypes_DEFINED
static const char * begin(const StringSlice &s)
Definition: editor.cpp:252
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
struct MyStruct s
struct MyStruct a[10]
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
Definition: dart.idl:550
const size_t EMPTY_INDEX
Definition: DartTypes.h:91
UnaryFunction directional_for_each(C &c, bool forwards, UnaryFunction f)
Definition: DartTypes.h:85
const SkRange< size_t > EMPTY_RANGE
Definition: DartTypes.h:128
Definition: DartTypes.h:13
#define T
Definition: precompiler.cc:65
PositionWithAffinity(int32_t p, Affinity a)
Definition: DartTypes.h:71
bool intersects(SkRange< size_t > other) const
Definition: DartTypes.h:115
SkRange< size_t > intersection(SkRange< size_t > other) const
Definition: DartTypes.h:119
std::make_signed_t< T > SignedT
Definition: DartTypes.h:96
bool operator==(const SkRange< T > &other) const
Definition: DartTypes.h:100
bool contains(SkRange< size_t > other) const
Definition: DartTypes.h:111
void Shift(SignedT delta)
Definition: DartTypes.h:106
TextBox(SkRect r, TextDirection d)
Definition: DartTypes.h:78
TextDirection direction
Definition: DartTypes.h:76