@geastack/engine 0.1.17 → 0.1.18
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 +40 -5
- package/package.json +1 -1
- package/rasterized_font.cpp +118 -7
- package/touch_runtime.cpp +118 -67
- package/ui/canvas_element.h +1 -1
- package/ui/child_node_list.h +94 -0
- package/ui/control_commit.h +23 -0
- package/ui/css_features.h +5 -0
- package/ui/document.cpp +43 -96
- package/ui/document.h +61 -6
- package/ui/input.cpp +72 -20
- package/ui/input_retirement.h +22 -0
- package/ui/internal.h +3 -1
- package/ui/layout.cpp +31 -25
- package/ui/node.cpp +123 -31
- package/ui/node.h +55 -16
- package/ui/node_lifecycle.cpp +3 -0
- package/ui/node_model.h +20 -1
- package/ui/render.cpp +16 -3
- package/ui/selector.cpp +527 -0
- package/ui/selector.h +32 -0
- package/ui/style.cpp +94 -23
- package/ui/style.h +8 -3
- package/ui/text.cpp +73 -49
- package/ui/tree_events.cpp +376 -85
- package/ui/tree_events.h +34 -2
- package/ui/tree_internal.h +17 -5
- package/ui/tree_nodes.cpp +218 -13
- package/ui/tree_state.h +4 -0
- package/ui/tree_style.cpp +4 -0
- package/ui/virtual_keyboard.cpp +8 -1
package/ui/text.cpp
CHANGED
|
@@ -123,6 +123,10 @@ struct LineBreakCacheEntry {
|
|
|
123
123
|
int firstLineIndent = 0;
|
|
124
124
|
int fontId = -2;
|
|
125
125
|
int fontSize = -1;
|
|
126
|
+
#if GEA_CSS_FONT_STRETCH
|
|
127
|
+
int fontWeight = 400;
|
|
128
|
+
int fontStretch = 1000;
|
|
129
|
+
#endif
|
|
126
130
|
int lineHeight = 0;
|
|
127
131
|
int lineCount = 0;
|
|
128
132
|
std::uint16_t renderBytes[kMaxCachedLines];
|
|
@@ -551,11 +555,11 @@ bool rasterizedTextInkBounds(const char *text,
|
|
|
551
555
|
int *outX0,
|
|
552
556
|
int *outY0,
|
|
553
557
|
int *outX1,
|
|
554
|
-
int *outY1)
|
|
558
|
+
int *outY1, int fontWeight = 400, int fontStretch = 1000)
|
|
555
559
|
{
|
|
556
560
|
if (!text || !text[0] || !outX0 || !outY0 || !outX1 || !outY1) return false;
|
|
557
561
|
gea::framework::graphics::RasterizedFont font =
|
|
558
|
-
gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize);
|
|
562
|
+
gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize, fontWeight, fontStretch);
|
|
559
563
|
if (!font.valid()) return false;
|
|
560
564
|
if (maxWidth <= 0) maxWidth = 32767;
|
|
561
565
|
|
|
@@ -704,11 +708,11 @@ int rasterizedSingleLineInkCenterOffsetY(const char *text,
|
|
|
704
708
|
int /*containerWidth*/,
|
|
705
709
|
int fontId,
|
|
706
710
|
int fontSize,
|
|
707
|
-
int lineHeight)
|
|
711
|
+
int lineHeight, int fontWeight = 400, int fontStretch = 1000)
|
|
708
712
|
{
|
|
709
713
|
if (!text || !text[0] || std::strchr(text, '\n')) return 0;
|
|
710
714
|
gea::framework::graphics::RasterizedFont font =
|
|
711
|
-
gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize);
|
|
715
|
+
gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize, fontWeight, fontStretch);
|
|
712
716
|
if (!font.valid()) return 0;
|
|
713
717
|
|
|
714
718
|
const FontInkExtent ink = rasterizedFontInkExtent(font);
|
|
@@ -732,7 +736,7 @@ bool recordProjectedRasterText(const Node &node, const char *text, uint8_t /*par
|
|
|
732
736
|
if (node.computedStyle().font_id < 0 || std::strchr(text, '\n')) return false;
|
|
733
737
|
const int fontSize = node.computedStyle().font_size > 0 ? node.computedStyle().font_size : kBitmapFontHeight;
|
|
734
738
|
gea::framework::graphics::RasterizedFont font =
|
|
735
|
-
gea::framework::graphics::FontRegistry::rasterizedFamily(node.computedStyle().font_id, fontSize);
|
|
739
|
+
gea::framework::graphics::FontRegistry::rasterizedFamily(node.computedStyle().font_id, fontSize, node.computedStyle().font_weight, node.computedStyle().font_stretch);
|
|
736
740
|
if (!font.valid()) return false;
|
|
737
741
|
|
|
738
742
|
int lineWidth = 0;
|
|
@@ -781,6 +785,7 @@ bool recordProjectedRasterText(const Node &node, const char *text, uint8_t /*par
|
|
|
781
785
|
cmd->projectedText.y3 = ys[3];
|
|
782
786
|
cmd->projectedText.fontId = node.computedStyle().font_id;
|
|
783
787
|
cmd->projectedText.fontSize = fontSize;
|
|
788
|
+
cmd->projectedText.fontWeight=node.computedStyle().font_weight;cmd->projectedText.fontStretch=node.computedStyle().font_stretch;
|
|
784
789
|
cmd->projectedText.color = node.computedStyle().text_color;
|
|
785
790
|
cmd->projectedText.alpha = node.computedStyle().text_alpha;
|
|
786
791
|
cmd->projectedText.textTransform = node.computedStyle().text_transform;
|
|
@@ -850,9 +855,11 @@ extern "C" __attribute__((weak)) bool gea_host_measure_text_with_style(const cha
|
|
|
850
855
|
return false;
|
|
851
856
|
}
|
|
852
857
|
|
|
858
|
+
extern "C" __attribute__((weak)) bool gea_host_measure_text_with_variations(const char *, int, int, int, int, int, int, int *, int *) { return false; }
|
|
859
|
+
|
|
853
860
|
class TextMetrics {
|
|
854
861
|
public:
|
|
855
|
-
static TextMeasure measure(const char *text, int maxWidth, int fontId, int fontSize, int lineHeight = 0, int fontWeight = 400)
|
|
862
|
+
static TextMeasure measure(const char *text, int maxWidth, int fontId, int fontSize, int lineHeight = 0, int fontWeight = 400, int fontStretch = 1000)
|
|
856
863
|
{
|
|
857
864
|
// Give the host first crack — when it returns true we trust its
|
|
858
865
|
// measurement absolutely, even if the values look surprising next to
|
|
@@ -862,7 +869,8 @@ public:
|
|
|
862
869
|
{
|
|
863
870
|
int hw = 0;
|
|
864
871
|
int hh = 0;
|
|
865
|
-
if (
|
|
872
|
+
if (gea_host_measure_text_with_variations(text, maxWidth, fontId, fontSize, fontWeight, fontStretch, lineHeight, &hw, &hh) ||
|
|
873
|
+
gea_host_measure_text_with_style(text, maxWidth, fontId, fontSize, fontWeight, lineHeight, &hw, &hh) ||
|
|
866
874
|
gea_host_measure_text_with_line_height(text, maxWidth, fontId, fontSize, lineHeight, &hw, &hh) ||
|
|
867
875
|
gea_host_measure_text(text, maxWidth, fontId, fontSize, &hw, &hh)) {
|
|
868
876
|
TextMeasure m;
|
|
@@ -873,7 +881,7 @@ public:
|
|
|
873
881
|
}
|
|
874
882
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
875
883
|
if (fontId >= 0) {
|
|
876
|
-
const TextMeasure measured = measureRasterized(text, maxWidth, fontId, fontSize, lineHeight);
|
|
884
|
+
const TextMeasure measured = measureRasterized(text, maxWidth, fontId, fontSize, lineHeight, fontWeight, fontStretch);
|
|
877
885
|
if (!text || !text[0] || measured.height > 0) return measured;
|
|
878
886
|
}
|
|
879
887
|
#else
|
|
@@ -910,12 +918,12 @@ public:
|
|
|
910
918
|
}
|
|
911
919
|
|
|
912
920
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
913
|
-
static TextMeasure measureRasterized(const char *text, int maxWidth, int fontId, int fontSize, int lineHeight = 0)
|
|
921
|
+
static TextMeasure measureRasterized(const char *text, int maxWidth, int fontId, int fontSize, int lineHeight = 0, int fontWeight = 400, int fontStretch = 1000)
|
|
914
922
|
{
|
|
915
923
|
TextMeasure result{};
|
|
916
924
|
if (!text || !text[0]) return result;
|
|
917
925
|
|
|
918
|
-
gea::framework::graphics::RasterizedFont font = gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize);
|
|
926
|
+
gea::framework::graphics::RasterizedFont font = gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize, fontWeight, fontStretch);
|
|
919
927
|
if (!font.valid()) return result;
|
|
920
928
|
const int lineAdvance = lineHeight > 0 ? lineHeight : font.lineHeight();
|
|
921
929
|
|
|
@@ -971,7 +979,7 @@ GlyphAdvanceSource advanceSourceForNode(const Node &node)
|
|
|
971
979
|
const int fontSize = node.computedStyle().font_size > 0 ? node.computedStyle().font_size : kBitmapFontHeight;
|
|
972
980
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
973
981
|
if (node.computedStyle().font_id >= 0) {
|
|
974
|
-
src.font = gea::framework::graphics::FontRegistry::rasterizedFamily(node.computedStyle().font_id, fontSize);
|
|
982
|
+
src.font = gea::framework::graphics::FontRegistry::rasterizedFamily(node.computedStyle().font_id, fontSize, node.computedStyle().font_weight, node.computedStyle().font_stretch);
|
|
975
983
|
if (src.font.valid()) {
|
|
976
984
|
src.rasterized = true;
|
|
977
985
|
src.valid = true;
|
|
@@ -1019,7 +1027,7 @@ TextLayoutMeasure measureTextLayoutForNode(const Node &node, const char *text, i
|
|
|
1019
1027
|
node.computedStyle().font_id,
|
|
1020
1028
|
node.computedStyle().font_size,
|
|
1021
1029
|
node.computedStyle().line_height,
|
|
1022
|
-
node.computedStyle().font_weight);
|
|
1030
|
+
node.computedStyle().font_weight, node.computedStyle().font_stretch);
|
|
1023
1031
|
TextLayoutMeasure out;
|
|
1024
1032
|
out.width = measured.width + boxInset(node.computedStyle(), 1) + boxInset(node.computedStyle(), 3);
|
|
1025
1033
|
out.height = measured.height + boxInset(node.computedStyle(), 0) + boxInset(node.computedStyle(), 2);
|
|
@@ -1042,7 +1050,7 @@ int measureSingleLineTextWidthForNode(const Node &node, const char *text)
|
|
|
1042
1050
|
node.computedStyle().font_id,
|
|
1043
1051
|
node.computedStyle().font_size,
|
|
1044
1052
|
node.computedStyle().line_height,
|
|
1045
|
-
node.computedStyle().font_weight).width;
|
|
1053
|
+
node.computedStyle().font_weight, node.computedStyle().font_stretch).width;
|
|
1046
1054
|
}
|
|
1047
1055
|
|
|
1048
1056
|
struct TextCoverageSink {
|
|
@@ -1064,6 +1072,14 @@ struct TextCoverageSink {
|
|
|
1064
1072
|
}
|
|
1065
1073
|
};
|
|
1066
1074
|
|
|
1075
|
+
static void drawStyledTextFontFamily(const char *text,int x,int y,std::uint16_t color,int family,int size,int weight=400,int stretch=1000) {
|
|
1076
|
+
#if GEA_EMBEDDED_TTF_FREETYPE
|
|
1077
|
+
gea::platform::display::Display::drawTextFontFamily(text,x,y,color,family,size,weight,stretch);
|
|
1078
|
+
#else
|
|
1079
|
+
(void)weight;(void)stretch;gea::platform::display::Display::drawTextFontFamily(text,x,y,color,family,size);
|
|
1080
|
+
#endif
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1067
1083
|
class TextDrawer {
|
|
1068
1084
|
public:
|
|
1069
1085
|
static void unionCoverageRow(const DisplayCommand &command, int screenY, int screenX,
|
|
@@ -1091,15 +1107,15 @@ public:
|
|
|
1091
1107
|
command.text.color, command.text.scale, command.text.align, command.text.containerWidth,
|
|
1092
1108
|
command.text.fontId, command.text.textTransform, command.text.lineHeight,
|
|
1093
1109
|
command.text.whiteSpace, command.text.textOverflow, command.text.maxHeight,
|
|
1094
|
-
command.text.firstLineIndent, &sink);
|
|
1110
|
+
command.text.firstLineIndent, &sink, command.text.fontWeight, command.text.fontStretch);
|
|
1095
1111
|
}
|
|
1096
1112
|
|
|
1097
1113
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
1098
1114
|
static void rasterizedGlyphRun(const char *text, int x, int y, int fontId, int fontSize,
|
|
1099
|
-
const TextCoverageSink &sink)
|
|
1115
|
+
const TextCoverageSink &sink, int fontWeight = 400, int fontStretch = 1000)
|
|
1100
1116
|
{
|
|
1101
1117
|
gea::framework::graphics::RasterizedFont font =
|
|
1102
|
-
gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize);
|
|
1118
|
+
gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize, fontWeight, fontStretch);
|
|
1103
1119
|
if (!font.valid()) return;
|
|
1104
1120
|
int penX = x;
|
|
1105
1121
|
for (const char *p = text; p && *p;) {
|
|
@@ -1145,7 +1161,7 @@ public:
|
|
|
1145
1161
|
}
|
|
1146
1162
|
}
|
|
1147
1163
|
|
|
1148
|
-
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)
|
|
1164
|
+
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, int fontWeight = 400, int fontStretch = 1000)
|
|
1149
1165
|
{
|
|
1150
1166
|
if (!text || !text[0]) return;
|
|
1151
1167
|
std::string transformed;
|
|
@@ -1174,12 +1190,12 @@ public:
|
|
|
1174
1190
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
1175
1191
|
if (fontId >= 0) {
|
|
1176
1192
|
const int fontSize = static_cast<int>(scale * kBitmapFontHeight + 0.5f);
|
|
1177
|
-
if (gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize).valid()) {
|
|
1193
|
+
if (gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize, fontWeight, fontStretch).valid()) {
|
|
1178
1194
|
if (noWrap)
|
|
1179
|
-
drawRasterizedSingleLine(text, x, y, maxWidth, color, textAlign, containerWidth, fontId, fontSize, lineHeight, ellipsis, clipX0, clipY0, clipX1, clipY1, coverageSink);
|
|
1195
|
+
drawRasterizedSingleLine(text, x, y, maxWidth, color, textAlign, containerWidth, fontId, fontSize, lineHeight, ellipsis, clipX0, clipY0, clipX1, clipY1, coverageSink, fontWeight, fontStretch);
|
|
1180
1196
|
else
|
|
1181
1197
|
drawRasterizedWrapped(text, x, y, maxWidth, color, textAlign, containerWidth, fontId, fontSize, lineHeight, clipX0, clipY0, clipX1, clipY1,
|
|
1182
|
-
ellipsis ? maxHeight : 0, firstLineIndent, coverageSink);
|
|
1198
|
+
ellipsis ? maxHeight : 0, firstLineIndent, coverageSink, fontWeight, fontStretch);
|
|
1183
1199
|
return;
|
|
1184
1200
|
}
|
|
1185
1201
|
}
|
|
@@ -1187,14 +1203,14 @@ public:
|
|
|
1187
1203
|
(void)fontId;
|
|
1188
1204
|
#endif
|
|
1189
1205
|
if (noWrap)
|
|
1190
|
-
drawBitmapSingleLine(text, x, y, maxWidth, color, scale, textAlign, containerWidth, lineHeight, ellipsis, clipX0, clipY0, clipX1, clipY1, coverageSink);
|
|
1206
|
+
drawBitmapSingleLine(text, x, y, maxWidth, color, scale, textAlign, containerWidth, lineHeight, ellipsis, clipX0, clipY0, clipX1, clipY1, coverageSink, fontWeight, fontStretch);
|
|
1191
1207
|
else
|
|
1192
|
-
drawBitmapWrapped(text, x, y, maxWidth, color, scale, textAlign, containerWidth, lineHeight, clipX0, clipY0, clipX1, clipY1, firstLineIndent, coverageSink);
|
|
1208
|
+
drawBitmapWrapped(text, x, y, maxWidth, color, scale, textAlign, containerWidth, lineHeight, clipX0, clipY0, clipX1, clipY1, firstLineIndent, coverageSink, fontWeight, fontStretch);
|
|
1193
1209
|
}
|
|
1194
1210
|
|
|
1195
1211
|
private:
|
|
1196
1212
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
1197
|
-
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)
|
|
1213
|
+
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, int fontWeight = 400, int fontStretch = 1000)
|
|
1198
1214
|
{
|
|
1199
1215
|
// Inline continuation: the run's first line starts `firstLineIndent` px in
|
|
1200
1216
|
// from the box's left edge (the pen position it inherited from the box
|
|
@@ -1206,7 +1222,7 @@ private:
|
|
|
1206
1222
|
return budget < 1 ? 1 : budget;
|
|
1207
1223
|
};
|
|
1208
1224
|
const auto lineOriginX_ = [&](int li) { return li == 0 ? x + firstLineIndent : x; };
|
|
1209
|
-
gea::framework::graphics::RasterizedFont font = gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize);
|
|
1225
|
+
gea::framework::graphics::RasterizedFont font = gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize, fontWeight, fontStretch);
|
|
1210
1226
|
if (!font.valid()) return;
|
|
1211
1227
|
|
|
1212
1228
|
const int glyphHeight = font.lineHeight();
|
|
@@ -1230,6 +1246,9 @@ private:
|
|
|
1230
1246
|
entry.firstLineIndent == firstLineIndent &&
|
|
1231
1247
|
entry.fontId == fontId &&
|
|
1232
1248
|
entry.fontSize == fontSize &&
|
|
1249
|
+
#if GEA_CSS_FONT_STRETCH
|
|
1250
|
+
entry.fontWeight==fontWeight && entry.fontStretch==fontStretch &&
|
|
1251
|
+
#endif
|
|
1233
1252
|
entry.lineHeight == lineAdvance;
|
|
1234
1253
|
|
|
1235
1254
|
if (!cacheHit) {
|
|
@@ -1239,6 +1258,9 @@ private:
|
|
|
1239
1258
|
entry.firstLineIndent = firstLineIndent;
|
|
1240
1259
|
entry.fontId = fontId;
|
|
1241
1260
|
entry.fontSize = fontSize;
|
|
1261
|
+
#if GEA_CSS_FONT_STRETCH
|
|
1262
|
+
entry.fontWeight=fontWeight;entry.fontStretch=fontStretch;
|
|
1263
|
+
#endif
|
|
1242
1264
|
entry.lineHeight = lineAdvance;
|
|
1243
1265
|
entry.lineCount = 0;
|
|
1244
1266
|
|
|
@@ -1270,7 +1292,7 @@ private:
|
|
|
1270
1292
|
// Last budgeted line with more text behind it: ellipsize the rest.
|
|
1271
1293
|
drawRasterizedSingleLine(lineStart, lineOriginX_(li), penY, lineBudget_(li), color, textAlign, containerWidth,
|
|
1272
1294
|
fontId, fontSize, lineHeight, /*ellipsis=*/true,
|
|
1273
|
-
clipX0, clipY0, clipX1, clipY1, coverageSink);
|
|
1295
|
+
clipX0, clipY0, clipX1, clipY1, coverageSink, fontWeight, fontStretch);
|
|
1274
1296
|
return;
|
|
1275
1297
|
}
|
|
1276
1298
|
const int chars = entry.renderBytes[li];
|
|
@@ -1283,8 +1305,8 @@ private:
|
|
|
1283
1305
|
const int copyLen = chars < kWrappedLineBufferBytes ? chars : kWrappedLineBufferBytes;
|
|
1284
1306
|
std::memcpy(lineBuffer, lineStart, copyLen);
|
|
1285
1307
|
lineBuffer[copyLen] = '\0';
|
|
1286
|
-
if (coverageSink) rasterizedGlyphRun(lineBuffer, lineX, lineBoxY, fontId, fontSize, *coverageSink);
|
|
1287
|
-
else
|
|
1308
|
+
if (coverageSink) rasterizedGlyphRun(lineBuffer, lineX, lineBoxY, fontId, fontSize, *coverageSink, fontWeight, fontStretch);
|
|
1309
|
+
else drawStyledTextFontFamily(lineBuffer, lineX, lineBoxY, color, fontId, fontSize, fontWeight, fontStretch);
|
|
1288
1310
|
}
|
|
1289
1311
|
}
|
|
1290
1312
|
lineStart += entry.consumedBytes[li];
|
|
@@ -1303,7 +1325,7 @@ private:
|
|
|
1303
1325
|
// Budget reached: ellipsize whatever remains onto this final line.
|
|
1304
1326
|
drawRasterizedSingleLine(lineStart, lineOriginX_(li), penY, lineBudget_(li), color, textAlign, containerWidth,
|
|
1305
1327
|
fontId, fontSize, lineHeight, /*ellipsis=*/true,
|
|
1306
|
-
clipX0, clipY0, clipX1, clipY1, coverageSink);
|
|
1328
|
+
clipX0, clipY0, clipX1, clipY1, coverageSink, fontWeight, fontStretch);
|
|
1307
1329
|
return;
|
|
1308
1330
|
}
|
|
1309
1331
|
const int lineIndex = li;
|
|
@@ -1320,8 +1342,8 @@ private:
|
|
|
1320
1342
|
const int copyLen = line.renderBytes < kWrappedLineBufferBytes ? line.renderBytes : kWrappedLineBufferBytes;
|
|
1321
1343
|
std::memcpy(lineBuffer, lineStart, copyLen);
|
|
1322
1344
|
lineBuffer[copyLen] = '\0';
|
|
1323
|
-
if (coverageSink) rasterizedGlyphRun(lineBuffer, lineX, lineBoxY, fontId, fontSize, *coverageSink);
|
|
1324
|
-
else
|
|
1345
|
+
if (coverageSink) rasterizedGlyphRun(lineBuffer, lineX, lineBoxY, fontId, fontSize, *coverageSink, fontWeight, fontStretch);
|
|
1346
|
+
else drawStyledTextFontFamily(lineBuffer, lineX, lineBoxY, color, fontId, fontSize, fontWeight, fontStretch);
|
|
1325
1347
|
}
|
|
1326
1348
|
}
|
|
1327
1349
|
|
|
@@ -1335,9 +1357,9 @@ private:
|
|
|
1335
1357
|
// appending an ASCII "..." when text-overflow: ellipsis is set, or hard-
|
|
1336
1358
|
// clipping at the box edge otherwise. The truncated run always fits within
|
|
1337
1359
|
// maxWidth, so it never wraps and never spills past the content box.
|
|
1338
|
-
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)
|
|
1360
|
+
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, int fontWeight = 400, int fontStretch = 1000)
|
|
1339
1361
|
{
|
|
1340
|
-
gea::framework::graphics::RasterizedFont font = gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize);
|
|
1362
|
+
gea::framework::graphics::RasterizedFont font = gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize, fontWeight, fontStretch);
|
|
1341
1363
|
if (!font.valid()) return;
|
|
1342
1364
|
|
|
1343
1365
|
const int glyphHeight = font.lineHeight();
|
|
@@ -1417,12 +1439,12 @@ private:
|
|
|
1417
1439
|
if (len <= 0) return;
|
|
1418
1440
|
buf[len] = '\0';
|
|
1419
1441
|
const int xOffset = alignedOffset(textAlign, containerWidth, drawnWidth);
|
|
1420
|
-
if (coverageSink) rasterizedGlyphRun(buf, x + xOffset, lineBoxY, fontId, fontSize, *coverageSink);
|
|
1421
|
-
else
|
|
1442
|
+
if (coverageSink) rasterizedGlyphRun(buf, x + xOffset, lineBoxY, fontId, fontSize, *coverageSink, fontWeight, fontStretch);
|
|
1443
|
+
else drawStyledTextFontFamily(buf, x + xOffset, lineBoxY, color, fontId, fontSize, fontWeight, fontStretch);
|
|
1422
1444
|
}
|
|
1423
1445
|
#endif
|
|
1424
1446
|
|
|
1425
|
-
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)
|
|
1447
|
+
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, int fontWeight = 400, int fontStretch = 1000)
|
|
1426
1448
|
{
|
|
1427
1449
|
if (scale < 0.1f) scale = 1.0f;
|
|
1428
1450
|
int glyphWidth = static_cast<int>(kBitmapFontWidth * scale + 0.5f);
|
|
@@ -1473,7 +1495,7 @@ private:
|
|
|
1473
1495
|
// that is what `measureBitmap` charges for, so counting bytes here put the
|
|
1474
1496
|
// truncation, the ellipsis budget and the alignment offset in different units
|
|
1475
1497
|
// from the layout that placed the text.
|
|
1476
|
-
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)
|
|
1498
|
+
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, int fontWeight = 400, int fontStretch = 1000)
|
|
1477
1499
|
{
|
|
1478
1500
|
(void)lineHeight;
|
|
1479
1501
|
if (scale < 0.1f) scale = 1.0f;
|
|
@@ -1743,6 +1765,7 @@ bool TextRenderer::canFragmentInlineRuns(const Node &node)
|
|
|
1743
1765
|
const int fontId = node.computedStyle().font_id;
|
|
1744
1766
|
const int fontSize = node.computedStyle().font_size > 0 ? node.computedStyle().font_size : kBitmapFontHeight;
|
|
1745
1767
|
const bool hostMeasures =
|
|
1768
|
+
gea_host_measure_text_with_variations("Mg",32767,fontId,fontSize,node.computedStyle().font_weight,node.computedStyle().font_stretch,node.computedStyle().line_height,&w,&h) ||
|
|
1746
1769
|
gea_host_measure_text_with_style("Mg", 32767, fontId, fontSize, node.computedStyle().font_weight, node.computedStyle().line_height, &w, &h) ||
|
|
1747
1770
|
gea_host_measure_text_with_line_height("Mg", 32767, fontId, fontSize, node.computedStyle().line_height, &w, &h) ||
|
|
1748
1771
|
gea_host_measure_text("Mg", 32767, fontId, fontSize, &w, &h);
|
|
@@ -1753,7 +1776,7 @@ bool TextRenderer::canFragmentInlineRuns(const Node &node)
|
|
|
1753
1776
|
int TextRenderer::baselineOffset(const Node &node, bool last)
|
|
1754
1777
|
{
|
|
1755
1778
|
const int fontSize = node.computedStyle().font_size > 0 ? node.computedStyle().font_size : 16;
|
|
1756
|
-
const auto font = gea::framework::graphics::FontRegistry::rasterizedFamily(node.computedStyle().font_id, fontSize);
|
|
1779
|
+
const auto font = gea::framework::graphics::FontRegistry::rasterizedFamily(node.computedStyle().font_id, fontSize, node.computedStyle().font_weight, node.computedStyle().font_stretch);
|
|
1757
1780
|
if (!font.valid()) return node.layout.height + node.computedStyle().margin[2];
|
|
1758
1781
|
const int lineAdvance = node.computedStyle().line_height > 0 ? node.computedStyle().line_height : font.lineHeight();
|
|
1759
1782
|
const int halfLeading = node.computedStyle().line_height > 0 ? (lineAdvance - font.lineHeight()) / 2 : 0;
|
|
@@ -1763,7 +1786,7 @@ int TextRenderer::baselineOffset(const Node &node, bool last)
|
|
|
1763
1786
|
const char *text = prepareText(node.text.c_str(), node.computedStyle().text_transform, node.computedStyle().white_space, storage);
|
|
1764
1787
|
const int width = node.computedStyle().white_space == 1 || node.computedStyle().white_space == 2
|
|
1765
1788
|
? 32767 : std::max(1, node.layout.width - boxInsets(node.computedStyle(), true));
|
|
1766
|
-
const auto measured = TextMetrics::measure(text, width, node.computedStyle().font_id, fontSize, node.computedStyle().line_height, node.computedStyle().font_weight);
|
|
1789
|
+
const auto measured = TextMetrics::measure(text, width, node.computedStyle().font_id, fontSize, node.computedStyle().line_height, node.computedStyle().font_weight, node.computedStyle().font_stretch);
|
|
1767
1790
|
offset += std::max(0, measured.height - lineAdvance);
|
|
1768
1791
|
}
|
|
1769
1792
|
return offset;
|
|
@@ -1934,9 +1957,9 @@ int TextRenderer::reflowToBoxWidth(int id)
|
|
|
1934
1957
|
return measured.width;
|
|
1935
1958
|
}
|
|
1936
1959
|
|
|
1937
|
-
void TextRenderer::drawWrapped(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, float scale, int text_align, int containerWidth, int fontId, int textTransform, int lineHeight, int whiteSpace, int textOverflow, int maxHeight, int firstLineIndent)
|
|
1960
|
+
void TextRenderer::drawWrapped(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, float scale, int text_align, int containerWidth, int fontId, int textTransform, int lineHeight, int whiteSpace, int textOverflow, int maxHeight, int firstLineIndent, int fontWeight, int fontStretch)
|
|
1938
1961
|
{
|
|
1939
|
-
TextDrawer::drawWrapped(text, x, y, maxWidth, color, scale, text_align, containerWidth, fontId, textTransform, lineHeight, whiteSpace, textOverflow, maxHeight, firstLineIndent);
|
|
1962
|
+
TextDrawer::drawWrapped(text, x, y, maxWidth, color, scale, text_align, containerWidth, fontId, textTransform, lineHeight, whiteSpace, textOverflow, maxHeight, firstLineIndent, nullptr, fontWeight, fontStretch);
|
|
1940
1963
|
}
|
|
1941
1964
|
|
|
1942
1965
|
void TextRenderer::unionCoverageRow(const DisplayCommand &command, int screenY, int screenX,
|
|
@@ -2114,7 +2137,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
2114
2137
|
: 0;
|
|
2115
2138
|
commandLineHeight = projectedLineHeight;
|
|
2116
2139
|
const TextMeasure projectedMeasure =
|
|
2117
|
-
TextMetrics::measure(measureText, 32767, n->computedStyle().font_id, projectedFontSize, projectedLineHeight, n->computedStyle().font_weight);
|
|
2140
|
+
TextMetrics::measure(measureText, 32767, n->computedStyle().font_id, projectedFontSize, projectedLineHeight, n->computedStyle().font_weight, n->computedStyle().font_stretch);
|
|
2118
2141
|
drawW = projectedMeasure.width > 0 ? projectedMeasure.width : projectedW;
|
|
2119
2142
|
const int drawH = projectedMeasure.height > 0 ? projectedMeasure.height : (contentH > 0 ? contentH : projectedH);
|
|
2120
2143
|
containerW = drawW;
|
|
@@ -2145,7 +2168,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
2145
2168
|
&ix0,
|
|
2146
2169
|
&iy0,
|
|
2147
2170
|
&ix1,
|
|
2148
|
-
&iy1)) {
|
|
2171
|
+
&iy1,n->computedStyle().font_weight,n->computedStyle().font_stretch)) {
|
|
2149
2172
|
const int inkPad = 2;
|
|
2150
2173
|
bx = drawX + ix0 - inkPad;
|
|
2151
2174
|
by = drawY + iy0 - inkPad;
|
|
@@ -2173,7 +2196,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
2173
2196
|
if (!transformed && inlineIndent == 0) {
|
|
2174
2197
|
const int commandFontSize = static_cast<int>(textScale * kBitmapFontHeight + 0.5f);
|
|
2175
2198
|
const TextMeasure paintMeasure =
|
|
2176
|
-
TextMetrics::measure(measureText, noSoftWrap ? 32767 : drawW, n->computedStyle().font_id, commandFontSize, commandLineHeight, n->computedStyle().font_weight);
|
|
2199
|
+
TextMetrics::measure(measureText, noSoftWrap ? 32767 : drawW, n->computedStyle().font_id, commandFontSize, commandLineHeight, n->computedStyle().font_weight, n->computedStyle().font_stretch);
|
|
2177
2200
|
if (paintMeasure.width > 0 && paintMeasure.height > 0) {
|
|
2178
2201
|
// CSS: a flex container's bare text becomes an anonymous flex item, so
|
|
2179
2202
|
// align-items centers (or end-aligns) it on the cross axis. This node
|
|
@@ -2202,7 +2225,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
2202
2225
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
2203
2226
|
if (n->computedStyle().font_id >= 0) {
|
|
2204
2227
|
gea::framework::graphics::RasterizedFont font =
|
|
2205
|
-
gea::framework::graphics::FontRegistry::rasterizedFamily(n->computedStyle().font_id, commandFontSize);
|
|
2228
|
+
gea::framework::graphics::FontRegistry::rasterizedFamily(n->computedStyle().font_id, commandFontSize,n->computedStyle().font_weight,n->computedStyle().font_stretch);
|
|
2206
2229
|
const int lineAdvance = commandLineHeight > 0 ? commandLineHeight : (font.valid() ? font.lineHeight() : 0);
|
|
2207
2230
|
const bool singleLine = font.valid() &&
|
|
2208
2231
|
std::strchr(measureText, '\n') == nullptr &&
|
|
@@ -2218,7 +2241,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
2218
2241
|
containerW,
|
|
2219
2242
|
n->computedStyle().font_id,
|
|
2220
2243
|
commandFontSize,
|
|
2221
|
-
commandLineHeight);
|
|
2244
|
+
commandLineHeight,n->computedStyle().font_weight,n->computedStyle().font_stretch);
|
|
2222
2245
|
}
|
|
2223
2246
|
}
|
|
2224
2247
|
#endif
|
|
@@ -2243,7 +2266,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
2243
2266
|
&ix0,
|
|
2244
2267
|
&iy0,
|
|
2245
2268
|
&ix1,
|
|
2246
|
-
&iy1)) {
|
|
2269
|
+
&iy1,n->computedStyle().font_weight,n->computedStyle().font_stretch)) {
|
|
2247
2270
|
// A nowrap run may be clipped/ellipsized horizontally, so its
|
|
2248
2271
|
// unbounded ink X extent is not a valid command bound. Its Y ink
|
|
2249
2272
|
// extent is still exact, however, and is essential when CSS
|
|
@@ -2269,7 +2292,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
2269
2292
|
if (std::getenv("GEA_TEXT_BASELINE_DEBUG") && n->computedStyle().font_id >= 0) {
|
|
2270
2293
|
const int dbgFontSize = static_cast<int>(textScale * kBitmapFontHeight + 0.5f);
|
|
2271
2294
|
gea::framework::graphics::RasterizedFont dbgFont =
|
|
2272
|
-
gea::framework::graphics::FontRegistry::rasterizedFamily(n->computedStyle().font_id, dbgFontSize);
|
|
2295
|
+
gea::framework::graphics::FontRegistry::rasterizedFamily(n->computedStyle().font_id, dbgFontSize,n->computedStyle().font_weight,n->computedStyle().font_stretch);
|
|
2273
2296
|
const int fontLH = dbgFont.valid() ? dbgFont.lineHeight() : -1;
|
|
2274
2297
|
const int asc = dbgFont.valid() ? dbgFont.ascender() : -1;
|
|
2275
2298
|
const int lineAdv = commandLineHeight > 0 ? commandLineHeight : fontLH;
|
|
@@ -2278,7 +2301,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
2278
2301
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
2279
2302
|
const int genFonts = 1;
|
|
2280
2303
|
inkOff = rasterizedSingleLineInkCenterOffsetY(measureText, n->computedStyle().text_align, containerW,
|
|
2281
|
-
n->computedStyle().font_id, dbgFontSize, commandLineHeight);
|
|
2304
|
+
n->computedStyle().font_id, dbgFontSize, commandLineHeight,n->computedStyle().font_weight,n->computedStyle().font_stretch);
|
|
2282
2305
|
#else
|
|
2283
2306
|
const int genFonts = 0;
|
|
2284
2307
|
#endif
|
|
@@ -2316,6 +2339,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
2316
2339
|
cmd->text.lineHeight = commandLineHeight;
|
|
2317
2340
|
cmd->text.containerWidth = containerW;
|
|
2318
2341
|
cmd->text.fontId = n->computedStyle().font_id;
|
|
2342
|
+
cmd->text.fontWeight=n->computedStyle().font_weight;cmd->text.fontStretch=n->computedStyle().font_stretch;
|
|
2319
2343
|
cmd->text.whiteSpace = n->computedStyle().white_space;
|
|
2320
2344
|
cmd->text.textOverflow = n->computedStyle().text_overflow;
|
|
2321
2345
|
cmd->text.firstLineIndent = static_cast<int16_t>(inlineIndent);
|
|
@@ -2332,7 +2356,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
|
|
|
2332
2356
|
// past the actual glyphs.
|
|
2333
2357
|
if (n->computedStyle().text_decoration != 0 && !n->text.empty()) {
|
|
2334
2358
|
const int fontSize = n->computedStyle().font_size > 0 ? n->computedStyle().font_size : kBitmapFontHeight;
|
|
2335
|
-
const int lineWidth = TextMetrics::measure(measureText, tw, n->computedStyle().font_id, n->computedStyle().font_size, 0, n->computedStyle().font_weight).width;
|
|
2359
|
+
const int lineWidth = TextMetrics::measure(measureText, tw, n->computedStyle().font_id, n->computedStyle().font_size, 0, n->computedStyle().font_weight, n->computedStyle().font_stretch).width;
|
|
2336
2360
|
const int lineHeight = textDecorationThickness(fontSize);
|
|
2337
2361
|
const int lineY = textDecorationY(ty, fontSize, lineHeight, n->computedStyle().text_decoration);
|
|
2338
2362
|
DisplayCommand *deco = DisplayList::instance().append();
|