fix(canvas2d): return TextMetrics for empty measureText - #150
Conversation
Pixi 8 CanvasTextSystem reads .width on empty remainder strings when letter-spacing is present. Returning without a metrics object crashes any Pixi Text on NativeScript Canvas.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The red AudioContext jobs are not from this diff.
The last The relevant job for this change is Build Native / Canvas iOS + visionOS. |
Brings in #150 and #151. #151 (window timer / EventTarget aliases) is TypeScript only and merged clean. #150 (TextMetrics for empty measureText) conflicted on the one line this branch spells differently: master reads the length through its canvas::Utf8Length shim, this branch calls Utf8LengthV2 directly. Kept this branch's call and took master's fix, which is the removal of the `if (text_utf8_len == 0) return;` early exit. The rest of MeasureText is safe at length 0: prefix_len is at least 3, so the scratch buffer is never empty, WriteUtf8V2 with a zero length writes nothing, and the empty string measures to a zero-width TextMetrics rather than returning undefined.
Problem
Pixi 8
CanvasTextSystem._drawLetterSpacingalways callscontext.measureText(remainder).width. When the remainder is"", NativeScript Canvas returned without constructing aTextMetricsobject, so.widththrew and anynew Text(...)crashed on iOS/tvOS.Change
Remove the
if (text_utf8_len == 0) return;guard. Empty strings go through the existing text engine/cache and return a metrics instance with width 0, matching browsers.Test plan
measureText("")is an object withwidth === 0Textwith default letter-spacing no longer throws on NativeScript CanvasDoes not include the concentric-radial Skia experiment; two-point conical already fades correctly on this stack.