pub enum FontColorTransferFunction {
Off,
Gamma(f32),
TwoCoverageMinusCoverageSq,
}Expand description
How to convert font coverage values into alpha and color values.
epaint stores all glyphs in the font atlas as white (with varying opacity), so that egui can reuse the same glyph for different text colors (with a simple color multiplication in the shader).
Because of this simplification, we need to apply a non-linear ramp to the glyph colors before writing them into the font atlas, as a way to compensate.
This whole thing is less than rigorous.
It would be better to either render all text colors into the font atlas (which would require more atlas space, but would allow for more accurate rendering of colored text and emojis), or do the color compensation in the shader, based on the active text color.
When experimenting, use https://fonts.google.com/specimen/Ubuntu to compare to a ground truth.
See https://hikogui.org/2022/10/24/the-trouble-with-anti-aliasing.html for related analysis.
Variants§
Off
Use the raw RGBA values from the font rasterizer, without any conversion.
This is the required mode for colored emojis etc.
This mode looks good for black-on-white text, i.e. light mode.
Gamma(f32)
alpha = coverage^gamma.
Gamma=1 looks good for black-on-white text, i.e. light mode.
TwoCoverageMinusCoverageSq
alpha = 2 * coverage - coverage^2
This looks good for white-on-black text, i.e. dark mode.
Very similar to a gamma of 0.5, but produces sharper text. See https://www.desmos.com/calculator/w0ndf5blmn for a comparison to gamma=0.5.
Implementations§
Source§impl FontColorTransferFunction
impl FontColorTransferFunction
Sourcepub const LIGHT_MODE_DEFAULT: Self = Self::Off
pub const LIGHT_MODE_DEFAULT: Self = Self::Off
A good-looking default for light mode (black-on-white text).
Sourcepub const DARK_MODE_DEFAULT: Self = Self::TwoCoverageMinusCoverageSq
pub const DARK_MODE_DEFAULT: Self = Self::TwoCoverageMinusCoverageSq
A good-looking default for dark mode (white-on-black text).
Sourcepub fn to_atlas_color(self, input_color: Color32) -> Color32
pub fn to_atlas_color(self, input_color: Color32) -> Color32
How to convert a white color written by the font rasterizer into a color to be written into the font atlas.
Sourcepub fn alpha_from_coverage(self, coverage: f32) -> f32
pub fn alpha_from_coverage(self, coverage: f32) -> f32
Convert coverage to alpha.
pub fn color_from_coverage(self, coverage: f32) -> Color32
Trait Implementations§
Source§impl Clone for FontColorTransferFunction
impl Clone for FontColorTransferFunction
Source§fn clone(&self) -> FontColorTransferFunction
fn clone(&self) -> FontColorTransferFunction
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more