pub struct FontSpec {
pub style: Font,
pub weight: Option<FontWeight>,
pub italic: bool,
pub tabular: bool,
pub monospace: bool,
pub scale: f64,
}Expand description
The full font descriptor a label carries: a semantic (or custom) Font style plus an optional
weight override, an italic flag, and the tabular-figures request. Backends resolve this to one
native font.
Fields§
§style: Font§weight: Option<FontWeight>§italic: bool§tabular: boolAsk for tabular (monospaced) figures: every digit takes the same advance, so a number that changes stops changing width.
In a proportional system font 1 is narrower than 8, so a readout beside a slider
wobbles as the value changes even when the digit count is fixed. Every platform ships this
as a font feature, so Day asks for the platform’s own rather than substituting a monospaced
family: the text keeps the system face, and only the digits change metrics.
Reserving space (Decorate::reserving) and tabular figures solve the two halves of the
same problem (reservation stops the box resizing, tabular stops the glyphs shifting inside
it), and a numeric readout usually wants both.
This rides the existing label realize/patch path rather than adding a Toolkit method, so it
is not a backend duty and has no duty-matrix row. Every in-tree backend honors it: AppKit
and UIKit re-pick the system face (monospacedDigitSystemFont), GTK and Qt and ArkUI set
the tnum OpenType feature, Android setFontFeatureSettings, XAML the Typography
NumeralAlignment property, and web-dom font-variant-numeric. A font with no tnum table,
or an SDK predating the attribute, renders the stock proportional figures.
monospace: boolAsk for the platform’s monospaced face at this style’s size, what `code` in a
markdown run needs (docs/text-runs.md).
A flag rather than a Font::Monospace(pt) variant so the run keeps its semantic style:
code inside a Footnote paragraph must stay footnote-sized and keep tracking the
reader’s text-size setting, which a fixed point size would throw away.
Like Self::tabular, this rides the label realize/patch path and is not a backend duty:
every toolkit has a system monospace face (monospacedSystemFont, Pango’s monospace
family, QFontDatabase::FixedFont, Typeface.MONOSPACE, CSS monospace).
scale: f64Multiply the resolved size. 1.0 is the style’s own size, 1.6 a heading against a body
paragraph, 0.8 a caption inside one.
Relative rather than an absolute point size, so that an editor’s font-size control can
move this while text a person reads for an hour still tracks the platform’s
accessibility text-scale. Font::System(pt) remains the absolute escape hatch, and it
is where an imported document’s \fs28 or font-size: 14px lands (docs/texteditor.md):
faithful to the file, and no longer responsive to the reader, which is the trade that
form makes.
Three toolkits take it directly (GtkTextTag::scale, Android’s RelativeSizeSpan, CSS
em); the rest multiply it into the size they already compute.
Implementations§
Source§impl FontSpec
impl FontSpec
Sourcepub fn new(style: Font) -> FontSpec
pub fn new(style: Font) -> FontSpec
The plain descriptor for a style: no weight override, no italic, scale 1.0.
Sourcepub fn scaled(self, scale: f64) -> FontSpec
pub fn scaled(self, scale: f64) -> FontSpec
This descriptor at a different relative size (see FontSpec::scale).
Sourcepub fn resolved_points(&self, style_points: f64) -> f64
pub fn resolved_points(&self, style_points: f64) -> f64
The point size this descriptor resolves to, given the size the platform assigns its
semantic style. The one place scale is applied, so every backend’s font resolver
multiplies the same way.
Trait Implementations§
impl Copy for FontSpec
impl StructuralPartialEq for FontSpec
Auto Trait Implementations§
impl Freeze for FontSpec
impl RefUnwindSafe for FontSpec
impl Send for FontSpec
impl Sync for FontSpec
impl Unpin for FontSpec
impl UnsafeUnpin for FontSpec
impl UnwindSafe for FontSpec
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more