@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/ui/style.cpp CHANGED
@@ -599,6 +599,7 @@ bool styleEqualExceptTextPaint(const ComputedStyle &a, const ComputedStyle &b)
599
599
  a.font_id != b.font_id ||
600
600
  a.font_size != b.font_size ||
601
601
  a.font_weight != b.font_weight ||
602
+ a.font_stretch != b.font_stretch ||
602
603
  a.line_height != b.line_height ||
603
604
  a.text_align != b.text_align ||
604
605
  a.overflow != b.overflow ||
@@ -718,6 +719,7 @@ bool styleEqualExceptLocalDisplayCommands(const ComputedStyle &a, const Computed
718
719
  a.font_id != b.font_id ||
719
720
  a.font_size != b.font_size ||
720
721
  a.font_weight != b.font_weight ||
722
+ a.font_stretch != b.font_stretch ||
721
723
  a.line_height != b.line_height ||
722
724
  a.text_align != b.text_align ||
723
725
  a.overflow != b.overflow ||
@@ -1241,6 +1243,7 @@ CssDeclarationId classifyDeclaration(const char *property)
1241
1243
  if (std::strcmp(property, "border-bottom-left-radius") == 0) return CssDeclarationId::BorderBottomLeftRadius;
1242
1244
  if (std::strcmp(property, "font-family") == 0) return CssDeclarationId::FontFamily;
1243
1245
  if (std::strcmp(property, "font-size") == 0) return CssDeclarationId::FontSize;
1246
+ if (std::strcmp(property, "font-stretch") == 0) return CssDeclarationId::FontStretch;
1244
1247
  if (std::strcmp(property, "font-weight") == 0) return CssDeclarationId::FontWeight;
1245
1248
  if (std::strcmp(property, "line-height") == 0) return CssDeclarationId::LineHeight;
1246
1249
  if (std::strcmp(property, "text-align") == 0) return CssDeclarationId::TextAlign;
@@ -4093,6 +4096,24 @@ int fontSizeValue(const std::string &value, int nodeId)
4093
4096
  return parseLengthForNode(value, nodeId, LengthAxis::Vertical);
4094
4097
  }
4095
4098
 
4099
+ int fontStretchValue(const std::string &value)
4100
+ {
4101
+ const std::string token = toLowerAscii(trimCssValue(value));
4102
+ if (token == "normal") return 1000;
4103
+ if (token == "ultra-condensed") return 500;
4104
+ if (token == "extra-condensed") return 625;
4105
+ if (token == "condensed") return 750;
4106
+ if (token == "semi-condensed") return 875;
4107
+ if (token == "semi-expanded") return 1125;
4108
+ if (token == "expanded") return 1250;
4109
+ if (token == "extra-expanded") return 1500;
4110
+ if (token == "ultra-expanded") return 2000;
4111
+ char *end = nullptr;
4112
+ const double number = std::strtod(token.c_str(), &end);
4113
+ if (!std::isfinite(number) || number <= 0 || !end || std::strcmp(end, "%") != 0) return -1;
4114
+ return static_cast<int>(std::clamp(std::round(number * 10.0), 1.0, 32767.0));
4115
+ }
4116
+
4096
4117
  int fontWeightValue(const std::string &rawValue)
