diff options
Diffstat (limited to 'src/host/gfx.zig')
| -rw-r--r-- | src/host/gfx.zig | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/host/gfx.zig b/src/host/gfx.zig index f84568a..d679067 100644 --- a/src/host/gfx.zig +++ b/src/host/gfx.zig @@ -613,15 +613,14 @@ fn fcolor(color: abi.Color) c.SDL_FColor { }; } -/// What `Command.text` covers at `scale`: the width of `bytes` and the -/// height of its line, in canvas units (`Host.textSize`, `textRun`). -pub fn textSize(scale: f32, bytes: []const u8, face: abi.Face) [2]f32 { - if (!(scale > 0) or !std.math.isFinite(scale)) return .{ 0, 0 }; - var advance: i32 = 0; +/// What `Command.text` gives `bytes` in `face` at `scale`, in canvas units: +/// `Host.VTable.textRun`. `xs` is empty, or a byte each. +pub fn textRun(face: abi.Face, scale: f32, bytes: []const u8, xs: []f32) abi.TextRun { + if (!(scale > 0) or !std.math.isFinite(scale) or (xs.len != 0 and xs.len != bytes.len)) return .{}; var ascent: i32 = 0; var height: i32 = 0; - _ = c.sk_text_shape(@backingInt(face), Glyphs.pixels(scale), bytes.ptr, bytes.len, null, 0, &advance, &ascent, &height); - return .{ @floatFromInt(advance), @floatFromInt(height) }; + const advance = c.sk_text_run(@backingInt(face), Glyphs.pixels(scale), bytes.ptr, bytes.len, if (xs.len == 0) null else xs.ptr, &ascent, &height); + return .{ .width = @floatFromInt(advance), .ascent = @floatFromInt(ascent), .height = @floatFromInt(height) }; } fn premultiply(color: abi.Color) abi.Color { |
