mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Make font hinting target configurable via FontTweak (#8262)
Fixes #8079, where font hinting only sharpens the vertical axis (vertical stems stay blurry), and none of the skrifa knobs were reachable — only switching to `Target::Mono` helped, but that wasn't exposed. This makes the hinting target configurable instead of hardcoding `Target::Smooth { symmetric_rendering: true, preserve_linear_metrics: true }`. ### API - New `epaint::text::HintingTarget` mirroring `skrifa::outline::Target`: - `Mono` - `Smooth(SmoothHinting)` where `SmoothHinting { light, symmetric_rendering, preserve_linear_metrics }` - New field `FontTweak::hinting_target: HintingTarget`. - Each variant/field is documented with what it does and the egui-specific caveats (e.g. `symmetric_rendering` only affects interpreter-hinted fonts; egui positions glyphs from shaper advances so `preserve_linear_metrics` mostly affects sharpness, not layout). ### Render - `font.rs` converts `HintingTarget` → `skrifa::outline::Target` and threads it into the per-glyph `reconfigure` call; the hinting instance is also reconfigured when the target changes. ### UI - The font-tweak settings panel gets a `hinting_target` row: Smooth/Mono radios, `light` / `symmetric_rendering` / `preserve_linear_metrics` checkboxes, and a `Reset` button — all with tooltips. ### Behavior - `HintingTarget::default()` matches egui's previous hardcoded target, so **rendering is unchanged** unless you opt in. To fix the horizontal blur from #8079, uncheck `preserve_linear_metrics` (or pick `Mono`). Whether to flip the *default* is left as a follow-up. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -225,6 +225,7 @@ impl FontCell {
|
||||
glyph_id: GlyphId,
|
||||
bin: SubpixelBin,
|
||||
location: skrifa::instance::LocationRef<'_>,
|
||||
hinting_target: skrifa::outline::Target,
|
||||
) -> Option<GlyphAllocation> {
|
||||
debug_assert!(
|
||||
glyph_id != skrifa::GlyphId::NOTDEF,
|
||||
@@ -244,18 +245,10 @@ impl FontCell {
|
||||
let size = skrifa::instance::Size::new(metrics.scale);
|
||||
if hinting_instance.size() != size
|
||||
|| hinting_instance.location().coords() != location.coords()
|
||||
|| hinting_instance.target() != hinting_target
|
||||
{
|
||||
hinting_instance
|
||||
.reconfigure(
|
||||
&font_data.outline_glyphs,
|
||||
size,
|
||||
location,
|
||||
skrifa::outline::Target::Smooth {
|
||||
mode: skrifa::outline::SmoothMode::Normal,
|
||||
symmetric_rendering: true,
|
||||
preserve_linear_metrics: true,
|
||||
},
|
||||
)
|
||||
.reconfigure(&font_data.outline_glyphs, size, location, hinting_target)
|
||||
.ok()?;
|
||||
}
|
||||
let draw_settings = skrifa::outline::DrawSettings::hinted(hinting_instance, false);
|
||||
@@ -637,9 +630,17 @@ impl FontFace {
|
||||
|
||||
let cache_key = GlyphCacheKey::new(glyph_id, metrics, bin);
|
||||
|
||||
let hinting_target = self.tweak.hinting_target.into();
|
||||
let alloc = *self.glyph_alloc_cache.entry(cache_key).or_insert_with(|| {
|
||||
self.font
|
||||
.allocate_glyph_uncached(atlas, metrics, glyph_id, bin, (&metrics.location).into())
|
||||
.allocate_glyph_uncached(
|
||||
atlas,
|
||||
metrics,
|
||||
glyph_id,
|
||||
bin,
|
||||
(&metrics.location).into(),
|
||||
hinting_target,
|
||||
)
|
||||
.unwrap_or_default()
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user