|
| 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 | + |
| 35 | +enum class RectWidthStyle { |
| 36 | + // Provide tight bounding boxes that fit widths to the runs of each line |
| 37 | + // independently. |
| 38 | + kTight, |
| 39 | + |
| 40 | + // Extends the width of the last rect of each line to match the position of |
| 41 | + // the widest rect over all the lines. |
| 42 | + kMax |
| 43 | +}; |
| 44 | + |
| 45 | +enum class TextAlign { |
| 46 | + kLeft, |
| 47 | + kRight, |
| 48 | + kCenter, |
| 49 | + kJustify, |
| 50 | + kStart, |
| 51 | + kEnd, |
| 52 | +}; |
| 53 | + |
| 54 | +enum class TextDirection { |
| 55 | + kRtl, |
| 56 | + kLtr, |
| 57 | +}; |
| 58 | + |
| 59 | +struct PositionWithAffinity { |
| 60 | + int32_t position; |
| 61 | + Affinity affinity; |
| 62 | + |
| 63 | + PositionWithAffinity(int32_t p, Affinity a) : position(p), affinity(a) {} |
| 64 | +}; |
| 65 | + |
| 66 | +struct TextBox { |
| 67 | + SkRect rect; |
| 68 | + TextDirection direction; |
| 69 | + |
| 70 | + TextBox(SkRect r, TextDirection d) : rect(r), direction(d) {} |
| 71 | +}; |
| 72 | + |
| 73 | +template <typename T> struct SkRange { |
| 74 | + SkRange() : start(), end() {} |
| 75 | + SkRange(T s, T e) : start(s), end(e) {} |
| 76 | + |
| 77 | + T start, end; |
| 78 | + |
| 79 | + bool operator==(const SkRange<T>& other) const { |
| 80 | + return start == other.start && end == other.end; |
| 81 | + } |
| 82 | + |
| 83 | + T width() { return end - start; } |
| 84 | + |
| 85 | + void Shift(T delta) { |
| 86 | + start += delta; |
| 87 | + end += delta; |
| 88 | + } |
| 89 | +}; |
| 90 | + |
| 91 | +enum class TextBaseline { |
| 92 | + kAlphabetic, |
| 93 | + kIdeographic, |
| 94 | +}; |
| 95 | +} // namespace textlayout |
| 96 | +} // namespace skia |
| 97 | + |
| 98 | +#endif // DartTypes_DEFINED |
0 commit comments