mirror of
https://github.com/servo/servo.git
synced 2025-08-10 16:05:43 +01:00
Auto merge of #20506 - jonleighton:font-fallback, r=emilio,mbrubeck
Font fallback This implements more complete support for font fallback, see #17267. r? @glennw @mbrubeck <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20506) <!-- Reviewable:end -->
This commit is contained in:
commit
77dcc678fe
83 changed files with 1379 additions and 462 deletions
|
@ -84,7 +84,7 @@ ${helpers.predefined_type("font-synthesis",
|
|||
${helpers.predefined_type(
|
||||
"font-stretch",
|
||||
"FontStretch",
|
||||
initial_value="computed::NonNegativePercentage::hundred()",
|
||||
initial_value="computed::FontStretch::hundred()",
|
||||
initial_specified_value="specified::FontStretch::normal()",
|
||||
animation_value_type="Percentage",
|
||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||
|
|
|
@ -2305,13 +2305,10 @@ pub mod style_structs {
|
|||
pub fn compute_font_hash(&mut self) {
|
||||
// Corresponds to the fields in
|
||||
// `gfx::font_template::FontTemplateDescriptor`.
|
||||
//
|
||||
// FIXME(emilio): Where's font-style?
|
||||
let mut hasher: FnvHasher = Default::default();
|
||||
// We hash the floating point number with four decimal
|
||||
// places.
|
||||
hasher.write_u64((self.font_weight.0 * 10000.).trunc() as u64);
|
||||
hasher.write_u64(((self.font_stretch.0).0 * 10000.).trunc() as u64);
|
||||
self.font_weight.hash(&mut hasher);
|
||||
self.font_stretch.hash(&mut hasher);
|
||||
self.font_style.hash(&mut hasher);
|
||||
self.font_family.hash(&mut hasher);
|
||||
self.hash = hasher.finish()
|
||||
}
|
||||
|
|
|
@ -15,21 +15,20 @@ use gecko_bindings::sugar::refptr::RefPtr;
|
|||
#[cfg(feature = "gecko")]
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
use std::fmt::{self, Write};
|
||||
#[cfg(feature = "gecko")]
|
||||
use std::hash::{Hash, Hasher};
|
||||
#[cfg(feature = "servo")]
|
||||
use std::slice;
|
||||
use style_traits::{CssWriter, ParseError, ToCss};
|
||||
use values::CSSFloat;
|
||||
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||
use values::computed::{Angle, Context, Integer, NonNegativeLength, Number, ToComputedValue};
|
||||
use values::computed::{Angle, Context, Integer, NonNegative, NonNegativeLength, NonNegativePercentage};
|
||||
use values::computed::{Number, Percentage, ToComputedValue};
|
||||
use values::generics::font::{self as generics, FeatureTagValue, FontSettings, VariationValue};
|
||||
use values::specified::font::{self as specified, MIN_FONT_WEIGHT, MAX_FONT_WEIGHT};
|
||||
use values::specified::length::{FontBaseSize, NoCalcLength};
|
||||
|
||||
pub use values::computed::Length as MozScriptMinSize;
|
||||
pub use values::specified::font::{FontSynthesis, MozScriptSizeMultiplier, XLang, XTextZoom};
|
||||
pub use values::computed::NonNegativePercentage as FontStretch;
|
||||
|
||||
/// A value for the font-weight property per:
|
||||
///
|
||||
|
@ -41,6 +40,12 @@ pub use values::computed::NonNegativePercentage as FontStretch;
|
|||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
pub struct FontWeight(pub Number);
|
||||
|
||||
impl Hash for FontWeight {
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
hasher.write_u64((self.0 * 10000.).trunc() as u64);
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for FontWeight {
|
||||
type AnimatedValue = Number;
|
||||
|
||||
|
@ -853,6 +858,12 @@ impl ToAnimatedValue for FontStyleAngle {
|
|||
}
|
||||
}
|
||||
|
||||
impl Hash for FontStyleAngle {
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
hasher.write_u64((self.0.degrees() * 10000.).trunc() as u64);
|
||||
}
|
||||
}
|
||||
|
||||
/// The computed value of `font-style`.
|
||||
///
|
||||
/// FIXME(emilio): Angle should be a custom type to handle clamping during
|
||||
|
@ -916,3 +927,43 @@ impl ToCss for FontStyle {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A value for the font-stretch property per:
|
||||
///
|
||||
/// https://drafts.csswg.org/css-fonts-4/#propdef-font-stretch
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
pub struct FontStretch(pub NonNegativePercentage);
|
||||
|
||||
impl FontStretch {
|
||||
/// 100%
|
||||
pub fn hundred() -> Self {
|
||||
FontStretch(NonNegativePercentage::hundred())
|
||||
}
|
||||
|
||||
/// The float value of the percentage
|
||||
#[inline]
|
||||
pub fn value(&self) -> CSSFloat {
|
||||
((self.0).0).0
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for FontStretch {
|
||||
type AnimatedValue = Percentage;
|
||||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self::AnimatedValue {
|
||||
(self.0).0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
FontStretch(NonNegative(animated))
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for FontStretch {
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
hasher.write_u64((self.value() * 10000.).trunc() as u64);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ impl Default for KeywordSize {
|
|||
/// https://drafts.csswg.org/css-fonts-4/#font-style-prop
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, Hash, MallocSizeOf,
|
||||
PartialEq, SpecifiedValueInfo, ToAnimatedValue, ToAnimatedZero)]
|
||||
pub enum FontStyle<Angle> {
|
||||
#[animation(error)]
|
||||
|
|
|
@ -156,7 +156,7 @@ impl SpecifiedValueInfo for CounterStyleOrNone {
|
|||
|
||||
/// A wrapper of Non-negative values.
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, Hash, MallocSizeOf,
|
||||
PartialEq, PartialOrd, SpecifiedValueInfo, ToAnimatedZero,
|
||||
ToComputedValue, ToCss)]
|
||||
pub struct NonNegative<T>(pub T);
|
||||
|
|
|
@ -490,22 +490,22 @@ impl Parse for FontStretch {
|
|||
}
|
||||
|
||||
impl ToComputedValue for FontStretch {
|
||||
type ComputedValue = NonNegative<ComputedPercentage>;
|
||||
type ComputedValue = computed::FontStretch;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
FontStretch::Stretch(ref percentage) => {
|
||||
NonNegative(percentage.to_computed_value(context))
|
||||
computed::FontStretch(NonNegative(percentage.to_computed_value(context)))
|
||||
},
|
||||
FontStretch::Keyword(ref kw) => {
|
||||
NonNegative(kw.compute())
|
||||
computed::FontStretch(NonNegative(kw.compute()))
|
||||
},
|
||||
FontStretch::System(_) => self.compute_system(context),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
FontStretch::Stretch(Percentage::from_computed_value(&computed.0))
|
||||
FontStretch::Stretch(Percentage::from_computed_value(&(computed.0).0))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue