Skip to main content

FontSpec

Struct FontSpec 

Source
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: bool

Ask 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: bool

Ask 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: f64

Multiply 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

Source

pub fn new(style: Font) -> Self

The plain descriptor for a style: no weight override, no italic, scale 1.0.

Source

pub fn scaled(self, scale: f64) -> Self

This descriptor at a different relative size (see FontSpec::scale).

Source

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§

Source§

impl Clone for FontSpec

Source§

fn clone(&self) -> FontSpec

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FontSpec

Source§

impl Debug for FontSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FontSpec

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Font> for FontSpec

Source§

fn from(style: Font) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for FontSpec

Source§

fn eq(&self, other: &FontSpec) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FontSpec

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Day API ↩ Guides· daybrite.dev