From ae80164f4edc569dcd1acc5a843865f352d5c965 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Mon, 17 Mar 2025 21:48:47 -0600 Subject: [PATCH] use CellType to render text --- build.zig | 4 ++++ build.zig.zon | 7 ++++++- examples/fontviewer.zig | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 1534132..6b322b9 100644 --- a/build.zig +++ b/build.zig @@ -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| { @@ -32,6 +35,7 @@ pub fn build(b: *std.Build) void { .target = target, .imports = &.{ .{ .name = "x", .module = x_mod }, + .{ .name = "celltype", .module = celltype_mod }, }, }); diff --git a/build.zig.zon b/build.zig.zon index de1d3ed..ac63ce6 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -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 = .{"."}, } diff --git a/examples/fontviewer.zig b/examples/fontviewer.zig index 3a8fc3a..40e73c4 100644 --- a/examples/fontviewer.zig +++ b/examples/fontviewer.zig @@ -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; @@ -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, @@ -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 });