From e19367ce33245db773985ebd813928348bdce4b8 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 30 Jan 2009 11:43:17 +0330 Subject: [PATCH] Bug 467672 - need additional bidi.numerals setting for Persian (eastern Arabic-Indic) numerals; r=roc,jfkthame sr=roc --- intl/unicharutil/util/nsBidiUtils.cpp | 37 ++++++--- intl/unicharutil/util/nsBidiUtils.h | 9 +-- layout/base/nsBidiPresUtils.cpp | 14 +++- layout/base/tests/Makefile.in | 10 +++ layout/base/tests/bug467672-1-ref.html | 8 ++ layout/base/tests/bug467672-1.html | 8 ++ layout/base/tests/bug467672-2-ref.html | 8 ++ layout/base/tests/bug467672-2.html | 8 ++ layout/base/tests/bug467672-3-ref.html | 8 ++ layout/base/tests/bug467672-3.html | 8 ++ layout/base/tests/bug467672-4-ref.html | 8 ++ layout/base/tests/bug467672-4.html | 8 ++ layout/base/tests/bug467672-5-ref.html | 8 ++ layout/base/tests/bug467672-5.html | 8 ++ layout/base/tests/test_bug441782.html | 101 +++++++++++++++++-------- modules/libpref/src/init/all.js | 2 + 16 files changed, 203 insertions(+), 50 deletions(-) create mode 100644 layout/base/tests/bug467672-1-ref.html create mode 100644 layout/base/tests/bug467672-1.html create mode 100644 layout/base/tests/bug467672-2-ref.html create mode 100644 layout/base/tests/bug467672-2.html create mode 100644 layout/base/tests/bug467672-3-ref.html create mode 100644 layout/base/tests/bug467672-3.html create mode 100644 layout/base/tests/bug467672-4-ref.html create mode 100644 layout/base/tests/bug467672-4.html create mode 100644 layout/base/tests/bug467672-5-ref.html create mode 100644 layout/base/tests/bug467672-5.html diff --git a/intl/unicharutil/util/nsBidiUtils.cpp b/intl/unicharutil/util/nsBidiUtils.cpp index be43b050174..f5fa6bceb56 100644 --- a/intl/unicharutil/util/nsBidiUtils.cpp +++ b/intl/unicharutil/util/nsBidiUtils.cpp @@ -280,14 +280,26 @@ static nsCharType cc2ucd[5] = { }; #define ARABIC_TO_HINDI_DIGIT_INCREMENT (START_HINDI_DIGITS - START_ARABIC_DIGITS) +#define PERSIAN_TO_HINDI_DIGIT_INCREMENT (START_HINDI_DIGITS - START_FARSI_DIGITS) +#define ARABIC_TO_PERSIAN_DIGIT_INCREMENT (START_FARSI_DIGITS - START_ARABIC_DIGITS) #define NUM_TO_ARABIC(c) \ ((((c)>=START_HINDI_DIGITS) && ((c)<=END_HINDI_DIGITS)) ? \ ((c) - (PRUint16)ARABIC_TO_HINDI_DIGIT_INCREMENT) : \ - (c)) + ((((c)>=START_FARSI_DIGITS) && ((c)<=END_FARSI_DIGITS)) ? \ + ((c) - (PRUint16)ARABIC_TO_PERSIAN_DIGIT_INCREMENT) : \ + (c))) #define NUM_TO_HINDI(c) \ ((((c)>=START_ARABIC_DIGITS) && ((c)<=END_ARABIC_DIGITS)) ? \ ((c) + (PRUint16)ARABIC_TO_HINDI_DIGIT_INCREMENT): \ - (c)) + ((((c)>=START_FARSI_DIGITS) && ((c)<=END_FARSI_DIGITS)) ? \ + ((c) + (PRUint16)PERSIAN_TO_HINDI_DIGIT_INCREMENT) : \ + (c))) +#define NUM_TO_PERSIAN(c) \ + ((((c)>=START_HINDI_DIGITS) && ((c)<=END_HINDI_DIGITS)) ? \ + ((c) - (PRUint16)PERSIAN_TO_HINDI_DIGIT_INCREMENT) : \ + ((((c)>=START_ARABIC_DIGITS) && ((c)<=END_ARABIC_DIGITS)) ? \ + ((c) + (PRUint16)ARABIC_TO_PERSIAN_DIGIT_INCREMENT) : \ + (c))) // helper function to reverse a PRUnichar buffer static void ReverseString(PRUnichar* aBuffer, PRUint32 aLen) @@ -560,13 +572,20 @@ PRUnichar HandleNumberInChar(PRUnichar aChar, PRBool aPrevCharArabic, PRUint32 a return NUM_TO_HINDI(aChar); case IBMBIDI_NUMERAL_ARABIC: return NUM_TO_ARABIC(aChar); + case IBMBIDI_NUMERAL_PERSIAN: + return NUM_TO_PERSIAN(aChar); case IBMBIDI_NUMERAL_REGULAR: case IBMBIDI_NUMERAL_HINDICONTEXT: + case IBMBIDI_NUMERAL_PERSIANCONTEXT: // for clipboard handling //XXX do we really want to convert numerals when copying text? - if (aPrevCharArabic) - return NUM_TO_HINDI(aChar); - else + if (aPrevCharArabic) { + if (aNumFlag == IBMBIDI_NUMERAL_PERSIANCONTEXT) + return NUM_TO_PERSIAN(aChar); + else + return NUM_TO_HINDI(aChar); + } + else return NUM_TO_ARABIC(aChar); case IBMBIDI_NUMERAL_NOMINAL: default: @@ -581,8 +600,10 @@ nsresult HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag) switch (aNumFlag) { case IBMBIDI_NUMERAL_HINDI: case IBMBIDI_NUMERAL_ARABIC: + case IBMBIDI_NUMERAL_PERSIAN: case IBMBIDI_NUMERAL_REGULAR: case IBMBIDI_NUMERAL_HINDICONTEXT: + case IBMBIDI_NUMERAL_PERSIANCONTEXT: for (i=0;i0 ? aBuffer[i-1] : 0), aNumFlag); break; @@ -593,12 +614,6 @@ nsresult HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag) return NS_OK; } -nsresult HandleNumbers(const nsString& aSrc, nsString& aDst) -{ - aDst = aSrc; - return HandleNumbers((PRUnichar *)aDst.get(),aDst.Length(), IBMBIDI_NUMERAL_REGULAR); -} - PRUint32 SymmSwap(PRUint32 aChar) { return Mirrored(aChar); diff --git a/intl/unicharutil/util/nsBidiUtils.h b/intl/unicharutil/util/nsBidiUtils.h index b3017f361e7..17befb0f247 100644 --- a/intl/unicharutil/util/nsBidiUtils.h +++ b/intl/unicharutil/util/nsBidiUtils.h @@ -181,13 +181,6 @@ typedef enum nsCharType nsCharType; */ nsresult HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag); - /** - * Scan an nsString, converting numerals to Arabic or Hindi forms - * @param aSrc is the input string - * @param aDst is the output string - */ - nsresult HandleNumbers(const nsString& aSrc, nsString& aDst); - /** * Give a Unicode character, return the symmetric equivalent */ @@ -277,6 +270,8 @@ typedef enum nsCharType nsCharType; #define IBMBIDI_NUMERAL_HINDICONTEXT 2 // 2 = hindicontextnumeralBidi #define IBMBIDI_NUMERAL_ARABIC 3 // 3 = arabicnumeralBidi #define IBMBIDI_NUMERAL_HINDI 4 // 4 = hindinumeralBidi +#define IBMBIDI_NUMERAL_PERSIANCONTEXT 5 // 5 = persiancontextnumeralBidi +#define IBMBIDI_NUMERAL_PERSIAN 6 // 6 = persiannumeralBidi // ------------------ // Support Mode // ------------------ diff --git a/layout/base/nsBidiPresUtils.cpp b/layout/base/nsBidiPresUtils.cpp index bdbb664d00c..2cd91690641 100644 --- a/layout/base/nsBidiPresUtils.cpp +++ b/layout/base/nsBidiPresUtils.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Uri Bernstein * Haamed Gheibi + * Ehsan Akhgari * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -1187,6 +1188,10 @@ nsBidiPresUtils::FormatUnicodeText(nsPresContext* aPresContext, HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); break; + case IBMBIDI_NUMERAL_PERSIAN: + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_PERSIAN); + break; + case IBMBIDI_NUMERAL_REGULAR: switch (aCharType) { @@ -1203,7 +1208,7 @@ nsBidiPresUtils::FormatUnicodeText(nsPresContext* aPresContext, break; } break; - + case IBMBIDI_NUMERAL_HINDICONTEXT: if ( ( (GET_BIDI_OPTION_DIRECTION(bidiOptions)==IBMBIDI_TEXTDIRECTION_RTL) && (IS_ARABIC_DIGIT (aText[0])) ) || (eCharType_ArabicNumber == aCharType) ) HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); @@ -1211,6 +1216,13 @@ nsBidiPresUtils::FormatUnicodeText(nsPresContext* aPresContext, HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); break; + case IBMBIDI_NUMERAL_PERSIANCONTEXT: + if ( ( (GET_BIDI_OPTION_DIRECTION(bidiOptions)==IBMBIDI_TEXTDIRECTION_RTL) && (IS_ARABIC_DIGIT (aText[0])) ) || (eCharType_ArabicNumber == aCharType) ) + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_PERSIAN); + else if (eCharType_EuropeanNumber == aCharType) + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); + break; + case IBMBIDI_NUMERAL_NOMINAL: default: break; diff --git a/layout/base/tests/Makefile.in b/layout/base/tests/Makefile.in index 4303f1d4805..99ce0ddc6e7 100644 --- a/layout/base/tests/Makefile.in +++ b/layout/base/tests/Makefile.in @@ -90,6 +90,16 @@ _TEST_FILES += \ bug441782-4-ref.html \ bug441782-5.html \ bug441782-5-ref.html \ + bug467672-1.html \ + bug467672-1-ref.html \ + bug467672-2.html \ + bug467672-2-ref.html \ + bug467672-3.html \ + bug467672-3-ref.html \ + bug467672-4.html \ + bug467672-4-ref.html \ + bug467672-5.html \ + bug467672-5-ref.html \ $(NULL) endif diff --git a/layout/base/tests/bug467672-1-ref.html b/layout/base/tests/bug467672-1-ref.html new file mode 100644 index 00000000000..5d7965a3499 --- /dev/null +++ b/layout/base/tests/bug467672-1-ref.html @@ -0,0 +1,8 @@ + + + + + +۳۴۵ + + \ No newline at end of file diff --git a/layout/base/tests/bug467672-1.html b/layout/base/tests/bug467672-1.html new file mode 100644 index 00000000000..1e572bd99e9 --- /dev/null +++ b/layout/base/tests/bug467672-1.html @@ -0,0 +1,8 @@ + + + + + +345 + + \ No newline at end of file diff --git a/layout/base/tests/bug467672-2-ref.html b/layout/base/tests/bug467672-2-ref.html new file mode 100644 index 00000000000..2a73b8a25eb --- /dev/null +++ b/layout/base/tests/bug467672-2-ref.html @@ -0,0 +1,8 @@ + + + + + +متن۳۴۵ + + \ No newline at end of file diff --git a/layout/base/tests/bug467672-2.html b/layout/base/tests/bug467672-2.html new file mode 100644 index 00000000000..0ffdb981c75 --- /dev/null +++ b/layout/base/tests/bug467672-2.html @@ -0,0 +1,8 @@ + + + + + +متن345 + + \ No newline at end of file diff --git a/layout/base/tests/bug467672-3-ref.html b/layout/base/tests/bug467672-3-ref.html new file mode 100644 index 00000000000..47e534b0ba7 --- /dev/null +++ b/layout/base/tests/bug467672-3-ref.html @@ -0,0 +1,8 @@ + + + + + +text۳۴۵ + + \ No newline at end of file diff --git a/layout/base/tests/bug467672-3.html b/layout/base/tests/bug467672-3.html new file mode 100644 index 00000000000..60e2e71dbbe --- /dev/null +++ b/layout/base/tests/bug467672-3.html @@ -0,0 +1,8 @@ + + + + + +text345 + + \ No newline at end of file diff --git a/layout/base/tests/bug467672-4-ref.html b/layout/base/tests/bug467672-4-ref.html new file mode 100644 index 00000000000..3842dd5afe8 --- /dev/null +++ b/layout/base/tests/bug467672-4-ref.html @@ -0,0 +1,8 @@ + + + + + +متن ۳۴۵ + + \ No newline at end of file diff --git a/layout/base/tests/bug467672-4.html b/layout/base/tests/bug467672-4.html new file mode 100644 index 00000000000..1437d291d62 --- /dev/null +++ b/layout/base/tests/bug467672-4.html @@ -0,0 +1,8 @@ + + + + + +متن 345 + + \ No newline at end of file diff --git a/layout/base/tests/bug467672-5-ref.html b/layout/base/tests/bug467672-5-ref.html new file mode 100644 index 00000000000..0144f94223f --- /dev/null +++ b/layout/base/tests/bug467672-5-ref.html @@ -0,0 +1,8 @@ + + + + + +text ۳۴۵ + + \ No newline at end of file diff --git a/layout/base/tests/bug467672-5.html b/layout/base/tests/bug467672-5.html new file mode 100644 index 00000000000..9dbad10bcab --- /dev/null +++ b/layout/base/tests/bug467672-5.html @@ -0,0 +1,8 @@ + + + + + +text 345 + + \ No newline at end of file diff --git a/layout/base/tests/test_bug441782.html b/layout/base/tests/test_bug441782.html index d068f56150e..57339b8d556 100644 --- a/layout/base/tests/test_bug441782.html +++ b/layout/base/tests/test_bug441782.html @@ -85,31 +85,68 @@ function bidiNumeral(val) { var bidiNumeralDefault = bidiNumeral(); var passes = [ - {file: 1, bidiNumeralValue: 0, op: "!="}, - {file: 1, bidiNumeralValue: 1, op: "=="}, - {file: 1, bidiNumeralValue: 2, op: "=="}, - {file: 1, bidiNumeralValue: 3, op: "=="}, - {file: 1, bidiNumeralValue: 4, op: "=="}, - {file: 2, bidiNumeralValue: 0, op: "!="}, - {file: 2, bidiNumeralValue: 1, op: "=="}, - {file: 2, bidiNumeralValue: 2, op: "=="}, - {file: 2, bidiNumeralValue: 3, op: "=="}, - {file: 2, bidiNumeralValue: 4, op: "=="}, - {file: 3, bidiNumeralValue: 0, op: "!="}, - {file: 3, bidiNumeralValue: 1, op: "=="}, - {file: 3, bidiNumeralValue: 2, op: "=="}, - {file: 3, bidiNumeralValue: 3, op: "=="}, - {file: 3, bidiNumeralValue: 4, op: "=="}, - {file: 4, bidiNumeralValue: 0, op: "!="}, - {file: 4, bidiNumeralValue: 1, op: "=="}, - {file: 4, bidiNumeralValue: 2, op: "=="}, - {file: 4, bidiNumeralValue: 3, op: "=="}, - {file: 4, bidiNumeralValue: 4, op: "=="}, - {file: 5, bidiNumeralValue: 0, op: "!="}, - {file: 5, bidiNumeralValue: 1, op: "=="}, - {file: 5, bidiNumeralValue: 2, op: "=="}, - {file: 5, bidiNumeralValue: 3, op: "=="}, - {file: 5, bidiNumeralValue: 4, op: "=="}, + // bug 441782 tests (Arabic) + {prefix: "bug441782", file: 1, bidiNumeralValue: 0, op: "!="}, + {prefix: "bug441782", file: 1, bidiNumeralValue: 1, op: "=="}, + {prefix: "bug441782", file: 1, bidiNumeralValue: 2, op: "=="}, + {prefix: "bug441782", file: 1, bidiNumeralValue: 3, op: "=="}, + {prefix: "bug441782", file: 1, bidiNumeralValue: 4, op: "=="}, + {prefix: "bug441782", file: 2, bidiNumeralValue: 0, op: "!="}, + {prefix: "bug441782", file: 2, bidiNumeralValue: 1, op: "=="}, + {prefix: "bug441782", file: 2, bidiNumeralValue: 2, op: "=="}, + {prefix: "bug441782", file: 2, bidiNumeralValue: 3, op: "=="}, + {prefix: "bug441782", file: 2, bidiNumeralValue: 4, op: "=="}, + {prefix: "bug441782", file: 3, bidiNumeralValue: 0, op: "!="}, + {prefix: "bug441782", file: 3, bidiNumeralValue: 1, op: "=="}, + {prefix: "bug441782", file: 3, bidiNumeralValue: 2, op: "=="}, + {prefix: "bug441782", file: 3, bidiNumeralValue: 3, op: "=="}, + {prefix: "bug441782", file: 3, bidiNumeralValue: 4, op: "=="}, + {prefix: "bug441782", file: 4, bidiNumeralValue: 0, op: "!="}, + {prefix: "bug441782", file: 4, bidiNumeralValue: 1, op: "=="}, + {prefix: "bug441782", file: 4, bidiNumeralValue: 2, op: "=="}, + {prefix: "bug441782", file: 4, bidiNumeralValue: 3, op: "=="}, + {prefix: "bug441782", file: 4, bidiNumeralValue: 4, op: "=="}, + {prefix: "bug441782", file: 5, bidiNumeralValue: 0, op: "!="}, + {prefix: "bug441782", file: 5, bidiNumeralValue: 1, op: "=="}, + {prefix: "bug441782", file: 5, bidiNumeralValue: 2, op: "=="}, + {prefix: "bug441782", file: 5, bidiNumeralValue: 3, op: "=="}, + {prefix: "bug441782", file: 5, bidiNumeralValue: 4, op: "=="}, + // bug 467672 tests (Arabic and Persian) + {prefix: "bug467672", file: 1, bidiNumeralValue: 0, op: "!="}, + {prefix: "bug467672", file: 1, bidiNumeralValue: 1, op: "=="}, + {prefix: "bug467672", file: 1, bidiNumeralValue: 2, op: "=="}, + {prefix: "bug467672", file: 1, bidiNumeralValue: 3, op: "=="}, + {prefix: "bug467672", file: 1, bidiNumeralValue: 4, op: "=="}, + {prefix: "bug467672", file: 1, bidiNumeralValue: 5, op: "=="}, + {prefix: "bug467672", file: 1, bidiNumeralValue: 6, op: "=="}, + {prefix: "bug467672", file: 2, bidiNumeralValue: 0, op: "!="}, + {prefix: "bug467672", file: 2, bidiNumeralValue: 1, op: "=="}, + {prefix: "bug467672", file: 2, bidiNumeralValue: 2, op: "=="}, + {prefix: "bug467672", file: 2, bidiNumeralValue: 3, op: "=="}, + {prefix: "bug467672", file: 2, bidiNumeralValue: 4, op: "=="}, + {prefix: "bug467672", file: 2, bidiNumeralValue: 5, op: "=="}, + {prefix: "bug467672", file: 2, bidiNumeralValue: 6, op: "=="}, + {prefix: "bug467672", file: 3, bidiNumeralValue: 0, op: "!="}, + {prefix: "bug467672", file: 3, bidiNumeralValue: 1, op: "=="}, + {prefix: "bug467672", file: 3, bidiNumeralValue: 2, op: "=="}, + {prefix: "bug467672", file: 3, bidiNumeralValue: 3, op: "=="}, + {prefix: "bug467672", file: 3, bidiNumeralValue: 4, op: "=="}, + {prefix: "bug467672", file: 3, bidiNumeralValue: 5, op: "=="}, + {prefix: "bug467672", file: 3, bidiNumeralValue: 6, op: "=="}, + {prefix: "bug467672", file: 4, bidiNumeralValue: 0, op: "!="}, + {prefix: "bug467672", file: 4, bidiNumeralValue: 1, op: "=="}, + {prefix: "bug467672", file: 4, bidiNumeralValue: 2, op: "=="}, + {prefix: "bug467672", file: 4, bidiNumeralValue: 3, op: "=="}, + {prefix: "bug467672", file: 4, bidiNumeralValue: 4, op: "=="}, + {prefix: "bug467672", file: 4, bidiNumeralValue: 5, op: "=="}, + {prefix: "bug467672", file: 4, bidiNumeralValue: 6, op: "=="}, + {prefix: "bug467672", file: 5, bidiNumeralValue: 0, op: "!="}, + {prefix: "bug467672", file: 5, bidiNumeralValue: 1, op: "=="}, + {prefix: "bug467672", file: 5, bidiNumeralValue: 2, op: "=="}, + {prefix: "bug467672", file: 5, bidiNumeralValue: 3, op: "=="}, + {prefix: "bug467672", file: 5, bidiNumeralValue: 4, op: "=="}, + {prefix: "bug467672", file: 5, bidiNumeralValue: 5, op: "=="}, + {prefix: "bug467672", file: 5, bidiNumeralValue: 6, op: "=="}, ]; var currentPass = 0; @@ -131,10 +168,10 @@ function do_test() var img_1 = canvases[0].getCanvas().toDataURL("image/png", ""); var img_2 = canvases[1].getCanvas().toDataURL("image/png", ""); if (passes[currentPass].op == "==") { - ok(img_1 == img_2, "Rendering of reftest " + passes[currentPass].file + + ok(img_1 == img_2, "Rendering of reftest " + fileprefix + passes[currentPass].file + " is different with bidi.numeral == " + passes[currentPass].bidiNumeralValue); } else if (passes[currentPass].op == "!=") { - ok(img_1 != img_2, "Rendering of reftest " + passes[currentPass].file + + ok(img_1 != img_2, "Rendering of reftest " + fileprefix + passes[currentPass].file + " is not different with bidi.numeral == " + passes[currentPass].bidiNumeralValue); } @@ -149,19 +186,21 @@ function do_test() } } + var fileprefix = passes[currentPass].prefix + "-"; var file = passes[currentPass].file; var header = document.createElement("p"); - header.appendChild(document.createTextNode("Testing reftest " + file + - " with bidi.numeral == " + passes[currentPass].bidiNumeralValue)); + header.appendChild(document.createTextNode("Testing reftest " + fileprefix + file + + " with bidi.numeral == " + passes[currentPass].bidiNumeralValue + + " expecting " + passes[currentPass].op)); document.body.appendChild(header); bidiNumeral(passes[currentPass].bidiNumeralValue); - var testCanvas = new RemoteCanvas("bug441782-" + file + ".html", "test-" + currentPass); + var testCanvas = new RemoteCanvas(fileprefix + file + ".html", "test-" + currentPass); testCanvas.load(callbackTestCanvas); - var refCanvas = new RemoteCanvas("bug441782-" + file + "-ref.html", "ref-" + currentPass); + var refCanvas = new RemoteCanvas(fileprefix + file + "-ref.html", "ref-" + currentPass); refCanvas.load(callbackTestCanvas); } diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index c75967cf024..392cff2e35c 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -1018,6 +1018,8 @@ pref("bidi.controlstextmode", 1); // 2 = hindicontextnumeralBidi // 3 = arabicnumeralBidi // 4 = hindinumeralBidi +// 5 = persiancontextnumeralBidi +// 6 = persiannumeralBidi pref("bidi.numeral", 0); // ------------------ // Support Mode