mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
fontconfig example
This commit is contained in:
@ -21,6 +21,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||||||
ftlib.link(exe);
|
ftlib.link(exe);
|
||||||
|
|
||||||
exe.linkSystemLibrary("epoxy");
|
exe.linkSystemLibrary("epoxy");
|
||||||
|
exe.linkSystemLibrary("fontconfig");
|
||||||
|
|
||||||
const run_cmd = exe.run();
|
const run_cmd = exe.run();
|
||||||
run_cmd.step.dependOn(b.getInstallStep());
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
, vttest
|
, vttest
|
||||||
, zig
|
, zig
|
||||||
|
|
||||||
|
, fontconfig
|
||||||
, libepoxy
|
, libepoxy
|
||||||
, libGL
|
, libGL
|
||||||
, libX11
|
, libX11
|
||||||
@ -32,6 +33,7 @@
|
|||||||
buildInputs = [
|
buildInputs = [
|
||||||
# TODO: non-linux
|
# TODO: non-linux
|
||||||
] ++ lib.optionals stdenv.isLinux [
|
] ++ lib.optionals stdenv.isLinux [
|
||||||
|
fontconfig
|
||||||
libepoxy
|
libepoxy
|
||||||
libGL
|
libGL
|
||||||
|
|
||||||
|
39
src/fonts.zig
Normal file
39
src/fonts.zig
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const fc = @cImport({
|
||||||
|
@cInclude("fontconfig/fontconfig.h");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set to true when FontConfig is initialized.
|
||||||
|
var initialized: bool = false;
|
||||||
|
|
||||||
|
pub fn list() !void {
|
||||||
|
if (!initialized) {
|
||||||
|
if (fc.FcInit() != fc.FcTrue) {
|
||||||
|
return error.InitializionFailed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const pat = fc.FcPatternCreate();
|
||||||
|
defer fc.FcPatternDestroy(pat);
|
||||||
|
|
||||||
|
const key = fc.FC_FULLNAME;
|
||||||
|
const os = fc.FcObjectSetBuild(
|
||||||
|
key,
|
||||||
|
@as([*c]const u8, 0), // @as required Zig #1481
|
||||||
|
);
|
||||||
|
defer fc.FcObjectSetDestroy(os);
|
||||||
|
|
||||||
|
const fs = fc.FcFontList(null, pat, os);
|
||||||
|
defer fc.FcFontSetDestroy(fs);
|
||||||
|
|
||||||
|
var i: usize = 0;
|
||||||
|
while (i <= fs.*.nfont) : (i += 1) {
|
||||||
|
const fpat = fs.*.fonts[i];
|
||||||
|
var str: [*c]fc.FcChar8 = undefined;
|
||||||
|
if (fc.FcPatternGetString(fpat, key, 0, &str) == fc.FcResultMatch) {
|
||||||
|
std.log.info("FONT: {s}", .{
|
||||||
|
@ptrCast([*:0]u8, str),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,8 +2,12 @@ const std = @import("std");
|
|||||||
const glfw = @import("glfw");
|
const glfw = @import("glfw");
|
||||||
const gl = @import("opengl.zig");
|
const gl = @import("opengl.zig");
|
||||||
const stb = @import("stb.zig");
|
const stb = @import("stb.zig");
|
||||||
|
const fonts = @import("fonts.zig");
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
// List our fonts
|
||||||
|
try fonts.list();
|
||||||
|
|
||||||
try glfw.init(.{});
|
try glfw.init(.{});
|
||||||
defer glfw.terminate();
|
defer glfw.terminate();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user