Bug 1351332 gfxDWriteFontList and gfxGDIFontList should ignore italic face of Meiryo for using synthetic italic style r?jfkthame
Meiryo has same glyph for both normal style and italic/oblique style. Therefore, if we will use it as default Japanese font, italic/oblique style won't be used in Japanese text. It's too bad for <em>, <i> and backward compatibility with MS PGothic.
This patch makes gfxDWriteFontList and gfxGDIFontList ignore italic style face(s) of Meiryo at creating Meiryo's font face list.
Note that in GDI mode, font names are localized. Therefore, we need to compare with both English name and Japanese name. However, in DirectWrite mode, face names are not localized. Therefore, it's enough to compare only with English face names.
MozReview-Commit-ID: 60tFxB0jcd
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -179,16 +179,26 @@ gfxDWriteFontFamily::FindStyleVariations
nsAutoString faceName;
hr = GetDirectWriteFontName(font, faceName);
if (FAILED(hr)) {
continue;
}
fullID.Append(' ');
fullID.Append(faceName);
+ // Ignore italic style's "Meiryo" because "Meiryo (Bold) Italic" has
+ // non-italic style glyphs as Japanese characters. However, using it
+ // causes serious problem if web pages wants some elements to be
+ // different style from others only with font-style. For example,
+ // <em> and <i> should be rendered as italic in the default style.
+ if (fullID.EqualsLiteral("Meiryo Italic") ||
+ fullID.EqualsLiteral("Meiryo Bold Italic")) {
+ continue;
+ }
+
gfxDWriteFontEntry *fe = new gfxDWriteFontEntry(fullID, font);
fe->SetForceGDIClassic(mForceGDIClassic);
AddFontEntry(fe);
// postscript/fullname if needed
nsAutoString psname, fullname;
if (fontInfoShouldHaveFaceNames) {
aFontInfoData->GetFaceNames(fe->Name(), fullname, psname);
--- a/gfx/thebes/gfxGDIFontList.cpp
+++ b/gfx/thebes/gfxGDIFontList.cpp
@@ -408,25 +408,41 @@ GDIFontEntry::AddSizeOfIncludingThis(Mal
}
/***************************************************************
*
* GDIFontFamily
*
*/
+static bool
+ShouldIgnoreItalicStyle(const nsAString& aName)
+{
+ // Ignore italic style's "Meiryo" because "Meiryo (Bold) Italic" has
+ // non-italic style glyphs as Japanese characters. However, using it
+ // causes serious problem if web pages wants some elements to be
+ // different style from others only with font-style. For example,
+ // <em> and <i> should be rendered as italic in the default style.
+ return aName.EqualsLiteral("Meiryo") ||
+ aName.Equals(NS_LITERAL_STRING(u"\x30E1\x30A4\x30EA\x30AA"));
+}
+
int CALLBACK
GDIFontFamily::FamilyAddStylesProc(const ENUMLOGFONTEXW *lpelfe,
const NEWTEXTMETRICEXW *nmetrics,
DWORD fontType, LPARAM data)
{
const NEWTEXTMETRICW& metrics = nmetrics->ntmTm;
LOGFONTW logFont = lpelfe->elfLogFont;
GDIFontFamily *ff = reinterpret_cast<GDIFontFamily*>(data);
+ if (logFont.lfItalic && ShouldIgnoreItalicStyle(ff->mName)) {
+ return 1;
+ }
+
// Some fonts claim to support things > 900, but we don't so clamp the sizes
logFont.lfWeight = clamped(logFont.lfWeight, LONG(100), LONG(900));
gfxWindowsFontType feType = GDIFontEntry::DetermineFontType(metrics, fontType);
GDIFontEntry *fe = nullptr;
for (uint32_t i = 0; i < ff->mAvailableFonts.Length(); ++i) {
fe = static_cast<GDIFontEntry*>(ff->mAvailableFonts[i].get());
@@ -526,24 +542,33 @@ GDIFontFamily::FindStyleVariations(FontI
if (mIsBadUnderlineFamily) {
SetBadUnderlineFonts();
}
// check for existence of italic face(s); if present, set the
// FamilyHasItalic flag on all faces so that we'll know *not*
// to use GDI's fake-italic effect with them
- size_t count = mAvailableFonts.Length();
- for (size_t i = 0; i < count; ++i) {
- if (mAvailableFonts[i]->IsItalic()) {
- for (uint32_t j = 0; j < count; ++j) {
- static_cast<GDIFontEntry*>(mAvailableFonts[j].get())->
- mFamilyHasItalicFace = true;
+
+ // If we ignored italic face(s), we should mark this has italic face.
+ bool hasItalicFace = ShouldIgnoreItalicStyle(mName);
+
+ if (!hasItalicFace) {
+ for (RefPtr<gfxFontEntry>& fontEntry : mAvailableFonts) {
+ if (fontEntry->IsItalic()) {
+ hasItalicFace = true;
+ break;
}
- break;
+ }
+ }
+
+ if (hasItalicFace) {
+ for (RefPtr<gfxFontEntry>& fontEntry : mAvailableFonts) {
+ static_cast<GDIFontEntry*>(fontEntry.get())->
+ mFamilyHasItalicFace = true;
}
}
}
/***************************************************************
*
* gfxGDIFontList
*
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-face/meiryo-en-bold.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML><html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style type="text/css">
+body { margin: 50px; font-size: 72pt; }
+#test { font-family: "Meiryo"; font-weight: bold; font-style: normal; }
+</style>
+</head>
+<body><p id="test">魅力的な人</p></body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-face/meiryo-en-bolditalic.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML><html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style type="text/css">
+body { margin: 50px; font-size: 72pt; }
+#test { font-family: "Meiryo"; font-weight: bold; font-style: italic; }
+</style>
+</head>
+<body><p id="test">魅力的な人</p></body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-face/meiryo-en-italic.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML><html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style type="text/css">
+body { margin: 50px; font-size: 72pt; }
+#test { font-family: "Meiryo"; font-weight: normal; font-style: italic; }
+</style>
+</head>
+<body><p id="test">魅力的な人</p></body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-face/meiryo-en-oblique.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML><html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style type="text/css">
+body { margin: 50px; font-size: 72pt; }
+#test { font-family: "Meiryo"; font-style: oblique; }
+</style>
+</head>
+<body><p id="test">魅力的な人</p></body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-face/meiryo-en.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML><html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style type="text/css">
+body { margin: 50px; font-size: 72pt; }
+#test { font-family: "Meiryo"; font-weight: normal; font-style: normal; }
+</style>
+</head>
+<body><p id="test">魅力的な人</p></body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-face/meiryo-ja-bold.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML><html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style type="text/css">
+body { margin: 50px; font-size: 72pt; }
+#test { font-family: "メイリオ"; font-weight: bold; font-style: normal; }
+</style>
+</head>
+<body><p id="test">魅力的な人</p></body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-face/meiryo-ja-bolditalic.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML><html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style type="text/css">
+body { margin: 50px; font-size: 72pt; }
+#test { font-family: "メイリオ"; font-weight: bold; font-style: italic; }
+</style>
+</head>
+<body><p id="test">魅力的な人</p></body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-face/meiryo-ja-italic.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML><html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style type="text/css">
+body { margin: 50px; font-size: 72pt; }
+#test { font-family: "メイリオ"; font-weight: normal; font-style: italic; }
+</style>
+</head>
+<body><p id="test">魅力的な人</p></body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-face/meiryo-ja-oblique.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML><html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style type="text/css">
+body { margin: 50px; font-size: 72pt; }
+#test { font-family: "メイリオ"; font-style: oblique; }
+</style>
+</head>
+<body><p id="test">魅力的な人</p></body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/font-face/meiryo-ja.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML><html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style type="text/css">
+body { margin: 50px; font-size: 72pt; }
+#test { font-family: "メイリオ"; font-weight: normal; font-style: normal; }
+</style>
+</head>
+<body><p id="test">魅力的な人</p></body>
+</html>
\ No newline at end of file
--- a/layout/reftests/font-face/reftest.list
+++ b/layout/reftests/font-face/reftest.list
@@ -179,8 +179,19 @@ HTTP(..) == reflow-sanity-delay-1a.html
HTTP(..) == reflow-sanity-delay-1b.html reflow-sanity-1-ref.html
HTTP(..) == reflow-sanity-delay-1c.html reflow-sanity-1-ref.html
HTTP(..) == reflow-sanity-delay-1-metrics.html reflow-sanity-1-ref.html
# font-display
pref(layout.css.font-display.enabled,true) HTTP(..) == font-display-1.html font-display-1-ref.html # normal font load (~500ms)
pref(layout.css.font-display.enabled,true) fuzzy-if(OSX==1010,3,5) HTTP(..) == font-display-2.html font-display-2-ref.html # font load takes 4500ms
+# Testing hack for Meiryo
+== meiryo-en.html meiryo-ja.html
+== meiryo-en-bold.html meiryo-ja-bold.html
+== meiryo-en-italic.html meiryo-ja-italic.html
+== meiryo-en-oblique.html meiryo-ja-oblique.html
+== meiryo-en-bolditalic.html meiryo-ja-bolditalic.html
+!= meiryo-en-bold.html meiryo-en.html
+!= meiryo-en-italic.html meiryo-en.html
+!= meiryo-en-oblique.html meiryo-en.html
+!= meiryo-en-bolditalic.html meiryo-en.html
+!= meiryo-en-bolditalic.html meiryo-en-bold.html