mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
stylo: Move font-size stuff to values::*::font
This commit is contained in:
parent
e1a39a2012
commit
df9d7cd941
8 changed files with 430 additions and 389 deletions
61
components/style/values/computed/font.rs
Normal file
61
components/style/values/computed/font.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Computed values for font properties
|
||||
|
||||
use app_units::Au;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::NonNegativeLength;
|
||||
use values::specified::font as specified;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
#[derive(ToAnimatedValue, Animate, ToAnimatedZero, ComputeSquaredDistance)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||
/// The computed value of font-size
|
||||
pub struct FontSize {
|
||||
/// The size.
|
||||
pub size: NonNegativeLength,
|
||||
/// If derived from a keyword, the keyword and additional transformations applied to it
|
||||
pub info: Option<KeywordInfo>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
#[derive(ToAnimatedValue, Animate, ToAnimatedZero, ComputeSquaredDistance)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||
/// Additional information for keyword-derived font sizes.
|
||||
pub struct KeywordInfo {
|
||||
/// The keyword used
|
||||
pub kw: specified::KeywordSize,
|
||||
/// A factor to be multiplied by the computed size of the keyword
|
||||
pub factor: f32,
|
||||
/// An additional Au offset to add to the kw*factor in the case of calcs
|
||||
pub offset: NonNegativeLength,
|
||||
}
|
||||
|
||||
impl KeywordInfo {
|
||||
/// Given a parent keyword info (self), apply an additional factor/offset to it
|
||||
pub fn compose(self, factor: f32, offset: NonNegativeLength) -> Self {
|
||||
KeywordInfo {
|
||||
kw: self.kw,
|
||||
factor: self.factor * factor,
|
||||
offset: self.offset.scale_by(factor) + offset,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FontSize {
|
||||
/// The actual computed font size.
|
||||
pub fn size(self) -> Au {
|
||||
self.size.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for FontSize {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.size.to_css(dest)
|
||||
}
|
||||
}
|
|
@ -67,6 +67,7 @@ pub mod box_;
|
|||
pub mod color;
|
||||
pub mod effects;
|
||||
pub mod flex;
|
||||
pub mod font;
|
||||
pub mod image;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub mod gecko;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue