@geastack/engine 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/canvas.cpp +34 -0
- package/css/animation.h +64 -0
- package/css/engine.h +6 -1
- package/package.json +2 -2
- package/ui/absolute_leaf_refresh.cpp +32 -31
- package/ui/core.cpp +9 -1
- package/ui/display_invalidation.cpp +29 -0
- package/ui/flex_balance.h +73 -0
- package/ui/image_node.cpp +24 -20
- package/ui/input.cpp +66 -36
- package/ui/input_render.cpp +13 -13
- package/ui/internal.h +51 -5
- package/ui/layout.cpp +2472 -400
- package/ui/layout_snapshot.cpp +21 -5
- package/ui/node_lifecycle.cpp +28 -3
- package/ui/node_model.h +323 -23
- package/ui/render.cpp +638 -265
- package/ui/root_scroll_refresh.cpp +15 -10
- package/ui/style.cpp +3254 -935
- package/ui/style.h +143 -6
- package/ui/style_values.h +16 -0
- package/ui/text.cpp +378 -103
- package/ui/tree_events.cpp +6 -3
- package/ui/tree_events.h +1 -0
- package/ui/tree_internal.h +19 -0
- package/ui/tree_nodes.cpp +6 -0
- package/ui/tree_render.cpp +71 -21
- package/ui/tree_state.h +54 -0
- package/ui/tree_style.cpp +287 -27
- package/ui/view.cpp +612 -251
package/ui/text.cpp
CHANGED
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
#include <cstring>
|
|
15
15
|
#include <string>
|
|
16
16
|
|
|
17
|
+
// ESP-IDF system headers may define quad as a compatibility type macro.
|
|
18
|
+
#ifdef quad
|
|
19
|
+
#undef quad
|
|
20
|
+
#endif
|
|
21
|
+
|
|
17
22
|
#ifndef GEA_EMBEDDED_RENDER_HOT_SRAM
|
|
18
23
|
#define GEA_EMBEDDED_RENDER_HOT_SRAM 0
|
|
19
24
|
#endif
|
|
@@ -46,26 +51,29 @@ struct ScopedRefreshStat
|
|
|
46
51
|
|
|
47
52
|
bool hasTransformState(const Node &node)
|
|
48
53
|
{
|
|
49
|
-
return rstyle(node.style)
|
|
54
|
+
return hasIndividualLinearTransform(rstyle(node.style)) || hadIndividualLinearTransform(node.render) ||
|
|
55
|
+
rstyle(node.style).transform_rotate != 0 ||
|
|
50
56
|
node.render.previous_transform_rotate != 0 ||
|
|
51
57
|
rstyle(node.style).transform_rotate_x != 0 ||
|
|
52
58
|
node.render.previous_transform_rotate_x != 0 ||
|
|
53
59
|
rstyle(node.style).transform_rotate_y != 0 ||
|
|
54
60
|
node.render.previous_transform_rotate_y != 0 ||
|
|
55
|
-
rstyle(node.style)
|
|
61
|
+
composedTranslateX(rstyle(node.style)) != 0 ||
|
|
56
62
|
node.render.previous_transform_translate_x != 0 ||
|
|
57
|
-
rstyle(node.style)
|
|
63
|
+
composedTranslateY(rstyle(node.style)) != 0 ||
|
|
58
64
|
node.render.previous_transform_translate_y != 0 ||
|
|
59
|
-
rstyle(node.style)
|
|
65
|
+
composedTranslateZ(rstyle(node.style)) != 0 ||
|
|
60
66
|
node.render.previous_transform_translate_z != 0 ||
|
|
61
|
-
rstyle(node.style)
|
|
67
|
+
composedTranslateXPercent(rstyle(node.style)) != 0 ||
|
|
62
68
|
node.render.previous_transform_translate_x_percent != 0 ||
|
|
63
|
-
rstyle(node.style)
|
|
69
|
+
composedTranslateYPercent(rstyle(node.style)) != 0 ||
|
|
64
70
|
node.render.previous_transform_translate_y_percent != 0 ||
|
|
65
71
|
rstyle(node.style).transform_scale_x != 1000 ||
|
|
66
72
|
node.render.previous_transform_scale_x != 1000 ||
|
|
67
73
|
rstyle(node.style).transform_scale_y != 1000 ||
|
|
74
|
+
rstyle(node.style).transform_scale_z != 1000 ||
|
|
68
75
|
node.render.previous_transform_scale_y != 1000 ||
|
|
76
|
+
node.render.previous_transform_scale_z != 1000 ||
|
|
69
77
|
rstyle(node.style).perspective > 0 ||
|
|
70
78
|
node.render.previous_perspective > 0;
|
|
71
79
|
}
|
|
@@ -207,19 +215,20 @@ bool currentTransformChainIsPureTranslate(const Node &node, float *outX, float *
|
|
|
207
215
|
bool anyTranslate = false;
|
|
208
216
|
for (;;) {
|
|
209
217
|
const Node &n = id >= 0 ? tree.node(id) : node;
|
|
210
|
-
if ((rstyle(n.style).transform_rotate % 3600) != 0 ||
|
|
218
|
+
if (hasIndividualLinearTransform(rstyle(n.style)) || (rstyle(n.style).transform_rotate % 3600) != 0 ||
|
|
211
219
|
(rstyle(n.style).transform_rotate_x % 3600) != 0 ||
|
|
212
220
|
(rstyle(n.style).transform_rotate_y % 3600) != 0 ||
|
|
213
|
-
rstyle(n.style)
|
|
221
|
+
composedTranslateZ(rstyle(n.style)) != 0 ||
|
|
214
222
|
rstyle(n.style).transform_scale_x != 1000 ||
|
|
215
223
|
rstyle(n.style).transform_scale_y != 1000 ||
|
|
224
|
+
rstyle(n.style).transform_scale_z != 1000 ||
|
|
216
225
|
rstyle(n.style).perspective > 0)
|
|
217
226
|
return false;
|
|
218
227
|
|
|
219
|
-
const float localDx = static_cast<float>(rstyle(n.style)
|
|
220
|
-
static_cast<float>(n.layout.width) * static_cast<float>(rstyle(n.style)
|
|
221
|
-
const float localDy = static_cast<float>(rstyle(n.style)
|
|
222
|
-
static_cast<float>(n.layout.height) * static_cast<float>(rstyle(n.style)
|
|
228
|
+
const float localDx = static_cast<float>(composedTranslateX(rstyle(n.style))) +
|
|
229
|
+
static_cast<float>(n.layout.width) * static_cast<float>(composedTranslateXPercent(rstyle(n.style))) * 0.001f;
|
|
230
|
+
const float localDy = static_cast<float>(composedTranslateY(rstyle(n.style))) +
|
|
231
|
+
static_cast<float>(n.layout.height) * static_cast<float>(composedTranslateYPercent(rstyle(n.style))) * 0.001f;
|
|
223
232
|
if (localDx != 0.0f || localDy != 0.0f) {
|
|
224
233
|
anyTranslate = true;
|
|
225
234
|
dx += localDx;
|
|
@@ -322,11 +331,7 @@ struct WrappedLine {
|
|
|
322
331
|
int renderBytes = 0;
|
|
323
332
|
int consumedBytes = 0;
|
|
324
333
|
int width = 0;
|
|
325
|
-
|
|
326
|
-
// An inline formatting context uses this to move a run that cannot start on
|
|
327
|
-
// the space left to the next line box, instead of splitting "technical" into
|
|
328
|
-
// "t" + "echnical".
|
|
329
|
-
bool hardSplit = false;
|
|
334
|
+
|
|
330
335
|
};
|
|
331
336
|
|
|
332
337
|
inline bool isWrappingSpace(int cp)
|
|
@@ -341,8 +346,8 @@ inline bool canBreakAfter(int cp)
|
|
|
341
346
|
}
|
|
342
347
|
|
|
343
348
|
// CSS white-space: normal/pre-line line breaking for the embedded renderer.
|
|
344
|
-
//
|
|
345
|
-
//
|
|
349
|
+
// Break at legal word boundaries. An unbreakable word can overflow the line;
|
|
350
|
+
// normal wrapping must never manufacture a break inside that word. `consumedBytes` includes discarded wrapping spaces or
|
|
346
351
|
// an explicit newline, while `renderBytes` contains only the visible run.
|
|
347
352
|
template <typename AdvanceForCodepoint>
|
|
348
353
|
WrappedLine nextWrappedLine(const char *text, int maxWidth, AdvanceForCodepoint advanceForCodepoint)
|
|
@@ -381,17 +386,11 @@ WrappedLine nextWrappedLine(const char *text, int maxWidth, AdvanceForCodepoint
|
|
|
381
386
|
// renderer re-wraps the run at that width, so a disagreement drew one
|
|
382
387
|
// more line than the box was tall and the run overlapped its next
|
|
383
388
|
// sibling (typography's specimen paragraphs).
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
} else {
|
|
390
|
-
line.renderBytes = bytes;
|
|
391
|
-
line.consumedBytes = bytes;
|
|
392
|
-
line.width = width;
|
|
393
|
-
line.hardSplit = true;
|
|
394
|
-
}
|
|
389
|
+
// Leading collapsible spaces cannot be an empty soft-wrapped line.
|
|
390
|
+
if (!isWrappingSpace(cp) && width + advance > maxWidth && bytes > 0 && breakRenderBytes > 0) {
|
|
391
|
+
line.renderBytes = breakRenderBytes;
|
|
392
|
+
line.consumedBytes = breakConsumedBytes;
|
|
393
|
+
line.width = breakWidth;
|
|
395
394
|
return line;
|
|
396
395
|
}
|
|
397
396
|
|
|
@@ -479,8 +478,34 @@ std::string transformedTextCopy(const char *text, int textTransform)
|
|
|
479
478
|
return out;
|
|
480
479
|
}
|
|
481
480
|
|
|
482
|
-
const char *textWithTransform(const char *text, int textTransform, std::string &storage)
|
|
481
|
+
const char *textWithTransform(const char *text, int textTransform, std::string &storage, int whiteSpace = -1)
|
|
483
482
|
{
|
|
483
|
+
// Perform CSS segment-break/space collapsing identically in measurement
|
|
484
|
+
// and painting, while retaining the authored Node::text for later mutation.
|
|
485
|
+
// Edge trimming belongs to line layout, not to individual inline runs.
|
|
486
|
+
if (text && (whiteSpace == 0 || whiteSpace == 1 || whiteSpace == 4) &&
|
|
487
|
+
(std::strpbrk(text, "\t\r\n\f") || std::strstr(text, " "))) {
|
|
488
|
+
std::string normalized;
|
|
489
|
+
normalized.reserve(std::strlen(text));
|
|
490
|
+
bool space = false;
|
|
491
|
+
for (const char *p = text; *p; ++p) {
|
|
492
|
+
char c = *p;
|
|
493
|
+
if (c == '\r') { if (p[1] == '\n') ++p; c = '\n'; }
|
|
494
|
+
if (whiteSpace == 4 && (c == '\n' || c == '\f')) {
|
|
495
|
+
if (!normalized.empty() && normalized.back() == ' ') normalized.pop_back();
|
|
496
|
+
normalized += '\n';
|
|
497
|
+
space = true;
|
|
498
|
+
} else if (c == ' ' || c == '\t' || c == '\n' || c == '\f') {
|
|
499
|
+
if (!space) normalized += ' ';
|
|
500
|
+
space = true;
|
|
501
|
+
} else {
|
|
502
|
+
normalized += c;
|
|
503
|
+
space = false;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
storage = textTransform ? transformedTextCopy(normalized.c_str(), textTransform) : std::move(normalized);
|
|
507
|
+
return storage.c_str();
|
|
508
|
+
}
|
|
484
509
|
if (!text || textTransform == 0) return text;
|
|
485
510
|
storage = transformedTextCopy(text, textTransform);
|
|
486
511
|
return storage.c_str();
|
|
@@ -684,26 +709,25 @@ int rasterizedSingleLineInkCenterOffsetY(const char *text,
|
|
|
684
709
|
return offset;
|
|
685
710
|
}
|
|
686
711
|
|
|
687
|
-
bool recordProjectedRasterText(const Node &node, uint8_t /*parentAlpha*/, int tx, int ty, int tw)
|
|
712
|
+
bool recordProjectedRasterText(const Node &node, const char *text, uint8_t /*parentAlpha*/, int tx, int ty, int tw)
|
|
688
713
|
{
|
|
689
|
-
if (node.style.font_id < 0 ||
|
|
714
|
+
if (node.style.font_id < 0 || std::strchr(text, '\n')) return false;
|
|
690
715
|
const int fontSize = node.style.font_size > 0 ? node.style.font_size : kBitmapFontHeight;
|
|
691
716
|
gea::framework::graphics::RasterizedFont font =
|
|
692
717
|
gea::framework::graphics::FontRegistry::rasterizedFamily(node.style.font_id, fontSize);
|
|
693
718
|
if (!font.valid()) return false;
|
|
694
719
|
|
|
695
720
|
int lineWidth = 0;
|
|
696
|
-
|
|
697
|
-
for (const char *p = node.text.c_str(); *p;) {
|
|
721
|
+
for (const char *p = text; *p;) {
|
|
698
722
|
gea::framework::graphics::Glyph glyph{};
|
|
699
|
-
const int cp =
|
|
723
|
+
const int cp = nextUtf8Codepoint(p);
|
|
700
724
|
lineWidth += font.glyph(cp, &glyph) ? glyph.advance : (font.sizePx() / 2);
|
|
701
725
|
}
|
|
702
726
|
|
|
703
727
|
int bx0, by0, bx1, by1;
|
|
704
728
|
ViewRenderer::transformedBounds(node, false, &bx0, &by0, &bx1, &by1);
|
|
705
729
|
|
|
706
|
-
|
|
730
|
+
if (lineWidth <= 0) return true;
|
|
707
731
|
|
|
708
732
|
const int fontLineHeight = font.lineHeight();
|
|
709
733
|
const int lineAdvance = node.style.line_height > 0 ? node.style.line_height : fontLineHeight;
|
|
@@ -743,19 +767,10 @@ bool recordProjectedRasterText(const Node &node, uint8_t /*parentAlpha*/, int tx
|
|
|
743
767
|
cmd->projectedText.color = node.style.text_color;
|
|
744
768
|
cmd->projectedText.alpha = node.style.text_alpha;
|
|
745
769
|
cmd->projectedText.textTransform = node.style.text_transform;
|
|
746
|
-
|
|
747
|
-
//
|
|
748
|
-
//
|
|
749
|
-
|
|
750
|
-
// reading only node.style left labels floating over culled faces.
|
|
751
|
-
{
|
|
752
|
-
bool backfaceHidden = node.style.backface_hidden != 0;
|
|
753
|
-
const Tree &tree = Tree::instance();
|
|
754
|
-
const Node *nodes = tree.nodes();
|
|
755
|
-
for (int a = node.parent; !backfaceHidden && a >= 0 && a < tree.nodeCount(); a = nodes[a].parent)
|
|
756
|
-
backfaceHidden = nodes[a].style.backface_hidden != 0;
|
|
757
|
-
cmd->projectedText.backfaceHidden = backfaceHidden ? 1 : 0;
|
|
758
|
-
}
|
|
770
|
+
cmd->projectedText.whiteSpace = node.style.white_space;
|
|
771
|
+
// Flattened ancestor groups are culled by the recorder for every paint type.
|
|
772
|
+
// This command's flag describes only its own face in a preserve-3d group.
|
|
773
|
+
cmd->projectedText.backfaceHidden = node.style.backface_hidden ? 1 : 0;
|
|
759
774
|
return true;
|
|
760
775
|
}
|
|
761
776
|
#endif
|
|
@@ -979,11 +994,11 @@ TextLayoutMeasure measureTextLayoutForNode(const Node &node, const char *text, i
|
|
|
979
994
|
{
|
|
980
995
|
if (contentWidth < 0) contentWidth = 0;
|
|
981
996
|
std::string transformed;
|
|
982
|
-
const char *measureText = textWithTransform(text, node.style.text_transform, transformed);
|
|
997
|
+
const char *measureText = textWithTransform(text, node.style.text_transform, transformed, node.style.white_space);
|
|
983
998
|
// white-space: nowrap lays the run out as a single line — measure against an
|
|
984
999
|
// unbounded width so the content box sizes to the full text (then max-width /
|
|
985
1000
|
// the parent box clamps it). Drawing truncates/ellipsizes the overflow.
|
|
986
|
-
const int measureWidth = node.style.white_space == 1 ? 32767 : contentWidth;
|
|
1001
|
+
const int measureWidth = (node.style.white_space == 1 || node.style.white_space == 2) ? 32767 : contentWidth;
|
|
987
1002
|
const TextMeasure measured = TextMetrics::measure(measureText,
|
|
988
1003
|
measureWidth,
|
|
989
1004
|
node.style.font_id,
|
|
@@ -991,14 +1006,14 @@ TextLayoutMeasure measureTextLayoutForNode(const Node &node, const char *text, i
|
|
|
991
1006
|
node.style.line_height,
|
|
992
1007
|
node.style.font_weight);
|
|
993
1008
|
TextLayoutMeasure out;
|
|
994
|
-
out.width = measured.width + node.style
|
|
995
|
-
out.height = measured.height + node.style
|
|
996
|
-
if (node.style.width != kUnset) out.width = node.style.width;
|
|
997
|
-
else if (node.style.width_percent != kUnset && node.layout.width > 0) out.width = node.layout.width;
|
|
998
|
-
if (node.style.height != kUnset) out.height = node.style.height;
|
|
999
|
-
else if (node.style.height_percent != kUnset && node.layout.height > 0) out.height = node.layout.height;
|
|
1000
|
-
out.width =
|
|
1001
|
-
out.height =
|
|
1009
|
+
out.width = measured.width + boxInset(node.style, 1) + boxInset(node.style, 3);
|
|
1010
|
+
out.height = measured.height + boxInset(node.style, 0) + boxInset(node.style, 2);
|
|
1011
|
+
if (node.style.width != kUnset) out.width = contentSizeToBorderSize(node.style, node.style.width, true);
|
|
1012
|
+
else if ((node.style.width_percent != kUnset || node.style.width_expression >= 0) && node.layout.width > 0) out.width = node.layout.width;
|
|
1013
|
+
if (node.style.height != kUnset) out.height = contentSizeToBorderSize(node.style, node.style.height, false);
|
|
1014
|
+
else if ((node.style.height_percent != kUnset || node.style.height_expression >= 0) && node.layout.height > 0) out.height = node.layout.height;
|
|
1015
|
+
out.width = clampBorderBoxSize(node.style, out.width, true);
|
|
1016
|
+
out.height = clampBorderBoxSize(node.style, out.height, false);
|
|
1002
1017
|
return out;
|
|
1003
1018
|
}
|
|
1004
1019
|
|
|
@@ -1006,7 +1021,7 @@ int measureSingleLineTextWidthForNode(const Node &node, const char *text)
|
|
|
1006
1021
|
{
|
|
1007
1022
|
if (!text || !text[0]) return 0;
|
|
1008
1023
|
std::string transformed;
|
|
1009
|
-
const char *measureText = textWithTransform(text, node.style.text_transform, transformed);
|
|
1024
|
+
const char *measureText = textWithTransform(text, node.style.text_transform, transformed, node.style.white_space);
|
|
1010
1025
|
return TextMetrics::measure(measureText,
|
|
1011
1026
|
32767,
|
|
1012
1027
|
node.style.font_id,
|
|
@@ -1015,19 +1030,124 @@ int measureSingleLineTextWidthForNode(const Node &node, const char *text)
|
|
|
1015
1030
|
node.style.font_weight).width;
|
|
1016
1031
|
}
|
|
1017
1032
|
|
|
1033
|
+
struct TextCoverageSink {
|
|
1034
|
+
int screenY = 0;
|
|
1035
|
+
int screenX = 0;
|
|
1036
|
+
int width = 0;
|
|
1037
|
+
int clipX0 = 0;
|
|
1038
|
+
int clipY0 = 0;
|
|
1039
|
+
int clipX1 = -1;
|
|
1040
|
+
int clipY1 = -1;
|
|
1041
|
+
std::uint8_t *coverage = nullptr;
|
|
1042
|
+
|
|
1043
|
+
void add(int x, int y, std::uint8_t value) const
|
|
1044
|
+
{
|
|
1045
|
+
if (!coverage || value == 0 || y != screenY || y < clipY0 || y > clipY1 ||
|
|
1046
|
+
x < screenX || x >= screenX + width || x < clipX0 || x > clipX1) return;
|
|
1047
|
+
auto &dst = coverage[x - screenX];
|
|
1048
|
+
if (value > dst) dst = value;
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1018
1052
|
class TextDrawer {
|
|
1019
1053
|
public:
|
|
1020
|
-
static void
|
|
1054
|
+
static void unionCoverageRow(const DisplayCommand &command, int screenY, int screenX,
|
|
1055
|
+
int width, std::uint8_t *outCoverage)
|
|
1056
|
+
{
|
|
1057
|
+
if (!outCoverage || width <= 0) return;
|
|
1058
|
+
if (command.textDecorationInk) {
|
|
1059
|
+
if (command.type != DisplayCommandType::FillRect) return;
|
|
1060
|
+
if (screenY < command.fill.y || screenY >= command.fill.y + command.fill.h) return;
|
|
1061
|
+
int clipX0, clipY0, clipX1, clipY1;
|
|
1062
|
+
gea::platform::display::Display::clip(&clipX0, &clipY0, &clipX1, &clipY1);
|
|
1063
|
+
if (screenY < clipY0 || screenY > clipY1) return;
|
|
1064
|
+
const int left = std::max({screenX, static_cast<int>(command.fill.x), clipX0});
|
|
1065
|
+
const int right = std::min({screenX + width, static_cast<int>(command.fill.x) + command.fill.w, clipX1 + 1});
|
|
1066
|
+
for (int x = left; x < right; ++x) outCoverage[x - screenX] = 255;
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
if (command.type != DisplayCommandType::DrawText) return;
|
|
1070
|
+
TextCoverageSink sink;
|
|
1071
|
+
sink.screenY = screenY;
|
|
1072
|
+
sink.screenX = screenX;
|
|
1073
|
+
sink.width = width;
|
|
1074
|
+
sink.coverage = outCoverage;
|
|
1075
|
+
drawWrapped(command.text.text, command.text.x, command.text.y, command.text.maxWidth,
|
|
1076
|
+
command.text.color, command.text.scale, command.text.align, command.text.containerWidth,
|
|
1077
|
+
command.text.fontId, command.text.textTransform, command.text.lineHeight,
|
|
1078
|
+
command.text.whiteSpace, command.text.textOverflow, command.text.maxHeight,
|
|
1079
|
+
command.text.firstLineIndent, &sink);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
1083
|
+
static void rasterizedGlyphRun(const char *text, int x, int y, int fontId, int fontSize,
|
|
1084
|
+
const TextCoverageSink &sink)
|
|
1085
|
+
{
|
|
1086
|
+
gea::framework::graphics::RasterizedFont font =
|
|
1087
|
+
gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize);
|
|
1088
|
+
if (!font.valid()) return;
|
|
1089
|
+
int penX = x;
|
|
1090
|
+
for (const char *p = text; p && *p;) {
|
|
1091
|
+
const int cp = nextUtf8Codepoint(p);
|
|
1092
|
+
gea::framework::graphics::Glyph glyph{};
|
|
1093
|
+
if (!font.glyph(cp, &glyph)) { penX += font.sizePx() / 2; continue; }
|
|
1094
|
+
const int gx = penX + glyph.bearingX;
|
|
1095
|
+
const int gy = y + font.ascender() - glyph.bearingY;
|
|
1096
|
+
const int row = sink.screenY - gy;
|
|
1097
|
+
if (row >= 0 && row < glyph.height)
|
|
1098
|
+
for (int col = 0; col < glyph.width; ++col)
|
|
1099
|
+
sink.add(gx + col, sink.screenY, font.coverage(glyph, row, col));
|
|
1100
|
+
penX += glyph.advance;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
#endif
|
|
1104
|
+
|
|
1105
|
+
static void bitmapGlyphRun(const char *text, int x, int y, float scale,
|
|
1106
|
+
const TextCoverageSink &sink)
|
|
1107
|
+
{
|
|
1108
|
+
if (scale < 0.1f) scale = 1.0f;
|
|
1109
|
+
const int glyphWidth = std::max(1, static_cast<int>(kBitmapFontWidth * scale + 0.5f));
|
|
1110
|
+
const int glyphHeight = std::max(1, static_cast<int>(kBitmapFontHeight * scale + 0.5f));
|
|
1111
|
+
const int row = sink.screenY - y;
|
|
1112
|
+
if (row < 0 || row >= glyphHeight) return;
|
|
1113
|
+
const int srcRow = row * kBitmapFontHeight / glyphHeight;
|
|
1114
|
+
const auto &font = gea::framework::graphics::FontRegistry::bitmap8x16();
|
|
1115
|
+
int penX = x;
|
|
1116
|
+
for (const char *p = text; p && *p;) {
|
|
1117
|
+
const int cp = nextUtf8Codepoint(p);
|
|
1118
|
+
if (cp == '\n') { penX = x; continue; }
|
|
1119
|
+
gea::framework::graphics::Glyph glyph{};
|
|
1120
|
+
font.glyph(cp, &glyph);
|
|
1121
|
+
for (int col = 0; col < glyphWidth; ++col) {
|
|
1122
|
+
const int srcCol = col * kBitmapFontWidth / glyphWidth;
|
|
1123
|
+
sink.add(penX + col, sink.screenY, font.coverage(glyph, srcRow, srcCol));
|
|
1124
|
+
}
|
|
1125
|
+
penX += glyphWidth;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
static void drawWrapped(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, float scale, int textAlign, int containerWidth, int fontId, int textTransform, int lineHeight, int whiteSpace, int textOverflow, int maxHeight = 0, int firstLineIndent = 0, TextCoverageSink *coverageSink = nullptr)
|
|
1021
1130
|
{
|
|
1022
1131
|
if (!text || !text[0]) return;
|
|
1023
1132
|
std::string transformed;
|
|
1024
|
-
text = textWithTransform(text, textTransform, transformed);
|
|
1133
|
+
text = textWithTransform(text, textTransform, transformed, whiteSpace);
|
|
1134
|
+
// Pre preserves forced breaks and paints every line without soft wrap.
|
|
1135
|
+
if (whiteSpace == 2) maxWidth = 32767;
|
|
1025
1136
|
|
|
1026
1137
|
int clipX0;
|
|
1027
1138
|
int clipY0;
|
|
1028
1139
|
int clipX1;
|
|
1029
1140
|
int clipY1;
|
|
1030
1141
|
gea::platform::display::Display::clip(&clipX0, &clipY0, &clipX1, &clipY1);
|
|
1142
|
+
TextCoverageSink clippedSink;
|
|
1143
|
+
if (coverageSink) {
|
|
1144
|
+
clippedSink = *coverageSink;
|
|
1145
|
+
clippedSink.clipX0 = clipX0;
|
|
1146
|
+
clippedSink.clipY0 = clipY0;
|
|
1147
|
+
clippedSink.clipX1 = clipX1;
|
|
1148
|
+
clippedSink.clipY1 = clipY1;
|
|
1149
|
+
coverageSink = &clippedSink;
|
|
1150
|
+
}
|
|
1031
1151
|
|
|
1032
1152
|
const bool noWrap = whiteSpace == 1;
|
|
1033
1153
|
const bool ellipsis = textOverflow == 1;
|
|
@@ -1037,10 +1157,10 @@ public:
|
|
|
1037
1157
|
const int fontSize = static_cast<int>(scale * kBitmapFontHeight + 0.5f);
|
|
1038
1158
|
if (gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize).valid()) {
|
|
1039
1159
|
if (noWrap)
|
|
1040
|
-
drawRasterizedSingleLine(text, x, y, maxWidth, color, textAlign, containerWidth, fontId, fontSize, lineHeight, ellipsis, clipX0, clipY0, clipX1, clipY1);
|
|
1160
|
+
drawRasterizedSingleLine(text, x, y, maxWidth, color, textAlign, containerWidth, fontId, fontSize, lineHeight, ellipsis, clipX0, clipY0, clipX1, clipY1, coverageSink);
|
|
1041
1161
|
else
|
|
1042
1162
|
drawRasterizedWrapped(text, x, y, maxWidth, color, textAlign, containerWidth, fontId, fontSize, lineHeight, clipX0, clipY0, clipX1, clipY1,
|
|
1043
|
-
ellipsis ? maxHeight : 0, firstLineIndent);
|
|
1163
|
+
ellipsis ? maxHeight : 0, firstLineIndent, coverageSink);
|
|
1044
1164
|
return;
|
|
1045
1165
|
}
|
|
1046
1166
|
}
|
|
@@ -1048,14 +1168,14 @@ public:
|
|
|
1048
1168
|
(void)fontId;
|
|
1049
1169
|
#endif
|
|
1050
1170
|
if (noWrap)
|
|
1051
|
-
drawBitmapSingleLine(text, x, y, maxWidth, color, scale, textAlign, containerWidth, lineHeight, ellipsis, clipX0, clipY0, clipX1, clipY1);
|
|
1171
|
+
drawBitmapSingleLine(text, x, y, maxWidth, color, scale, textAlign, containerWidth, lineHeight, ellipsis, clipX0, clipY0, clipX1, clipY1, coverageSink);
|
|
1052
1172
|
else
|
|
1053
|
-
drawBitmapWrapped(text, x, y, maxWidth, color, scale, textAlign, containerWidth, lineHeight, clipX0, clipY0, clipX1, clipY1, firstLineIndent);
|
|
1173
|
+
drawBitmapWrapped(text, x, y, maxWidth, color, scale, textAlign, containerWidth, lineHeight, clipX0, clipY0, clipX1, clipY1, firstLineIndent, coverageSink);
|
|
1054
1174
|
}
|
|
1055
1175
|
|
|
1056
1176
|
private:
|
|
1057
1177
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
1058
|
-
static void drawRasterizedWrapped(const char *text, int x, int y, int maxWidth, std::uint16_t color, int textAlign, int containerWidth, int fontId, int fontSize, int lineHeight, int clipX0, int clipY0, int clipX1, int clipY1, int ellipsisMaxHeight = 0, int firstLineIndent = 0)
|
|
1178
|
+
static void drawRasterizedWrapped(const char *text, int x, int y, int maxWidth, std::uint16_t color, int textAlign, int containerWidth, int fontId, int fontSize, int lineHeight, int clipX0, int clipY0, int clipX1, int clipY1, int ellipsisMaxHeight = 0, int firstLineIndent = 0, const TextCoverageSink *coverageSink = nullptr)
|
|
1059
1179
|
{
|
|
1060
1180
|
// Inline continuation: the run's first line starts `firstLineIndent` px in
|
|
1061
1181
|
// from the box's left edge (the pen position it inherited from the box
|
|
@@ -1132,9 +1252,9 @@ private:
|
|
|
1132
1252
|
if (penY + lineBoxOffset > clipY1) break;
|
|
1133
1253
|
if (li == lineBudget - 1 && li < entry.lineCount - 1) {
|
|
1134
1254
|
// Last budgeted line with more text behind it: ellipsize the rest.
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1255
|
+
drawRasterizedSingleLine(lineStart, lineOriginX_(li), penY, lineBudget_(li), color, textAlign, containerWidth,
|
|
1256
|
+
fontId, fontSize, lineHeight, /*ellipsis=*/true,
|
|
1257
|
+
clipX0, clipY0, clipX1, clipY1, coverageSink);
|
|
1138
1258
|
return;
|
|
1139
1259
|
}
|
|
1140
1260
|
const int chars = entry.renderBytes[li];
|
|
@@ -1147,7 +1267,8 @@ private:
|
|
|
1147
1267
|
const int copyLen = chars < kWrappedLineBufferBytes ? chars : kWrappedLineBufferBytes;
|
|
1148
1268
|
std::memcpy(lineBuffer, lineStart, copyLen);
|
|
1149
1269
|
lineBuffer[copyLen] = '\0';
|
|
1150
|
-
|
|
1270
|
+
if (coverageSink) rasterizedGlyphRun(lineBuffer, lineX, lineBoxY, fontId, fontSize, *coverageSink);
|
|
1271
|
+
else gea::platform::display::Display::drawTextFontFamily(lineBuffer, lineX, lineBoxY, color, fontId, fontSize);
|
|
1151
1272
|
}
|
|
1152
1273
|
}
|
|
1153
1274
|
lineStart += entry.consumedBytes[li];
|
|
@@ -1166,7 +1287,7 @@ private:
|
|
|
1166
1287
|
// Budget reached: ellipsize whatever remains onto this final line.
|
|
1167
1288
|
drawRasterizedSingleLine(lineStart, lineOriginX_(li), penY, lineBudget_(li), color, textAlign, containerWidth,
|
|
1168
1289
|
fontId, fontSize, lineHeight, /*ellipsis=*/true,
|
|
1169
|
-
clipX0, clipY0, clipX1, clipY1);
|
|
1290
|
+
clipX0, clipY0, clipX1, clipY1, coverageSink);
|
|
1170
1291
|
return;
|
|
1171
1292
|
}
|
|
1172
1293
|
const int lineIndex = li;
|
|
@@ -1185,7 +1306,8 @@ private:
|
|
|
1185
1306
|
const int copyLen = line.renderBytes < kWrappedLineBufferBytes ? line.renderBytes : kWrappedLineBufferBytes;
|
|
1186
1307
|
std::memcpy(lineBuffer, lineStart, copyLen);
|
|
1187
1308
|
lineBuffer[copyLen] = '\0';
|
|
1188
|
-
|
|
1309
|
+
if (coverageSink) rasterizedGlyphRun(lineBuffer, lineX, lineBoxY, fontId, fontSize, *coverageSink);
|
|
1310
|
+
else gea::platform::display::Display::drawTextFontFamily(lineBuffer, lineX, lineBoxY, color, fontId, fontSize);
|
|
1189
1311
|
}
|
|
1190
1312
|
}
|
|
1191
1313
|
|
|
@@ -1199,7 +1321,7 @@ private:
|
|
|
1199
1321
|
// appending an ASCII "..." when text-overflow: ellipsis is set, or hard-
|
|
1200
1322
|
// clipping at the box edge otherwise. The truncated run always fits within
|
|
1201
1323
|
// maxWidth, so it never wraps and never spills past the content box.
|
|
1202
|
-
static void drawRasterizedSingleLine(const char *text, int x, int y, int maxWidth, std::uint16_t color, int textAlign, int containerWidth, int fontId, int fontSize, int lineHeight, bool ellipsis, int clipX0, int clipY0, int clipX1, int clipY1)
|
|
1324
|
+
static void drawRasterizedSingleLine(const char *text, int x, int y, int maxWidth, std::uint16_t color, int textAlign, int containerWidth, int fontId, int fontSize, int lineHeight, bool ellipsis, int clipX0, int clipY0, int clipX1, int clipY1, const TextCoverageSink *coverageSink = nullptr)
|
|
1203
1325
|
{
|
|
1204
1326
|
gea::framework::graphics::RasterizedFont font = gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize);
|
|
1205
1327
|
if (!font.valid()) return;
|
|
@@ -1265,11 +1387,12 @@ private:
|
|
|
1265
1387
|
if (len <= 0) return;
|
|
1266
1388
|
buf[len] = '\0';
|
|
1267
1389
|
const int xOffset = alignedOffset(textAlign, containerWidth, drawnWidth);
|
|
1268
|
-
|
|
1390
|
+
if (coverageSink) rasterizedGlyphRun(buf, x + xOffset, lineBoxY, fontId, fontSize, *coverageSink);
|
|
1391
|
+
else gea::platform::display::Display::drawTextFontFamily(buf, x + xOffset, lineBoxY, color, fontId, fontSize);
|
|
1269
1392
|
}
|
|
1270
1393
|
#endif
|
|
1271
1394
|
|
|
1272
|
-
static void drawBitmapWrapped(const char *text, int x, int y, int maxWidth, std::uint16_t color, float scale, int textAlign, int containerWidth, int lineHeight, int clipX0, int clipY0, int clipX1, int clipY1, int firstLineIndent = 0)
|
|
1395
|
+
static void drawBitmapWrapped(const char *text, int x, int y, int maxWidth, std::uint16_t color, float scale, int textAlign, int containerWidth, int lineHeight, int clipX0, int clipY0, int clipX1, int clipY1, int firstLineIndent = 0, const TextCoverageSink *coverageSink = nullptr)
|
|
1273
1396
|
{
|
|
1274
1397
|
if (scale < 0.1f) scale = 1.0f;
|
|
1275
1398
|
int glyphWidth = static_cast<int>(kBitmapFontWidth * scale + 0.5f);
|
|
@@ -1302,7 +1425,8 @@ private:
|
|
|
1302
1425
|
char buf[5] = {};
|
|
1303
1426
|
const int bytes = static_cast<int>(glyph - glyphStart);
|
|
1304
1427
|
std::memcpy(buf, glyphStart, bytes);
|
|
1305
|
-
|
|
1428
|
+
if (coverageSink) bitmapGlyphRun(buf, penX, penY, scale, *coverageSink);
|
|
1429
|
+
else gea::platform::display::Display::drawText(buf, penX, penY, color, scale);
|
|
1306
1430
|
penX += glyphWidth;
|
|
1307
1431
|
}
|
|
1308
1432
|
}
|
|
@@ -1318,7 +1442,7 @@ private:
|
|
|
1318
1442
|
// that is what `measureBitmap` charges for, so counting bytes here put the
|
|
1319
1443
|
// truncation, the ellipsis budget and the alignment offset in different units
|
|
1320
1444
|
// from the layout that placed the text.
|
|
1321
|
-
static void drawBitmapSingleLine(const char *text, int x, int y, int maxWidth, std::uint16_t color, float scale, int textAlign, int containerWidth, int lineHeight, bool ellipsis, int clipX0, int clipY0, int clipX1, int clipY1)
|
|
1445
|
+
static void drawBitmapSingleLine(const char *text, int x, int y, int maxWidth, std::uint16_t color, float scale, int textAlign, int containerWidth, int lineHeight, bool ellipsis, int clipX0, int clipY0, int clipX1, int clipY1, const TextCoverageSink *coverageSink = nullptr)
|
|
1322
1446
|
{
|
|
1323
1447
|
(void)lineHeight;
|
|
1324
1448
|
if (scale < 0.1f) scale = 1.0f;
|
|
@@ -1362,13 +1486,15 @@ private:
|
|
|
1362
1486
|
nextUtf8Codepoint(glyph);
|
|
1363
1487
|
char b[5] = {};
|
|
1364
1488
|
std::memcpy(b, glyphStart, static_cast<std::size_t>(glyph - glyphStart));
|
|
1365
|
-
|
|
1489
|
+
if (coverageSink) bitmapGlyphRun(b, penX, penY, scale, *coverageSink);
|
|
1490
|
+
else gea::platform::display::Display::drawText(b, penX, penY, color, scale);
|
|
1366
1491
|
penX += glyphWidth;
|
|
1367
1492
|
}
|
|
1368
1493
|
if (addEllipsis) {
|
|
1369
1494
|
for (int i = 0; i < 3; ++i) {
|
|
1370
1495
|
char b[2] = { '.', '\0' };
|
|
1371
|
-
|
|
1496
|
+
if (coverageSink) bitmapGlyphRun(b, penX, penY, scale, *coverageSink);
|
|
1497
|
+
else gea::platform::display::Display::drawText(b, penX, penY, color, scale);
|
|
1372
1498
|
penX += glyphWidth;
|
|
1373
1499
|
}
|
|
1374
1500
|
}
|
|
@@ -1580,6 +1706,25 @@ bool TextRenderer::canFragmentInlineRuns(const Node &node)
|
|
|
1580
1706
|
return cached != 0;
|
|
1581
1707
|
}
|
|
1582
1708
|
|
|
1709
|
+
int TextRenderer::baselineOffset(const Node &node, bool last)
|
|
1710
|
+
{
|
|
1711
|
+
const int fontSize = node.style.font_size > 0 ? node.style.font_size : 16;
|
|
1712
|
+
const auto font = gea::framework::graphics::FontRegistry::rasterizedFamily(node.style.font_id, fontSize);
|
|
1713
|
+
if (!font.valid()) return node.layout.height + node.style.margin[2];
|
|
1714
|
+
const int lineAdvance = node.style.line_height > 0 ? node.style.line_height : font.lineHeight();
|
|
1715
|
+
const int halfLeading = node.style.line_height > 0 ? (lineAdvance - font.lineHeight()) / 2 : 0;
|
|
1716
|
+
int offset = boxInset(node.style, 0) + halfLeading + font.ascender();
|
|
1717
|
+
if (last) {
|
|
1718
|
+
std::string storage;
|
|
1719
|
+
const char *text = prepareText(node.text.c_str(), node.style.text_transform, node.style.white_space, storage);
|
|
1720
|
+
const int width = node.style.white_space == 1 || node.style.white_space == 2
|
|
1721
|
+
? 32767 : std::max(1, node.layout.width - boxInsets(node.style, true));
|
|
1722
|
+
const auto measured = TextMetrics::measure(text, width, node.style.font_id, fontSize, node.style.line_height, node.style.font_weight);
|
|
1723
|
+
offset += std::max(0, measured.height - lineAdvance);
|
|
1724
|
+
}
|
|
1725
|
+
return offset;
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1583
1728
|
InlineFlowMeasure TextRenderer::measureInlineFlow(const Node &node, int firstAvail, int contentWidth, bool atLineStart)
|
|
1584
1729
|
{
|
|
1585
1730
|
InlineFlowMeasure out;
|
|
@@ -1587,20 +1732,20 @@ InlineFlowMeasure TextRenderer::measureInlineFlow(const Node &node, int firstAva
|
|
|
1587
1732
|
if (!raw || !raw[0]) return out;
|
|
1588
1733
|
// nowrap is a single line by definition, and an author-sized box wraps within
|
|
1589
1734
|
// its own width — neither participates in the block's line boxes.
|
|
1590
|
-
if (node.style.white_space == 1) return out;
|
|
1735
|
+
if (node.style.white_space == 1 || node.style.white_space == 2) return out;
|
|
1591
1736
|
if (!canFragmentInlineRuns(node)) return out;
|
|
1592
1737
|
|
|
1593
1738
|
const GlyphAdvanceSource advance = advanceSourceForNode(node);
|
|
1594
1739
|
if (!advance.valid || advance.lineAdvance <= 0) return out;
|
|
1595
1740
|
|
|
1596
1741
|
std::string transformed;
|
|
1597
|
-
const char *text = textWithTransform(raw, node.style.text_transform, transformed);
|
|
1742
|
+
const char *text = textWithTransform(raw, node.style.text_transform, transformed, node.style.white_space);
|
|
1598
1743
|
if (!text || !text[0]) return out;
|
|
1599
1744
|
|
|
1600
1745
|
if (contentWidth < 1) contentWidth = 1;
|
|
1601
1746
|
if (firstAvail < 0) firstAvail = 0;
|
|
1602
1747
|
|
|
1603
|
-
if (atLineStart) {
|
|
1748
|
+
if (atLineStart && (node.style.white_space == 0 || node.style.white_space == 4)) {
|
|
1604
1749
|
const int lead = leadingCollapsibleBytes(text);
|
|
1605
1750
|
if (lead > 0) {
|
|
1606
1751
|
const char *p = text;
|
|
@@ -1620,7 +1765,14 @@ InlineFlowMeasure TextRenderer::measureInlineFlow(const Node &node, int firstAva
|
|
|
1620
1765
|
const int visible = line.width + (lineIndex == 0 ? out.firstLineIndentAdjust : 0);
|
|
1621
1766
|
if (lineIndex == 0) {
|
|
1622
1767
|
out.firstLineWidth = visible;
|
|
1623
|
-
|
|
1768
|
+
if (node.style.white_space == 0 || node.style.white_space == 4) {
|
|
1769
|
+
const char *end = p + line.renderBytes;
|
|
1770
|
+
for (const char *glyph = p; glyph < end;) {
|
|
1771
|
+
const int cp = nextUtf8Codepoint(glyph);
|
|
1772
|
+
out.firstLineTrailingSpace = isWrappingSpace(cp)
|
|
1773
|
+
? out.firstLineTrailingSpace + advance(cp) : 0;
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1624
1776
|
}
|
|
1625
1777
|
out.lastLineWidth = visible;
|
|
1626
1778
|
if (visible > out.maxLineWidth) out.maxLineWidth = visible;
|
|
@@ -1632,14 +1784,57 @@ InlineFlowMeasure TextRenderer::measureInlineFlow(const Node &node, int firstAva
|
|
|
1632
1784
|
return out;
|
|
1633
1785
|
}
|
|
1634
1786
|
|
|
1787
|
+
int TextRenderer::firstUnbreakableWidth(const Node &node)
|
|
1788
|
+
{
|
|
1789
|
+
std::string storage;
|
|
1790
|
+
const char *text = prepareText(node.text.c_str(), node.style.text_transform, node.style.white_space, storage);
|
|
1791
|
+
if (!text) return 0;
|
|
1792
|
+
if (node.style.white_space == 0 || node.style.white_space == 1 || node.style.white_space == 4)
|
|
1793
|
+
text += leadingCollapsibleBytes(text);
|
|
1794
|
+
const bool wrapping = node.style.white_space != 1 && node.style.white_space != 2;
|
|
1795
|
+
const char *end = text;
|
|
1796
|
+
while (*end) {
|
|
1797
|
+
const char *start = end;
|
|
1798
|
+
const int cp = nextUtf8Codepoint(end);
|
|
1799
|
+
if (cp == '\n' || (wrapping && isWrappingSpace(cp))) { end = start; break; }
|
|
1800
|
+
if (wrapping && canBreakAfter(cp)) break;
|
|
1801
|
+
}
|
|
1802
|
+
return measureSingleLineTextWidthForNode(node, std::string(text, end - text).c_str());
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
int TextRenderer::minContentWidth(const Node &node, int *pendingWord)
|
|
1806
|
+
{
|
|
1807
|
+
std::string storage;
|
|
1808
|
+
const char *text = prepareText(node.text.c_str(), node.style.text_transform, node.style.white_space, storage);
|
|
1809
|
+
const bool wrapping = node.style.white_space != 1 && node.style.white_space != 2;
|
|
1810
|
+
const char *start = text;
|
|
1811
|
+
int width = 0, current = pendingWord ? *pendingWord : 0;
|
|
1812
|
+
for (const char *p = text;; ++p) {
|
|
1813
|
+
if (!*p || *p == '\n' || (wrapping && (*p == ' ' || *p == '\t'))) {
|
|
1814
|
+
const std::string word(start, p - start);
|
|
1815
|
+
current += measureSingleLineTextWidthForNode(node, word.c_str());
|
|
1816
|
+
width = std::max(width, current);
|
|
1817
|
+
if (!*p) { if (pendingWord) *pendingWord = current; break; }
|
|
1818
|
+
current = 0;
|
|
1819
|
+
start = p + 1;
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return width;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
const char *TextRenderer::prepareText(const char *text, int textTransform, int whiteSpace, std::string &storage)
|
|
1826
|
+
{
|
|
1827
|
+
return textWithTransform(text, textTransform, storage, whiteSpace);
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1635
1830
|
void TextRenderer::layout(int id, int avail_w)
|
|
1636
1831
|
{
|
|
1637
1832
|
Node *n = &Tree::instance().nodes()[id];
|
|
1638
1833
|
|
|
1639
|
-
int content_w = avail_w - n->style
|
|
1834
|
+
int content_w = avail_w - boxInset(n->style, 1) - boxInset(n->style, 3)
|
|
1640
1835
|
- n->style.margin[1] - n->style.margin[3];
|
|
1641
|
-
if (n->style.width != kUnset) content_w = n->style.width - n->style
|
|
1642
|
-
else if (n->style.width_percent != kUnset && n->layout.width > 0) content_w = n->layout.width - n->style
|
|
1836
|
+
if (n->style.width != kUnset) content_w = contentSizeToBorderSize(n->style, n->style.width, true) - boxInset(n->style, 1) - boxInset(n->style, 3);
|
|
1837
|
+
else if ((n->style.width_percent != kUnset || n->style.width_expression >= 0) && n->layout.width > 0) content_w = n->layout.width - boxInset(n->style, 1) - boxInset(n->style, 3);
|
|
1643
1838
|
if (content_w < 0) content_w = 0;
|
|
1644
1839
|
|
|
1645
1840
|
const TextLayoutMeasure measured = measureTextLayoutForNode(*n, n->text.c_str(), content_w);
|
|
@@ -1664,9 +1859,9 @@ bool TextRenderer::remeasureContentBox(int id, bool keepBoxWidth)
|
|
|
1664
1859
|
// explicit width re-wraps within the fixed box; natural-width text hugs the
|
|
1665
1860
|
// new content (the 0x4000 bound matches setText's bbox predictor).
|
|
1666
1861
|
int content_w = 0x4000;
|
|
1667
|
-
if (keepBoxWidth) content_w = n.layout.width;
|
|
1668
|
-
else if (n.style.width != kUnset) content_w = n.style.width - n.style
|
|
1669
|
-
else if (n.style.width_percent != kUnset && n.layout.width > 0) content_w = n.layout.width - n.style
|
|
1862
|
+
if (keepBoxWidth) content_w = n.layout.width - boxInsets(n.style, true);
|
|
1863
|
+
else if (n.style.width != kUnset) content_w = contentSizeToBorderSize(n.style, n.style.width, true) - boxInset(n.style, 1) - boxInset(n.style, 3);
|
|
1864
|
+
else if ((n.style.width_percent != kUnset || n.style.width_expression >= 0) && n.layout.width > 0) content_w = n.layout.width - boxInset(n.style, 1) - boxInset(n.style, 3);
|
|
1670
1865
|
if (content_w < 0) content_w = 0;
|
|
1671
1866
|
const TextLayoutMeasure measured = measureTextLayoutForNode(n, n.text.c_str(), content_w);
|
|
1672
1867
|
if (keepBoxWidth) {
|
|
@@ -1685,6 +1880,12 @@ void TextRenderer::drawWrapped(const char *text, int x, int y, int maxWidth, gea
|
|
|
1685
1880
|
TextDrawer::drawWrapped(text, x, y, maxWidth, color, scale, text_align, containerWidth, fontId, textTransform, lineHeight, whiteSpace, textOverflow, maxHeight, firstLineIndent);
|
|
1686
1881
|
}
|
|
1687
1882
|
|
|
1883
|
+
void TextRenderer::unionCoverageRow(const DisplayCommand &command, int screenY, int screenX,
|
|
1884
|
+
int width, std::uint8_t *outCoverage)
|
|
1885
|
+
{
|
|
1886
|
+
TextDrawer::unionCoverageRow(command, screenY, screenX, width, outCoverage);
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1688
1889
|
int TextRenderer::measureWidth(const char *text, int fontId, int fontSize, int textTransform)
|
|
1689
1890
|
{
|
|
1690
1891
|
if (!text || !text[0]) return 0;
|
|
@@ -1710,13 +1911,83 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
1710
1911
|
const Node *n = &node;
|
|
1711
1912
|
if (n->type != NodeType::Text || n->text.empty()) return;
|
|
1712
1913
|
|
|
1914
|
+
// A first-line background belongs to the inline fragment, not the block's
|
|
1915
|
+
// entire width. Layout records this run's first line box/advance only when an
|
|
1916
|
+
// ancestor has a resolved ::first-line background. Emit it before the text
|
|
1917
|
+
// command so the glyphs remain painted above the inline background.
|
|
1918
|
+
const int textNodeId = static_cast<int>(n - Tree::instance().nodes());
|
|
1919
|
+
const NodeRareData *textRare = rareDataFor(textNodeId);
|
|
1920
|
+
const NodeRareData *lineStyleRare = nullptr;
|
|
1921
|
+
for (int ancestor = n->parent; ancestor >= 0 && ancestor < Tree::instance().nodeCount();
|
|
1922
|
+
ancestor = Tree::instance().node(ancestor).parent) {
|
|
1923
|
+
const NodeRareData *candidate = rareDataFor(ancestor);
|
|
1924
|
+
if (candidate && candidate->firstLineBackground.hasColor) {
|
|
1925
|
+
lineStyleRare = candidate;
|
|
1926
|
+
break;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
if (textRare && textRare->firstLineFragment.valid && lineStyleRare &&
|
|
1930
|
+
lineStyleRare->firstLineBackground.lineValid &&
|
|
1931
|
+
textRare->firstLineFragment.width > 0 && textRare->firstLineFragment.height > 0 &&
|
|
1932
|
+
lineStyleRare->firstLineBackground.alpha > 0) {
|
|
1933
|
+
const auto &fragment = textRare->firstLineFragment;
|
|
1934
|
+
const auto &background = lineStyleRare->firstLineBackground;
|
|
1935
|
+
const uint8_t backgroundAlpha = combineAlpha(parentAlpha, background.alpha);
|
|
1936
|
+
int fragmentX = fragment.x;
|
|
1937
|
+
int fragmentY = fragment.y;
|
|
1938
|
+
const Tree &tree = Tree::instance();
|
|
1939
|
+
if (fragment.contextNode >= 0 && fragment.contextNode < tree.nodeCount()) {
|
|
1940
|
+
fragmentX += tree.node(fragment.contextNode).layout.x;
|
|
1941
|
+
fragmentY += tree.node(fragment.contextNode).layout.y;
|
|
1942
|
+
}
|
|
1943
|
+
int ownerId = -1;
|
|
1944
|
+
for (int ancestor = n->parent; ancestor >= 0 && ancestor < tree.nodeCount();
|
|
1945
|
+
ancestor = tree.node(ancestor).parent) {
|
|
1946
|
+
const NodeRareData *candidate = rareDataFor(ancestor);
|
|
1947
|
+
if (candidate && &candidate->firstLineBackground == &lineStyleRare->firstLineBackground) {
|
|
1948
|
+
ownerId = ancestor;
|
|
1949
|
+
break;
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
const bool onOwnerFirstLine = ownerId >= 0 && background.lineContextNode >= 0 &&
|
|
1953
|
+
background.lineContextNode < tree.nodeCount() &&
|
|
1954
|
+
fragmentY == tree.node(background.lineContextNode).layout.y + background.lineY;
|
|
1955
|
+
if (onOwnerFirstLine) {
|
|
1956
|
+
int16_t xs[4], ys[4];
|
|
1957
|
+
ViewRenderer::transformedRectCorners(*n, false, fragmentX, fragmentY,
|
|
1958
|
+
fragment.width, fragment.height, xs, ys);
|
|
1959
|
+
int bx0, by0, bx1, by1;
|
|
1960
|
+
boundsFromCorners(xs, ys, &bx0, &by0, &bx1, &by1);
|
|
1961
|
+
if (backgroundAlpha != parentAlpha)
|
|
1962
|
+
appendAlphaCommand(backgroundAlpha, bx0, by0, bx1 - bx0 + 1, by1 - by0 + 1);
|
|
1963
|
+
DisplayCommand *fill = DisplayList::instance().append();
|
|
1964
|
+
if (fill) {
|
|
1965
|
+
fill->type = DisplayCommandType::FillQuad;
|
|
1966
|
+
fill->bx = bx0; fill->by = by0;
|
|
1967
|
+
fill->bw = bx1 - bx0 + 1; fill->bh = by1 - by0 + 1;
|
|
1968
|
+
fill->quad.x0 = xs[0]; fill->quad.y0 = ys[0];
|
|
1969
|
+
fill->quad.x1 = xs[1]; fill->quad.y1 = ys[1];
|
|
1970
|
+
fill->quad.x2 = xs[2]; fill->quad.y2 = ys[2];
|
|
1971
|
+
fill->quad.x3 = xs[3]; fill->quad.y3 = ys[3];
|
|
1972
|
+
fill->quad.lx = static_cast<int16_t>(fragmentX); fill->quad.ly = static_cast<int16_t>(fragmentY);
|
|
1973
|
+
fill->quad.lw = fragment.width; fill->quad.lh = fragment.height;
|
|
1974
|
+
fill->quad.aux = 0;
|
|
1975
|
+
fill->quad.color = background.color;
|
|
1976
|
+
fill->quad.reprojectMode = 1;
|
|
1977
|
+
}
|
|
1978
|
+
if (backgroundAlpha != parentAlpha)
|
|
1979
|
+
appendAlphaCommand(parentAlpha, bx0, by0, bx1 - bx0 + 1, by1 - by0 + 1);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
|
|
1713
1984
|
int x = n->layout.x;
|
|
1714
1985
|
int y = n->layout.y;
|
|
1715
1986
|
int w = n->layout.width;
|
|
1716
1987
|
int h = n->layout.height;
|
|
1717
|
-
int tx = x + n->style
|
|
1718
|
-
int ty = y + n->style
|
|
1719
|
-
int tw = w - n->style
|
|
1988
|
+
int tx = x + boxInset(n->style, 3);
|
|
1989
|
+
int ty = y + boxInset(n->style, 0);
|
|
1990
|
+
int tw = w - boxInset(n->style, 1) - boxInset(n->style, 3);
|
|
1720
1991
|
if (tw < 0) tw = 0;
|
|
1721
1992
|
float textScale = n->style.font_size > 0 ? static_cast<float>(n->style.font_size) / kBitmapFontHeight : 1.0f;
|
|
1722
1993
|
|
|
@@ -1755,14 +2026,14 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
1755
2026
|
}
|
|
1756
2027
|
}
|
|
1757
2028
|
std::string transformedText;
|
|
1758
|
-
const char *measureText = textWithTransform(n->text.c_str(), n->style.text_transform, transformedText);
|
|
2029
|
+
const char *measureText = textWithTransform(n->text.c_str(), n->style.text_transform, transformedText, n->style.white_space);
|
|
1759
2030
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
1760
|
-
if (transformed && recordProjectedRasterText(*n, parentAlpha, tx, ty, tw)) return;
|
|
2031
|
+
if (transformed && recordProjectedRasterText(*n, measureText, parentAlpha, tx, ty, tw)) return;
|
|
1761
2032
|
#endif
|
|
1762
2033
|
if (transformed && transformedX1 >= transformedX0 && transformedY1 >= transformedY0) {
|
|
1763
2034
|
const int projectedW = transformedX1 - transformedX0 + 1;
|
|
1764
2035
|
const int projectedH = transformedY1 - transformedY0 + 1;
|
|
1765
|
-
const int contentH = h - n->style
|
|
2036
|
+
const int contentH = h - boxInset(n->style, 0) - boxInset(n->style, 2);
|
|
1766
2037
|
const int centerX = transformedX0 + projectedW / 2;
|
|
1767
2038
|
const int centerY = transformedY0 + projectedH / 2;
|
|
1768
2039
|
float projectedScaleX = tw > 0 ? static_cast<float>(projectedW) / static_cast<float>(tw) : 1.0f;
|
|
@@ -1822,6 +2093,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
1822
2093
|
}
|
|
1823
2094
|
|
|
1824
2095
|
const bool noWrap = n->style.white_space == 1;
|
|
2096
|
+
const bool noSoftWrap = noWrap || n->style.white_space == 2;
|
|
1825
2097
|
// Inline continuation (see LayoutBox::inline_indent): line 0 starts at
|
|
1826
2098
|
// `drawX + inlineIndent`, every later line at `drawX`. The tight ink/paint
|
|
1827
2099
|
// bounds below all assume one origin for the whole run, so an indented run
|
|
@@ -1837,7 +2109,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
1837
2109
|
if (!transformed && inlineIndent == 0) {
|
|
1838
2110
|
const int commandFontSize = static_cast<int>(textScale * kBitmapFontHeight + 0.5f);
|
|
1839
2111
|
const TextMeasure paintMeasure =
|
|
1840
|
-
TextMetrics::measure(measureText,
|
|
2112
|
+
TextMetrics::measure(measureText, noSoftWrap ? 32767 : drawW, n->style.font_id, commandFontSize, commandLineHeight, n->style.font_weight);
|
|
1841
2113
|
if (paintMeasure.width > 0 && paintMeasure.height > 0) {
|
|
1842
2114
|
// CSS: a flex container's bare text becomes an anonymous flex item, so
|
|
1843
2115
|
// align-items centers (or end-aligns) it on the cross axis. This node
|
|
@@ -1847,11 +2119,12 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
1847
2119
|
// axis is vertical there); a child-bearing flex container aligns its
|
|
1848
2120
|
// child BOXES through layout as before.
|
|
1849
2121
|
if (n->style.display == kDisplayFlex && n->first_child < 0 &&
|
|
1850
|
-
(n->style.align_items == 1 || n->style.align_items == 2) &&
|
|
1851
2122
|
usesRowLayout(n->style)) {
|
|
1852
|
-
const int contentH = h - n->style
|
|
2123
|
+
const int contentH = h - boxInset(n->style, 0) - boxInset(n->style, 2);
|
|
1853
2124
|
const int slack = contentH - paintMeasure.height;
|
|
1854
|
-
|
|
2125
|
+
const int alignment = usedAlignment(n->style.align_items, slack, (n->style.flex_wrap & 3) == 2);
|
|
2126
|
+
if (alignment == 1) drawY += slack / 2;
|
|
2127
|
+
else if (alignment == 2) drawY += slack;
|
|
1855
2128
|
}
|
|
1856
2129
|
// nowrap truncates/clips the run to the content box, so the painted
|
|
1857
2130
|
// width never exceeds drawW even though the unbounded measure may.
|
|
@@ -1892,7 +2165,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
1892
2165
|
int ix1 = -1;
|
|
1893
2166
|
int iy1 = -1;
|
|
1894
2167
|
if (rasterizedTextInkBounds(measureText,
|
|
1895
|
-
|
|
2168
|
+
noSoftWrap ? 32767 : drawW,
|
|
1896
2169
|
n->style.text_align,
|
|
1897
2170
|
containerW,
|
|
1898
2171
|
n->style.font_id,
|
|
@@ -1953,6 +2226,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
1953
2226
|
std::fflush(stdout);
|
|
1954
2227
|
}
|
|
1955
2228
|
|
|
2229
|
+
|
|
1956
2230
|
const uint8_t effectiveAlpha = combineAlpha(parentAlpha, n->style.text_alpha);
|
|
1957
2231
|
if (effectiveAlpha != parentAlpha) appendAlphaCommand(effectiveAlpha, bx, by, bw, bh);
|
|
1958
2232
|
|
|
@@ -1977,7 +2251,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
1977
2251
|
cmd->text.textOverflow = n->style.text_overflow;
|
|
1978
2252
|
cmd->text.firstLineIndent = static_cast<int16_t>(inlineIndent);
|
|
1979
2253
|
{
|
|
1980
|
-
const int contentH = h - n->style
|
|
2254
|
+
const int contentH = h - boxInset(n->style, 0) - boxInset(n->style, 2);
|
|
1981
2255
|
cmd->text.maxHeight = static_cast<int16_t>(contentH > 0 ? (contentH > 32767 ? 32767 : contentH) : 0);
|
|
1982
2256
|
}
|
|
1983
2257
|
|
|
@@ -1995,6 +2269,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
1995
2269
|
DisplayCommand *deco = DisplayList::instance().append();
|
|
1996
2270
|
if (deco) {
|
|
1997
2271
|
deco->type = DisplayCommandType::FillRect;
|
|
2272
|
+
deco->textDecorationInk = true;
|
|
1998
2273
|
deco->bx = x; deco->by = y; deco->bw = w; deco->bh = h;
|
|
1999
2274
|
deco->fill.x = tx;
|
|
2000
2275
|
deco->fill.y = lineY;
|