mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implement font fallback
Prior to this change, if none of the fonts specified in CSS contained a glyph for a codepoint, we tried only one fallback font. If that font didn't contain the glyph, we'd give up. With this change, we try multiple fonts in turn. The font names we try differ across each platform, and based on the codepoint we're trying to match. The current implementation is heavily inspired by the analogous code in Gecko, but I've used to ucd lib to make it more readable, whereas Gecko matches raw unicode ranges. This fixes some of the issues reported in #17267, although colour emoji support is not implemented. == Notes on changes to WPT metadata == === css/css-text/i18n/css3-text-line-break-opclns-* === A bunch of these have started failing on macos when they previously passed. These tests check that the browser automatically inserts line breaks near certain characters that are classified as "opening and closing punctuation". The idea is that if we have e.g. an opening parenthesis, it does not make sense for it to appear at the end of a line box; it should "stick" to the next character and go into the next line box. Before this change, a lot of these codepoints rendered as a missing glyph on Mac and Linux. In some cases, that meant that the test was passing. After this change, a bunch of these codepoints are now rendering glyphs on Mac (but not Linux). In some cases, the test should continue to pass where it previously did when rendering with the missing glyph. However, it seems this has also exposed a layout bug. The "ref" div in these tests contains a <br> element, and it seems that this, combined with these punctuation characters, makes the spacing between glyphs ever so slightly different to the "test" div. (Speculation: might be something to do with shaping?) Therefore I've had to mark a bunch of these tests failing on mac. === css/css-text/i18n/css3-text-line-break-baspglwj-* === Some of these previously passed on Mac due to a missing glyph. Now that we're rendering the correct glyph, they are failing. === css/css-text/word-break/word-break-normal-bo-000.html === The characters now render correctly on Mac, and the test is passing. But we do not find a suitable fallback font on Linux, so it is still failing on that platform. === css/css-text/word-break/word-break-break-all-007.html === This was previously passing on Mac, but only because missing character glyphs were rendered. Now that a fallback font is able to be found, it (correctly) fails. === mozilla/tests/css/font_fallback_* === These are new tests added in this commit. 01 and 02 are marked failing on Linux because the builders don't have the appropriate fonts installed (that will be a follow-up). Fix build errors from rebase FontTemplateDescriptor can no longer just derive(Hash). We need to implement it on each component part, because the components now generally wrap floats, which do not impl Hash because of NaN. However in this case we know that we won't have a NaN, so it is safe to manually impl Hash.
This commit is contained in:
parent
15a677c639
commit
691c6c6f1a
81 changed files with 1192 additions and 360 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue