Synthetic italic not applied when Fontconfig returns an upright fallback face #13583
Unanswered
UnsaltedScholar
asked this question in
Issue Triage
Replies: 1 comment
|
This is a very minimal patch against f124c42 that seems to fix this issue (for the italics case): diff --git a/src/font/discovery.zig b/src/font/discovery.zig
--- a/src/font/discovery.zig
+++ b/src/font/discovery.zig
@@ -315,6 +315,14 @@ pub const Fontconfig = struct {
pub fn next(self: *DiscoverIterator) fontconfig.Error!?DeferredFace {
if (self.i >= self.fonts.len) return null;
+
+ const requested_slant: fontconfig.Slant =
+ @enumFromInt((try self.pattern.get(.slant, 0)).integer);
+ const matched_slant: fontconfig.Slant =
+ @enumFromInt((try self.fonts[self.i].get(.slant, 0)).integer);
+ if (requested_slant != .roman and matched_slant == .roman) {
+ return null;
+ }
// Get the copied pattern from our fontset that has the
// attributes configured for rendering.Edit: diff --git a/src/font/discovery.zig b/src/font/discovery.zig
--- a/src/font/discovery.zig
+++ b/src/font/discovery.zig
@@ -315,6 +315,28 @@ pub const Fontconfig = struct {
pub fn next(self: *DiscoverIterator) fontconfig.Error!?DeferredFace {
if (self.i >= self.fonts.len) return null;
+
+ const requested_slant: fontconfig.Slant =
+ @enumFromInt((try self.pattern.get(.slant, 0)).integer);
+ const matched_slant: fontconfig.Slant =
+ @enumFromInt((try self.fonts[self.i].get(.slant, 0)).integer);
+
+ const requested_weight =
+ (try self.pattern.get(.weight, 0)).integer;
+ const matched_weight = try self.fonts[self.i].get(.weight, 0);
+ const bold_min = @intFromEnum(fontconfig.Weight.demibold);
+ const weight_mismatch = requested_weight >= bold_min and
+ switch (matched_weight) {
+ .integer => |weight| weight < bold_min,
+ .range => false,
+ else => true,
+ };
+
+ if ((requested_slant != .roman and matched_slant == .roman) or
+ weight_mismatch)
+ {
+ return null;
+ }
// Get the copied pattern from our fontset that has the
// attributes configured for rendering. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Issue Description
Potential duplicate of #3791, but making this as the previous discussion seems stale.
I am using Ghostty with FiraCode Nerd Font. FiraCode does not provide native italic faces, so I expected Ghostty to synthesize italic text. Instead, italic and bold-italic are rendered upright.
Bold began working correctly after I changed the configuration from the weight-specific "FiraCode Nerd Font Med" family to the general "FiraCode Nerd Font" family. Synthetic italic still does not work.
This may be related to how Ghostty handles approximate Fontconfig matches.
If I understand correctly, in src/font/discovery.zig, Ghostty creates a Fontconfig pattern with the requested italic slant and obtains a sorted set of matching fonts. When the requested family has no italic variant, Fontconfig may still return the closest available upright face.
The returned face is then consumed in src/font/SharedGridSet.zig. The first result is added to the collection under the style that was requested:
Synthetic style completion occurs later in the same function:
So I am assuming Ghostty requests an italic FiraCode face, Fontconfig returns an upright face as its closest match, and Ghostty adds that face to the italic slot. Because the italic slot is then considered populated, completeStyles does not synthesize the missing slant.
Would the intended behavior be for Ghostty to verify that a Fontconfig result actually satisfies the requested weight or slant before assigning it to that style slot?
Addendum:
I also think a similar issue might be possible for fonts that don't have a native bold face and Fontconfig returns an upright, non-bold approximation (with inappropriate weight), but I was unable to find an example font where this is an issue.
Expected Behavior
Because Fira Code has no native italic face and font-synthetic-style should handle both italic and bold-italic, I expected Ghostty to synthesize the missing slant.
Actual Behavior
Normal text renders correctly. Bold text uses a visibly heavier face. Italic text appears identical to upright text. Bold-italic text is bold but not slanted.
Reproduction Steps
Ghostty Logs
Ghostty Version
OS Version Information
CachyOS Linux
(Linux only) Display Server
Wayland
(Linux only) Desktop Environment/Window Manager
KDE Plasma 6.7.3
Minimal Ghostty Configuration
Additional Relevant Configuration
Built with system fontconfig (to fix log errors):
zig build -Doptimize=ReleaseFast -p ~/.local/ -fsys=fontconfigI acknowledge that:
```) on separate lines.All reactions