This commit is contained in:
Mitchell Hashimoto
2022-11-25 14:41:17 -08:00
parent 781571d7fb
commit 7676c1c52b
3 changed files with 174 additions and 0 deletions

67
conformance/blocks.zig Normal file
View File

@ -0,0 +1,67 @@
//! Delete Line (DL) - Esc [ M
const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
// Box Drawing
{
try stdout.print("\x1b[4mBox Drawing\x1b[0m\n", .{});
var i: usize = 0x2500;
var step: usize = 32;
while (i <= 0x257F) : (i += step) {
var j: usize = 0;
while (j < step) : (j += 1) {
try stdout.print("{u} ", .{@intCast(u21, i + j)});
}
try stdout.print("\n\n", .{});
}
}
// Block Elements
{
try stdout.print("\x1b[4mBlock Elements\x1b[0m\n", .{});
var i: usize = 0x2580;
var step: usize = 32;
while (i <= 0x259f) : (i += step) {
var j: usize = 0;
while (j < step) : (j += 1) {
try stdout.print("{u} ", .{@intCast(u21, i + j)});
}
try stdout.print("\n\n", .{});
}
}
// Braille Elements
{
try stdout.print("\x1b[4mBraille\x1b[0m\n", .{});
var i: usize = 0x2800;
var step: usize = 32;
while (i <= 0x28FF) : (i += step) {
var j: usize = 0;
while (j < step) : (j += 1) {
try stdout.print("{u} ", .{@intCast(u21, i + j)});
}
try stdout.print("\n\n", .{});
}
}
{
try stdout.print("\x1b[4mSextants\x1b[0m\n", .{});
var i: usize = 0x1FB00;
var step: usize = 32;
const end = 0x1FB3B;
while (i <= end) : (i += step) {
var j: usize = 0;
while (j < step) : (j += 1) {
const v = i + j;
if (v <= end) try stdout.print("{u} ", .{@intCast(u21, v)});
}
try stdout.print("\n\n", .{});
}
}
}

View File

