diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-19 20:23:04 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-19 20:23:04 +0000 |
commit | 990000e307fe52b5a27f9a93dcab89f8b449beec (patch) | |
tree | 796c4c80555dcdcc1359b52b2785525c8ef3934d | |
parent | a883abac6b4ef01883f84ca839c7d2dce7fd45cd (diff) | |
download | chromium_src-990000e307fe52b5a27f9a93dcab89f8b449beec.zip chromium_src-990000e307fe52b5a27f9a93dcab89f8b449beec.tar.gz chromium_src-990000e307fe52b5a27f9a93dcab89f8b449beec.tar.bz2 |
Match Windows font metrics on Linux.
With this change, many layout tests involving text match render trees
exactly. By turning off anti-aliasing we also almost match pixel
exact. There are a couple of single-pixel differences between Win32 font
rendering and FreeType however (see the bottom left pixel of an 'a'
glyph for example), so we aren't quite pixel-for-pixel yet.
Mike Reed expects to redo much of the font configuration code in Skia to
cope with complex text and subpixel text so, for now, I'm not going to
have anti-aliasing be a command line flag etc.
Review URL: http://codereview.chromium.org/11284
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5704 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 98 insertions, 18 deletions
diff --git a/skia/ports/SkFontHost_fontconfig.cpp b/skia/ports/SkFontHost_fontconfig.cpp index cb95a60..f36bb2e 100644 --- a/skia/ports/SkFontHost_fontconfig.cpp +++ b/skia/ports/SkFontHost_fontconfig.cpp @@ -278,13 +278,8 @@ void SkFontHost::Serialize(const SkTypeface*, SkWStream*) { SkScalerContext* SkFontHost::CreateFallbackScalerContext (const SkScalerContext::Rec& rec) { - FcPattern* pattern = FcPatternCreate(); - FcConfigSubstitute(0, pattern, FcMatchPattern); - FcDefaultSubstitute(pattern); - - FcResult result; - FcPattern* match = FcFontMatch(0, pattern, &result); - FcPatternDestroy(pattern); + FcPattern* match = FontMatch(FC_FAMILY, FcTypeString, "serif", + NULL); // This will fail when we have no fonts on the system. SkASSERT(match); diff --git a/webkit/port/platform/graphics/chromium/FontPlatformDataLinux.cpp b/webkit/port/platform/graphics/chromium/FontPlatformDataLinux.cpp index b047cb334..a3d9dd0 100644 --- a/webkit/port/platform/graphics/chromium/FontPlatformDataLinux.cpp +++ b/webkit/port/platform/graphics/chromium/FontPlatformDataLinux.cpp @@ -58,7 +58,7 @@ void FontPlatformData::setupPaint(SkPaint* paint) const { const float ts = m_textSize > 0 ? m_textSize : 12; - paint->setAntiAlias(true); + paint->setAntiAlias(false); paint->setSubpixelText(false); paint->setTextSize(SkFloatToScalar(ts)); paint->setTypeface(m_typeface); diff --git a/webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp b/webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp index 7371275..29b5d74 100644 --- a/webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp +++ b/webkit/port/platform/graphics/chromium/SimpleFontDataLinux.cpp @@ -29,17 +29,13 @@ void SimpleFontData::platformInit() m_font.setupPaint(&paint); paint.getFontMetrics(&metrics); - // use ceil instead of round to favor descent, given a lot of accidental - // clipping of descenders (e.g. 14pt 'g') in textedit fields - const int descent = SkScalarCeil(metrics.fDescent); - const int span = SkScalarRound(metrics.fDescent - metrics.fAscent); - const int ascent = span - descent; - - m_ascent = ascent; - m_descent = descent; + // Beware those who step here: This code is designed to match Win32 font + // metrics *exactly*. + m_ascent = SkScalarCeil(-metrics.fAscent); + m_descent = SkScalarCeil(metrics.fDescent); m_xHeight = SkScalarToFloat(-metrics.fAscent) * 0.56f; // hack I stole from the Windows port - m_lineSpacing = ascent + descent; - m_lineGap = SkScalarRound(metrics.fLeading); + m_lineGap = SkScalarCeil(metrics.fLeading); + m_lineSpacing = m_ascent + m_descent + m_lineGap; // In WebKit/WebCore/platform/graphics/SimpleFontData.cpp, m_spaceWidth is // calculated for us, but we need to calculate m_maxCharWidth and diff --git a/webkit/tools/test_shell/resources/linux-fontconfig-config b/webkit/tools/test_shell/resources/linux-fontconfig-config new file mode 100644 index 0000000..57757c3 --- /dev/null +++ b/webkit/tools/test_shell/resources/linux-fontconfig-config @@ -0,0 +1,76 @@ +<?xml version="1.0"?> +<!DOCTYPE fontconfig SYSTEM "fonts.dtd"> +<!-- /etc/fonts/fonts.conf file to configure system font access --> +<fontconfig> + <match target="pattern"> + <test qual="any" name="family"> + <string>Times</string> + </test> + <edit name="family" mode="assign"> + <string>Times New Roman</string> + </edit> + </match> + + <match target="pattern"> + <test qual="any" name="family"> + <string>sans</string> + </test> + <edit name="family" mode="assign"> + <string>Arial</string> + </edit> + </match> + + <match target="pattern"> + <test qual="any" name="family"> + <string>sans serif</string> + </test> + <edit name="family" mode="assign"> + <string>Arial</string> + </edit> + </match> + + <match target="pattern"> + <test qual="any" name="family"> + <string>sans-serif</string> + </test> + <edit name="family" mode="assign"> + <string>Arial</string> + </edit> + </match> + + <match target="pattern"> + <test qual="any" name="family"> + <string>serif</string> + </test> + <edit name="family" mode="assign"> + <string>Times New Roman</string> + </edit> + </match> + + <match target="pattern"> + <test qual="any" name="family"> + <string>mono</string> + </test> + <edit name="family" mode="assign"> + <string>Courier New</string> + </edit> + </match> + + <match target="pattern"> + <test qual="any" name="family"> + <string>monospace</string> + </test> + <edit name="family" mode="assign"> + <string>Courier New</string> + </edit> + </match> + + <match target="pattern"> + <test qual="any" name="family"> + <string>Courier</string> + </test> + <edit name="family" mode="assign"> + <string>Courier New</string> + </edit> + </match> +</fontconfig> diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc index 6f072b6..7ef9db3 100644 --- a/webkit/tools/test_shell/test_shell_gtk.cc +++ b/webkit/tools/test_shell/test_shell_gtk.cc @@ -61,8 +61,21 @@ void TestShell::InitializeTestShell(bool interactive) { NULL }; + // We have fontconfig parse a config file from our resources directory. This + // sets a number of aliases ("sans"->"Arial" etc), but doesn't include any + // font directories. + FilePath path; + PathService::Get(base::DIR_SOURCE_ROOT, &path); + path.Append("webkti/tools/test_shell/resources/linux-fontconfig-config"); + FcInit(); + FcConfig* fontcfg = FcConfigCreate(); + if (!FcConfigParseAndLoad(fontcfg, (const FcChar8*) path.value().c_str(), + true)) { + LOG(FATAL) << "Failed to parse fontconfig config file"; + } + for (unsigned i = 0; fonts[i]; ++i) { if (access(fonts[i], R_OK)) { LOG(FATAL) << "You are missing " << fonts[i] << ". " |