Skip to main content

epaint/text/
mod.rs

1//! Everything related to text, fonts, text layout, cursors etc.
2
3pub mod cursor;
4mod font;
5mod fonts;
6mod index;
7mod text_layout;
8mod text_layout_types;
9
10pub use {
11    fonts::{
12        FontData, FontDefinitions, FontFamily, FontId, FontInsert, FontPriority, FontTweak,
13        FontVariationAxis, Fonts, FontsImpl, FontsView, HintingTarget, InsertFontFamily,
14        SmoothHinting,
15    },
16    index::{ByteIndex, ByteRange, ByteRangeExt, CharIndex, CharRange, CharRangeExt},
17    text_layout::*,
18    text_layout_types::*,
19};
20
21/// Suggested character to use to replace those in password text fields.
22pub const PASSWORD_REPLACEMENT_CHAR: char = '•';
23
24/// Controls how we render text
25#[derive(Clone, Copy, Debug, PartialEq)]
26#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
27pub struct TextOptions {
28    /// Maximum size of the font texture.
29    pub max_texture_side: usize,
30
31    /// Controls how to convert glyph colors when writing to the font atlas.
32    pub color_transfer_function: crate::FontColorTransferFunction,
33
34    /// Whether to enable font hinting
35    ///
36    /// (round some font coordinates to pixels for sharper text).
37    ///
38    /// Default is `true`.
39    pub font_hinting: bool,
40
41    /// Enable sub-pixel binning for glyphs.
42    ///
43    /// Sub-pixel binning renders each glyph at up to four fractional horizontal offsets,
44    /// giving more even kerning at the cost of more atlas space.
45    ///
46    /// It also lead to text looking more blurry.
47    ///
48    /// This is always disabled for CJK characters (which have too many unique glyphs).
49    ///
50    /// Can be overridden per font with [`FontTweak::subpixel_binning`].
51    ///
52    /// Default: `true`.
53    pub subpixel_binning: bool,
54}
55
56impl Default for TextOptions {
57    fn default() -> Self {
58        Self {
59            max_texture_side: 2048, // Small but portable
60            color_transfer_function: crate::FontColorTransferFunction::default(),
61            font_hinting: true,
62            subpixel_binning: true,
63        }
64    }
65}