<rdar://problem/9528843> STIX glyphs not rendered on this stackoverflow answer
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Sep 2011 22:32:43 +0000 (22:32 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Sep 2011 22:32:43 +0000 (22:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67444

Reviewed by Darin Adler.

Source/WebCore:

Test: fast/text/fallback-traits-fixup.html

After obtaining STIX Regular as a fallback font for some characters, getFontDataForCharacters()
proceeded to ask for a font from the same family having the desired traits and weight (because
wkGetFontInLanguageForRange() does not preserve traits and weight). The returned font was different
and happened to not contain the desired character.

* platform/graphics/mac/FontCacheMac.mm:
(WebCore::FontCache::getFontDataForCharacters): Only ask for a family member with the desired
traits and weight if the substitute font does not already have them, and only use the returned
member if it actually contains the desired character.

LayoutTests:

* fast/text/fallback-traits-fixup.html: Added.
* platform/mac/fast/text/fallback-traits-fixup-expected.png: Added.
* platform/mac/fast/text/fallback-traits-fixup-expected.txt: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@94352 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/text/fallback-traits-fixup.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/text/fallback-traits-fixup-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/text/fallback-traits-fixup-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/mac/FontCacheMac.mm

index 7296f3ea74ed57c597188f89695fe48b34cf739a..a83637f7e20178e45244f8b8bb1b2380301afbac 100644 (file)
@@ -1,3 +1,14 @@
+2011-09-01  Dan Bernstein  <mitz@apple.com>
+
+        <rdar://problem/9528843> STIX glyphs not rendered on this stackoverflow answer
+        https://bugs.webkit.org/show_bug.cgi?id=67444
+
+        Reviewed by Darin Adler.
+
+        * fast/text/fallback-traits-fixup.html: Added.
+        * platform/mac/fast/text/fallback-traits-fixup-expected.png: Added.
+        * platform/mac/fast/text/fallback-traits-fixup-expected.txt: Added.
+
 2011-09-01  James Robinson  <jamesr@chromium.org>
 
         [chromium] Update more SVG baselines
diff --git a/LayoutTests/fast/text/fallback-traits-fixup.html b/LayoutTests/fast/text/fallback-traits-fixup.html
new file mode 100644 (file)
index 0000000..df67f20
--- /dev/null
@@ -0,0 +1,10 @@
+<p>
+    Test for <i><a href="rdar://problem/9528843">rdar://problem/9528843</a>
+    STIX glyphs not rendered on this stackoverflow answer</i>.
+</p>
+<p>
+    A black circle: <span style="font-size: xx-large;">&#x26ab;</span>
+</p>
+<p>
+    Another black circle: <span style="font-size: xx-large; font-weight: bold;">&#x26ab;</span>
+</p>
diff --git a/LayoutTests/platform/mac/fast/text/fallback-traits-fixup-expected.png b/LayoutTests/platform/mac/fast/text/fallback-traits-fixup-expected.png
new file mode 100644 (file)
index 0000000..5d0dcd5
Binary files /dev/null and b/LayoutTests/platform/mac/fast/text/fallback-traits-fixup-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/text/fallback-traits-fixup-expected.txt b/LayoutTests/platform/mac/fast/text/fallback-traits-fixup-expected.txt
new file mode 100644 (file)
index 0000000..e04355e
--- /dev/null
@@ -0,0 +1,31 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x576
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 53x18
+          text run at (0,0) width 53: "Test for "
+        RenderInline {I} at (0,0) size 507x18
+          RenderInline {A} at (0,0) size 154x18 [color=#0000EE]
+            RenderText {#text} at (53,0) size 154x18
+              text run at (53,0) width 154: "rdar://problem/9528843"
+          RenderText {#text} at (207,0) size 353x18
+            text run at (207,0) width 4: " "
+            text run at (211,0) width 349: "STIX glyphs not rendered on this stackoverflow answer"
+        RenderText {#text} at (560,0) size 4x18
+          text run at (560,0) width 4: "."
+      RenderBlock {P} at (0,34) size 784x49
+        RenderText {#text} at (0,20) size 96x18
+          text run at (0,20) width 96: "A black circle: "
+        RenderInline {SPAN} at (0,0) size 24x37
+          RenderText {#text} at (96,5) size 24x37
+            text run at (96,5) width 24: "\x{26AB}"
+        RenderText {#text} at (0,0) size 0x0
+      RenderBlock {P} at (0,99) size 784x49
+        RenderText {#text} at (0,20) size 136x18
+          text run at (0,20) width 136: "Another black circle: "
+        RenderInline {SPAN} at (0,0) size 25x37
+          RenderText {#text} at (136,5) size 25x37
+            text run at (136,5) width 25: "\x{26AB}"
+        RenderText {#text} at (0,0) size 0x0
index 26bdeb136cc3749c6bdafe4258a3ceb724d2e22d..c748c13b82dba2f8932e57f6f9914b6d64004099 100644 (file)
@@ -1,3 +1,22 @@
+2011-09-01  Dan Bernstein  <mitz@apple.com>
+
+        <rdar://problem/9528843> STIX glyphs not rendered on this stackoverflow answer
+        https://bugs.webkit.org/show_bug.cgi?id=67444
+
+        Reviewed by Darin Adler.
+
+        Test: fast/text/fallback-traits-fixup.html
+
+        After obtaining STIX Regular as a fallback font for some characters, getFontDataForCharacters()
+        proceeded to ask for a font from the same family having the desired traits and weight (because
+        wkGetFontInLanguageForRange() does not preserve traits and weight). The returned font was different
+        and happened to not contain the desired character.
+
+        * platform/graphics/mac/FontCacheMac.mm:
+        (WebCore::FontCache::getFontDataForCharacters): Only ask for a family member with the desired
+        traits and weight if the substitute font does not already have them, and only use the returned
+        member if it actually contains the desired character.
+
 2011-09-01  Kentaro Hara  <haraken@google.com>
 
         Generate an XSLTProcessor constructor of V8 using the IDL 'Constructor' extended attribute
index 5a9b50c38175e0f7325d5e366a552079e143c9d3..fc119f190f3118cd7876ef02a72a6ec9c98fc07f 100644 (file)
@@ -101,7 +101,9 @@ static inline bool isAppKitFontWeightBold(NSInteger appKitFontWeight)
 
 const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length)
 {
-    const FontPlatformData& platformData = font.fontDataAt(0)->fontDataForCharacter(characters[0])->platformData();
+    UChar32 character;
+    U16_GET(characters, 0, 0, length, character);
+    const FontPlatformData& platformData = font.fontDataAt(0)->fontDataForCharacter(character)->platformData();
     NSFont *nsFont = platformData.font();
 
     NSString *string = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(characters) length:length freeWhenDone:NO];
@@ -140,13 +142,21 @@ const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, cons
         size = font.pixelSize();
     }
 
-    if (NSFont *bestVariation = [fontManager fontWithFamily:[substituteFont familyName] traits:traits weight:weight size:size])
-        substituteFont = bestVariation;
+    NSFontTraitMask substituteFontTraits = [fontManager traitsOfFont:substituteFont];
+    NSInteger substituteFontWeight = [fontManager weightOfFont:substituteFont];
+
+    if (traits != substituteFontTraits || weight != substituteFontWeight) {
+        if (NSFont *bestVariation = [fontManager fontWithFamily:[substituteFont familyName] traits:traits weight:weight size:size]) {
+            if (([fontManager traitsOfFont:bestVariation] != substituteFontTraits || [fontManager weightOfFont:bestVariation] != substituteFontWeight)
+                && [[bestVariation coveredCharacterSet] longCharacterIsMember:character])
+                substituteFont = bestVariation;
+        }
+    }
 
     substituteFont = font.fontDescription().usePrinterFont() ? [substituteFont printerFont] : [substituteFont screenFont];
 
-    NSFontTraitMask substituteFontTraits = [fontManager traitsOfFont:substituteFont];
-    NSInteger substituteFontWeight = [fontManager weightOfFont:substituteFont];
+    substituteFontTraits = [fontManager traitsOfFont:substituteFont];
+    substituteFontWeight = [fontManager weightOfFont:substituteFont];
 
     FontPlatformData alternateFont(substituteFont, platformData.size(),
         !font.isPlatformFont() && isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(substituteFontWeight),