pub struct FontScaleCurve { /* private fields */ }Expand description
The sp → dp conversion the platform performs, sampled from the platform.
With no knots this is sp * scale. With knots it is the piecewise-linear
function through them, extended past both ends by the ratio of the knot on
that end — which is how the platform extends its own table, so a size below
the first knot scales by the plain setting and one above the last keeps the
last knot’s ratio.
A curve is Copy and rides in every crate::Density, which each layout
node keeps and the measurement path passes by value, so its knots live in
a table shared by every curve with the same knots, which it reaches by a
thin pointer: a curve is 16 bytes.
Implementations§
Source§impl FontScaleCurve
impl FontScaleCurve
Sourcepub const fn linear(scale: f32) -> Self
pub const fn linear(scale: f32) -> Self
The plain multiplier: what every platform without a conversion table does, and what Android itself did before it had one.
Sourcepub fn from_samples(scale: f32, samples: &[(f32, f32)]) -> Self
pub fn from_samples(scale: f32, samples: &[(f32, f32)]) -> Self
A curve through samples, which are (sp, dp) pairs read from the
platform in ascending sp order.
Samples that lie on the straight line between their neighbours are
dropped, so a densely sampled table comes back as the handful of points
that actually bend. Anything the platform could not have produced — an
empty or unsorted set, a non-finite or non-positive value, or more bends
than MAX_FONT_SCALE_KNOTS — is refused, and the caller gets the
multiplier rather than a curve nobody measured. Samples that all lie on
the multiplier’s own line are the multiplier, and come back as it, so a
platform answering with the plain setting gives a curve equal to
FontScaleCurve::linear.
Sourcepub fn scale(self) -> f32
pub fn scale(self) -> f32
The setting itself — what the user chose, whatever the table then does with an individual size. This is the number to report, not the number to multiply by.
Sourcepub fn is_identity(self) -> bool
pub fn is_identity(self) -> bool
Whether resolving an Sp through this curve changes nothing at all.
Asked of the conversion and not of the representation: a platform that hands back a table while the setting sits at 1.0 hands back a table whose every knot maps a size to itself, and that is still nothing to do.
Sourcepub fn knots(self) -> &'static [(f32, f32)]
pub fn knots(self) -> &'static [(f32, f32)]
The knots, ascending by sp. Empty for a linear curve.
Sourcepub fn knot_count(self) -> usize
pub fn knot_count(self) -> usize
How many FontScaleCurve::knots there are.
Sourcepub fn fingerprint(self) -> u32
pub fn fingerprint(self) -> u32
A cheap identity for cache keys: two curves that convert identically share it, and one that does not is overwhelmingly unlikely to.
Sourcepub fn sp_to_dp(self, sp: f32) -> f32
pub fn sp_to_dp(self, sp: f32) -> f32
A size in scale-independent pixels, in dp.
This is FontScaleConverterImpl.convertSpToDp: the sign is carried
separately, an exact hit on a knot returns that knot, a size outside the
table scales by the ratio of the nearest end, and everything between two
knots is interpolated.
Trait Implementations§
Source§impl Clone for FontScaleCurve
impl Clone for FontScaleCurve
impl Copy for FontScaleCurve
Source§impl Debug for FontScaleCurve
impl Debug for FontScaleCurve
Source§impl Default for FontScaleCurve
impl Default for FontScaleCurve
Source§impl PartialEq for FontScaleCurve
impl PartialEq for FontScaleCurve
impl StructuralPartialEq for FontScaleCurve
Auto Trait Implementations§
impl Freeze for FontScaleCurve
impl RefUnwindSafe for FontScaleCurve
impl Send for FontScaleCurve
impl Sync for FontScaleCurve
impl Unpin for FontScaleCurve
impl UnsafeUnpin for FontScaleCurve
impl UnwindSafe for FontScaleCurve
Blanket Implementations§
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