all: move standalone libraries to libs/ subdirectory
The root dir of our repository has grown quite a lot the past few months.
I'd like to make it more clear where the bulk of the engine lives (`src/`) and
also make it more clear which Mach libraries are consumable as standalone projects.
As for the name of this directory, `libs` was my first choice but there's a bit of
a convention of that being external libraries in Zig projects _today_, while these
are libraries maintained as part of Mach in this repository - not external ones.
We will name this directory `libs`, and if we have a need for external libraries
we will use `external` or `deps` for that directory name. I considered other names
such as `components`, `systems`, `modules` (which are bad as they overlap with
major ECS / engine concepts), and it seems likely the official Zig package manager
will break the convention of using a `libs` dir anyway.
Performed via:
```sh
mkdir libs/
git mv freetype libs/
git mv basisu libs/
git mv gamemode libs/
git mv glfw libs/
git mv gpu libs/
git mv gpu-dawn libs/
git mv sysaudio libs/
git mv sysjs libs/
git mv ecs libs/
```
git-subtree-dir: glfw
git-subtree-mainline: 0d5b853443
git-subtree-split: 572d1144f11b353abdb64fff828b25a4f0fbb7ca
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
git mv ecs libs/
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
79ec61396f
commit
0645429df9
240 changed files with 6 additions and 6 deletions
128
libs/freetype/examples/glyph-to-svg.zig
Normal file
128
libs/freetype/examples/glyph-to-svg.zig
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
const std = @import("std");
|
||||
const freetype = @import("freetype");
|
||||
|
||||
// Remove once the stage2 compiler fixes pkg std not found
|
||||
comptime {
|
||||
_ = @import("utils");
|
||||
}
|
||||
|
||||
const OutlinePrinter = struct {
|
||||
library: freetype.Library,
|
||||
face: freetype.Face,
|
||||
output_file: std.fs.File,
|
||||
path_stream: std.io.FixedBufferStream([]u8),
|
||||
|
||||
xMin: isize,
|
||||
yMin: isize,
|
||||
width: isize,
|
||||
height: isize,
|
||||
|
||||
const Self = @This();
|
||||
|
||||
var buf = [_]u8{0} ** (1024 * 10);
|
||||
pub fn init(file: std.fs.File) freetype.Error!Self {
|
||||
var lib = try freetype.Library.init();
|
||||
return Self{
|
||||
.library = lib,
|
||||
.face = try lib.createFace("upstream/assets/FiraSans-Regular.ttf", 0),
|
||||
.output_file = file,
|
||||
.path_stream = std.io.fixedBufferStream(&buf),
|
||||
.xMin = 0,
|
||||
.yMin = 0,
|
||||
.width = 0,
|
||||
.height = 0,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: Self) void {
|
||||
self.library.deinit();
|
||||
}
|
||||
|
||||
pub fn outlineExists(self: Self) bool {
|
||||
const outline = self.face.glyph().outline() orelse return false;
|
||||
if (outline.numContours() <= 0 or outline.numPoints() <= 0)
|
||||
return false;
|
||||
outline.check() catch return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn flipOutline(self: Self) void {
|
||||
const multiplier = 65536;
|
||||
const matrix = freetype.Matrix{
|
||||
.xx = 1 * multiplier,
|
||||
.xy = 0 * multiplier,
|
||||
.yx = 0 * multiplier,
|
||||
.yy = -1 * multiplier,
|
||||
};
|
||||
self.face.glyph().outline().?.transform(matrix);
|
||||
}
|
||||
|
||||
pub fn extractOutline(self: *Self) !void {
|
||||
try self.path_stream.writer().writeAll("<path d='");
|
||||
var callbacks = freetype.Outline.Funcs(*Self){
|
||||
.move_to = moveToFunction,
|
||||
.line_to = lineToFunction,
|
||||
.conic_to = conicToFunction,
|
||||
.cubic_to = cubicToFunction,
|
||||
.shift = 0,
|
||||
.delta = 0,
|
||||
};
|
||||
try self.face.glyph().outline().?.decompose(self, callbacks);
|
||||
try self.path_stream.writer().writeAll("' fill='#000'/>");
|
||||
}
|
||||
|
||||
pub fn computeViewBox(self: *Self) !void {
|
||||
const boundingBox = try self.face.glyph().outline().?.bbox();
|
||||
self.xMin = boundingBox.xMin;
|
||||
self.yMin = boundingBox.yMin;
|
||||
self.width = boundingBox.xMax - boundingBox.xMin;
|
||||
self.height = boundingBox.yMax - boundingBox.yMin;
|
||||
}
|
||||
|
||||
pub fn printSVG(self: Self) !void {
|
||||
try self.output_file.writer().print(
|
||||
\\<svg xmlns='http://www.w3.org/2000/svg'
|
||||
\\ xmlns:xlink='http://www.w3.org/1999/xlink'
|
||||
\\ viewBox='{d} {d} {d} {d}'>
|
||||
\\ {s}
|
||||
\\</svg>
|
||||
, .{ self.xMin, self.yMin, self.width, self.height, self.path_stream.getWritten() });
|
||||
}
|
||||
|
||||
pub fn moveToFunction(self: *Self, to: freetype.Vector) freetype.Error!void {
|
||||
self.path_stream.writer().print("M {d} {d}\t", .{ to.x, to.y }) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn lineToFunction(self: *Self, to: freetype.Vector) freetype.Error!void {
|
||||
self.path_stream.writer().print("L {d} {d}\t", .{ to.x, to.y }) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn conicToFunction(self: *Self, control: freetype.Vector, to: freetype.Vector) freetype.Error!void {
|
||||
self.path_stream.writer().print("Q {d} {d}, {d} {d}\t", .{ control.x, control.y, to.x, to.y }) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn cubicToFunction(self: *Self, control_0: freetype.Vector, control_1: freetype.Vector, to: freetype.Vector) freetype.Error!void {
|
||||
self.path_stream.writer().print("C {d} {d}, {d} {d}, {d} {d}\t", .{ control_0.x, control_0.y, control_1.x, control_1.y, to.x, to.y }) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn run(self: *Self, symbol: u32) !void {
|
||||
try self.face.loadChar(symbol, .{ .no_scale = true, .no_bitmap = true });
|
||||
|
||||
if (!self.outlineExists())
|
||||
return error.OutlineDoesntExists;
|
||||
|
||||
self.flipOutline();
|
||||
try self.extractOutline();
|
||||
try self.computeViewBox();
|
||||
try self.printSVG();
|
||||
}
|
||||
};
|
||||
|
||||
pub fn main() !void {
|
||||
var file = try std.fs.cwd().createFile("out.svg", .{});
|
||||
defer file.close();
|
||||
|
||||
var outline_printer = try OutlinePrinter.init(file);
|
||||
defer outline_printer.deinit();
|
||||
try outline_printer.run(@as(u32, 'ë'));
|
||||
}
|
||||
38
libs/freetype/examples/single-glyph.zig
Normal file
38
libs/freetype/examples/single-glyph.zig
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// zig build run-example-single-glyph -- B
|
||||
const std = @import("std");
|
||||
const freetype = @import("freetype");
|
||||
|
||||
// Remove once the stage2 compiler fixes pkg std not found
|
||||
comptime {
|
||||
_ = @import("utils");
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
defer _ = gpa.deinit();
|
||||
const allocator = gpa.allocator();
|
||||
var args = try std.process.argsAlloc(allocator);
|
||||
defer std.process.argsFree(allocator, args);
|
||||
|
||||
const lib = try freetype.Library.init();
|
||||
defer lib.deinit();
|
||||
|
||||
const face = try lib.createFace("upstream/assets/FiraSans-Regular.ttf", 0);
|
||||
try face.setCharSize(60 * 48, 0, 50, 0);
|
||||
try face.loadChar(args[1][0], .{ .render = true });
|
||||
const bitmap = face.glyph().bitmap();
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < bitmap.rows()) : (i += 1) {
|
||||
var j: usize = 0;
|
||||
while (j < bitmap.width()) : (j += 1) {
|
||||
const char: u8 = switch (bitmap.buffer().?[i * bitmap.width() + j]) {
|
||||
0 => ' ',
|
||||
1...128 => ';',
|
||||
else => '#',
|
||||
};
|
||||
std.debug.print("{c}", .{char});
|
||||
}
|
||||
std.debug.print("\n", .{});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue