From c58e0532845d90da341de99bc0734b7d077bfe38 Mon Sep 17 00:00:00 2001 From: "mitz@apple.com" Date: Thu, 20 Dec 2007 06:21:47 +0000 Subject: [PATCH] WebCore: Reviewed by Darin Adler and Dave Hyatt. - Substitute the user's preferred standard font for an unknown primary font before falling back on the platform's last resort font Cannot be tested in DumpRenderTree because it sets the standard font to Times, which is also the hard-coded last resort font on Mac. * css/CSSFontSelector.cpp: (WebCore::CSSFontSelector::getFontData): Changed the early bail out condition to allow getting generic font families from settings even if there are not @font-face rules. Fixed a typo that mapped fantasy to cursive. Added a mapping from -webkit-standard to the standard family. * css/CSSStyleSelector.cpp: (WebCore::CSSStyleSelector::CSSStyleSelector): Changed to always create a font selector. (WebCore::CSSRuleSet::addRulesFromSheet): (WebCore::CSSStyleSelector::applyProperty): Changed to always use the font selector. * css/CSSStyleSelector.h: (WebCore::CSSStyleSelector::fontSelector): * platform/graphics/FontCache.cpp: (WebCore::FontCache::getFontData): Try the user's preferred standard font before the platform's last resort font. LayoutTests: - remove passing tests following the change to font fallback * platform/win/Skipped: Removed tests that failed only because they specified as primary font family a font family that was not available on Windows and therefore were rendered using the platform last resort font, Times New Roman. Now they are rendered using the 'standard' font family, which is set to Times on both Mac and Windows when running the tests. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28882 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 11 +++++++++ LayoutTests/platform/win/Skipped | 33 ------------------------- WebCore/ChangeLog | 27 ++++++++++++++++++++ WebCore/css/CSSFontSelector.cpp | 6 +++-- WebCore/css/CSSStyleSelector.cpp | 26 ++++++------------- WebCore/css/CSSStyleSelector.h | 1 - WebCore/platform/graphics/FontCache.cpp | 15 ++++++++--- 7 files changed, 62 insertions(+), 57 deletions(-) diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 85d3c4718e2f..b50e02e33284 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,14 @@ +2007-12-19 Dan Bernstein + + - remove passing tests following the change to font fallback + + * platform/win/Skipped: Removed tests that failed only because they + specified as primary font family a font family that was not available + on Windows and therefore were rendered using the platform last resort + font, Times New Roman. Now they are rendered using the 'standard' + font family, which is set to Times on both Mac and Windows when running + the tests. + 2007-12-19 Alice Liu Reviewed by Darin. diff --git a/LayoutTests/platform/win/Skipped b/LayoutTests/platform/win/Skipped index 5d60709728b6..8875d2fbbff5 100644 --- a/LayoutTests/platform/win/Skipped +++ b/LayoutTests/platform/win/Skipped @@ -49,10 +49,8 @@ css2.1/t1202-counter-09-b.html css2.1/t1202-counters-09-b.html editing/deleting/5144139-2.html fast/css/beforeSelectorOnCodeElement.html -fast/css/font_property_normal.html fast/css/rtl-ordering.html fast/css/text-security.html -fast/encoding/denormalised-voiced-japanese-chars.html fast/encoding/invalid-UTF-8.html fast/forms/select-visual-hebrew.html fast/forms/select-writing-direction-natural.html @@ -60,38 +58,19 @@ fast/forms/visual-hebrew-text-field.html fast/lists/w3-list-styles.html fast/text/international/bidi-neutral-run.html fast/xsl/xslt-text.xml -svg/W3C-SVG-1.1/animate-elem-03-t.svg -svg/W3C-SVG-1.1/animate-elem-24-t.svg -svg/W3C-SVG-1.1/animate-elem-36-t.svg -svg/W3C-SVG-1.1/animate-elem-40-t.svg svg/W3C-SVG-1.1/coords-viewattr-01-b.svg -svg/W3C-SVG-1.1/fonts-desc-02-t.svg svg/W3C-SVG-1.1/fonts-elem-01-t.svg svg/W3C-SVG-1.1/fonts-elem-02-t.svg svg/W3C-SVG-1.1/fonts-elem-03-b.svg svg/W3C-SVG-1.1/fonts-elem-04-b.svg -svg/W3C-SVG-1.1/fonts-elem-05-t.svg -svg/W3C-SVG-1.1/fonts-elem-06-t.svg svg/W3C-SVG-1.1/fonts-elem-07-b.svg svg/W3C-SVG-1.1/fonts-glyph-02-t.svg -svg/W3C-SVG-1.1/fonts-glyph-03-t.svg -svg/W3C-SVG-1.1/fonts-glyph-04-t.svg -svg/W3C-SVG-1.1/fonts-kern-01-t.svg svg/W3C-SVG-1.1/interact-cursor-01-f.svg -svg/W3C-SVG-1.1/masking-mask-01-b.svg svg/W3C-SVG-1.1/metadata-example-01-b.svg -svg/W3C-SVG-1.1/pservers-grad-08-b.svg -svg/W3C-SVG-1.1/render-elems-06-t.svg -svg/W3C-SVG-1.1/render-elems-07-t.svg svg/W3C-SVG-1.1/render-elems-08-t.svg svg/W3C-SVG-1.1/render-groups-01-b.svg -svg/W3C-SVG-1.1/render-groups-03-t.svg -svg/W3C-SVG-1.1/text-altglyph-01-b.svg svg/W3C-SVG-1.1/text-fonts-01-t.svg svg/W3C-SVG-1.1/text-intro-05-t.svg -svg/W3C-SVG-1.1/text-text-04-t.svg -svg/W3C-SVG-1.1/text-text-05-t.svg -svg/W3C-SVG-1.1/text-text-06-t.svg svg/W3C-SVG-1.1/text-tselect-02-f.svg svg/W3C-SVG-1.1/animate-elem-06-t.svg svg/W3C-SVG-1.1/animate-elem-07-t.svg @@ -100,12 +79,6 @@ svg/W3C-SVG-1.1/text-path-01-b.svg svg/batik/text/smallFonts.svg svg/batik/text/textAnchor.svg svg/batik/text/textBiDi.svg -svg/batik/text/textEffect3.svg -svg/batik/text/textEffect.svg -svg/batik/text/textFeatures.svg -svg/batik/text/textPosition2.svg -svg/batik/text/textProperties2.svg -svg/batik/text/textStyles.svg svg/batik/paints/patternRegions.svg svg/carto.net/button.svg svg/carto.net/colourpicker.svg @@ -120,21 +93,15 @@ svg/custom/circular-marker-reference-4.svg svg/custom/control-points-for-S-and-T.svg svg/custom/coords-relative-units-transforms.svg svg/custom/marker-changes.svg -svg/custom/scrolling-embedded-svg-file-image-repaint-problem.html svg/custom/use-referencing-nonexisting-symbol.svg svg/custom/width-full-percentage.svg svg/hixie/text/003.html svg/hixie/text/003a.xml svg/hixie/viewbox/preserveAspectRatio/002.xml -svg/text/text-altglyph-01-b.svg svg/text/text-fonts-01-t.svg svg/text/text-intro-05-t.svg -svg/text/text-text-04-t.svg -svg/text/text-text-05-t.svg -svg/text/text-text-06-t.svg svg/text/text-tselect-02-f.svg tables/mozilla/core/bloomberg.html -tables/mozilla/bugs/bug8381.html tables/mozilla/bugs/bug10633.html tables/mozilla/bugs/bug23151.html tables/mozilla/bugs/bug113424.html diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 1d61eaa532f9..08385658afda 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,30 @@ +2007-12-19 Dan Bernstein + + Reviewed by Darin Adler and Dave Hyatt. + + - Substitute the user's preferred standard font for an unknown primary + font before falling back on the platform's last resort font + + Cannot be tested in DumpRenderTree because it sets the standard font to + Times, which is also the hard-coded last resort font on Mac. + + * css/CSSFontSelector.cpp: + (WebCore::CSSFontSelector::getFontData): Changed the early bail out + condition to allow getting generic font families from settings even if + there are not @font-face rules. Fixed a typo that mapped fantasy to + cursive. Added a mapping from -webkit-standard to the standard family. + * css/CSSStyleSelector.cpp: + (WebCore::CSSStyleSelector::CSSStyleSelector): Changed to always create + a font selector. + (WebCore::CSSRuleSet::addRulesFromSheet): + (WebCore::CSSStyleSelector::applyProperty): Changed to always use the + font selector. + * css/CSSStyleSelector.h: + (WebCore::CSSStyleSelector::fontSelector): + * platform/graphics/FontCache.cpp: + (WebCore::FontCache::getFontData): Try the user's preferred standard + font before the platform's last resort font. + 2007-12-19 Sven Herzberg Reviewed by Alp Toker. diff --git a/WebCore/css/CSSFontSelector.cpp b/WebCore/css/CSSFontSelector.cpp index 0b92413b4f81..0a8973f944e9 100644 --- a/WebCore/css/CSSFontSelector.cpp +++ b/WebCore/css/CSSFontSelector.cpp @@ -199,7 +199,7 @@ void CSSFontSelector::fontLoaded(CSSFontFace*) FontData* CSSFontSelector::getFontData(const FontDescription& fontDescription, const AtomicString& familyName) { - if (m_fonts.isEmpty()) + if (m_fonts.isEmpty() && !familyName.startsWith("-webkit-")) return 0; bool bold = fontDescription.bold(); @@ -246,9 +246,11 @@ FontData* CSSFontSelector::getFontData(const FontDescription& fontDescription, c else if (familyName == "-webkit-cursive") genericFamily = settings->cursiveFontFamily(); else if (familyName == "-webkit-fantasy") - genericFamily = settings->cursiveFontFamily(); + genericFamily = settings->fantasyFontFamily(); else if (familyName == "-webkit-monospace") genericFamily = settings->fixedFontFamily(); + else if (familyName == "-webkit-standard") + genericFamily = settings->standardFontFamily(); if (!genericFamily.isEmpty()) return FontCache::getCachedFontData(FontCache::getCachedFontPlatformData(fontDescription, genericFamily)); diff --git a/WebCore/css/CSSStyleSelector.cpp b/WebCore/css/CSSStyleSelector.cpp index 50778d31b01f..ab95a9548f43 100644 --- a/WebCore/css/CSSStyleSelector.cpp +++ b/WebCore/css/CSSStyleSelector.cpp @@ -247,6 +247,7 @@ CSSStyleSelector::CSSStyleSelector(Document* doc, const String& userStyleSheet, init(); m_document = doc; + m_fontSelector = new CSSFontSelector(doc); m_matchAuthorAndUserStyles = matchAuthorAndUserStyles; @@ -298,10 +299,6 @@ CSSStyleSelector::CSSStyleSelector(Document* doc, const String& userStyleSheet, for (; it.current(); ++it) if (it.current()->isCSSStyleSheet() && !it.current()->disabled()) m_authorStyle->addRulesFromSheet(static_cast(it.current()), *m_medium, this); - - // Just delete our font selector if we end up with nothing but invalid @font-face rules. - if (m_fontSelector && m_fontSelector->isEmpty()) - m_fontSelector = 0; } void CSSStyleSelector::init() @@ -1819,14 +1816,14 @@ void CSSRuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluat } else if (item->isFontFaceRule() && styleSelector) { // Add this font face to our set. const CSSFontFaceRule* fontFaceRule = static_cast(item); - styleSelector->ensureFontSelector()->addFontFaceRule(fontFaceRule); + styleSelector->fontSelector()->addFontFaceRule(fontFaceRule); } } // for rules } // if rules } else if (item->isFontFaceRule() && styleSelector) { // Add this font face to our set. const CSSFontFaceRule* fontFaceRule = static_cast(item); - styleSelector->ensureFontSelector()->addFontFaceRule(fontFaceRule); + styleSelector->fontSelector()->addFontFaceRule(fontFaceRule); } } } @@ -3132,23 +3129,23 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value) face = settings->standardFontFamily(); break; case CSS_VAL_SERIF: - face = m_fontSelector ? "-webkit-serif" : settings->serifFontFamily(); + face = "-webkit-serif"; fontDescription.setGenericFamily(FontDescription::SerifFamily); break; case CSS_VAL_SANS_SERIF: - face = m_fontSelector ? "-webkit-sans-serif" : settings->sansSerifFontFamily(); + face = "-webkit-sans-serif"; fontDescription.setGenericFamily(FontDescription::SansSerifFamily); break; case CSS_VAL_CURSIVE: - face = m_fontSelector ? "-webkit-cursive" : settings->cursiveFontFamily(); + face = "-webkit-cursive"; fontDescription.setGenericFamily(FontDescription::CursiveFamily); break; case CSS_VAL_FANTASY: - face = m_fontSelector ? "-webkit-fantasy" : settings->fantasyFontFamily(); + face = "-webkit-fantasy"; fontDescription.setGenericFamily(FontDescription::FantasyFamily); break; case CSS_VAL_MONOSPACE: - face = m_fontSelector ? "-webkit-monospace" : settings->fixedFontFamily(); + face = "-webkit-monospace"; fontDescription.setGenericFamily(FontDescription::MonospaceFamily); break; } @@ -4720,11 +4717,4 @@ bool CSSStyleSelector::hasSelectorForAttribute(const AtomicString &attrname) return m_selectorAttrs.contains(attrname.impl()); } -CSSFontSelector* CSSStyleSelector::ensureFontSelector() -{ - if (!m_fontSelector.get()) - m_fontSelector = new CSSFontSelector(m_document); - return m_fontSelector.get(); -} - } // namespace WebCore diff --git a/WebCore/css/CSSStyleSelector.h b/WebCore/css/CSSStyleSelector.h index 0ccf7d57ebff..a844e5c06eee 100644 --- a/WebCore/css/CSSStyleSelector.h +++ b/WebCore/css/CSSStyleSelector.h @@ -128,7 +128,6 @@ class StyledElement; bool hasSelectorForAttribute(const AtomicString &attrname); CSSFontSelector* fontSelector() { return m_fontSelector.get(); } - CSSFontSelector* ensureFontSelector(); protected: diff --git a/WebCore/platform/graphics/FontCache.cpp b/WebCore/platform/graphics/FontCache.cpp index d1aba16ec041..7cf9fbb280c3 100644 --- a/WebCore/platform/graphics/FontCache.cpp +++ b/WebCore/platform/graphics/FontCache.cpp @@ -252,10 +252,19 @@ const FontData* FontCache::getFontData(const Font& font, int& familyIndex, FontS // Geeza Pro font. result = getSimilarFontPlatformData(font); - if (!result && startIndex == 0) - // We still don't have a result. Hand back our last resort fallback font. We only do the last resort fallback - // when trying to find the primary font. Otherwise our fallback will rely on the actual characters used. + if (!result && startIndex == 0) { + // If it's the primary font that we couldn't find, we try the following. In all other cases, we will + // just use per-character system fallback. + + if (fontSelector) { + // Try the user's preferred standard font. + if (FontData* data = fontSelector->getFontData(font.fontDescription(), "-webkit-standard")) + return data; + } + + // Still no result. Hand back our last resort fallback font. result = getLastResortFallbackFont(font.fontDescription()); + } // Now that we have a result, we need to go from FontPlatformData -> FontData. return getCachedFontData(result); -- 2.36.0