drawnui-react 0.1.0-preview.31 → 0.1.0-preview.33

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/SKIPPED.md CHANGED
@@ -19,7 +19,7 @@ DrawnUi name and semantics; nothing here is a redesign, only an omission.
19
19
  | Disposal (`Dispose` / `OnDisposing`) | ported | The React renderer calls `Dispose()` when an element leaves the tree (`detachDeletedInstance`): caches, gradient shaders, running `*ToAsync` animations, overlay effects, the accessibility node, then the children (static and templated pool); `SkiaScroll`/`SnappingLayout` stop their animators, `SkiaSvg` drops its raster, `SkiaLottie`/`SkiaGif` free the Skottie animation / frames; `Canvas.Dispose` disposes the content. Not ported: `IsDisposing` staged disposal, `Disposing` event, `OnWillDisposeWithChildren`. |
20
20
  | Hover: `ReceivesHover` (opt-in; on by default in SkiaButton, SkiaSlider, the toggles, SkiaRadioButton, SkiaCarousel, SkiaDrawer), `IsHovered`, `HoverChanged` (turns `ReceivesHover` on, as C# `OnHovered`) | ported | drawnui-cross 6m: every opted-in control under the mouse is hovered; nothing changes while a scroll, carousel or drawer moves its content, one check at the last pointer position when it stops and after an add / remove, a rebind, a hidden hovered control or an instant scroll jump; pointerleave clears at once; touch never hovers (`Canvas.Hover`, a `HoverManager`). Not ported: C# `SetHover`, `CheckHovered` / `OnHover` / `IsPointerOver` (no Pointer gestures are routed), SkiaSpinner / wheel picker (no such controls). |
21
21
  | `KeyboardManager` | ported | Window-level keydown / keyup capture listeners like `drawnui-keyboard.js`: `KeyDown` / `KeyUp` with the DOM `event.code` ("KeyA", "ArrowLeft"; C# maps the same codes to `InputKey`), `KeyChar` for printable keys without Ctrl / Alt / Meta, `IsShiftPressed` / `IsControlPressed` / `IsAltPressed`, `AttachToKeyboard` (idempotent, pointerdown pulls window focus inside iframes), `BlurExternalTextInput`, `IsOwnedByElement` / `IsInputMethodKey` (React additions: a handler acting on keys skips keys a focused DOM element or the input method owns, C# 845b26e9); `Subscribe` / `Unsubscribe` instead of C# events. Not ported: `InputKey` enum (codes are strings). |
22
- | `SkiaEditor` | partial | SkiaShape host with padding, content `SkiaLabel` (single-line: `HorizontalTextAlignment` Center / End get the field as the label's minimum width, so short text centers and long text still scrolls), placeholder label, caret (blinking 1 s, `CursorColor`, `CanShowCursor`) and selection overlay (`SelectionColor`) painted by the editor, single line (`MaxLines` 1, scrolls horizontally to the caret) / multiline (`MaxLines` != 1, `AutoHeight`) with own scroll offsets instead of the C# inner `SkiaScroll`; `Text` (line breaks normalized, spaces for single line), `PlaceholderText/Color/HorizontalAlignment`, `FontSize` (12) / `FontFamily` / `FontWeight` / `TextColor` / `TextGradient` / `LineHeight` / `Horizontal|VerticalTextAlignment`, `IsPassword` (bullets), `ReturnType` (Send submits multiline), `KeyboardType` / `IsSpellCheckEnabled` / `UseMarkdown` / `UseUnicode` accepted, `CursorPosition`, `SelectionLength`, `IsFocused` (one focused editor at a time), `ControlStyle` (C# `ApplyControlStyleVisuals` palettes over unset values), events `TextChanged` / `FocusChanged` / `CursorMoved` / `TextSubmitted`, `Submit` / `SelectAll` / `SetSelection` / `SelectWord` / `GetSelectedText` / `DeleteSelection` / `InsertAtCursor` / `CutSelection` / `CopySelection` / `PasteFromClipboard` (navigator.clipboard), the Blazor head stubs `StubTypeText` / `StubPressEnter` / `StubBackspace` / `StubDelete` (grapheme clusters via Intl.Segmenter) / `StubMoveCursor` / `StubSelectRange` / `StubSelectAll` / `HandleVerticalArrow`, Ctrl+A / C / X / V, Home / End, Escape blurs, tap places the caret, drag selects, long press selects a word, shift + tap extends. Keys come from `KeyboardManager` like the Blazor / Wasm heads; on top of that (not in DrawnUi.Blazor) a focused editor is mirrored by a hidden DOM textarea (`TextInputProxy`, `inputmode` from `KeyboardType`, `enterkeyhint` from `ReturnType`) so IME composition, the mobile soft keyboard, autocorrect and native paste / cut / undo reach the editor: every input event is diffed against the editor text and replayed through `StubSelectRange` + `StubTypeText` / `StubBackspace` / `StubPressEnter`; while the proxy holds DOM focus, Backspace / Delete / Enter / Ctrl+C / X / V key events are left to it. iOS may need a second tap for the keyboard (focus() runs on the next frame, outside the touch handler). Not ported: `SkiaCursor` control + `CursorGradient`, `SkiaEditorSelection` handles, `Superview.FocusedChild`, `CommandOn*`, `SkiaEditorDocument` (rich formatting), single-line Enter clearing focus (Blazor keeps it). Right-to-left and mixed text: the caret, taps, Left / Right (visual moves) and the selection follow the screen, stops at grapheme boundaries (drawnui-cross 6ak, same rules as DrawnUi.Rust). |
22
+ | `SkiaEditor` | partial | SkiaShape host with padding, content `SkiaLabel` (single-line: `HorizontalTextAlignment` Center / End get the field as the label's minimum width, so short text centers and long text still scrolls), placeholder label, caret (blinking 1 s, `CursorColor`, `CanShowCursor`) and selection overlay (`SelectionColor`) painted by the editor, single line (`MaxLines` 1, scrolls horizontally to the caret) / multiline (`MaxLines` != 1, `AutoHeight`) with own scroll offsets instead of the C# inner `SkiaScroll`; `Text` (line breaks normalized, spaces for single line), `PlaceholderText/Color/HorizontalAlignment`, `FontSize` (12) / `FontFamily` / `FontWeight` / `TextColor` / `TextGradient` / `LineHeight` / `Horizontal|VerticalTextAlignment`, `IsPassword` (bullets), `ReturnType` (Send submits multiline), `KeyboardType` / `IsSpellCheckEnabled` / `UseMarkdown` / `UseUnicode` accepted, `CursorPosition`, `SelectionLength`, `IsFocused` (one focused editor at a time), `ControlStyle` (C# `ApplyControlStyleVisuals` palettes over unset values), events `TextChanged` / `FocusChanged` / `CursorMoved` / `TextSubmitted`, `Submit` / `SelectAll` / `SetSelection` / `SelectWord` / `GetSelectedText` / `DeleteSelection` / `InsertAtCursor` / `CutSelection` / `CopySelection` / `PasteFromClipboard` (navigator.clipboard), the Blazor head stubs `StubTypeText` / `StubPressEnter` / `StubBackspace` / `StubDelete` (grapheme clusters via Intl.Segmenter) / `StubMoveCursor` / `StubSelectRange` / `StubSelectAll` / `HandleVerticalArrow`, Ctrl+A / C / X / V, Home / End, Escape blurs, tap places the caret, drag selects, long press selects a word, shift + tap extends. Keys come from `KeyboardManager` like the Blazor / Wasm heads; on top of that (not in DrawnUi.Blazor) a focused editor is mirrored by a hidden DOM textarea (`TextInputProxy`, `inputmode` from `KeyboardType`, `enterkeyhint` from `ReturnType`) so IME composition, the mobile soft keyboard, autocorrect and native paste / cut / undo reach the editor: every input event is diffed against the editor text and replayed through `StubSelectRange` + `StubTypeText` / `StubBackspace` / `StubPressEnter`; while the proxy holds DOM focus, Backspace / Delete / Enter / Ctrl+C / X / V key events are left to it. iOS may need a second tap for the keyboard (focus() runs on the next frame, outside the touch handler). Not ported: `SkiaCursor` control + `CursorGradient`, `SkiaEditorSelection` handles, `Superview.FocusedChild`, `CommandOn*`, `SkiaEditorDocument` (rich formatting), single-line Enter clearing focus (Blazor keeps it). Right-to-left and mixed text: a single-line field starts a right-to-left paragraph at its right edge; the caret, taps, Left / Right (visual moves) and the selection follow the screen, stops at grapheme boundaries (drawnui-cross 6ak, same rules as DrawnUi.Rust). |
23
23
  | `SkiaSprite` / `SkiaSpriteSet` | ported | Sprite: `Source` (sheets cached per source, `CachedSpriteSheets`), `Columns` / `Rows` / `MaxFrames`, `FramesPerSecond` (24), `FrameSequence` / `AnimationName` + `CreateAnimationSequence` / `RegisteredAnimations`, `CurrentFrame`, `TotalFrames` / `DurationMs` / `FrameDurationMs` / `FrameWidth` / `FrameHeight`, `ApplyPlacementConfig` (units-per-pixel, size, anchor, offset = C# SpriteFrameImage ResolveFrameMetrics), transparent frame borders trimmed per frame (pixels read once), nearest sampling, AspectFit of the frame, `DisplayRect`, `Success` / `Error`, the AnimatedFramesRenderer playback. Set: `State`, `Define(state, source, columns, rows, fps, repeat, autoPlay, placement)`, `CurrentSprite`, `OnChangeState` hook, hit box from the drawn frame. Not ported: `Display` as a separate SkiaImage child (`SpriteFrameImage`) and the standalone `SkiaSprite(display)` ctor, `RescalingQuality` other than None, `InflateAmount`, `ClearCache` / `RemoveFromCache` (SkiaImageManager owns the images), `SkiaSpriteSet.InvalidateInternal`. Code-behind subclasses (FastRepro `WarriorSprite`) mount through a ref + `AddSubView` and are disposed by the mounting effect. |
24
24
  | `IsClippedToBounds`, `ClipEffects` | ported | Clip to `DrawingRect` around content, children and post-animators; `ClipEffects=false` grows the clip by the aggregated effects margin so a child's shadow/glow can escape. Layouts aggregate their children's effects margins (C# `AggregatedEffectsMarginPixels`), cached per control and reset by `InvalidateMeasure`. Not ported: `Clipping` callback, `ClipWith`, `ClipFrom`, platform clips; C# currently ignores `ClipEffects` in its render path (always expands). |
25
25
  | `Padding` on base `SkiaControl` | skipped | Only `SkiaLayout.Padding` exists. |
@@ -72,7 +72,7 @@ DrawnUi name and semantics; nothing here is a redesign, only an omission.
72
72
  | `SkiaLayout` Wrap (static children) + `SkiaWrap` alias | ported | Left-to-right flow, `Spacing` between items and rows, row height = tallest item. Not ported: `Split`, main-axis `Fill` children sharing a row (1.9.7.4 flex-fill), `UseDynamicColumns`, RTL. |
73
73
  | `SkiaLayout` Masonry + `SkiaMasonry` alias (Split 2, horizontal fill) | ported | C# `MeasureMasonry` / `BuildMasonryLayout`: `Split` columns of width round((width - (Split - 1) * Spacing) / Split), every visible item measured unbounded at that width and placed at the bottom of the shortest column (the first on a tie), `Spacing` between columns and items. Children or `ItemsSource` + `ItemTemplate` (recycled slots, taps, `ScrollToIndex` from the slot rect, `LoadMore`); a templated slot keeps its item's size, so an appended page or a changed item is the only one measured and every item is placed again. No items window. Content = used columns wide, tallest column high. `npm run check:masonry` (C# MasonryLayoutTests) |
74
74
  | `SkiaLayout` Grid (static children) + `SkiaGrid` alias | ported | Port of `SkiaGridStructure` (MAUI grid manager): `ColumnDefinitions`/`RowDefinitions` as `"*, 2*, Auto, 100"` or arrays, `DefaultColumnDefinition`/`DefaultRowDefinition` (Auto, like C#), `ColumnSpacing`/`RowSpacing`, child `Column`/`Row`/`ColumnSpan`/`RowSpan` (plain props instead of attached properties), implicit tracks, unknown/known measure passes, span resolution, star compression, Fill-child minimums, last-track stretch when the grid fills, remeasure at final cells. Not ported: `Split`/`Invert` (templated grids), `UseDynamicColumns`, `SkiaDecoratedGrid`, `GetOrderedSubviews` ZIndex ordering. |
75
- | `SkiaLabel` | partial | Word wrap (+ character break for long words), `MaxLines` with tail ellipsis, `LineBreakMode` (NoWrap / wraps / Tail; Head/Middle behave as Tail), `HorizontalTextAlignment` Start/Center/End, Start and End following each paragraph's direction (a right-to-left paragraph starts at the right; Fill* accepted, not stretched, placed at the paragraph's start), `VerticalTextAlignment`, `LineSpacing`, `LineHeight`, `FontWeight` + `FontAttributes` via faces registered per weight (`AddFont(src, alias, weight)`, nearest weight wins, synthetic bold (`setEmbolden`) when the nearest face is lighter than 600 — C# `Font.Embolden`; italic = synthetic skew when no italic face; empty `FontFamily` = the first registered family, weights included), `TextTransform`, `Padding`, `LinesCount`; text measured with unhinted (linear) advances, the same widths as DrawnUi.Rust on every platform; synthetic italic keeps its slant in every cache type (drawing room only, widths unchanged); defaults as C# (`FontSize` 12, `TextColor` GreenYellow). `FontFamilyFallback` ported and extended: comma-separated chain (`"FontSymbols,FontSymbols2"`), per-codepoint run segmentation, spaces always stay on the main font; `fonts.AddSymbols()` (`FontSymbols` = Noto Sans Math subset, `FontSymbols2` = Noto Sans Symbols 2 subset) and `fonts.AddEmojis()` (`FontEmoji` = Noto Color Emoji subset: faces, hands, skin tones and the demo emoji) ship the same subsets as DrawnUi.Blazor. A joiner, variation selector, skin tone, keycap or tag keeps the font of the glyph before it (C# JoinsPreviousGlyph). Text shaping where the text needs it (C# `UnicodeNeedsShaping` ranges plus Hebrew, Arabic supplements and emoji sequence characters): Arabic joins, Indic conjuncts and marks, emoji sequences as one glyph, through the CanvasKit paragraph module already in the build (HarfBuzz + ICU, no extra wasm); other text keeps the plain glyph-by-glyph path. Right-to-left lines: runs cut where the bidirectional level changes (ICU levels; the paragraph direction from its first strong letter, explicit embeddings reported as their direction only) and placed in visual order (rule L2). A space keeps the style of the span it was written in; where two spans meet with a space each, both stay (C#). `Spans` ported as `<TextSpan>` children: `Text`, `TextColor`/`FontSize`/`FontFamily` (unset = inherit from the label, like C# HasSetColor/HasSetSize/HasSetFont), `FontWeight`, `IsBold`, `IsItalic`, `Underline`/`UnderlineWidth`, `Strikeout`/`StrikeoutWidth`/`StrikeoutColor` (Red default), `BackgroundColor`, `Tapped` + `ForceCaptureInput` (hit-tested through per-fragment `Rects`, ripple on the label, `OnSpanTapped` overridable), mixed sizes on one line share a baseline. TextSpan not ported: `ParagraphColor`, `CommandTapped`, per-span `LineSpacing`/`LineHeight`, `AutoFindFont`, `DrawingOffset`. `CharacterSpacing` (C#: (value - 1) points after every glyph, measured, wrapped and cut at the drawn width), Chinese / Japanese line breaks between characters with kinsoku (C# FitAtBreak, `CanBreakInsideWord`). Text `StrokeColor`/`StrokeWidth`/`StrokeGradient`, `DropShadow*` and `GradientByLines` ported (C# DrawText order). Not ported: `AutoFont`, `AutoSize`/`AutoSizeText`, `MonoForDigits`, `KeepSpacesOnLineBreaks` (accepted, no effect), `Format`, hyphenation, |
75
+ | `SkiaLabel` | partial | Word wrap (+ character break for long words), `MaxLines` with tail ellipsis, `LineBreakMode` (NoWrap / wraps / Tail; Head/Middle behave as Tail), `HorizontalTextAlignment` Start/Center/End, Start and End following each paragraph's direction (a right-to-left paragraph starts at the right; Fill* accepted, not stretched, placed at the paragraph's start), `VerticalTextAlignment`, `LineSpacing`, `LineHeight`, `FontWeight` + `FontAttributes` via faces registered per weight (`AddFont(src, alias, weight)`, nearest weight wins, synthetic bold (`setEmbolden`) when the nearest face is lighter than 600 — C# `Font.Embolden`; italic = synthetic skew when no italic face; empty `FontFamily` = the first registered family, weights included), `TextTransform`, `Padding`, `LinesCount`; text measured with unhinted (linear) advances, the same widths as DrawnUi.Rust on every platform; ink past a line's ends (italic slant, a glyph's negative side bearing such as the hook of "j") is kept by every cache type (drawing room only, widths unchanged); defaults as C# (`FontSize` 12, `TextColor` GreenYellow). `FontFamilyFallback` ported and extended: comma-separated chain (`"FontSymbols,FontSymbols2"`), per-codepoint run segmentation, spaces always stay on the main font; `fonts.AddSymbols()` (`FontSymbols` = Noto Sans Math subset, `FontSymbols2` = Noto Sans Symbols 2 subset) and `fonts.AddEmojis()` (`FontEmoji` = Noto Color Emoji subset: faces, hands, skin tones and the demo emoji) ship the same subsets as DrawnUi.Blazor. A joiner, variation selector, skin tone, keycap or tag keeps the font of the glyph before it (C# JoinsPreviousGlyph). Text shaping where the text needs it (C# `UnicodeNeedsShaping` ranges plus Hebrew, Arabic supplements and emoji sequence characters): Arabic joins, Indic conjuncts and marks, emoji sequences as one glyph, through the CanvasKit paragraph module already in the build (HarfBuzz + ICU, no extra wasm); other text keeps the plain glyph-by-glyph path. Right-to-left lines: runs cut where the bidirectional level changes (ICU levels; the paragraph direction from its first strong letter, explicit embeddings reported as their direction only) and placed in visual order (rule L2). A space keeps the style of the span it was written in; where two spans meet with a space each, both stay (C#). `Spans` ported as `<TextSpan>` children: `Text`, `TextColor`/`FontSize`/`FontFamily` (unset = inherit from the label, like C# HasSetColor/HasSetSize/HasSetFont), `FontWeight`, `IsBold`, `IsItalic`, `Underline`/`UnderlineWidth`, `Strikeout`/`StrikeoutWidth`/`StrikeoutColor` (Red default), `BackgroundColor`, `Tapped` + `ForceCaptureInput` (hit-tested through per-fragment `Rects`, ripple on the label, `OnSpanTapped` overridable), mixed sizes on one line share a baseline. TextSpan not ported: `ParagraphColor`, `CommandTapped`, per-span `LineSpacing`/`LineHeight`, `AutoFindFont`, `DrawingOffset`. `CharacterSpacing` (C#: (value - 1) points after every glyph, measured, wrapped and cut at the drawn width), Chinese / Japanese line breaks between characters with kinsoku (C# FitAtBreak, `CanBreakInsideWord`). Text `StrokeColor`/`StrokeWidth`/`StrokeGradient`, `DropShadow*` and `GradientByLines` ported (C# DrawText order). Not ported: `AutoFont`, `AutoSize`/`AutoSizeText`, `MonoForDigits`, `KeepSpacesOnLineBreaks` (accepted, no effect), `Format`, hyphenation, |
76
76
  | `SkiaHotspot` | ported | Fill/Fill, `Tapped`, `Down`, `Up`, `LockPanning`, `TouchDown`; consumes only Tapped like the C# one. No `AnimationTapped`/ripple/shimmer. |
77
77
  | `SkiaButton` | partial | Default look only: rounded frame radius 8 (hardcoded like the C# default content), centered label, `Text`/`TextColor`/`FontSize`/`FontFamily`/`BackgroundColor`/`IsPressed`/`RespondsToGestures` (`IsDisabled` = its obsolete opposite)/`LockPanning`, `Tapped`/`Down`/`Up`. `RespondsToGestures = false`: no press, no `Tapped`/`Down`/`Up`, a press or tap on it stops there, keyboard skips it, reported disabled (drawnui-cross 6w). `IsPressed` is tracked but has no visual; press feedback = `ApplyEffect="Ripple"`. No `ButtonStyle` platform looks, icons, `TextCase`, elevation, shimmer, `BtnText`/`BtnShape` templating. |
78
78
  | `SkiaImage` | partial | Effects ported: `AddEffect` (BlackAndWhite/Grayscale, Pastel, Sepia, InvertColors, Tint + `ColorTint`/`EffectBlendMode`, Darken, Lighten, Contrast, Saturation, Brightness, TSL, Gamma ≈ linear fit — CanvasKit has no table color filter), `Blur` (image filter, mirror tile), `ZoomX/ZoomY`, `HorizontalOffset/VerticalOffset`; C# color matrices use 0..255 translations, CanvasKit 0..1 — converted. `HSL` (hue from `Gamma`, `Saturation`, `Brightness`, tint blend), `Custom` = your own `PaintColorFilter` (C# public fields `PaintColorFilter` / `PaintImageFilter`, the latter replaces `Blur`), `ImageBitmap` (decoded image shared, not owned), `LoadPriority` of the queued `Source` load. Not ported: `UseGradient`/`StartColor`/`EndColor`, sprites, `InflateAmount`, `EraseChangedContent`, `RescaleSource`/`RescalingQuality`. `Source` (URL), `Aspect` (all `TransformAspect` values; `Tile` is a no-op like C#, tiling is `SkiaImageTiles`, same `RescaleAspect` math), `HorizontalAlignment`/`VerticalAlignment`, `Success`/`Error`, `IsLoading`, `LoadedSource`, `DisplayRect`, `AspectScale`; overflow clipped to the box. Not ported: `LoadSourceOnFirstDraw`, `PreviewBase64`, `ImageBitmap`/`LoadedImageSource`, `RescaleSource`/`CacheRescaledSource`/`RescalingQuality`, all adjustments (`Brightness`…`Blur`, `ColorTint`, gradient, `Zoom*`, offsets), sprites, `DrawWhenEmpty`, `EraseChangedContent`, `UseAssembly`. Measure: bounded box taken as is, unbounded axis from source aspect; no `NeedAutoWidth/Height` from Start alignment. |
@@ -332,8 +332,10 @@ export class SkiaEditor extends SkiaShape {
332
332
  const innerW = isFinite(w) ? Math.max(0, w - px) : Infinity;
333
333
  // Single-line: the label is Start-aligned and measures to its content, so Center / End alignment had nothing to
334
334
  // align in. Give it the field as a MINIMUM: short text centers in the field, longer text still grows past it and
335
- // scrolls (C# 2e334ddd).
336
- const minWidth = !this.IsMultiline && this.horizontalTextAlignment !== "Start" && isFinite(innerW) && innerW > 0 ? innerW / scale : -1;
335
+ // scrolls (C# 2e334ddd). A right-to-left paragraph aligns even with Start (it starts at the right, drawnui-cross 6am,
336
+ // C# 8e4b18ef).
337
+ const aligns = this.horizontalTextAlignment !== "Start" || SkiaLabel.FirstStrongIsRtl(this.Label.Text);
338
+ const minWidth = !this.IsMultiline && aligns && isFinite(innerW) && innerW > 0 ? innerW / scale : -1;
337
339
  if (this.Label.MinimumWidthRequest !== minWidth) {
338
340
  this.Label.MinimumWidthRequest = minWidth;
339
341
  this.Label.NeedMeasure = true;
@@ -191,13 +191,16 @@ export declare class SkiaLabel extends SkiaControl {
191
191
  /** ParagraphSpacing above a line that starts a paragraph (after the first): that many of its lines, with their spacing. */
192
192
  private ParagraphSpace;
193
193
  private BlockHeight;
194
- /** Skew of synthetic italic (Super.GetFont setSkewX -0.25): x moves by 0.25 per pixel above the baseline. */
195
- private static readonly ItalicSkew;
196
- /** Pixels synthetic italic glyphs reach past the line box: right at the ascent, left at the descent. */
197
- private slantRight;
198
- private slantLeft;
199
- /** The slant of synthetic italic is drawn outside the label's box: caches record that room too (C# / DrawnUi.Rust draw it whole). */
194
+ /** Pixels of ink outside the lines' advance boxes, at their left and right ends (side bearings, italic slant). */
195
+ private inkLeft;
196
+ private inkRight;
197
+ /** Ink drawn outside the label's box (a "j" hook, an italic slant) is recorded by caches too, as C# draws it whole. */
200
198
  ComputeEffectsMargin(scale: number): Thickness;
199
+ /**
200
+ * C# (after 106e768a): the ink bounds of the first glyph of each line's leftmost run and the last glyph of its
201
+ * rightmost run, beyond the advance box of that run. Two glyph bounds per line, at measure.
202
+ */
203
+ private MeasureInkOverhang;
201
204
  /**
202
205
  * Where a line starts inside [left, right] (drawnui-cross 6am): Start and End follow the paragraph's direction (in a
203
206
  * right-to-left paragraph Start is the right edge); Center is centered; Fill* lines are not stretched here and sit
@@ -138,7 +138,7 @@ export class SkiaLabel extends SkiaControl {
138
138
  const main = Super.GetFont(family, weight, italic, sizePx);
139
139
  const m = main.getMetrics();
140
140
  f = {
141
- Key: key, Main: main, SizePx: sizePx, Ascent: -m.ascent, Descent: m.descent, Italic: italic,
141
+ Key: key, Main: main, SizePx: sizePx, Ascent: -m.ascent, Descent: m.descent,
142
142
  Fallbacks: this.fontFamilyFallback
143
143
  ? this.fontFamilyFallback.split(",").map((a) => a.trim()).filter(Boolean).map((a) => Super.GetFont(a, weight, italic, sizePx))
144
144
  : [],
@@ -606,17 +606,50 @@ export class SkiaLabel extends SkiaControl {
606
606
  }
607
607
  return h;
608
608
  }
609
- /** Skew of synthetic italic (Super.GetFont setSkewX -0.25): x moves by 0.25 per pixel above the baseline. */
610
- static ItalicSkew = 0.25;
611
- /** Pixels synthetic italic glyphs reach past the line box: right at the ascent, left at the descent. */
612
- slantRight = 0;
613
- slantLeft = 0;
614
- /** The slant of synthetic italic is drawn outside the label's box: caches record that room too (C# / DrawnUi.Rust draw it whole). */
609
+ /** Pixels of ink outside the lines' advance boxes, at their left and right ends (side bearings, italic slant). */
610
+ inkLeft = 0;
611
+ inkRight = 0;
612
+ /** Ink drawn outside the label's box (a "j" hook, an italic slant) is recorded by caches too, as C# draws it whole. */
615
613
  ComputeEffectsMargin(scale) {
616
614
  const m = super.ComputeEffectsMargin(scale);
617
- if (this.slantRight === 0 && this.slantLeft === 0)
615
+ if (this.inkRight === 0 && this.inkLeft === 0)
618
616
  return m;
619
- return new Thickness(m.Left + this.slantLeft, m.Top, m.Right + this.slantRight, m.Bottom);
617
+ return new Thickness(m.Left + this.inkLeft, m.Top, m.Right + this.inkRight, m.Bottom);
618
+ }
619
+ /**
620
+ * C# (after 106e768a): the ink bounds of the first glyph of each line's leftmost run and the last glyph of its
621
+ * rightmost run, beyond the advance box of that run. Two glyph bounds per line, at measure.
622
+ */
623
+ MeasureInkOverhang() {
624
+ const sp = this.glyphSpacing;
625
+ let left = 0, right = 0;
626
+ for (const line of this.lines) {
627
+ const runs = line.Runs.filter((r) => r.Text.trim().length > 0);
628
+ if (runs.length === 0)
629
+ continue;
630
+ const first = runs.reduce((a, b) => ((b.X ?? 0) < (a.X ?? 0) ? b : a)), last = runs.reduce((a, b) => ((b.X ?? 0) >= (a.X ?? 0) ? b : a));
631
+ const firstX = first.X ?? 0, lastEnd = (last.X ?? line.Width) + (last.X === undefined ? 0 : last.Width - sp);
632
+ // ink x of a run's visually first / last glyph, from the line start
633
+ const ends = (r, x0) => {
634
+ if (r.Shaped) {
635
+ const g = r.Shaped.Glyphs, n = g.length;
636
+ if (n === 0)
637
+ return [x0, x0];
638
+ const b = r.Font.getGlyphBounds([g[0], g[n - 1]]);
639
+ return [x0 + r.Shaped.Positions[0] + b[0], x0 + r.Shaped.Positions[(n - 1) * 2] + b[6]];
640
+ }
641
+ const ids = r.Font.getGlyphIDs(r.Text);
642
+ const n = ids.length;
643
+ const b = r.Font.getGlyphBounds([ids[0], ids[n - 1]]);
644
+ const lastAdvance = r.Font.getGlyphWidths([ids[n - 1]])[0];
645
+ return [x0 + b[0], x0 + r.Width - sp - lastAdvance + b[6]];
646
+ };
647
+ // a line without placed runs (no bidi): its runs follow each other from x 0, the last ends at the line width
648
+ const lastX0 = last.X ?? (line.Width - (last.Width - sp));
649
+ left = Math.max(left, firstX - ends(first, firstX)[0]);
650
+ right = Math.max(right, ends(last, lastX0)[1] - (last.X === undefined ? line.Width : lastEnd));
651
+ }
652
+ return [Math.max(0, left), Math.max(0, right)];
620
653
  }
621
654
  /**
622
655
  * Where a line starts inside [left, right] (drawnui-cross 6am): Start and End follow the paragraph's direction (in a
@@ -641,17 +674,11 @@ export class SkiaLabel extends SkiaControl {
641
674
  const extraH = this.EffectsExtra(scale).H;
642
675
  this.lines = this.text || this.Spans.length > 0 ? this.LayoutLines(widthConstraint - px, scale, heightConstraint - py - extraH) : [];
643
676
  this.ShapeLines(this.lines);
644
- // synthetic italic leans its glyphs past their advances: drawing room for caches, widths unchanged (DrawnUi.Rust label.rs)
645
- let slantRight = 0, slantLeft = 0;
646
- for (const l of this.lines)
647
- for (const r of l.Runs)
648
- if (r.Fonts.Italic && r.Text.trim()) {
649
- slantRight = Math.max(slantRight, SkiaLabel.ItalicSkew * r.Fonts.Ascent);
650
- slantLeft = Math.max(slantLeft, SkiaLabel.ItalicSkew * r.Fonts.Descent);
651
- }
652
- if (slantRight !== this.slantRight || slantLeft !== this.slantLeft) {
653
- this.slantRight = slantRight;
654
- this.slantLeft = slantLeft;
677
+ // ink past the lines' ends (a "j" hook, an italic slant) is drawing room for caches; widths unchanged
678
+ const [inkLeft, inkRight] = this.MeasureInkOverhang();
679
+ if (inkLeft !== this.inkLeft || inkRight !== this.inkRight) {
680
+ this.inkLeft = inkLeft;
681
+ this.inkRight = inkRight;
655
682
  this.InvalidateEffectsMargin();
656
683
  }
657
684
  let width = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drawnui-react",
3
- "version": "0.1.0-preview.31",
3
+ "version": "0.1.0-preview.33",
4
4
  "description": "DrawnUi for React: the DrawnUi (.NET) drawn-UI engine in TypeScript on CanvasKit (Skia WASM). Same controls, same PascalCase API as DrawnUi.Net.",
5
5
  "license": "MIT",
6
6
  "author": "Nick Kovalsky (AppoMobi)",