Check alt text for right-to-left characters and enable bidi processing if they are found. Bug 503269, r+sr=roc

This commit is contained in:
Simon Montagu 2009-07-12 06:32:48 -07:00
parent f2c74b24fa
commit 650af63626
7 changed files with 48 additions and 20 deletions

View File

@ -641,16 +641,16 @@ PRBool IsBidiControl(PRUint32 aChar)
return (eBidiCat_CC == GetBidiCat(aChar) || ((aChar)&0xfffffe)==LRM_CHAR);
}
PRBool HasRTLChars(nsAString& aString)
PRBool HasRTLChars(const nsAString& aString)
{
// This is used to determine whether to enable bidi if a string has
// right-to-left characters. To simplify things, anything that could be a
// surrogate or RTL presentation form is covered just by testing >= 0xD800).
// It's fine to enable bidi in rare cases where it actually isn't needed.
PRInt32 length = aString.Length();
for (PRInt32 i = 0; i < length; i++) {
if ((UCS2_CHAR_IS_BIDI(aString.CharAt(i)) ) ||
((NS_IS_HIGH_SURROGATE(aString.CharAt(i))) &&
(++i < length) &&
(NS_IS_LOW_SURROGATE(aString.CharAt(i))) &&
(UTF32_CHAR_IS_BIDI(SURROGATE_TO_UCS4(aString.CharAt(i-1),
aString.CharAt(i)))))) {
PRUnichar ch = aString.CharAt(i);
if (ch >= 0xD800 || IS_IN_BMP_RTL_BLOCK(ch)) {
return PR_TRUE;
}
}

View File

@ -214,7 +214,7 @@ typedef enum nsCharType nsCharType;
* Give an nsString.
* @return PR_TRUE if the string contains right-to-left characters
*/
PRBool HasRTLChars(nsAString& aString);
PRBool HasRTLChars(const nsAString& aString);
// --------------------------------------------------
// IBMBIDI

View File

@ -944,6 +944,11 @@ nsImageFrame::DisplayAltText(nsPresContext* aPresContext,
const PRUnichar* str = aAltText.get();
PRInt32 strLen = aAltText.Length();
nscoord y = aRect.y;
if (!aPresContext->BidiEnabled() && HasRTLChars(aAltText)) {
aPresContext->SetBidiEnabled();
}
// Always show the first line, even if we have to clip it below
PRBool firstLine = PR_TRUE;
while ((strLen > 0) && (firstLine || (y + maxDescent) < aRect.YMost())) {

View File

@ -0,0 +1,16 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Welcome to Flickr!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<ul>
<li><span><a href="/photos/foo/" title="مسجد قبة الصخرة by Yaqut"><img src="/foo.jpg" width="75" height="75" alt="مسجد قبة الصخرة by Yaqut"></a></span><div>From <a href="/photos/yaqut/" title="Yaqut">Yaqut</a></div></li>
<li><span><a href="/photos/bar/" title="מערכת שליחת ההודעות באתר אורנג עובדת בפיירפוקס - מזל טוב!"><img src="/bar.jpg" width="75" height="75" alt="מערכת שליחת ההודעות באתר אורנג עובדת בפיירפוקס - מזל טוב! by MosheOofnik"></a></span><div>From <a href="/photos/mosheoofnik/" title="MosheOofnik">Moshe Oofnik</a></div></li>
<li><span><a href="/photos/baz/" title="Fruit Basket by Elmo"><img src="/baz.jpg" width="75" height="75" alt="Fruit Basket by Elmo"></a></span><div>From <a href="/photos/elmo/" title="Elmo">Elmo</a></div></li>
</ul>&rlm;
</div>
</body>
</html>

View File

@ -0,0 +1,16 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Welcome to Flickr!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<ul>
<li><span><a href="/photos/foo/" title="مسجد قبة الصخرة by Yaqut"><img src="/foo.jpg" width="75" height="75" alt="مسجد قبة الصخرة by Yaqut"></a></span><div>From <a href="/photos/yaqut/" title="Yaqut">Yaqut</a></div></li>
<li><span><a href="/photos/bar/" title="מערכת שליחת ההודעות באתר אורנג עובדת בפיירפוקס - מזל טוב!"><img src="/bar.jpg" width="75" height="75" alt="מערכת שליחת ההודעות באתר אורנג עובדת בפיירפוקס - מזל טוב! by MosheOofnik"></a></span><div>From <a href="/photos/mosheoofnik/" title="MosheOofnik">Moshe Oofnik</a></div></li>
<li><span><a href="/photos/baz/" title="Fruit Basket by Elmo"><img src="/baz.jpg" width="75" height="75" alt="Fruit Basket by Elmo"></a></span><div>From <a href="/photos/elmo/" title="Elmo">Elmo</a></div></li>
</ul>
</div>
</body>
</html>

View File

@ -41,3 +41,4 @@ random-if(MOZ_WIDGET_TOOLKIT=="gtk2") == 386339.html 386339-ref.html
== 489887-1.html 489887-1-ref.html
== 492231-1.html 492231-1-ref.html
== 496006-1.html 496006-1-ref.html
== 503269-1.html 503269-1-ref.html

View File

@ -1351,18 +1351,8 @@ nsTreeBodyFrame::CheckTextForBidi(nsAutoString& aText)
// We could check to see whether the prescontext already has bidi enabled,
// but usually it won't, so it's probably faster to avoid the call to
// GetPresContext() when it's not needed.
const PRUnichar* text = aText.get();
PRUint32 length = aText.Length();
PRUint32 i;
for (i = 0; i < length; ++i) {
PRUnichar ch = text[i];
// To simplify things, anything that could be a surrogate or RTL
// presentation form is covered just by testing >= 0xD800). It's fine to
// enable bidi in rare cases where it actually isn't needed.
if (ch >= 0xD800 || IS_IN_BMP_RTL_BLOCK(ch)) {
PresContext()->SetBidiEnabled();
break;
}
if (HasRTLChars(aText)) {
PresContext()->SetBidiEnabled();
}
}