From 22757683834a35fb017d95f2282af72963786ff9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 2 Nov 2023 21:46:50 -0700 Subject: [PATCH] font: if a codepoint is emoji presentation, prefer that for shaping Fixes #787 --- build.zig | 5 +++++ build.zig.zon | 11 +++++++---- src/font/shaper/run.zig | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index 7b7f0ce94..30c0c6d7a 100644 --- a/build.zig +++ b/build.zig @@ -669,6 +669,10 @@ fn addDeps( .@"enable-freetype" = true, .@"enable-coretext" = font_backend.hasCoretext(), }); + const ziglyph_dep = b.dependency("ziglyph", .{ + .target = step.target, + .optimize = step.optimize, + }); // Wasm we do manually since it is such a different build. if (step.target.getCpuArch() == .wasm32) { @@ -716,6 +720,7 @@ fn addDeps( step.addModule("xev", libxev_dep.module("xev")); step.addModule("pixman", pixman_dep.module("pixman")); step.addModule("utf8proc", utf8proc_dep.module("utf8proc")); + step.addModule("ziglyph", ziglyph_dep.module("ziglyph")); // Mac Stuff if (step.target.isDarwin()) { diff --git a/build.zig.zon b/build.zig.zon index bfca4e766..765e3c0ee 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -4,6 +4,10 @@ .paths = .{""}, .dependencies = .{ // Zig libs + .glfw = .{ + .url = "https://pkg.machengine.org/glfw/14181bd28aa65915262ac3b4549bbd2dc70bbaa5.tar.gz", + .hash = "1220c6bb317ae3948b95161b9706777dde0509e72e8b35b62b92898aef801897d904", + }, .libxev = .{ .url = "https://github.com/mitchellh/libxev/archive/5ecbc871f3bfa80fb7bf0fa853866cb93b99bc18.tar.gz", .hash = "1220416854e424601ecc9814afb461a5dc9cf95db5917d82f794594a58ffc723b82c", @@ -20,10 +24,9 @@ .url = "https://github.com/mitchellh/zig-js/archive/60ac42ab137461cdba2b38cc6c5e16376470aae6.tar.gz", .hash = "1220319b42fbc0116f3f198343256018e9f1da9483cef259201afe4ebab0ce0d8f6a", }, - - .glfw = .{ - .url = "https://pkg.machengine.org/glfw/14181bd28aa65915262ac3b4549bbd2dc70bbaa5.tar.gz", - .hash = "1220c6bb317ae3948b95161b9706777dde0509e72e8b35b62b92898aef801897d904", + .ziglyph = .{ + .url = "https://codeberg.org/dude_the_builder/ziglyph/archive/v0.11.1.tar.gz", + .hash = "1220dee955839b7f267c1bb21e0ee60888c08f408c30f0722b243cabcc8cce8b7508", }, // C libs diff --git a/src/font/shaper/run.zig b/src/font/shaper/run.zig index 94a5da3f0..9af4a9b4c 100644 --- a/src/font/shaper/run.zig +++ b/src/font/shaper/run.zig @@ -1,6 +1,7 @@ const std = @import("std"); const assert = std.debug.assert; const Allocator = std.mem.Allocator; +const ziglyph = @import("ziglyph"); const font = @import("../main.zig"); const shape = @import("../shape.zig"); const terminal = @import("../../terminal/main.zig"); @@ -109,12 +110,20 @@ pub const RunIterator = struct { // presentation format must be directly adjacent to the codepoint. var it = self.row.codepointIterator(j); if (it.next()) |cp| { - if (cp == 0xFE0E) break :p font.Presentation.text; - if (cp == 0xFE0F) break :p font.Presentation.emoji; + if (cp == 0xFE0E) break :p .text; + if (cp == 0xFE0F) break :p .emoji; } break :p null; - } else null; + } else emoji: { + // If we're not a grapheme, our individual char could be + // an emoji so we want to check if we expect emoji presentation. + if (ziglyph.emoji.isEmojiPresentation(@intCast(cell.char))) { + break :emoji .emoji; + } + + break :emoji .text; + }; // If our cursor is on this line then we break the run around the // cursor. This means that any row with a cursor has at least