1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 15:13:12 -04:00
Files
egui/crates/epaint/src/text/mod.rs
Emil Ernerfeldt 3abba21f2d Add subpixel_binning to TextOptions and FontTweak (#8072)
This lets you turn off subpixel horizontal binning of glyphs. The option
is a trade-off between even kerning and sharp text.

* Closes https://github.com/emilk/egui/issues/8034
2026-04-07 10:38:37 +02:00

63 lines
1.8 KiB
Rust

//! Everything related to text, fonts, text layout, cursors etc.
pub mod cursor;
mod font;
mod fonts;
mod text_layout;
mod text_layout_types;
pub use {
fonts::{
FontData, FontDefinitions, FontFamily, FontId, FontInsert, FontPriority, FontTweak, Fonts,
FontsImpl, FontsView, InsertFontFamily,
},
text_layout::*,
text_layout_types::*,
};
/// Suggested character to use to replace those in password text fields.
pub const PASSWORD_REPLACEMENT_CHAR: char = '•';
/// Controls how we render text
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct TextOptions {
/// Maximum size of the font texture.
pub max_texture_side: usize,
/// Controls how to convert glyph coverage to alpha.
pub alpha_from_coverage: crate::AlphaFromCoverage,
/// Whether to enable font hinting
///
/// (round some font coordinates to pixels for sharper text).
///
/// Default is `true`.
pub font_hinting: bool,
/// Enable sub-pixel binning for glyphs.
///
/// Sub-pixel binning renders each glyph at up to four fractional horizontal offsets,
/// giving more even kerning at the cost of more atlas space.
///
/// It also lead to text looking more blurry.
///
/// This is always disabled for CJK characters (which have too many unique glyphs).
///
/// Can be overridden per font with [`FontTweak::subpixel_binning`].
///
/// Default: `true`.
pub subpixel_binning: bool,
}
impl Default for TextOptions {
fn default() -> Self {
Self {
max_texture_side: 2048, // Small but portable
alpha_from_coverage: crate::AlphaFromCoverage::default(),
font_hinting: true,
subpixel_binning: true,
}
}
}