add default font / eliminate font-assets dependency
Our default font is a ~200K download which is not substantial enough to warrant the need for a seperate dependency/repository. Signed-off-by: Emi <emi@hexops.com>
This commit is contained in:
parent
8ef4227770
commit
ad5e8f98e0
7 changed files with 100 additions and 9 deletions
|
|
@ -136,8 +136,7 @@ pub fn build(b: *std.Build) !void {
|
||||||
module.addImport("mach-opus", dep.module("mach-opus"));
|
module.addImport("mach-opus", dep.module("mach-opus"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (b.lazyDependency("font_assets", .{})) |dep| module.addImport("font-assets", dep.module("font-assets"));
|
|
||||||
|
|
||||||
if (want_examples) {
|
if (want_examples) {
|
||||||
for (examples) |example| b.getInstallStep().dependOn(example.install_step);
|
for (examples) |example| b.getInstallStep().dependOn(example.install_step);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,6 @@
|
||||||
.hash = "1220adfccce3dbc4e4fa8650fdaec110a676f6b8a1462ed6ef422815207f8288e9d2",
|
.hash = "1220adfccce3dbc4e4fa8650fdaec110a676f6b8a1462ed6ef422815207f8288e9d2",
|
||||||
.lazy = true,
|
.lazy = true,
|
||||||
},
|
},
|
||||||
.font_assets = .{
|
|
||||||
.url = "https://github.com/hexops/font-assets/archive/b2336a29b1ae633d47452a2041b258e9538ef5f0.tar.gz",
|
|
||||||
.hash = "1220521ff5b01885da9b3cba75b607b315f60ae351594ee9e4a270b164374889fea0",
|
|
||||||
.lazy = true,
|
|
||||||
},
|
|
||||||
.mach_objc = .{
|
.mach_objc = .{
|
||||||
.url = "https://pkg.machengine.org/mach-objc/79b6f80c32b14948554958afe72dace261b14afc.tar.gz",
|
.url = "https://pkg.machengine.org/mach-objc/79b6f80c32b14948554958afe72dace261b14afc.tar.gz",
|
||||||
.hash = "12203675829014e69be2ea7c126ecf25d403009d336b7ca5f6e7c4ccede826c8e597",
|
.hash = "12203675829014e69be2ea7c126ecf25d403009d336b7ca5f6e7c4ccede826c8e597",
|
||||||
|
|
|
||||||
|
|
@ -500,7 +500,7 @@ fn updatePipelineBuffers(
|
||||||
// TODO(text): keep fonts around for reuse later
|
// TODO(text): keep fonts around for reuse later
|
||||||
// const font_name = text_style.get(style, .font_name).?;
|
// const font_name = text_style.get(style, .font_name).?;
|
||||||
// _ = font_name; // TODO(text): actually use font name
|
// _ = font_name; // TODO(text): actually use font name
|
||||||
const font_bytes = @import("font-assets").fira_sans_regular_ttf;
|
const font_bytes = gfx.default_font;
|
||||||
var font = if (text.font_once) |f| f else blk: {
|
var font = if (text.font_once) |f| f else blk: {
|
||||||
text.font_once = try gfx.Font.initBytes(font_bytes);
|
text.font_once = try gfx.Font.initBytes(font_bytes);
|
||||||
break :blk text.font_once.?;
|
break :blk text.font_once.?;
|
||||||
|
|
|
||||||
BIN
src/gfx/font/firasans/FiraSans-Regular.ttf
Normal file
BIN
src/gfx/font/firasans/FiraSans-Regular.ttf
Normal file
Binary file not shown.
93
src/gfx/font/firasans/LICENSE
Normal file
93
src/gfx/font/firasans/LICENSE
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
Copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A.
|
||||||
|
|
||||||
|
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||||
|
This license is copied below, and is also available with a FAQ at:
|
||||||
|
http://scripts.sil.org/OFL
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
PREAMBLE
|
||||||
|
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||||
|
development of collaborative font projects, to support the font creation
|
||||||
|
efforts of academic and linguistic communities, and to provide a free and
|
||||||
|
open framework in which fonts may be shared and improved in partnership
|
||||||
|
with others.
|
||||||
|
|
||||||
|
The OFL allows the licensed fonts to be used, studied, modified and
|
||||||
|
redistributed freely as long as they are not sold by themselves. The
|
||||||
|
fonts, including any derivative works, can be bundled, embedded,
|
||||||
|
redistributed and/or sold with any software provided that any reserved
|
||||||
|
names are not used by derivative works. The fonts and derivatives,
|
||||||
|
however, cannot be released under any other type of license. The
|
||||||
|
requirement for fonts to remain under this license does not apply
|
||||||
|
to any document created using the fonts or their derivatives.
|
||||||
|
|
||||||
|
DEFINITIONS
|
||||||
|
"Font Software" refers to the set of files released by the Copyright
|
||||||
|
Holder(s) under this license and clearly marked as such. This may
|
||||||
|
include source files, build scripts and documentation.
|
||||||
|
|
||||||
|
"Reserved Font Name" refers to any names specified as such after the
|
||||||
|
copyright statement(s).
|
||||||
|
|
||||||
|
"Original Version" refers to the collection of Font Software components as
|
||||||
|
distributed by the Copyright Holder(s).
|
||||||
|
|
||||||
|
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||||
|
or substituting -- in part or in whole -- any of the components of the
|
||||||
|
Original Version, by changing formats or by porting the Font Software to a
|
||||||
|
new environment.
|
||||||
|
|
||||||
|
"Author" refers to any designer, engineer, programmer, technical
|
||||||
|
writer or other person who contributed to the Font Software.
|
||||||
|
|
||||||
|
PERMISSION & CONDITIONS
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||||
|
redistribute, and sell modified and unmodified copies of the Font
|
||||||
|
Software, subject to the following conditions:
|
||||||
|
|
||||||
|
1) Neither the Font Software nor any of its individual components,
|
||||||
|
in Original or Modified Versions, may be sold by itself.
|
||||||
|
|
||||||
|
2) Original or Modified Versions of the Font Software may be bundled,
|
||||||
|
redistributed and/or sold with any software, provided that each copy
|
||||||
|
contains the above copyright notice and this license. These can be
|
||||||
|
included either as stand-alone text files, human-readable headers or
|
||||||
|
in the appropriate machine-readable metadata fields within text or
|
||||||
|
binary files as long as those fields can be easily viewed by the user.
|
||||||
|
|
||||||
|
3) No Modified Version of the Font Software may use the Reserved Font
|
||||||
|
Name(s) unless explicit written permission is granted by the corresponding
|
||||||
|
Copyright Holder. This restriction only applies to the primary font name as
|
||||||
|
presented to the users.
|
||||||
|
|
||||||
|
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||||
|
Software shall not be used to promote, endorse or advertise any
|
||||||
|
Modified Version, except to acknowledge the contribution(s) of the
|
||||||
|
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
5) The Font Software, modified or unmodified, in part or in whole,
|
||||||
|
must be distributed entirely under this license, and must not be
|
||||||
|
distributed under any other license. The requirement for fonts to
|
||||||
|
remain under this license does not apply to any document created
|
||||||
|
using the Font Software.
|
||||||
|
|
||||||
|
TERMINATION
|
||||||
|
This license becomes null and void if any of the above conditions are
|
||||||
|
not met.
|
||||||
|
|
||||||
|
DISCLAIMER
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||||
|
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||||
|
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||||
|
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||||
|
|
@ -79,12 +79,15 @@ pub const RenderedGlyph = struct {
|
||||||
height: u32,
|
height: u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// The default font used by Mach. currently Fira Sans Regular, but may change in the future.
|
||||||
|
pub const default_font = @embedFile("firasans/FiraSans-Regular.ttf");
|
||||||
|
|
||||||
test {
|
test {
|
||||||
std.testing.refAllDeclsRecursive(@This());
|
std.testing.refAllDeclsRecursive(@This());
|
||||||
|
|
||||||
// Load a font
|
// Load a font
|
||||||
const allocator = std.testing.allocator;
|
const allocator = std.testing.allocator;
|
||||||
const font_bytes = @import("font-assets").fira_sans_regular_ttf;
|
const font_bytes = default_font;
|
||||||
var font = try Font.initBytes(font_bytes);
|
var font = try Font.initBytes(font_bytes);
|
||||||
defer font.deinit(allocator);
|
defer font.deinit(allocator);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ pub const modules = .{ Sprite, Text };
|
||||||
|
|
||||||
// Fonts
|
// Fonts
|
||||||
pub const Font = @import("font/main.zig").Font;
|
pub const Font = @import("font/main.zig").Font;
|
||||||
|
pub const default_font = @import("font/main.zig").default_font;
|
||||||
pub const TextRun = @import("font/main.zig").TextRun;
|
pub const TextRun = @import("font/main.zig").TextRun;
|
||||||
pub const Glyph = @import("font/main.zig").Glyph;
|
pub const Glyph = @import("font/main.zig").Glyph;
|
||||||
pub const px_per_pt = @import("font/main.zig").px_per_pt;
|
pub const px_per_pt = @import("font/main.zig").px_per_pt;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue