Support rotated text and reuse scaled Cairo images
This commit is contained in:
1 parent
8f2291577c
commit
20b38574f2
86 files changed
+1296
-61
No files matched your search
@@ -2,6 +2,9 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Text can rotate around a chosen origin while keeping its full font size on native, web and Android renderers.
|
||||
- Repeatedly scaled scene images render smoothly without resampling each frame.
|
||||
|
||||
- X11 session idle time now includes typing in other applications.
|
||||
- Custom cursors persist until changed, an application-wide cursor covers every session, and bitmap cursors no longer flicker or show light edges.
|
||||
- An application pointing cursor shows only over something clickable, including painted targets an app hit-tests itself.
|
||||
|
||||
@@ -691,3 +691,16 @@ play-billing-test:
|
||||
canvas-app-hooks-test:
|
||||
@python3 tests/canvas_app_hooks_test.py
|
||||
canvas-test: canvas-app-hooks-test
|
||||
|
||||
.PHONY: rotated-text-test
|
||||
rotated-text-test: project-toolchain $(RAYLIB_ARCHIVES)
|
||||
@sh tests/rotated_text_test.sh
|
||||
@sh tests/rotated_text_raylib_test.sh
|
||||
@sh tests/rotated_text_cairo_test.sh
|
||||
@python3 tests/rotated_text_web_test.py
|
||||
test: rotated-text-test
|
||||
|
||||
.PHONY: cairo-scaled-image-test
|
||||
cairo-scaled-image-test: project-toolchain
|
||||
@sh tests/ziran_cairo_scaled_image_test.sh
|
||||
test: cairo-scaled-image-test
|
||||
@@ -579,6 +579,15 @@ following the finger, clamped to that base. It disappears on release and
|
||||
does not take input. Draw it after the board; `size` is the base diameter
|
||||
in logical units (56 by default). The app keeps its movement rules.
|
||||
|
||||
## Rotated text
|
||||
|
||||
`TextProps.rotation` rotates text clockwise in degrees about `bounds` top left
|
||||
plus `TextProps.origin` (logical units). Zero keeps horizontal text; `origin =
|
||||
Vector2.{bounds.width / 2.0, bounds.height / 2.0}` rotates about the box centre.
|
||||
Layout and font sizes stay unchanged. Native Raylib (including Android), Canvas
|
||||
and DOM preserve the same pivot; local text clipping rotates with the text,
|
||||
while ancestor clipping stays in its original coordinate space.
|
||||
|
||||
## Reading pages
|
||||
|
||||
`text_measure.TextPage(session, props, start)` returns a UTF-8 byte range
|
||||
|
||||
@@ -255,3 +255,12 @@ main :: () -> s32 {
|
||||
if shape_count < 4 || label_count != 4 { return 1 }
|
||||
return 0
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused value; unused x; unused y; unused font; unused color; unused clip; unused origin
|
||||
unused rotation; unused outer_clip; unused outer_clipped; unused emphasis; unused italic
|
||||
image_error = true
|
||||
}
|
||||
@@ -31,7 +31,7 @@ Player :: struct {
|
||||
Supported :: (module: string, function: string) -> bool {
|
||||
if ModuleName(module,"zx_run") { return function=="ReadBundleInput" || function=="TakeBundleCodepoint" || function=="BundleTextInputHost" || function=="BundleFrameFinishedHost" || function=="BundleFrameReusableHost" }
|
||||
if ModuleName(module,"font_metrics") { return function=="MeasureGlyphWidth" || function=="MeasureGlyphLineHeight" }
|
||||
if ModuleName(module,"raster_text") { return function=="RasterText" || function=="RasterTextClipped" }
|
||||
if ModuleName(module,"raster_text") { return function=="RasterText" || function=="RasterTextClipped" || function=="RasterTextRotated" }
|
||||
if ModuleName(module,"raster_shape") { return function=="RasterRoundedRectangle" || function=="RasterRoundedRectangleOutline" }
|
||||
if ModuleName(module,"raster") { return function=="RasterLine" }
|
||||
if ModuleName(module,"raster_triangles") { return function=="RasterTriangles" }
|
||||
|
||||
@@ -132,6 +132,16 @@ PrepareInput :: (player: *Player) -> bool {
|
||||
cast(s32)args[2].integer, cast(float32)args[3].real, ColorFrom(args[4]))
|
||||
return 1
|
||||
}
|
||||
if function == "RasterTextRotated" && count == 12 &&
|
||||
args[0].kind == HostString && args[1].kind == HostInteger && args[2].kind == HostInteger &&
|
||||
args[3].kind == HostInteger && ColorValue(args[4]) && RectangleValue(args[5]) && VectorValue(args[6]) &&
|
||||
args[7].kind == HostReal && RectangleValue(args[8]) && args[9].kind == HostInteger &&
|
||||
args[10].kind == HostInteger && args[11].kind == HostInteger {
|
||||
RasterTextRotated(TextValue(args[0]),cast(s32)args[1].integer,cast(s32)args[2].integer,
|
||||
cast(s32)args[3].integer,ColorFrom(args[4]),RectangleFrom(args[5]),VectorFrom(args[6]),
|
||||
cast(float32)args[7].real,RectangleFrom(args[8]),args[9].integer != 0,args[10].integer != 0,args[11].integer != 0)
|
||||
return 1
|
||||
}
|
||||
if (function == "RasterText" && count == 5) ||
|
||||
(function == "RasterTextClipped" && count == 6) {
|
||||
if args[0].kind != HostString || args[1].kind != HostInteger ||
|
||||
|
||||
@@ -21,6 +21,10 @@ RasterImageCall :: #type (asset: string, generation: u32, source: Rectangle, des
|
||||
RasterTrianglesCall :: #type (points: []Vector2, color: Color) -> void;
|
||||
RasterImageMeshCall :: #type (asset: string, generation: u32, source: Rectangle, points: []Vector2, columns: s32, rows: s32, clip: Rectangle, tint: Color) -> void;
|
||||
|
||||
RasterTextRotatedCall :: #type (text: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) -> void;
|
||||
|
||||
RasterHost :: struct {
|
||||
asset_bundle: *void
|
||||
x: float32
|
||||
@@ -33,6 +37,7 @@ RasterHost :: struct {
|
||||
rectangle: RasterRoundedRectangleCall
|
||||
outline: RasterRoundedRectangleOutlineCall
|
||||
clipped_text: RasterTextClippedCall
|
||||
rotated_text: RasterTextRotatedCall
|
||||
text: RasterTextCall
|
||||
image: RasterImageCall
|
||||
triangles: RasterTrianglesCall
|
||||
@@ -49,6 +54,7 @@ RasterHostValid :: (host: RasterHost) -> bool {
|
||||
host.outline != null &&
|
||||
host.clipped_text != null &&
|
||||
host.text != null &&
|
||||
host.rotated_text != null &&
|
||||
host.image != null &&
|
||||
host.triangles != null &&
|
||||
host.mesh != null
|
||||
@@ -133,6 +139,18 @@ RasterHostCall :: (context: *void, module: *u8, function_name: *u8,
|
||||
cast(s32)args[2].integer, cast(float32)args[3].real, Values.ColorFrom(args[4]))
|
||||
return 1
|
||||
}
|
||||
if function == "RasterTextRotated" && count == 12 &&
|
||||
args[0].kind == HostString && args[1].kind == HostInteger && args[2].kind == HostInteger &&
|
||||
args[3].kind == HostInteger && Values.ColorValue(args[4]) && Values.RectangleValue(args[5]) &&
|
||||
Values.VectorValue(args[6]) && args[7].kind == HostReal && Values.RectangleValue(args[8]) &&
|
||||
args[9].kind == HostInteger && args[10].kind == HostInteger && args[11].kind == HostInteger {
|
||||
origin := Values.VectorFrom(args[6]); origin.x += host.x; origin.y += host.y
|
||||
host.rotated_text(Values.TextValue(args[0]),cast(s32)args[1].integer+cast(s32)host.x,
|
||||
cast(s32)args[2].integer+cast(s32)host.y,cast(s32)args[3].integer,Values.ColorFrom(args[4]),
|
||||
RasterHostBounds(host,args[5]),origin,cast(float32)args[7].real,RasterHostBounds(host,args[8]),
|
||||
args[9].integer != 0,args[10].integer != 0,args[11].integer != 0)
|
||||
return 1
|
||||
}
|
||||
if (function == "RasterText" && count == 5) ||
|
||||
(function == "RasterTextClipped" && count == 6) {
|
||||
if args[0].kind != HostString || args[1].kind != HostInteger ||
|
||||
|
||||
@@ -148,7 +148,7 @@ RaylibBundleOpen :: (host: *RaylibBundle, data: string, previous: *RaylibBundle
|
||||
.measure_width = MeasureGlyphWidth, .measure_height = MeasureGlyphLineHeight,
|
||||
.image_width = ImageWidth, .image_height = ImageHeight,
|
||||
.line = RasterLine, .rectangle = RasterRoundedRectangle, .outline = RasterRoundedRectangleOutline,
|
||||
.text = RasterText, .clipped_text = RasterTextClipped,
|
||||
.text = RasterText, .clipped_text = RasterTextClipped, .rotated_text = RasterTextRotated,
|
||||
.image = RasterImage, .triangles = RasterTriangles, .mesh = RasterImageMesh}
|
||||
RaylibSetAssetReader(RaylibBundleAsset, cast(*void)host)
|
||||
if !Player.PlayerUseRenderer(*host.player, RasterHostCall, cast(*void)(*host.raster)) ||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#import "font_metrics"
|
||||
#import "image_props"
|
||||
#import "paint_texture"
|
||||
#import "math"
|
||||
Utf8 :: #import "std/utf8";
|
||||
Video :: #import "video_linux";
|
||||
video_surface: *void;
|
||||
@@ -118,6 +119,7 @@ CairoMatrix :: struct {
|
||||
y0: float64
|
||||
}
|
||||
TransformBy :: (paint: *void, matrix: *CairoMatrix) #foreign cairo_library "cairo_transform";
|
||||
GetMatrix :: (paint: *void, matrix: *CairoMatrix) #foreign cairo_library "cairo_get_matrix";
|
||||
PatternForSurface :: (surface: *void) -> *void #foreign cairo_library "cairo_pattern_create_for_surface";
|
||||
PatternDestroy :: (pattern: *void) #foreign cairo_library "cairo_pattern_destroy";
|
||||
SetSource :: (paint: *void, pattern: *void) #foreign cairo_library "cairo_set_source";
|
||||
@@ -208,6 +210,80 @@ frame_pending: bool;
|
||||
Decode :: #import "image_decode_linux";
|
||||
CachedImage :: struct { path: [4096]u8; length: s32; image: *void; used: u64; bytes: s64; }
|
||||
cached_images: [128]CachedImage;
|
||||
|
||||
// Repeated smooth downscaling can dominate a frame even when decoded images
|
||||
// are retained. Cache device-aligned samples, including the subpixel phase,
|
||||
// so clipping, tint and translation still compose on the original paint.
|
||||
ScaledImage :: struct {
|
||||
source: *void; image: *void; width: float32; height: float32;
|
||||
phase_x: float32; phase_y: float32; used: u64; bytes: s64;
|
||||
}
|
||||
scaled_images: [32]ScaledImage;
|
||||
scaled_bytes: s64;
|
||||
scaled_clock: u64;
|
||||
ClearScaledImage :: (index: s32) {
|
||||
if scaled_images[index].image != null { SurfaceDestroy(scaled_images[index].image) }
|
||||
scaled_bytes -= scaled_images[index].bytes
|
||||
scaled_images[index] = .{}
|
||||
}
|
||||
ForgetScaledImage :: (source: *void) {
|
||||
for i: cast(s32)0..31 { if scaled_images[i].source == source { ClearScaledImage(i) } }
|
||||
}
|
||||
ScaledImageFor :: (image: *void, source: Rectangle, destination: Rectangle) -> *void {
|
||||
if !Finite32(destination.x) || !Finite32(destination.y) || !Finite32(destination.width) ||
|
||||
!Finite32(destination.height) || destination.width > 4096.0 || destination.height > 4096.0 ||
|
||||
destination.x < -1048576.0 || destination.x > 1048576.0 ||
|
||||
destination.y < -1048576.0 || destination.y > 1048576.0 { return null }
|
||||
width := ImageSurfaceWidth(image); height := ImageSurfaceHeight(image)
|
||||
if image == video_surface || source.x != 0.0 || source.y != 0.0 ||
|
||||
source.width != cast(float32)width || source.height != cast(float32)height ||
|
||||
cast(s64)width * height < 65536 || destination.width >= source.width ||
|
||||
destination.height >= source.height { return null }
|
||||
matrix: CairoMatrix; GetMatrix(paint, *matrix)
|
||||
if matrix.xx != 1.0 || matrix.yy != 1.0 || matrix.xy != 0.0 || matrix.yx != 0.0 ||
|
||||
matrix.x0 != 0.0 || matrix.y0 != 0.0 { return null }
|
||||
px := destination.x - cast(float32)FloorInteger(destination.x)
|
||||
py := destination.y - cast(float32)FloorInteger(destination.y)
|
||||
scaled_clock += 1
|
||||
for i: cast(s32)0..31 {
|
||||
entry := *scaled_images[i]
|
||||
if entry.source == image && entry.width == destination.width && entry.height == destination.height &&
|
||||
entry.phase_x == px && entry.phase_y == py {
|
||||
entry.used = scaled_clock; return entry.image
|
||||
}
|
||||
}
|
||||
w := CeilInteger(px + destination.width)
|
||||
h := CeilInteger(py + destination.height)
|
||||
bytes := cast(s64)w * h * 4
|
||||
if w <= 0 || h <= 0 || bytes > 67108864 { return null }
|
||||
slot: s32 = -1
|
||||
while true {
|
||||
oldest: s32 = -1
|
||||
for i: cast(s32)0..31 {
|
||||
if scaled_images[i].image == null { if slot < 0 { slot = i }; continue }
|
||||
if oldest < 0 || scaled_images[i].used < scaled_images[oldest].used { oldest = i }
|
||||
}
|
||||
if slot >= 0 && scaled_bytes + bytes <= 67108864 { break }
|
||||
if oldest < 0 { return null }
|
||||
ClearScaledImage(oldest)
|
||||
if slot < 0 { slot = oldest }
|
||||
}
|
||||
sampled := ImageSurfaceCreate(0, w, h)
|
||||
if sampled == null || SurfaceStatus(sampled) != 0 {
|
||||
if sampled != null { SurfaceDestroy(sampled) }; return null
|
||||
}
|
||||
context := Create(sampled)
|
||||
Translate(context, px, py)
|
||||
Scale(context, cast(float64)destination.width / source.width, cast(float64)destination.height / source.height)
|
||||
pattern := PatternForSurface(image)
|
||||
PatternFilter(pattern, 1); SetSource(context, pattern); Paint(context)
|
||||
PatternDestroy(pattern)
|
||||
ok := Status(context) == 0; Destroy(context)
|
||||
if !ok { SurfaceDestroy(sampled); return null }
|
||||
scaled_images[slot] = .{image, sampled, destination.width, destination.height, px, py, scaled_clock, bytes}
|
||||
scaled_bytes += bytes
|
||||
return sampled
|
||||
}
|
||||
image_clock: u64;
|
||||
image_bytes: s64;
|
||||
|
||||
@@ -324,6 +400,7 @@ OpenRaster :: (width: s32, height: s32) -> bool {
|
||||
|
||||
#program_export
|
||||
CloseRaster :: () {
|
||||
for i: cast(s32)0..31 { ClearScaledImage(i) }
|
||||
if video_surface != null { SurfaceDestroy(video_surface); video_surface = null }
|
||||
video_revision = 0; video_width = 0; video_height = 0
|
||||
GlyphCaretClear()
|
||||
@@ -605,6 +682,7 @@ LoadPNG :: (asset_path: string) -> *void {
|
||||
if slot >= 0 && image_bytes + bytes <= 268435456 { break }
|
||||
if oldest < 0 { SurfaceDestroy(image); return null }
|
||||
image_bytes -= cached_images[oldest].bytes
|
||||
ForgetScaledImage(cached_images[oldest].image)
|
||||
SurfaceDestroy(cached_images[oldest].image); cached_images[oldest] = .{}
|
||||
if slot < 0 { slot = oldest }
|
||||
}
|
||||
@@ -658,6 +736,10 @@ RasterImage :: (asset_path: string, texture_id: u32,
|
||||
image_error = true
|
||||
return
|
||||
}
|
||||
sampled: *void
|
||||
if rotation == 0.0 && origin.x == 0.0 && origin.y == 0.0 && CurrentPaintSmooth() {
|
||||
sampled = ScaledImageFor(image, source, destination)
|
||||
}
|
||||
Save(paint)
|
||||
RoundBox(clip, radius)
|
||||
Clip(paint)
|
||||
@@ -672,6 +754,16 @@ RasterImage :: (asset_path: string, texture_id: u32,
|
||||
}
|
||||
ClosePath(paint); Clip(paint)
|
||||
}
|
||||
if sampled != null {
|
||||
// Apply the same destination edge clip once, after sampling, so a
|
||||
// fractional edge does not acquire a second antialiasing coverage.
|
||||
CanvasRectangle(paint, destination.x, destination.y, destination.width, destination.height)
|
||||
Clip(paint)
|
||||
Translate(paint, cast(float64)FloorInteger(destination.x), cast(float64)FloorInteger(destination.y))
|
||||
pattern := PatternForSurface(sampled)
|
||||
PatternFilter(pattern, 3); PaintImagePattern(pattern, tint)
|
||||
PatternDestroy(pattern); Restore(paint); return
|
||||
}
|
||||
Translate(paint, destination.x,
|
||||
destination.y)
|
||||
Rotate(paint, cast(float64)rotation *
|
||||
@@ -801,3 +893,17 @@ CairoMeshTriangle :: (image: *void, a: Vector2, a_source: Vector2,
|
||||
PatternDestroy(pattern)
|
||||
Restore(paint)
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32,
|
||||
color: Color, clip: Rectangle, origin: Vector2, rotation: float32,
|
||||
outer_clip: Rectangle, outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
PrepareRasterPaint(); Save(paint)
|
||||
if outer_clipped { NewPath(paint); CanvasRectangle(paint,outer_clip.x,outer_clip.y,outer_clip.width,outer_clip.height); Clip(paint) }
|
||||
Translate(paint,origin.x,origin.y); Rotate(paint,cast(float64)rotation*0.017453292519943295)
|
||||
Translate(paint,-origin.x,-origin.y)
|
||||
unused italic
|
||||
stroke := ifx emphasis then (ifx font / 24 > 0 then font / 24 else 1) else 0
|
||||
RasterTextClipped(value,x+stroke,y,font,color,clip)
|
||||
Restore(paint)
|
||||
}
|
||||
@@ -302,3 +302,26 @@ CanvasMeshTriangle :: (id: s32, a: Vector2, a_source: Vector2, b: Vector2,
|
||||
cast(float64)c_source.x, cast(float64)c_source.y,
|
||||
cast(s32)tint.r, cast(s32)tint.g, cast(s32)tint.b, cast(s32)tint.a, filter)
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32,
|
||||
color: Color, clip: Rectangle, origin: Vector2, rotation: float32,
|
||||
outer_clip: Rectangle, outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
scope := WebScope(); ctx := PageContext()
|
||||
unused WebCall0(ctx,WebName("save"))
|
||||
if outer_clipped {
|
||||
unused WebCall0(ctx,WebName("beginPath"))
|
||||
unused WebCall4(ctx,WebName("rect"),WebNumber(outer_clip.x),WebNumber(outer_clip.y),WebNumber(outer_clip.width),WebNumber(outer_clip.height))
|
||||
unused WebCall0(ctx,WebName("clip"))
|
||||
}
|
||||
unused WebCall2(ctx,WebName("translate"),WebNumber(origin.x),WebNumber(origin.y))
|
||||
unused WebCall1(ctx,WebName("rotate"),WebNumber(cast(float64)rotation*0.017453292519943295))
|
||||
unused WebCall2(ctx,WebName("translate"),WebNumber(-origin.x),WebNumber(-origin.y))
|
||||
unused WebCall0(ctx,WebName("beginPath"))
|
||||
unused WebCall4(ctx,WebName("rect"),WebNumber(clip.x),WebNumber(clip.y),WebNumber(clip.width),WebNumber(clip.height))
|
||||
unused WebCall0(ctx,WebName("clip"))
|
||||
unused italic
|
||||
stroke := ifx emphasis then (ifx font / 24 > 0 then font / 24 else 1) else 0
|
||||
RasterText(value,x+stroke,y,font,color)
|
||||
unused WebCall0(ctx,WebName("restore")); WebEnd(scope)
|
||||
}
|
||||
@@ -74,6 +74,13 @@ DomPaintRecord :: (queued: QueuedPaint) -> bool {
|
||||
scope := WebScope()
|
||||
defer { WebEnd(scope) }
|
||||
p := queued.data
|
||||
if (p.kind == 4 || p.kind == 6) && p.rotation != 0.0 {
|
||||
dom_paint_tile_node = -2
|
||||
if dom_paint_tile_context != 0 { WebRelease(dom_paint_tile_context) }
|
||||
dom_paint_tile_context = 0
|
||||
DomRotatedText(p)
|
||||
return true
|
||||
}
|
||||
native := p.kind >= 1 && p.kind <= 7
|
||||
if p.kind == 1 && p.bounds.width != 0.0 && p.bounds.height != 0.0 { native = false }
|
||||
image_id: s32
|
||||
@@ -266,3 +273,49 @@ DomPaintClose :: () {
|
||||
DomPaintCss(PageCanvas(),"visibility","visible")
|
||||
WebEnd(scope)
|
||||
}
|
||||
|
||||
// The outer box keeps ancestor clipping in world space; the child keeps
|
||||
// text clipping, selection and the rotation in local space.
|
||||
DomRotatedText :: (p: PaintCommand) {
|
||||
outer := DomPaintElement("div",p.kind)
|
||||
if outer == 0 { return }
|
||||
bounds := RotatedRectangleBounds(p.clip,p.origin,p.rotation)
|
||||
if p.text_outer_clipped { bounds = RectangleIntersection(bounds,p.text_outer_clip) }
|
||||
DomPaintBox(outer,bounds); DomPaintCss(outer,"overflow","hidden")
|
||||
at := dom_paint_used-1
|
||||
inner := dom_paint_nodes[at].child
|
||||
if inner == 0 {
|
||||
inner = WebAsObject(WebCall1(WebGetObject(WebGlobal,WebName("document")),WebName("createElement"),WebText("span")))
|
||||
dom_paint_nodes[at].child = WebKeep(inner)
|
||||
unused WebCall1(outer,WebName("appendChild"),WebObject(inner))
|
||||
}
|
||||
DomPaintCss(inner,"position","absolute")
|
||||
DomPaintCss(inner,"whiteSpace","pre"); DomPaintCss(inner,"pointerEvents","auto"); DomPaintCss(inner,"userSelect","text")
|
||||
previous := TextTypefaceUse(p.asset_path)
|
||||
face: s32
|
||||
if canvas_font_loaded { face = CanvasFontFace(canvas_font) }
|
||||
size := PageTextSizeFor(PageMeasureContext(),face,p.font)
|
||||
DomPaintCss(inner,"font",PageFontSpec(size.hundredths,face))
|
||||
unused TextTypefaceUse(previous)
|
||||
DomPaintLength(inner,"lineHeight",cast(float64)p.font)
|
||||
DomPaintCss(inner,"color",PageColor(p.color.r,p.color.g,p.color.b,p.color.a))
|
||||
DomPaintCss(inner,"fontStyle",ifx p.italic then "italic" else "normal")
|
||||
DomPaintCss(inner,"fontWeight",ifx p.emphasis then "bold" else "normal")
|
||||
if !DomSame(WebGet(inner,WebName("textContent")),WebText(p.value)) { WebSet(inner,WebName("textContent"),WebText(p.value)) }
|
||||
// Put the local clip on a full local box; text keeps its own offset.
|
||||
DomPaintBox(inner,Rectangle.{cast(float32)p.x-bounds.x,cast(float32)p.y-bounds.y,
|
||||
cast(float32)PageTextWidth(face,p.value,p.font)+2.0,cast(float32)p.font})
|
||||
transform: Vec(u8)
|
||||
BuilderPrint(*transform,"rotate(%deg)",p.rotation)
|
||||
DomPaintCss(inner,"transform",BuilderFinish(transform))
|
||||
pivot: Vec(u8)
|
||||
BuilderPrint(*pivot,"%px %px",p.origin.x-cast(float32)p.x,p.origin.y-cast(float32)p.y)
|
||||
DomPaintCss(inner,"transformOrigin",BuilderFinish(pivot))
|
||||
path: Vec(u8)
|
||||
right := p.clip.x+p.clip.width-cast(float32)p.x
|
||||
bottom := p.clip.y+p.clip.height-cast(float32)p.y
|
||||
BuilderPrint(*path,"polygon(%px %px,%px %px,%px %px,%px %px)",
|
||||
p.clip.x-cast(float32)p.x,p.clip.y-cast(float32)p.y,
|
||||
right,p.clip.y-cast(float32)p.y,right,bottom,p.clip.x-cast(float32)p.x,bottom)
|
||||
DomPaintCss(inner,"clipPath",BuilderFinish(path))
|
||||
}
|
||||
+62
-3
@@ -669,6 +669,27 @@ PixmapDrawEmoji :: (emoji: s32, x: s32, y: s32, size: s32) {
|
||||
if offset < 0 { return }
|
||||
color: Color
|
||||
color.a = cast(u8)255
|
||||
if pixmap_text_rotation != 0.0 {
|
||||
bounds := Rectangle.{cast(float32)x/pixmap_scale_x,cast(float32)y/pixmap_scale_y,
|
||||
cast(float32)size/pixmap_scale_x,cast(float32)size/pixmap_scale_y}
|
||||
area := PixmapDeviceBounds(RotatedRectangleBounds(bounds,pixmap_text_origin,pixmap_text_rotation))
|
||||
camera: Camera = .{.offset=pixmap_text_origin,.target=pixmap_text_origin,.rotation=pixmap_text_rotation,.zoom=1.0}
|
||||
for row: cast(s32)area.y-1..cast(s32)(area.y+area.height)+1 {
|
||||
for column: cast(s32)area.x-1..cast(s32)(area.x+area.width)+1 {
|
||||
point := ScreenToWorld(Vector2.{(cast(float32)column+0.5)/pixmap_scale_x,(cast(float32)row+0.5)/pixmap_scale_y},camera)
|
||||
clip := pixmap_text_local_clip
|
||||
sx := cast(s32)(point.x*pixmap_scale_x)-x; sy := cast(s32)(point.y*pixmap_scale_y)-y
|
||||
if sx >= 0 && sy >= 0 && sx < size && sy < size && point.x >= clip.x && point.y >= clip.y &&
|
||||
point.x < clip.x+clip.width && point.y < clip.y+clip.height {
|
||||
pixel := pixmap_emoji_pool[offset+sy*size+sx]
|
||||
tint: Color = .{cast(u8)((pixel >> cast(u32)16) & cast(u32)255),
|
||||
cast(u8)((pixel >> cast(u32)8) & cast(u32)255),cast(u8)(pixel & cast(u32)255),cast(u8)255}
|
||||
PixmapBlend(cast(s32)column,cast(s32)row,tint,cast(s32)(pixel >> cast(u32)24))
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if pixmap_gpu_active {
|
||||
key := -(cast(s64)emoji * 256 + cast(s64)size + 1) - (cast(s64)1 << cast(s64)56)
|
||||
slot := PixmapGpuFind(key)
|
||||
@@ -719,6 +740,7 @@ PixmapBlendMaskRGB :: (old: u32, source_rb: u32, source_green: u32,
|
||||
// Source channels and host alpha are constant; only coverage and the old
|
||||
// RGB channels vary per pixel. No glyph-sized color cache is needed.
|
||||
PixmapBlendMask :: (mask: PixmapGlyphMask, coverage: []u8, color: Color) {
|
||||
if pixmap_text_rotation != 0.0 { PixmapBlendRotatedMask(mask,coverage,color); return }
|
||||
source_alpha := cast(u32)color.a
|
||||
if source_alpha == cast(u32)0 { return }
|
||||
top: s32 = mask.top
|
||||
@@ -782,7 +804,7 @@ PixmapDrawText :: (value: string, x: s32, y: s32, font: s32, pen_font: s64, colo
|
||||
// A glyph stays well within two font sizes of its line box and advance,
|
||||
// so text past the clip draws nothing and is not rasterized.
|
||||
reach: s32 = font * 2
|
||||
if y + font + reach <= pixmap_clip_top || y - reach >= pixmap_clip_bottom { return }
|
||||
if pixmap_text_rotation == 0.0 && (y + font + reach <= pixmap_clip_top || y - reach >= pixmap_clip_bottom) { return }
|
||||
baseline: s64 = cast(s64)y * 256 + PixmapTextBaseline(font)
|
||||
pen: s64 = 0
|
||||
mask: PixmapGlyphMask
|
||||
@@ -794,8 +816,8 @@ PixmapDrawText :: (value: string, x: s32, y: s32, font: s32, pen_font: s64, colo
|
||||
origin: s64 = cast(s64)x * 256 + PixmapFloorDiv(pen * pen_font, cast(s64)PixmapTextLine)
|
||||
whole: s32 = cast(s32)PixmapFloorDiv(origin, 256)
|
||||
// Advances never move left, so no later glyph reaches the clip.
|
||||
if whole - reach >= pixmap_clip_right { break }
|
||||
if whole + PixmapTextWidth(unit.advance, font) + reach > pixmap_clip_left {
|
||||
if pixmap_text_rotation == 0.0 && whole - reach >= pixmap_clip_right { break }
|
||||
if pixmap_text_rotation != 0.0 || whole + PixmapTextWidth(unit.advance, font) + reach > pixmap_clip_left {
|
||||
if unit.emoji >= 0 {
|
||||
PixmapDrawEmoji(unit.emoji, whole, y, font)
|
||||
} else if unit.glyph >= 0 {
|
||||
@@ -1334,3 +1356,40 @@ SystemClipboardWriteHost :: (text: string) -> bool {
|
||||
unused text
|
||||
return false
|
||||
}
|
||||
|
||||
pixmap_text_rotation: float32;
|
||||
pixmap_text_origin: Vector2;
|
||||
pixmap_text_local_clip: Rectangle;
|
||||
PixmapBlendRotatedMask :: (mask: PixmapGlyphMask, coverage: []u8, color: Color) {
|
||||
// Rotate in logical units so nonuniform device density preserves the angle.
|
||||
local := Rectangle.{cast(float32)mask.left/pixmap_scale_x,cast(float32)mask.top/pixmap_scale_y,
|
||||
cast(float32)mask.width/pixmap_scale_x,cast(float32)mask.height/pixmap_scale_y}
|
||||
bounds := PixmapDeviceBounds(RotatedRectangleBounds(local,pixmap_text_origin,pixmap_text_rotation))
|
||||
camera: Camera = .{.offset=pixmap_text_origin,.target=pixmap_text_origin,.rotation=pixmap_text_rotation,.zoom=1.0}
|
||||
for y: cast(s32)bounds.y-1..cast(s32)(bounds.y+bounds.height)+1 {
|
||||
for x: cast(s32)bounds.x-1..cast(s32)(bounds.x+bounds.width)+1 {
|
||||
point := ScreenToWorld(Vector2.{(cast(float32)x+0.5)/pixmap_scale_x,(cast(float32)y+0.5)/pixmap_scale_y},camera)
|
||||
clip := pixmap_text_local_clip
|
||||
if point.x >= clip.x && point.y >= clip.y && point.x < clip.x+clip.width && point.y < clip.y+clip.height {
|
||||
column := cast(s32)(point.x*pixmap_scale_x)-mask.left
|
||||
row := cast(s32)(point.y*pixmap_scale_y)-mask.top
|
||||
if column >= 0 && row >= 0 && column < mask.width && row < mask.height {
|
||||
PixmapBlend(x,y,color,cast(s32)coverage[row*mask.width+column])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32,
|
||||
color: Color, clip: Rectangle, origin: Vector2, rotation: float32,
|
||||
outer_clip: Rectangle, outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
left := pixmap_clip_left; top := pixmap_clip_top; right := pixmap_clip_right; bottom := pixmap_clip_bottom
|
||||
if outer_clipped { PixmapClipTo(outer_clip) }
|
||||
pixmap_text_rotation = rotation; pixmap_text_origin = origin; pixmap_text_local_clip = clip
|
||||
unused italic
|
||||
stroke := ifx emphasis then (ifx font / 24 > 0 then font / 24 else 1) else 0
|
||||
RasterText(value,x+stroke,y,font,color)
|
||||
pixmap_text_rotation = 0.0
|
||||
pixmap_clip_left=left; pixmap_clip_top=top; pixmap_clip_right=right; pixmap_clip_bottom=bottom
|
||||
}
|
||||
@@ -12,6 +12,7 @@ RAYLIB_FRAME_THREADS :: #defined(ANDROID_BUILD) || #defined(KRYON_FRAME_THREADS)
|
||||
#import "c_string"
|
||||
#import "drawing_props"
|
||||
#import "geometry"
|
||||
#import "math"
|
||||
#import "test_driver"
|
||||
#import "session"
|
||||
#import "image_props"
|
||||
@@ -112,6 +113,7 @@ RaylibGlyphInfo :: struct {
|
||||
advance_x: s32
|
||||
image: ImagePixels.RaylibGlyphImage
|
||||
}
|
||||
HostRaylibDefaultFont :: () -> RaylibFont #foreign raylib "GetFontDefault";
|
||||
HostRaylibGlyphIndex :: (font: RaylibFont, codepoint: s32) -> s32 #foreign raylib "GetGlyphIndex";
|
||||
HostRaylibCodepoint :: (value: *u8, length: *s32) -> s32 #foreign raylib "GetCodepointNext";
|
||||
HostRaylibLoadFont :: (path: *u8, size: s32, codepoints: *s32,
|
||||
@@ -2545,7 +2547,7 @@ RaylibTextWithFallback :: (value: string, x: s32, y: s32, size: s32,
|
||||
RaylibDrawEmphasis(RaylibGlyphFont(selected, codepoint), *glyph[0], glyph_position,
|
||||
text_size, color, pixels, matrix)
|
||||
} else {
|
||||
HostRaylibDrawFontText(RaylibGlyphFont(selected, codepoint), *glyph[0],
|
||||
RaylibDrawClippedGlyph(RaylibGlyphFont(selected, codepoint), *glyph[0],
|
||||
glyph_position, text_size, 0.0, color)
|
||||
}
|
||||
if raylib_text_italic {
|
||||
@@ -2575,7 +2577,7 @@ RaylibDrawEmphasis :: (font: RaylibFont, glyph: *u8, position: Vector2,
|
||||
step = 1.0 / matrix.m0
|
||||
}
|
||||
for stroke: 1..strokes {
|
||||
HostRaylibDrawFontText(font, glyph,
|
||||
RaylibDrawClippedGlyph(font, glyph,
|
||||
.{position.x + step * cast(float32)stroke, position.y}, size, 0.0, color)
|
||||
}
|
||||
}
|
||||
@@ -4291,3 +4293,58 @@ PollSecondaryPointer :: () -> SecondaryPointerFrame { return raylib_secondary }
|
||||
return ok
|
||||
}
|
||||
}
|
||||
|
||||
// Clip each glyph in its own local coordinates before rotating its quad.
|
||||
// This avoids a rotated scissor's enlarged bounding box leaking glyph edges.
|
||||
raylib_rotated_text: bool;
|
||||
raylib_rotated_text_clip: Rectangle;
|
||||
RaylibDrawClippedGlyph :: (font: RaylibFont, value: *u8, position: Vector2,
|
||||
size: float32, spacing: float32, tint: Color) {
|
||||
if !raylib_rotated_text { HostRaylibDrawFontText(font,value,position,size,spacing,tint); return }
|
||||
length: s32
|
||||
code := HostRaylibCodepoint(value,*length)
|
||||
index := HostRaylibGlyphIndex(font,code)
|
||||
glyphs := cast(*RaylibGlyphInfo)font.glyphs
|
||||
scale := size / cast(float32)font.base_size
|
||||
padding := cast(float32)font.glyph_padding
|
||||
rec := font.recs[index]
|
||||
source := Rectangle.{rec.x-padding,rec.y-padding,rec.width+2.0*padding,rec.height+2.0*padding}
|
||||
destination := Rectangle.{position.x+(cast(float32)glyphs[index].offset_x-padding)*scale,
|
||||
position.y+(cast(float32)glyphs[index].offset_y-padding)*scale,source.width*scale,source.height*scale}
|
||||
visible := RectangleIntersection(destination,raylib_rotated_text_clip)
|
||||
if visible.width <= 0.0 || visible.height <= 0.0 { return }
|
||||
source.x += (visible.x-destination.x)/scale; source.y += (visible.y-destination.y)/scale
|
||||
source.width = visible.width/scale; source.height = visible.height/scale
|
||||
HostRaylibDrawTexture(font.texture,source,visible,Vector2.{},0.0,tint)
|
||||
}
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32,
|
||||
color: Color, clip: Rectangle, origin: Vector2, rotation: float32,
|
||||
outer_clip: Rectangle, outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
#if RAYLIB_FRAME_THREADS {
|
||||
if RecordFrameOperation(PaintCommand.{.value=value,.x=x,.y=y,.font=font,.color=color,
|
||||
.clip=clip,.origin=origin,.rotation=rotation,.text_outer_clip=outer_clip,
|
||||
.text_outer_clipped=outer_clipped,.emphasis=emphasis,.italic=italic}, RaylibReplayRotatedText) { return }
|
||||
}
|
||||
saved: RasterClipState
|
||||
if outer_clipped { saved = BeginRasterClip(outer_clip) }
|
||||
sine := SineDegrees(rotation); cosine := CosineDegrees(rotation)
|
||||
matrix: [16]float32 = .[cosine,sine,0.0,0.0,-sine,cosine,0.0,0.0,0.0,0.0,1.0,0.0,
|
||||
origin.x-cosine*origin.x+sine*origin.y,origin.y-sine*origin.x-cosine*origin.y,0.0,1.0]
|
||||
HostRaylibPushMatrix(); HostRaylibMultMatrix(*matrix[0])
|
||||
raylib_rotated_text = true; raylib_rotated_text_clip = clip
|
||||
raylib_text_emphasis = emphasis; raylib_text_italic = italic
|
||||
old_font := raylib_font; old_loaded := raylib_font_loaded
|
||||
if !old_loaded { raylib_font = HostRaylibDefaultFont(); raylib_font_loaded = true }
|
||||
RasterText(value,x,y,font,color)
|
||||
raylib_font = old_font; raylib_font_loaded = old_loaded
|
||||
raylib_text_emphasis = false; raylib_text_italic = false; raylib_rotated_text = false
|
||||
HostRaylibPopMatrix()
|
||||
if outer_clipped { EndRasterClip(saved) }
|
||||
}
|
||||
#if RAYLIB_FRAME_THREADS {
|
||||
RaylibReplayRotatedText :: (p: PaintCommand) {
|
||||
RasterTextRotated(p.value,p.x,p.y,p.font,p.color,p.clip,p.origin,p.rotation,
|
||||
p.text_outer_clip,p.text_outer_clipped,p.emphasis,p.italic)
|
||||
}
|
||||
}
|
||||
@@ -337,3 +337,28 @@ SystemClipboardWriteHost :: (text: string) -> bool {
|
||||
unused text
|
||||
return false
|
||||
}
|
||||
|
||||
// Terminal layout uses cells: rotate each glyph's cell position. The terminal
|
||||
// still owns the appearance of each character, as for ordinary terminal text.
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32,
|
||||
color: Color, clip: Rectangle, origin: Vector2, rotation: float32,
|
||||
outer_clip: Rectangle, outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused font; unused color; unused emphasis; unused italic
|
||||
camera: Camera = .{.offset=origin,.target=origin,.rotation=rotation,.zoom=1.0}
|
||||
at: s32; column: s32 = x
|
||||
while at < cast(s32)value.count {
|
||||
glyph := Decode(value,at)
|
||||
if glyph.after <= at { break }
|
||||
if cast(float32)column >= clip.x && cast(float32)column < clip.x+clip.width &&
|
||||
cast(float32)y >= clip.y && cast(float32)y < clip.y+clip.height {
|
||||
point := WorldToScreen(Vector2.{cast(float32)column,cast(float32)y},camera)
|
||||
if !outer_clipped || (point.x >= outer_clip.x && point.y >= outer_clip.y &&
|
||||
point.x < outer_clip.x+outer_clip.width && point.y < outer_clip.y+outer_clip.height) {
|
||||
cell: Cell; cell.glyph = glyph.value
|
||||
CellPut(terminal_buffer[0:1920],terminal_columns,terminal_rows,cast(s32)point.x,cast(s32)point.y,cell)
|
||||
}
|
||||
}
|
||||
column += 1; at = glyph.after
|
||||
}
|
||||
}
|
||||
+34
-29
@@ -175,9 +175,36 @@ WidgetValidTextRange :: (value: HostValue) -> bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Widget codec schema: ["TextProps",[["key","u64"],["bounds","Rectangle"],["text","string"],["font","s32"],["fallback_font","s32"],["style_kind","s32"],["semantic_kind","SemanticKind"],["heading_level","s32"],["class_name","s32"],["wrap","TextWrap"],["align","TextAlign"],["vertical_align","TextAlign"],["disabled","bool"],["selectable","bool"],["strikethrough","bool"],["strong","[]TextRange"],["typing","bool"],["typed","s32"],["links","[]TextRange"],["typeface","string"],["line_gap","s32"]]]
|
||||
WidgetVector2Codec :: struct {
|
||||
fields: [2]HostField
|
||||
}
|
||||
|
||||
WidgetEncodeVector2 :: (data: Vector2, codec: *WidgetVector2Codec) -> HostValue {
|
||||
value := HostRecordValue("Vector2", codec.fields[:])
|
||||
codec.fields[0] = HostField.{.name = HostTextData("x"), .value = HostValue.{.kind = cast(s32)HostReal, .type_name = HostTextData("float32"), .real = cast(float64)data.x}}
|
||||
codec.fields[1] = HostField.{.name = HostTextData("y"), .value = HostValue.{.kind = cast(s32)HostReal, .type_name = HostTextData("float32"), .real = cast(float64)data.y}}
|
||||
return value
|
||||
}
|
||||
|
||||
WidgetDecodeVector2 :: (value: HostValue, codec: *WidgetVector2Codec) -> Vector2 {
|
||||
data: Vector2
|
||||
unused codec
|
||||
zero: HostValue
|
||||
data.x = cast(float32)HostFieldValue(*value, 0, "x", *zero).real
|
||||
data.y = cast(float32)HostFieldValue(*value, 1, "y", *zero).real
|
||||
return data
|
||||
}
|
||||
|
||||
WidgetValidVector2 :: (value: HostValue) -> bool {
|
||||
if !HostRecordValid(*value, "Vector2") { return false }
|
||||
if !HostFieldScalarValid(*value, 0, "x", "float32", cast(s32)HostReal) { return false }
|
||||
if !HostFieldScalarValid(*value, 1, "y", "float32", cast(s32)HostReal) { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
// Widget codec schema: ["TextProps",[["key","u64"],["bounds","Rectangle"],["text","string"],["font","s32"],["fallback_font","s32"],["style_kind","s32"],["semantic_kind","SemanticKind"],["heading_level","s32"],["class_name","s32"],["wrap","TextWrap"],["align","TextAlign"],["vertical_align","TextAlign"],["disabled","bool"],["selectable","bool"],["strikethrough","bool"],["strong","[]TextRange"],["typing","bool"],["typed","s32"],["links","[]TextRange"],["typeface","string"],["line_gap","s32"],["rotation","float32"],["origin","Vector2"]]]
|
||||
WidgetTextPropsCodec :: struct {
|
||||
fields: [21]HostField
|
||||
fields: [23]HostField
|
||||
bounds: WidgetRectangleCodec
|
||||
strong_values: [1024]HostValue
|
||||
strong_codecs: [1024]WidgetTextRangeCodec
|
||||
@@ -185,6 +212,7 @@ WidgetTextPropsCodec :: struct {
|
||||
links_values: [1024]HostValue
|
||||
links_codecs: [1024]WidgetTextRangeCodec
|
||||
links_decoded: [1024]TextRange
|
||||
origin: WidgetVector2Codec
|
||||
}
|
||||
|
||||
WidgetDecodeTextProps :: (value: HostValue, codec: *WidgetTextPropsCodec) -> TextProps {
|
||||
@@ -235,6 +263,8 @@ WidgetDecodeTextProps :: (value: HostValue, codec: *WidgetTextPropsCodec) -> Tex
|
||||
}
|
||||
data.typeface = HostValueText(HostFieldValue(*value, 19, "typeface", *zero).*)
|
||||
data.line_gap = cast(s32)HostFieldValue(*value, 20, "line_gap", *zero).integer
|
||||
data.rotation = cast(float32)HostFieldValue(*value, 21, "rotation", *zero).real
|
||||
data.origin = WidgetDecodeVector2(HostFieldValue(*value, 22, "origin", *zero).*, *codec.origin)
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -263,33 +293,8 @@ WidgetValidTextProps :: (value: HostValue) -> bool {
|
||||
HostElementRule.{.validate_record = WidgetValidTextRange}) { return false }
|
||||
if !HostFieldScalarValid(*value, 19, "typeface", "string", cast(s32)HostString) { return false }
|
||||
if !HostFieldScalarValid(*value, 20, "line_gap", "s32", cast(s32)HostInteger) { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
WidgetVector2Codec :: struct {
|
||||
fields: [2]HostField
|
||||
}
|
||||
|
||||
WidgetEncodeVector2 :: (data: Vector2, codec: *WidgetVector2Codec) -> HostValue {
|
||||
value := HostRecordValue("Vector2", codec.fields[:])
|
||||
codec.fields[0] = HostField.{.name = HostTextData("x"), .value = HostValue.{.kind = cast(s32)HostReal, .type_name = HostTextData("float32"), .real = cast(float64)data.x}}
|
||||
codec.fields[1] = HostField.{.name = HostTextData("y"), .value = HostValue.{.kind = cast(s32)HostReal, .type_name = HostTextData("float32"), .real = cast(float64)data.y}}
|
||||
return value
|
||||
}
|
||||
|
||||
WidgetDecodeVector2 :: (value: HostValue, codec: *WidgetVector2Codec) -> Vector2 {
|
||||
data: Vector2
|
||||
unused codec
|
||||
zero: HostValue
|
||||
data.x = cast(float32)HostFieldValue(*value, 0, "x", *zero).real
|
||||
data.y = cast(float32)HostFieldValue(*value, 1, "y", *zero).real
|
||||
return data
|
||||
}
|
||||
|
||||
WidgetValidVector2 :: (value: HostValue) -> bool {
|
||||
if !HostRecordValid(*value, "Vector2") { return false }
|
||||
if !HostFieldScalarValid(*value, 0, "x", "float32", cast(s32)HostReal) { return false }
|
||||
if !HostFieldScalarValid(*value, 1, "y", "float32", cast(s32)HostReal) { return false }
|
||||
if !HostFieldScalarValid(*value, 21, "rotation", "float32", cast(s32)HostReal) { return false }
|
||||
if !HostFieldRecordValid(*value, 22, "origin", WidgetValidVector2) { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -64,3 +64,18 @@ RectangleIntersection :: (a: Rectangle, b: Rectangle) -> Rectangle {
|
||||
if result.height < 0.0 { result.height = 0.0 }
|
||||
return result
|
||||
}
|
||||
|
||||
// Axis-aligned coverage of a rectangle rotated clockwise about a world point.
|
||||
RotatedRectangleBounds :: (bounds: Rectangle, origin: Vector2, rotation: float32) -> Rectangle {
|
||||
camera: Camera = .{.offset = origin, .target = origin, .rotation = rotation, .zoom = 1.0}
|
||||
points: [4]Vector2 = .[.{bounds.x,bounds.y},.{bounds.x+bounds.width,bounds.y},
|
||||
.{bounds.x+bounds.width,bounds.y+bounds.height},.{bounds.x,bounds.y+bounds.height}]
|
||||
first := WorldToScreen(points[0], camera)
|
||||
left := first.x; right := first.x; top := first.y; bottom := first.y
|
||||
for point: points {
|
||||
at := WorldToScreen(point, camera)
|
||||
if at.x < left { left = at.x }; if at.x > right { right = at.x }
|
||||
if at.y < top { top = at.y }; if at.y > bottom { bottom = at.y }
|
||||
}
|
||||
return .{left,top,right-left,bottom-top}
|
||||
}
|
||||
+37
-5
@@ -52,6 +52,8 @@ PaintCommand :: struct {
|
||||
clip_set: bool
|
||||
origin: Vector2
|
||||
rotation: float32
|
||||
text_outer_clip: Rectangle
|
||||
text_outer_clipped: bool
|
||||
// Queued text is copied into the session's frame text so a caller may
|
||||
// pass a label formatted into its own short-lived buffer.
|
||||
text_start: s64
|
||||
@@ -585,7 +587,11 @@ EmitRoundedOutline :: (command: PaintCommand) {
|
||||
EmitLabel :: (command: PaintCommand) {
|
||||
previous := TextTypefaceUse(command.asset_path)
|
||||
defer { unused TextTypefaceUse(previous) }
|
||||
if command.italic {
|
||||
if command.rotation != 0.0 {
|
||||
PaintTextRotated(command.value,command.x,command.y,command.font,command.color,
|
||||
command.clip,command.origin,command.rotation,command.text_outer_clip,
|
||||
command.text_outer_clipped,command.emphasis,command.italic)
|
||||
} else if command.italic {
|
||||
PaintTextItalicClipped(command.value, command.x, command.y,
|
||||
command.font, command.color, command.clip, command.emphasis)
|
||||
} else if command.emphasis {
|
||||
@@ -622,6 +628,11 @@ EmitImage :: (command: PaintCommand) {
|
||||
}
|
||||
|
||||
ClipLabel :: (command: PaintCommand, geometry: NodeGeometry) -> PaintCommand {
|
||||
if command.rotation != 0.0 {
|
||||
command.text_outer_clip = geometry.clip
|
||||
command.text_outer_clipped = true
|
||||
return command
|
||||
}
|
||||
if command.kind == PaintKindText {
|
||||
command.kind = PaintKindClippedText
|
||||
command.clip = geometry.clip
|
||||
@@ -695,6 +706,9 @@ QueuePaint :: (session: Session, command: *QueuedPaint) {
|
||||
command.data.bounds.y += dy
|
||||
command.data.clip.x += dx
|
||||
command.data.clip.y += dy
|
||||
if command.data.rotation != 0.0 && (command.data.kind == PaintKindText || command.data.kind == PaintKindClippedText) {
|
||||
command.data.origin.x += dx; command.data.origin.y += dy
|
||||
}
|
||||
command.data.x += cast(s32)dx
|
||||
command.data.y += cast(s32)dy
|
||||
if full_bounds {
|
||||
@@ -833,7 +847,8 @@ PaintLabel :: (session: Session, node: s32, value: string, x: s32, y: s32,
|
||||
|
||||
#program_export
|
||||
PaintClippedLabel :: (session: Session, node: s32, value: string, x: s32, y: s32,
|
||||
font: s32, color: Color, clip: Rectangle, typeface: string = "") {
|
||||
font: s32, color: Color, clip: Rectangle, typeface: string = "",
|
||||
rotation: float32 = 0.0, origin: Vector2 = Vector2.{}) {
|
||||
command: QueuedPaint
|
||||
command.data.kind = PaintKindClippedText
|
||||
command.data.node = node
|
||||
@@ -843,6 +858,8 @@ PaintClippedLabel :: (session: Session, node: s32, value: string, x: s32, y: s32
|
||||
command.data.y = y
|
||||
command.data.font = font
|
||||
command.data.color = color
|
||||
command.data.rotation = rotation
|
||||
command.data.origin = origin
|
||||
command.data.clip = clip
|
||||
emit: PaintEmitter = EmitLabel
|
||||
clip_for: PaintClipper = ClipLabel
|
||||
@@ -857,7 +874,8 @@ PaintClippedLabel :: (session: Session, node: s32, value: string, x: s32, y: s32
|
||||
// The extra stroke of emphasized text, at the position of its painted label.
|
||||
#program_export
|
||||
PaintClippedEmphasis :: (session: Session, node: s32, value: string, x: s32, y: s32,
|
||||
font: s32, color: Color, clip: Rectangle, typeface: string = "") {
|
||||
font: s32, color: Color, clip: Rectangle, typeface: string = "",
|
||||
rotation: float32 = 0.0, origin: Vector2 = Vector2.{}) {
|
||||
command: QueuedPaint
|
||||
command.data.kind = PaintKindClippedText
|
||||
command.data.node = node
|
||||
@@ -867,6 +885,8 @@ PaintClippedEmphasis :: (session: Session, node: s32, value: string, x: s32, y:
|
||||
command.data.y = y
|
||||
command.data.font = font
|
||||
command.data.color = color
|
||||
command.data.rotation = rotation
|
||||
command.data.origin = origin
|
||||
command.data.clip = clip
|
||||
command.data.emphasis = true
|
||||
emit: PaintEmitter = EmitLabel
|
||||
@@ -883,7 +903,8 @@ PaintClippedEmphasis :: (session: Session, node: s32, value: string, x: s32, y:
|
||||
// text, at the position of its painted label.
|
||||
#program_export
|
||||
PaintClippedSlanted :: (session: Session, node: s32, value: string, x: s32, y: s32,
|
||||
font: s32, color: Color, clip: Rectangle, emphasis: bool, typeface: string = "") {
|
||||
font: s32, color: Color, clip: Rectangle, emphasis: bool, typeface: string = "",
|
||||
rotation: float32 = 0.0, origin: Vector2 = Vector2.{}) {
|
||||
command: QueuedPaint
|
||||
command.data.kind = PaintKindClippedText
|
||||
command.data.node = node
|
||||
@@ -893,6 +914,8 @@ PaintClippedSlanted :: (session: Session, node: s32, value: string, x: s32, y: s
|
||||
command.data.y = y
|
||||
command.data.font = font
|
||||
command.data.color = color
|
||||
command.data.rotation = rotation
|
||||
command.data.origin = origin
|
||||
command.data.clip = clip
|
||||
command.data.emphasis = emphasis
|
||||
command.data.italic = true
|
||||
@@ -1182,6 +1205,11 @@ PaintCommandEqual :: (slot: s32, current: PaintCommand,
|
||||
if current.origin.x != previous.data.origin.x ||
|
||||
current.origin.y != previous.data.origin.y ||
|
||||
current.rotation != previous.data.rotation { return false }
|
||||
if current.text_outer_clipped != previous.data.text_outer_clipped ||
|
||||
current.text_outer_clip.x != previous.data.text_outer_clip.x ||
|
||||
current.text_outer_clip.y != previous.data.text_outer_clip.y ||
|
||||
current.text_outer_clip.width != previous.data.text_outer_clip.width ||
|
||||
current.text_outer_clip.height != previous.data.text_outer_clip.height { return false }
|
||||
if current.smooth != previous.data.smooth { return false }
|
||||
if current.image_clip_count != previous.data.image_clip_count || current.mesh_columns != previous.data.mesh_columns ||
|
||||
current.mesh_rows != previous.data.mesh_rows { return false }
|
||||
@@ -1375,7 +1403,11 @@ PaintCommandArea :: (command: PaintCommand, area: *Rectangle) -> bool {
|
||||
// These draw only inside their clip.
|
||||
area.* = Rectangle.{command.clip.x - margin, command.clip.y - margin,
|
||||
command.clip.width + margin * 2.0, command.clip.height + margin * 2.0}
|
||||
return command.clip.width > 0.0 && command.clip.height > 0.0
|
||||
if kind == PaintKindClippedText && command.rotation != 0.0 {
|
||||
area.* = RotatedRectangleBounds(area.*, command.origin, command.rotation)
|
||||
if command.text_outer_clipped { area.* = RectangleIntersection(area.*, command.text_outer_clip) }
|
||||
}
|
||||
return area.width > 0.0 && area.height > 0.0
|
||||
}
|
||||
if kind == PaintKindText {
|
||||
lines: s32 = 1
|
||||
|
||||
@@ -49,3 +49,14 @@ PaintTextItalicClipped :: (value: string, x: s32, y: s32, font: s32,
|
||||
}
|
||||
RasterTextClipped(value, x, y, font, color, clip)
|
||||
}
|
||||
|
||||
// Local text clipping rotates with the glyphs; ancestor clipping stays fixed.
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32,
|
||||
color: Color, clip: Rectangle, origin: Vector2, rotation: float32,
|
||||
outer_clip: Rectangle, outer_clipped: bool, emphasis: bool, italic: bool) #foreign host_api;
|
||||
PaintTextRotated :: (value: string, x: s32, y: s32, font: s32,
|
||||
color: Color, clip: Rectangle, origin: Vector2, rotation: float32,
|
||||
outer_clip: Rectangle, outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
if clip.width <= 0.0 || clip.height <= 0.0 { return }
|
||||
RasterTextRotated(value,x,y,font,color,clip,origin,rotation,outer_clip,outer_clipped,emphasis,italic)
|
||||
}
|
||||
@@ -62,6 +62,9 @@ TextProps :: struct {
|
||||
typeface: string
|
||||
// Extra units between lines; zero keeps the default gap.
|
||||
line_gap: s32
|
||||
// Clockwise degrees, around bounds top-left plus origin (logical units).
|
||||
rotation: float32
|
||||
origin: Vector2
|
||||
}
|
||||
|
||||
PreparedText :: struct {
|
||||
|
||||
+37
-9
@@ -20,6 +20,8 @@ Theme :: #import "theme";
|
||||
#import "drawing_props"
|
||||
#import "font_metrics"
|
||||
#import "geometry"
|
||||
#import "math"
|
||||
#import "shape_paint"
|
||||
#import "paint_queue"
|
||||
#import "text_layout"
|
||||
#import "semantic"
|
||||
@@ -101,7 +103,7 @@ Theme :: #import "theme";
|
||||
left := x + GlyphWidth(props.text[line.start:at], prepared.font, prepared.typeface)
|
||||
color := ifx run.link then TextLinkColor(prepared.color) else prepared.color
|
||||
PaintClippedEmphasis(session, node, props.text[at:run.end], left, y,
|
||||
prepared.font, color, clip, prepared.typeface)
|
||||
prepared.font, color, clip, prepared.typeface, props.rotation, TextOrigin(props, prepared))
|
||||
at = run.end
|
||||
}
|
||||
}
|
||||
@@ -160,16 +162,16 @@ Theme :: #import "theme";
|
||||
left := x + GlyphWidth(props.text[line_start:at], prepared.font, prepared.typeface)
|
||||
if !run.link {
|
||||
PaintClippedLabel(session, node, props.text[at:run.end], left, y, prepared.font,
|
||||
prepared.color, clip, prepared.typeface)
|
||||
prepared.color, clip, prepared.typeface, props.rotation, TextOrigin(props, prepared))
|
||||
} else {
|
||||
color := TextLinkColor(prepared.color)
|
||||
PaintClippedLabel(session, node, props.text[at:run.end], left, y, prepared.font,
|
||||
color, clip, prepared.typeface)
|
||||
color, clip, prepared.typeface, props.rotation, TextOrigin(props, prepared))
|
||||
width := GlyphWidth(props.text[at:run.end], prepared.font, prepared.typeface)
|
||||
underline := RectangleIntersection(Rectangle.{cast(float32)left,
|
||||
cast(float32)(y + prepared.line_height - 1), cast(float32)width, 1.0}, clip)
|
||||
if underline.width > 0.0 && underline.height > 0.0 {
|
||||
PaintRoundedFill(session, node, underline, 0.0, 1, color)
|
||||
PaintTextRule(session,node,props,prepared,underline,color)
|
||||
}
|
||||
}
|
||||
at = run.end
|
||||
@@ -324,7 +326,7 @@ Theme :: #import "theme";
|
||||
if ellipsis {
|
||||
PaintClippedLabel(session, node, "...",
|
||||
x + line.width - dots_width, y, prepared.font,
|
||||
prepared.color, clip, prepared.typeface)
|
||||
prepared.color, clip, prepared.typeface, props.rotation, TextOrigin(props, prepared))
|
||||
}
|
||||
PaintTextEmphasis(session, node, props, prepared, line, x, y, clip)
|
||||
if props.strikethrough {
|
||||
@@ -333,7 +335,7 @@ Theme :: #import "theme";
|
||||
cast(float32)prepared.line_height, 1.0)
|
||||
strike = RectangleIntersection(strike, prepared.bounds)
|
||||
if strike.width > 0.0 && strike.height > 0.0 {
|
||||
PaintRoundedFill(session, node, strike, 0.0, 1, prepared.color)
|
||||
PaintTextRule(session,node,props,prepared,strike,prepared.color)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -342,6 +344,24 @@ Theme :: #import "theme";
|
||||
}
|
||||
}
|
||||
|
||||
PaintTextRule :: (session: Session, node: s32, props: TextProps, prepared: PreparedText,
|
||||
bounds: Rectangle, color: Color) {
|
||||
if props.rotation == 0.0 { PaintRoundedFill(session,node,bounds,0.0,1,color); return }
|
||||
origin := TextOrigin(props,prepared)
|
||||
camera: Camera = .{.offset=origin,.target=origin,.rotation=props.rotation,.zoom=1.0}
|
||||
a := WorldToScreen(Vector2.{bounds.x,bounds.y},camera)
|
||||
b := WorldToScreen(Vector2.{bounds.x+bounds.width,bounds.y},camera)
|
||||
c := WorldToScreen(Vector2.{bounds.x+bounds.width,bounds.y+bounds.height},camera)
|
||||
d := WorldToScreen(Vector2.{bounds.x,bounds.y+bounds.height},camera)
|
||||
area := RotatedRectangleBounds(bounds,origin,props.rotation)
|
||||
PaintTriangleShape(session,node,area,a,b,c,color)
|
||||
PaintTriangleShape(session,node,area,a,c,d,color)
|
||||
}
|
||||
|
||||
TextOrigin :: (props: TextProps, prepared: PreparedText) -> Vector2 {
|
||||
return .{prepared.bounds.x + props.origin.x, prepared.bounds.y + props.origin.y}
|
||||
}
|
||||
|
||||
// The face Text paints props with.
|
||||
TextFaceOf :: (props: TextProps) -> TextFace {
|
||||
defaults: TextFace = DefaultTextFace()
|
||||
@@ -354,11 +374,13 @@ Theme :: #import "theme";
|
||||
|
||||
#program_export
|
||||
Text :: (session: Session, props: TextProps) {
|
||||
if !Finite32(props.rotation) || !Finite32(props.origin.x) || !Finite32(props.origin.y) { return }
|
||||
face: TextFace = TextFaceOf(props)
|
||||
prepared: PreparedText = PrepareText(props, face)
|
||||
node: s32 = -1
|
||||
if TreeIsBuilding(session) {
|
||||
node = TreeSubmitCurrent(session, props.key, WidgetKindText, prepared.bounds)
|
||||
node = TreeSubmitCurrent(session, props.key, WidgetKindText,
|
||||
RotatedRectangleBounds(prepared.bounds, TextOrigin(props, prepared), props.rotation))
|
||||
if node < 0 { return }
|
||||
TreeSetLabel(session, node, props.text)
|
||||
TreeSetStyleClass(session, node, props.class_name)
|
||||
@@ -383,6 +405,9 @@ Theme :: #import "theme";
|
||||
return -1
|
||||
}
|
||||
prepared := PrepareText(props, TextFaceOf(props))
|
||||
origin := TextOrigin(props, prepared)
|
||||
point := ScreenToWorld(Vector2.{x,y}, Camera.{.offset=origin,.target=origin,.rotation=props.rotation,.zoom=1.0})
|
||||
x = point.x; y = point.y
|
||||
top := TextFirstLineY(props, prepared)
|
||||
start: s32 = 0
|
||||
while start <= cast(s32)props.text.count {
|
||||
@@ -427,6 +452,9 @@ Theme :: #import "theme";
|
||||
}
|
||||
|
||||
TextByteAtPoint :: (props: TextProps, prepared: PreparedText, x: float32, y: float32) -> s32 {
|
||||
origin := TextOrigin(props,prepared)
|
||||
point := ScreenToWorld(Vector2.{x,y},Camera.{.offset=origin,.target=origin,.rotation=props.rotation,.zoom=1.0})
|
||||
x = point.x; y = point.y
|
||||
top := TextFirstLineY(props, prepared)
|
||||
start: s32 = 0
|
||||
while start <= props.text.count {
|
||||
@@ -488,9 +516,9 @@ Theme :: #import "theme";
|
||||
line.width, cast(s32)props.align)
|
||||
before := GlyphWidth(props.text[line.start:from], prepared.font, prepared.typeface)
|
||||
after := GlyphWidth(props.text[line.start:to], prepared.font, prepared.typeface)
|
||||
PaintRoundedFill(session, node, RectangleIntersection(prepared.bounds,
|
||||
PaintTextRule(session,node,props,prepared,RectangleIntersection(prepared.bounds,
|
||||
Rectangle.{cast(float32)(left + before), cast(float32)top,
|
||||
cast(float32)(after - before), cast(float32)prepared.line_height}), 0.0, 1, color)
|
||||
cast(float32)(after - before), cast(float32)prepared.line_height}),color)
|
||||
}
|
||||
start = line.next
|
||||
top += prepared.line_height + prepared.line_gap
|
||||
|
||||
@@ -14,6 +14,7 @@ set -- --bind raster:RasterLine=pixmap:RasterLine \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=pixmap:RasterRoundedRectangleOutline \
|
||||
--bind raster_text:RasterText=pixmap:RasterText \
|
||||
--bind raster_text:RasterTextClipped=pixmap:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=pixmap:RasterTextRotated \
|
||||
--bind raster_triangles:RasterTriangles=pixmap:RasterTriangles
|
||||
"$ziran" ir --project --root "$repo/tests" --module-path "$repo/tests" -o "$work/ir" "$source"
|
||||
for target in c go; do
|
||||
|
||||
@@ -41,6 +41,7 @@ BINDINGS = ['raster:RasterLine=pixmap:RasterLine',
|
||||
'raster_shape:RasterRoundedRectangleOutline=pixmap:RasterRoundedRectangleOutline',
|
||||
'raster_text:RasterText=pixmap:RasterText',
|
||||
'raster_text:RasterTextClipped=pixmap:RasterTextClipped',
|
||||
'raster_text:RasterTextRotated=pixmap:RasterTextRotated',
|
||||
'raster_triangles:RasterTriangles=pixmap:RasterTriangles']
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
Raster :: #import "cairo_raster";
|
||||
Texture :: #import "paint_texture";
|
||||
#import "geometry"
|
||||
#import "drawing_props"
|
||||
#import "std/byte_text_linux"
|
||||
#import "std/format"
|
||||
#import "std/vec"
|
||||
|
||||
reference: [65536]u8;
|
||||
Draw :: (path: string, bounds: Rectangle, tint: Color, cached: bool) -> bool {
|
||||
Raster.BeginRasterFrame()
|
||||
Texture.emitting_smooth = true
|
||||
origin: Vector2
|
||||
if !cached { bounds.x += 1.0; origin.x = 1.0 }
|
||||
Raster.RasterImage(path, 0, .{0.0,0.0,512.0,512.0}, bounds,
|
||||
.{7.0,9.0,113.0,103.0}, origin, 0.0, 0.0, tint)
|
||||
return Raster.FinishRasterFrame()
|
||||
}
|
||||
main :: (argc: s32, argv: **u8) -> s32 {
|
||||
if argc != 2 { return 1 }
|
||||
text: Vec(u8); BuilderPrint(*text,"%/scaled.png",TextFromCString(argv[1])); path := BuilderFinish(text)
|
||||
if !Raster.OpenRaster(128,128) { return 2 }
|
||||
defer Raster.CloseRaster()
|
||||
tints: [3]Color = .[.{255,255,255,255},.{255,255,255,128},.{40,160,70,200}]
|
||||
for phase: 0..3 { for tint: tints {
|
||||
bounds: Rectangle = .{-15.0 + cast(float32)phase * 0.25, 3.0 + cast(float32)phase * 0.25, 149.25, 117.5}
|
||||
if !Draw(path,bounds,tint,false) { return 3 }
|
||||
data := Raster.RasterSurfaceData()
|
||||
for i: 0..65535 { reference[i] = data[i] }
|
||||
for repeat: 0..1 {
|
||||
if !Draw(path,bounds,tint,true) { return 4 }
|
||||
data = Raster.RasterSurfaceData()
|
||||
for i: 0..65535 {
|
||||
delta := cast(s32)data[i] - cast(s32)reference[i]
|
||||
if delta < -2 || delta > 2 { print("cached sample differs at %: % vs %\n",i,data[i],reference[i]); return 5 }
|
||||
}
|
||||
}
|
||||
} }
|
||||
Raster.CloseRaster()
|
||||
if !Raster.OpenRaster(128,128) || !Draw(path,.{0.0,0.0,100.0,100.0},.{255,255,255,255},true) { return 6 }
|
||||
print("Cairo cached scaling matches direct filtering, fractional translation, clips, alpha, tint and reopen\n")
|
||||
return 0
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
using UI :: #import "kryon/Widgets";
|
||||
#import "std/web"
|
||||
#import "kryon/paint_queue"
|
||||
frames: s32;
|
||||
#program_export
|
||||
Frame :: (session: Session, viewport: Rectangle) -> s32 {
|
||||
unused viewport
|
||||
frames += 1
|
||||
WebSet(WebGlobal,WebName("__fixtureFrames"),WebNumber(cast(float64)frames))
|
||||
Text(session,TextProps.{.key=cast(u64)10,.bounds=.{100.0,100.0,180.0,40.0},
|
||||
.text="Rotated",.font=32,.rotation=27.5,.origin=.{90.0,20.0},.wrap=.TextWrapNone})
|
||||
Text(session,TextProps.{.key=cast(u64)11,.bounds=.{100.0,260.0,180.0,40.0},
|
||||
.text="Horizontal",.font=32,.wrap=.TextWrapNone})
|
||||
WebSet(WebGlobal,WebName("__fixturePaint"),WebNumber(cast(float64)PendingPaintCount(session)))
|
||||
return 0
|
||||
}
|
||||
@@ -40,3 +40,14 @@ RasterImageMesh :: (path: string, texture_id: u32, source: Rectangle,
|
||||
|
||||
#program_export
|
||||
HostValid :: () -> bool { return !failed && fills == 7 }
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused value; unused x; unused y; unused font; unused color; unused clip; unused origin
|
||||
unused rotation; unused outer_clip; unused outer_clipped; unused emphasis; unused italic
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTriangles :: (points: []Vector2, color: Color) { unused points; unused color }
|
||||
@@ -12,6 +12,7 @@ set -- --bind raster:RasterLine=pixmap:RasterLine \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=pixmap:RasterRoundedRectangleOutline \
|
||||
--bind raster_text:RasterText=pixmap:RasterText \
|
||||
--bind raster_text:RasterTextClipped=pixmap:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=pixmap:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=pixmap:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=pixmap:RasterImageMesh
|
||||
"$ziran" ir --project --root "$repo/tests" -o "$work/ir" "$source"
|
||||
|
||||
@@ -15,6 +15,7 @@ set -- --bind raster:RasterLine=pixmap:RasterLine \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=pixmap:RasterRoundedRectangleOutline \
|
||||
--bind raster_text:RasterText=pixmap:RasterText \
|
||||
--bind raster_text:RasterTextClipped=pixmap:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=pixmap:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=pixmap:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=pixmap:RasterImageMesh \
|
||||
--bind image_raster:ImageWidth=pixmap:ImageWidth \
|
||||
|
||||
@@ -216,3 +216,12 @@ rlVertex2f :: (x: float32, y: float32) {
|
||||
unused x
|
||||
unused y
|
||||
}
|
||||
|
||||
#program_export
|
||||
GetFontDefault :: () -> RaylibFont { selection_effects += 1; return RaylibFont.{} }
|
||||
#program_export
|
||||
DrawTexturePro :: (texture: Texture2D, source: Rectangle, destination: Rectangle,
|
||||
origin: Vector2, rotation: float32, color: Color) {
|
||||
selection_effects += 1
|
||||
unused texture; unused source; unused destination; unused origin; unused rotation; unused color
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify real Canvas transforms and DOM text styles in private headless Chromium.
|
||||
|
||||
Uses only its DevTools pipe and never captures pixels.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
import select
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
html, profile = sys.argv[1], Path(sys.argv[2])
|
||||
backend = sys.argv[3]
|
||||
shutil.rmtree(profile, ignore_errors=True)
|
||||
profile.mkdir(parents=True)
|
||||
environment = dict(os.environ)
|
||||
for name in ("DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "GDK_DISPLAY", "DBUS_SESSION_BUS_ADDRESS",
|
||||
"SESSION_MANAGER"):
|
||||
environment.pop(name, None)
|
||||
environment["YUE_DESKTOP_RECOVERY"] = "0"
|
||||
browser = subprocess.Popen(
|
||||
["sh", "-c", 'exec 3<&0 4>&1 "$@" </dev/null >/dev/null', "chromium",
|
||||
os.environ.get("CHROMIUM", "chromium"), "--headless", "--no-sandbox", "--disable-gpu",
|
||||
"--disable-webgl", "--use-gl=disabled",
|
||||
"--disable-dev-shm-usage", "--no-first-run", "--no-default-browser-check",
|
||||
"--remote-debugging-pipe", "--user-data-dir=" + str(profile), "about:blank"],
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=(profile / "chromium.log").open("wb"), env=environment)
|
||||
diagnostics = []
|
||||
received = b""
|
||||
sequence = 0
|
||||
session = None
|
||||
|
||||
|
||||
def command(method, **params):
|
||||
global received, sequence
|
||||
sequence += 1
|
||||
message = {"id": sequence, "method": method, "params": params}
|
||||
if session:
|
||||
message["sessionId"] = session
|
||||
browser.stdin.write(json.dumps(message).encode() + b"\0")
|
||||
browser.stdin.flush()
|
||||
deadline = time.monotonic() + 30
|
||||
while time.monotonic() < deadline:
|
||||
while b"\0" in received:
|
||||
raw, received = received.split(b"\0", 1)
|
||||
if not raw:
|
||||
continue
|
||||
reply = json.loads(raw)
|
||||
if reply.get('method')=='Runtime.consoleAPICalled' and reply['params'].get('type')=='error':
|
||||
diagnostics.append([arg.get('value',arg.get('description','')) for arg in reply['params']['args']])
|
||||
if reply.get("method") == "Runtime.exceptionThrown":
|
||||
detail = reply["params"].get("exceptionDetails", {})
|
||||
diagnostics.append((detail.get("exception") or {}).get("description") or detail.get("text"))
|
||||
if reply.get("id") == sequence:
|
||||
if "error" in reply:
|
||||
raise RuntimeError(method + ": " + json.dumps(reply["error"]))
|
||||
return reply.get("result", {})
|
||||
if select.select([browser.stdout], [], [], 0.5)[0]:
|
||||
data = os.read(browser.stdout.fileno(), 1 << 20)
|
||||
if not data:
|
||||
raise RuntimeError("Private Chromium exited with code " + str(browser.poll()) + "; see " + str(profile / "chromium.log"))
|
||||
received += data
|
||||
raise TimeoutError(method)
|
||||
|
||||
|
||||
def evaluate(expression):
|
||||
result = command("Runtime.evaluate", expression=expression, returnByValue=True)
|
||||
if "exceptionDetails" in result:
|
||||
raise RuntimeError(json.dumps(result["exceptionDetails"])[:2000])
|
||||
return result.get("result", {}).get("value")
|
||||
|
||||
|
||||
try:
|
||||
target = next(item["targetId"] for item in command("Target.getTargets")["targetInfos"] if item["type"] == "page")
|
||||
session = command("Target.attachToTarget", targetId=target, flatten=True)["sessionId"]
|
||||
command("Runtime.enable")
|
||||
command("Page.enable")
|
||||
command("Emulation.setDeviceMetricsOverride", width=640, height=480, deviceScaleFactor=1, mobile=False)
|
||||
command("Page.addScriptToEvaluateOnNewDocument", source=r"""
|
||||
globalThis.__rotatedCalls=[];
|
||||
for (const Type of [globalThis.CanvasRenderingContext2D,globalThis.OffscreenCanvasRenderingContext2D]) {
|
||||
if (!Type) continue;
|
||||
const draw=Type.prototype.fillText;
|
||||
Type.prototype.fillText=function(text,...args) {
|
||||
if ((text==='Rotated' || text==='Horizontal') && __rotatedCalls.length<32) {
|
||||
const m=this.getTransform();
|
||||
__rotatedCalls.push({text,a:m.a,b:m.b,c:m.c,d:m.d,e:m.e,f:m.f,font:this.font});
|
||||
}
|
||||
return draw.call(this,text,...args);
|
||||
};
|
||||
}
|
||||
new MutationObserver(()=> {
|
||||
const root=document.getElementById('kryon-dom-paint');
|
||||
if(root) globalThis.__rotationDom=[...root.querySelectorAll('span')].filter(n=>n.textContent==='Rotated')
|
||||
.map(n=>({transform:n.style.transform,origin:n.style.transformOrigin,font:n.style.font,
|
||||
clip:n.style.clipPath,outer:n.parentElement.style.overflow}));
|
||||
}).observe(document,{childList:true,subtree:true,attributes:true});
|
||||
""")
|
||||
command("Page.navigate",url=html)
|
||||
command('Page.bringToFront')
|
||||
deadline=time.monotonic()+30
|
||||
while time.monotonic()<deadline:
|
||||
value=evaluate("({calls:globalThis.__rotatedCalls||[],dom:globalThis.__rotationDom||[]})")
|
||||
if (backend=='dom' and value['dom']) or (backend=='canvas' and
|
||||
all(any(c['text']==label for c in value['calls']) for label in ('Rotated','Horizontal'))):
|
||||
break
|
||||
time.sleep(.05)
|
||||
assert not diagnostics,diagnostics
|
||||
assert value['dom'] if backend=='dom' else value['calls'],(value,evaluate('({body:document.body.innerText.slice(0,1200),frames:globalThis.__fixtureFrames,paint:globalThis.__fixturePaint,visibility:document.visibilityState,ready:document.readyState,module:typeof Module,called:typeof Module!=="undefined"?Module.calledRun:null,main:typeof Module!=="undefined"?typeof Module._main:null,canvases:[...document.querySelectorAll("canvas")].map(n=>[n.width,n.height])})'))
|
||||
if backend=='dom':
|
||||
item=value['dom'][0]
|
||||
assert item['transform']=='rotate(27.5deg)',item
|
||||
assert item['origin']=='90px 20px',item
|
||||
assert item['clip'].startswith('polygon(') and item['outer']=='hidden',item
|
||||
assert float(re.search(r'([0-9.]+)px',item['font']).group(1))>=24,item
|
||||
else:
|
||||
import math
|
||||
rotated=next(c for c in value['calls'] if c['text']=='Rotated')
|
||||
flat=next(c for c in value['calls'] if c['text']=='Horizontal')
|
||||
assert rotated['font']==flat['font'] and float(re.search(r'([0-9.]+)px',rotated['font']).group(1))>=24,(rotated,flat)
|
||||
c=math.cos(math.radians(27.5));s=math.sin(math.radians(27.5))
|
||||
for actual,expected in [(rotated['a'],c),(rotated['b'],s),(rotated['c'],-s),(rotated['d'],c),
|
||||
(rotated['e'],190-c*190+s*120),(rotated['f'],120-s*190-c*120),
|
||||
(flat['a'],1),(flat['b'],0),(flat['c'],0),(flat['d'],1)]:
|
||||
assert abs(actual-expected)<.02,(rotated,flat,actual,expected)
|
||||
assert not diagnostics,diagnostics
|
||||
print(backend+': real renderer arbitrary angle, centre pivot, full font size and transform restoration PASS')
|
||||
finally:
|
||||
try:
|
||||
command('Browser.close')
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
browser.wait(timeout=10)
|
||||
except subprocess.TimeoutExpired:
|
||||
browser.terminate();browser.wait(timeout=10)
|
||||
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
. "$repo/tests/toolchain.sh"
|
||||
output=$repo/build/scratch/rotated-text/cairo
|
||||
mkdir -p "$output"
|
||||
"$ziran" build --target=c --root "$repo/tests" --module-path "$repo/src/ui" \
|
||||
--module-path "$repo/src/backend" --module-path "$ziran_root/std" \
|
||||
-o "$output" "$repo/tests/rotated_text_cairo_test.zi"
|
||||
"${CC:-cc}" -std=c11 -O2 -ffunction-sections -fdata-sections -Wl,--gc-sections \
|
||||
-I"$output" "$output"/*.c $(pkg-config --libs pangocairo fontconfig freetype2) -lm -o "$output/test"
|
||||
"$output/test"
|
||||
echo 'Cairo rotated text: offscreen arbitrary angle, pivot and font size PASS'
|
||||
@@ -0,0 +1,29 @@
|
||||
#import "cairo_raster"
|
||||
#import "geometry"
|
||||
#import "drawing_props"
|
||||
|
||||
Coverage :: (angle: float32) -> Rectangle {
|
||||
BeginRasterFrame()
|
||||
RasterTextRotated("Diagonal",60,100,32,Color.{0,0,0,255},Rectangle.{60.0,100.0,140.0,32.0},
|
||||
Vector2.{130.0,116.0},angle,Rectangle.{},false,false,false)
|
||||
if !FinishRasterFrame() { return Rectangle.{} }
|
||||
pixels := RasterSurfaceData(); stride := RasterSurfaceStride()
|
||||
left: s32=256;right: s32;top: s32=256;bottom: s32;count: s32
|
||||
for y: 0..255 { for x: 0..255 {
|
||||
if pixels[y*stride+x*4] < cast(u8)128 {
|
||||
count+=1
|
||||
if x<left { left=cast(s32)x };if x>right { right=cast(s32)x }
|
||||
if y<top { top=cast(s32)y };if y>bottom { bottom=cast(s32)y }
|
||||
}
|
||||
} }
|
||||
if count<100 { return Rectangle.{} }
|
||||
return .{cast(float32)left,cast(float32)top,cast(float32)(right-left+1),cast(float32)(bottom-top+1)}
|
||||
}
|
||||
#program_export
|
||||
main :: () -> s32 {
|
||||
if !OpenRaster(256,256) { return 1 }
|
||||
defer CloseRaster()
|
||||
horizontal:=Coverage(0.0);vertical:=Coverage(90.0);angled:=Coverage(-27.0)
|
||||
if horizontal.width<80.0 || horizontal.height>32.0 || vertical.height<80.0 || vertical.width>32.0 || angled.height<45.0 { return 2 }
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
. "$repo/tests/toolchain.sh"
|
||||
work=$repo/build/scratch/rotated-text/raylib
|
||||
mkdir -p "$work"
|
||||
archive=${RAYLIB_A:-$repo/build/raylib-ziran/libraylib.a}
|
||||
libs=${RAYLIB_LIBS:-$(pkg-config --libs sdl2 libdrm gbm egl glesv2) -ldl -lpthread -lm}
|
||||
for profile in native android-replay; do
|
||||
set --
|
||||
if [ "$profile" = android-replay ]; then set -- --define KRYON_FRAME_THREADS; fi
|
||||
output=$work/$profile
|
||||
"$ziran" build --target=c "$@" --root "$repo/tests" --module-path "$repo/src/ui" \
|
||||
--module-path "$repo/src/backend" --module-path "$ziran_root/std" \
|
||||
-o "$output" "$repo/tests/rotated_text_raylib_test.zi"
|
||||
"${CC:-cc}" -std=c11 -O2 -ffunction-sections -fdata-sections -Wl,--gc-sections \
|
||||
-I"$output" "$output"/*.c "$archive" "${WEBP_A:-$repo/build/webp-ziran/libkryonwebp.a}" $libs -o "$output/test"
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS \
|
||||
-u GDK_DISPLAY YUE_DESKTOP_RECOVERY=0 LIBGL_ALWAYS_SOFTWARE=1 \
|
||||
timeout --kill-after=2s 45s xvfb-run -a -n 300 -s '-screen 0 300x300x24' "$output/test"
|
||||
done
|
||||
echo 'Native and Android shared text/replay renderer: offscreen glyph rotation PASS'
|
||||
@@ -0,0 +1,78 @@
|
||||
#import "raylib_runtime"
|
||||
#import "raylib_image_decode"
|
||||
#import "geometry"
|
||||
#import "drawing_props"
|
||||
#import "c_string"
|
||||
|
||||
rotation_test_raylib :: #system_library "raylib";
|
||||
ReadTexture :: (texture: Texture2D) -> RaylibGlyphImage #foreign rotation_test_raylib "LoadImageFromTexture";
|
||||
|
||||
TestBeginTarget :: (target: HostRaylibRenderTexture) #foreign rotation_test_raylib "BeginTextureMode";
|
||||
TestEndTarget :: () #foreign rotation_test_raylib "EndTextureMode";
|
||||
TestClear :: (color: Color) #foreign rotation_test_raylib "ClearBackground";
|
||||
TestInit :: (width: s32, height: s32, title: *u8) #foreign rotation_test_raylib "InitWindow";
|
||||
TestReady :: () -> bool #foreign rotation_test_raylib "IsWindowReady";
|
||||
TestClose :: () #foreign rotation_test_raylib "CloseWindow";
|
||||
TestDefault :: () -> RaylibFont #foreign rotation_test_raylib "GetFontDefault";
|
||||
TestLoadTarget :: (width: s32, height: s32) -> HostRaylibRenderTexture #foreign rotation_test_raylib "LoadRenderTexture";
|
||||
TestTargetReady :: (target: HostRaylibRenderTexture) -> bool #foreign rotation_test_raylib "IsRenderTextureValid";
|
||||
TestFreeTarget :: (target: HostRaylibRenderTexture) #foreign rotation_test_raylib "UnloadRenderTexture";
|
||||
TestFreeImage :: (image: RaylibGlyphImage) #foreign rotation_test_raylib "UnloadImage";
|
||||
|
||||
#if #defined(KRYON_FRAME_THREADS) {
|
||||
#import "render_dispatch"
|
||||
test_pipeline: RenderPipeline;
|
||||
}
|
||||
DrawRotated :: (argument: *void) {
|
||||
angle := (cast(*float32)argument).*
|
||||
RasterTextRotated("Diagonal",60,100,32,Color.{255,255,255,255},
|
||||
Rectangle.{60.0,100.0,140.0,32.0},Vector2.{130.0,116.0},angle,Rectangle.{},false,false,false)
|
||||
}
|
||||
|
||||
// Read only our offscreen render texture; never capture a window or desktop.
|
||||
Coverage :: (target: HostRaylibRenderTexture, angle: float32) -> Rectangle {
|
||||
TestBeginTarget(target)
|
||||
TestClear(Color.{0,0,0,255})
|
||||
#if #defined(KRYON_FRAME_THREADS) {
|
||||
if !RenderPipelineStep(*test_pipeline, DrawRotated, cast(*void)*angle) ||
|
||||
!RenderPipelineFlush(*test_pipeline) { return Rectangle.{} }
|
||||
} else { DrawRotated(cast(*void)*angle) }
|
||||
TestEndTarget()
|
||||
image := ReadTexture(target.texture)
|
||||
defer TestFreeImage(image)
|
||||
pixels := cast(*u8)image.data
|
||||
left: s32=256; right: s32; top: s32=256; bottom: s32; count: s32
|
||||
for y: 0..255 { for x: 0..255 {
|
||||
at := (y*256+x)*4
|
||||
if pixels[at] > cast(u8)16 {
|
||||
count += 1
|
||||
if x<left { left=cast(s32)x }; if x>right { right=cast(s32)x }
|
||||
if y<top { top=cast(s32)y }; if y>bottom { bottom=cast(s32)y }
|
||||
}
|
||||
} }
|
||||
if count < 100 { return Rectangle.{} }
|
||||
return .{cast(float32)left,cast(float32)top,cast(float32)(right-left+1),cast(float32)(bottom-top+1)}
|
||||
}
|
||||
#program_export
|
||||
main :: () -> s32 {
|
||||
title: [32]u8
|
||||
unused CopyCString("Rotation test",title[:])
|
||||
TestInit(256,256,*title[0])
|
||||
if !TestReady() { return 1 }
|
||||
defer TestClose()
|
||||
raylib_font=TestDefault(); raylib_font_loaded=true
|
||||
#if #defined(KRYON_FRAME_THREADS) {
|
||||
if !RenderPipelineOpen(*test_pipeline) { return 5 }
|
||||
defer RenderPipelineClose(*test_pipeline)
|
||||
}
|
||||
target := TestLoadTarget(256,256)
|
||||
if !TestTargetReady(target) { return 2 }
|
||||
defer TestFreeTarget(target)
|
||||
horizontal := Coverage(target,0.0)
|
||||
vertical := Coverage(target,90.0)
|
||||
if horizontal.width < 80.0 || horizontal.height > 32.0 ||
|
||||
vertical.height < 80.0 || vertical.width > 32.0 { return 3 }
|
||||
angled := Coverage(target,-27.0)
|
||||
if angled.width < 70.0 || angled.height < 45.0 { return 4 }
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
. "$repo/tests/toolchain.sh"
|
||||
output=$repo/build/scratch/rotated-text/core
|
||||
mkdir -p "$output"
|
||||
"$ziran" build --target=c --root "$repo/tests" --module-path "$repo/src/ui" \
|
||||
--module-path "$repo/src/backend" --module-path "$ziran_root/std" \
|
||||
-o "$output" "$repo/tests/rotated_text_test.zi"
|
||||
"${CC:-cc}" -std=c11 -O2 -ffunction-sections -fdata-sections -Wl,--gc-sections \
|
||||
-I"$output" "$output"/*.c -lm -o "$output/test"
|
||||
"$output/test"
|
||||
echo 'Rotated text: real pixmap glyphs, arbitrary angles, pivot, font size and link hits PASS'
|
||||
|
||||
set -- --bind font_metrics:MeasureGlyphWidth=pixmap:MeasureGlyphWidth \
|
||||
--bind font_metrics:MeasureGlyphLineHeight=pixmap:MeasureGlyphLineHeight \
|
||||
--bind raster_triangles:RasterTriangles=pixmap:RasterTriangles \
|
||||
--bind raster:RasterLine=pixmap:RasterLine \
|
||||
--bind raster_shape:RasterRoundedRectangle=pixmap:RasterRoundedRectangle \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=pixmap:RasterRoundedRectangleOutline \
|
||||
--bind raster_text:RasterText=pixmap:RasterText \
|
||||
--bind raster_text:RasterTextClipped=pixmap:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=pixmap:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=pixmap:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=pixmap:RasterImageMesh
|
||||
"$ziran" bundle --root "$repo/tests" --module-path "$repo/src/ui" \
|
||||
--module-path "$repo/src/backend" --module-path "$ziran_root/std" "$@" \
|
||||
--entry rotated_text_test:main -o "$output/test.zx" "$repo/tests/rotated_text_test.zi"
|
||||
test "$("$ziran" run "$output/test.zx")" = 0
|
||||
echo 'Rotated text: portable ZX glyph rotation PASS'
|
||||
@@ -0,0 +1,85 @@
|
||||
#import "geometry"
|
||||
#import "drawing_props"
|
||||
#import "pixmap"
|
||||
#import "raster_text"
|
||||
#import "text_widget"
|
||||
#import "text_props"
|
||||
#import "text_measure"
|
||||
#import "session"
|
||||
#import "tree"
|
||||
#import "widget_kind"
|
||||
using WidgetKind;
|
||||
#import "tree_draw"
|
||||
#import "paint_queue"
|
||||
|
||||
pixels: [65536]u32;
|
||||
Clear :: () { unused PixmapBeginInto(cast(u32)0xffffff,256,256,pixels[:]) }
|
||||
|
||||
FrameText :: (session: Session, angle: float32) -> bool {
|
||||
BeginFrame(session,cast(u64)1,Rectangle.{0.0,0.0,256.0,256.0})
|
||||
props: TextProps = .{.key=cast(u64)2,.bounds=.{60.0,100.0,140.0,32.0},
|
||||
.text="Diagonal",.font=32,.rotation=angle,.origin=.{70.0,16.0},.wrap=.TextWrapNone}
|
||||
if TextWidth(session,props) <= 80 { return false }
|
||||
Text(session,props)
|
||||
command := PendingPaintAt(session,0)
|
||||
if command.font != 32 || command.rotation != angle || command.origin.x != 130.0 || command.origin.y != 116.0 { return false }
|
||||
area: Rectangle
|
||||
if !PaintCommandArea(command,*area) || area.width <= 0.0 || area.height <= 0.0 { return false }
|
||||
return EndFrame(session) == .FrameOk
|
||||
}
|
||||
|
||||
#program_export
|
||||
main :: () -> s32 {
|
||||
session := SessionOpen()
|
||||
if !SessionValid(session) { return 1 }
|
||||
Clear()
|
||||
if !FrameText(session,0.0) { return 2 }
|
||||
horizontal: s32
|
||||
for pixel: pixmap_surface { if pixel != cast(u32)0xffffff { horizontal += 1 } }
|
||||
Clear()
|
||||
if !FrameText(session,90.0) { return 3 }
|
||||
vertical: s32; left: s32=256; right: s32; top: s32=256; bottom: s32
|
||||
for y: 0..255 { for x: 0..255 {
|
||||
if pixmap_surface[y*256+x] != cast(u32)0xffffff {
|
||||
vertical += 1
|
||||
if x<left { left=cast(s32)x }; if x>right { right=cast(s32)x }
|
||||
if y<top { top=cast(s32)y }; if y>bottom { bottom=cast(s32)y }
|
||||
}
|
||||
} }
|
||||
if horizontal < 200 || vertical < horizontal*8/10 || bottom-top < (right-left)*2 { return 4 }
|
||||
angles: [3]float32 = .[-37.0,23.5,180.0]
|
||||
for angle: angles {
|
||||
Clear()
|
||||
if !FrameText(session,angle) { return 5 }
|
||||
count: s32
|
||||
for pixel: pixmap_surface { if pixel != cast(u32)0xffffff { count += 1 } }
|
||||
if count < 100 { return 7 }
|
||||
}
|
||||
// Ancestor clipping stays in world coordinates while the label clip rotates.
|
||||
Clear()
|
||||
BeginFrame(session,cast(u64)1,Rectangle.{0.0,0.0,256.0,256.0})
|
||||
parent := TreeSubmitCurrent(session,cast(u64)3,WidgetKindGroup,Rectangle.{0.0,0.0,256.0,256.0})
|
||||
TreeSetChildClip(session,parent,Rectangle.{0.0,0.0,256.0,116.0})
|
||||
if !TreePushScope(session,parent) { return 8 }
|
||||
Text(session,TextProps.{.key=cast(u64)4,.bounds=.{60.0,100.0,140.0,32.0},
|
||||
.text="Diagonal",.font=32,.rotation=90.0,.origin=.{70.0,16.0},.wrap=.TextWrapNone})
|
||||
TreePopScope(session)
|
||||
if EndFrame(session) != .FrameOk { return 9 }
|
||||
clipped: s32
|
||||
for y: 0..255 { for x: 0..255 {
|
||||
if pixmap_surface[y*256+x] != cast(u32)0xffffff {
|
||||
if y >= 116 { return 10 }
|
||||
clipped += 1
|
||||
}
|
||||
} }
|
||||
if clipped < 100 || clipped >= vertical { return 11 }
|
||||
// Link hit testing follows the inverse transform around the same pivot.
|
||||
links: [1]TextRange = .[.{0,4}]
|
||||
props: TextProps = .{.bounds=.{40.0,40.0,120.0,32.0},.text="Link",.font=32,
|
||||
.rotation=90.0,.origin=.{60.0,16.0},.links=links[:],.wrap=.TextWrapNone}
|
||||
origin: Vector2 = .{100.0,56.0}
|
||||
point := WorldToScreen(Vector2.{44.0,45.0},Camera.{.offset=origin,.target=origin,.rotation=90.0,.zoom=1.0})
|
||||
if TextLinkAt(session,props,point.x,point.y) != 0 { return 6 }
|
||||
SessionClose(session)
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
"""Compile the public Text API with both actual browser renderers."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
from toolchain import ZIRAN, ZIRAN_ROOT
|
||||
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
env=dict(os.environ)
|
||||
for key in ('DISPLAY','WAYLAND_DISPLAY','XAUTHORITY','DBUS_SESSION_BUS_ADDRESS','GDK_DISPLAY'):
|
||||
env.pop(key,None)
|
||||
env['YUE_DESKTOP_RECOVERY']='0'
|
||||
short_temp=ROOT/'build/scratch/t'
|
||||
short_temp.mkdir(parents=True,exist_ok=True)
|
||||
env['TMPDIR']=str(short_temp)
|
||||
env.setdefault('EM_CACHE',str(ROOT/'build/emscripten-cache'))
|
||||
projects=[]
|
||||
for backend in ('canvas','dom'):
|
||||
project=ROOT/'build/scratch/rotated-text'/backend
|
||||
(project/'src').mkdir(parents=True,exist_ok=True)
|
||||
(project/'assets').mkdir(exist_ok=True)
|
||||
(project/'src/app.zi').write_bytes((ROOT/'tests/fixtures/rotated_text.zi').read_bytes())
|
||||
(project/'ziran.toml').write_text(
|
||||
'[package]\nname="text_rotation"\nentry="src/app.zi"\nmodule_roots=["src"]\nbridge_modules=["app"]\n'
|
||||
'[toolchain]\ngit="https://github.com/ziranlang/ziran.git"\nref="master"\n'
|
||||
'[dependencies.kryon]\ngit="https://github.com/kryonlabs/kryon.git"\nref="master"\n'
|
||||
'[tool.kryon.profiles.web]\nbackend="'+backend+'"\nassets="assets"\n')
|
||||
(project/'ziran.local.toml').write_text('[overrides]\nkryon="'+str(ROOT)+'"\nziran="'+str(ZIRAN_ROOT)+'"\n')
|
||||
def run(args):
|
||||
subprocess.run(list(map(str,args)),cwd=project,env=env,check=True,timeout=600)
|
||||
run([ZIRAN,'lock'])
|
||||
run([ZIRAN,'tool','kryon','build','--profile','web'])
|
||||
projects.append((backend,project))
|
||||
if '--build-only' not in sys.argv:
|
||||
for backend,project in projects:
|
||||
run([sys.executable,ROOT/'tests/rotated_text_browser.py',
|
||||
(project/'build/text_rotation-web.html').as_uri(),project/'browser-profile',backend])
|
||||
@@ -45,6 +45,7 @@ set -- --bind raster:RasterLine=pixmap:RasterLine \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=pixmap:RasterRoundedRectangleOutline \
|
||||
--bind raster_text:RasterText=pixmap:RasterText \
|
||||
--bind raster_text:RasterTextClipped=pixmap:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=pixmap:RasterTextRotated \
|
||||
--bind raster_triangles:RasterTriangles=pixmap:RasterTriangles
|
||||
"$ziran" ir --project --root "$repo/tests" --module-path "$repo/tests" \
|
||||
-o "$output/ir" "$source"
|
||||
|
||||
@@ -60,3 +60,14 @@ HostCountsAre :: (want_lines: s32, want_labels: s32,
|
||||
return !failed && lines == want_lines && labels == want_labels &&
|
||||
measures == want_measures && bullets == want_bullets
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused value; unused x; unused y; unused font; unused color; unused clip; unused origin
|
||||
unused rotation; unused outer_clip; unused outer_clipped; unused emphasis; unused italic
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTriangles :: (points: []Vector2, color: Color) { unused points; unused color }
|
||||
@@ -10,3 +10,15 @@ set -- "$@" \
|
||||
--bind "raster:RasterLine=$widget_host:RasterLine" \
|
||||
--bind "paint_queue:RasterImage=$widget_host:RasterImage" \
|
||||
--bind "paint_queue:RasterImageMesh=$widget_mesh_host:RasterImageMesh"
|
||||
|
||||
widget_rotated_host=ziran_mesh_noop_host
|
||||
case "$widget_host" in
|
||||
ziran_link_widget_host|separator_widget_host|ziran_overlay_widget_host|ziran_shape_widget_host|ziran_context_menu_widget_host|ziran_mixed_tree_host|paned_view_host|ziran_test_driver_host)
|
||||
widget_rotated_host=$widget_host ;;
|
||||
esac
|
||||
widget_triangles_function=RasterTriangles
|
||||
if test "$widget_rotated_host" = ziran_mesh_noop_host; then widget_triangles_function=NoopRasterTriangles; fi
|
||||
set -- "$@" --bind "raster_text:RasterTextRotated=$widget_rotated_host:RasterTextRotated"
|
||||
if test "${widget_triangles_needed:-0}" = 1; then
|
||||
set -- "$@" --bind "raster_triangles:RasterTriangles=$widget_rotated_host:$widget_triangles_function"
|
||||
fi
|
||||
@@ -7,6 +7,7 @@ widget_mesh_host=ziran_mesh_noop_host
|
||||
set -- \
|
||||
--bind image_raster:ImageWidth=ziran_widget_noop_host:ImageWidth \
|
||||
--bind image_raster:ImageHeight=ziran_widget_noop_host:ImageHeight
|
||||
widget_triangles_needed=1
|
||||
. "$repo/tests/widget_raster_bindings.sh"
|
||||
|
||||
widget_std="$ziran_root/std"
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
# Image sampling through the Cairo host: sharp pixels unless smooth.
|
||||
set -eu
|
||||
repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
. "$repo/tests/toolchain.sh"
|
||||
work="$repo/build/scratch/cairo-scaled-image"
|
||||
mkdir -p "$work/fixtures"
|
||||
unset DISPLAY WAYLAND_DISPLAY XAUTHORITY DBUS_SESSION_BUS_ADDRESS SESSION_MANAGER
|
||||
export YUE_DESKTOP_RECOVERY=0
|
||||
python3 - "$work/fixtures" <<'PY'
|
||||
from pathlib import Path
|
||||
from PIL import Image
|
||||
import sys
|
||||
image = Image.new('RGBA', (512, 512))
|
||||
image.putdata([((x*19)%256,(y*23)%256,((x+y)*7)%256,(x*3+y*5)%256) for y in range(512) for x in range(512)])
|
||||
image.save(Path(sys.argv[1]) / 'scaled.png')
|
||||
PY
|
||||
libs="$(pkg-config --libs cairo freetype2 pangocairo fontconfig glib-2.0) -ldl -lm -lpthread"
|
||||
source="$repo/tests/cairo_scaled_image_test.zi"
|
||||
"$ziran" ir --root "$repo/tests" --module-path "$repo/src/backend" \
|
||||
--module-path "$repo/src/ui" --module-path "$ziran_root/std" -o "$work/ir" "$source"
|
||||
for form in source saved; do
|
||||
input=$source; root=$repo/tests
|
||||
if test "$form" = saved; then input=$work/ir/cairo_scaled_image_test.zir; root=$work/ir; fi
|
||||
for target in c; do
|
||||
output=$work/$target-$form
|
||||
"$ziran" build --root "$root" --module-path "$repo/src/backend" \
|
||||
--module-path "$repo/src/ui" --module-path "$ziran_root/std" \
|
||||
--target="$target" --no-main -o "$output" "$input"
|
||||
suffix=c; header=h; compiler=${CC:-cc}; standard=c11
|
||||
printf '#include "cairo_scaled_image_test.%s"\nint main(int argc, char **argv) { return cairo_scaled_image_test_main(argc, (uint8_t **)argv); }\n' "$header" > "$output/entry.$suffix"
|
||||
"$compiler" -std="$standard" -O2 -I"$ziran_root/include" -I"$output" \
|
||||
"$output"/*."$suffix" $libs -o "$output/test"
|
||||
"$output/test" "$work/fixtures"
|
||||
done
|
||||
done
|
||||
@@ -7,6 +7,7 @@ widget_mesh_host=ziran_mesh_noop_host
|
||||
set -- \
|
||||
--bind image_raster:ImageWidth=ziran_image_widget_host:ImageWidth \
|
||||
--bind image_raster:ImageHeight=ziran_image_widget_host:ImageHeight
|
||||
widget_triangles_needed=1
|
||||
. "$repo/tests/widget_raster_bindings.sh"
|
||||
|
||||
widget_native=1
|
||||
|
||||
@@ -49,3 +49,14 @@ RasterImageMesh :: (path: string, texture_id: u32, source: Rectangle,
|
||||
|
||||
#program_export
|
||||
ContextMenuLabelCount :: () -> s32 { return labels }
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused value; unused x; unused y; unused font; unused color; unused clip; unused origin
|
||||
unused rotation; unused outer_clip; unused outer_clipped; unused emphasis; unused italic
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTriangles :: (points: []Vector2, color: Color) { unused points; unused color }
|
||||
@@ -10,6 +10,7 @@ set -- \
|
||||
--bind system_clipboard:SystemClipboardOpenHost=ziran_system_clipboard_host:SystemClipboardOpenHost \
|
||||
--bind system_clipboard:SystemClipboardByteHost=ziran_system_clipboard_host:SystemClipboardByteHost \
|
||||
--bind system_clipboard:SystemClipboardWriteHost=ziran_system_clipboard_host:SystemClipboardWriteHost
|
||||
widget_triangles_needed=1
|
||||
. "$repo/tests/widget_raster_bindings.sh"
|
||||
|
||||
widget_std="$ziran_root/std"
|
||||
|
||||
@@ -9,6 +9,7 @@ set -- \
|
||||
--bind raster:RasterLine=fieldset_widget_host:RasterLine \
|
||||
--bind raster_text:RasterText=fieldset_widget_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=fieldset_widget_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=fieldset_widget_host:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=ziran_mesh_noop_host:RasterImageMesh
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ set -- \
|
||||
--bind raster:RasterLine=ziran_frame_retained_host:RasterLine \
|
||||
--bind raster_text:RasterText=ziran_frame_retained_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=ziran_frame_retained_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=ziran_frame_retained_host:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=ziran_mesh_noop_host:RasterImageMesh
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ set -- \
|
||||
--bind raster:RasterLine=ziran_frame_retained_host:RasterLine \
|
||||
--bind raster_text:RasterText=ziran_frame_retained_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=ziran_frame_retained_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=ziran_frame_retained_host:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=ziran_mesh_noop_host:RasterImageMesh
|
||||
|
||||
|
||||
@@ -162,3 +162,6 @@ CarouselCoverDraws :: () -> s32 { return carousel_draws }
|
||||
|
||||
#program_export
|
||||
CarouselLastSource :: () -> Rectangle { return last_source }
|
||||
|
||||
#program_export
|
||||
RasterTriangles :: (points: []Vector2, color: Color) { unused points; unused color }
|
||||
@@ -64,3 +64,14 @@ LinkLineCount :: () -> s32 { return lines }
|
||||
|
||||
#program_export
|
||||
LinkHostFailed :: () -> bool { return failed }
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused value; unused x; unused y; unused font; unused color; unused clip; unused origin
|
||||
unused rotation; unused outer_clip; unused outer_clipped; unused emphasis; unused italic
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTriangles :: (points: []Vector2, color: Color) { unused points; unused color }
|
||||
@@ -47,6 +47,9 @@ func (linkHost) RasterText(value string, x, y, font int32, color Color) {
|
||||
ZiranLinkWidgetHost_RasterText(value, x, y, font, color)
|
||||
}
|
||||
|
||||
func (linkHost) RasterTextRotated(value string, x, y, font int32, color Color, clip Rectangle, origin Vector2, rotation float32, outerClip Rectangle, outerClipped, emphasis, italic bool) {
|
||||
ZiranLinkWidgetHost_RasterTextRotated(value,x,y,font,color,clip,origin,rotation,outerClip,outerClipped,emphasis,italic)
|
||||
}
|
||||
func (linkHost) RasterTextClipped(value string, x, y, font int32,
|
||||
color Color, clip Rectangle) {
|
||||
ZiranLinkWidgetHost_RasterTextClipped(value, x, y, font, color, clip)
|
||||
|
||||
@@ -9,6 +9,7 @@ set -- \
|
||||
--bind raster:RasterLine=list_box_widget_host:RasterLine \
|
||||
--bind raster_text:RasterText=list_box_widget_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=list_box_widget_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=list_box_widget_host:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=ziran_mesh_noop_host:RasterImageMesh
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ set -- \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=ziran_context_menu_widget_host:RasterRoundedRectangleOutline \
|
||||
--bind raster:RasterLine=ziran_context_menu_widget_host:RasterLine \
|
||||
--bind raster_text:RasterText=ziran_context_menu_widget_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=ziran_context_menu_widget_host:RasterTextClipped
|
||||
--bind raster_text:RasterTextClipped=ziran_context_menu_widget_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_context_menu_widget_host:RasterTextRotated
|
||||
"$ziran" ir --root "$repo/tests" --module-path "$repo/src/ui" --entry "$entry" -o "$work/ir" "$source"
|
||||
for form in source saved; do
|
||||
input=$source
|
||||
|
||||
@@ -15,3 +15,14 @@ RasterImageMesh :: (asset_path: string, texture_id: u32,
|
||||
unused clip
|
||||
unused tint
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused value; unused x; unused y; unused font; unused color; unused clip; unused origin
|
||||
unused rotation; unused outer_clip; unused outer_clipped; unused emphasis; unused italic
|
||||
}
|
||||
|
||||
#program_export
|
||||
NoopRasterTriangles :: (points: []Vector2, color: Color) { unused points; unused color }
|
||||
@@ -66,3 +66,14 @@ MixedEventCount :: () -> s32 { return events }
|
||||
|
||||
#program_export
|
||||
MixedHostFailed :: () -> bool { return failed }
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused value; unused x; unused y; unused font; unused color; unused clip; unused origin
|
||||
unused rotation; unused outer_clip; unused outer_clipped; unused emphasis; unused italic
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTriangles :: (points: []Vector2, color: Color) { unused points; unused color }
|
||||
@@ -52,6 +52,9 @@ func (mixedHost) RasterText(value string, x, y, font int32, color Color) {
|
||||
ZiranMixedTreeHost_RasterText(value, x, y, font, color)
|
||||
}
|
||||
|
||||
func (mixedHost) RasterTextRotated(value string, x, y, font int32, color Color, clip Rectangle, origin Vector2, rotation float32, outerClip Rectangle, outerClipped, emphasis, italic bool) {
|
||||
ZiranMixedTreeHost_RasterTextRotated(value,x,y,font,color,clip,origin,rotation,outerClip,outerClipped,emphasis,italic)
|
||||
}
|
||||
func (mixedHost) RasterTextClipped(value string, x, y, font int32,
|
||||
color Color, clip Rectangle) {
|
||||
ZiranMixedTreeHost_RasterTextClipped(value, x, y, font, color, clip)
|
||||
|
||||
@@ -13,6 +13,7 @@ widget_mesh_host=ziran_mesh_noop_host
|
||||
set -- \
|
||||
--bind image_raster:ImageWidth=ziran_widget_noop_host:ImageWidth \
|
||||
--bind image_raster:ImageHeight=ziran_widget_noop_host:ImageHeight
|
||||
widget_triangles_needed=1
|
||||
. "$repo/tests/widget_raster_bindings.sh"
|
||||
|
||||
widget_std="$ziran_root/std"
|
||||
|
||||
@@ -6,6 +6,7 @@ set -- \
|
||||
--bind raster:RasterLine=ziran_navigation_bar_widget_host:RasterLine \
|
||||
--bind raster_text:RasterText=ziran_navigation_bar_widget_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=ziran_navigation_bar_widget_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated \
|
||||
--bind raster_shape:RasterRoundedRectangle=ziran_navigation_bar_widget_host:RasterRoundedRectangle \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=ziran_navigation_bar_widget_host:RasterRoundedRectangleOutline \
|
||||
--bind paint_queue:RasterImage=ziran_navigation_bar_widget_host:RasterImage \
|
||||
|
||||
@@ -48,3 +48,14 @@ OverlayFillCount :: () -> s32 { return fills }
|
||||
|
||||
#program_export
|
||||
OverlayHostFailed :: () -> bool { return failed }
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused value; unused x; unused y; unused font; unused color; unused clip; unused origin
|
||||
unused rotation; unused outer_clip; unused outer_clipped; unused emphasis; unused italic
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTriangles :: (points: []Vector2, color: Color) { unused points; unused color }
|
||||
@@ -15,6 +15,7 @@ set -- \
|
||||
--bind raster:RasterLine=ziran_overlay_widget_host:RasterLine \
|
||||
--bind raster_text:RasterText=ziran_overlay_widget_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=ziran_overlay_widget_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_overlay_widget_host:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=ziran_overlay_widget_host:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=ziran_overlay_widget_host:RasterImageMesh
|
||||
|
||||
@@ -64,6 +65,9 @@ func (testOverlayHost) RasterText(value string, x, y, font int32,
|
||||
ZiranOverlayWidgetHost_RasterText(value, x, y, font, color)
|
||||
}
|
||||
|
||||
func (testOverlayHost) RasterTextRotated(value string, x, y, font int32, color Color, clip Rectangle, origin Vector2, rotation float32, outerClip Rectangle, outerClipped, emphasis, italic bool) {
|
||||
ZiranOverlayWidgetHost_RasterTextRotated(value,x,y,font,color,clip,origin,rotation,outerClip,outerClipped,emphasis,italic)
|
||||
}
|
||||
func (testOverlayHost) RasterTextClipped(value string, x, y, font int32,
|
||||
color Color, clip Rectangle) {
|
||||
ZiranOverlayWidgetHost_RasterTextClipped(value, x, y, font, color, clip)
|
||||
|
||||
@@ -5,6 +5,7 @@ source=$repo/tests/ziran_page_text_test.zi
|
||||
widget_host=ziran_page_text_host
|
||||
widget_mesh_host=ziran_mesh_noop_host
|
||||
set --
|
||||
widget_triangles_needed=1
|
||||
. "$repo/tests/widget_raster_bindings.sh"
|
||||
|
||||
widget_std="$ziran_root/std"
|
||||
|
||||
@@ -109,6 +109,13 @@ HOST void RasterImageMesh(String path, uint32_t id, Rectangle source,
|
||||
(void)path; (void)id; (void)source; (void)points;
|
||||
(void)columns; (void)rows; (void)clip; (void)tint;
|
||||
}
|
||||
HOST void RasterTextRotated(String value, int32_t x, int32_t y, int32_t font,
|
||||
Color color, Rectangle clip, Vector2 origin, float rotation,
|
||||
Rectangle outer_clip, bool outer_clipped, bool emphasis, bool italic) {
|
||||
(void)value; (void)x; (void)y; (void)font; (void)color; (void)clip;
|
||||
(void)origin; (void)rotation; (void)outer_clip; (void)outer_clipped;
|
||||
(void)emphasis; (void)italic; assert(0 && "unexpected rotated text");
|
||||
}
|
||||
int main(void) {
|
||||
assert(Frame() == 42);
|
||||
assert(text_draws == 2 && image_draws == 1 && shape_draws == 18);
|
||||
@@ -147,6 +154,7 @@ func (h *clipHost) RasterLine(bounds Rectangle,
|
||||
color Color) { h.t.Fatal("unexpected line") }
|
||||
func (h *clipHost) RasterText(value string, x, y, font int32,
|
||||
color Color) { h.t.Fatal("unexpected plain text") }
|
||||
func (h *clipHost) RasterTextRotated(value string, x, y, font int32, color Color, clip Rectangle, origin Vector2, rotation float32, outerClip Rectangle, outerClipped, emphasis, italic bool) { panic("unexpected rotated text") }
|
||||
func (h *clipHost) RasterTextClipped(value string, x, y, font int32,
|
||||
color Color, clip Rectangle) {
|
||||
if !((value == "Clip" && x == 10 && y == 10) ||
|
||||
|
||||
@@ -44,6 +44,7 @@ ZI
|
||||
|
||||
cat > "$work/main.c" <<'C'
|
||||
#include "app.h"
|
||||
#include <assert.h>
|
||||
static int rows;
|
||||
static float last_y, last_height;
|
||||
static Color first, last;
|
||||
@@ -79,6 +80,13 @@ void RasterImageMesh(String path, uint32_t id, Rectangle source,
|
||||
(void)path; (void)id; (void)source; (void)points;
|
||||
(void)columns; (void)rows; (void)clip; (void)tint;
|
||||
}
|
||||
void RasterTextRotated(String value, int32_t x, int32_t y, int32_t font,
|
||||
Color color, Rectangle clip, Vector2 origin, float rotation,
|
||||
Rectangle outer_clip, bool outer_clipped, bool emphasis, bool italic) {
|
||||
(void)value; (void)x; (void)y; (void)font; (void)color; (void)clip;
|
||||
(void)origin; (void)rotation; (void)outer_clip; (void)outer_clipped;
|
||||
(void)emphasis; (void)italic; assert(0 && "unexpected rotated text");
|
||||
}
|
||||
int main(void) {
|
||||
if (Answer() != 42) return 1;
|
||||
/* Four one-pixel rows sampled at 1/8, 3/8, 5/8, and 7/8. */
|
||||
|
||||
@@ -13,6 +13,7 @@ set -- \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=ziran_paint_text_large_test:RasterRoundedRectangleOutline \
|
||||
--bind raster_text:RasterText=ziran_paint_text_large_test:RasterText \
|
||||
--bind raster_text:RasterTextClipped=ziran_paint_text_large_test:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=ziran_paint_text_large_test:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=ziran_mesh_noop_host:RasterImageMesh
|
||||
"$ziran" ir --root "$repo/tests" --module-path "$repo/src/ui" \
|
||||
|
||||
@@ -45,6 +45,7 @@ ZI
|
||||
cat > "$work/main.c" <<'C'
|
||||
#include <string.h>
|
||||
#include "app.h"
|
||||
#include <assert.h>
|
||||
static int labels;
|
||||
static int matched;
|
||||
void RasterRoundedRectangle(Rectangle bounds, float radius,
|
||||
@@ -77,6 +78,13 @@ void RasterImageMesh(String path, uint32_t id, Rectangle source,
|
||||
(void)path; (void)id; (void)source; (void)points;
|
||||
(void)columns; (void)rows; (void)clip; (void)tint;
|
||||
}
|
||||
void RasterTextRotated(String value, int32_t x, int32_t y, int32_t font,
|
||||
Color color, Rectangle clip, Vector2 origin, float rotation,
|
||||
Rectangle outer_clip, bool outer_clipped, bool emphasis, bool italic) {
|
||||
(void)value; (void)x; (void)y; (void)font; (void)color; (void)clip;
|
||||
(void)origin; (void)rotation; (void)outer_clip; (void)outer_clipped;
|
||||
(void)emphasis; (void)italic; assert(0 && "unexpected rotated text");
|
||||
}
|
||||
int main(void) {
|
||||
if (Answer() != 42) return 1;
|
||||
if (labels != 1 || matched != 1) return 2;
|
||||
|
||||
@@ -11,7 +11,7 @@ bind_image=paint_queue:RasterImage=paned_view_host:RasterImage
|
||||
bind_mesh=paint_queue:RasterImageMesh=paned_view_host:RasterImageMesh
|
||||
|
||||
set -- --bind "$bind_fill" --bind "$bind_outline" --bind "$bind_line" \
|
||||
--bind "$bind_text" --bind "$bind_clipped" --bind "$bind_image" --bind "$bind_mesh"
|
||||
--bind raster_text:RasterTextRotated=paned_view_host:RasterTextRotated --bind "$bind_text" --bind "$bind_clipped" --bind "$bind_image" --bind "$bind_mesh"
|
||||
widget_native=1
|
||||
widget_run_saved=1
|
||||
widget_std="$ziran_root/std"
|
||||
|
||||
@@ -16,6 +16,7 @@ set -- --bind raster_triangles:RasterTriangles=pixmap:RasterTriangles \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=pixmap:RasterRoundedRectangleOutline \
|
||||
--bind raster_text:RasterText=pixmap:RasterText \
|
||||
--bind raster_text:RasterTextClipped=pixmap:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=pixmap:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=pixmap:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=pixmap:RasterImageMesh
|
||||
"$ziran" ir --project --root "$repo/tests" -o "$work/ir" "$source"
|
||||
|
||||
@@ -7,6 +7,7 @@ set -- \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=ziran_progress_raster_host:RasterRoundedRectangleOutline \
|
||||
--bind raster_text:RasterText=ziran_progress_raster_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=ziran_progress_raster_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated \
|
||||
--bind raster:RasterLine=ziran_progress_raster_host:RasterLine \
|
||||
--bind paint_queue:RasterImage=ziran_progress_raster_host:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=ziran_mesh_noop_host:RasterImageMesh
|
||||
|
||||
@@ -9,7 +9,8 @@ set -- \
|
||||
--bind raster_shape:RasterRoundedRectangle=ziran_progress_raster_host:RasterRoundedRectangle \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=ziran_progress_raster_host:RasterRoundedRectangleOutline \
|
||||
--bind raster_text:RasterText=ziran_progress_raster_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=ziran_progress_raster_host:RasterTextClipped
|
||||
--bind raster_text:RasterTextClipped=ziran_progress_raster_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated
|
||||
|
||||
"$ziran" ir --root "$repo/tests" --module-path "$repo/src/ui" --module-path "$ziran_root/std" \
|
||||
-o "$work/ir" "$portable"
|
||||
@@ -97,6 +98,13 @@ HOST void RasterImageMesh(String path, uint32_t id, Rectangle source,
|
||||
(void)path; (void)id; (void)source; (void)points;
|
||||
(void)columns; (void)rows; (void)clip; (void)tint;
|
||||
}
|
||||
HOST void RasterTextRotated(String value, int32_t x, int32_t y, int32_t font,
|
||||
Color color, Rectangle clip, Vector2 origin, float rotation,
|
||||
Rectangle outer_clip, bool outer_clipped, bool emphasis, bool italic) {
|
||||
(void)value; (void)x; (void)y; (void)font; (void)color; (void)clip;
|
||||
(void)origin; (void)rotation; (void)outer_clip; (void)outer_clipped;
|
||||
(void)emphasis; (void)italic; assert(0 && "unexpected rotated text");
|
||||
}
|
||||
int main(void) {
|
||||
assert(Answer() == 42 && measures == 2 && draws == 5);
|
||||
return 0;
|
||||
@@ -157,6 +165,7 @@ func (host *widgetHost) RasterText(value string, x int32, y int32,
|
||||
}
|
||||
host.draws++
|
||||
}
|
||||
func (host *widgetHost) RasterTextRotated(value string, x, y, font int32, color Color, clip Rectangle, origin Vector2, rotation float32, outerClip Rectangle, outerClipped, emphasis, italic bool) { panic("unexpected rotated text") }
|
||||
func (host *widgetHost) RasterTextClipped(value string, x, y, font int32,
|
||||
color Color, clip Rectangle) {
|
||||
host.t.Fatal("Progress should not draw clipped text")
|
||||
|
||||
@@ -207,6 +207,7 @@ cat > "$work/native_main.h" <<'C'
|
||||
#define HOST extern "C"
|
||||
#else
|
||||
#include "app.h"
|
||||
#include <assert.h>
|
||||
#define HOST
|
||||
#endif
|
||||
HOST void RasterRoundedRectangle(Rectangle bounds, float radius,
|
||||
@@ -239,6 +240,13 @@ HOST void RasterImageMesh(String path, uint32_t id, Rectangle source,
|
||||
(void)path; (void)id; (void)source; (void)points;
|
||||
(void)columns; (void)rows; (void)clip; (void)tint;
|
||||
}
|
||||
HOST void RasterTextRotated(String value, int32_t x, int32_t y, int32_t font,
|
||||
Color color, Rectangle clip, Vector2 origin, float rotation,
|
||||
Rectangle outer_clip, bool outer_clipped, bool emphasis, bool italic) {
|
||||
(void)value; (void)x; (void)y; (void)font; (void)color; (void)clip;
|
||||
(void)origin; (void)rotation; (void)outer_clip; (void)outer_clipped;
|
||||
(void)emphasis; (void)italic; assert(0 && "unexpected rotated text");
|
||||
}
|
||||
int main(void) { return Answer() == 42 ? 0 : 1; }
|
||||
C
|
||||
|
||||
|
||||
@@ -338,6 +338,7 @@ cat > "$work/native_main.h" <<'C'
|
||||
#define HOST extern "C"
|
||||
#else
|
||||
#include "app.h"
|
||||
#include <assert.h>
|
||||
#define HOST
|
||||
#endif
|
||||
HOST void RasterRoundedRectangle(Rectangle bounds, float radius,
|
||||
@@ -370,6 +371,13 @@ HOST void RasterImageMesh(String path, uint32_t id, Rectangle source,
|
||||
(void)path; (void)id; (void)source; (void)points;
|
||||
(void)columns; (void)rows; (void)clip; (void)tint;
|
||||
}
|
||||
HOST void RasterTextRotated(String value, int32_t x, int32_t y, int32_t font,
|
||||
Color color, Rectangle clip, Vector2 origin, float rotation,
|
||||
Rectangle outer_clip, bool outer_clipped, bool emphasis, bool italic) {
|
||||
(void)value; (void)x; (void)y; (void)font; (void)color; (void)clip;
|
||||
(void)origin; (void)rotation; (void)outer_clip; (void)outer_clipped;
|
||||
(void)emphasis; (void)italic; assert(0 && "unexpected rotated text");
|
||||
}
|
||||
int main(void) { return Answer() == 42 ? 0 : 1; }
|
||||
C
|
||||
|
||||
@@ -425,6 +433,7 @@ set -- \
|
||||
--bind raster:RasterLine=ziran_widget_noop_host:RasterLine \
|
||||
--bind raster_text:RasterText=ziran_widget_noop_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=ziran_widget_noop_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=ziran_widget_noop_host:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=ziran_mesh_noop_host:RasterImageMesh
|
||||
"$ziran" ir --root "$work" --module-path "$repo/src/ui" --module-path "$repo/tests" \
|
||||
|
||||
@@ -9,6 +9,7 @@ set -- \
|
||||
--bind raster:RasterLine=selectable_widget_host:RasterLine \
|
||||
--bind raster_text:RasterText=selectable_widget_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=selectable_widget_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=selectable_widget_host:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=ziran_mesh_noop_host:RasterImageMesh
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ set -- \
|
||||
--bind raster:RasterLine=separator_widget_host:RasterLine \
|
||||
--bind raster_text:RasterText=separator_widget_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=separator_widget_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=separator_widget_host:RasterTextRotated \
|
||||
--bind font_metrics:MeasureGlyphWidth=separator_widget_host:MeasureGlyphWidth \
|
||||
--bind raster_shape:RasterRoundedRectangle=separator_widget_host:RasterRoundedRectangle
|
||||
|
||||
@@ -99,6 +100,13 @@ HOST void RasterImageMesh(String path, uint32_t id, Rectangle source,
|
||||
(void)path; (void)id; (void)source; (void)points;
|
||||
(void)columns; (void)rows; (void)clip; (void)tint;
|
||||
}
|
||||
HOST void RasterTextRotated(String value, int32_t x, int32_t y, int32_t font,
|
||||
Color color, Rectangle clip, Vector2 origin, float rotation,
|
||||
Rectangle outer_clip, bool outer_clipped, bool emphasis, bool italic) {
|
||||
(void)value; (void)x; (void)y; (void)font; (void)color; (void)clip;
|
||||
(void)origin; (void)rotation; (void)outer_clip; (void)outer_clipped;
|
||||
(void)emphasis; (void)italic; assert(0 && "unexpected rotated text");
|
||||
}
|
||||
int main(void) {
|
||||
assert(Answer() == 42 && lines == 2 && texts == 1 &&
|
||||
measures == 1 && bullets == 1);
|
||||
@@ -145,6 +153,7 @@ func (h *separatorHost) RasterText(value string, x, y, font int32,
|
||||
color.B != 0xcc || color.A != 0xdd { h.t.Fatal("label") }
|
||||
h.texts++
|
||||
}
|
||||
func (h *separatorHost) RasterTextRotated(value string, x, y, font int32, color Color, clip Rectangle, origin Vector2, rotation float32, outerClip Rectangle, outerClipped, emphasis, italic bool) { panic("unexpected rotated text") }
|
||||
func (h *separatorHost) RasterTextClipped(value string, x, y, font int32,
|
||||
color Color, clip Rectangle) {
|
||||
h.t.Fatal("Separator should not draw clipped text")
|
||||
|
||||
@@ -50,7 +50,7 @@ cd "$project"
|
||||
set --
|
||||
for effect in raster_triangles:RasterTriangles \
|
||||
raster_shape:RasterRoundedRectangle raster_shape:RasterRoundedRectangleOutline \
|
||||
raster:RasterLine raster_text:RasterText raster_text:RasterTextClipped \
|
||||
raster:RasterLine raster_text:RasterText raster_text:RasterTextClipped raster_text:RasterTextRotated \
|
||||
paint_queue:RasterImage paint_queue:RasterImageMesh; do
|
||||
set -- "$@" --bind "kryon/$effect=ziran_shape_widget_host:${effect#*:}"
|
||||
done
|
||||
|
||||
@@ -138,3 +138,11 @@ ShapeHostRoundedRadius :: () -> float32 { return rounded_radius }
|
||||
|
||||
#program_export
|
||||
ShapeHostFailed :: () -> bool { return failed }
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused value; unused x; unused y; unused font; unused color; unused clip; unused origin
|
||||
unused rotation; unused outer_clip; unused outer_clipped; unused emphasis; unused italic
|
||||
}
|
||||
@@ -21,6 +21,7 @@ set -- \
|
||||
--bind raster:RasterLine=$host:RasterLine \
|
||||
--bind raster_text:RasterText=$host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=$host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_shape_widget_host:RasterTextRotated \
|
||||
--bind paint_queue:RasterImage=$host:RasterImage \
|
||||
--bind paint_queue:RasterImageMesh=$host:RasterImageMesh
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ set -- \
|
||||
--bind raster:RasterLine=ziran_navigation_bar_widget_host:RasterLine \
|
||||
--bind raster_text:RasterText=ziran_navigation_bar_widget_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=ziran_navigation_bar_widget_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated \
|
||||
--bind raster_shape:RasterRoundedRectangle=ziran_navigation_bar_widget_host:RasterRoundedRectangle \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=ziran_navigation_bar_widget_host:RasterRoundedRectangleOutline \
|
||||
--bind paint_queue:RasterImage=ziran_navigation_bar_widget_host:RasterImage \
|
||||
|
||||
@@ -7,6 +7,7 @@ set -- \
|
||||
--bind raster:RasterLine=ziran_navigation_bar_widget_host:RasterLine \
|
||||
--bind raster_text:RasterText=ziran_navigation_bar_widget_host:RasterText \
|
||||
--bind raster_text:RasterTextClipped=ziran_navigation_bar_widget_host:RasterTextClipped \
|
||||
--bind raster_text:RasterTextRotated=ziran_mesh_noop_host:RasterTextRotated \
|
||||
--bind raster_shape:RasterRoundedRectangle=ziran_navigation_bar_widget_host:RasterRoundedRectangle \
|
||||
--bind raster_shape:RasterRoundedRectangleOutline=ziran_navigation_bar_widget_host:RasterRoundedRectangleOutline \
|
||||
--bind paint_queue:RasterImage=ziran_navigation_bar_widget_host:RasterImage \
|
||||
|
||||
@@ -45,3 +45,14 @@ RasterImage :: (asset_path: string, texture_id: u32, source: Rectangle,
|
||||
RasterImageMesh :: (asset_path: string, texture_id: u32, source: Rectangle,
|
||||
points: []Vector2, columns: s32, rows: s32, clip: Rectangle,
|
||||
tint: Color) {}
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused value; unused x; unused y; unused font; unused color; unused clip; unused origin
|
||||
unused rotation; unused outer_clip; unused outer_clipped; unused emphasis; unused italic
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTriangles :: (points: []Vector2, color: Color) { unused points; unused color }
|
||||
@@ -11,6 +11,7 @@ source=$repo/tests/ziran_text_ellipsis_test.zi
|
||||
widget_host=ziran_widget_noop_host
|
||||
widget_mesh_host=ziran_mesh_noop_host
|
||||
set --
|
||||
widget_triangles_needed=1
|
||||
. "$repo/tests/widget_raster_bindings.sh"
|
||||
|
||||
widget_std="$ziran_root/std"
|
||||
|
||||
@@ -5,6 +5,7 @@ source=$repo/tests/ziran_text_page_test.zi
|
||||
widget_host=ziran_text_page_host
|
||||
widget_mesh_host=ziran_mesh_noop_host
|
||||
set --
|
||||
widget_triangles_needed=1
|
||||
. "$repo/tests/widget_raster_bindings.sh"
|
||||
|
||||
widget_std="$ziran_root/std"
|
||||
|
||||
@@ -9,6 +9,7 @@ set -- \
|
||||
--bind system_clipboard:SystemClipboardOpenHost=ziran_system_clipboard_host:SystemClipboardOpenHost \
|
||||
--bind system_clipboard:SystemClipboardByteHost=ziran_system_clipboard_host:SystemClipboardByteHost \
|
||||
--bind system_clipboard:SystemClipboardWriteHost=ziran_system_clipboard_host:SystemClipboardWriteHost
|
||||
widget_triangles_needed=1
|
||||
. "$repo/tests/widget_raster_bindings.sh"
|
||||
matrix_bundles=before
|
||||
matrix_forms=source
|
||||
|
||||
@@ -5,6 +5,7 @@ source=$repo/tests/ziran_text_widget_test.zi
|
||||
widget_host=ziran_text_widget_host
|
||||
widget_mesh_host=ziran_mesh_noop_host
|
||||
set --
|
||||
widget_triangles_needed=1
|
||||
. "$repo/tests/widget_raster_bindings.sh"
|
||||
|
||||
widget_std="$ziran_root/std"
|
||||
|
||||
@@ -195,6 +195,15 @@ Scale :: () -> s32 {
|
||||
return 42
|
||||
}
|
||||
|
||||
#program_export
|
||||
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
||||
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
||||
outer_clipped: bool, emphasis: bool, italic: bool) {
|
||||
unused value; unused x; unused y; unused font; unused color; unused clip; unused origin
|
||||
unused rotation; unused outer_clip; unused outer_clipped; unused emphasis; unused italic
|
||||
}
|
||||
|
||||
|
||||
#program_export
|
||||
main :: () -> s32 {
|
||||
if Check() == 42 && Scale() == 42 { return 0 }
|
||||
|
||||
@@ -62,8 +62,8 @@ ReplayState :: struct {
|
||||
failed: bool
|
||||
pointer_fields: [5]HostField
|
||||
labels: [12]Name
|
||||
bindings: [22]HostBinding
|
||||
binding_names: [44]Name
|
||||
bindings: [23]HostBinding
|
||||
binding_names: [46]Name
|
||||
samples: [1024]ReplaySample
|
||||
current_sample: s32
|
||||
input_names: [20]Name
|
||||
@@ -416,7 +416,7 @@ ReplayCall :: (context: *void, module_name: *u8, function_name: *u8,
|
||||
(function == "RasterRoundedRectangle" ||
|
||||
function == "RasterRoundedRectangleOutline")) ||
|
||||
(module == "raster_text" &&
|
||||
(function == "RasterText" || function == "RasterTextClipped")) ||
|
||||
(function == "RasterText" || function == "RasterTextClipped" || function == "RasterTextRotated")) ||
|
||||
(module == "paint_queue" &&
|
||||
(function == "RasterImage" || function == "RasterImageMesh")) ||
|
||||
(module == "raster_triangles" && function == "RasterTriangles") {
|
||||
@@ -729,7 +729,8 @@ ReadTrace :: (state: *ReplayState, path: string) -> bool {
|
||||
InitializeBindings :: (state: *ReplayState, pointer_module: string) -> bool {
|
||||
callback: HostCall = ReplayCall
|
||||
if !PreparePointer(state) || !PrepareInput(state) { return false }
|
||||
return SetBinding(state, 0, "font_metrics", "MeasureGlyphWidth", callback) &&
|
||||
return SetBinding(state, 22, "raster_text", "RasterTextRotated", callback) &&
|
||||
SetBinding(state, 0, "font_metrics", "MeasureGlyphWidth", callback) &&
|
||||
SetBinding(state, 1, "font_metrics", "MeasureGlyphLineHeight", callback) &&
|
||||
SetBinding(state, 2, "raster_shape", "RasterRoundedRectangle", callback) &&
|
||||
SetBinding(state, 3, "raster_shape", "RasterRoundedRectangleOutline", callback) &&
|
||||
@@ -760,7 +761,7 @@ Replay :: (state: *ReplayState, bundle_path: string,
|
||||
bundle: *void = OpenBundle(*bundle_name[0])
|
||||
if bundle == null { return false }
|
||||
instance: *void = InstantiateBundle(bundle, *state.bindings[0],
|
||||
cast(u64)22)
|
||||
cast(u64)23)
|
||||
if instance == null { CloseBundle(bundle); return false }
|
||||
state.output = OpenReplace(output_path)
|
||||
if !state.output.valid {
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ Supported :: (module: string, function: string) -> bool {
|
||||
return function == "MeasureGlyphWidth" || function == "MeasureGlyphLineHeight"
|
||||
}
|
||||
if ModuleName(module, "raster_text") {
|
||||
return function == "RasterText" || function == "RasterTextClipped"
|
||||
return function == "RasterText" || function == "RasterTextClipped" || function == "RasterTextRotated"
|
||||
}
|
||||
if ModuleName(module, "raster_shape") {
|
||||
return function == "RasterRoundedRectangle" ||
|
||||
|
||||
+1
-1
@@ -234,7 +234,7 @@ main :: () -> s32 {
|
||||
.measure_width = MeasureGlyphWidth, .measure_height = MeasureGlyphLineHeight,
|
||||
.image_width = ImageWidth, .image_height = ImageHeight,
|
||||
.line = RasterLine, .rectangle = RasterRoundedRectangle, .outline = RasterRoundedRectangleOutline,
|
||||
.text = RasterText, .clipped_text = RasterTextClipped,
|
||||
.text = RasterText, .clipped_text = RasterTextClipped, .rotated_text = RasterTextRotated,
|
||||
.image = RasterImage, .triangles = RasterTriangles, .mesh = RasterImageMesh}
|
||||
if !RasterHostValid(raster) { return 1 }
|
||||
player: Player.Player
|
||||
|
||||
Reference in new issue
Block a user