Bug 476378. Use U+002D instead of U+2010 for a soft hyphen if the first font in the fontgroup doesn't have a glyph for U+2010. r+sr=roc
authorJonathan Kew <jfkthame@gmail.com>
Thu, 05 Feb 2009 21:23:50 +1300
changeset 23446 3289ec4eeae742bf6dd4d77192f40d8c5b4ec528
parent 23445 23adc0bc597d8fea598f521de437fa62dcd69405
child 23447 f5c3154cf35a9c53b182b284944ee9cae8a51512
push id778
push userrocallahan@mozilla.com
push dateThu, 26 Feb 2009 09:56:42 +0000
bugs476378
milestone1.9.1b3pre
Bug 476378. Use U+002D instead of U+2010 for a soft hyphen if the first font in the fontgroup doesn't have a glyph for U+2010. r+sr=roc
layout/generic/nsTextFrameThebes.cpp
layout/reftests/text/444656-ref.html
layout/reftests/text/476378-soft-hyphen-fallback-ref.html
layout/reftests/text/476378-soft-hyphen-fallback.html
layout/reftests/text/reftest.list
layout/reftests/text/soft-hyphens-1-ref.html
--- a/layout/generic/nsTextFrameThebes.cpp
+++ b/layout/generic/nsTextFrameThebes.cpp
@@ -1454,24 +1454,25 @@ GetHyphenTextRun(gfxTextRun* aTextRun, g
     ctx = GetReferenceRenderingContext(aTextFrame, nsnull);
   }
   if (!ctx)
     return nsnull;
 
   gfxFontGroup* fontGroup = aTextRun->GetFontGroup();
   PRUint32 flags = gfxFontGroup::TEXT_IS_PERSISTENT;
 
+  // only use U+2010 if it is supported by the first font in the group;
+  // it's better to use ASCII '-' from the primary font than to fall back to U+2010
+  // from some other, possibly poorly-matching face
   static const PRUnichar unicodeHyphen = 0x2010;
-  gfxTextRun* textRun =
-    gfxTextRunCache::MakeTextRun(&unicodeHyphen, 1, fontGroup, ctx,
-                                 aTextRun->GetAppUnitsPerDevUnit(), flags);
-  if (textRun && textRun->CountMissingGlyphs() == 0)
-    return textRun;
-
-  gfxTextRunCache::ReleaseTextRun(textRun);
+  gfxFont *font = fontGroup->GetFontAt(0);
+  if (font && font->HasCharacter(unicodeHyphen)) {
+    return gfxTextRunCache::MakeTextRun(&unicodeHyphen, 1, fontGroup, ctx,
+                                        aTextRun->GetAppUnitsPerDevUnit(), flags);
+  }
 
   static const PRUint8 dash = '-';
   return gfxTextRunCache::MakeTextRun(&dash, 1, fontGroup, ctx,
                                       aTextRun->GetAppUnitsPerDevUnit(),
                                       flags);
 }
 
 static gfxFont::Metrics
--- a/layout/reftests/text/444656-ref.html
+++ b/layout/reftests/text/444656-ref.html
@@ -1,12 +1,12 @@
 <!DOCTYPE html>
 <html>
  <head>
   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
   <title>Test soft hyphen in rtl text</title>
  </head>
  <body dir="rtl">
   <p>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכל</p>
-  <p>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת&#x2010;<br>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת&#x2010;<br>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת&#x2010;<br>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת&#x2010;<br>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת&#x2010;<br>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת&#x2010;<br>אבגדהוזחטיכלמנסעפצקרשת</p>
+  <p>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת-<br>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת-<br>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת-<br>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת-<br>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת-<br>אבגדהוזחטיכלמנסעפצקרשתאבגדהוזחטיכלמנסעפצקרשת-<br>אבגדהוזחטיכלמנסעפצקרשת</p>
   </p>
  </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/text/476378-soft-hyphen-fallback-ref.html
@@ -0,0 +1,19 @@
+<html>
+<head>
+<title>Soft hyphen font fallback (for bug 476378)</title>
+</head>
+<body>
+
+<!-- On OS X, Hoefler Text has a distinctive hyphen; on Windows, Segoe UI does.
+     In each case U+2010 will fall back to a font with a very different glyph. -->
+<div style="width: 50pt;
+     font-family: Hoefler Text, Segoe UI, Trebuchet MS, Lucida Grande;
+     font-size: 24pt;">
+
+<!-- reference text uses an explicit ASCII hyphen at the expected break point -->
+<p>aaa-<br>aa</p>
+
+</div>
+
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/text/476378-soft-hyphen-fallback.html
@@ -0,0 +1,19 @@
+<html>
+<head>
+<title>Soft hyphen font fallback (for bug 476378)</title>
+</head>
+<body>
+
+<!-- On OS X, Hoefler Text has a distinctive hyphen; on Windows, Segoe UI does.
+     In each case U+2010 will fall back to a font with a very different glyph. -->
+<div style="width: 50pt;
+     font-family: Hoefler Text, Segoe UI, Trebuchet MS, Lucida Grande;
+     font-size: 24pt;">
+
+<!-- test whether soft-hyphen gets rendered from the primary font -->
+<p>aaa&shy;aa</p>
+
+</div>
+
+</body>
+</html>
--- a/layout/reftests/text/reftest.list
+++ b/layout/reftests/text/reftest.list
@@ -26,10 +26,11 @@ random-if(MOZ_WIDGET_TOOLKIT=="gtk2") ==
 != wordwrap-09.html wordwrap-01-ref.html
 == wordwrap-09.html wordwrap-09-ref.html
 == zwnj-01.html zwnj-01-ref.html
 HTTP(..) == zwnj-02.xhtml zwnj-02-ref.xhtml # HTTP(..) for ../filters.svg
 random-if(MOZ_WIDGET_TOOLKIT=="gtk2") != zwnj-01.html zwnj-01-notref.html # Bad fonts on the tinderbox -- works locally
 fails-if(MOZ_WIDGET_TOOLKIT=="windows") == cgj-01.html cgj-01-ref.html # bug 455455
 == 444656.html 444656-ref.html
 == 449555-1.html 449555-1-ref.html
+== 476378-soft-hyphen-fallback.html 476378-soft-hyphen-fallback-ref.html
 random-if(MOZ_WIDGET_TOOLKIT=="windows") HTTP(..) == 475092-sub.html 475092-ref.html
 random-if(MOZ_WIDGET_TOOLKIT=="gtk2") HTTP(..) == 475092-pos.html 475092-sub.html
--- a/layout/reftests/text/soft-hyphens-1-ref.html
+++ b/layout/reftests/text/soft-hyphens-1-ref.html
@@ -1,13 +1,13 @@
 <html>
 <body>
 
 <div>
-<p>Hy&#x2010;<br>phen.
-<p>Hy&#x2010;<br>phen.
-<p>Hy&#x2010;<br>phen.
-<p>Hy&#x2010;<br>phen.
-<p>Hy&#x2010;<br>phen.
+<p>Hy-<br>phen.
+<p>Hy-<br>phen.
+<p>Hy-<br>phen.
+<p>Hy-<br>phen.
+<p>Hy-<br>phen.
 </div>
 
 </body>
 </html>