Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
stylo: Move font-size stuff to values::*::font
- Loading branch information
1 parent
e1a39a2
commit df9d7cd
Showing
8 changed files
with
430 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.