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.
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.
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 knot_count(self) -> usize
pub fn knot_count(self) -> usize
How many of FontScaleCurve::knots are used.
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.