@native-sdk/cli 0.4.2 → 0.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -23,14 +23,14 @@
23
23
  "LICENSE"
24
24
  ],
25
25
  "optionalDependencies": {
26
- "@native-sdk/cli-darwin-arm64": "0.4.2",
27
- "@native-sdk/cli-darwin-x64": "0.4.2",
28
- "@native-sdk/cli-linux-arm64-gnu": "0.4.2",
29
- "@native-sdk/cli-linux-arm64-musl": "0.4.2",
30
- "@native-sdk/cli-linux-x64-gnu": "0.4.2",
31
- "@native-sdk/cli-linux-x64-musl": "0.4.2",
32
- "@native-sdk/cli-win32-arm64": "0.4.2",
33
- "@native-sdk/cli-win32-x64": "0.4.2"
26
+ "@native-sdk/cli-darwin-arm64": "0.4.3",
27
+ "@native-sdk/cli-darwin-x64": "0.4.3",
28
+ "@native-sdk/cli-linux-arm64-gnu": "0.4.3",
29
+ "@native-sdk/cli-linux-arm64-musl": "0.4.3",
30
+ "@native-sdk/cli-linux-x64-gnu": "0.4.3",
31
+ "@native-sdk/cli-linux-x64-musl": "0.4.3",
32
+ "@native-sdk/cli-win32-arm64": "0.4.3",
33
+ "@native-sdk/cli-win32-x64": "0.4.3"
34
34
  },
35
35
  "repository": {
36
36
  "type": "git",
@@ -722,8 +722,8 @@ test "chart golden: line + bar + band render byte-identically in light and dark"
722
722
  // category labels (q1, q3) under the bars. Both themes clear with their
723
723
  // background token. Update deliberately when chart rendering changes,
724
724
  // reviewing the dumped pixels first.
725
- const golden_light_signature: u64 = 11237334215963301158;
726
- const golden_dark_signature: u64 = 4053146140543071333;
725
+ const golden_light_signature: u64 = 4743613392161459263;
726
+ const golden_dark_signature: u64 = 13208780493823093371;
727
727
 
728
728
  fn goldenDumpRequested() bool {
729
729
  if (comptime !@import("builtin").link_libc) return false;
@@ -405,7 +405,7 @@ test "the README-shaped fixture renders through the mapper and the reference ren
405
405
  // separators, fenced-code panels, and near-black underlined links.
406
406
  // Update deliberately when markdown rendering changes, reviewing the
407
407
  // rendered pixels first (see reference_tests.zig conventions).
408
- const markdown_document_reference_signature: u64 = 6015448079037287912;
408
+ const markdown_document_reference_signature: u64 = 4124710367581899536;
409
409
 
410
410
 
411
411
  test "bare URLs autolink at word boundaries with trailing punctuation trimmed" {
@@ -225,9 +225,11 @@ pub const ReferenceRenderSurface = struct {
225
225
  }
226
226
 
227
227
  pub fn renderPass(self: ReferenceRenderSurface, pass: CanvasRenderPass, clear_color: Color) Error!void {
228
- // One-time sRGB decode table fill (see the table's doc comment);
229
- // outside the per-pixel loops so the hot path pays no checks.
228
+ // One-time sRGB decode/encode table fills (see the tables' doc
229
+ // comments); outside the per-pixel loops so the hot path pays no
230
+ // checks.
230
231
  ensureSrgbToLinearByteTable();
232
+ ensureLinearToSrgbTable();
231
233
  // Fresh per-pass panel-fill budget (see the memo's doc comment).
232
234
  if (self.render_memo) |memo| memo.image_scale_fills_this_pass = 0;
233
235
  const scale = referencePassScale(pass.scale);
@@ -309,7 +311,7 @@ pub const ReferenceRenderSurface = struct {
309
311
  continue;
310
312
  }
311
313
  const coverage = referenceRoundedRectCoverage(point, rect, radius);
312
- if (coverage > 0) self.blendPixel(@intCast(x), @intCast(y), referenceScaleColorAlpha(referenceSampleFill(value.fill, command.transform, point), coverage), command.opacity);
314
+ if (coverage > 0) self.blendPixelCoverage(@intCast(x), @intCast(y), referenceSampleFill(value.fill, command.transform, point), coverage, command.opacity, .linear_light);
313
315
  }
314
316
  }
315
317
  self.memoStore(probe, pixel_rect);
@@ -353,7 +355,7 @@ pub const ReferenceRenderSurface = struct {
353
355
  }
354
356
  const coverage = std.math.clamp(referenceRoundedRectCoverage(point, outer, outer_radius) - referenceRoundedRectCoverage(point, inner, inner_radius), 0, 1);
355
357
  if (coverage > 0) {
356
- self.blendPixel(@intCast(x), @intCast(y), referenceScaleColorAlpha(referenceSampleFill(value.stroke.fill, command.transform, point), coverage), command.opacity);
358
+ self.blendPixelCoverage(@intCast(x), @intCast(y), referenceSampleFill(value.stroke.fill, command.transform, point), coverage, command.opacity, .linear_light);
357
359
  }
358
360
  }
359
361
  }
