ferroui_base/platform/surfaces/platform_text_rendering_parameters.rs
1//! What the platform says about how text is rendered on a surface: the
2//! settings of the system a render backend needs to render text the way
3//! the native text of the platform looks (docs/porting/text-rendering.md).
4//!
5//! This is FerroUI's own addition (docs/porting/DEVIATIONS.md, area
6//! `Text rendering`): the reference renders text the same way on every
7//! surface.
8
9/// The arrangement of the colour stripes of the pixels of a display, which
10/// subpixel (LCD) text antialiasing is rendered for.
11#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
12pub enum SubpixelGeometry {
13 /// Not known: subpixel text cannot be rendered for the display.
14 #[default]
15 Unknown,
16 /// Red, green and blue from left to right.
17 RgbHorizontal,
18 /// Blue, green and red from left to right.
19 BgrHorizontal,
20 /// Red, green and blue from top to bottom.
21 RgbVertical,
22 /// Blue, green and red from top to bottom.
23 BgrVertical,
24}
25
26/// The text rendering settings of the platform for a render surface.
27///
28/// A surface reports them through
29/// [`IPlatformRenderSurface::text_rendering_parameters`](super::IPlatformRenderSurface::text_rendering_parameters)
30/// when the platform knows them; a surface that reports nothing gets the
31/// defaults of the backend (greyscale antialiasing).
32#[derive(Clone, Copy, Debug, Default, PartialEq)]
33pub struct PlatformTextRenderingParameters {
34 /// Whether the system renders text with subpixel antialiasing on the
35 /// display of the surface: ClearType on Windows (`SPI_GETFONTSMOOTHING`
36 /// and `SPI_GETFONTSMOOTHINGTYPE`), `Xft.rgba` on X11.
37 pub subpixel_antialiasing: bool,
38
39 /// The arrangement of the subpixels of the display, when it is known
40 /// (`SPI_GETFONTSMOOTHINGORIENTATION` on Windows).
41 pub subpixel_geometry: SubpixelGeometry,
42
43 /// Whether the surface is composed with other content by a system
44 /// compositor (Windows.UI.Composition, DirectComposition, a swap chain
45 /// panel of a WinUI host). Native frameworks render greyscale text on
46 /// such surfaces (WinUI 3 does), so subpixel text is not the default
47 /// there.
48 pub composited: bool,
49
50 /// The contrast added to the coverage of text, from 0 to 1, or `None`
51 /// for the default of the backend.
52 pub text_contrast: Option<f32>,
53
54 /// The gamma the coverage of text is corrected for, from 0 (exclusive
55 /// of 4), where 0 means sRGB, or `None` for the default of the backend.
56 pub text_gamma: Option<f32>,
57}