Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub fn build(b: *std.Build) void {
.root_source_file = b.path("src/x.zig"),
});

const celltype_dep = b.dependency("celltype", .{});
const celltype_mod = celltype_dep.module("celltype");

const examples_step = b.step("examples", "");

inline for (examples) |example_name| {
Expand All @@ -32,6 +35,7 @@ pub fn build(b: *std.Build) void {
.target = target,
.imports = &.{
.{ .name = "x", .module = x_mod },
.{ .name = "celltype", .module = celltype_mod },
},
});

Expand Down
7 changes: 6 additions & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
.version = "0.0.0",
.fingerprint = 0x8cdc16832b06463e,
.minimum_zig_version = "0.14.0",
.dependencies = .{},
.dependencies = .{
.celltype = .{
.url = "git+https://github.com/marler8997/CellType#8836a2e3d793bb8062890af071845b41c5b3f26b",
.hash = "celltype-0.0.0-hmHVU4JgAgC--FJ5ibbZKcHJBTERK0Y5gwh_ySRHZQV5",
},
},
.paths = .{"."},
}
23 changes: 23 additions & 0 deletions examples/fontviewer.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const std = @import("std");
const x = @import("x");
const common = @import("common.zig");
const celltype = @import("celltype");

pub const log_level = std.log.Level.info;

Expand Down Expand Up @@ -392,6 +393,7 @@ fn render(
sock: std.posix.socket_t,
sequence: *u16,
ids: Ids,
image_format: ImageFormat,
fonts: []x.Slice(u8, [*]const u8),
font_index: usize,
font_info: *const x.ServerMsg.QueryFont,
Expand Down Expand Up @@ -420,6 +422,27 @@ fn render(

const font_height = font_info.font_ascent + font_info.font_descent;

{
const width = 15;
const height = width * 2;
var grayscale: [width * height]u8 = undefined;
const config = celltype.Config{};
const len = celltype.renderText(
&config,
u16,
width,
height,
celltype.calcStrokeWidth(u16, width, height, celltype.default_weight),
&grayscale,
width,
.{ .output_precleared = false },
"A",
) catch |err| switch (err) {
error.Utf8Decode => unreachable,
};
std.debug.assert(len == 1);
}

try renderText(sock, sequence, ids.window(), ids.gcText(), 10, 10 + (font_height * 1), "font {}/{}", .{ font_index + 1, fonts.len });
try renderText(sock, sequence, ids.window(), ids.gcText(), 10, 10 + (font_height * 2), "{s}", .{font_name});
try renderText(sock, sequence, ids.window(), ids.gcText(), 10, 10 + (font_height * 3), "property_count={} char_info_count={}", .{ font_info.property_count, font_info.info_count });
Expand Down