config: font-synthetic-style to enable/disable synthetic styles

This adds a new configuration "font-synthetic-style" to enable or
disable synthetic styles. This is different from "font-style-*" which
specifies a named style or disables a style completely.

Instead, "font-synthetic-style" will disable only the creation of
synthetic styles in the case a font does not support a given style.
This is useful for users who want to obviously know when a font doesn't
support a given style or a user who wants to explicitly only use the
styles that were designed by the font designer.

The default value is to enable all synthetic styles.
This commit is contained in:
Mitchell Hashimoto
2024-08-26 20:46:14 -07:00
parent 80327402b8
commit bdcc21942d
4 changed files with 70 additions and 4 deletions

View File

@@ -128,7 +128,7 @@ pub fn ref(
// Build our collection. This is the expensive operation that
// involves finding fonts, loading them (maybe, some are deferred),
// etc.
var c = try self.collection(&key, font_size);
var c = try self.collection(&key, font_size, config);
errdefer c.deinit(self.alloc);
// Setup our enabled/disabled styles
@@ -156,6 +156,7 @@ fn collection(
self: *SharedGridSet,
key: *const Key,
size: DesiredSize,
config: *const DerivedConfig,
) !Collection {
// A quick note on memory management:
// - font_lib is owned by the SharedGridSet
@@ -300,7 +301,7 @@ fn collection(
// Complete our styles to ensure we have something to satisfy every
// possible style request.
try c.completeStyles(self.alloc);
try c.completeStyles(self.alloc, config.@"font-synthetic-style");
return c;
}
@@ -386,6 +387,7 @@ pub const DerivedConfig = struct {
@"font-variation-italic": configpkg.RepeatableFontVariation,
@"font-variation-bold-italic": configpkg.RepeatableFontVariation,
@"font-codepoint-map": configpkg.RepeatableCodepointMap,
@"font-synthetic-style": configpkg.FontSyntheticStyle,
@"adjust-cell-width": ?Metrics.Modifier,
@"adjust-cell-height": ?Metrics.Modifier,
@"adjust-font-baseline": ?Metrics.Modifier,
@@ -416,6 +418,7 @@ pub const DerivedConfig = struct {
.@"font-variation-italic" = try config.@"font-variation-italic".clone(alloc),
.@"font-variation-bold-italic" = try config.@"font-variation-bold-italic".clone(alloc),
.@"font-codepoint-map" = try config.@"font-codepoint-map".clone(alloc),
.@"font-synthetic-style" = config.@"font-synthetic-style",
.@"adjust-cell-width" = config.@"adjust-cell-width",
.@"adjust-cell-height" = config.@"adjust-cell-height",
.@"adjust-font-baseline" = config.@"adjust-font-baseline",