bug 970891 - don't assume the primary font will always support the <space> character - fall back down the font stack if necessary. r=roc
authorJonathan Kew <jkew@mozilla.com>
Tue, 11 Feb 2014 15:28:21 +0000
changeset 190815 1c83d1306f2a52596208045a1685788c8df05170
parent 190805 c9f09336bc6c6d350dbffb0f9eba2d0e41a8bb62
child 190816 4e6a6fa1e02572cf2e4944fea1ac5a24d1b5115c
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs970891
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 970891 - don't assume the primary font will always support the <space> character - fall back down the font stack if necessary. r=roc
gfx/thebes/gfxFont.cpp
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -4575,17 +4575,30 @@ gfxFontGroup::MakeSpaceTextRun(const Par
     gfxFont *font = GetFontAt(0);
     if (MOZ_UNLIKELY(GetStyle()->size == 0)) {
         // Short-circuit for size-0 fonts, as Windows and ATSUI can't handle
         // them, and always create at least size 1 fonts, i.e. they still
         // render something for size 0 fonts.
         textRun->AddGlyphRun(font, gfxTextRange::kFontGroup, 0, false);
     }
     else {
-        textRun->SetSpaceGlyph(font, aParams->mContext, 0);
+        if (font->GetSpaceGlyph()) {
+            // Normally, the font has a cached space glyph, so we can avoid
+            // the cost of calling FindFontForChar.
+            textRun->SetSpaceGlyph(font, aParams->mContext, 0);
+        } else {
+            // In case the primary font doesn't have <space> (bug 970891),
+            // find one that does.
+            uint8_t matchType;
+            nsRefPtr<gfxFont> spaceFont =
+                FindFontForChar(' ', 0, MOZ_SCRIPT_LATIN, nullptr, &matchType);
+            if (spaceFont) {
+                textRun->SetSpaceGlyph(spaceFont, aParams->mContext, 0);
+            }
+        }
     }
 
     // Note that the gfxGlyphExtents glyph bounds storage for the font will
     // always contain an entry for the font's space glyph, so we don't have
     // to call FetchGlyphExtents here.
     return textRun;
 }