mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
font: mostly empty web canvas sprite renderer, but compiles
This commit is contained in:
@ -272,8 +272,6 @@ pub fn renderGlyph(
|
|||||||
max_height: ?u16,
|
max_height: ?u16,
|
||||||
) !Glyph {
|
) !Glyph {
|
||||||
// Special-case fonts are rendered directly.
|
// Special-case fonts are rendered directly.
|
||||||
// TODO: web_canvas
|
|
||||||
if (options.backend != .web_canvas) {
|
|
||||||
if (index.special()) |sp| switch (sp) {
|
if (index.special()) |sp| switch (sp) {
|
||||||
.sprite => return try self.sprite.?.renderGlyph(
|
.sprite => return try self.sprite.?.renderGlyph(
|
||||||
alloc,
|
alloc,
|
||||||
@ -281,7 +279,6 @@ pub fn renderGlyph(
|
|||||||
glyph_index,
|
glyph_index,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const face = &self.faces.get(index.style).items[@intCast(usize, index.idx)];
|
const face = &self.faces.get(index.style).items[@intCast(usize, index.idx)];
|
||||||
try face.load(self.lib, self.size);
|
try face.load(self.lib, self.size);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
const js = @import("zig-js");
|
||||||
const pixman = @import("pixman");
|
const pixman = @import("pixman");
|
||||||
const font = @import("../main.zig");
|
const font = @import("../main.zig");
|
||||||
|
|
||||||
@ -91,7 +92,70 @@ pub const Canvas = switch (font.options.backend) {
|
|||||||
else => PixmanImpl,
|
else => PixmanImpl,
|
||||||
};
|
};
|
||||||
|
|
||||||
const WebCanvasImpl = struct {};
|
const WebCanvasImpl = struct {
|
||||||
|
/// The canvas element that is our final image.
|
||||||
|
canvas: js.Object,
|
||||||
|
|
||||||
|
pub fn init(alloc: Allocator, width: u32, height: u32) !WebCanvasImpl {
|
||||||
|
_ = alloc;
|
||||||
|
|
||||||
|
// Create our canvas that we're going to continue to reuse.
|
||||||
|
const doc = try js.global.get(js.Object, "document");
|
||||||
|
defer doc.deinit();
|
||||||
|
const canvas = try doc.call(js.Object, "createElement", .{js.string("canvas")});
|
||||||
|
errdefer canvas.deinit();
|
||||||
|
|
||||||
|
// Set our dimensions.
|
||||||
|
try canvas.set("width", width);
|
||||||
|
try canvas.set("height", height);
|
||||||
|
|
||||||
|
return WebCanvasImpl{
|
||||||
|
.canvas = canvas,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: *WebCanvasImpl, alloc: Allocator) void {
|
||||||
|
_ = alloc;
|
||||||
|
self.canvas.deinit();
|
||||||
|
self.* = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn rect(self: *WebCanvasImpl, v: Rect, color: Color) void {
|
||||||
|
_ = self;
|
||||||
|
_ = v;
|
||||||
|
_ = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn trapezoid(self: *WebCanvasImpl, t: Trapezoid) void {
|
||||||
|
_ = self;
|
||||||
|
_ = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn triangle(self: *WebCanvasImpl, t: Triangle, color: Color) void {
|
||||||
|
_ = self;
|
||||||
|
_ = t;
|
||||||
|
_ = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn composite(
|
||||||
|
self: *WebCanvasImpl,
|
||||||
|
op: CompositionOp,
|
||||||
|
src: *const WebCanvasImpl,
|
||||||
|
dest: Rect,
|
||||||
|
) void {
|
||||||
|
_ = self;
|
||||||
|
_ = op;
|
||||||
|
_ = src;
|
||||||
|
_ = dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn writeAtlas(self: *WebCanvasImpl, alloc: Allocator, atlas: *font.Atlas) !font.Atlas.Region {
|
||||||
|
_ = self;
|
||||||
|
_ = alloc;
|
||||||
|
_ = atlas;
|
||||||
|
return error.Unimplemented;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const PixmanImpl = struct {
|
const PixmanImpl = struct {
|
||||||
/// The underlying image.
|
/// The underlying image.
|
||||||
|
Reference in New Issue
Block a user