@ -300,6 +300,8 @@ fn draw(self: BoxFont, alloc: Allocator, img: *pixman.Image, cp: u32) !void {
0x2800...0x28FF => self.draw_braille(img, cp),
0x1FB00...0x1FB3B => self.draw_sextant(img, cp),
else => return error.InvalidCodepoint,
}
}
@ -1574,6 +1576,108 @@ fn draw_braille(self: BoxFont, img: *pixman.Image, cp: u32) void {
self.rect(img, x[1], y[3], x[1] + w, y[3] + w);
}
fn draw_sextant(self: BoxFont, img: *pixman.Image, cp: u32) void {
const UPPER_LEFT: u8 = 1 << 0;
const MIDDLE_LEFT: u8 = 1 << 1;
const LOWER_LEFT: u8 = 1 << 2;
const UPPER_RIGHT: u8 = 1 << 3;
const MIDDLE_RIGHT: u8 = 1 << 4;
const LOWER_RIGHT: u8 = 1 << 5;
const matrix: [60]u8 = .{
// U+1fb00 - U+1fb0f
UPPER_LEFT,
UPPER_RIGHT,
UPPER_LEFT | UPPER_RIGHT,
MIDDLE_LEFT,
UPPER_LEFT | MIDDLE_LEFT,
UPPER_RIGHT | MIDDLE_LEFT,
UPPER_LEFT | UPPER_RIGHT | MIDDLE_LEFT,
MIDDLE_RIGHT,
UPPER_LEFT | MIDDLE_RIGHT,
UPPER_RIGHT | MIDDLE_RIGHT,
UPPER_LEFT | UPPER_RIGHT | MIDDLE_RIGHT,
MIDDLE_LEFT | MIDDLE_RIGHT,
UPPER_LEFT | MIDDLE_LEFT | MIDDLE_RIGHT,
UPPER_RIGHT | MIDDLE_LEFT | MIDDLE_RIGHT,
UPPER_LEFT | UPPER_RIGHT | MIDDLE_LEFT | MIDDLE_RIGHT,
LOWER_LEFT,
// U+1fb10 - U+1fb1f
UPPER_LEFT | LOWER_LEFT,
UPPER_RIGHT | LOWER_LEFT,
UPPER_LEFT | UPPER_RIGHT | LOWER_LEFT,
MIDDLE_LEFT | LOWER_LEFT,
UPPER_RIGHT | MIDDLE_LEFT | LOWER_LEFT,
UPPER_LEFT | UPPER_RIGHT | MIDDLE_LEFT | LOWER_LEFT,
MIDDLE_RIGHT | LOWER_LEFT,
UPPER_LEFT | MIDDLE_RIGHT | LOWER_LEFT,
UPPER_RIGHT | MIDDLE_RIGHT | LOWER_LEFT,
UPPER_LEFT | UPPER_RIGHT | MIDDLE_RIGHT | LOWER_LEFT,
MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_LEFT,
UPPER_LEFT | MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_LEFT,
UPPER_RIGHT | MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_LEFT,
UPPER_LEFT | UPPER_RIGHT | MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_LEFT,
LOWER_RIGHT,
UPPER_LEFT | LOWER_RIGHT,
// U+1fb20 - U+1fb2f
UPPER_RIGHT | LOWER_RIGHT,
UPPER_LEFT | UPPER_RIGHT | LOWER_RIGHT,
MIDDLE_LEFT | LOWER_RIGHT,
UPPER_LEFT | MIDDLE_LEFT | LOWER_RIGHT,
UPPER_RIGHT | MIDDLE_LEFT | LOWER_RIGHT,
UPPER_LEFT | UPPER_RIGHT | MIDDLE_LEFT | LOWER_RIGHT,
MIDDLE_RIGHT | LOWER_RIGHT,
UPPER_LEFT | MIDDLE_RIGHT | LOWER_RIGHT,
UPPER_LEFT | UPPER_RIGHT | MIDDLE_RIGHT | LOWER_RIGHT,
MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_RIGHT,
UPPER_LEFT | MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_RIGHT,
UPPER_RIGHT | MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_RIGHT,
UPPER_LEFT | UPPER_RIGHT | MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_RIGHT,
LOWER_LEFT | LOWER_RIGHT,
UPPER_LEFT | LOWER_LEFT | LOWER_RIGHT,
UPPER_RIGHT | LOWER_LEFT | LOWER_RIGHT,
// U+1fb30 - U+1fb3b
UPPER_LEFT | UPPER_RIGHT | LOWER_LEFT | LOWER_RIGHT,
MIDDLE_LEFT | LOWER_LEFT | LOWER_RIGHT,
UPPER_LEFT | MIDDLE_LEFT | LOWER_LEFT | LOWER_RIGHT,
UPPER_RIGHT | MIDDLE_LEFT | LOWER_LEFT | LOWER_RIGHT,
UPPER_LEFT | UPPER_RIGHT | MIDDLE_LEFT | LOWER_LEFT | LOWER_RIGHT,
MIDDLE_RIGHT | LOWER_LEFT | LOWER_RIGHT,
UPPER_LEFT | MIDDLE_RIGHT | LOWER_LEFT | LOWER_RIGHT,
UPPER_RIGHT | MIDDLE_RIGHT | LOWER_LEFT | LOWER_RIGHT,
UPPER_LEFT | UPPER_RIGHT | MIDDLE_RIGHT | LOWER_LEFT | LOWER_RIGHT,
MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_LEFT | LOWER_RIGHT,
UPPER_LEFT | MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_LEFT | LOWER_RIGHT,
UPPER_RIGHT | MIDDLE_LEFT | MIDDLE_RIGHT | LOWER_LEFT | LOWER_RIGHT,
};
assert(cp >= 0x1fb00 and cp <= 0x1fb3b);
const idx = cp - 0x1fb00;
const encoded = matrix[idx];
const x_halfs: [2]u32 = .{
@floatToInt(u32, @round(@intToFloat(f64, self.width) / 2)),
@floatToInt(u32, @intToFloat(f64, self.width) / 2),
};
const y_thirds: [2]u32 = switch (@mod(self.height, 3)) {
0 => .{ self.height / 3, 2 * self.height / 3 },
1 => .{ self.height / 3, 2 * self.height / 3 + 1 },
2 => .{ self.height / 3 + 1, 2 * self.height / 3 },
else => unreachable,
};
if (encoded & UPPER_LEFT > 0) self.rect(img, 0, 0, x_halfs[0], y_thirds[0]);
if (encoded & MIDDLE_LEFT > 0) self.rect(img, 0, y_thirds[0], x_halfs[0], y_thirds[1]);
if (encoded & LOWER_LEFT > 0) self.rect(img, 0, y_thirds[1], x_halfs[0], self.height);
if (encoded & UPPER_RIGHT > 0) self.rect(img, x_halfs[1], 0, self.width, y_thirds[0]);
if (encoded & MIDDLE_RIGHT > 0) self.rect(img, x_halfs[1], y_thirds[0], self.width, y_thirds[1]);
if (encoded & LOWER_RIGHT > 0) self.rect(img, x_halfs[1], y_thirds[1], self.width, self.height);
}
fn draw_light_arc(
self: BoxFont,
alloc: Allocator,

View File

@ -192,6 +192,9 @@ pub fn indexForCodepoint(
// "Braille" block
0x2800...0x28FF => true,
// "Symbols for Legacy Computing" block
0x1FB00...0x1FB3B => true,
else => false,
}) {
return FontIndex.initSpecial(.box);