@@ -389,6 +391,7 @@ pub const ReferenceRenderSurface = struct {
389
391
  .fill = value.fill,
390
392
  .transform = command.transform,
391
393
  .opacity = command.opacity,
394
+ .coverage_blend = .linear_light,
392
395
  };
393
396
  vector.fillPath(
394
397
  value.elements,
@@ -416,6 +419,7 @@ pub const ReferenceRenderSurface = struct {
416
419
  .fill = value.stroke.fill,
417
420
  .transform = command.transform,
418
421
  .opacity = command.opacity,
422
+ .coverage_blend = .linear_light,
419
423
  };
420
424
  vector.strokePath(
421
425
  value.elements,
@@ -823,11 +827,16 @@ pub const ReferenceRenderSurface = struct {
823
827
  if (builder.slice().len == 0) return true; // Space: nothing to ink.
824
828
 
825
829
  const pixel_rect = referencePixelRect(draw_bounds, self.width, self.height) orelse return true;
830
+ // Glyph coverage blends in sRGB, not linear light (see
831
+ // `CoverageBlend`): apparent text weight is set by how edge
832
+ // pixels darken, and re-blending them in linear light thins
833
+ // dark-on-light runs and blooms light-on-dark runs at UI sizes.
826
834
  var sink = ReferenceCoverageSink{
827
835
  .surface = self,
828
836
  .fill = .{ .color = value.color },
829
837
  .transform = command.transform,
830
838
  .opacity = command.opacity,
839
+ .coverage_blend = .srgb,
831
840
  };
832
841
  // The outline is already in device space; TrueType interiorness
833
842
  // is the nonzero rule.
@@ -869,18 +878,66 @@ pub const ReferenceRenderSurface = struct {
869
878
  self.pixels[index + 3] = out[3];
870
879
  }
871
880
 
881
+ /// Blend one pixel whose fractional alpha is ANTI-ALIASED EDGE
882
+ /// COVERAGE (kept separate from the color's own alpha so the blend
883
+ /// can tell an AA fringe from a translucent wash — see
884
+ /// `CoverageBlend`).
885
+ fn blendPixelCoverage(self: ReferenceRenderSurface, x: usize, y: usize, color: Color, coverage: f32, opacity: f32, blend: CoverageBlend) void {
886
+ const index = (y * self.width + x) * 4;
887
+ const dst = [4]u8{
888
+ self.pixels[index + 0],
889
+ self.pixels[index + 1],
890
+ self.pixels[index + 2],
891
+ self.pixels[index + 3],
892
+ };
893
+ const out = blendRgba8Coverage(dst, color, coverage, opacity, blend);
894
+ self.pixels[index + 0] = out[0];
895
+ self.pixels[index + 1] = out[1];
896
+ self.pixels[index + 2] = out[2];
897
+ self.pixels[index + 3] = out[3];
898
+ }
899
+
872
900
  fn findImage(self: ReferenceRenderSurface, id: ImageId) ?ReferenceImage {
873
901
  return findReferenceImage(self.images, id);
874
902
  }
875
903
  };
876
904
 
905
+ /// Which space a shape's fractional edge coverage blends in.
906
+ ///
907
+ /// GEOMETRY — rounded rects, filled/stroked paths, icons, chart marks —
908
+ /// blends its anti-aliased edge pixels in LINEAR LIGHT. Compositing the
909
+ /// sRGB-encoded bytes directly weights half coverage far below half the
910
+ /// light (a 50% black-on-white fringe lands near 21% luminance instead
911
+ /// of 50%), so every edge grows a dark rim on light backgrounds (a light
912
+ /// halo on dark ones) that reads as jagged even though the coverage
913
+ /// values are correct. Decoding to linear light, blending, and
914
+ /// re-encoding removes the rim.
915
+ ///
916
+ /// GLYPHS stay in sRGB. Text coverage funnels through the exact same
917
+ /// vector core, but apparent text WEIGHT is a product of how edge pixels
918
+ /// darken: the same coverage blended in linear light renders visibly
919
+ /// thinner dark-on-light runs and bloomier light-on-dark runs at UI
920
+ /// sizes, and the toolkit's type ramp was tuned against sRGB-blended
921
+ /// stems. sRGB glyph compositing also matches the packet-backed macOS
922
+ /// text pipeline, so mixed CPU/host frames keep one text weight.
923
+ ///
924
+ /// Only opaque-source fractional-coverage pixels differ between the two
925
+ /// modes: fully covered pixels short-circuit identically in either
926
+ /// space, and translucent sources (washes, scrims, faded layers) keep
927
+ /// sRGB blending so overlay brightness — tuned in sRGB terms — is
928
+ /// untouched and an AA edge never diverges from the interior it borders.
929
+ const CoverageBlend = enum { linear_light, srgb };
930
+
877
931
  /// Per-pixel coverage sink for the vector core: samples the fill at the
878
- /// pixel center and blends with the coverage folded into alpha.
932
+ /// pixel center and blends with the coverage, in the blend space the
933
+ /// emitter declared (geometry linear-light, glyphs sRGB — see
934
+ /// `CoverageBlend`).
879
935
  const ReferenceCoverageSink = struct {
880
936
  surface: ReferenceRenderSurface,
881
937
  fill: Fill,
882
938
  transform: Affine,
883
939
  opacity: f32,
940
+ coverage_blend: CoverageBlend,
884
941
 
885
942
  pub fn pixel(self: *ReferenceCoverageSink, x: i32, y: i32, coverage: f32) void {
886
943
  if (x < 0 or y < 0) return;
@@ -889,7 +946,7 @@ const ReferenceCoverageSink = struct {
889
946
  if (px >= self.surface.width or py >= self.surface.height) return;
890
947
  const point = referencePixelCenter(px, py);
891
948
  const color = referenceSampleFill(self.fill, self.transform, point);
892
- self.surface.blendPixel(px, py, referenceScaleColorAlpha(color, coverage), self.opacity);
949
+ self.surface.blendPixelCoverage(px, py, color, coverage, self.opacity, self.coverage_blend);
893
950
  }
894
951
  };
895
952
 
@@ -1339,6 +1396,31 @@ fn ensureSrgbToLinearByteTable() void {
1339
1396
  srgb_to_linear_byte_table_ready = true;
1340
1397
  }
1341
1398
 
1399
+ /// Precomputed `referenceLinearToSrgb` over evenly spaced linear inputs:
1400
+ /// the linear-light coverage blend re-encodes three channels per fringe
1401
+ /// pixel, and each direct encode costs a `pow`. 4096 entries keep the
1402
+ /// nearest-entry result within one 8-bit step of direct evaluation: the
1403
+ /// curve is steepest near black (slope 12.92), where one table cell
1404
+ /// still spans under one output byte step, so the looked-up value sits
1405
+ /// within half a step of exact and the final byte rounding moves by at
1406
+ /// most one level. Same benign-race lazy fill as the decode table above.
1407
+ const linear_to_srgb_table_len = 4096;
1408
+ var linear_to_srgb_table: [linear_to_srgb_table_len]f32 = undefined;
1409
+ var linear_to_srgb_table_ready: bool = false;
1410
+
1411
+ fn ensureLinearToSrgbTable() void {
1412
+ if (linear_to_srgb_table_ready) return;
1413
+ for (&linear_to_srgb_table, 0..) |*value, index| {
1414
+ value.* = referenceLinearToSrgb(@as(f32, @floatFromInt(index)) / (linear_to_srgb_table_len - 1));
1415
+ }
1416
+ linear_to_srgb_table_ready = true;
1417
+ }
1418
+
1419
+ fn referenceLinearToSrgbLut(value: f32) f32 {
1420
+ const index: usize = @intFromFloat(@round(std.math.clamp(value, 0, 1) * (linear_to_srgb_table_len - 1)));
1421
+ return linear_to_srgb_table[index];
1422
+ }
1423
+
1342
1424
  fn referencePremultiplySrgba8(pixel: [4]u8) ReferencePremultipliedLinearColor {
1343
1425
  const alpha = @as(f32, @floatFromInt(pixel[3])) / 255.0;
1344
1426
  return .{
@@ -1528,6 +1610,53 @@ fn blendRgba8(dst: [4]u8, src: Color, opacity: f32) [4]u8 {
1528
1610
  };
1529
1611
  }
1530
1612
 
1613
+ /// Source-over with the source's fractional alpha split into COLOR alpha
1614
+ /// and EDGE COVERAGE, so the blend space can key off what the alpha
1615
+ /// means (see `CoverageBlend`).
1616
+ ///
1617
+ /// Linear-light blending is reserved for the one case the split targets:
1618
+ /// an effectively opaque source's anti-aliased fringe. Everything else —
1619
+ /// sRGB-mode callers (glyphs), fully covered pixels, and translucent
1620
+ /// sources — folds coverage into alpha and takes the historical sRGB
1621
+ /// blend, byte for byte. That routing is also the cost story: interiors
1622
+ /// (`coverage >= 1`) and washes never pay a decode/encode round-trip, so
1623
+ /// the linear math runs only on the thin edge band, where the two table
1624
+ /// lookups per channel replace `pow` evaluations.
1625
+ fn blendRgba8Coverage(dst: [4]u8, src: Color, coverage: f32, opacity: f32, blend: CoverageBlend) [4]u8 {
1626
+ const cov = std.math.clamp(coverage, 0, 1);
1627
+ const src_a = std.math.clamp(src.a, 0, 1) * std.math.clamp(opacity, 0, 1);
1628
+ if (blend == .srgb or cov <= 0 or cov >= 1 or src_a < 1) {
1629
+ return blendRgba8(dst, referenceScaleColorAlpha(src, cov), opacity);
1630
+ }
1631
+
1632
+ // Belt over the renderPass-level fills for direct callers (unit
1633
+ // tests, future paths): two predictable branches per fringe pixel.
1634
+ ensureSrgbToLinearByteTable();
1635
+ ensureLinearToSrgbTable();
1636
+
1637
+ // Alpha stays in coverage space — it counts covered area, not light
1638
+ // — so the alpha math is IDENTICAL to the sRGB path; only the color
1639
+ // channels decode to linear light. `out_a >= cov > 0` here, so the
1640
+ // straight-alpha un-premultiply divide is safe. The source decodes
1641
+ // through the same byte quantization its coverage-1 pixels store,
1642
+ // so a fringe converges exactly onto the interior bytes it borders.
1643
+ const dst_a = @as(f32, @floatFromInt(dst[3])) / 255.0;
1644
+ const out_a = cov + dst_a * (1 - cov);
1645
+ const src_r = srgb_to_linear_byte_table[colorChannelToByte(src.r)];
1646
+ const src_g = srgb_to_linear_byte_table[colorChannelToByte(src.g)];
1647
+ const src_b = srgb_to_linear_byte_table[colorChannelToByte(src.b)];
1648
+ const dst_r = srgb_to_linear_byte_table[dst[0]];
1649
+ const dst_g = srgb_to_linear_byte_table[dst[1]];
1650
+ const dst_b = srgb_to_linear_byte_table[dst[2]];
1651
+ const dst_weight = dst_a * (1 - cov);
1652
+ return .{
1653
+ colorChannelToByte(referenceLinearToSrgbLut((src_r * cov + dst_r * dst_weight) / out_a)),
1654
+ colorChannelToByte(referenceLinearToSrgbLut((src_g * cov + dst_g * dst_weight) / out_a)),
1655
+ colorChannelToByte(referenceLinearToSrgbLut((src_b * cov + dst_b * dst_weight) / out_a)),
1656
+ colorChannelToByte(out_a),
1657
+ };
1658
+ }
1659
+
1531
1660
  fn colorChannelToByte(value: f32) u8 {
1532
1661
  return @intFromFloat(@round(std.math.clamp(value, 0, 1) * 255.0));
1533
1662
  }
@@ -788,6 +788,168 @@ test "rounded-rect coverage matches supersampled ground truth with no silhouette
788
788
  }
789
789
  }
790
790
 
791
+ // ---------------------------------------------------------------------------
792
+ // Coverage blend-space split.
793
+ //
794
+ // Geometry (paths, rounded rects) blends its anti-aliased edge coverage
795
+ // in linear light; glyph coverage blends in sRGB to preserve text
796
+ // weight. These tests pin the split from both sides with independently
797
+ // computed ground truth, so a refactor can never silently swap the two
798
+ // (a swap fails BOTH assertions, loudly).
799
+
800
+ /// The exact sRGB decode the renderer's 256-entry byte table holds.
801
+ fn blendSplitSrgbToLinear(value: f32) f32 {
802
+ const channel = std.math.clamp(value, 0, 1);
803
+ if (channel <= 0.04045) return channel / 12.92;
804
+ return std.math.pow(f32, (channel + 0.055) / 1.055, 2.4);
805
+ }
806
+
807
+ fn blendSplitLinearToSrgb(value: f32) f32 {
808
+ const channel = std.math.clamp(value, 0, 1);
809
+ if (channel <= 0.0031308) return channel * 12.92;
810
+ return 1.055 * std.math.pow(f32, channel, 1.0 / 2.4) - 0.055;
811
+ }
812
+
813
+ /// The renderer's encode-table lookup, replicated: nearest of 4096
814
+ /// evenly spaced entries, then the final byte rounding.
815
+ fn blendSplitEncodeByte(value: f32) u8 {
816
+ const index = @round(std.math.clamp(value, 0, 1) * 4095.0);
817
+ return @intFromFloat(@round(blendSplitLinearToSrgb(index / 4095.0) * 255.0));
818
+ }
819
+
820
+ /// Linear-light coverage blend of an opaque source byte over an opaque
821
+ /// destination byte, from the same LUT math the renderer tabulates.
822
+ fn blendSplitLinearByte(src: u8, dst: u8, coverage: f32) u8 {
823
+ const src_linear = blendSplitSrgbToLinear(@as(f32, @floatFromInt(src)) / 255.0);
824
+ const dst_linear = blendSplitSrgbToLinear(@as(f32, @floatFromInt(dst)) / 255.0);
825
+ return blendSplitEncodeByte(src_linear * coverage + dst_linear * (1 - coverage));
826
+ }
827
+
828
+ /// sRGB-space coverage blend of the same pixel (the historical fold).
829
+ fn blendSplitSrgbByte(src: u8, dst: u8, coverage: f32) u8 {
830
+ const src_f = @as(f32, @floatFromInt(src)) / 255.0;
831
+ const dst_f = @as(f32, @floatFromInt(dst)) / 255.0;
832
+ return @intFromFloat(@round((src_f * coverage + dst_f * (1 - coverage)) * 255.0));
833
+ }
834
+
835
+ fn blendSplitRenderPass(surface: ReferenceRenderSurface, command: RenderCommand, clear: Color, width: usize, height: usize) !void {
836
+ const pass = CanvasRenderPass{
837
+ .surface_size = geometry.SizeF.init(@floatFromInt(width), @floatFromInt(height)),
838
+ .scale = 1,
839
+ .full_repaint = true,
840
+ .commands = &.{command},
841
+ };
842
+ try surface.renderPass(pass, clear);
843
+ }
844
+
845
+ test "geometry edge coverage blends in linear light, computed from the LUT math" {
846
+ // A black path whose right edge splits pixel column 12 exactly in
847
+ // half: the vector core reports coverage 0.5 there, interiors 1.
848
+ const split_width: usize = 24;
849
+ const split_height: usize = 16;
850
+ const white = Color{ .r = 1, .g = 1, .b = 1, .a = 1 };
851
+ const black = Color{ .r = 0, .g = 0, .b = 0, .a = 1 };
852
+ const bounds = geometry.RectF.init(0, 0, split_width, split_height);
853
+ const elements = [_]PathElement{
854
+ .{ .verb = .move_to, .points = .{ geometry.PointF.init(4, 4), geometry.PointF.zero(), geometry.PointF.zero() } },
855
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(12.5, 4), geometry.PointF.zero(), geometry.PointF.zero() } },
856
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(12.5, 12), geometry.PointF.zero(), geometry.PointF.zero() } },
857
+ .{ .verb = .line_to, .points = .{ geometry.PointF.init(4, 12), geometry.PointF.zero(), geometry.PointF.zero() } },
858
+ .{ .verb = .close, .points = .{ geometry.PointF.zero(), geometry.PointF.zero(), geometry.PointF.zero() } },
859
+ };
860
+
861
+ const linear_edge = blendSplitLinearByte(0, 255, 0.5);
862
+ const srgb_edge = blendSplitSrgbByte(0, 255, 0.5);
863
+ // The split is only observable if the two spaces disagree here.
864
+ try std.testing.expect(linear_edge != srgb_edge);
865
+
866
+ // fill_path: the vector-core geometry route.
867
+ {
868
+ var pixels: [split_width * split_height * 4]u8 = undefined;
869
+ const surface = try ReferenceRenderSurface.init(split_width, split_height, &pixels);
870
+ try blendSplitRenderPass(surface, .{
871
+ .command = .{ .fill_path = .{ .elements = &elements, .fill = .{ .color = black } } },
872
+ .local_bounds = bounds,
873
+ .bounds = bounds,
874
+ }, white, split_width, split_height);
875
+ // Fully covered interior pixels stay bit-identical to the plain
876
+ // sRGB blend: an opaque source at coverage 1 is a copy in either
877
+ // space.
878
+ try expectPixelRgba8(.{ 0, 0, 0, 255 }, surface, 8, 8);
879
+ // The half-covered edge pixel holds the linear-light value.
880
+ try expectPixelRgba8(.{ linear_edge, linear_edge, linear_edge, 255 }, surface, 12, 8);
881
+ }
882
+
883
+ // fill_rounded_rect: the signed-distance geometry route. Its right
884
+ // edge is a straight segment at the same half-pixel boundary (the
885
+ // radius-2 corners are far from row 8), so coverage is 0.5 again.
886
+ {
887
+ var pixels: [split_width * split_height * 4]u8 = undefined;
888
+ const surface = try ReferenceRenderSurface.init(split_width, split_height, &pixels);
889
+ try blendSplitRenderPass(surface, .{
890
+ .command = .{ .fill_rounded_rect = .{ .rect = geometry.RectF.init(4, 4, 8.5, 8), .radius = Radius.all(2), .fill = .{ .color = black } } },
891
+ .local_bounds = bounds,
892
+ .bounds = bounds,
893
+ }, white, split_width, split_height);
894
+ try expectPixelRgba8(.{ 0, 0, 0, 255 }, surface, 8, 8);
895
+ try expectPixelRgba8(.{ linear_edge, linear_edge, linear_edge, 255 }, surface, 12, 8);
896
+ }
897
+ }
898
+
899
+ test "glyph edge coverage blends in sRGB, not linear light" {
900
+ // The same discrimination from the text side: render one glyph twice
901
+ // — once over transparent (whose alpha channel IS the coverage, in
902
+ // any blend space) and once over white — then check every fringe
903
+ // pixel of the white render against both models. Text must track the
904
+ // sRGB fold and stay far from the linear-light value at mid
905
+ // coverage, so inverting the sink's blend space can never pass.
906
+ const glyph_width: usize = 32;
907
+ const glyph_height: usize = 48;
908
+ const white = Color{ .r = 1, .g = 1, .b = 1, .a = 1 };
909
+ const black = Color{ .r = 0, .g = 0, .b = 0, .a = 1 };
910
+ const clear = Color{ .r = 0, .g = 0, .b = 0, .a = 0 };
911
+ const bounds = geometry.RectF.init(0, 0, glyph_width, glyph_height);
912
+ const command = RenderCommand{
913
+ .command = .{ .draw_text = .{ .size = 32, .origin = geometry.PointF.init(4, 40), .color = black, .text = "o" } },
914
+ .local_bounds = bounds,
915
+ .bounds = bounds,
916
+ };
917
+
918
+ var coverage_pixels: [glyph_width * glyph_height * 4]u8 = undefined;
919
+ const coverage_surface = try ReferenceRenderSurface.init(glyph_width, glyph_height, &coverage_pixels);
920
+ try blendSplitRenderPass(coverage_surface, command, clear, glyph_width, glyph_height);
921
+
922
+ var blended_pixels: [glyph_width * glyph_height * 4]u8 = undefined;
923
+ const blended_surface = try ReferenceRenderSurface.init(glyph_width, glyph_height, &blended_pixels);
924
+ try blendSplitRenderPass(blended_surface, command, white, glyph_width, glyph_height);
925
+
926
+ var mid_coverage_pixels: usize = 0;
927
+ var y: usize = 0;
928
+ while (y < glyph_height) : (y += 1) {
929
+ var x: usize = 0;
930
+ while (x < glyph_width) : (x += 1) {
931
+ const coverage_byte = coverage_surface.pixelRgba8(x, y)[3];
932
+ if (coverage_byte == 0 or coverage_byte == 255) continue;
933
+ const coverage = @as(f32, @floatFromInt(coverage_byte)) / 255.0;
934
+ const rendered: i32 = blended_surface.pixelRgba8(x, y)[0];
935
+ const srgb_expected: i32 = blendSplitSrgbByte(0, 255, coverage);
936
+ // One level of slack: the recovered coverage byte is itself
937
+ // rounded, so the re-derived sRGB fold can sit one step off
938
+ // the value blended from the unrounded coverage.
939
+ try std.testing.expect(@max(rendered - srgb_expected, srgb_expected - rendered) <= 1);
940
+ // Mid-coverage fringes are where the spaces disagree most;
941
+ // hold text a wide margin away from the linear value there.
942
+ if (coverage_byte >= 64 and coverage_byte <= 192) {
943
+ mid_coverage_pixels += 1;
944
+ const linear_expected: i32 = blendSplitLinearByte(0, 255, coverage);
945
+ try std.testing.expect(linear_expected - rendered >= 16);
946
+ }
947
+ }
948
+ }
949
+ // The glyph must actually have exercised the fringe band.
950
+ try std.testing.expect(mid_coverage_pixels >= 4);
951
+ }
952
+
791
953
  test "reference renderer applies clip transform and opacity" {
792
954
  const commands = [_]CanvasCommand{
793
955
  .{ .push_clip = .{ .rect = geometry.RectF.init(1, 1, 2, 2) } },
@@ -965,13 +1127,16 @@ test "reference renderer strokes paths: butt caps end at the segment, round caps
965
1127
  // One horizontal unit-width segment, rendered once per cap shape.
966
1128
  // The end pixels (0,1) and (2,1) are where the caps live: the butt
967
1129
  // cap stops at the endpoint (the segment covers exactly half of each
968
- // end pixel — 128 after coverage rounding), while the round cap
969
- // bulges a half-width semicircle past it (75% coverage per the
970
- // anti-aliased vector core). Interior and off-stroke pixels are
971
- // cap-independent.
1130
+ // end pixel), while the round cap bulges a half-width semicircle
1131
+ // past it (75% coverage per the anti-aliased vector core). Interior
1132
+ // and off-stroke pixels are cap-independent. The expected end-pixel
1133
+ // bytes are the LINEAR-LIGHT encodings of those coverages over black
1134
+ // — geometry edge coverage blends in linear light (see the renderer's
1135
+ // `CoverageBlend`), so 50% coverage of a 255 channel re-encodes to
1136
+ // 188 and 75% to 225, not the 128/191 sRGB-space folds.
972
1137
  const cases = [_]struct { cap: canvas.LineCap, end_coverage: u8 }{
973
- .{ .cap = .butt, .end_coverage = 128 },
974
- .{ .cap = .round, .end_coverage = 191 },
1138
+ .{ .cap = .butt, .end_coverage = 188 },
1139
+ .{ .cap = .round, .end_coverage = 225 },
975
1140
  };
976
1141
  for (cases) |case| {
977
1142
  const elements = [_]PathElement{
@@ -631,6 +631,9 @@ pub const textInputClearButtonHitRect = widget_runtime.textInputClearButtonHitRe
631
631
  pub const textInputContentExtentForWidget = widget_runtime.textInputContentExtentForWidget;
632
632
  pub const textInputMaxScrollOffsetForWidget = widget_runtime.textInputMaxScrollOffsetForWidget;
633
633
  pub const clampedTextInputScrollOffsetForWidget = widget_runtime.clampedTextInputScrollOffsetForWidget;
634
+ pub const textInputMaxHorizontalScrollOffsetForWidget = widget_runtime.textInputMaxHorizontalScrollOffsetForWidget;
635
+ pub const clampedTextInputHorizontalScrollOffsetForWidget = widget_runtime.clampedTextInputHorizontalScrollOffsetForWidget;
636
+ pub const textInputCaretVisibleScrollOffsetForWidget = widget_runtime.textInputCaretVisibleScrollOffsetForWidget;
634
637
  pub const intrinsicWidgetSize = widget_runtime.intrinsicWidgetSize;
635
638
  pub const cursorForWidgetHit = widget_runtime.cursorForWidgetHit;
636
639
  pub const cursorForWidgetTarget = widget_runtime.cursorForWidgetTarget;
@@ -314,6 +314,9 @@ pub const textInputViewportForWidget = canvas.textInputViewportForWidget;
314
314
  pub const textInputContentExtentForWidget = canvas.textInputContentExtentForWidget;
315
315
  pub const textInputMaxScrollOffsetForWidget = canvas.textInputMaxScrollOffsetForWidget;
316
316
  pub const clampedTextInputScrollOffsetForWidget = canvas.clampedTextInputScrollOffsetForWidget;
317
+ pub const textInputMaxHorizontalScrollOffsetForWidget = canvas.textInputMaxHorizontalScrollOffsetForWidget;
318
+ pub const clampedTextInputHorizontalScrollOffsetForWidget = canvas.clampedTextInputHorizontalScrollOffsetForWidget;
319
+ pub const textInputCaretVisibleScrollOffsetForWidget = canvas.textInputCaretVisibleScrollOffsetForWidget;
317
320
  pub const intrinsicWidgetSize = canvas.intrinsicWidgetSize;
318
321
  pub const cursorForWidgetHit = canvas.cursorForWidgetHit;
319
322
  pub const cursorForWidgetTarget = canvas.cursorForWidgetTarget;