mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 09:16:11 +03:00
font: Box font uses canvas abstraction
This commit is contained in:
@ -2167,8 +2167,9 @@ fn draw_light_arc(
|
|||||||
const width = self.width * supersample;
|
const width = self.width * supersample;
|
||||||
|
|
||||||
// Allocate our supersample sized canvas
|
// Allocate our supersample sized canvas
|
||||||
var supercanvas = try font.sprite.Canvas.init(alloc, width, height);
|
var ss_data = try alloc.alloc(u8, height * width);
|
||||||
defer supercanvas.deinit(alloc);
|
defer alloc.free(ss_data);
|
||||||
|
std.mem.set(u8, ss_data, 0);
|
||||||
|
|
||||||
const height_pixels = self.height;
|
const height_pixels = self.height;
|
||||||
const width_pixels = self.width;
|
const width_pixels = self.width;
|
||||||
@ -2357,49 +2358,42 @@ fn draw_light_arc(
|
|||||||
if (dist > @intToFloat(f64, thick) / 2) continue;
|
if (dist > @intToFloat(f64, thick) / 2) continue;
|
||||||
|
|
||||||
// Set our pixel
|
// Set our pixel
|
||||||
supercanvas.rect(.{ .x = c, .y = r, .width = 1, .height = 1 }, .on);
|
const idx = @intCast(usize, r * @intCast(i32, width) + c);
|
||||||
|
ss_data[idx] = 0xFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Downsample
|
// Downsample
|
||||||
// {
|
{
|
||||||
// var ss_data = try supercanvas.getData(alloc);
|
var r: u32 = 0;
|
||||||
// defer alloc.free(ss_data);
|
while (r < self.height) : (r += 1) {
|
||||||
//
|
var c: u32 = 0;
|
||||||
// var r: u32 = 0;
|
while (c < self.width) : (c += 1) {
|
||||||
// while (r < self.height) : (r += 1) {
|
var total: u32 = 0;
|
||||||
// var c: u32 = 0;
|
var i: usize = 0;
|
||||||
// while (c < self.width) : (c += 1) {
|
while (i < supersample) : (i += 1) {
|
||||||
// var total: u32 = 0;
|
var j: usize = 0;
|
||||||
// var i: usize = 0;
|
while (j < supersample) : (j += 1) {
|
||||||
// while (i < supersample) : (i += 1) {
|
const idx = (r * supersample + i) * width + (c * supersample + j);
|
||||||
// var j: usize = 0;
|
total += ss_data[idx];
|
||||||
// while (j < supersample) : (j += 1) {
|
}
|
||||||
// const idx = (r * supersample + i) * (c * supersample) + (c * supersample + j);
|
}
|
||||||
// total += ss_data[idx];
|
|
||||||
// // const idx = (r * supersample + i) * @intCast(usize, stride) + c * supersample + j;
|
const average = @intCast(u8, @min(total / (supersample * supersample), 0xff));
|
||||||
// //total += data[idx];
|
canvas.rect(
|
||||||
// }
|
.{
|
||||||
// }
|
.x = @intCast(i32, c),
|
||||||
//
|
.y = @intCast(i32, r),
|
||||||
// const average = @intCast(u8, @min(total / (supersample * supersample), 0xff));
|
.width = 1,
|
||||||
// canvas.rect(
|
.height = 1,
|
||||||
// .{
|
},
|
||||||
// .x = @intCast(i32, c),
|
@intToEnum(font.sprite.Color, average),
|
||||||
// .y = @intCast(i32, r),
|
);
|
||||||
// .width = 1,
|
}
|
||||||
// .height = 1,
|
}
|
||||||
// },
|
}
|
||||||
// @intToEnum(font.sprite.Color, average),
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// // const idx = r * @intCast(usize, real_stride) + c;
|
|
||||||
// // real_data[idx] = average;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// draw vertical/horizontal lines from quartercircle-edge to box-edge.
|
// draw vertical/horizontal lines from quartercircle-edge to box-edge.
|
||||||
self.vline(canvas, @min(c_y_pixels, vert_to), @max(c_y_pixels, vert_to), (width_pixels - thick_pixels) / 2, thick_pixels);
|
self.vline(canvas, @min(c_y_pixels, vert_to), @max(c_y_pixels, vert_to), (width_pixels - thick_pixels) / 2, thick_pixels);
|
||||||
|
@ -262,25 +262,25 @@ const PixmanImpl = struct {
|
|||||||
pub fn getData(self: *const Canvas, alloc: Allocator) ![]u8 {
|
pub fn getData(self: *const Canvas, alloc: Allocator) ![]u8 {
|
||||||
const width = @intCast(u32, self.image.getWidth());
|
const width = @intCast(u32, self.image.getWidth());
|
||||||
const height = @intCast(u32, self.image.getHeight());
|
const height = @intCast(u32, self.image.getHeight());
|
||||||
|
const stride = self.image.getStride();
|
||||||
|
|
||||||
var result = try alloc.alloc(u8, height * width);
|
var result = try alloc.alloc(u8, height * width);
|
||||||
errdefer alloc.free(result);
|
errdefer alloc.free(result);
|
||||||
|
|
||||||
// We want to convert our []u32 to []u8 since we use an 8bpp format
|
// We want to convert our []u32 to []u8 since we use an 8bpp format
|
||||||
var data_u32 = self.image.getData();
|
const data = @alignCast(
|
||||||
const len_u8 = data_u32.len * 4;
|
@alignOf(u8),
|
||||||
var real_data = @alignCast(@alignOf(u8), @ptrCast([*]u8, data_u32.ptr)[0..len_u8]);
|
@ptrCast([*]u8, self.data.ptr)[0 .. self.data.len * 4],
|
||||||
const real_stride = self.image.getStride();
|
);
|
||||||
|
|
||||||
// Convert our strided data
|
// Convert our strided data
|
||||||
var r: u32 = 0;
|
var dst_ptr = result;
|
||||||
while (r < height) : (r += 1) {
|
var src_ptr = data.ptr;
|
||||||
var c: u32 = 0;
|
var i: usize = 0;
|
||||||
while (c < width) : (c += 1) {
|
while (i < height) : (i += 1) {
|
||||||
const src = r * @intCast(usize, real_stride) + c;
|
std.mem.copy(u8, dst_ptr, src_ptr[0..width]);
|
||||||
const dst = (r * c) + c;
|
dst_ptr = dst_ptr[width..];
|
||||||
result[dst] = real_data[src];
|
src_ptr += @intCast(usize, stride);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user