pub enum FontWeight {
Regular,
Medium,
SemiBold,
Bold,
}Expand description
Font weight — a useful subset, mapped onto the CSS/OpenType weights.
Variants§
Implementations§
Source§impl FontWeight
impl FontWeight
Sourcepub fn lerp(self, other: FontWeight, t: f32) -> FontWeight
pub fn lerp(self, other: FontWeight, t: f32) -> FontWeight
The weight t of the way from self to other — the nearest of the four,
not a number between them.
A weight is drawn with a face, and there are four faces. Interpolating the number would ask for a 437 that no font has, so what moves is the choice: the numeric weights are interpolated and the result snaps to whichever of the four is closest. Halfway from regular to bold is semi-bold, and a run of words thickens in steps rather than gliding.
The reference does exactly this over its nine weights, and this is its method rather than a lookalike: the position in the list is interpolated and rounded, not the OpenType number. The two agree here because the four are evenly spaced, and the list is what stays right if a fifth face is ever added between two of them.
A tie goes to the heavier face. Exactly halfway from regular to bold is 550, which has no nearest — rounding a half up the list answers semi-bold, going in either direction, so a run of words thickening and one thinning pass through the same face at the same moment instead of missing each other by one step.
Four steps make the stepping easier to see than nine would. That is a reason to say so here, not a reason to do something else: a variable-font axis is the thing that would make a weight glide, and this framework does not have one yet.