summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md11
-rw-r--r--src/abi.zig9
-rw-r--r--test/text.script4
-rw-r--r--test/text.zig3
-rw-r--r--vendor/fonts/JetBrainsMono-Bold.ttfbin0 -> 277828 bytes
-rw-r--r--vendor/fonts/JetBrainsMono-Italic.ttfbin0 -> 276840 bytes
-rw-r--r--vendor/fonts/JetBrainsMono-Regular.ttfbin0 -> 273900 bytes
-rw-r--r--vendor/fonts/LICENSE-JetBrainsMono93
-rw-r--r--vendor/fonts/README.md8
-rw-r--r--vendor/text.c15
-rw-r--r--vendor/text.h2
11 files changed, 134 insertions, 11 deletions
diff --git a/README.md b/README.md
index e4718af..01c86cb 100644
--- a/README.md
+++ b/README.md
@@ -113,10 +113,13 @@ character.
`f.textIn(face, x, y, scale, bytes, color)` is the same line in another
face of the Go family, all six bundled in the binary (`sk.Face`): `.mono`,
`.mono_bold`, `.mono_italic` for data and code, `.sans`, `.sans_medium`,
-`.sans_bold` for what is said about it; `f.host.textSizeIn(face, scale,
-bytes)` measures it. The three mono faces advance alike (0.6 em: whole
-pixels at 25, 30, 35, 45 and 60 px and at their doubles), so columns of
-text need no measuring. The web host draws every face as its one.
+`.sans_bold` for what is said about it; and `.code`, `.code_bold`,
+`.code_italic` are JetBrains Mono, bundled too, for programs.
+`f.host.textSizeIn(face, scale, bytes)` measures a line. The six
+monospaced faces advance alike (0.6 em: whole pixels at 20, 25, 30, 35, 45
+and 60 px and at their doubles), so columns of text need no measuring;
+JetBrains Mono's line box is taller (ascent 1.02 em, where Go's is 0.945).
+The web host draws every face as its one.
Text is shaped for the size it is drawn at, so under a camera that zooms
its letters would shift against each other from frame to frame.
diff --git a/src/abi.zig b/src/abi.zig
index cf7b838..0cce939 100644
--- a/src/abi.zig
+++ b/src/abi.zig
@@ -57,10 +57,11 @@ pub const Color = extern struct {
}
};
-/// The face a text is set in: the Go family, bundled with the native host.
-/// Mono is for data and code, sans for what is said about it. The web host
-/// has one face, the page's `monospace`.
-pub const Face = enum(u8) { mono, mono_bold, mono_italic, sans, sans_medium, sans_bold };
+/// The face a text is set in: the Go family, and JetBrains Mono (`code`)
+/// for programs, all bundled with the native host. Mono is for data, sans
+/// for what is said about it. The web host has one face, the page's
+/// `monospace`.
+pub const Face = enum(u8) { mono, mono_bold, mono_italic, sans, sans_medium, sans_bold, code, code_bold, code_italic };
/// How 2D drawing combines with what is already there (`Command.blend`).
/// Both are fixed-function on both hosts and match: `alpha` is source
diff --git a/test/text.script b/test/text.script
index c27df2a..82ce32c 100644
--- a/test/text.script
+++ b/test/text.script
@@ -15,3 +15,7 @@ expect-pixel .zig-cache/text/native.png 180 222 16 16 16 255
# of scale 3's 230), not the 120 that scale 1.5 would shape.
expect-pixel .zig-cache/text/native.png 123 265 32 64 96 255
expect-pixel .zig-cache/text/native.png 127 256 16 16 16 255
+# JetBrains Mono (`.code`) advances as the mono faces do: eleven characters
+# at scale 2 are 176 px, on its own taller line.
+expect-pixel .zig-cache/text/native.png 184 275 32 64 96 255
+expect-pixel .zig-cache/text/native.png 190 290 16 16 16 255
diff --git a/test/text.zig b/test/text.zig
index 74bbaed..1318d1f 100644
--- a/test/text.zig
+++ b/test/text.zig
@@ -16,6 +16,9 @@ const lines = [_]struct { scale: f32, text: []const u8, face: sk.Face = .mono, r
// Rasterized at 3 and drawn at 1.5: half of what scale 3 covers (115 px
// for ten digits), not what scale 1.5 would shape (120).
.{ .scale = 1.5, .text = "0123456789", .raster = 3 },
+ // JetBrains Mono, for code, advances as Go Mono does: ten columns
+ // at scale 2 are the 160 px of the bold line above.
+ .{ .scale = 2, .text = "rsp \u{2014}\u{25b8} 0x10", .face = .code },
};
pub fn draw(f: *sk.Frame) void {
diff --git a/vendor/fonts/JetBrainsMono-Bold.ttf b/vendor/fonts/JetBrainsMono-Bold.ttf
new file mode 100644
index 0000000..8c93043
--- /dev/null
+++ b/vendor/fonts/JetBrainsMono-Bold.ttf
Binary files differ
diff --git a/vendor/fonts/JetBrainsMono-Italic.ttf b/vendor/fonts/JetBrainsMono-Italic.ttf
new file mode 100644
index 0000000..ccc9d6a
--- /dev/null
+++ b/vendor/fonts/JetBrainsMono-Italic.ttf
Binary files differ
diff --git a/vendor/fonts/JetBrainsMono-Regular.ttf b/vendor/fonts/JetBrainsMono-Regular.ttf
new file mode 100644
index 0000000..dff66cc
--- /dev/null
+++ b/vendor/fonts/JetBrainsMono-Regular.ttf
Binary files differ
diff --git a/vendor/fonts/LICENSE-JetBrainsMono b/vendor/fonts/LICENSE-JetBrainsMono
new file mode 100644
index 0000000..8bee414
--- /dev/null
+++ b/vendor/fonts/LICENSE-JetBrainsMono
@@ -0,0 +1,93 @@
+Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono)
+
+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:
+https://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.
diff --git a/vendor/fonts/README.md b/vendor/fonts/README.md
index 3c49784..34b26a0 100644
--- a/vendor/fonts/README.md
+++ b/vendor/fonts/README.md
@@ -17,7 +17,13 @@ Five more faces of the same family are bundled the same way, for
Each is a font description of its own (`sk_text_draw_face`); the sans
faces fall back to installed sans families instead of mono ones.
-The font is embedded in the binary with C23 `#embed`. It is registered in a
+Three faces of **JetBrains Mono** follow them (`.code`, `.code_bold`,
+`.code_italic`): `JetBrainsMono-Regular.ttf`, `-Bold.ttf` and
+`-Italic.ttf` as the `ttf-jetbrains-mono` package installs them, under the
+SIL Open Font License in `LICENSE-JetBrainsMono`. They fall back as the
+mono faces do.
+
+The fonts are embedded in the binary with C23 `#embed`. It is registered in a
private Fontconfig config through a Linux memfd, so moving the executable does
not require a font installation or the source checkout. Installed outline fonts
provide Unicode fallback, in the order listed in `vendor/text.c`; actual glyph
diff --git a/vendor/text.c b/vendor/text.c
index c1548d6..f901f90 100644
--- a/vendor/text.c
+++ b/vendor/text.c
@@ -36,6 +36,16 @@ static const unsigned char go_medium[] = {
static const unsigned char go_bold[] = {
#embed "fonts/Go-Bold.ttf"
};
+/* JetBrains Mono, for code: the same 0.6 em advance as Go Mono. */
+static const unsigned char jb_mono[] = {
+#embed "fonts/JetBrainsMono-Regular.ttf"
+};
+static const unsigned char jb_mono_bold[] = {
+#embed "fonts/JetBrainsMono-Bold.ttf"
+};
+static const unsigned char jb_mono_italic[] = {
+#embed "fonts/JetBrainsMono-Italic.ttf"
+};
static const struct { const unsigned char *bytes; size_t len; const char *family, *style; } faces[SK_TEXT_FACES] = {
{go_mono, sizeof(go_mono), "Go Mono", ""},
{go_mono_bold, sizeof(go_mono_bold), "Go Mono", " Bold"},
@@ -43,6 +53,9 @@ static const struct { const unsigned char *bytes; size_t len; const char *family
{go_regular, sizeof(go_regular), "Go", ""},
{go_medium, sizeof(go_medium), "Go Medium", ""},
{go_bold, sizeof(go_bold), "Go", " Bold"},
+ {jb_mono, sizeof(jb_mono), "JetBrains Mono", ""},
+ {jb_mono_bold, sizeof(jb_mono_bold), "JetBrains Mono", " Bold"},
+ {jb_mono_italic, sizeof(jb_mono_italic), "JetBrains Mono", " Italic"},
};
typedef struct {
@@ -117,7 +130,7 @@ static TextCache *cache_for(SDL_Renderer *renderer) {
mono one. The sans faces fall back the same way after their own. */
const char *first = getenv("SKETCHBOOK_FONT");
for (int i = 0; i < SK_TEXT_FACES; ++i) {
- const bool mono = i <= SK_TEXT_MONO_ITALIC;
+ const bool mono = i <= SK_TEXT_MONO_ITALIC || i >= SK_TEXT_CODE;
char families[640];
snprintf(families, sizeof(families), "%s%s%s, %sNoto Sans Arabic, Noto Sans Hebrew, IBM Plex Sans JP, Noto Color Emoji, Noto Sans Symbols 2, DejaVu Sans, %s%s",
mono && first ? first : "", mono && first ? ", " : "", faces[i].family,
diff --git a/vendor/text.h b/vendor/text.h
index a421961..71cf0d1 100644
--- a/vendor/text.h
+++ b/vendor/text.h
@@ -11,7 +11,7 @@ bool sk_text_draw(SDL_Renderer *, float x, float y, float scale,
bool sk_text_measure(SDL_Renderer *, float scale, const char *utf8, size_t len,
float *width, float *height);
/* The same in another face of the bundled Go family (`abi.Face`'s order). */
-enum { SK_TEXT_MONO, SK_TEXT_MONO_BOLD, SK_TEXT_MONO_ITALIC, SK_TEXT_SANS, SK_TEXT_SANS_MEDIUM, SK_TEXT_SANS_BOLD, SK_TEXT_FACES };
+enum { SK_TEXT_MONO, SK_TEXT_MONO_BOLD, SK_TEXT_MONO_ITALIC, SK_TEXT_SANS, SK_TEXT_SANS_MEDIUM, SK_TEXT_SANS_BOLD, SK_TEXT_CODE, SK_TEXT_CODE_BOLD, SK_TEXT_CODE_ITALIC, SK_TEXT_FACES };
bool sk_text_draw_face(SDL_Renderer *, int face, float x, float y, float scale,
const char *utf8, size_t len, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
bool sk_text_measure_face(SDL_Renderer *, int face, float scale, const char *utf8, size_t len,