4097
4118
  {
4098
4119
  const std::string value = toLowerAscii(trimCssValue(rawValue));
@@ -7191,6 +7212,9 @@ bool compileKeywordValue(CssDeclarationId declaration, const std::string &value,
7191
7212
  compiled.values[0] = fontFamilyValue(value);
7192
7213
  return true;
7193
7214
  }
7215
+ case CssDeclarationId::FontStretch:
7216
+ compiled.values[0] = fontStretchValue(value);
7217
+ return compiled.values[0] > 0;
7194
7218
  case CssDeclarationId::FontWeight:
7195
7219
  compiled.values[0] = fontWeightValue(value);
7196
7220
  return true;
@@ -7771,7 +7795,7 @@ bool isLineHeightProperty(Property property)
7771
7795
 
7772
7796
  bool isFontMetricProperty(Property property)
7773
7797
  {
7774
- return property == Property::FontId || property == Property::FontSize || property == Property::FontWeight;
7798
+ return property == Property::FontId || property == Property::FontSize || property == Property::FontWeight || property == Property::FontStretch;
7775
7799
  }
7776
7800
 
7777
7801
  void applyGridTemplateValue(NodeHandle node, const std::string &value, bool columns)
@@ -8308,6 +8332,9 @@ bool setClassRuleValueFastUnchecked(Node &target, Property property, int value)
8308
8332
  #if GEA_CSS_FONT_WEIGHT
8309
8333
  case Property::FontWeight: style.font_weight = value; return true;
8310
8334
  #endif
8335
+ #if GEA_CSS_FONT_STRETCH
8336
+ case Property::FontStretch: style.font_stretch = value; return true;
8337
+ #endif
8311
8338
  #if GEA_CSS_LINE_HEIGHT
8312
8339
  case Property::LineHeight:
8313
8340
  #if GEA_CSS_LINE_HEIGHT_MULTIPLIER
@@ -9303,19 +9330,19 @@ bool resolveLayoutBoxLengths(int nodeId, int percentageBasis)
9303
9330
 
9304
9331
  void Style::set(Property property, int value) const
9305
9332
  {
9306
- if (nodeId_ < 0) return;
9333
+ if (nodeId() < 0) return;
9307
9334
  #if GEA_CSS_ANIMATIONS
9308
9335
  double before = 0;
9309
- const bool transition = inlineTransitionBefore(nodeId_, property, before);
9336
+ const bool transition = inlineTransitionBefore(nodeId(), property, before);
9310
9337
  #endif
9311
- Tree::instance().setStyle(nodeId_, property, value);
9338
+ Tree::instance().setStyle(nodeId(), property, value);
9312
9339
  #if GEA_CSS_ANIMATIONS
9313
- if (transition) applyInlineTransition(nodeId_, property, before);
9340
+ if (transition) applyInlineTransition(nodeId(), property, before);
9314
9341
  #endif
9315
9342
  // This element's cascaded lengths can depend on its own font too. Updating
9316
9343
  // descendants alone leaves, for example, class padding in ch at old metrics.
9317
- if (isFontMetricProperty(property) || isLineHeightProperty(property)) recomputeSubtreeClassStyles(nodeId_);
9318
- else if (propertyAffectsDescendantStyle(property)) recomputeDescendantClassStyles(nodeId_);
9344
+ if (isFontMetricProperty(property) || isLineHeightProperty(property)) recomputeSubtreeClassStyles(nodeId());
9345
+ else if (propertyAffectsDescendantStyle(property)) recomputeDescendantClassStyles(nodeId());
9319
9346
  }
9320
9347
 
9321
9348
  void Style::backgroundColor(int rgb565) const
@@ -9326,20 +9353,20 @@ void Style::backgroundColor(int rgb565) const
9326
9353
 
9327
9354
  void Style::setProperty(const std::string &property, const std::string &value) const
9328
9355
  {
9329
- if (nodeId_ < 0) return;
9330
- StyleSheet::instance().applyProperty(NodeHandle(nodeId_), property, value);
9356
+ if (nodeId() < 0) return;
9357
+ StyleSheet::instance().applyProperty(NodeHandle(nodeId()), property, value);
9331
9358
  }
9332
9359
 
9333
9360
  bool Style::setNumberProperty(const std::string &property, double value) const
9334
9361
  {
9335
- if (nodeId_ < 0) return false;
9336
- return StyleSheet::instance().applyNumberProperty(NodeHandle(nodeId_), property.c_str(), value);
9362
+ if (nodeId() < 0) return false;
9363
+ return StyleSheet::instance().applyNumberProperty(NodeHandle(nodeId()), property.c_str(), value);
9337
9364
  }
9338
9365
 
9339
9366
  bool Style::removeProperty(const std::string &property) const
9340
9367
  {
9341
- if (nodeId_ < 0) return false;
9342
- return StyleSheet::instance().removeProperty(NodeHandle(nodeId_), property);
9368
+ if (nodeId() < 0) return false;
9369
+ return StyleSheet::instance().removeProperty(NodeHandle(nodeId()), property);
9343
9370
  }
9344
9371
 
9345
9372
  void applyAnimatedStyleValue(int nodeId, Property property, int value)
@@ -9377,6 +9404,9 @@ void applyInheritedStyleDefaults(int node)
9377
9404
  style.text_color = parentStyle.text_color;
9378
9405
  #if GEA_CSS_TEXT_ALPHA
9379
9406
  style.text_alpha = parentStyle.text_alpha;
9407
+ #endif
9408
+ #if GEA_CSS_FONT_STRETCH
9409
+ style.font_stretch = parentStyle.font_stretch;
9380
9410
  #endif
9381
9411
  style.font_id = parentStyle.font_id;
9382
9412
  style.font_size = parentStyle.font_size;
@@ -9523,6 +9553,12 @@ bool applyNumberDeclarationWithSource(NodeHandle node,
9523
9553
  case CssDeclarationId::FontSize:
9524
9554
  setStyleValue(node, Property::FontSize, length, source);
9525
9555
  return true;
9556
+ #if GEA_CSS_FONT_STRETCH
9557
+ case CssDeclarationId::FontStretch:
9558
+ if (!std::isfinite(value) || value <= 0) return false;
9559
+ setStyleValue(node, Property::FontStretch, std::clamp(roundToInt(std::clamp(value, 0.1, 3276.7) * 10), 1, 32767), source);
9560
+ return true;
9561
+ #endif
9526
9562
  case CssDeclarationId::FontWeight:
9527
9563
  setStyleValue(node, Property::FontWeight, std::clamp(roundToInt(value), 1, 1000), source);
9528
9564
  return true;
@@ -9622,6 +9658,10 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
9622
9658
  case CssDeclarationId::WritingMode:
9623
9659
  return false;
9624
9660
  #endif
9661
+ #if !GEA_CSS_FONT_STRETCH
9662
+ case CssDeclarationId::FontStretch:
9663
+ return false;
9664
+ #endif
9625
9665
 
9626
9666
  case CssDeclarationId::BackgroundClip: {
9627
9667
  const int parent = Tree::instance().node(nodeId).parent;
@@ -10074,6 +10114,9 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
10074
10114
  case CssDeclarationId::Font: {
10075
10115
  ParsedFontShorthand font;
10076
10116
  if (!parseFontShorthand(value, font)) return true;
10117
+ #if GEA_CSS_FONT_STRETCH
10118
+ setStyleValue(node, Property::FontStretch, 1000, source);
10119
+ #endif
10077
10120
  setStyleValue(node, Property::FontWeight, font.weight, source);
10078
10121
  setStyleValue(node, Property::FontId, fontFamilyValue(font.family), source);
10079
10122
  setLengthStyleValue(node, font.size, Property::FontSize, fontSizeValue(font.size, nodeId), source);
@@ -10083,6 +10126,13 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
10083
10126
  case CssDeclarationId::FontSize:
10084
10127
  setLengthStyleValue(node, value, Property::FontSize, fontSizeValue(value, nodeId), source);
10085
10128
  return true;
10129
+ #if GEA_CSS_FONT_STRETCH
10130
+ case CssDeclarationId::FontStretch: {
10131
+ const int stretch = fontStretchValue(value);
10132
+ if (stretch > 0) setStyleValue(node, Property::FontStretch, stretch, source);
10133
+ return true;
10134
+ }
10135
+ #endif
10086
10136
  case CssDeclarationId::FontWeight:
10087
10137
  setStyleValue(node, Property::FontWeight, fontWeightValue(value), source);
10088
10138
  return true;
@@ -11170,6 +11220,7 @@ bool applyCompiledCssValueWithSource(NodeHandle node, const CssCompiledValue &co
11170
11220
  case CssDeclarationId::OverflowX: setStyleValue(node, Property::OverflowX, compiled.values[0], source); return true;
11171
11221
  case CssDeclarationId::OverflowY: setStyleValue(node, Property::OverflowY, compiled.values[0], source); return true;
11172
11222
  case CssDeclarationId::FontFamily: setStyleValue(node, Property::FontId, compiled.values[0], source); return true;
11223
+ case CssDeclarationId::FontStretch: setStyleValue(node, Property::FontStretch, compiled.values[0], source); return true;
11173
11224
  case CssDeclarationId::FontWeight: setStyleValue(node, Property::FontWeight, compiled.values[0], source); return true;
11174
11225
  default: return false;
11175
11226
  }
@@ -14008,6 +14059,7 @@ bool addCachedKeywordDeclaration(CachedStyleApplyOp &op, CssDeclarationId declar
14008
14059
  case CssDeclarationId::OverflowX: return addCachedStyleApplyProperty(op, Property::OverflowX, value);
14009
14060
  case CssDeclarationId::OverflowY: return addCachedStyleApplyProperty(op, Property::OverflowY, value);
14010
14061
  case CssDeclarationId::FontFamily: return addCachedStyleApplyProperty(op, Property::FontId, value);
14062
+ case CssDeclarationId::FontStretch: return addCachedStyleApplyProperty(op, Property::FontStretch, value);
14011
14063
  case CssDeclarationId::FontWeight: return addCachedStyleApplyProperty(op, Property::FontWeight, value);
14012
14064
  default: return false;
14013
14065
  }
@@ -14919,6 +14971,7 @@ bool addCompiledValueWrites(const CssCompiledValue &compiled, PropertyWriteMask
14919
14971
  case CssDeclarationId::OverflowX: addPropertyWrite(mask, Property::OverflowX); return true;
14920
14972
  case CssDeclarationId::OverflowY: addPropertyWrite(mask, Property::OverflowY); return true;
14921
14973
  case CssDeclarationId::FontFamily: addPropertyWrite(mask, Property::FontId); return true;
14974
+ case CssDeclarationId::FontStretch: addPropertyWrite(mask, Property::FontStretch); return true;
14922
14975
  case CssDeclarationId::FontWeight: addPropertyWrite(mask, Property::FontWeight); return true;
14923
14976
  default: return false;
14924
14977
  }
@@ -15721,7 +15774,7 @@ void applyCachedRuleWithSource(NodeHandle node, const CachedRuleApply &op, Style
15721
15774
  bool setsFontMetrics(CssDeclarationId declaration)
15722
15775
  {
15723
15776
  return declaration == CssDeclarationId::Font || declaration == CssDeclarationId::FontFamily ||
15724
- declaration == CssDeclarationId::FontSize || declaration == CssDeclarationId::FontWeight;
15777
+ declaration == CssDeclarationId::FontSize || declaration == CssDeclarationId::FontWeight || declaration == CssDeclarationId::FontStretch;
15725
15778
  }
15726
15779
 
15727
15780
  void applyActiveRuleSpanToNode(int node, const ActiveRulePlan &plan, int bucketId, int metricsOnly = 0)
@@ -16070,6 +16123,11 @@ struct ParentStyleSnapshot {
16070
16123
  std::uint8_t text_alpha;
16071
16124
  #else
16072
16125
  static constexpr std::uint8_t text_alpha = 255;
16126
+ #endif
16127
+ #if GEA_CSS_FONT_STRETCH
16128
+ std::int16_t font_stretch;
16129
+ #else
16130
+ static constexpr std::int16_t font_stretch = 1000;
16073
16131
  #endif
16074
16132
  std::int16_t font_id;
16075
16133
  decltype(ComputedStyle::font_size) font_size;
@@ -16127,6 +16185,9 @@ ParentStyleSnapshot snapshotParentStyle(const ComputedStyle &s)
16127
16185
  #if GEA_CSS_FONT_WEIGHT
16128
16186
  out.font_weight = s.font_weight;
16129
16187
  #endif
16188
+ #if GEA_CSS_FONT_STRETCH
16189
+ out.font_stretch = s.font_stretch;
16190
+ #endif
16130
16191
  #if GEA_CSS_LINE_HEIGHT
16131
16192
  out.line_height = s.line_height;
16132
16193
  #endif
@@ -16157,7 +16218,8 @@ ParentStyleSnapshot snapshotParentStyle(const ComputedStyle &s)
16157
16218
  bool parentStylesDiffer(const ParentStyleSnapshot &a, const ParentStyleSnapshot &b)
16158
16219
  {
16159
16220
  return a.text_color != b.text_color || a.text_alpha != b.text_alpha || a.font_id != b.font_id || a.font_size != b.font_size ||
16160
- a.font_weight != b.font_weight || a.line_height != b.line_height || a.line_height_multiplier != b.line_height_multiplier ||
16221
+ a.font_weight != b.font_weight ||
16222
+ a.font_stretch != b.font_stretch || a.line_height != b.line_height || a.line_height_multiplier != b.line_height_multiplier ||
16161
16223
  a.text_align != b.text_align || a.text_transform != b.text_transform ||
16162
16224
  a.white_space != b.white_space || a.visibility != b.visibility || a.border_widths != b.border_widths;
16163
16225
  }
@@ -17616,19 +17678,28 @@ BackgroundPlacement StyleValues::backgroundPlacement(const ComputedStyle &style,
17616
17678
  if (const auto *v = entry(r.bg_attachment_list)) out.attachment = v->a;
17617
17679
  if (const auto *v = entry(r.bg_origin_list)) out.origin = v->a;
17618
17680
  if (const auto *v = entry(r.bg_repeat_list)) { out.repeatX = v->a; out.repeatY = v->b; }
17619
- const Node &node = treeState().nodes[nodeId];
17681
+ // nodeId comes from ViewGeometry::nodeIndex(), which is -1 for a box that is
17682
+ // not a slot of the tree (a Node recorded straight from the stack, as the
17683
+ // renderer tests do). Indexing nodes[-1] read whatever sits before the heap
17684
+ // TreeState and handed its garbage rare_style handle to rstyle(), so the
17685
+ // result -- and whether the process segfaulted -- depended on the address
17686
+ // layout. Such a box has no scroll state, and its own style is the only
17687
+ // border/padding there is to inset by.
17688
+ const auto &state = treeState();
17689
+ const Node *node = nodeId >= 0 && nodeId < state.nodeCount ? &state.nodes[nodeId] : nullptr;
17690
+ const ComputedStyle &box = node ? node->computedStyle() : style;
17620
17691
  if (out.attachment == 1) {
17621
- x = y = 0; width = treeState().mountedWidth; height = treeState().mountedHeight;
17692
+ x = y = 0; width = state.mountedWidth; height = state.mountedHeight;
17622
17693
  } else {
17623
- if (out.attachment == 2) {
17624
- width = std::max<int>(width, node.layout.scroll_content_width);
17625
- height = std::max<int>(height, node.layout.scroll_content_height);
17626
- x -= node.layout.scroll_x; y -= node.layout.scroll_y;
17694
+ if (out.attachment == 2 && node) {
17695
+ width = std::max<int>(width, node->layout.scroll_content_width);
17696
+ height = std::max<int>(height, node->layout.scroll_content_height);
17697
+ x -= node->layout.scroll_x; y -= node->layout.scroll_y;
17627
17698
  }
17628
17699
  if (out.origin != 0) {
17629
17700
  int inset[4];
17630
- for (int i = 0; i < 4; ++i) inset[i] = computedBorderWidth(node.computedStyle(), i) +
17631
- (out.origin == 2 ? std::max<int>(0, node.computedStyle().padding[i]) : 0);
17701
+ for (int i = 0; i < 4; ++i) inset[i] = computedBorderWidth(box, i) +
17702
+ (out.origin == 2 ? std::max<int>(0, box.padding[i]) : 0);
17632
17703
  x += inset[3]; y += inset[0]; width -= inset[1]+inset[3]; height -= inset[0]+inset[2];
17633
17704
  }
17634
17705
  }
package/ui/style.h CHANGED
@@ -1,6 +1,7 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  #pragma once
3
3
 
4
+ #include "native_identity.h"
4
5
  #include <cstdint>
5
6
  #include <initializer_list>
6
7
  #include <string>
@@ -212,6 +213,7 @@ enum class Property : int {
212
213
  BorderBottomRelief,
213
214
  BorderLeftRelief,
214
215
  BorderRelief,
216
+ FontStretch,
215
217
  Count
216
218
  };
217
219
 
@@ -346,14 +348,16 @@ enum class StyleDeclaration : std::uint8_t {
346
348
  BackgroundOrigin,
347
349
  MarginTrim,
348
350
  Transition,
349
- AnimationPlayState
351
+ AnimationPlayState,
352
+ FontStretch
350
353
  };
351
354
 
352
355
  class Style {
353
356
  public:
354
- explicit Style(int nodeId = -1) : nodeId_(nodeId) {}
357
+ explicit Style(int nodeId = -1)
358
+ : nodeId_(nodeId), identity_(gea::framework::identity::node(nodeId)) {}
355
359
 
356
- int nodeId() const { return nodeId_; }
360
+ int nodeId() const { return gea::framework::identity::current(nodeId_, identity_) ? nodeId_ : -1; }
357
361
  void set(Property property, int value) const;
358
362
 
359
363
  void width(int value) const { set(Property::Width, value); }
@@ -387,6 +391,7 @@ public:
387
391
 
388
392
  private:
389
393
  int nodeId_;
394
+ gea::framework::identity::Owner identity_;
390
395
  };
391
396
 
392
397
  class NodeHandle;