From d0afe7409284d160f904657d77567fd1f79f9b8c Mon Sep 17 00:00:00 2001 From: "smontagu%netscape.com" Date: Tue, 19 Feb 2002 20:41:32 +0000 Subject: [PATCH] Converting bidi utilities to non-XPCOM interfaces. Bug 120818; r=mkaply, nhotta; sr=attinasi git-svn-id: svn://10.0.0.236/trunk@114942 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsCopySupport.cpp | 14 +- mozilla/content/base/src/nsDocument.cpp | 2 +- mozilla/content/base/src/nsDocumentViewer.cpp | 2 +- mozilla/content/base/src/nsStyleContext.cpp | 4 - .../html/content/src/nsFormSubmission.cpp | 16 +- .../html/document/src/nsHTMLDocument.cpp | 2 +- mozilla/content/macbuild/contentshared.xml | 30 + mozilla/content/shared/public/MANIFEST | 1 + mozilla/content/shared/public/Makefile.in | 4 + mozilla/content/shared/public/makefile.win | 3 + .../shared/public/nsBidiUtils.h} | 133 +- mozilla/content/shared/src/Makefile.in | 1 + mozilla/content/shared/src/makefile.win | 1 + .../shared/src/nsBidiUtils.cpp} | 236 +- mozilla/content/shared/src/nsStyleStruct.cpp | 2 +- mozilla/content/shared/src/nsTextFragment.cpp | 2 +- .../intl/unicharutil/macbuild/unicharutil.xml | 60 - mozilla/intl/unicharutil/public/MANIFEST | 2 - mozilla/intl/unicharutil/public/Makefile.in | 2 - mozilla/intl/unicharutil/public/makefile.win | 2 - mozilla/intl/unicharutil/src/Makefile.in | 7 - mozilla/intl/unicharutil/src/makefile.win | 4 - mozilla/intl/unicharutil/src/nsBidiImp.h | 431 --- mozilla/intl/unicharutil/src/nsBidiUtilsImp.h | 82 - .../unicharutil/src/nsUcharUtilModule.cpp | 14 - .../src => layout/base}/bidicattable.h | 5 +- .../nsBidiImp.cpp => layout/base/nsBidi.cpp} | 256 +- .../public/nsIBidi.h => layout/base/nsBidi.h} | 483 +++- mozilla/layout/base/nsBidiPresUtils.cpp | 79 +- mozilla/layout/base/nsBidiPresUtils.h | 30 +- mozilla/layout/base/nsBidiUtils.cpp | 462 ++++ mozilla/layout/base/nsBidiUtils.h | 200 ++ mozilla/layout/base/nsDocumentViewer.cpp | 2 +- mozilla/layout/base/public/MANIFEST | 2 + mozilla/layout/base/public/Makefile.in | 1 + mozilla/layout/base/public/makefile.win | 1 + mozilla/layout/base/public/nsBidi.h | 1047 ++++++++ mozilla/layout/base/public/nsBidiPresUtils.h | 30 +- mozilla/layout/base/src/Makefile.in | 1 + mozilla/layout/base/src/bidicattable.h | 1945 ++++++++++++++ mozilla/layout/base/src/makefile.win | 1 + mozilla/layout/base/src/nsBidi.cpp | 2342 +++++++++++++++++ mozilla/layout/base/src/nsBidiPresUtils.cpp | 79 +- mozilla/layout/base/src/nsCopySupport.cpp | 14 +- mozilla/layout/base/src/nsPresContext.h | 2 +- .../base}/src/symmtable.h | 0 mozilla/layout/base/symmtable.h | 151 ++ mozilla/layout/generic/nsLineLayout.cpp | 2 +- mozilla/layout/generic/nsTextFrame.cpp | 2 +- mozilla/layout/html/base/src/nsLineLayout.cpp | 2 +- mozilla/layout/html/base/src/nsTextFrame.cpp | 2 +- mozilla/layout/html/forms/src/nsFormFrame.cpp | 7 - mozilla/layout/macbuild/layout.xml | 30 + mozilla/layout/style/nsStyleContext.cpp | 4 - mozilla/layout/style/nsStyleStruct.cpp | 2 +- .../tools/BidiMirroring.txt | 0 .../tools/genbidicattable.pl | 688 +++-- .../tools/gensymmtable.pl | 231 +- .../layout/xul/base/src/nsTextBoxFrame.cpp | 2 +- 59 files changed, 7505 insertions(+), 1657 deletions(-) rename mozilla/{intl/unicharutil/public/nsIUBidiUtils.h => content/shared/public/nsBidiUtils.h} (64%) rename mozilla/{intl/unicharutil/src/nsBidiUtilsImp.cpp => content/shared/src/nsBidiUtils.cpp} (70%) delete mode 100644 mozilla/intl/unicharutil/src/nsBidiImp.h delete mode 100644 mozilla/intl/unicharutil/src/nsBidiUtilsImp.h rename mozilla/{intl/unicharutil/src => layout/base}/bidicattable.h (99%) rename mozilla/{intl/unicharutil/src/nsBidiImp.cpp => layout/base/nsBidi.cpp} (92%) rename mozilla/{intl/unicharutil/public/nsIBidi.h => layout/base/nsBidi.h} (54%) create mode 100644 mozilla/layout/base/nsBidiUtils.cpp create mode 100644 mozilla/layout/base/nsBidiUtils.h create mode 100644 mozilla/layout/base/public/nsBidi.h create mode 100644 mozilla/layout/base/src/bidicattable.h create mode 100644 mozilla/layout/base/src/nsBidi.cpp rename mozilla/{intl/unicharutil => layout/base}/src/symmtable.h (100%) create mode 100644 mozilla/layout/base/symmtable.h rename mozilla/{intl/unicharutil => layout}/tools/BidiMirroring.txt (100%) rename mozilla/{intl/unicharutil => layout}/tools/genbidicattable.pl (94%) rename mozilla/{intl/unicharutil => layout}/tools/gensymmtable.pl (93%) diff --git a/mozilla/content/base/src/nsCopySupport.cpp b/mozilla/content/base/src/nsCopySupport.cpp index 97d465e486e..19133e5d502 100644 --- a/mozilla/content/base/src/nsCopySupport.cpp +++ b/mozilla/content/base/src/nsCopySupport.cpp @@ -59,7 +59,8 @@ #include "nsIHTMLDocument.h" #include "nsHTMLAtoms.h" #ifdef IBMBIDI -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" +#include "nsBidiPresUtils.h" //static NS_DEFINE_CID(kUBidiUtilCID, NS_UNICHARBIDIUTIL_CID); #endif @@ -134,11 +135,12 @@ nsresult nsCopySupport::HTMLCopy(nsISelection *aSel, nsIDocument *aDoc, PRInt16 if (context) { context->IsArabicEncoding(arabicCharset); if (arabicCharset) { - nsCOMPtr bidiUtils = do_GetService("@mozilla.org/intl/unicharbidiutil;1"); + nsBidiPresUtils* bidiUtils; PRUint32 bidiOptions; PRBool isVisual; PRBool isBidiSystem; - + + context->GetBidiUtils(&bidiUtils); context->GetBidi(&bidiOptions); context->IsVisualMode(isVisual); context->GetIsBidiSystem(isBidiSystem); @@ -147,10 +149,10 @@ nsresult nsCopySupport::HTMLCopy(nsISelection *aSel, nsIDocument *aDoc, PRInt16 nsAutoString newBuffer; if (isBidiSystem) { if (GET_BIDI_OPTION_DIRECTION(bidiOptions) == IBMBIDI_TEXTDIRECTION_RTL) { - bidiUtils->Conv_FE_06(buffer, newBuffer); + Conv_FE_06(buffer, newBuffer); } else { - bidiUtils->Conv_FE_06_WithReverse(buffer, newBuffer); + Conv_FE_06_WithReverse(buffer, newBuffer); } } else { //nonbidisystem @@ -165,7 +167,7 @@ nsresult nsCopySupport::HTMLCopy(nsISelection *aSel, nsIDocument *aDoc, PRInt16 if (bidiCharset.EqualsIgnoreCase("UTF-8") || (!isVisual)) { if ( (GET_BIDI_OPTION_CLIPBOARDTEXTMODE(bidiOptions) == IBMBIDI_CLIPBOARDTEXTMODE_VISUAL) || (!isBidiSystem) ) { nsAutoString newBuffer; - bidiUtils->Conv_06_FE_WithReverse(buffer, newBuffer, GET_BIDI_OPTION_DIRECTION(bidiOptions)); + Conv_06_FE_WithReverse(buffer, newBuffer, GET_BIDI_OPTION_DIRECTION(bidiOptions)); bidiUtils->HandleNumbers(newBuffer, buffer); } } diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index bb95d366c88..4eb18c2a5b5 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -127,7 +127,7 @@ #include "nsXULAtoms.h" #ifdef IBMBIDI -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" #endif static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID); diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 55beacb0464..7d416f1af29 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -172,7 +172,7 @@ static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID); #include "nsITransformMediator.h" #ifdef IBMBIDI -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" #endif static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); diff --git a/mozilla/content/base/src/nsStyleContext.cpp b/mozilla/content/base/src/nsStyleContext.cpp index f8ce6021ebd..3badfe8fc8b 100644 --- a/mozilla/content/base/src/nsStyleContext.cpp +++ b/mozilla/content/base/src/nsStyleContext.cpp @@ -55,10 +55,6 @@ #include "nsRuleNode.h" -#ifdef IBMBIDI -#include "nsIUBidiUtils.h" -#endif - #ifdef DEBUG // #define NOISY_DEBUG #endif diff --git a/mozilla/content/html/content/src/nsFormSubmission.cpp b/mozilla/content/html/content/src/nsFormSubmission.cpp index 3d4e2545b73..3fe58d7a4e1 100644 --- a/mozilla/content/html/content/src/nsFormSubmission.cpp +++ b/mozilla/content/html/content/src/nsFormSubmission.cpp @@ -62,8 +62,7 @@ static NS_DEFINE_CID(kCharsetConverterManagerCID, //BIDI #ifdef IBMBIDI -#include "nsIUBidiUtils.h" -//static NS_DEFINE_CID(kUBidiUtilCID, NS_UNICHARBIDIUTIL_CID); +#include "nsBidiUtils.h" #else // // Make BIDI stuff work when BIDI is off @@ -882,17 +881,14 @@ nsFormSubmission::UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen, PRUint8 textDirAtSubmit = GET_BIDI_OPTION_DIRECTION(mBidiOptions); //ahmed 15-1 nsAutoString temp; - nsCOMPtr bidiUtils( - do_GetService("@mozilla.org/intl/unicharbidiutil;1", &rv)); - nsAutoString newBuffer; //This condition handle the RTL,LTR for a logical file if (ctrlsModAtSubmit == IBMBIDI_CONTROLSTEXTMODE_VISUAL && mCharset.Equals(NS_LITERAL_STRING("windows-1256"), nsCaseInsensitiveStringComparator())) { - bidiUtils->Conv_06_FE_WithReverse(nsString(aSrc), - newBuffer, - textDirAtSubmit); + Conv_06_FE_WithReverse(nsString(aSrc), + newBuffer, + textDirAtSubmit); aSrc = (PRUnichar*)newBuffer.get(); aLen=newBuffer.Length(); } @@ -901,7 +897,7 @@ nsFormSubmission::UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen, nsCaseInsensitiveStringComparator())) { //For 864 file, When it is logical, if LTR then only convert //If RTL will mak a reverse for the buffer - bidiUtils->Conv_FE_06(nsString(aSrc), newBuffer); + Conv_FE_06(nsString(aSrc), newBuffer); aSrc = (PRUnichar*)newBuffer.get(); temp = newBuffer; aLen=newBuffer.Length(); @@ -921,7 +917,7 @@ nsFormSubmission::UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen, nsCaseInsensitiveStringComparator()) && textDirAtSubmit == IBMBIDI_TEXTDIRECTION_RTL) { - bidiUtils->Conv_FE_06(nsString(aSrc), newBuffer); + Conv_FE_06(nsString(aSrc), newBuffer); aSrc = (PRUnichar*)newBuffer.get(); temp = newBuffer; aLen=newBuffer.Length(); diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index c433fcce347..3fd05887977 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -132,7 +132,7 @@ #include "nsIPrompt.h" //AHMED 12-2 #ifdef IBMBIDI -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" #endif #define DETECTOR_CONTRACTID_MAX 127 diff --git a/mozilla/content/macbuild/contentshared.xml b/mozilla/content/macbuild/contentshared.xml index 07c3db50a7e..282b9ee0086 100644 --- a/mozilla/content/macbuild/contentshared.xml +++ b/mozilla/content/macbuild/contentshared.xml @@ -988,6 +988,13 @@ Text + + Name + nsBidiUtils.cpp + MacOS + Text + + @@ -1060,6 +1067,11 @@ nsXBLAtoms.cpp MacOS + + Name + nsBidiUtils.cpp + MacOS + @@ -1997,6 +2009,13 @@ Text + + Name + nsBidiUtils.cpp + MacOS + Text + + @@ -2069,6 +2088,11 @@ nsXBLAtoms.cpp MacOS + + Name + nsBidiUtils.cpp + MacOS + @@ -2158,6 +2182,12 @@ nsHTMLUtils.cpp MacOS + + contentsharedDebug.o + Name + nsBidiUtils.cpp + MacOS + contentsharedDebug.o diff --git a/mozilla/content/shared/public/MANIFEST b/mozilla/content/shared/public/MANIFEST index c6a698d80ff..bc224f0ce3f 100644 --- a/mozilla/content/shared/public/MANIFEST +++ b/mozilla/content/shared/public/MANIFEST @@ -1,6 +1,7 @@ # # This is a list of local files which get copied to the mozilla:dist:content directory # +nsBidiUtils.h nsCSSAtomList.h nsCSSAtoms.h nsCSSKeywordList.h diff --git a/mozilla/content/shared/public/Makefile.in b/mozilla/content/shared/public/Makefile.in index eb9daeab36c..77acd8fe11f 100644 --- a/mozilla/content/shared/public/Makefile.in +++ b/mozilla/content/shared/public/Makefile.in @@ -58,5 +58,9 @@ ifdef MOZ_SVG EXPORTS += nsSVGAtomList.h nsSVGAtoms.h endif +ifdef IBMBIDI +EXPORTS += nsBidiUtils.h +endif + include $(topsrcdir)/config/rules.mk diff --git a/mozilla/content/shared/public/makefile.win b/mozilla/content/shared/public/makefile.win index 81b571ce9f0..d8105be6fd4 100644 --- a/mozilla/content/shared/public/makefile.win +++ b/mozilla/content/shared/public/makefile.win @@ -46,6 +46,9 @@ EXPORTS = \ !ifdef MOZ_SVG nsSVGAtomList.h \ nsSVGAtoms.h \ +!endif +!ifdef IBMBIDI + nsBidiUtils.h \ !endif nsXBLAtomList.h \ nsXBLAtoms.h \ diff --git a/mozilla/intl/unicharutil/public/nsIUBidiUtils.h b/mozilla/content/shared/public/nsBidiUtils.h similarity index 64% rename from mozilla/intl/unicharutil/public/nsIUBidiUtils.h rename to mozilla/content/shared/public/nsBidiUtils.h index 92b44745ce5..49a8ec87a81 100644 --- a/mozilla/intl/unicharutil/public/nsIUBidiUtils.h +++ b/mozilla/content/shared/public/nsBidiUtils.h @@ -1,5 +1,5 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of @@ -17,100 +17,18 @@ * Copyright (C) 2000 IBM Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): + * Maha Abou El Rous + * Lina Kemmel + * Simon Montagu * */ -#ifndef nsIUBidiUtils_h__ -#define nsIUBidiUtils_h__ +#ifndef nsBidiUtils_h__ +#define nsBidiUtils_h__ -#include "nsISupports.h" -#include "nscore.h" +#include "nsCOMPtr.h" #include "nsString.h" -// Include nsIBidi.h for nsCharType data type -#include "nsIBidi.h" - - /** - * Read ftp://ftp.unicode.org/Public/UNIDATA/ReadMe-Latest.txt - * section BIDIRECTIONAL PROPERTIES - * for the detailed definition of the following categories - * - * The values here must match the equivalents in %map in - * mozilla/intl/unicharutil/tools/genbidicattable.pl - */ - -typedef enum { - eBidiCat_Undefined, - eBidiCat_L, /* Left-to-Right */ - eBidiCat_R, /* Right-to-Left */ - eBidiCat_AL, /* Right-to-Left Arabic */ - eBidiCat_AN, /* Arabic Number */ - eBidiCat_EN, /* European Number */ - eBidiCat_ES, /* European Number Separator */ - eBidiCat_ET, /* European Number Terminator */ - eBidiCat_CS, /* Common Number Separator */ - eBidiCat_ON, /* Other Neutrals */ - eBidiCat_NSM, /* Non-Spacing Mark */ - eBidiCat_BN, /* Boundary Neutral */ - eBidiCat_B, /* Paragraph Separator */ - eBidiCat_S, /* Segment Separator */ - eBidiCat_WS, /* Whitespace */ - eBidiCat_CC = 0xf, /* Control Code */ - /* (internal use only - will never be outputed) */ - eBidiCat_LRE = 0x2a, /* Left-to-Right Embedding */ - eBidiCat_RLE = 0x2b, /* Right-to-Left Embedding */ - eBidiCat_PDF = 0x2c, /* Pop Directional Formatting */ - eBidiCat_LRO = 0x2d, /* Left-to-Right Override */ - eBidiCat_RLO = 0x2e /* Right-to-Left Override */ -} eBidiCategory; - -/* {D23D2DD0-E2F9-11d3-B6DF-00104B4119F8} */ -#define NS_UNICHARBIDIUTIL_CID \ - { 0xd23d2dd0, 0xe2f9, 0x11d3, \ - {0xb6, 0xdf, 0x0, 0x10, 0x4b, 0x41, 0x19, 0xf8} } - -#define NS_UNICHARBIDIUTIL_CONTRACTID "@mozilla.org/intl/unicharbidiutil;1" - - -/* {49926730-E221-11d3-B6DE-00104B4119F8} */ -#define NS_IUBIDIUTILS_IID \ - { 0x49926730, 0xe221, 0x11d3, \ - { 0xb6, 0xde, 0x0, 0x10, 0x4b, 0x41, 0x19, 0xf8} } - -class nsIUBidiUtils : public nsISupports { - - public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IUBIDIUTILS_IID) - - /** - * Give a Unichar, return an eBidiCategory - */ - NS_IMETHOD GetBidiCategory(PRUnichar aChar, eBidiCategory* oResult) = 0 ; - - /** - * Give a Unichar, and a eBidiCategory, - * return PR_TRUE if the Unichar is in that category, - * return PR_FALSE, otherwise - */ - NS_IMETHOD IsBidiCategory(PRUnichar aChar, eBidiCategory aBidiCategory, PRBool* oResult) = 0; - - /** - * Give a Unichar - * return PR_TRUE if the Unichar is a Bidi control character (LRE, RLE, PDF, LRO, RLO, LRM, RLM) - * return PR_FALSE, otherwise - */ - NS_IMETHOD IsBidiControl(PRUnichar aChar, PRBool* oResult) = 0; - - /** - * Give a Unichar, return a nsCharType (compatible with ICU) - */ - NS_IMETHOD GetCharType(PRUnichar aChar, nsCharType* oResult) = 0 ; - - /** - * Give a Unichar, return the symmetric equivalent - */ - NS_IMETHOD SymmSwap(PRUnichar* aChar) = 0 ; /** * Perform Arabic shaping on a Unichar string @@ -119,26 +37,8 @@ class nsIUBidiUtils : public nsISupports { * @param aBuf receives the shaped output * @param aBuflen receives the length of aBuf */ - NS_IMETHOD ArabicShaping(const PRUnichar* aString, PRUint32 aLen, - PRUnichar* aBuf, PRUint32* aBufLen)=0; - - /** - * Scan a Unichar string, converting numbers to Arabic or Hindi forms in place - * @param aBuffer is the string - * @param aSize is the size of aBuffer - * @param aNumFlag specifies the conversion to perform: - * IBMBIDI_NUMERAL_HINDI: convert to Hindi forms (Unicode 0660-0669) - * IBMBIDI_NUMERAL_ARABIC: convert to Arabic forms (Unicode 0030-0039) - * IBMBIDI_NUMERAL_HINDICONTEXT: convert numbers in Arabic text to Hindi, otherwise to Arabic - */ - NS_IMETHOD HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag)=0; - - /** - * Scan an nsString, converting numerals to Arabic or Hindi forms - * @param aSrc is the input string - * @param aDst is the output string - */ - NS_IMETHOD HandleNumbers(const nsString aSrc, nsString & aDst) = 0; + nsresult ArabicShaping(const PRUnichar* aString, PRUint32 aLen, + PRUnichar* aBuf, PRUint32* aBufLen); /** * Scan an nsString, converting characters in the FExx range (Arabic presentation forms) to the equivalent characters in the 06xx @@ -146,7 +46,7 @@ class nsIUBidiUtils : public nsISupports { * @param aSrc is the input string * @param aDst is the output string */ - NS_IMETHOD Conv_FE_06(const nsString aSrc, nsString & aDst) = 0; + nsresult Conv_FE_06(const nsString& aSrc, nsString& aDst); /** * Scan an nsString, converting characters in the FExx range (Arabic presentation forms) to the equivalent characters in the 06xx @@ -154,7 +54,7 @@ class nsIUBidiUtils : public nsISupports { * @param aSrc is the input string * @param aDst is the output string */ - NS_IMETHOD Conv_FE_06_WithReverse(const nsString aSrc, nsString & aDst) = 0; + nsresult Conv_FE_06_WithReverse(const nsString& aSrc, nsString& aDst); /** * Scan an nsString, converting characters in the 06xx range to the equivalent characters in the 0Fxx range (Arabic presentation @@ -165,9 +65,8 @@ class nsIUBidiUtils : public nsISupports { * IBMBIDI_TEXTDIRECTION_LTR: do not reverse the string * IBMBIDI_TEXTDIRECTION_RTL: reverse the string */ - NS_IMETHOD Conv_06_FE_WithReverse(const nsString aSrc, nsString & aDst, PRUint32 aDir) = 0; + nsresult Conv_06_FE_WithReverse(const nsString& aSrc, nsString& aDst, PRUint32 aDir); -}; // -------------------------------------------------- // IBMBIDI // -------------------------------------------------- @@ -298,6 +197,4 @@ class nsIUBidiUtils : public nsISupports { #define CHAR_IS_BIDI(c) ( (IS_HINDI_DIGIT(c) ) || (IS_HEBREW_CHAR(c) ) \ || (IS_06_CHAR(c) ) || (IS_FE_CHAR(c) ) ) -#endif /* nsIUbidiUtils_h__ */ - - +#endif /* nsBidiUtils_h__ */ diff --git a/mozilla/content/shared/src/Makefile.in b/mozilla/content/shared/src/Makefile.in index 970cb64d97e..3ed3c5af297 100644 --- a/mozilla/content/shared/src/Makefile.in +++ b/mozilla/content/shared/src/Makefile.in @@ -58,6 +58,7 @@ CPPSRCS = \ nsXBLAtoms.cpp \ nsStyleCoord.cpp \ nsStyleStruct.cpp \ + nsBidiUtils.cpp \ $(NULL) ifdef MOZ_SVG diff --git a/mozilla/content/shared/src/makefile.win b/mozilla/content/shared/src/makefile.win index 3303f12b961..f9dcec97dc8 100644 --- a/mozilla/content/shared/src/makefile.win +++ b/mozilla/content/shared/src/makefile.win @@ -58,6 +58,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsXULAtoms.obj \ .\$(OBJDIR)\nsXBLAtoms.obj \ .\$(OBJDIR)\nsStyleCoord.obj \ + .\$(OBJDIR)\nsBidiUtils.obj \ !ifdef MOZ_SVG .\$(OBJDIR)\nsSVGAtoms.obj \ !endif diff --git a/mozilla/intl/unicharutil/src/nsBidiUtilsImp.cpp b/mozilla/content/shared/src/nsBidiUtils.cpp similarity index 70% rename from mozilla/intl/unicharutil/src/nsBidiUtilsImp.cpp rename to mozilla/content/shared/src/nsBidiUtils.cpp index 18692ee10e4..c8bc125a599 100644 --- a/mozilla/intl/unicharutil/src/nsBidiUtilsImp.cpp +++ b/mozilla/content/shared/src/nsBidiUtils.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file @@ -17,52 +17,14 @@ * Copyright (C) 2000 IBM Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): + * Maha Abou El Rous + * Lina Kemmel + * Simon Montagu * Roozbeh Pournader */ #ifdef IBMBIDI -#include "nsCom.h" -#include "pratom.h" -#include "nsUUDll.h" -#include "nsISupports.h" -#include "nsBidiUtilsImp.h" -#include "bidicattable.h" -#include "symmtable.h" - -#include "nsIServiceManager.h" -#include "nsIUBidiUtils.h" -#include "nsIBidi.h" -static NS_DEFINE_CID(kBidiCID, NS_BIDI_CID); -NS_IMPL_ISUPPORTS1(nsBidiUtilsImp, nsIUBidiUtils) - -static nsCharType ebc2ucd[15] = { - eCharType_OtherNeutral, /* Placeholder -- there will never be a 0 index value */ - eCharType_LeftToRight, - eCharType_RightToLeft, - eCharType_RightToLeftArabic, - eCharType_ArabicNumber, - eCharType_EuropeanNumber, - eCharType_EuropeanNumberSeparator, - eCharType_EuropeanNumberTerminator, - eCharType_CommonNumberSeparator, - eCharType_OtherNeutral, - eCharType_DirNonSpacingMark, - eCharType_BoundaryNeutral, - eCharType_BlockSeparator, - eCharType_SegmentSeparator, - eCharType_WhiteSpaceNeutral -}; - -static nsCharType cc2ucd[5] = { - eCharType_LeftToRightEmbedding, - eCharType_RightToLeftEmbedding, - eCharType_PopDirectionalFormat, - eCharType_LeftToRightOverride, - eCharType_RightToLeftOverride -}; - -#define FULL_ARABIC_SHAPING 1 -// the Array Index = FE_CHAR - FE_TO_06_OFFSET +#include "nsBidiUtils.h" #define FE_TO_06_OFFSET 0xfe70 @@ -265,90 +227,10 @@ static PRUint16 gArabicLigatureMap[] = 0x8EDF, // 0xFE8E 0xFEDF -> 0xFEFB 0x8EE0 // 0xFE8E 0xFEE0 -> 0xFEFC }; -#define CHAR_IS_HEBREW(c) ((0x0590 <= (c)) && ((c)<= 0x05FF)) -#define CHAR_IS_ARABIC(c) ((0x0600 <= (c)) && ((c)<= 0x06FF)) -// Note: The above code are moved from gfx/src/windows/nsRenderingContextWin.cpp -#define LRM_CHAR 0x200e -#define ARABIC_TO_HINDI_DIGIT_INCREMENT (START_HINDI_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)) -#define NUM_TO_HINDI(c) \ - ((((c)>=START_ARABIC_DIGITS) && ((c)<=END_ARABIC_DIGITS)) ? \ - ((c) + (PRUint16)ARABIC_TO_HINDI_DIGIT_INCREMENT): \ - (c)) - -nsBidiUtilsImp::nsBidiUtilsImp() +nsresult ArabicShaping(const PRUnichar* aString, PRUint32 aLen, + PRUnichar* aBuf, PRUint32 *aBufLen) { - NS_INIT_REFCNT(); -} - -nsBidiUtilsImp::~nsBidiUtilsImp() -{ -} - -NS_IMETHODIMP nsBidiUtilsImp::GetBidiCategory(PRUnichar aChar, eBidiCategory* oResult) -{ - *oResult = GetBidiCat(aChar); - if (eBidiCat_CC == *oResult) - *oResult = (eBidiCategory)(aChar & 0xFF); /* Control codes have special treatment to keep the tables smaller */ - return NS_OK; -} - -NS_IMETHODIMP nsBidiUtilsImp::IsBidiCategory(PRUnichar aChar, eBidiCategory aBidiCategory, PRBool* oResult) -{ - eBidiCategory bCat = GetBidiCat(aChar); - if (eBidiCat_CC == bCat) - bCat = (eBidiCategory)(aChar & 0xFF); - *oResult = (bCat == aBidiCategory); - return NS_OK; -} - -NS_IMETHODIMP nsBidiUtilsImp::IsBidiControl(PRUnichar aChar, PRBool* oResult) -{ - // This method is used when stripping Bidi control characters for - // display, so it will return TRUE for LRM and RLM as well as the - // characters with category eBidiCat_CC - *oResult = (eBidiCat_CC == GetBidiCat(aChar) || ((aChar)&0xfffe)==LRM_CHAR); - return NS_OK; -} - -NS_IMETHODIMP nsBidiUtilsImp::GetCharType(PRUnichar aChar, nsCharType* oResult) -{ - eBidiCategory bCat = GetBidiCat(aChar); - if (eBidiCat_CC != bCat) { - NS_ASSERTION(bCat < (sizeof(ebc2ucd)/sizeof(nsCharType)), "size mismatch"); - if(bCat < (sizeof(ebc2ucd)/sizeof(nsCharType))) - *oResult = ebc2ucd[bCat]; - else - *oResult = ebc2ucd[0]; // something is very wrong, but we need to return a value - } else { - NS_ASSERTION((aChar-0x202a) < (sizeof(cc2ucd)/sizeof(nsCharType)), "size mismatch"); - if((aChar-0x202a) < (sizeof(cc2ucd)/sizeof(nsCharType))) - *oResult = cc2ucd[aChar - 0x202a]; - else - *oResult = ebc2ucd[0]; // something is very wrong, but we need to return a value - } - return NS_OK; -} - -NS_IMETHODIMP nsBidiUtilsImp::SymmSwap(PRUnichar* aChar) -{ - *aChar = Mirrored(*aChar); - return NS_OK; -} - -NS_IMETHODIMP nsBidiUtilsImp::ArabicShaping(const PRUnichar* aString, PRUint32 aLen, - PRUnichar* aBuf, PRUint32 *aBufLen) -{ - // Note: The real implementation is still under reviewing process - // will be check in soon. - // a stub routine which simply copy the data is now place here untill the - // real code get check in. -#ifdef FULL_ARABIC_SHAPING - // Start Unreview Code const PRUnichar* src = aString; const PRUnichar* p; PRUnichar* dest = aBuf; @@ -361,11 +243,11 @@ NS_IMETHODIMP nsBidiUtilsImp::ArabicShaping(const PRUnichar* aString, PRUint32 a leftJ = thisJ; if ((eTr != leftJ) || ((leftJ == eTr) && - ( ( (src-1) >= aString ) && !CHAR_IS_ARABIC(*(src-1))))) + ( ( (src-1) >= aString ) && !IS_ARABIC_CHAR(*(src-1))))) leftNoTrJ = thisJ; if(src-2 >= (aString)){ - for(p=src-2; (p >= (aString))&& (eTr == leftNoTrJ) && (CHAR_IS_ARABIC(*(p+1))) ; p--) + for(p=src-2; (p >= (aString))&& (eTr == leftNoTrJ) && (IS_ARABIC_CHAR(*(p+1))) ; p--) leftNoTrJ = GetJoiningClass(*(p)) ; } @@ -373,7 +255,7 @@ NS_IMETHODIMP nsBidiUtilsImp::ArabicShaping(const PRUnichar* aString, PRUint32 a rightJ = rightNoTrJ = GetJoiningClass(*(src+1)) ; if(src+2 <= (aString+aLen-1)){ - for(p=src+2; (p <= (aString+aLen-1))&&(eTr == rightNoTrJ) && (CHAR_IS_ARABIC(*(src+1))); p++) + for(p=src+2; (p <= (aString+aLen-1))&&(eTr == rightNoTrJ) && (IS_ARABIC_CHAR(*(src+1))); p++) rightNoTrJ = GetJoiningClass(*(p)) ; } @@ -383,11 +265,11 @@ NS_IMETHODIMP nsBidiUtilsImp::ArabicShaping(const PRUnichar* aString, PRUint32 a } if((eTr != thisJ) || - ((thisJ == eTr) && (((src-1)>=aString) && (!CHAR_IS_ARABIC(*(src-1)))))) + ((thisJ == eTr) && (((src-1)>=aString) && (!IS_ARABIC_CHAR(*(src-1)))))) leftNoTrJ = thisJ; if(src-2 >= (aString)){ - for(p=src-2; (src-2 >= (aString)) && (eTr == leftNoTrJ) && (CHAR_IS_ARABIC(*(p+1))); p--) + for(p=src-2; (src-2 >= (aString)) && (eTr == leftNoTrJ) && (IS_ARABIC_CHAR(*(p+1))); p--) leftNoTrJ = GetJoiningClass(*(p)) ; } @@ -426,58 +308,10 @@ NS_IMETHODIMP nsBidiUtilsImp::ArabicShaping(const PRUnichar* aString, PRUint32 a *aBufLen = lDest - aBuf; return NS_OK; -#else - for(*aBufLen = 0;*aBufLen < aLen; (*aBufLen)++) - aBuf[*aBufLen] = aString[*aBufLen]; - return NS_OK; -#endif } - -NS_IMETHODIMP nsBidiUtilsImp::HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag) +nsresult Conv_FE_06(const nsString& aSrc, nsString& aDst) { - PRUint32 i; - // IBMBIDI_NUMERAL_REGULAR * - // IBMBIDI_NUMERAL_HINDICONTEXT - // IBMBIDI_NUMERAL_ARABIC - // IBMBIDI_NUMERAL_HINDI - mNumflag=aNumFlag; - - switch (aNumFlag) { - case IBMBIDI_NUMERAL_HINDI: - for (i=0;iText Debug - - Name - nsBidiUtilsImp.cpp - MacOS - Text - Debug - - - Name - nsBidiImp.cpp - MacOS - Text - Debug - @@ -1087,16 +1073,6 @@ nsSaveAsCharset.cpp MacOS - - Name - nsBidiUtilsImp.cpp - MacOS - - - Name - nsBidiImp.cpp - MacOS - @@ -2057,20 +2033,6 @@ Text Debug - - Name - nsBidiUtilsImp.cpp - MacOS - Text - Debug - - - Name - nsBidiImp.cpp - MacOS - Text - Debug - @@ -2133,16 +2095,6 @@ nsSaveAsCharset.cpp MacOS - - Name - nsBidiUtilsImp.cpp - MacOS - - - Name - nsBidiImp.cpp - MacOS - @@ -2190,18 +2142,6 @@ nsEntityConverter.cpp MacOS - - unicharutil.shlb - Name - nsBidiUtilsImp.cpp - MacOS - - - unicharutil.shlb - Name - nsBidiImp.cpp - MacOS - NS Libraries Optimized diff --git a/mozilla/intl/unicharutil/public/MANIFEST b/mozilla/intl/unicharutil/public/MANIFEST index bb07faac647..d422c117d36 100644 --- a/mozilla/intl/unicharutil/public/MANIFEST +++ b/mozilla/intl/unicharutil/public/MANIFEST @@ -6,5 +6,3 @@ nsIUGenDetailCategory.h nsUnicharUtilCIID.h nsHankakuToZenkakuCID.h nsArabicBasicLToPFormBVCID.h -nsIBidi.h -nsIUBidiUtils.h diff --git a/mozilla/intl/unicharutil/public/Makefile.in b/mozilla/intl/unicharutil/public/Makefile.in index 7793fbd9224..1937d656e1c 100644 --- a/mozilla/intl/unicharutil/public/Makefile.in +++ b/mozilla/intl/unicharutil/public/Makefile.in @@ -37,8 +37,6 @@ EXPORTS = \ nsUnicharUtilCIID.h \ nsHankakuToZenkakuCID.h \ nsArabicBasicLToPFormBVCID.h \ - nsIUBidiUtils.h \ - nsIBidi.h \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/intl/unicharutil/public/makefile.win b/mozilla/intl/unicharutil/public/makefile.win index 14384d36543..1869aac01f2 100644 --- a/mozilla/intl/unicharutil/public/makefile.win +++ b/mozilla/intl/unicharutil/public/makefile.win @@ -31,8 +31,6 @@ EXPORTS = \ nsHankakuToZenkakuCID.h \ nsArabicBasicLToPFormBVCID.h \ nsUnicharUtilCIID.h \ - nsIUBidiUtils.h \ - nsIBidi.h \ $(NULL) MODULE=unicharutil diff --git a/mozilla/intl/unicharutil/src/Makefile.in b/mozilla/intl/unicharutil/src/Makefile.in index 3cc9be82a5c..36bf77e1983 100644 --- a/mozilla/intl/unicharutil/src/Makefile.in +++ b/mozilla/intl/unicharutil/src/Makefile.in @@ -47,13 +47,6 @@ CPPSRCS = \ nsSaveAsCharset.cpp \ $(NULL) -ifdef IBMBIDI -CPPSRCS += \ - nsBidiUtilsImp.cpp \ - nsBidiImp.cpp \ - $(NULL) -endif - EXTRA_DSO_LDOPTS =\ $(MOZ_NECKO_UTIL_LIBS) \ $(MOZ_COMPONENT_LIBS) \ diff --git a/mozilla/intl/unicharutil/src/makefile.win b/mozilla/intl/unicharutil/src/makefile.win index 6298ce4680a..326ea7989fd 100644 --- a/mozilla/intl/unicharutil/src/makefile.win +++ b/mozilla/intl/unicharutil/src/makefile.win @@ -53,10 +53,6 @@ CPP_OBJS= \ .\$(OBJDIR)\nsHankakuToZenkaku.obj \ .\$(OBJDIR)\nsEntityConverter.obj \ .\$(OBJDIR)\nsSaveAsCharset.obj \ -!ifdef IBMBIDI - .\$(OBJDIR)\nsBidiUtilsImp.obj \ - .\$(OBJDIR)\nsBidiImp.obj \ -!endif $(NULL) LLIBS= \ diff --git a/mozilla/intl/unicharutil/src/nsBidiImp.h b/mozilla/intl/unicharutil/src/nsBidiImp.h deleted file mode 100644 index 9ebbfd25d51..00000000000 --- a/mozilla/intl/unicharutil/src/nsBidiImp.h +++ /dev/null @@ -1,431 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * IBM Corporation. Portions created by IBM are - * Copyright (C) 2000 IBM Corporation. All - * Rights Reserved. - * - * This module is based on the ICU (International Components for Unicode) - * - * Copyright (C) 2000, International Business Machines - * Corporation and others. All Rights Reserved. - * - * Contributor(s): - */ -#ifdef IBMBIDI - -#ifndef nsBidiImp_h__ -#define nsBidiImp_h__ - -#include "nsIBidi.h" - -/* helper macros for each allocated array member */ -#define GETDIRPROPSMEMORY(length) \ - GetMemory((void **)&mDirPropsMemory, &mDirPropsSize, \ - mMayAllocateText, (length)) - -#define GETLEVELSMEMORY(length) \ - GetMemory((void **)&mLevelsMemory, &mLevelsSize, \ - mMayAllocateText, (length)) - -#define GETRUNSMEMORY(length) \ - GetMemory((void **)&mRunsMemory, &mRunsSize, \ - mMayAllocateRuns, (length)*sizeof(Run)) - -/* additional macros used by constructor - always allow allocation */ -#define GETINITIALDIRPROPSMEMORY(length) \ - GetMemory((void **)&mDirPropsMemory, &mDirPropsSize, \ - PR_TRUE, (length)) - -#define GETINITIALLEVELSMEMORY(length) \ - GetMemory((void **)&mLevelsMemory, &mLevelsSize, \ - PR_TRUE, (length)) - -#define GETINITIALRUNSMEMORY(length) \ - GetMemory((void **)&mRunsMemory, &mRunsSize, \ - PR_TRUE, (length)*sizeof(Run)) - -/* - * Sometimes, bit values are more appropriate - * to deal with directionality properties. - * Abbreviations in these macro names refer to names - * used in the Bidi algorithm. - */ -typedef PRUint8 DirProp; - -#define DIRPROP_FLAG(dir) (1UL<<(dir)) - -/* special flag for multiple runs from explicit embedding codes */ -#define DIRPROP_FLAG_MULTI_RUNS (1UL<<31) - -/* are there any characters that are LTR or RTL? */ -#define MASK_LTR (DIRPROP_FLAG(L)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(AN)|DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)) -#define MASK_RTL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO)) - -/* explicit embedding codes */ -#define MASK_LRX (DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)) -#define MASK_RLX (DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO)) -#define MASK_OVERRIDE (DIRPROP_FLAG(LRO)|DIRPROP_FLAG(RLO)) - -#define MASK_EXPLICIT (MASK_LRX|MASK_RLX|DIRPROP_FLAG(PDF)) -#define MASK_BN_EXPLICIT (DIRPROP_FLAG(BN)|MASK_EXPLICIT) - -/* paragraph and segment separators */ -#define MASK_B_S (DIRPROP_FLAG(B)|DIRPROP_FLAG(S)) - -/* all types that are counted as White Space or Neutral in some steps */ -#define MASK_WS (MASK_B_S|DIRPROP_FLAG(WS)|MASK_BN_EXPLICIT) -#define MASK_N (DIRPROP_FLAG(O_N)|MASK_WS) - -/* all types that are included in a sequence of European Terminators for (W5) */ -#define MASK_ET_NSM_BN (DIRPROP_FLAG(ET)|DIRPROP_FLAG(NSM)|MASK_BN_EXPLICIT) - -/* types that are neutrals or could becomes neutrals in (Wn) */ -#define MASK_POSSIBLE_N (DIRPROP_FLAG(CS)|DIRPROP_FLAG(ES)|DIRPROP_FLAG(ET)|MASK_N) - -/* - * These types may be changed to "e", - * the embedding type (L or R) of the run, - * in the Bidi algorithm (N2) - */ -#define MASK_EMBEDDING (DIRPROP_FLAG(NSM)|MASK_POSSIBLE_N) - -/* the dirProp's L and R are defined to 0 and 1 values in nsCharType */ -#define GET_LR_FROM_LEVEL(level) ((DirProp)((level)&1)) - -#define IS_DEFAULT_LEVEL(level) (((level)&0xfe)==0xfe) - -/* handle surrogate pairs --------------------------------------------------- */ - -#define IS_FIRST_SURROGATE(uchar) (((uchar)&0xfc00)==0xd800) -#define IS_SECOND_SURROGATE(uchar) (((uchar)&0xfc00)==0xdc00) - -/* get the UTF-32 value directly from the surrogate pseudo-characters */ -#define SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000) -#define GET_UTF_32(first, second) (((first)<<10UL)+(second)-SURROGATE_OFFSET) - - -#define UTF_ERROR_VALUE 0xffff -/* definitions with forward iteration --------------------------------------- */ - -/* - * all the macros that go forward assume that - * the initial offset is 0<=i>10)+0xd7c0; \ - (s)[(i)++]=(PRUnichar)(c)&0x3ff|0xdc00; \ - } \ -} - -/* safe versions with error-checking and optional regularity-checking */ - -#define UTF16_APPEND_CHAR_SAFE(s, i, length, c) { \ - if((PRUInt32)(c)<=0xffff) { \ - (s)[(i)++]=(PRUnichar)(c); \ - } else if((PRUInt32)(c)<=0x10ffff) { \ - if((i)+1<(length)) { \ - (s)[(i)++]=(PRUnichar)((c)>>10)+0xd7c0; \ - (s)[(i)++]=(PRUnichar)(c)&0x3ff|0xdc00; \ - } else /* not enough space */ { \ - (s)[(i)++]=UTF_ERROR_VALUE; \ - } \ - } else /* c>0x10ffff, write error value */ { \ - (s)[(i)++]=UTF_ERROR_VALUE; \ - } \ -} - -/* definitions with backward iteration -------------------------------------- */ - -/* - * all the macros that go backward assume that - * the valid buffer range starts at offset 0 - * and that the initial offset is 00) { \ - UTF16_BACK_1_UNSAFE(s, i); \ - --__N; \ - } \ -} - -/* safe versions with error-checking and optional regularity-checking */ - -#define UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) { \ - (c)=(s)[--(i)]; \ - if(IS_SECOND_SURROGATE(c)) { \ - PRUnichar __c2; \ - if((i)>(start) && IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \ - --(i); \ - (c)=GET_UTF_32(__c2, (c)); \ - /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() */ \ - } else if(strict) {\ - /* unmatched second surrogate */ \ - (c)=UTF_ERROR_VALUE; \ - } \ - } else if(strict && IS_FIRST_SURROGATE(c)) { \ - /* unmatched first surrogate */ \ - (c)=UTF_ERROR_VALUE; \ - /* else strict: (c)==0xfffe is caught by UTF_IS_ERROR() */ \ - } \ -} - -#define UTF16_BACK_1_SAFE(s, start, i) { \ - if(IS_SECOND_SURROGATE((s)[--(i)]) && (i)>(start) && IS_FIRST_SURROGATE((s)[(i)-1])) { \ - --(i); \ - } \ -} - -#define UTF16_BACK_N_SAFE(s, start, i, n) { \ - PRInt32 __N=(n); \ - while(__N>0 && (i)>(start)) { \ - UTF16_BACK_1_SAFE(s, start, i); \ - --__N; \ - } \ -} - -#define UTF_PREV_CHAR_UNSAFE(s, i, c) UTF16_PREV_CHAR_UNSAFE(s, i, c) -#define UTF_PREV_CHAR_SAFE(s, start, i, c, strict) UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) -#define UTF_BACK_1_UNSAFE(s, i) UTF16_BACK_1_UNSAFE(s, i) -#define UTF_BACK_1_SAFE(s, start, i) UTF16_BACK_1_SAFE(s, start, i) -#define UTF_BACK_N_UNSAFE(s, i, n) UTF16_BACK_N_UNSAFE(s, i, n) -#define UTF_BACK_N_SAFE(s, start, i, n) UTF16_BACK_N_SAFE(s, start, i, n) -#define UTF_APPEND_CHAR_UNSAFE(s, i, c) UTF16_APPEND_CHAR_UNSAFE(s, i, c) -#define UTF_APPEND_CHAR_SAFE(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c) - -#define UTF_PREV_CHAR(s, start, i, c) UTF_PREV_CHAR_SAFE(s, start, i, c, PR_FALSE) -#define UTF_BACK_1(s, start, i) UTF_BACK_1_SAFE(s, start, i) -#define UTF_BACK_N(s, start, i, n) UTF_BACK_N_SAFE(s, start, i, n) -#define UTF_APPEND_CHAR(s, i, length, c) UTF_APPEND_CHAR_SAFE(s, i, length, c) - -/* Run structure for reordering --------------------------------------------- */ - -typedef struct Run { - PRInt32 logicalStart, /* first character of the run; b31 indicates even/odd level */ - visualLimit; /* last visual position of the run +1 */ -} Run; - -/* in a Run, logicalStart will get this bit set if the run level is odd */ -#define INDEX_ODD_BIT (1UL<<31) - -#define MAKE_INDEX_ODD_PAIR(index, level) (index|((PRUint32)level<<31)) -#define ADD_ODD_BIT_FROM_LEVEL(x, level) ((x)|=((PRUint32)level<<31)) -#define REMOVE_ODD_BIT(x) ((x)&=~INDEX_ODD_BIT) - -#define GET_INDEX(x) (x&~INDEX_ODD_BIT) -#define GET_ODD_BIT(x) ((PRUint32)x>>31) -#define IS_ODD_RUN(x) ((x&INDEX_ODD_BIT)!=0) -#define IS_EVEN_RUN(x) ((x&INDEX_ODD_BIT)==0) - -typedef PRUint32 Flags; - - /** - * Implementation of the nsIBidi interface - */ -class nsBidi : public nsIBidi { - NS_DECL_ISUPPORTS - -public: - /** @brief Default constructor. - * - * The nsBidi object is initially empty. It is assigned - * the Bidi properties of a paragraph by SetPara() - * or the Bidi properties of a line of a paragraph by - * GetLine().

- * This object can be reused for as long as it is not destroyed.

- * SetPara() will allocate additional memory for - * internal structures as necessary. - * - */ - nsBidi(); - - /** @brief Preallocating constructor - * Allocate an nsBidi - * object with preallocated memory for internal structures. This - * constructor provides an nsBidi object like - * the default constructor, but it also - * preallocates memory for internal structures according to the sizings - * supplied by the caller.

Subsequent functions will not allocate - * any more memory, and are thus guaranteed not to fail because of lack - * of memory.

The preallocation can be limited to some of the - * internal memory by setting some values to 0 here. That means that - * if, e.g., aMaxRunCount cannot be reasonably - * predetermined and should not be set to aMaxLength (the - * only failproof value) to avoid wasting memory, then - * aMaxRunCount could be set to 0 here and the internal - * structures that are associated with it will be allocated on demand, - * just like with the default constructor. - * - * If sufficient memory could not be allocated, no exception is thrown. - * Test whether mDirPropsSize == aMaxLength and/or mRunsSize == aMaxRunCount. - * - * @param aMaxLength is the maximum paragraph or line length that internal memory - * will be preallocated for. An attempt to associate this object with a - * longer text will fail, unless this value is 0, which leaves the allocation - * up to the implementation. - * - * @param aMaxRunCount is the maximum anticipated number of same-level runs - * that internal memory will be preallocated for. An attempt to access - * visual runs on an object that was not preallocated for as many runs - * as the text was actually resolved to will fail, - * unless this value is 0, which leaves the allocation up to the implementation.

- * The number of runs depends on the actual text and maybe anywhere between - * 1 and aMaxLength. It is typically small.

- */ - nsBidi(PRUint32 aMaxLength, PRUint32 aMaxRunCount); - - /** @brief Destructor. */ - virtual ~nsBidi(); - - NS_IMETHOD SetPara(const PRUnichar *aText, PRInt32 aLength, nsBidiLevel aParaLevel, nsBidiLevel *aEmbeddingLevels); - -#ifdef FULL_BIDI_ENGINE - NS_IMETHOD SetLine(nsIBidi* aParaBidi, PRInt32 aStart, PRInt32 aLimit); - - NS_IMETHOD GetDirection(nsBidiDirection* aDirection); - - NS_IMETHOD GetLength(PRInt32* aLength); - - NS_IMETHOD GetParaLevel(nsBidiLevel* aParaLevel); - - NS_IMETHOD GetLevelAt(PRInt32 aCharIndex, nsBidiLevel* aLevel); - - NS_IMETHOD GetLevels(nsBidiLevel** aLevels); -#endif // FULL_BIDI_ENGINE - NS_IMETHOD GetCharTypeAt(PRInt32 aCharIndex, nsCharType* aType); - - NS_IMETHOD GetLogicalRun(PRInt32 aLogicalStart, PRInt32* aLogicalLimit, nsBidiLevel* aLevel); - - NS_IMETHOD CountRuns(PRInt32* aRunCount); - - NS_IMETHOD GetVisualRun(PRInt32 aRunIndex, PRInt32* aLogicalStart, PRInt32* aLength, nsBidiDirection* aDirection); -#ifdef FULL_BIDI_ENGINE - NS_IMETHOD GetVisualIndex(PRInt32 aLogicalIndex, PRInt32* aVisualIndex); - - NS_IMETHOD GetLogicalIndex(PRInt32 aVisualIndex, PRInt32* aLogicalIndex); - - NS_IMETHOD GetLogicalMap(PRInt32 *aIndexMap); - - NS_IMETHOD GetVisualMap(PRInt32 *aIndexMap); - - NS_IMETHOD ReorderLogical(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap); - - NS_IMETHOD InvertMap(const PRInt32 *aSrcMap, PRInt32 *aDestMap, PRInt32 aLength); -#endif // FULL_BIDI_ENGINE - NS_IMETHOD ReorderVisual(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap); - - NS_IMETHOD WriteReverse(const PRUnichar *aSrc, PRInt32 aSrcLength, PRUnichar *aDest, PRUint16 aOptions, PRInt32 *aDestSize); - -protected: - /** length of the current text */ - PRInt32 mLength; - - /** memory sizes in bytes */ - PRSize mDirPropsSize, mLevelsSize, mRunsSize; - - /** allocated memory */ - DirProp* mDirPropsMemory; - nsBidiLevel* mLevelsMemory; - Run* mRunsMemory; - - /** indicators for whether memory may be allocated after construction */ - PRBool mMayAllocateText, mMayAllocateRuns; - - const DirProp* mDirProps; - nsBidiLevel* mLevels; - - /** the paragraph level */ - nsBidiLevel mParaLevel; - - /** flags is a bit set for which directional properties are in the text */ - Flags mFlags; - - /** the overall paragraph or line directionality - see nsBidiDirection */ - nsBidiDirection mDirection; - - /** characters after trailingWSStart are WS and are */ - /* implicitly at the paraLevel (rule (L1)) - levels may not reflect that */ - PRInt32 mTrailingWSStart; - - /** fields for line reordering */ - PRInt32 mRunCount; /* ==-1: runs not set up yet */ - Run* mRuns; - - /** for non-mixed text, we only need a tiny array of runs (no malloc()) */ - Run mSimpleRuns[1]; - -private: - - void Init(); - - PRBool GetMemory(void **aMemory, PRSize* aSize, PRBool aMayAllocate, PRSize aSizeNeeded); - - void Free(); - - void GetDirProps(const PRUnichar *aText); - - nsBidiDirection ResolveExplicitLevels(); - - nsresult CheckExplicitLevels(nsBidiDirection *aDirection); - - nsBidiDirection DirectionFromFlags(Flags aFlags); - - void ResolveImplicitLevels(PRInt32 aStart, PRInt32 aLimit, DirProp aSOR, DirProp aEOR); - - void AdjustWSLevels(); - - void SetTrailingWSStart(); - - PRBool GetRuns(); - - void GetSingleRun(nsBidiLevel aLevel); - - void ReorderLine(nsBidiLevel aMinLevel, nsBidiLevel aMaxLevel); - - PRBool PrepareReorder(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap, nsBidiLevel *aMinLevel, nsBidiLevel *aMaxLevel); -}; -#endif - -#endif // IBMBIDI diff --git a/mozilla/intl/unicharutil/src/nsBidiUtilsImp.h b/mozilla/intl/unicharutil/src/nsBidiUtilsImp.h deleted file mode 100644 index df7801b927a..00000000000 --- a/mozilla/intl/unicharutil/src/nsBidiUtilsImp.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * IBM Corporation. Portions created by IBM are - * Copyright (C) 2000 IBM Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsBidiUtilsImp_h__ -#define nsBidiUtilsImp_h__ - -#include "nsCom.h" -#include "nsISupports.h" -#include "nsIUBidiUtils.h" - -class nsBidiUtilsImp : public nsIUBidiUtils { - NS_DECL_ISUPPORTS - -public: - nsBidiUtilsImp(); - virtual ~nsBidiUtilsImp(); - - - /** - * Give a Unichar, return an eBidiCategory - */ - NS_IMETHOD GetBidiCategory(PRUnichar aChar, eBidiCategory* oResult); - - /** - * Give a Unichar, and an eBidiCategory, - * return PR_TRUE if the Unichar is in that category, - * return PR_FALSE, otherwise - */ - NS_IMETHOD IsBidiCategory(PRUnichar aChar, eBidiCategory aBidiCategory, PRBool* oResult); - - /** - * Give a Unichar - * return PR_TRUE if the Unichar is a Bidi control character (LRE, RLE, PDF, LRO, RLO, LRM, RLM) - * return PR_FALSE, otherwise - */ - NS_IMETHOD IsBidiControl(PRUnichar aChar, PRBool* oResult); - - /** - * Give a Unichar, return a nsCharType (compatible with ICU) - */ - NS_IMETHOD GetCharType(PRUnichar aChar, nsCharType* oResult); - - /** - * Give a Unichar, return the symmetric equivalent - */ - NS_IMETHOD SymmSwap(PRUnichar* aChar); - - - NS_IMETHOD ArabicShaping(const PRUnichar* aString, PRUint32 aLen, - PRUnichar* aBuf, PRUint32 *aBufLen); - - NS_IMETHOD HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag); - NS_IMETHOD HandleNumbers(const nsString aSrc, nsString & aDst ); - - NS_IMETHOD Conv_FE_06(const nsString aSrc, nsString & aDst ); - - NS_IMETHOD Conv_FE_06_WithReverse(const nsString aSrc, nsString & aDst ); - NS_IMETHOD Conv_06_FE_WithReverse(const nsString aSrc, nsString & aDst,PRUint32 aDir); -private: - PRUint32 mNumflag; -}; - -#endif /* nsBidiUtilsImp_h__ */ - diff --git a/mozilla/intl/unicharutil/src/nsUcharUtilModule.cpp b/mozilla/intl/unicharutil/src/nsUcharUtilModule.cpp index b663487c1c2..a8bfc266d8b 100644 --- a/mozilla/intl/unicharutil/src/nsUcharUtilModule.cpp +++ b/mozilla/intl/unicharutil/src/nsUcharUtilModule.cpp @@ -48,10 +48,6 @@ #include "nsUUDll.h" #include "nsFileSpec.h" #include "nsIFile.h" -#ifdef IBMBIDI -#include "nsBidiUtilsImp.h" -#include "nsBidiImp.h" -#endif // IBMBIDI // Functions used to create new instances of a given object by the // generic factory. @@ -87,10 +83,6 @@ MAKE_CTOR(HankakuToZenkaku) NS_GENERIC_FACTORY_CONSTRUCTOR(nsCaseConversionImp2) NS_GENERIC_FACTORY_CONSTRUCTOR(nsEntityConverter) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSaveAsCharset) -#ifdef IBMBIDI -NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiUtilsImp) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidi) -#endif // IBMBIDI //---------------------------------------------------------------------- // Since our class still refer to this two per dll global leave it here untill @@ -106,12 +98,6 @@ static const nsModuleComponentInfo components[] = NS_SAVEASCHARSET_CONTRACTID, nsSaveAsCharsetConstructor}, { "Japanese Hankaku To Zenkaku", NS_HANKAKUTOZENKAKU_CID, NS_HANKAKUTOZENKAKU_CONTRACTID, CreateNewHankakuToZenkaku}, -#ifdef IBMBIDI - { "Unichar Bidi Utility", NS_UNICHARBIDIUTIL_CID, - NS_UNICHARBIDIUTIL_CONTRACTID, nsBidiUtilsImpConstructor}, - { "Bidi Reordering Engine", NS_BIDI_CID, - NS_BIDI_CONTRACTID, nsBidiConstructor}, -#endif // IBMBIDI }; NS_IMPL_NSGETMODULE(UcharUtil, components) diff --git a/mozilla/intl/unicharutil/src/bidicattable.h b/mozilla/layout/base/bidicattable.h similarity index 99% rename from mozilla/intl/unicharutil/src/bidicattable.h rename to mozilla/layout/base/bidicattable.h index 38cbb68446a..f97939ba079 100644 --- a/mozilla/intl/unicharutil/src/bidicattable.h +++ b/mozilla/layout/base/bidicattable.h @@ -10,8 +10,8 @@ * for the specific language governing rights and limitations under the * MPL. * - * The Initial Developer of the Original Code is - * IBM Corporation. Portions created by IBM are + * The Initial Developer of the Original Code is IBM + * Corporation. Portions created by IBM are * Copyright (C) 2000 IBM Corporation. All * Rights Reserved. */ @@ -1943,4 +1943,3 @@ static eBidiCategory GetBidiCat(PRUnichar u) return eBidiCat_L; /* UNDEFINE = L */ }; /* total data size = 2252 */ - diff --git a/mozilla/intl/unicharutil/src/nsBidiImp.cpp b/mozilla/layout/base/nsBidi.cpp similarity index 92% rename from mozilla/intl/unicharutil/src/nsBidiImp.cpp rename to mozilla/layout/base/nsBidi.cpp index 32de5f97158..d8782adca2a 100644 --- a/mozilla/intl/unicharutil/src/nsBidiImp.cpp +++ b/mozilla/layout/base/nsBidi.cpp @@ -22,19 +22,41 @@ * Copyright (C) 2000, International Business Machines * Corporation and others. All Rights Reserved. * - * Contributor(s): + * Contributor(s): Simon Montagu */ #ifdef IBMBIDI #include "prmem.h" -#include "nsBidiImp.h" -#include "nsUUDll.h" -#include "nsIServiceManager.h" -#include "nsIUBidiUtils.h" +#include "nsBidi.h" +#include "nsBidiUtils.h" +#include "bidicattable.h" +#include "symmtable.h" +static nsCharType ebc2ucd[15] = { + eCharType_OtherNeutral, /* Placeholder -- there will never be a 0 index value */ + eCharType_LeftToRight, + eCharType_RightToLeft, + eCharType_RightToLeftArabic, + eCharType_ArabicNumber, + eCharType_EuropeanNumber, + eCharType_EuropeanNumberSeparator, + eCharType_EuropeanNumberTerminator, + eCharType_CommonNumberSeparator, + eCharType_OtherNeutral, + eCharType_DirNonSpacingMark, + eCharType_BoundaryNeutral, + eCharType_BlockSeparator, + eCharType_SegmentSeparator, + eCharType_WhiteSpaceNeutral +}; -NS_IMPL_ISUPPORTS1(nsBidi, nsIBidi) - +static nsCharType cc2ucd[5] = { + eCharType_LeftToRightEmbedding, + eCharType_RightToLeftEmbedding, + eCharType_PopDirectionalFormat, + eCharType_LeftToRightOverride, + eCharType_RightToLeftOverride +}; /* Comparing the description of the Bidi algorithm with this implementation is easier with the same names for the Bidi types in the code as there. @@ -200,7 +222,6 @@ nsBidi::~nsBidi() void nsBidi::Init() { - NS_INIT_REFCNT(); /* reset the object, all pointers NULL, all flags PR_FALSE, all sizes 0 */ mLength = 0; mParaLevel = 0; @@ -289,8 +310,8 @@ void nsBidi::Free() /* SetPara ------------------------------------------------------------ */ -NS_IMETHODIMP nsBidi::SetPara(const PRUnichar *aText, PRInt32 aLength, - nsBidiLevel aParaLevel, nsBidiLevel *aEmbeddingLevels) +nsresult nsBidi::SetPara(const PRUnichar *aText, PRInt32 aLength, + nsBidiLevel aParaLevel, nsBidiLevel *aEmbeddingLevels) { nsBidiDirection direction; @@ -477,82 +498,53 @@ void nsBidi::GetDirProps(const PRUnichar *aText) Flags flags=0; /* collect all directionalities in the text */ PRUnichar uchar; DirProp dirProp; - nsCharType dir; - nsCOMPtr bidiUtils = do_GetService("@mozilla.org/intl/unicharbidiutil;1"); - - if (!bidiUtils) { - /* default to left-to-right*/ - flags |= DIRPROP_FLAG(L); - if(IS_DEFAULT_LEVEL(mParaLevel)) { - mParaLevel&=1; - } - while (iGetCharType(uchar, &dir); - flags|=DIRPROP_FLAG(dirProps[i]=dirProp=dir); - } else { - /* a surrogate pair */ - dirProps[i++]=BN; /* first surrogate in the pair gets the BN type */ - bidiUtils->GetCharType(GET_UTF_32(uchar, aText[i]), &dir); - flags|=DIRPROP_FLAG(dirProps[i]=dirProp=dir)|DIRPROP_FLAG(BN); - } - ++i; - if(dirProp==L) { - mParaLevel=0; - break; - } else if(dirProp==R || dirProp==AL) { - mParaLevel=1; - break; - } else if(i==length) { - /* - * see comment in nsIBidi.h: - * the DEFAULT_XXX values are designed so that - * their bit 0 alone yields the intended default - */ - mParaLevel&=1; - break; - } + if(dirProp==L) { + mParaLevel=0; + break; + } else if(dirProp==R || dirProp==AL) { + mParaLevel=1; + break; + } else if(i==length) { + /* + * see comment in nsIBidi.h: + * the DEFAULT_XXX values are designed so that + * their bit 0 alone yields the intended default + */ + mParaLevel&=1; + break; } } + } - /* get the rest of the directional properties and the flags bits */ - while(iGetCharType(uchar, &dir); - flags|=DIRPROP_FLAG(dirProps[i]=dir); - } else { - /* a surrogate pair */ - dirProps[i++]=BN; /* second surrogate in the pair gets the BN type */ - bidiUtils->GetCharType(GET_UTF_32(uchar, aText[i]), &dir); - flags|=DIRPROP_FLAG(dirProps[i]=dir)|DIRPROP_FLAG(BN); - } - ++i; - } - if(flags&MASK_EMBEDDING) { - flags|=DIRPROP_FLAG_LR(mParaLevel); + /* get the rest of the directional properties and the flags bits */ + while(ivisual mapping ------------------------------- */ -NS_IMETHODIMP nsBidi::GetVisualIndex(PRInt32 aLogicalIndex, PRInt32* aVisualIndex) { +nsresult nsBidi::GetVisualIndex(PRInt32 aLogicalIndex, PRInt32* aVisualIndex) { if(aLogicalIndex<0 || mLength<=aLogicalIndex) { return NS_ERROR_INVALID_ARG; } else { @@ -1947,7 +1939,7 @@ NS_IMETHODIMP nsBidi::GetVisualIndex(PRInt32 aLogicalIndex, PRInt32* aVisualInde } } -NS_IMETHODIMP nsBidi::GetLogicalIndex(PRInt32 aVisualIndex, PRInt32 *aLogicalIndex) +nsresult nsBidi::GetLogicalIndex(PRInt32 aVisualIndex, PRInt32 *aLogicalIndex) { if(aVisualIndex<0 || mLength<=aVisualIndex) { return NS_ERROR_INVALID_ARG; @@ -2006,7 +1998,7 @@ NS_IMETHODIMP nsBidi::GetLogicalIndex(PRInt32 aVisualIndex, PRInt32 *aLogicalInd } } -NS_IMETHODIMP nsBidi::GetLogicalMap(PRInt32 *aIndexMap) +nsresult nsBidi::GetLogicalMap(PRInt32 *aIndexMap) { nsBidiLevel *levels; nsresult rv; @@ -2022,7 +2014,7 @@ NS_IMETHODIMP nsBidi::GetLogicalMap(PRInt32 *aIndexMap) } } -NS_IMETHODIMP nsBidi::GetVisualMap(PRInt32 *aIndexMap) +nsresult nsBidi::GetVisualMap(PRInt32 *aIndexMap) { PRInt32* runCount=NULL; nsresult rv; @@ -2061,7 +2053,7 @@ NS_IMETHODIMP nsBidi::GetVisualMap(PRInt32 *aIndexMap) /* reorder a line based on a levels array (L2) ------------------------------ */ -NS_IMETHODIMP nsBidi::ReorderLogical(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap) +nsresult nsBidi::ReorderLogical(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap) { PRInt32 start, limit, sumOfSosEos; nsBidiLevel minLevel, maxLevel; @@ -2126,7 +2118,7 @@ NS_IMETHODIMP nsBidi::ReorderLogical(const nsBidiLevel *aLevels, PRInt32 aLength return NS_OK; } -NS_IMETHODIMP nsBidi::InvertMap(const PRInt32 *aSrcMap, PRInt32 *aDestMap, PRInt32 aLength) +nsresult nsBidi::InvertMap(const PRInt32 *aSrcMap, PRInt32 *aDestMap, PRInt32 aLength) { if(aSrcMap!=NULL && aDestMap!=NULL) { aSrcMap+=aLength; @@ -2138,8 +2130,8 @@ NS_IMETHODIMP nsBidi::InvertMap(const PRInt32 *aSrcMap, PRInt32 *aDestMap, PRInt } #endif // FULL_BIDI_ENGINE -static PRInt32 doWriteReverse(const PRUnichar *src, PRInt32 srcLength, - PRUnichar *dest, PRUint16 options) { +PRInt32 nsBidi::doWriteReverse(const PRUnichar *src, PRInt32 srcLength, + PRUnichar *dest, PRUint16 options) { /* * RTL run - * @@ -2161,8 +2153,6 @@ static PRInt32 doWriteReverse(const PRUnichar *src, PRInt32 srcLength, PRInt32 i, j, destSize; PRUint32 c; - nsCOMPtr bidiUtils = do_GetService("@mozilla.org/intl/unicharbidiutil;1"); - /* optimize for several combinations of options */ switch(options&(NSBIDI_REMOVE_BIDI_CONTROLS|NSBIDI_DO_MIRRORING|NSBIDI_KEEP_BASE_COMBINING)) { case 0: @@ -2204,11 +2194,9 @@ static PRInt32 doWriteReverse(const PRUnichar *src, PRInt32 srcLength, i=srcLength; /* collect code units and modifier letters for one base character */ - PRBool isModifier; do { UTF_PREV_CHAR(src, 0, srcLength, c); - bidiUtils->IsBidiCategory(c, eBidiCat_NSM, &isModifier); - } while(srcLength>0 && isModifier); + } while(srcLength>0 && IsBidiCategory(c, eBidiCat_NSM)); /* copy this "user character" */ j=srcLength; @@ -2232,13 +2220,11 @@ static PRInt32 doWriteReverse(const PRUnichar *src, PRInt32 srcLength, which will not include the Bidi control characters */ PRInt32 length=srcLength; PRUnichar ch; - PRBool isBidiControl; i=0; do { ch=*src++; - bidiUtils->IsBidiControl(ch, &isBidiControl); - if(!isBidiControl) { + if (!IsBidiControl(ch)) { ++i; } } while(--length>0); @@ -2255,18 +2241,12 @@ static PRInt32 doWriteReverse(const PRUnichar *src, PRInt32 srcLength, UTF_PREV_CHAR(src, 0, srcLength, c); if(options&NSBIDI_KEEP_BASE_COMBINING) { /* collect modifier letters for this base character */ - PRBool isModifier; - bidiUtils->IsBidiCategory(c, eBidiCat_NSM, &isModifier); - while(srcLength>0 && isModifier) { + while(srcLength>0 && IsBidiCategory(c, eBidiCat_NSM)) { UTF_PREV_CHAR(src, 0, srcLength, c); - bidiUtils->IsBidiCategory(c, eBidiCat_NSM, &isModifier); } } - PRBool isBidiControl; - bidiUtils->IsBidiControl(c, &isBidiControl); - - if(options&NSBIDI_REMOVE_BIDI_CONTROLS && isBidiControl) { + if(options&NSBIDI_REMOVE_BIDI_CONTROLS && IsBidiControl(c)) { /* do not copy this Bidi control character */ continue; } @@ -2275,13 +2255,8 @@ static PRInt32 doWriteReverse(const PRUnichar *src, PRInt32 srcLength, j=srcLength; if(options&NSBIDI_DO_MIRRORING) { /* mirror only the base character */ - if (!bidiUtils) - ; /* default to the original form */ - else { - PRUnichar ch = (PRUnichar)c; - bidiUtils->SymmSwap(&ch); - c = ch; - } + c = SymmSwap((PRUnichar)c); + PRInt32 k=0; UTF_APPEND_CHAR_UNSAFE(dest, k, c); dest+=k; @@ -2296,7 +2271,7 @@ static PRInt32 doWriteReverse(const PRUnichar *src, PRInt32 srcLength, return destSize; } -NS_IMETHODIMP nsBidi::WriteReverse(const PRUnichar *aSrc, PRInt32 aSrcLength, PRUnichar *aDest, PRUint16 aOptions, PRInt32 *aDestSize) +nsresult nsBidi::WriteReverse(const PRUnichar *aSrc, PRInt32 aSrcLength, PRUnichar *aDest, PRUint16 aOptions, PRInt32 *aDestSize) { if( aSrc==NULL || aSrcLength<0 || aDest==NULL @@ -2317,4 +2292,51 @@ NS_IMETHODIMP nsBidi::WriteReverse(const PRUnichar *aSrc, PRInt32 aSrcLength, PR return NS_OK; } +eBidiCategory nsBidi::GetBidiCategory(PRUnichar aChar) +{ + eBidiCategory oResult = GetBidiCat(aChar); + if (eBidiCat_CC == oResult) + oResult = (eBidiCategory)(aChar & 0xFF); /* Control codes have special treatment to keep the tables smaller */ + return oResult; +} + +PRBool nsBidi::IsBidiCategory(PRUnichar aChar, eBidiCategory aBidiCategory) +{ + return (GetBidiCategory(aChar) == aBidiCategory); +} + +#define LRM_CHAR 0x200e +PRBool nsBidi::IsBidiControl(PRUnichar aChar) +{ + // This method is used when stripping Bidi control characters for + // display, so it will return TRUE for LRM and RLM as well as the + // characters with category eBidiCat_CC + return (eBidiCat_CC == GetBidiCat(aChar) || ((aChar)&0xfffe)==LRM_CHAR); +} + +nsCharType nsBidi::GetCharType(PRUnichar aChar) +{ + nsCharType oResult; + eBidiCategory bCat = GetBidiCat(aChar); + if (eBidiCat_CC != bCat) { + NS_ASSERTION(bCat < (sizeof(ebc2ucd)/sizeof(nsCharType)), "size mismatch"); + if(bCat < (sizeof(ebc2ucd)/sizeof(nsCharType))) + oResult = ebc2ucd[bCat]; + else + oResult = ebc2ucd[0]; // something is very wrong, but we need to return a value + } else { + NS_ASSERTION((aChar-0x202a) < (sizeof(cc2ucd)/sizeof(nsCharType)), "size mismatch"); + if((aChar-0x202a) < (sizeof(cc2ucd)/sizeof(nsCharType))) + oResult = cc2ucd[aChar - 0x202a]; + else + oResult = ebc2ucd[0]; // something is very wrong, but we need to return a value + } + return oResult; +} + +PRUnichar nsBidi::SymmSwap(PRUnichar aChar) +{ + return Mirrored(aChar); +} + #endif // IBMBIDI diff --git a/mozilla/intl/unicharutil/public/nsIBidi.h b/mozilla/layout/base/nsBidi.h similarity index 54% rename from mozilla/intl/unicharutil/public/nsIBidi.h rename to mozilla/layout/base/nsBidi.h index 3edbf934519..8224d7d2591 100644 --- a/mozilla/intl/unicharutil/public/nsIBidi.h +++ b/mozilla/layout/base/nsBidi.h @@ -22,26 +22,16 @@ * Copyright (C) 2000, International Business Machines * Corporation and others. All Rights Reserved. * - * Contributor(s): + * Contributor(s): Simon Montagu */ -#ifdef IBMBIDI -#ifndef nsIBidi_h__ -#define nsIBidi_h__ +#ifndef nsBidi_h__ +#define nsBidi_h__ -#include "nsISupports.h" -#include "prtypes.h" - -#define NS_BIDI_CID \ - { 0xd9123b91, 0xf4f2, 0x11d3, \ - {0xb6, 0xf1, 0x0, 0x10, 0x4b, 0x41, 0x19, 0xf8} } - -#define NS_BIDI_CONTRACTID "@mozilla.org/intl/bidi;1" - -#define NS_BIDI_IID \ - { 0xd9123b92, 0xf4f2, 0x11d3, \ - { 0xb6, 0xf1, 0x0, 0x10, 0x4b, 0x41, 0x19, 0xf8 } } +#include "nsCOMPtr.h" +#include "nsString.h" +// Bidi reordering engine from ICU /* * javadoc-style comments are intended to be transformed into HTML * using DOC++ - see @@ -153,6 +143,40 @@ typedef enum nsBidiDirection nsBidiDirection; /* miscellaneous definitions ------------------------------------------------ */ + /** + * Read ftp://ftp.unicode.org/Public/UNIDATA/ReadMe-Latest.txt + * section BIDIRECTIONAL PROPERTIES + * for the detailed definition of the following categories + * + * The values here must match the equivalents in %map in + * mozilla/intl/unicharutil/tools/genbidicattable.pl + */ + +typedef enum { + eBidiCat_Undefined, + eBidiCat_L, /* Left-to-Right */ + eBidiCat_R, /* Right-to-Left */ + eBidiCat_AL, /* Right-to-Left Arabic */ + eBidiCat_AN, /* Arabic Number */ + eBidiCat_EN, /* European Number */ + eBidiCat_ES, /* European Number Separator */ + eBidiCat_ET, /* European Number Terminator */ + eBidiCat_CS, /* Common Number Separator */ + eBidiCat_ON, /* Other Neutrals */ + eBidiCat_NSM, /* Non-Spacing Mark */ + eBidiCat_BN, /* Boundary Neutral */ + eBidiCat_B, /* Paragraph Separator */ + eBidiCat_S, /* Segment Separator */ + eBidiCat_WS, /* Whitespace */ + eBidiCat_CC = 0xf, /* Control Code */ + /* (internal use only - will never be outputed) */ + eBidiCat_LRE = 0x2a, /* Left-to-Right Embedding */ + eBidiCat_RLE = 0x2b, /* Right-to-Left Embedding */ + eBidiCat_PDF = 0x2c, /* Pop Directional Formatting */ + eBidiCat_LRO = 0x2d, /* Left-to-Right Override */ + eBidiCat_RLO = 0x2e /* Right-to-Left Override */ +} eBidiCategory; + enum nsCharType { eCharType_LeftToRight = 0, eCharType_RightToLeft = 1, @@ -217,6 +241,236 @@ typedef enum nsCharType nsCharType; */ #define NSBIDI_REMOVE_BIDI_CONTROLS 8 +/* helper macros for each allocated array member */ +#define GETDIRPROPSMEMORY(length) \ + GetMemory((void **)&mDirPropsMemory, &mDirPropsSize, \ + mMayAllocateText, (length)) + +#define GETLEVELSMEMORY(length) \ + GetMemory((void **)&mLevelsMemory, &mLevelsSize, \ + mMayAllocateText, (length)) + +#define GETRUNSMEMORY(length) \ + GetMemory((void **)&mRunsMemory, &mRunsSize, \ + mMayAllocateRuns, (length)*sizeof(Run)) + +/* additional macros used by constructor - always allow allocation */ +#define GETINITIALDIRPROPSMEMORY(length) \ + GetMemory((void **)&mDirPropsMemory, &mDirPropsSize, \ + PR_TRUE, (length)) + +#define GETINITIALLEVELSMEMORY(length) \ + GetMemory((void **)&mLevelsMemory, &mLevelsSize, \ + PR_TRUE, (length)) + +#define GETINITIALRUNSMEMORY(length) \ + GetMemory((void **)&mRunsMemory, &mRunsSize, \ + PR_TRUE, (length)*sizeof(Run)) + +/* + * Sometimes, bit values are more appropriate + * to deal with directionality properties. + * Abbreviations in these macro names refer to names + * used in the Bidi algorithm. + */ +typedef PRUint8 DirProp; + +#define DIRPROP_FLAG(dir) (1UL<<(dir)) + +/* special flag for multiple runs from explicit embedding codes */ +#define DIRPROP_FLAG_MULTI_RUNS (1UL<<31) + +/* are there any characters that are LTR or RTL? */ +#define MASK_LTR (DIRPROP_FLAG(L)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(AN)|DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)) +#define MASK_RTL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO)) + +/* explicit embedding codes */ +#define MASK_LRX (DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)) +#define MASK_RLX (DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO)) +#define MASK_OVERRIDE (DIRPROP_FLAG(LRO)|DIRPROP_FLAG(RLO)) + +#define MASK_EXPLICIT (MASK_LRX|MASK_RLX|DIRPROP_FLAG(PDF)) +#define MASK_BN_EXPLICIT (DIRPROP_FLAG(BN)|MASK_EXPLICIT) + +/* paragraph and segment separators */ +#define MASK_B_S (DIRPROP_FLAG(B)|DIRPROP_FLAG(S)) + +/* all types that are counted as White Space or Neutral in some steps */ +#define MASK_WS (MASK_B_S|DIRPROP_FLAG(WS)|MASK_BN_EXPLICIT) +#define MASK_N (DIRPROP_FLAG(O_N)|MASK_WS) + +/* all types that are included in a sequence of European Terminators for (W5) */ +#define MASK_ET_NSM_BN (DIRPROP_FLAG(ET)|DIRPROP_FLAG(NSM)|MASK_BN_EXPLICIT) + +/* types that are neutrals or could becomes neutrals in (Wn) */ +#define MASK_POSSIBLE_N (DIRPROP_FLAG(CS)|DIRPROP_FLAG(ES)|DIRPROP_FLAG(ET)|MASK_N) + +/* + * These types may be changed to "e", + * the embedding type (L or R) of the run, + * in the Bidi algorithm (N2) + */ +#define MASK_EMBEDDING (DIRPROP_FLAG(NSM)|MASK_POSSIBLE_N) + +/* the dirProp's L and R are defined to 0 and 1 values in nsCharType */ +#define GET_LR_FROM_LEVEL(level) ((DirProp)((level)&1)) + +#define IS_DEFAULT_LEVEL(level) (((level)&0xfe)==0xfe) + +/* handle surrogate pairs --------------------------------------------------- */ + +#define IS_FIRST_SURROGATE(uchar) (((uchar)&0xfc00)==0xd800) +#define IS_SECOND_SURROGATE(uchar) (((uchar)&0xfc00)==0xdc00) + +/* get the UTF-32 value directly from the surrogate pseudo-characters */ +#define SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000) +#define GET_UTF_32(first, second) (((first)<<10UL)+(second)-SURROGATE_OFFSET) + + +#define UTF_ERROR_VALUE 0xffff +/* definitions with forward iteration --------------------------------------- */ + +/* + * all the macros that go forward assume that + * the initial offset is 0<=i>10)+0xd7c0; \ + (s)[(i)++]=(PRUnichar)(c)&0x3ff|0xdc00; \ + } \ +} + +/* safe versions with error-checking and optional regularity-checking */ + +#define UTF16_APPEND_CHAR_SAFE(s, i, length, c) { \ + if((PRUInt32)(c)<=0xffff) { \ + (s)[(i)++]=(PRUnichar)(c); \ + } else if((PRUInt32)(c)<=0x10ffff) { \ + if((i)+1<(length)) { \ + (s)[(i)++]=(PRUnichar)((c)>>10)+0xd7c0; \ + (s)[(i)++]=(PRUnichar)(c)&0x3ff|0xdc00; \ + } else /* not enough space */ { \ + (s)[(i)++]=UTF_ERROR_VALUE; \ + } \ + } else /* c>0x10ffff, write error value */ { \ + (s)[(i)++]=UTF_ERROR_VALUE; \ + } \ +} + +/* definitions with backward iteration -------------------------------------- */ + +/* + * all the macros that go backward assume that + * the valid buffer range starts at offset 0 + * and that the initial offset is 00) { \ + UTF16_BACK_1_UNSAFE(s, i); \ + --__N; \ + } \ +} + +/* safe versions with error-checking and optional regularity-checking */ + +#define UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) { \ + (c)=(s)[--(i)]; \ + if(IS_SECOND_SURROGATE(c)) { \ + PRUnichar __c2; \ + if((i)>(start) && IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \ + --(i); \ + (c)=GET_UTF_32(__c2, (c)); \ + /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() */ \ + } else if(strict) {\ + /* unmatched second surrogate */ \ + (c)=UTF_ERROR_VALUE; \ + } \ + } else if(strict && IS_FIRST_SURROGATE(c)) { \ + /* unmatched first surrogate */ \ + (c)=UTF_ERROR_VALUE; \ + /* else strict: (c)==0xfffe is caught by UTF_IS_ERROR() */ \ + } \ +} + +#define UTF16_BACK_1_SAFE(s, start, i) { \ + if(IS_SECOND_SURROGATE((s)[--(i)]) && (i)>(start) && IS_FIRST_SURROGATE((s)[(i)-1])) { \ + --(i); \ + } \ +} + +#define UTF16_BACK_N_SAFE(s, start, i, n) { \ + PRInt32 __N=(n); \ + while(__N>0 && (i)>(start)) { \ + UTF16_BACK_1_SAFE(s, start, i); \ + --__N; \ + } \ +} + +#define UTF_PREV_CHAR_UNSAFE(s, i, c) UTF16_PREV_CHAR_UNSAFE(s, i, c) +#define UTF_PREV_CHAR_SAFE(s, start, i, c, strict) UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) +#define UTF_BACK_1_UNSAFE(s, i) UTF16_BACK_1_UNSAFE(s, i) +#define UTF_BACK_1_SAFE(s, start, i) UTF16_BACK_1_SAFE(s, start, i) +#define UTF_BACK_N_UNSAFE(s, i, n) UTF16_BACK_N_UNSAFE(s, i, n) +#define UTF_BACK_N_SAFE(s, start, i, n) UTF16_BACK_N_SAFE(s, start, i, n) +#define UTF_APPEND_CHAR_UNSAFE(s, i, c) UTF16_APPEND_CHAR_UNSAFE(s, i, c) +#define UTF_APPEND_CHAR_SAFE(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c) + +#define UTF_PREV_CHAR(s, start, i, c) UTF_PREV_CHAR_SAFE(s, start, i, c, PR_FALSE) +#define UTF_BACK_1(s, start, i) UTF_BACK_1_SAFE(s, start, i) +#define UTF_BACK_N(s, start, i, n) UTF_BACK_N_SAFE(s, start, i, n) +#define UTF_APPEND_CHAR(s, i, length, c) UTF_APPEND_CHAR_SAFE(s, i, length, c) + +/* Run structure for reordering --------------------------------------------- */ + +typedef struct Run { + PRInt32 logicalStart, /* first character of the run; b31 indicates even/odd level */ + visualLimit; /* last visual position of the run +1 */ +} Run; + +/* in a Run, logicalStart will get this bit set if the run level is odd */ +#define INDEX_ODD_BIT (1UL<<31) + +#define MAKE_INDEX_ODD_PAIR(index, level) (index|((PRUint32)level<<31)) +#define ADD_ODD_BIT_FROM_LEVEL(x, level) ((x)|=((PRUint32)level<<31)) +#define REMOVE_ODD_BIT(x) ((x)&=~INDEX_ODD_BIT) + +#define GET_INDEX(x) (x&~INDEX_ODD_BIT) +#define GET_ODD_BIT(x) ((PRUint32)x>>31) +#define IS_ODD_RUN(x) ((x&INDEX_ODD_BIT)!=0) +#define IS_EVEN_RUN(x) ((x&INDEX_ODD_BIT)==0) + +typedef PRUint32 Flags; + /** * This class holds information about a paragraph of text * with Bidi-algorithm-related details, or about one line of @@ -233,10 +487,61 @@ typedef enum nsCharType nsCharType; * SetPara will allocate additional memory for * internal structures as necessary. */ -class nsIBidi : public nsISupports +class nsBidi { public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_BIDI_IID) + /** @brief Default constructor. + * + * The nsBidi object is initially empty. It is assigned + * the Bidi properties of a paragraph by SetPara() + * or the Bidi properties of a line of a paragraph by + * GetLine().

+ * This object can be reused for as long as it is not destroyed.

+ * SetPara() will allocate additional memory for + * internal structures as necessary. + * + */ + nsBidi(); + + /** @brief Preallocating constructor + * Allocate an nsBidi + * object with preallocated memory for internal structures. This + * constructor provides an nsBidi object like + * the default constructor, but it also + * preallocates memory for internal structures according to the sizings + * supplied by the caller.

Subsequent functions will not allocate + * any more memory, and are thus guaranteed not to fail because of lack + * of memory.

The preallocation can be limited to some of the + * internal memory by setting some values to 0 here. That means that + * if, e.g., aMaxRunCount cannot be reasonably + * predetermined and should not be set to aMaxLength (the + * only failproof value) to avoid wasting memory, then + * aMaxRunCount could be set to 0 here and the internal + * structures that are associated with it will be allocated on demand, + * just like with the default constructor. + * + * If sufficient memory could not be allocated, no exception is thrown. + * Test whether mDirPropsSize == aMaxLength and/or mRunsSize == aMaxRunCount. + * + * @param aMaxLength is the maximum paragraph or line length that internal memory + * will be preallocated for. An attempt to associate this object with a + * longer text will fail, unless this value is 0, which leaves the allocation + * up to the implementation. + * + * @param aMaxRunCount is the maximum anticipated number of same-level runs + * that internal memory will be preallocated for. An attempt to access + * visual runs on an object that was not preallocated for as many runs + * as the text was actually resolved to will fail, + * unless this value is 0, which leaves the allocation up to the implementation.

+ * The number of runs depends on the actual text and maybe anywhere between + * 1 and aMaxLength. It is typically small.

+ */ + nsBidi(PRUint32 aMaxLength, PRUint32 aMaxRunCount); + + /** @brief Destructor. */ + virtual ~nsBidi(); + + /** * Perform the Unicode Bidi algorithm. It is defined in the * Unicode Technical Report 9, @@ -298,7 +603,7 @@ public: * The aEmbeddingLevels array must be * at least aLength long. */ - NS_IMETHOD SetPara(const PRUnichar *aText, PRInt32 aLength, nsBidiLevel aParaLevel, nsBidiLevel *aEmbeddingLevels) = 0; + nsresult SetPara(const PRUnichar *aText, PRInt32 aLength, nsBidiLevel aParaLevel, nsBidiLevel *aEmbeddingLevels); #ifdef FULL_BIDI_ENGINE /** @@ -334,7 +639,7 @@ public: * * @see SetPara */ - NS_IMETHOD SetLine(nsIBidi* aParaBidi, PRInt32 aStart, PRInt32 aLimit) = 0; + nsresult SetLine(nsIBidi* aParaBidi, PRInt32 aStart, PRInt32 aLimit); /** * Get the directionality of the text. @@ -345,14 +650,14 @@ public: * * @see nsBidiDirection */ - NS_IMETHOD GetDirection(nsBidiDirection* aDirection) = 0; + nsresult GetDirection(nsBidiDirection* aDirection); /** * Get the length of the text. * * @param aLength receives the length of the text that the nsBidi object was created for. */ - NS_IMETHOD GetLength(PRInt32* aLength) = 0; + nsresult GetLength(PRInt32* aLength); /** * Get the paragraph level of the text. @@ -361,7 +666,7 @@ public: * * @see nsBidiLevel */ - NS_IMETHOD GetParaLevel(nsBidiLevel* aParaLevel) = 0; + nsresult GetParaLevel(nsBidiLevel* aParaLevel); /** * Get the level for one character. @@ -372,7 +677,7 @@ public: * * @see nsBidiLevel */ - NS_IMETHOD GetLevelAt(PRInt32 aCharIndex, nsBidiLevel* aLevel) = 0; + nsresult GetLevelAt(PRInt32 aCharIndex, nsBidiLevel* aLevel); /** * Get an array of levels for each character.

@@ -385,7 +690,7 @@ public: * * @see nsBidiLevel */ - NS_IMETHOD GetLevels(nsBidiLevel** aLevels) = 0; + nsresult GetLevels(nsBidiLevel** aLevels); #endif // FULL_BIDI_ENGINE /** * Get the bidirectional type for one character. @@ -394,7 +699,7 @@ public: * * @param aType receives the bidirectional type of the character at aCharIndex. */ - NS_IMETHOD GetCharTypeAt(PRInt32 aCharIndex, nsCharType* aType) = 0; + nsresult GetCharTypeAt(PRInt32 aCharIndex, nsCharType* aType); /** * Get a logical run. @@ -415,7 +720,7 @@ public: * This pointer can be NULL if this * value is not necessary. */ - NS_IMETHOD GetLogicalRun(PRInt32 aLogicalStart, PRInt32* aLogicalLimit, nsBidiLevel* aLevel) = 0; + nsresult GetLogicalRun(PRInt32 aLogicalStart, PRInt32* aLogicalLimit, nsBidiLevel* aLevel); /** * Get the number of runs. @@ -427,7 +732,7 @@ public: * * @param aRunCount will receive the number of runs. */ - NS_IMETHOD CountRuns(PRInt32* aRunCount) = 0; + nsresult CountRuns(PRInt32* aRunCount); /** * Get one run's logical start, length, and directionality, @@ -477,7 +782,7 @@ public: * modifier letters before base characters and second surrogates * before first ones. */ - NS_IMETHOD GetVisualRun(PRInt32 aRunIndex, PRInt32* aLogicalStart, PRInt32* aLength, nsBidiDirection* aDirection) = 0; + nsresult GetVisualRun(PRInt32 aRunIndex, PRInt32* aLogicalStart, PRInt32* aLength, nsBidiDirection* aDirection); #ifdef FULL_BIDI_ENGINE /** @@ -497,7 +802,7 @@ public: * @see GetLogicalMap * @see GetLogicalIndex */ - NS_IMETHOD GetVisualIndex(PRInt32 aLogicalIndex, PRInt32* aVisualIndex) = 0; + nsresult GetVisualIndex(PRInt32 aLogicalIndex, PRInt32* aVisualIndex); /** * Get the logical text position from a visual position. @@ -514,7 +819,7 @@ public: * @see GetVisualMap * @see GetVisualIndex */ - NS_IMETHOD GetLogicalIndex(PRInt32 aVisualIndex, PRInt32* aLogicalIndex) = 0; + nsresult GetLogicalIndex(PRInt32 aVisualIndex, PRInt32* aLogicalIndex); /** * Get a logical-to-visual index map (array) for the characters in the nsBidi @@ -528,7 +833,7 @@ public: * @see GetVisualMap * @see GetVisualIndex */ - NS_IMETHOD GetLogicalMap(PRInt32 *aIndexMap) = 0; + nsresult GetLogicalMap(PRInt32 *aIndexMap); /** * Get a visual-to-logical index map (array) for the characters in the nsBidi @@ -542,7 +847,7 @@ public: * @see GetLogicalMap * @see GetLogicalIndex */ - NS_IMETHOD GetVisualMap(PRInt32 *aIndexMap) = 0; + nsresult GetVisualMap(PRInt32 *aIndexMap); /** * This is a convenience function that does not use a nsBidi object. @@ -563,7 +868,7 @@ public: * The array does not need to be initialized.

* The index map will result in aIndexMap[aLogicalIndex]==aVisualIndex. */ - NS_IMETHOD ReorderLogical(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap) = 0; + nsresult ReorderLogical(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap); #endif // FULL_BIDI_ENGINE /** * This is a convenience function that does not use a nsBidi object. @@ -584,7 +889,7 @@ public: * The array does not need to be initialized.

* The index map will result in aIndexMap[aVisualIndex]==aLogicalIndex. */ - NS_IMETHOD ReorderVisual(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap) = 0; + nsresult ReorderVisual(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap); #ifdef FULL_BIDI_ENGINE /** @@ -600,7 +905,7 @@ public: * * @param aLength is the length of each array. */ - NS_IMETHOD InvertMap(const PRInt32 *aSrcMap, PRInt32 *aDestMap, PRInt32 aLength) = 0; + nsresult InvertMap(const PRInt32 *aSrcMap, PRInt32 *aDestMap, PRInt32 aLength); #endif // FULL_BIDI_ENGINE /** * Reverse a Right-To-Left run of Unicode text. @@ -637,10 +942,106 @@ public: * * @param aDestSize will receive the number of characters that were written to aDest. */ - NS_IMETHOD WriteReverse(const PRUnichar *aSrc, PRInt32 aSrcLength, PRUnichar *aDest, PRUint16 aOptions, PRInt32 *aDestSize) = 0; + nsresult WriteReverse(const PRUnichar *aSrc, PRInt32 aSrcLength, PRUnichar *aDest, PRUint16 aOptions, PRInt32 *aDestSize); +protected: + /** length of the current text */ + PRInt32 mLength; + + /** memory sizes in bytes */ + PRSize mDirPropsSize, mLevelsSize, mRunsSize; + + /** allocated memory */ + DirProp* mDirPropsMemory; + nsBidiLevel* mLevelsMemory; + Run* mRunsMemory; + + /** indicators for whether memory may be allocated after construction */ + PRBool mMayAllocateText, mMayAllocateRuns; + + const DirProp* mDirProps; + nsBidiLevel* mLevels; + + /** the paragraph level */ + nsBidiLevel mParaLevel; + + /** flags is a bit set for which directional properties are in the text */ + Flags mFlags; + + /** the overall paragraph or line directionality - see nsBidiDirection */ + nsBidiDirection mDirection; + + /** characters after trailingWSStart are WS and are */ + /* implicitly at the paraLevel (rule (L1)) - levels may not reflect that */ + PRInt32 mTrailingWSStart; + + /** fields for line reordering */ + PRInt32 mRunCount; /* ==-1: runs not set up yet */ + Run* mRuns; + + /** for non-mixed text, we only need a tiny array of runs (no malloc()) */ + Run mSimpleRuns[1]; + +private: + + void Init(); + + PRBool GetMemory(void **aMemory, PRSize* aSize, PRBool aMayAllocate, PRSize aSizeNeeded); + + void Free(); + + void GetDirProps(const PRUnichar *aText); + + nsBidiDirection ResolveExplicitLevels(); + + nsresult CheckExplicitLevels(nsBidiDirection *aDirection); + + nsBidiDirection DirectionFromFlags(Flags aFlags); + + void ResolveImplicitLevels(PRInt32 aStart, PRInt32 aLimit, DirProp aSOR, DirProp aEOR); + + void AdjustWSLevels(); + + void SetTrailingWSStart(); + + PRBool GetRuns(); + + void GetSingleRun(nsBidiLevel aLevel); + + void ReorderLine(nsBidiLevel aMinLevel, nsBidiLevel aMaxLevel); + + PRBool PrepareReorder(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap, nsBidiLevel *aMinLevel, nsBidiLevel *aMaxLevel); + /** + * Give a Unichar, return an eBidiCategory + */ + eBidiCategory GetBidiCategory(PRUnichar aChar); + + /** + * Give a Unichar, and a eBidiCategory, + * return PR_TRUE if the Unichar is in that category, + * return PR_FALSE, otherwise + */ + PRBool IsBidiCategory(PRUnichar aChar, eBidiCategory aBidiCategory); + + /** + * Give a Unichar + * return PR_TRUE if the Unichar is a Bidi control character (LRE, RLE, PDF, LRO, RLO, LRM, RLM) + * return PR_FALSE, otherwise + */ + PRBool IsBidiControl(PRUnichar aChar); + + /** + * Give a Unichar, return a nsCharType (compatible with ICU) + */ + nsCharType GetCharType(PRUnichar aChar); + + /** + * Give a Unichar, return the symmetric equivalent + */ + PRUnichar SymmSwap(PRUnichar aChar); + + PRInt32 doWriteReverse(const PRUnichar *src, PRInt32 srcLength, + PRUnichar *dest, PRUint16 options); + }; -#endif /* nsIBidi_h__ */ - -#endif /* IBMBIDI */ - +#endif // _nsBidi_h_ diff --git a/mozilla/layout/base/nsBidiPresUtils.cpp b/mozilla/layout/base/nsBidiPresUtils.cpp index fff7325a3e6..71467878d8e 100644 --- a/mozilla/layout/base/nsBidiPresUtils.cpp +++ b/mozilla/layout/base/nsBidiPresUtils.cpp @@ -49,7 +49,7 @@ #include "nsIFrameManager.h" #include "nsBidiFrames.h" #include "nsITextFrame.h" -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" static const PRUnichar kSpace = 0x0020; static const PRUnichar kLineSeparator = 0x2028; @@ -64,6 +64,19 @@ static const PRUnichar kPDF = 0x202C; static const PRUnichar ALEF = 0x05D0; #endif +#define CHAR_IS_HEBREW(c) ((0x0590 <= (c)) && ((c)<= 0x05FF)) +// Note: The above code are moved from gfx/src/windows/nsRenderingContextWin.cpp + +#define ARABIC_TO_HINDI_DIGIT_INCREMENT (START_HINDI_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)) +#define NUM_TO_HINDI(c) \ + ((((c)>=START_ARABIC_DIGITS) && ((c)<=END_ARABIC_DIGITS)) ? \ + ((c) + (PRUint16)ARABIC_TO_HINDI_DIGIT_INCREMENT): \ + (c)) + extern nsresult NS_NewContinuingTextFrame(nsIPresShell* aPresShell, nsIFrame** aResult); extern nsresult @@ -73,10 +86,9 @@ nsBidiPresUtils::nsBidiPresUtils() : mArraySize(8), mIndexMap(nsnull), mLevels(nsnull), mSuccess(NS_ERROR_FAILURE), - mBidiEngine(nsnull), - mUnicodeUtils(nsnull) + mBidiEngine(nsnull) { - mBidiEngine = do_GetService("@mozilla.org/intl/bidi;1"); + mBidiEngine = new nsBidi(); if (mBidiEngine) { mSuccess = NS_OK; } @@ -861,12 +873,6 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, PRBool aIsBidiSystem) { nsresult rv = NS_OK; - if (!mUnicodeUtils) { - mUnicodeUtils = do_GetService("@mozilla.org/intl/unicharbidiutil;1"); - if (!mUnicodeUtils) { - return NS_ERROR_FAILURE; - } - } // ahmed //adjusted for correct numeral shaping PRUint32 bidiOptions; @@ -874,11 +880,11 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, switch (GET_BIDI_OPTION_NUMERAL(bidiOptions)) { case IBMBIDI_NUMERAL_HINDI: - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); break; case IBMBIDI_NUMERAL_ARABIC: - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); break; case IBMBIDI_NUMERAL_REGULAR: @@ -886,11 +892,11 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, switch (aCharType) { case eCharType_EuropeanNumber: - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); break; case eCharType_ArabicNumber: - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); break; default: @@ -900,9 +906,9 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, case IBMBIDI_NUMERAL_HINDICONTEXT: if ( ( (GET_BIDI_OPTION_DIRECTION(bidiOptions)==IBMBIDI_TEXTDIRECTION_RTL) && (IS_ARABIC_DIGIT (aText[0])) ) || (eCharType_ArabicNumber == aCharType) ) - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); else if (eCharType_EuropeanNumber == aCharType) - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); break; default: @@ -940,7 +946,7 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, } } if (doShape) { - rv = mUnicodeUtils->ArabicShaping(aText, aTextLength, buffer, (PRUint32 *)&newLen); + rv = ArabicShaping(aText, aTextLength, buffer, (PRUint32 *)&newLen); if (NS_SUCCEEDED(rv) ) { aTextLength = newLen; memcpy(aText, buffer, aTextLength * sizeof(PRUnichar) ); @@ -1044,12 +1050,11 @@ nsBidiPresUtils::CalculateCharType(PRInt32& aOffset, aOffset = offset; } -nsresult nsBidiPresUtils::GetBidiEngine(nsIBidi** aBidiEngine) +nsresult nsBidiPresUtils::GetBidiEngine(nsBidi** aBidiEngine) { nsresult rv = NS_ERROR_FAILURE; if (mBidiEngine) { *aBidiEngine = mBidiEngine; - NS_ADDREF(*aBidiEngine); rv = NS_OK; } return rv; @@ -1136,4 +1141,40 @@ nsresult nsBidiPresUtils::RenderText(PRUnichar* aText, return NS_OK; } +nsresult nsBidiPresUtils::HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag) +{ + PRUint32 i; + // IBMBIDI_NUMERAL_REGULAR * + // IBMBIDI_NUMERAL_HINDICONTEXT + // IBMBIDI_NUMERAL_ARABIC + // IBMBIDI_NUMERAL_HINDI + mNumflag=aNumFlag; + + switch (aNumFlag) { + case IBMBIDI_NUMERAL_HINDI: + for (i=0;i mBidiEngine; - nsCOMPtr mUnicodeUtils; + nsBidi* mBidiEngine; }; #endif /* nsBidiPresUtils_h___ */ diff --git a/mozilla/layout/base/nsBidiUtils.cpp b/mozilla/layout/base/nsBidiUtils.cpp new file mode 100644 index 00000000000..c8bc125a599 --- /dev/null +++ b/mozilla/layout/base/nsBidiUtils.cpp @@ -0,0 +1,462 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * IBM Corporation. Portions created by IBM are + * Copyright (C) 2000 IBM Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Maha Abou El Rous + * Lina Kemmel + * Simon Montagu + * Roozbeh Pournader + */ +#ifdef IBMBIDI +#include "nsBidiUtils.h" + +#define FE_TO_06_OFFSET 0xfe70 + +static PRUnichar FE_TO_06 [][2] = { + {0x064b,0x0000},{0x064b,0x0640},{0x064c,0x0000}, + {0x0000,0x0000},{0x064d,0x0000},{0x0000,0x0000}, + {0x064e,0x0000},{0x064e,0x0640},{0x064f,0x0000}, + {0x064f,0x0640},{0x0650,0x0000},{0x0650,0x0640}, + {0x0651,0x0000},{0x0651,0x0640},{0x0652,0x0000}, + {0x0652,0x0640},{0x0621,0x0000},{0x0622,0x0000}, + {0x0622,0x0000},{0x0623,0x0000},{0x0623,0x0000}, + {0x0624,0x0000},{0x0624,0x0000},{0x0625,0x0000}, + {0x0625,0x0000},{0x0626,0x0000},{0x0626,0x0000}, + {0x0626,0x0000},{0x0626,0x0000},{0x0627,0x0000}, + {0x0627,0x0000},{0x0628,0x0000},{0x0628,0x0000}, + {0x0628,0x0000},{0x0628,0x0000},{0x0629,0x0000}, + {0x0629,0x0000},{0x062a,0x0000},{0x062a,0x0000}, + {0x062a,0x0000},{0x062a,0x0000},{0x062b,0x0000}, + {0x062b,0x0000},{0x062b,0x0000},{0x062b,0x0000}, + {0x062c,0x0000},{0x062c,0x0000},{0x062c,0x0000}, + {0x062c,0x0000},{0x062d,0x0000},{0x062d,0x0000}, + {0x062d,0x0000},{0x062d,0x0000},{0x062e,0x0000}, + {0x062e,0x0000},{0x062e,0x0000},{0x062e,0x0000}, + {0x062f,0x0000},{0x062f,0x0000},{0x0630,0x0000}, + {0x0630,0x0000},{0x0631,0x0000},{0x0631,0x0000}, + {0x0632,0x0000},{0x0632,0x0000},{0x0633,0x0000}, + {0x0633,0x0000},{0x0633,0x0000},{0x0633,0x0000}, + {0x0634,0x0000},{0x0634,0x0000},{0x0634,0x0000}, + {0x0634,0x0000},{0x0635,0x0000},{0x0635,0x0000}, + {0x0635,0x0000},{0x0635,0x0000},{0x0636,0x0000}, + {0x0636,0x0000},{0x0636,0x0000},{0x0636,0x0000}, + {0x0637,0x0000},{0x0637,0x0000},{0x0637,0x0000}, + {0x0637,0x0000},{0x0638,0x0000},{0x0638,0x0000}, + {0x0638,0x0000},{0x0638,0x0000},{0x0639,0x0000}, + {0x0639,0x0000},{0x0639,0x0000},{0x0639,0x0000}, + {0x063a,0x0000},{0x063a,0x0000},{0x063a,0x0000}, + {0x063a,0x0000},{0x0641,0x0000},{0x0641,0x0000}, + {0x0641,0x0000},{0x0641,0x0000},{0x0642,0x0000}, + {0x0642,0x0000},{0x0642,0x0000},{0x0642,0x0000}, + {0x0643,0x0000},{0x0643,0x0000},{0x0643,0x0000}, + {0x0643,0x0000},{0x0644,0x0000},{0x0644,0x0000}, + {0x0644,0x0000},{0x0644,0x0000},{0x0645,0x0000}, + {0x0645,0x0000},{0x0645,0x0000},{0x0645,0x0000}, + {0x0646,0x0000},{0x0646,0x0000},{0x0646,0x0000}, + {0x0646,0x0000},{0x0647,0x0000},{0x0647,0x0000}, + {0x0647,0x0000},{0x0647,0x0000},{0x0648,0x0000}, + {0x0648,0x0000},{0x0649,0x0000},{0x0649,0x0000}, + {0x064a,0x0000},{0x064a,0x0000},{0x064a,0x0000}, + {0x064a,0x0000},{0x0644,0x0622},{0x0644,0x0622}, + {0x0644,0x0623},{0x0644,0x0623},{0x0644,0x0625}, + {0x0644,0x0625},{0x0644,0x0627},{0x0644,0x0627} +}; + +static PRUnichar FB_TO_06 [] = { + 0x0671,0x0671,0x067B,0x067B,0x067B,0x067B,0x067E,0x067E, //FB50-FB57 + 0x067E,0x067E,0x0680,0x0680,0x0680,0x0680,0x067A,0x067A, //FB58-FB5F + 0x067A,0x067A,0x067F,0x067F,0x067F,0x067F,0x0679,0x0679, //FB60-FB67 + 0x0679,0x0679,0x06A4,0x06A4,0x06A4,0x06A4,0x06A6,0x06A6, //FB68-FB6F + 0x06A6,0x06A6,0x0684,0x0684,0x0684,0x0684,0x0683,0x0683, //FB70-FB77 + 0x0683,0x0683,0x0686,0x0686,0x0686,0x0686,0x0687,0x0687, //FB78-FB7F + 0x0687,0x0687,0x068D,0x068D,0x068C,0x068C,0x068E,0x068E, //FB80-FB87 + 0x0688,0x0688,0x0698,0x0698,0x0691,0x0691,0x06A9,0x06A9, //FB88-FB8F + 0x06A9,0x06A9,0x06AF,0x06AF,0x06AF,0x06AF,0x06B3,0x06B3, //FB90-FB97 + 0x06B3,0x06B3,0x06B1,0x06B1,0x06B1,0x06B1,0x06BA,0x06BA, //FB98-FB9F + 0x06BB,0x06BB,0x06BB,0x06BB,0x06C0,0x06C0,0x06C1,0x06C1, //FBA0-FBA7 + 0x06C1,0x06C1,0x06BE,0x06BE,0x06BE,0x06BE,0x06D2,0x06D2, //FBA8-FBAF + 0x06D3,0x06D3,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBB0-FBB7 + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBB8-FBBF + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBC0-FBC7 + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBC8-FBCF + 0x0000,0x0000,0x0000,0x06AD,0x06AD,0x06AD,0x06AD,0x06C7, //FBD0-FBD7 + 0x06C7,0x06C6,0x06C6,0x06C8,0x06C8,0x0677,0x06CB,0x06CB, //FBD8-FBDF + 0x06C5,0x06C5,0x06C9,0x06C9,0x06D0,0x06D0,0x06D0,0x06D0, //FBE0-FBE7 + 0x0649,0x0649,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBE8-FBEF + 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBF0-FBF7 + 0x0000,0x0000,0x0000,0x0000,0x06CC,0x06CC,0x06CC,0x06CC //FBF8-FBFF +}; + +#define PresentationToOriginal(c, order) \ + (((0xFE70 <= (c) && (c) <= 0xFEFC)) ? \ + FE_TO_06[(c)- FE_TO_06_OFFSET][order] : \ + (((0xFB50 <= (c) && (c) <= 0xFBFF) && (order) == 0) ? \ + FB_TO_06[(c)-0xFB50] : (PRUnichar) 0x0000)) + +//============ Begin Arabic Basic to Presentation Form B Code ============ +// Note: the following code are moved from gfx/src/windows/nsRenderingContextWin.cpp +static PRUint8 gArabicMap1[] = { + 0x81, 0x83, 0x85, 0x87, 0x89, 0x8D, // 0622-0627 +0x8F, 0x93, 0x95, 0x99, 0x9D, 0xA1, 0xA5, 0xA9, // 0628-062F +0xAB, 0xAD, 0xAF, 0xB1, 0xB5, 0xB9, 0xBD, 0xC1, // 0630-0637 +0xC5, 0xC9, 0xCD // 0638-063A +}; + +static PRUint8 gArabicMap2[] = { + 0xD1, 0xD5, 0xD9, 0xDD, 0xE1, 0xE5, 0xE9, // 0641-0647 +0xED, 0xEF, 0xF1 // 0648-064A +}; + +static PRUint8 gArabicMapEx[] = { + 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0671-0677 +0x00, 0x66, 0x5E, 0x52, 0x00, 0x00, 0x56, 0x62, // 0678-067F +0x5A, 0x00, 0x00, 0x76, 0x72, 0x00, 0x7A, 0x7E, // 0680-0687 +0x88, 0x00, 0x00, 0x00, 0x84, 0x82, 0x86, 0x00, // 0688-068F +0x00, 0x8C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0690-0697 +0x8A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0698-069F +0x00, 0x00, 0x00, 0x00, 0x6A, 0x00, 0x6E, 0x00, // 06A0-06A7 +0x00, 0x8E, 0x00, 0x00, 0x00, 0xD3, 0x00, 0x92, // 06A8-06AF +0x00, 0x9A, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, // 06B0-06B7 +0x00, 0x00, 0x00, 0xA0, 0x00, 0x00, 0xAA, 0x00, // 06B8-06BF +0xA4, 0xA6, 0x00, 0x00, 0x00, 0xE0, 0xD9, 0xD7, // 06C0-06C7 +0xDB, 0xE2, 0x00, 0xDE, 0xFC, 0x00, 0x00, 0x00, // 06C8-06CF +0xE4, 0x00, 0xAE, 0xB0 // 06D0-06D3 +}; + +#define PresentationFormB(c, form) \ + (((0x0622<=(c)) && ((c)<=0x063A)) ? \ + (0xFE00|(gArabicMap1[(c)-0x0622] + (form))) : \ + (((0x0641<=(c)) && ((c)<=0x064A)) ? \ + (0xFE00|(gArabicMap2[(c)-0x0641] + (form))) : \ + (((0x0671<=(c)) && ((c))<=0x06D3) && gArabicMapEx[(c)-0x0671]) ? \ + (0xFB00|(gArabicMapEx[(c)-0x0671] + (form))) : (c))) +enum { + eIsolated, // or Char N + eFinal, // or Char R + eInitial, // or Char L + eMedial // or Char M +} eArabicForm; +enum { + eTr = 0, // Transparent + eRJ = 1, // Right-Joining + eLJ = 2, // Left-Joining + eDJ = 3, // Dual-Joining + eNJ = 4, // Non-Joining + eJC = 7, // Joining Causing + eRightJCMask = 2, // bit of Right-Join Causing + eLeftJCMask = 1 // bit of Left-Join Causing +} eArabicJoiningClass; + +#define RightJCClass(j) (eRightJCMask&(j)) +#define LeftJCClass(j) (eLeftJCMask&(j)) + +#define DecideForm(jl,j,jr) \ + (((eRJ == (j)) && RightJCClass(jr)) ? eFinal \ + : \ + ((eDJ == (j)) ? \ + ((RightJCClass(jr)) ? \ + (((LeftJCClass(jl)) ? eMedial \ + : eFinal)) \ + : \ + (((LeftJCClass(jl)) ? eInitial \ + : eIsolated)) \ + ) : eIsolated)) \ + +// All letters without an equivalen in the FB50 block are 'eNJ' here. This +// should be fixed after finding some better mechanism for handling Arabic. +static PRInt8 gJoiningClass[] = { + eNJ, eRJ, eRJ, eRJ, eRJ, eDJ, eRJ, // 0621-0627 +eDJ, eRJ, eDJ, eDJ, eDJ, eDJ, eDJ, eRJ, // 0628-062F +eRJ, eRJ, eRJ, eDJ, eDJ, eDJ, eDJ, eDJ, // 0630-0637 +eDJ, eDJ, eDJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0638-063F +eJC, eDJ, eDJ, eDJ, eDJ, eDJ, eDJ, eDJ, // 0640-0647 +eRJ, eRJ, eDJ, eTr, eTr, eTr, eTr, eTr, // 0648-064F +eTr, eTr, eTr, eTr, eTr, eTr, eNJ, eNJ, // 0650-0657 +eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0658-065F +eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0660-0667 +eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0668-066F +eTr, eRJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0670-0677 +eNJ, eDJ, eDJ, eDJ, eNJ, eNJ, eDJ, eDJ, // 0678-067F +eDJ, eNJ, eNJ, eDJ, eDJ, eNJ, eDJ, eDJ, // 0680-0687 +eRJ, eNJ, eNJ, eNJ, eRJ, eRJ, eRJ, eNJ, // 0688-068F +eNJ, eRJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0690-0697 +eRJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0698-069F +eNJ, eNJ, eNJ, eNJ, eDJ, eNJ, eDJ, eNJ, // 06A0-06A7 +eNJ, eDJ, eNJ, eNJ, eNJ, eDJ, eNJ, eDJ, // 06A8-06AF +eNJ, eDJ, eNJ, eDJ, eNJ, eNJ, eNJ, eNJ, // 06B0-06B7 +eNJ, eNJ, eNJ, eDJ, eNJ, eNJ, eDJ, eNJ, // 06B8-06BF +eRJ, eDJ, eNJ, eNJ, eNJ, eRJ, eRJ, eRJ, // 06C0-06C7 +eRJ, eRJ, eNJ, eRJ, eDJ, eNJ, eNJ, eNJ, // 06C8-06CF +eDJ, eNJ, eRJ, eRJ, eNJ, eNJ, eTr, eTr, // 06D0-06D7 +eTr, eTr, eTr, eTr, eTr, eTr, eTr, eTr, // 06D8-06DF +eTr, eTr, eTr, eTr, eTr, eNJ, eNJ, eTr, // 06E0-06E7 +eTr, eNJ, eTr, eTr, eTr, eTr, eNJ, eNJ, // 06E8-06EF +eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 06F0-06F7 +eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ // 06F8-06FF +}; + +#define GetJoiningClass(c) \ + (((0x0621 <= (c)) && ((c) <= 0x06FF)) ? \ + (gJoiningClass[(c) - 0x0621]) : \ + ((0x200D == (c)) ? eJC : eTr)) + +static PRUint16 gArabicLigatureMap[] = +{ +0x82DF, // 0xFE82 0xFEDF -> 0xFEF5 +0x82E0, // 0xFE82 0xFEE0 -> 0xFEF6 +0x84DF, // 0xFE84 0xFEDF -> 0xFEF7 +0x84E0, // 0xFE84 0xFEE0 -> 0xFEF8 +0x88DF, // 0xFE88 0xFEDF -> 0xFEF9 +0x88E0, // 0xFE88 0xFEE0 -> 0xFEFA +0x8EDF, // 0xFE8E 0xFEDF -> 0xFEFB +0x8EE0 // 0xFE8E 0xFEE0 -> 0xFEFC +}; + +nsresult ArabicShaping(const PRUnichar* aString, PRUint32 aLen, + PRUnichar* aBuf, PRUint32 *aBufLen) +{ + const PRUnichar* src = aString; + const PRUnichar* p; + PRUnichar* dest = aBuf; + PRUnichar formB; + PRInt8 leftJ, thisJ, rightJ; + PRInt8 leftNoTrJ, rightNoTrJ; + thisJ = eNJ; + rightJ = GetJoiningClass(*(src)); + while(src= aString ) && !IS_ARABIC_CHAR(*(src-1))))) + leftNoTrJ = thisJ; + + if(src-2 >= (aString)){ + for(p=src-2; (p >= (aString))&& (eTr == leftNoTrJ) && (IS_ARABIC_CHAR(*(p+1))) ; p--) + leftNoTrJ = GetJoiningClass(*(p)) ; + } + + thisJ = rightJ; + rightJ = rightNoTrJ = GetJoiningClass(*(src+1)) ; + + if(src+2 <= (aString+aLen-1)){ + for(p=src+2; (p <= (aString+aLen-1))&&(eTr == rightNoTrJ) && (IS_ARABIC_CHAR(*(src+1))); p++) + rightNoTrJ = GetJoiningClass(*(p)) ; + } + + formB = PresentationFormB(*src, DecideForm(leftNoTrJ, thisJ, rightNoTrJ)); + *dest++ = formB; + src++; + + } + if((eTr != thisJ) || + ((thisJ == eTr) && (((src-1)>=aString) && (!IS_ARABIC_CHAR(*(src-1)))))) + leftNoTrJ = thisJ; + + if(src-2 >= (aString)){ + for(p=src-2; (src-2 >= (aString)) && (eTr == leftNoTrJ) && (IS_ARABIC_CHAR(*(p+1))); p--) + leftNoTrJ = GetJoiningClass(*(p)) ; + } + + formB = PresentationFormB(*src, DecideForm(leftNoTrJ, rightJ, eNJ)); + *dest++ = formB; + src++; + + PRUnichar *lSrc = aBuf; + PRUnichar *lDest = aBuf; + while(lSrc < (dest-1)) { + PRUnichar next = *(lSrc+1); + if(((0xFEDF == next) || (0xFEE0 == next)) && + (0xFE80 == (0xFFF1 & *lSrc))) { + PRBool done = PR_FALSE; + PRUint16 key = ((*lSrc) << 8) | ( 0x00FF & next); + PRUint16 i; + for(i=0;i<8;i++) { + if(key == gArabicLigatureMap[i]) { + done = PR_TRUE; + *lDest++ = 0x200B;//ZERO WIDTH SPACE + *lDest++ = 0xFEF5 + i; + lSrc+=2; + break; + } + } + if(! done) + *lDest++ = *lSrc++; + } + else + *lDest++ = *lSrc++; + + } + if(lSrc < dest) + *lDest++ = *lSrc++; + + *aBufLen = lDest - aBuf; + + return NS_OK; +} + +nsresult Conv_FE_06(const nsString& aSrc, nsString& aDst) +{ + PRUnichar *aSrcUnichars = (PRUnichar *)aSrc.get(); + PRUint32 i, size = aSrc.Length(); + aDst.Truncate(); + for (i=0;i=beginArabic; i--) { + if(IS_FE_CHAR(aSrcUnichars[i])) { + //ahmed for the bug of lamalf + aDst += PresentationToOriginal(aSrcUnichars[i], 0); + if (PresentationToOriginal(aSrcUnichars[i], 1)) { + // Two characters, we have to resize the buffer :( + aDst += PresentationToOriginal(aSrcUnichars[i], 1); + } // if expands to 2 char + } else { + // do we need to check the following if ? + if((IS_ARABIC_CHAR(aSrcUnichars[i]))|| + (IS_ARABIC_DIGIT(aSrcUnichars[i]))|| + (aSrcUnichars[i]==0x0020)) + aDst += aSrcUnichars[i]; + } + } + } else { + aDst += aSrcUnichars[endArabic]; + } + foundArabic=PR_FALSE; + }// for : loop the buffer + return NS_OK; +} + +nsresult Conv_06_FE_WithReverse(const nsString& aSrc, + nsString& aDst, + PRUint32 aDir) +{ + PRUnichar *aSrcUnichars = (PRUnichar *)aSrc.get(); + PRUint32 i,beginArabic, endArabic, size = aSrc.Length(); + aDst.Truncate(); + PRBool foundArabic = PR_FALSE; + for (endArabic=0;endArabic + * Lina Kemmel + * Simon Montagu + * + */ + +#ifndef nsBidiUtils_h__ +#define nsBidiUtils_h__ + +#include "nsCOMPtr.h" +#include "nsString.h" + + /** + * Perform Arabic shaping on a Unichar string + * @param aString is the input string + * @param aLen is the length of aStrong + * @param aBuf receives the shaped output + * @param aBuflen receives the length of aBuf + */ + nsresult ArabicShaping(const PRUnichar* aString, PRUint32 aLen, + PRUnichar* aBuf, PRUint32* aBufLen); + + /** + * Scan an nsString, converting characters in the FExx range (Arabic presentation forms) to the equivalent characters in the 06xx + * range + * @param aSrc is the input string + * @param aDst is the output string + */ + nsresult Conv_FE_06(const nsString& aSrc, nsString& aDst); + + /** + * Scan an nsString, converting characters in the FExx range (Arabic presentation forms) to the equivalent characters in the 06xx + * range, and also reverse the string + * @param aSrc is the input string + * @param aDst is the output string + */ + nsresult Conv_FE_06_WithReverse(const nsString& aSrc, nsString& aDst); + + /** + * Scan an nsString, converting characters in the 06xx range to the equivalent characters in the 0Fxx range (Arabic presentation + * forms), with the option to reverse the string + * @param aSrc is the input string + * @param aDst is the output string + * @param aDir indicates whether the string should be reversed + * IBMBIDI_TEXTDIRECTION_LTR: do not reverse the string + * IBMBIDI_TEXTDIRECTION_RTL: reverse the string + */ + nsresult Conv_06_FE_WithReverse(const nsString& aSrc, nsString& aDst, PRUint32 aDir); + +// -------------------------------------------------- +// IBMBIDI +// -------------------------------------------------- +// +// These values are shared with Preferences dialog +// ------------------ +// If Pref values are to be changed +// in the XUL file of Prefs. the values +// Must be changed here too.. +// ------------------ +// +#define IBMBIDI_TEXTDIRECTION_STR "bidi.direction" +#define IBMBIDI_TEXTTYPE_STR "bidi.texttype" +#define IBMBIDI_CONTROLSTEXTMODE_STR "bidi.controlstextmode" +#define IBMBIDI_CLIPBOARDTEXTMODE_STR "bidi.clipboardtextmode" +#define IBMBIDI_NUMERAL_STR "bidi.numeral" +#define IBMBIDI_SUPPORTMODE_STR "bidi.support" +#define IBMBIDI_CHARSET_STR "bidi.characterset" + +#define IBMBIDI_TEXTDIRECTION 1 +#define IBMBIDI_TEXTTYPE 2 +#define IBMBIDI_CONTROLSTEXTMODE 3 +#define IBMBIDI_CLIPBOARDTEXTMODE 4 +#define IBMBIDI_NUMERAL 5 +#define IBMBIDI_SUPPORTMODE 6 +#define IBMBIDI_CHARSET 7 + +// ------------------ +// Text Direction +// ------------------ +// bidi.direction +#define IBMBIDI_TEXTDIRECTION_LTR 1 // 1 = directionLTRBidi * +#define IBMBIDI_TEXTDIRECTION_RTL 2 // 2 = directionRTLBidi +// ------------------ +// Text Type +// ------------------ +// bidi.texttype +#define IBMBIDI_TEXTTYPE_CHARSET 1 // 1 = charsettexttypeBidi * +#define IBMBIDI_TEXTTYPE_LOGICAL 2 // 2 = logicaltexttypeBidi +#define IBMBIDI_TEXTTYPE_VISUAL 3 // 3 = visualtexttypeBidi +// ------------------ +// Controls Text Mode +// ------------------ +// bidi.controlstextmode +#define IBMBIDI_CONTROLSTEXTMODE_LOGICAL 1 // 1 = logicalcontrolstextmodeBidiCmd * +#define IBMBIDI_CONTROLSTEXTMODE_VISUAL 2 // 2 = visualcontrolstextmodeBidi +#define IBMBIDI_CONTROLSTEXTMODE_CONTAINER 3 // 3 = containercontrolstextmodeBidi +// ------------------ +// Clipboard Text Mode +// ------------------ +// bidi.clipboardtextmode +#define IBMBIDI_CLIPBOARDTEXTMODE_LOGICAL 1 // 1 = logicalclipboardtextmodeBidi +#define IBMBIDI_CLIPBOARDTEXTMODE_VISUAL 2 // 2 = visualclipboardtextmodeBidi +#define IBMBIDI_CLIPBOARDTEXTMODE_SOURCE 3 // 3 = sourceclipboardtextmodeBidi * +// ------------------ +// Numeral Style +// ------------------ +// bidi.numeral +#define IBMBIDI_NUMERAL_REGULAR 1 // 1 = regularcontextnumeralBidi * +#define IBMBIDI_NUMERAL_HINDICONTEXT 2 // 2 = hindicontextnumeralBidi +#define IBMBIDI_NUMERAL_ARABIC 3 // 3 = arabicnumeralBidi +#define IBMBIDI_NUMERAL_HINDI 4 // 4 = hindinumeralBidi +// ------------------ +// Support Mode +// ------------------ +// bidi.support +#define IBMBIDI_SUPPORTMODE_MOZILLA 1 // 1 = mozillaBidisupport * +#define IBMBIDI_SUPPORTMODE_OSBIDI 2 // 2 = OsBidisupport +#define IBMBIDI_SUPPORTMODE_DISABLE 3 // 3 = disableBidisupport +// ------------------ +// Charset Mode +// ------------------ +// bidi.characterset +#define IBMBIDI_CHARSET_BIDI 1 // 1 = doccharactersetBidi * +#define IBMBIDI_CHARSET_DEFAULT 2 // 2 = defaultcharactersetBidi + +#define IBMBIDI_DEFAULT_BIDI_OPTIONS \ + ((IBMBIDI_TEXTDIRECTION_LTR<<0) | \ + (IBMBIDI_TEXTTYPE_CHARSET<<4) | \ + (IBMBIDI_CONTROLSTEXTMODE_LOGICAL<<8) | \ + (IBMBIDI_CLIPBOARDTEXTMODE_SOURCE<<12) | \ + (IBMBIDI_NUMERAL_REGULAR<<16) | \ + (IBMBIDI_SUPPORTMODE_MOZILLA<<20) | \ + (IBMBIDI_CHARSET_BIDI<<24)) + + +#define GET_BIDI_OPTION_DIRECTION(bo) (((bo)>>0) & 0x0000000F) /* 4 bits for DIRECTION */ +#define GET_BIDI_OPTION_TEXTTYPE(bo) (((bo)>>4) & 0x0000000F) /* 4 bits for TEXTTYPE */ +#define GET_BIDI_OPTION_CONTROLSTEXTMODE(bo) (((bo)>>8) & 0x0000000F) /* 4 bits for CONTROLTEXTMODE */ +#define GET_BIDI_OPTION_CLIPBOARDTEXTMODE(bo) (((bo)>>12) & 0x0000000F) /* 4 bits for CLIPBOARDTEXTMODE */ +#define GET_BIDI_OPTION_NUMERAL(bo) (((bo)>>16) & 0x0000000F) /* 4 bits for NUMERAL */ +#define GET_BIDI_OPTION_SUPPORT(bo) (((bo)>>20) & 0x0000000F) /* 4 bits for SUPPORT */ +#define GET_BIDI_OPTION_CHARACTERSET(bo) (((bo)>>24) & 0x0000000F) /* 4 bits for CHARACTERSET */ + +#define SET_BIDI_OPTION_DIRECTION(bo, dir) {(bo)=((bo) & 0xFFFFFFF0)|(((dir)& 0x0000000F)<<0);} +#define SET_BIDI_OPTION_TEXTTYPE(bo, tt) {(bo)=((bo) & 0xFFFFFF0F)|(((tt)& 0x0000000F)<<4);} +#define SET_BIDI_OPTION_CONTROLSTEXTMODE(bo, cotm) {(bo)=((bo) & 0xFFFFF0FF)|(((cotm)& 0x0000000F)<<8);} +#define SET_BIDI_OPTION_CLIPBOARDTEXTMODE(bo, cltm) {(bo)=((bo) & 0xFFFF0FFF)|(((cltm)& 0x0000000F)<<12);} +#define SET_BIDI_OPTION_NUMERAL(bo, num) {(bo)=((bo) & 0xFFF0FFFF)|(((num)& 0x0000000F)<<16);} +#define SET_BIDI_OPTION_SUPPORT(bo, sup) {(bo)=((bo) & 0xFF0FFFFF)|(((sup)& 0x0000000F)<<20);} +#define SET_BIDI_OPTION_CHARACTERSET(bo, cs) {(bo)=((bo) & 0xF0FFFFFF)|(((cs)& 0x0000000F)<<24);} + +/* Constants related to the position of numerics in the codepage */ +#define START_HINDI_DIGITS 0x0660 +#define END_HINDI_DIGITS 0x0669 +#define START_ARABIC_DIGITS 0x0030 +#define END_ARABIC_DIGITS 0x0039 +#define START_FARSI_DIGITS 0x06f0 +#define END_FARSI_DIGITS 0x06f9 +#define IS_HINDI_DIGIT(u) ( ( (u) >= START_HINDI_DIGITS ) && ( (u) <= END_HINDI_DIGITS ) ) +#define IS_ARABIC_DIGIT(u) ( ( (u) >= START_ARABIC_DIGITS ) && ( (u) <= END_ARABIC_DIGITS ) ) +#define IS_FARSI_DIGIT(u) ( ( (u) >= START_FARSI_DIGITS ) && ( (u) <= END_FARSI_DIGITS ) ) + +#define IS_BIDI_DIACRITIC(u) ( \ + ( (u) >= 0x0591 && (u) <= 0x05A1) || ( (u) >= 0x05A3 && (u) <= 0x05B9) \ + || ( (u) >= 0x05BB && (u) <= 0x05BD) || ( (u) == 0x05BF) || ( (u) == 0x05C1) \ + || ( (u) == 0x05C2) || ( (u) == 0x05C4) \ + || ( (u) >= 0x064B && (u) <= 0x0652) || ( (u) == 0x0670) \ + || ( (u) >= 0x06D7 && (u) <= 0x06E4) || ( (u) == 0x06E7) || ( (u) == 0x06E8) \ + || ( (u) >= 0x06EA && (u) <= 0x06ED) ) + +#define IS_HEBREW_CHAR(c) (((0x0590 <= (c)) && ((c)<= 0x05FF)) || (((c) >= 0xfb1d) && ((c) <= 0xfb4f))) +#define IS_06_CHAR(c) ((0x0600 <= (c)) && ((c)<= 0x06FF)) +#define IS_FE_CHAR(c) (((0xfb50 <= (c)) && ((c)<= 0xfbFF)) \ + || ((0xfe70 <= (c)) && ((c)<= 0xfeFC))) +#define IS_ARABIC_CHAR(c) ((0x0600 <= (c)) && ((c)<= 0x06FF)) +#define IS_ARABIC_ALPHABETIC(c) (IS_ARABIC_CHAR(c) && !(IS_HINDI_DIGIT(c) || IS_FARSI_DIGIT(c))) + +#define CHAR_IS_BIDI(c) ( (IS_HINDI_DIGIT(c) ) || (IS_HEBREW_CHAR(c) ) \ + || (IS_06_CHAR(c) ) || (IS_FE_CHAR(c) ) ) +#endif /* nsBidiUtils_h__ */ diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 55beacb0464..7d416f1af29 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -172,7 +172,7 @@ static NS_DEFINE_IID(kPrinterEnumeratorCID, NS_PRINTER_ENUMERATOR_CID); #include "nsITransformMediator.h" #ifdef IBMBIDI -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" #endif static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); diff --git a/mozilla/layout/base/public/MANIFEST b/mozilla/layout/base/public/MANIFEST index 9af757b9ddb..13d50934d9b 100644 --- a/mozilla/layout/base/public/MANIFEST +++ b/mozilla/layout/base/public/MANIFEST @@ -1,6 +1,8 @@ # # This is a list of local files which get copied to the mozilla:dist:layout directory # +nsBidi.h +nsBidiPresUtils.h nsFrameList.h nsFrameTraversal.h nsHTMLReflowMetrics.h diff --git a/mozilla/layout/base/public/Makefile.in b/mozilla/layout/base/public/Makefile.in index 823d5815f91..f5c6f741faa 100644 --- a/mozilla/layout/base/public/Makefile.in +++ b/mozilla/layout/base/public/Makefile.in @@ -72,6 +72,7 @@ $(NULL) ifdef IBMBIDI EXPORTS += \ nsBidiPresUtils.h \ + nsBidi.h \ nsITextFrame.h \ $(NULL) endif diff --git a/mozilla/layout/base/public/makefile.win b/mozilla/layout/base/public/makefile.win index bae73789e72..9c52c48d0d2 100644 --- a/mozilla/layout/base/public/makefile.win +++ b/mozilla/layout/base/public/makefile.win @@ -65,6 +65,7 @@ EXPORTS = \ !ifdef IBMBIDI nsBidiPresUtils.h \ nsITextFrame.h \ + nsBidi.h \ !endif $(NULL) diff --git a/mozilla/layout/base/public/nsBidi.h b/mozilla/layout/base/public/nsBidi.h new file mode 100644 index 00000000000..8224d7d2591 --- /dev/null +++ b/mozilla/layout/base/public/nsBidi.h @@ -0,0 +1,1047 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * IBM Corporation. Portions created by IBM are + * Copyright (C) 2000 IBM Corporation. All + * Rights Reserved. + * + * This module is based on the ICU (International Components for Unicode) + * + * Copyright (C) 2000, International Business Machines + * Corporation and others. All Rights Reserved. + * + * Contributor(s): Simon Montagu + */ + +#ifndef nsBidi_h__ +#define nsBidi_h__ + +#include "nsCOMPtr.h" +#include "nsString.h" + +// Bidi reordering engine from ICU +/* + * javadoc-style comments are intended to be transformed into HTML + * using DOC++ - see + * http://www.zib.de/Visual/software/doc++/index.html . + * + * The HTML documentation is created with + * doc++ -H nsIBidi.h + */ + +/** + * @mainpage BIDI algorithm for Mozilla (from ICU) + * + *

BIDI algorithm for Mozilla

+ * + * This is an implementation of the Unicode Bidirectional algorithm. + * The algorithm is defined in the + * Unicode Technical Report 9, + * version 5, also described in The Unicode Standard, Version 3.0 .

+ * + *

General remarks about the API:

+ * + * The limit of a sequence of characters is the position just after their + * last character, i.e., one more than that position.

+ * + * Some of the API functions provide access to runs. + * Such a run is defined as a sequence of characters + * that are at the same embedding level + * after performing the BIDI algorithm.

+ * + * @author Markus W. Scherer. Ported to Mozilla by Simon Montagu + * @version 1.0 + */ + +/** + * nsBidiLevel is the type of the level values in this + * Bidi implementation. + * It holds an embedding level and indicates the visual direction + * by its bit 0 (even/odd value).

+ * + * It can also hold non-level values for the + * aParaLevel and aEmbeddingLevels + * arguments of SetPara; there: + *

    + *
  • bit 7 of an aEmbeddingLevels[] + * value indicates whether the using application is + * specifying the level of a character to override whatever the + * Bidi implementation would resolve it to.
  • + *
  • aParaLevel can be set to the + * pseudo-level values NSBIDI_DEFAULT_LTR + * and NSBIDI_DEFAULT_RTL.
+ * + * @see nsIBidi::SetPara + * + *

The related constants are not real, valid level values. + * NSBIDI_DEFAULT_XXX can be used to specify + * a default for the paragraph level for + * when the SetPara function + * shall determine it but there is no + * strongly typed character in the input.

+ * + * Note that the value for NSBIDI_DEFAULT_LTR is even + * and the one for NSBIDI_DEFAULT_RTL is odd, + * just like with normal LTR and RTL level values - + * these special values are designed that way. Also, the implementation + * assumes that NSBIDI_MAX_EXPLICIT_LEVEL is odd. + * + * @see NSBIDI_DEFAULT_LTR + * @see NSBIDI_DEFAULT_RTL + * @see NSBIDI_LEVEL_OVERRIDE + * @see NSBIDI_MAX_EXPLICIT_LEVEL + */ +typedef PRUint8 nsBidiLevel; + +/** Paragraph level setting. + * If there is no strong character, then set the paragraph level to 0 (left-to-right). + */ +#define NSBIDI_DEFAULT_LTR 0xfe + +/** Paragraph level setting. + * If there is no strong character, then set the paragraph level to 1 (right-to-left). + */ +#define NSBIDI_DEFAULT_RTL 0xff + +/** + * Maximum explicit embedding level. + * (The maximum resolved level can be up to NSBIDI_MAX_EXPLICIT_LEVEL+1). + * + */ +#define NSBIDI_MAX_EXPLICIT_LEVEL 61 + +/** Bit flag for level input. + * Overrides directional properties. + */ +#define NSBIDI_LEVEL_OVERRIDE 0x80 + +/** + * nsBidiDirection values indicate the text direction. + */ +enum nsBidiDirection { + /** All left-to-right text This is a 0 value. */ + NSBIDI_LTR, + /** All right-to-left text This is a 1 value. */ + NSBIDI_RTL, + /** Mixed-directional text. */ + NSBIDI_MIXED +}; + +typedef enum nsBidiDirection nsBidiDirection; + +/* miscellaneous definitions ------------------------------------------------ */ + + /** + * Read ftp://ftp.unicode.org/Public/UNIDATA/ReadMe-Latest.txt + * section BIDIRECTIONAL PROPERTIES + * for the detailed definition of the following categories + * + * The values here must match the equivalents in %map in + * mozilla/intl/unicharutil/tools/genbidicattable.pl + */ + +typedef enum { + eBidiCat_Undefined, + eBidiCat_L, /* Left-to-Right */ + eBidiCat_R, /* Right-to-Left */ + eBidiCat_AL, /* Right-to-Left Arabic */ + eBidiCat_AN, /* Arabic Number */ + eBidiCat_EN, /* European Number */ + eBidiCat_ES, /* European Number Separator */ + eBidiCat_ET, /* European Number Terminator */ + eBidiCat_CS, /* Common Number Separator */ + eBidiCat_ON, /* Other Neutrals */ + eBidiCat_NSM, /* Non-Spacing Mark */ + eBidiCat_BN, /* Boundary Neutral */ + eBidiCat_B, /* Paragraph Separator */ + eBidiCat_S, /* Segment Separator */ + eBidiCat_WS, /* Whitespace */ + eBidiCat_CC = 0xf, /* Control Code */ + /* (internal use only - will never be outputed) */ + eBidiCat_LRE = 0x2a, /* Left-to-Right Embedding */ + eBidiCat_RLE = 0x2b, /* Right-to-Left Embedding */ + eBidiCat_PDF = 0x2c, /* Pop Directional Formatting */ + eBidiCat_LRO = 0x2d, /* Left-to-Right Override */ + eBidiCat_RLO = 0x2e /* Right-to-Left Override */ +} eBidiCategory; + +enum nsCharType { + eCharType_LeftToRight = 0, + eCharType_RightToLeft = 1, + eCharType_EuropeanNumber = 2, + eCharType_EuropeanNumberSeparator = 3, + eCharType_EuropeanNumberTerminator = 4, + eCharType_ArabicNumber = 5, + eCharType_CommonNumberSeparator = 6, + eCharType_BlockSeparator = 7, + eCharType_SegmentSeparator = 8, + eCharType_WhiteSpaceNeutral = 9, + eCharType_OtherNeutral = 10, + eCharType_LeftToRightEmbedding = 11, + eCharType_LeftToRightOverride = 12, + eCharType_RightToLeftArabic = 13, + eCharType_RightToLeftEmbedding = 14, + eCharType_RightToLeftOverride = 15, + eCharType_PopDirectionalFormat = 16, + eCharType_DirNonSpacingMark = 17, + eCharType_BoundaryNeutral = 18, + eCharType_CharTypeCount +}; + +/** + * This specifies the language directional property of a character set. + */ +typedef enum nsCharType nsCharType; + +/** + * definitions of bidirection character types by category + */ + +#define CHARTYPE_IS_RTL(val) ( ( (val) == eCharType_RightToLeft) || ( (val) == eCharType_RightToLeftArabic) ) + +#define CHARTYPE_IS_WEAK(val) ( ( (val) == eCharType_EuropeanNumberSeparator) \ + || ( (val) == eCharType_EuropeanNumberTerminator) \ + || ( ( (val) > eCharType_ArabicNumber) && ( (val) != eCharType_RightToLeftArabic) ) ) + +/** option flags for WriteReverse() */ +/** + * option bit for WriteReverse(): + * keep combining characters after their base characters in RTL runs + * + * @see WriteReverse + */ +#define NSBIDI_KEEP_BASE_COMBINING 1 + +/** + * option bit for WriteReverse(): + * replace characters with the "mirrored" property in RTL runs + * by their mirror-image mappings + * + * @see WriteReverse + */ +#define NSBIDI_DO_MIRRORING 2 + +/** + * option bit for WriteReverse(): + * remove Bidi control characters + * + * @see WriteReverse + */ +#define NSBIDI_REMOVE_BIDI_CONTROLS 8 + +/* helper macros for each allocated array member */ +#define GETDIRPROPSMEMORY(length) \ + GetMemory((void **)&mDirPropsMemory, &mDirPropsSize, \ + mMayAllocateText, (length)) + +#define GETLEVELSMEMORY(length) \ + GetMemory((void **)&mLevelsMemory, &mLevelsSize, \ + mMayAllocateText, (length)) + +#define GETRUNSMEMORY(length) \ + GetMemory((void **)&mRunsMemory, &mRunsSize, \ + mMayAllocateRuns, (length)*sizeof(Run)) + +/* additional macros used by constructor - always allow allocation */ +#define GETINITIALDIRPROPSMEMORY(length) \ + GetMemory((void **)&mDirPropsMemory, &mDirPropsSize, \ + PR_TRUE, (length)) + +#define GETINITIALLEVELSMEMORY(length) \ + GetMemory((void **)&mLevelsMemory, &mLevelsSize, \ + PR_TRUE, (length)) + +#define GETINITIALRUNSMEMORY(length) \ + GetMemory((void **)&mRunsMemory, &mRunsSize, \ + PR_TRUE, (length)*sizeof(Run)) + +/* + * Sometimes, bit values are more appropriate + * to deal with directionality properties. + * Abbreviations in these macro names refer to names + * used in the Bidi algorithm. + */ +typedef PRUint8 DirProp; + +#define DIRPROP_FLAG(dir) (1UL<<(dir)) + +/* special flag for multiple runs from explicit embedding codes */ +#define DIRPROP_FLAG_MULTI_RUNS (1UL<<31) + +/* are there any characters that are LTR or RTL? */ +#define MASK_LTR (DIRPROP_FLAG(L)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(AN)|DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)) +#define MASK_RTL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO)) + +/* explicit embedding codes */ +#define MASK_LRX (DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)) +#define MASK_RLX (DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO)) +#define MASK_OVERRIDE (DIRPROP_FLAG(LRO)|DIRPROP_FLAG(RLO)) + +#define MASK_EXPLICIT (MASK_LRX|MASK_RLX|DIRPROP_FLAG(PDF)) +#define MASK_BN_EXPLICIT (DIRPROP_FLAG(BN)|MASK_EXPLICIT) + +/* paragraph and segment separators */ +#define MASK_B_S (DIRPROP_FLAG(B)|DIRPROP_FLAG(S)) + +/* all types that are counted as White Space or Neutral in some steps */ +#define MASK_WS (MASK_B_S|DIRPROP_FLAG(WS)|MASK_BN_EXPLICIT) +#define MASK_N (DIRPROP_FLAG(O_N)|MASK_WS) + +/* all types that are included in a sequence of European Terminators for (W5) */ +#define MASK_ET_NSM_BN (DIRPROP_FLAG(ET)|DIRPROP_FLAG(NSM)|MASK_BN_EXPLICIT) + +/* types that are neutrals or could becomes neutrals in (Wn) */ +#define MASK_POSSIBLE_N (DIRPROP_FLAG(CS)|DIRPROP_FLAG(ES)|DIRPROP_FLAG(ET)|MASK_N) + +/* + * These types may be changed to "e", + * the embedding type (L or R) of the run, + * in the Bidi algorithm (N2) + */ +#define MASK_EMBEDDING (DIRPROP_FLAG(NSM)|MASK_POSSIBLE_N) + +/* the dirProp's L and R are defined to 0 and 1 values in nsCharType */ +#define GET_LR_FROM_LEVEL(level) ((DirProp)((level)&1)) + +#define IS_DEFAULT_LEVEL(level) (((level)&0xfe)==0xfe) + +/* handle surrogate pairs --------------------------------------------------- */ + +#define IS_FIRST_SURROGATE(uchar) (((uchar)&0xfc00)==0xd800) +#define IS_SECOND_SURROGATE(uchar) (((uchar)&0xfc00)==0xdc00) + +/* get the UTF-32 value directly from the surrogate pseudo-characters */ +#define SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000) +#define GET_UTF_32(first, second) (((first)<<10UL)+(second)-SURROGATE_OFFSET) + + +#define UTF_ERROR_VALUE 0xffff +/* definitions with forward iteration --------------------------------------- */ + +/* + * all the macros that go forward assume that + * the initial offset is 0<=i>10)+0xd7c0; \ + (s)[(i)++]=(PRUnichar)(c)&0x3ff|0xdc00; \ + } \ +} + +/* safe versions with error-checking and optional regularity-checking */ + +#define UTF16_APPEND_CHAR_SAFE(s, i, length, c) { \ + if((PRUInt32)(c)<=0xffff) { \ + (s)[(i)++]=(PRUnichar)(c); \ + } else if((PRUInt32)(c)<=0x10ffff) { \ + if((i)+1<(length)) { \ + (s)[(i)++]=(PRUnichar)((c)>>10)+0xd7c0; \ + (s)[(i)++]=(PRUnichar)(c)&0x3ff|0xdc00; \ + } else /* not enough space */ { \ + (s)[(i)++]=UTF_ERROR_VALUE; \ + } \ + } else /* c>0x10ffff, write error value */ { \ + (s)[(i)++]=UTF_ERROR_VALUE; \ + } \ +} + +/* definitions with backward iteration -------------------------------------- */ + +/* + * all the macros that go backward assume that + * the valid buffer range starts at offset 0 + * and that the initial offset is 00) { \ + UTF16_BACK_1_UNSAFE(s, i); \ + --__N; \ + } \ +} + +/* safe versions with error-checking and optional regularity-checking */ + +#define UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) { \ + (c)=(s)[--(i)]; \ + if(IS_SECOND_SURROGATE(c)) { \ + PRUnichar __c2; \ + if((i)>(start) && IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \ + --(i); \ + (c)=GET_UTF_32(__c2, (c)); \ + /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() */ \ + } else if(strict) {\ + /* unmatched second surrogate */ \ + (c)=UTF_ERROR_VALUE; \ + } \ + } else if(strict && IS_FIRST_SURROGATE(c)) { \ + /* unmatched first surrogate */ \ + (c)=UTF_ERROR_VALUE; \ + /* else strict: (c)==0xfffe is caught by UTF_IS_ERROR() */ \ + } \ +} + +#define UTF16_BACK_1_SAFE(s, start, i) { \ + if(IS_SECOND_SURROGATE((s)[--(i)]) && (i)>(start) && IS_FIRST_SURROGATE((s)[(i)-1])) { \ + --(i); \ + } \ +} + +#define UTF16_BACK_N_SAFE(s, start, i, n) { \ + PRInt32 __N=(n); \ + while(__N>0 && (i)>(start)) { \ + UTF16_BACK_1_SAFE(s, start, i); \ + --__N; \ + } \ +} + +#define UTF_PREV_CHAR_UNSAFE(s, i, c) UTF16_PREV_CHAR_UNSAFE(s, i, c) +#define UTF_PREV_CHAR_SAFE(s, start, i, c, strict) UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) +#define UTF_BACK_1_UNSAFE(s, i) UTF16_BACK_1_UNSAFE(s, i) +#define UTF_BACK_1_SAFE(s, start, i) UTF16_BACK_1_SAFE(s, start, i) +#define UTF_BACK_N_UNSAFE(s, i, n) UTF16_BACK_N_UNSAFE(s, i, n) +#define UTF_BACK_N_SAFE(s, start, i, n) UTF16_BACK_N_SAFE(s, start, i, n) +#define UTF_APPEND_CHAR_UNSAFE(s, i, c) UTF16_APPEND_CHAR_UNSAFE(s, i, c) +#define UTF_APPEND_CHAR_SAFE(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c) + +#define UTF_PREV_CHAR(s, start, i, c) UTF_PREV_CHAR_SAFE(s, start, i, c, PR_FALSE) +#define UTF_BACK_1(s, start, i) UTF_BACK_1_SAFE(s, start, i) +#define UTF_BACK_N(s, start, i, n) UTF_BACK_N_SAFE(s, start, i, n) +#define UTF_APPEND_CHAR(s, i, length, c) UTF_APPEND_CHAR_SAFE(s, i, length, c) + +/* Run structure for reordering --------------------------------------------- */ + +typedef struct Run { + PRInt32 logicalStart, /* first character of the run; b31 indicates even/odd level */ + visualLimit; /* last visual position of the run +1 */ +} Run; + +/* in a Run, logicalStart will get this bit set if the run level is odd */ +#define INDEX_ODD_BIT (1UL<<31) + +#define MAKE_INDEX_ODD_PAIR(index, level) (index|((PRUint32)level<<31)) +#define ADD_ODD_BIT_FROM_LEVEL(x, level) ((x)|=((PRUint32)level<<31)) +#define REMOVE_ODD_BIT(x) ((x)&=~INDEX_ODD_BIT) + +#define GET_INDEX(x) (x&~INDEX_ODD_BIT) +#define GET_ODD_BIT(x) ((PRUint32)x>>31) +#define IS_ODD_RUN(x) ((x&INDEX_ODD_BIT)!=0) +#define IS_EVEN_RUN(x) ((x&INDEX_ODD_BIT)==0) + +typedef PRUint32 Flags; + +/** + * This class holds information about a paragraph of text + * with Bidi-algorithm-related details, or about one line of + * such a paragraph.

+ * Reordering can be done on a line, or on a paragraph which is + * then interpreted as one single line.

+ * + * On construction, the class is initially empty. It is assigned + * the Bidi properties of a paragraph by SetPara + * or the Bidi properties of a line of a paragraph by + * SetLine.

+ * A Bidi class can be reused for as long as it is not deallocated + * by calling its destructor.

+ * SetPara will allocate additional memory for + * internal structures as necessary. + */ +class nsBidi +{ +public: + /** @brief Default constructor. + * + * The nsBidi object is initially empty. It is assigned + * the Bidi properties of a paragraph by SetPara() + * or the Bidi properties of a line of a paragraph by + * GetLine().

+ * This object can be reused for as long as it is not destroyed.

+ * SetPara() will allocate additional memory for + * internal structures as necessary. + * + */ + nsBidi(); + + /** @brief Preallocating constructor + * Allocate an nsBidi + * object with preallocated memory for internal structures. This + * constructor provides an nsBidi object like + * the default constructor, but it also + * preallocates memory for internal structures according to the sizings + * supplied by the caller.

Subsequent functions will not allocate + * any more memory, and are thus guaranteed not to fail because of lack + * of memory.

The preallocation can be limited to some of the + * internal memory by setting some values to 0 here. That means that + * if, e.g., aMaxRunCount cannot be reasonably + * predetermined and should not be set to aMaxLength (the + * only failproof value) to avoid wasting memory, then + * aMaxRunCount could be set to 0 here and the internal + * structures that are associated with it will be allocated on demand, + * just like with the default constructor. + * + * If sufficient memory could not be allocated, no exception is thrown. + * Test whether mDirPropsSize == aMaxLength and/or mRunsSize == aMaxRunCount. + * + * @param aMaxLength is the maximum paragraph or line length that internal memory + * will be preallocated for. An attempt to associate this object with a + * longer text will fail, unless this value is 0, which leaves the allocation + * up to the implementation. + * + * @param aMaxRunCount is the maximum anticipated number of same-level runs + * that internal memory will be preallocated for. An attempt to access + * visual runs on an object that was not preallocated for as many runs + * as the text was actually resolved to will fail, + * unless this value is 0, which leaves the allocation up to the implementation.

+ * The number of runs depends on the actual text and maybe anywhere between + * 1 and aMaxLength. It is typically small.

+ */ + nsBidi(PRUint32 aMaxLength, PRUint32 aMaxRunCount); + + /** @brief Destructor. */ + virtual ~nsBidi(); + + + /** + * Perform the Unicode Bidi algorithm. It is defined in the + * Unicode Technical Report 9, + * version 5, + * also described in The Unicode Standard, Version 3.0 .

+ * + * This function takes a single plain text paragraph with or without + * externally specified embedding levels from styled text + * and computes the left-right-directionality of each character.

+ * + * If the entire paragraph consists of text of only one direction, then + * the function may not perform all the steps described by the algorithm, + * i.e., some levels may not be the same as if all steps were performed. + * This is not relevant for unidirectional text.
+ * For example, in pure LTR text with numbers the numbers would get + * a resolved level of 2 higher than the surrounding text according to + * the algorithm. This implementation may set all resolved levels to + * the same value in such a case.

+ * + * The text must be externally split into separate paragraphs (rule P1). + * Paragraph separators (B) should appear at most at the very end. + * + * @param aText is a pointer to the single-paragraph text that the + * Bidi algorithm will be performed on + * (step (P1) of the algorithm is performed externally). + * The text must be (at least) aLength long. + * + * @param aLength is the length of the text; if aLength==-1 then + * the text must be zero-terminated. + * + * @param aParaLevel specifies the default level for the paragraph; + * it is typically 0 (LTR) or 1 (RTL). + * If the function shall determine the paragraph level from the text, + * then aParaLevel can be set to + * either NSBIDI_DEFAULT_LTR + * or NSBIDI_DEFAULT_RTL; + * if there is no strongly typed character, then + * the desired default is used (0 for LTR or 1 for RTL). + * Any other value between 0 and NSBIDI_MAX_EXPLICIT_LEVEL is also valid, + * with odd levels indicating RTL. + * + * @param aEmbeddingLevels (in) may be used to preset the embedding and override levels, + * ignoring characters like LRE and PDF in the text. + * A level overrides the directional property of its corresponding + * (same index) character if the level has the + * NSBIDI_LEVEL_OVERRIDE bit set.

+ * Except for that bit, it must be + * aParaLevel<=aEmbeddingLevels[]<=NSBIDI_MAX_EXPLICIT_LEVEL.

+ * Caution: A copy of this pointer, not of the levels, + * will be stored in the nsBidi object; + * the aEmbeddingLevels array must not be + * deallocated before the nsBidi object is destroyed or reused, + * and the aEmbeddingLevels + * should not be modified to avoid unexpected results on subsequent Bidi operations. + * However, the SetPara and + * SetLine functions may modify some or all of the levels.

+ * After the nsBidi object is reused or destroyed, the caller + * must take care of the deallocation of the aEmbeddingLevels array.

+ * The aEmbeddingLevels array must be + * at least aLength long. + */ + nsresult SetPara(const PRUnichar *aText, PRInt32 aLength, nsBidiLevel aParaLevel, nsBidiLevel *aEmbeddingLevels); + +#ifdef FULL_BIDI_ENGINE + /** + * SetLine sets an nsBidi to + * contain the reordering information, especially the resolved levels, + * for all the characters in a line of text. This line of text is + * specified by referring to an nsBidi object representing + * this information for a paragraph of text, and by specifying + * a range of indexes in this paragraph.

+ * In the new line object, the indexes will range from 0 to aLimit-aStart.

+ * + * This is used after calling SetPara + * for a paragraph, and after line-breaking on that paragraph. + * It is not necessary if the paragraph is treated as a single line.

+ * + * After line-breaking, rules (L1) and (L2) for the treatment of + * trailing WS and for reordering are performed on + * an nsBidi object that represents a line.

+ * + * Important: the line nsBidi object shares data with + * aParaBidi. + * You must destroy or reuse this object before aParaBidi. + * In other words, you must destroy or reuse the nsBidi object for a line + * before the object for its parent paragraph. + * + * @param aParaBidi is the parent paragraph object. + * + * @param aStart is the line's first index into the paragraph text. + * + * @param aLimit is just behind the line's last index into the paragraph text + * (its last index +1).
+ * It must be 0<=aStart<=aLimit<=paragraph length. + * + * @see SetPara + */ + nsresult SetLine(nsIBidi* aParaBidi, PRInt32 aStart, PRInt32 aLimit); + + /** + * Get the directionality of the text. + * + * @param aDirection receives a NSBIDI_XXX value that indicates if the entire text + * represented by this object is unidirectional, + * and which direction, or if it is mixed-directional. + * + * @see nsBidiDirection + */ + nsresult GetDirection(nsBidiDirection* aDirection); + + /** + * Get the length of the text. + * + * @param aLength receives the length of the text that the nsBidi object was created for. + */ + nsresult GetLength(PRInt32* aLength); + + /** + * Get the paragraph level of the text. + * + * @param aParaLevel receives a NSBIDI_XXX value indicating the paragraph level + * + * @see nsBidiLevel + */ + nsresult GetParaLevel(nsBidiLevel* aParaLevel); + + /** + * Get the level for one character. + * + * @param aCharIndex the index of a character. + * + * @param aLevel receives the level for the character at aCharIndex. + * + * @see nsBidiLevel + */ + nsresult GetLevelAt(PRInt32 aCharIndex, nsBidiLevel* aLevel); + + /** + * Get an array of levels for each character.

+ * + * Note that this function may allocate memory under some + * circumstances, unlike GetLevelAt. + * + * @param aLevels receives a pointer to the levels array for the text, + * or NULL if an error occurs. + * + * @see nsBidiLevel + */ + nsresult GetLevels(nsBidiLevel** aLevels); +#endif // FULL_BIDI_ENGINE + /** + * Get the bidirectional type for one character. + * + * @param aCharIndex the index of a character. + * + * @param aType receives the bidirectional type of the character at aCharIndex. + */ + nsresult GetCharTypeAt(PRInt32 aCharIndex, nsCharType* aType); + + /** + * Get a logical run. + * This function returns information about a run and is used + * to retrieve runs in logical order.

+ * This is especially useful for line-breaking on a paragraph. + * + * @param aLogicalStart is the first character of the run. + * + * @param aLogicalLimit will receive the limit of the run. + * The l-value that you point to here may be the + * same expression (variable) as the one for + * aLogicalStart. + * This pointer can be NULL if this + * value is not necessary. + * + * @param aLevel will receive the level of the run. + * This pointer can be NULL if this + * value is not necessary. + */ + nsresult GetLogicalRun(PRInt32 aLogicalStart, PRInt32* aLogicalLimit, nsBidiLevel* aLevel); + + /** + * Get the number of runs. + * This function may invoke the actual reordering on the + * nsBidi object, after SetPara + * may have resolved only the levels of the text. Therefore, + * CountRuns may have to allocate memory, + * and may fail doing so. + * + * @param aRunCount will receive the number of runs. + */ + nsresult CountRuns(PRInt32* aRunCount); + + /** + * Get one run's logical start, length, and directionality, + * which can be 0 for LTR or 1 for RTL. + * In an RTL run, the character at the logical start is + * visually on the right of the displayed run. + * The length is the number of characters in the run.

+ * CountRuns should be called + * before the runs are retrieved. + * + * @param aRunIndex is the number of the run in visual order, in the + * range [0..CountRuns-1]. + * + * @param aLogicalStart is the first logical character index in the text. + * The pointer may be NULL if this index is not needed. + * + * @param aLength is the number of characters (at least one) in the run. + * The pointer may be NULL if this is not needed. + * + * @param aDirection will receive the directionality of the run, + * NSBIDI_LTR==0 or NSBIDI_RTL==1, + * never NSBIDI_MIXED. + * + * @see CountRuns

+ * + * Example: + * @code + * PRInt32 i, count, logicalStart, visualIndex=0, length; + * nsBidiDirection dir; + * pBidi->CountRuns(&count); + * for(i=0; iGetVisualRun(i, &logicalStart, &length, &dir); + * if(NSBIDI_LTR==dir) { + * do { // LTR + * show_char(text[logicalStart++], visualIndex++); + * } while(--length>0); + * } else { + * logicalStart+=length; // logicalLimit + * do { // RTL + * show_char(text[--logicalStart], visualIndex++); + * } while(--length>0); + * } + * } + * @endcode + * + * Note that in right-to-left runs, code like this places + * modifier letters before base characters and second surrogates + * before first ones. + */ + nsresult GetVisualRun(PRInt32 aRunIndex, PRInt32* aLogicalStart, PRInt32* aLength, nsBidiDirection* aDirection); + +#ifdef FULL_BIDI_ENGINE + /** + * Get the visual position from a logical text position. + * If such a mapping is used many times on the same + * nsBidi object, then calling + * GetLogicalMap is more efficient.

+ * + * Note that in right-to-left runs, this mapping places + * modifier letters before base characters and second surrogates + * before first ones. + * + * @param aLogicalIndex is the index of a character in the text. + * + * @param aVisualIndex will receive the visual position of this character. + * + * @see GetLogicalMap + * @see GetLogicalIndex + */ + nsresult GetVisualIndex(PRInt32 aLogicalIndex, PRInt32* aVisualIndex); + + /** + * Get the logical text position from a visual position. + * If such a mapping is used many times on the same + * nsBidi object, then calling + * GetVisualMap is more efficient.

+ * + * This is the inverse function to GetVisualIndex. + * + * @param aVisualIndex is the visual position of a character. + * + * @param aLogicalIndex will receive the index of this character in the text. + * + * @see GetVisualMap + * @see GetVisualIndex + */ + nsresult GetLogicalIndex(PRInt32 aVisualIndex, PRInt32* aLogicalIndex); + + /** + * Get a logical-to-visual index map (array) for the characters in the nsBidi + * (paragraph or line) object. + * + * @param aIndexMap is a pointer to an array of GetLength + * indexes which will reflect the reordering of the characters. + * The array does not need to be initialized.

+ * The index map will result in aIndexMap[aLogicalIndex]==aVisualIndex.

+ * + * @see GetVisualMap + * @see GetVisualIndex + */ + nsresult GetLogicalMap(PRInt32 *aIndexMap); + + /** + * Get a visual-to-logical index map (array) for the characters in the nsBidi + * (paragraph or line) object. + * + * @param aIndexMap is a pointer to an array of GetLength + * indexes which will reflect the reordering of the characters. + * The array does not need to be initialized.

+ * The index map will result in aIndexMap[aVisualIndex]==aLogicalIndex.

+ * + * @see GetLogicalMap + * @see GetLogicalIndex + */ + nsresult GetVisualMap(PRInt32 *aIndexMap); + + /** + * This is a convenience function that does not use a nsBidi object. + * It is intended to be used for when an application has determined the levels + * of objects (character sequences) and just needs to have them reordered (L2). + * This is equivalent to using GetLogicalMap on a + * nsBidi object. + * + * @param aLevels is an array with aLength levels that have been determined by + * the application. + * + * @param aLength is the number of levels in the array, or, semantically, + * the number of objects to be reordered. + * It must be aLength>0. + * + * @param aIndexMap is a pointer to an array of aLength + * indexes which will reflect the reordering of the characters. + * The array does not need to be initialized.

+ * The index map will result in aIndexMap[aLogicalIndex]==aVisualIndex. + */ + nsresult ReorderLogical(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap); +#endif // FULL_BIDI_ENGINE + /** + * This is a convenience function that does not use a nsBidi object. + * It is intended to be used for when an application has determined the levels + * of objects (character sequences) and just needs to have them reordered (L2). + * This is equivalent to using GetVisualMap on a + * nsBidi object. + * + * @param aLevels is an array with aLength levels that have been determined by + * the application. + * + * @param aLength is the number of levels in the array, or, semantically, + * the number of objects to be reordered. + * It must be aLength>0. + * + * @param aIndexMap is a pointer to an array of aLength + * indexes which will reflect the reordering of the characters. + * The array does not need to be initialized.

+ * The index map will result in aIndexMap[aVisualIndex]==aLogicalIndex. + */ + nsresult ReorderVisual(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap); + +#ifdef FULL_BIDI_ENGINE + /** + * Invert an index map. + * The one-to-one index mapping of the first map is inverted and written to + * the second one. + * + * @param aSrcMap is an array with aLength indexes + * which define the original mapping. + * + * @param aDestMap is an array with aLength indexes + * which will be filled with the inverse mapping. + * + * @param aLength is the length of each array. + */ + nsresult InvertMap(const PRInt32 *aSrcMap, PRInt32 *aDestMap, PRInt32 aLength); +#endif // FULL_BIDI_ENGINE + /** + * Reverse a Right-To-Left run of Unicode text. + * + * This function preserves the integrity of characters with multiple + * code units and (optionally) modifier letters. + * Characters can be replaced by mirror-image characters + * in the destination buffer. Note that "real" mirroring has + * to be done in a rendering engine by glyph selection + * and that for many "mirrored" characters there are no + * Unicode characters as mirror-image equivalents. + * There are also options to insert or remove Bidi control + * characters; see the description of the aDestSize + * and aOptions parameters and of the option bit flags. + * + * Since no Bidi controls are inserted here, this function will never + * write more than aSrcLength characters to aDest. + * + * @param aSrc A pointer to the RTL run text. + * + * @param aSrcLength The length of the RTL run. + * If the NSBIDI_REMOVE_BIDI_CONTROLS option + * is set, then the destination length may be less than + * aSrcLength. + * If this option is not set, then the destination length + * will be exactly aSrcLength. + * + * @param aDest A pointer to where the reordered text is to be copied. + * aSrc[aSrcLength] and aDest[aSrcLength] + * must not overlap. + * + * @param aOptions A bit set of options for the reordering that control + * how the reordered text is written. + * + * @param aDestSize will receive the number of characters that were written to aDest. + */ + nsresult WriteReverse(const PRUnichar *aSrc, PRInt32 aSrcLength, PRUnichar *aDest, PRUint16 aOptions, PRInt32 *aDestSize); +protected: + /** length of the current text */ + PRInt32 mLength; + + /** memory sizes in bytes */ + PRSize mDirPropsSize, mLevelsSize, mRunsSize; + + /** allocated memory */ + DirProp* mDirPropsMemory; + nsBidiLevel* mLevelsMemory; + Run* mRunsMemory; + + /** indicators for whether memory may be allocated after construction */ + PRBool mMayAllocateText, mMayAllocateRuns; + + const DirProp* mDirProps; + nsBidiLevel* mLevels; + + /** the paragraph level */ + nsBidiLevel mParaLevel; + + /** flags is a bit set for which directional properties are in the text */ + Flags mFlags; + + /** the overall paragraph or line directionality - see nsBidiDirection */ + nsBidiDirection mDirection; + + /** characters after trailingWSStart are WS and are */ + /* implicitly at the paraLevel (rule (L1)) - levels may not reflect that */ + PRInt32 mTrailingWSStart; + + /** fields for line reordering */ + PRInt32 mRunCount; /* ==-1: runs not set up yet */ + Run* mRuns; + + /** for non-mixed text, we only need a tiny array of runs (no malloc()) */ + Run mSimpleRuns[1]; + +private: + + void Init(); + + PRBool GetMemory(void **aMemory, PRSize* aSize, PRBool aMayAllocate, PRSize aSizeNeeded); + + void Free(); + + void GetDirProps(const PRUnichar *aText); + + nsBidiDirection ResolveExplicitLevels(); + + nsresult CheckExplicitLevels(nsBidiDirection *aDirection); + + nsBidiDirection DirectionFromFlags(Flags aFlags); + + void ResolveImplicitLevels(PRInt32 aStart, PRInt32 aLimit, DirProp aSOR, DirProp aEOR); + + void AdjustWSLevels(); + + void SetTrailingWSStart(); + + PRBool GetRuns(); + + void GetSingleRun(nsBidiLevel aLevel); + + void ReorderLine(nsBidiLevel aMinLevel, nsBidiLevel aMaxLevel); + + PRBool PrepareReorder(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap, nsBidiLevel *aMinLevel, nsBidiLevel *aMaxLevel); + /** + * Give a Unichar, return an eBidiCategory + */ + eBidiCategory GetBidiCategory(PRUnichar aChar); + + /** + * Give a Unichar, and a eBidiCategory, + * return PR_TRUE if the Unichar is in that category, + * return PR_FALSE, otherwise + */ + PRBool IsBidiCategory(PRUnichar aChar, eBidiCategory aBidiCategory); + + /** + * Give a Unichar + * return PR_TRUE if the Unichar is a Bidi control character (LRE, RLE, PDF, LRO, RLO, LRM, RLM) + * return PR_FALSE, otherwise + */ + PRBool IsBidiControl(PRUnichar aChar); + + /** + * Give a Unichar, return a nsCharType (compatible with ICU) + */ + nsCharType GetCharType(PRUnichar aChar); + + /** + * Give a Unichar, return the symmetric equivalent + */ + PRUnichar SymmSwap(PRUnichar aChar); + + PRInt32 doWriteReverse(const PRUnichar *src, PRInt32 srcLength, + PRUnichar *dest, PRUint16 options); + +}; + +#endif // _nsBidi_h_ diff --git a/mozilla/layout/base/public/nsBidiPresUtils.h b/mozilla/layout/base/public/nsBidiPresUtils.h index 73274460b02..8b3dbc35c5a 100644 --- a/mozilla/layout/base/public/nsBidiPresUtils.h +++ b/mozilla/layout/base/public/nsBidiPresUtils.h @@ -28,8 +28,8 @@ #include "nsVoidArray.h" #include "nsIFrame.h" -#include "nsIBidi.h" -#include "nsIUBidiUtils.h" +#include "nsBidi.h" +#include "nsBidiUtils.h" #include "nsCOMPtr.h" class nsBidiPresUtils { @@ -75,9 +75,9 @@ public: PRBool aIsBidiSystem); /** - * Return our nsIBidi object (bidi reordering engine) + * Return our nsBidi object (bidi reordering engine) */ - nsresult GetBidiEngine(nsIBidi** aBidiEngine); + nsresult GetBidiEngine(nsBidi** aBidiEngine); /** * Reorder plain text using the Unicode Bidi algorithm and send it to @@ -100,6 +100,24 @@ public: nscoord aX, nscoord aY); + /** + * Scan a Unichar string, converting numbers to Arabic or Hindi forms in place + * @param aBuffer is the string + * @param aSize is the size of aBuffer + * @param aNumFlag specifies the conversion to perform: + * IBMBIDI_NUMERAL_HINDI: convert to Hindi forms (Unicode 0660-0669) + * IBMBIDI_NUMERAL_ARABIC: convert to Arabic forms (Unicode 0030-0039) + * IBMBIDI_NUMERAL_HINDICONTEXT: convert numbers in Arabic text to Hindi, otherwise to Arabic + */ + 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); + private: /** * Create a string containing entire text content of this block. @@ -169,9 +187,9 @@ private: PRInt32* mIndexMap; PRUint8* mLevels; nsresult mSuccess; + PRUint32 mNumflag; - nsCOMPtr mBidiEngine; - nsCOMPtr mUnicodeUtils; + nsBidi* mBidiEngine; }; #endif /* nsBidiPresUtils_h___ */ diff --git a/mozilla/layout/base/src/Makefile.in b/mozilla/layout/base/src/Makefile.in index 15ebf28a1ed..c5de62cce95 100644 --- a/mozilla/layout/base/src/Makefile.in +++ b/mozilla/layout/base/src/Makefile.in @@ -72,6 +72,7 @@ CPPSRCS = \ ifdef IBMBIDI CPPSRCS += \ nsBidiPresUtils.cpp \ + nsBidi.cpp \ $(NULL) endif diff --git a/mozilla/layout/base/src/bidicattable.h b/mozilla/layout/base/src/bidicattable.h new file mode 100644 index 00000000000..f97939ba079 --- /dev/null +++ b/mozilla/layout/base/src/bidicattable.h @@ -0,0 +1,1945 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "MPL"); you may not use this file except in + * compliance with the MPL. You may obtain a copy of the MPL at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the MPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the MPL + * for the specific language governing rights and limitations under the + * MPL. + * + * The Initial Developer of the Original Code is IBM + * Corporation. Portions created by IBM are + * Copyright (C) 2000 IBM Corporation. All + * Rights Reserved. + */ +/* + DO NOT EDIT THIS DOCUMENT !!! THIS DOCUMENT IS GENERATED BY + mozilla/intl/unicharutil/tools/genbidicattable.pl + */ + + +#include "nscore.h" + +static PRUint8 gBidiCatIdx1[256] = { + 11, /* U+0000 - U+0007 : 0xBBBBBBBB */ + 16, /* U+0008 - U+000F : 0xBBCEDCDB */ + 11, /* U+0010 - U+0017 : 0xBBBBBBBB */ + 17, /* U+0018 - U+001F : 0xDCCCBBBB */ + 18, /* U+0020 - U+0027 : 0x9977799E */ + 19, /* U+0028 - U+002F : 0x68787999 */ + 5, /* U+0030 - U+0037 : 0x55555555 */ + 20, /* U+0038 - U+003F : 0x99999855 */ + 21, /* U+0040 - U+0047 : 0x11111119 */ + 1, /* U+0048 - U+004F : 0x11111111 */ + 1, /* U+0050 - U+0057 : 0x11111111 */ + 22, /* U+0058 - U+005F : 0x99999111 */ + 21, /* U+0060 - U+0067 : 0x11111119 */ + 1, /* U+0068 - U+006F : 0x11111111 */ + 1, /* U+0070 - U+0077 : 0x11111111 */ + 23, /* U+0078 - U+007F : 0xB9999111 */ + 24, /* U+0080 - U+0087 : 0xBBCBBBBB */ + 11, /* U+0088 - U+008F : 0xBBBBBBBB */ + 11, /* U+0090 - U+0097 : 0xBBBBBBBB */ + 11, /* U+0098 - U+009F : 0xBBBBBBBB */ + 25, /* U+00A0 - U+00A7 : 0x99777798 */ + 26, /* U+00A8 - U+00AF : 0x99999199 */ + 27, /* U+00B0 - U+00B7 : 0x99195577 */ + 28, /* U+00B8 - U+00BF : 0x99999159 */ + 1, /* U+00C0 - U+00C7 : 0x11111111 */ + 1, /* U+00C8 - U+00CF : 0x11111111 */ + 29, /* U+00D0 - U+00D7 : 0x91111111 */ + 1, /* U+00D8 - U+00DF : 0x11111111 */ + 1, /* U+00E0 - U+00E7 : 0x11111111 */ + 1, /* U+00E8 - U+00EF : 0x11111111 */ + 29, /* U+00F0 - U+00F7 : 0x91111111 */ + 1, /* U+00F8 - U+00FF : 0x11111111 */ + 1, /* U+0100 - U+0107 : 0x11111111 */ + 1, /* U+0108 - U+010F : 0x11111111 */ + 1, /* U+0110 - U+0117 : 0x11111111 */ + 1, /* U+0118 - U+011F : 0x11111111 */ + 1, /* U+0120 - U+0127 : 0x11111111 */ + 1, /* U+0128 - U+012F : 0x11111111 */ + 1, /* U+0130 - U+0137 : 0x11111111 */ + 1, /* U+0138 - U+013F : 0x11111111 */ + 1, /* U+0140 - U+0147 : 0x11111111 */ + 1, /* U+0148 - U+014F : 0x11111111 */ + 1, /* U+0150 - U+0157 : 0x11111111 */ + 1, /* U+0158 - U+015F : 0x11111111 */ + 1, /* U+0160 - U+0167 : 0x11111111 */ + 1, /* U+0168 - U+016F : 0x11111111 */ + 1, /* U+0170 - U+0177 : 0x11111111 */ + 1, /* U+0178 - U+017F : 0x11111111 */ + 1, /* U+0180 - U+0187 : 0x11111111 */ + 1, /* U+0188 - U+018F : 0x11111111 */ + 1, /* U+0190 - U+0197 : 0x11111111 */ + 1, /* U+0198 - U+019F : 0x11111111 */ + 1, /* U+01A0 - U+01A7 : 0x11111111 */ + 1, /* U+01A8 - U+01AF : 0x11111111 */ + 1, /* U+01B0 - U+01B7 : 0x11111111 */ + 1, /* U+01B8 - U+01BF : 0x11111111 */ + 1, /* U+01C0 - U+01C7 : 0x11111111 */ + 1, /* U+01C8 - U+01CF : 0x11111111 */ + 1, /* U+01D0 - U+01D7 : 0x11111111 */ + 1, /* U+01D8 - U+01DF : 0x11111111 */ + 1, /* U+01E0 - U+01E7 : 0x11111111 */ + 1, /* U+01E8 - U+01EF : 0x11111111 */ + 1, /* U+01F0 - U+01F7 : 0x11111111 */ + 1, /* U+01F8 - U+01FF : 0x11111111 */ + 1, /* U+0200 - U+0207 : 0x11111111 */ + 1, /* U+0208 - U+020F : 0x11111111 */ + 1, /* U+0210 - U+0217 : 0x11111111 */ + 1, /* U+0218 - U+021F : 0x11111111 */ + 1, /* U+0220 - U+0227 : 0x11111111 */ + 1, /* U+0228 - U+022F : 0x11111111 */ + 1, /* U+0230 - U+0237 : 0x11111111 */ + 1, /* U+0238 - U+023F : 0x11111111 */ + 1, /* U+0240 - U+0247 : 0x11111111 */ + 1, /* U+0248 - U+024F : 0x11111111 */ + 1, /* U+0250 - U+0257 : 0x11111111 */ + 1, /* U+0258 - U+025F : 0x11111111 */ + 1, /* U+0260 - U+0267 : 0x11111111 */ + 1, /* U+0268 - U+026F : 0x11111111 */ + 1, /* U+0270 - U+0277 : 0x11111111 */ + 1, /* U+0278 - U+027F : 0x11111111 */ + 1, /* U+0280 - U+0287 : 0x11111111 */ + 1, /* U+0288 - U+028F : 0x11111111 */ + 1, /* U+0290 - U+0297 : 0x11111111 */ + 1, /* U+0298 - U+029F : 0x11111111 */ + 1, /* U+02A0 - U+02A7 : 0x11111111 */ + 1, /* U+02A8 - U+02AF : 0x11111111 */ + 1, /* U+02B0 - U+02B7 : 0x11111111 */ + 30, /* U+02B8 - U+02BF : 0x11111991 */ + 31, /* U+02C0 - U+02C7 : 0x99999911 */ + 9, /* U+02C8 - U+02CF : 0x99999999 */ + 31, /* U+02D0 - U+02D7 : 0x99999911 */ + 9, /* U+02D8 - U+02DF : 0x99999999 */ + 32, /* U+02E0 - U+02E7 : 0x99911111 */ + 33, /* U+02E8 - U+02EF : 0x11999999 */ + 1, /* U+02F0 - U+02F7 : 0x11111111 */ + 1, /* U+02F8 - U+02FF : 0x11111111 */ + 10, /* U+0300 - U+0307 : 0xAAAAAAAA */ + 10, /* U+0308 - U+030F : 0xAAAAAAAA */ + 10, /* U+0310 - U+0317 : 0xAAAAAAAA */ + 10, /* U+0318 - U+031F : 0xAAAAAAAA */ + 10, /* U+0320 - U+0327 : 0xAAAAAAAA */ + 10, /* U+0328 - U+032F : 0xAAAAAAAA */ + 10, /* U+0330 - U+0337 : 0xAAAAAAAA */ + 10, /* U+0338 - U+033F : 0xAAAAAAAA */ + 10, /* U+0340 - U+0347 : 0xAAAAAAAA */ + 34, /* U+0348 - U+034F : 0x1AAAAAAA */ + 1, /* U+0350 - U+0357 : 0x11111111 */ + 1, /* U+0358 - U+035F : 0x11111111 */ + 35, /* U+0360 - U+0367 : 0x11111AAA */ + 1, /* U+0368 - U+036F : 0x11111111 */ + 36, /* U+0370 - U+0377 : 0x11991111 */ + 37, /* U+0378 - U+037F : 0x19111111 */ + 38, /* U+0380 - U+0387 : 0x91991111 */ + 1, /* U+0388 - U+038F : 0x11111111 */ + 1, /* U+0390 - U+0397 : 0x11111111 */ + 1, /* U+0398 - U+039F : 0x11111111 */ + 1, /* U+03A0 - U+03A7 : 0x11111111 */ + 1, /* U+03A8 - U+03AF : 0x11111111 */ + 1, /* U+03B0 - U+03B7 : 0x11111111 */ + 1, /* U+03B8 - U+03BF : 0x11111111 */ + 1, /* U+03C0 - U+03C7 : 0x11111111 */ + 1, /* U+03C8 - U+03CF : 0x11111111 */ + 1, /* U+03D0 - U+03D7 : 0x11111111 */ + 1, /* U+03D8 - U+03DF : 0x11111111 */ + 1, /* U+03E0 - U+03E7 : 0x11111111 */ + 1, /* U+03E8 - U+03EF : 0x11111111 */ + 1, /* U+03F0 - U+03F7 : 0x11111111 */ + 1, /* U+03F8 - U+03FF : 0x11111111 */ + 1, /* U+0400 - U+0407 : 0x11111111 */ + 1, /* U+0408 - U+040F : 0x11111111 */ + 1, /* U+0410 - U+0417 : 0x11111111 */ + 1, /* U+0418 - U+041F : 0x11111111 */ + 1, /* U+0420 - U+0427 : 0x11111111 */ + 1, /* U+0428 - U+042F : 0x11111111 */ + 1, /* U+0430 - U+0437 : 0x11111111 */ + 1, /* U+0438 - U+043F : 0x11111111 */ + 1, /* U+0440 - U+0447 : 0x11111111 */ + 1, /* U+0448 - U+044F : 0x11111111 */ + 1, /* U+0450 - U+0457 : 0x11111111 */ + 1, /* U+0458 - U+045F : 0x11111111 */ + 1, /* U+0460 - U+0467 : 0x11111111 */ + 1, /* U+0468 - U+046F : 0x11111111 */ + 1, /* U+0470 - U+0477 : 0x11111111 */ + 1, /* U+0478 - U+047F : 0x11111111 */ + 39, /* U+0480 - U+0487 : 0x1AAAA111 */ + 40, /* U+0488 - U+048F : 0x111111AA */ + 1, /* U+0490 - U+0497 : 0x11111111 */ + 1, /* U+0498 - U+049F : 0x11111111 */ + 1, /* U+04A0 - U+04A7 : 0x11111111 */ + 1, /* U+04A8 - U+04AF : 0x11111111 */ + 1, /* U+04B0 - U+04B7 : 0x11111111 */ + 1, /* U+04B8 - U+04BF : 0x11111111 */ + 1, /* U+04C0 - U+04C7 : 0x11111111 */ + 1, /* U+04C8 - U+04CF : 0x11111111 */ + 1, /* U+04D0 - U+04D7 : 0x11111111 */ + 1, /* U+04D8 - U+04DF : 0x11111111 */ + 1, /* U+04E0 - U+04E7 : 0x11111111 */ + 1, /* U+04E8 - U+04EF : 0x11111111 */ + 1, /* U+04F0 - U+04F7 : 0x11111111 */ + 1, /* U+04F8 - U+04FF : 0x11111111 */ + 1, /* U+0500 - U+0507 : 0x11111111 */ + 1, /* U+0508 - U+050F : 0x11111111 */ + 1, /* U+0510 - U+0517 : 0x11111111 */ + 1, /* U+0518 - U+051F : 0x11111111 */ + 1, /* U+0520 - U+0527 : 0x11111111 */ + 1, /* U+0528 - U+052F : 0x11111111 */ + 1, /* U+0530 - U+0537 : 0x11111111 */ + 1, /* U+0538 - U+053F : 0x11111111 */ + 1, /* U+0540 - U+0547 : 0x11111111 */ + 1, /* U+0548 - U+054F : 0x11111111 */ + 1, /* U+0550 - U+0557 : 0x11111111 */ + 1, /* U+0558 - U+055F : 0x11111111 */ + 1, /* U+0560 - U+0567 : 0x11111111 */ + 1, /* U+0568 - U+056F : 0x11111111 */ + 1, /* U+0570 - U+0577 : 0x11111111 */ + 1, /* U+0578 - U+057F : 0x11111111 */ + 1, /* U+0580 - U+0587 : 0x11111111 */ + 41, /* U+0588 - U+058F : 0x11111911 */ + 42, /* U+0590 - U+0597 : 0xAAAAAAA2 */ + 10, /* U+0598 - U+059F : 0xAAAAAAAA */ + 43, /* U+05A0 - U+05A7 : 0xAAAAA2AA */ + 10, /* U+05A8 - U+05AF : 0xAAAAAAAA */ + 10, /* U+05B0 - U+05B7 : 0xAAAAAAAA */ + 44, /* U+05B8 - U+05BF : 0xA2AAA2AA */ + 45, /* U+05C0 - U+05C7 : 0x222A2AA2 */ + 2, /* U+05C8 - U+05CF : 0x22222222 */ + 2, /* U+05D0 - U+05D7 : 0x22222222 */ + 2, /* U+05D8 - U+05DF : 0x22222222 */ + 2, /* U+05E0 - U+05E7 : 0x22222222 */ + 2, /* U+05E8 - U+05EF : 0x22222222 */ + 2, /* U+05F0 - U+05F7 : 0x22222222 */ + 2, /* U+05F8 - U+05FF : 0x22222222 */ + 3, /* U+0600 - U+0607 : 0x33333333 */ + 46, /* U+0608 - U+060F : 0x33383333 */ + 3, /* U+0610 - U+0617 : 0x33333333 */ + 3, /* U+0618 - U+061F : 0x33333333 */ + 3, /* U+0620 - U+0627 : 0x33333333 */ + 3, /* U+0628 - U+062F : 0x33333333 */ + 3, /* U+0630 - U+0637 : 0x33333333 */ + 3, /* U+0638 - U+063F : 0x33333333 */ + 3, /* U+0640 - U+0647 : 0x33333333 */ + 47, /* U+0648 - U+064F : 0xAAAAA333 */ + 48, /* U+0650 - U+0657 : 0x33AAAAAA */ + 3, /* U+0658 - U+065F : 0x33333333 */ + 4, /* U+0660 - U+0667 : 0x44444444 */ + 49, /* U+0668 - U+066F : 0x33344744 */ + 50, /* U+0670 - U+0677 : 0x3333333A */ + 3, /* U+0678 - U+067F : 0x33333333 */ + 3, /* U+0680 - U+0687 : 0x33333333 */ + 3, /* U+0688 - U+068F : 0x33333333 */ + 3, /* U+0690 - U+0697 : 0x33333333 */ + 3, /* U+0698 - U+069F : 0x33333333 */ + 3, /* U+06A0 - U+06A7 : 0x33333333 */ + 3, /* U+06A8 - U+06AF : 0x33333333 */ + 3, /* U+06B0 - U+06B7 : 0x33333333 */ + 3, /* U+06B8 - U+06BF : 0x33333333 */ + 3, /* U+06C0 - U+06C7 : 0x33333333 */ + 3, /* U+06C8 - U+06CF : 0x33333333 */ + 51, /* U+06D0 - U+06D7 : 0xAA333333 */ + 10, /* U+06D8 - U+06DF : 0xAAAAAAAA */ + 52, /* U+06E0 - U+06E7 : 0xA33AAAAA */ + 53, /* U+06E8 - U+06EF : 0x33AAAA9A */ + 5, /* U+06F0 - U+06F7 : 0x55555555 */ + 54, /* U+06F8 - U+06FF : 0x33333355 */ + 3, /* U+0700 - U+0707 : 0x33333333 */ + 55, /* U+0708 - U+070F : 0xB3333333 */ + 56, /* U+0710 - U+0717 : 0x333333A3 */ + 3, /* U+0718 - U+071F : 0x33333333 */ + 3, /* U+0720 - U+0727 : 0x33333333 */ + 3, /* U+0728 - U+072F : 0x33333333 */ + 10, /* U+0730 - U+0737 : 0xAAAAAAAA */ + 10, /* U+0738 - U+073F : 0xAAAAAAAA */ + 10, /* U+0740 - U+0747 : 0xAAAAAAAA */ + 57, /* U+0748 - U+074F : 0x33333AAA */ + 3, /* U+0750 - U+0757 : 0x33333333 */ + 3, /* U+0758 - U+075F : 0x33333333 */ + 3, /* U+0760 - U+0767 : 0x33333333 */ + 3, /* U+0768 - U+076F : 0x33333333 */ + 3, /* U+0770 - U+0777 : 0x33333333 */ + 3, /* U+0778 - U+077F : 0x33333333 */ + 3, /* U+0780 - U+0787 : 0x33333333 */ + 3, /* U+0788 - U+078F : 0x33333333 */ + 3, /* U+0790 - U+0797 : 0x33333333 */ + 3, /* U+0798 - U+079F : 0x33333333 */ + 51, /* U+07A0 - U+07A7 : 0xAA333333 */ + 10, /* U+07A8 - U+07AF : 0xAAAAAAAA */ + 50, /* U+07B0 - U+07B7 : 0x3333333A */ + 3, /* U+07B8 - U+07BF : 0x33333333 */ + 1, /* U+07C0 - U+07C7 : 0x11111111 */ + 1, /* U+07C8 - U+07CF : 0x11111111 */ + 1, /* U+07D0 - U+07D7 : 0x11111111 */ + 1, /* U+07D8 - U+07DF : 0x11111111 */ + 1, /* U+07E0 - U+07E7 : 0x11111111 */ + 1, /* U+07E8 - U+07EF : 0x11111111 */ + 1, /* U+07F0 - U+07F7 : 0x11111111 */ + 1, /* U+07F8 - U+07FF : 0x11111111 */ +}; + +static PRUint8 gBidiCatIdx2[512] = { + 58, /* U+0900 - U+0907 : 0x11111AA1 */ + 1, /* U+0908 - U+090F : 0x11111111 */ + 1, /* U+0910 - U+0917 : 0x11111111 */ + 1, /* U+0918 - U+091F : 0x11111111 */ + 1, /* U+0920 - U+0927 : 0x11111111 */ + 1, /* U+0928 - U+092F : 0x11111111 */ + 1, /* U+0930 - U+0937 : 0x11111111 */ + 59, /* U+0938 - U+093F : 0x111A1111 */ + 60, /* U+0940 - U+0947 : 0xAAAAAAA1 */ + 61, /* U+0948 - U+094F : 0x11A1111A */ + 62, /* U+0950 - U+0957 : 0x111AAAA1 */ + 1, /* U+0958 - U+095F : 0x11111111 */ + 63, /* U+0960 - U+0967 : 0x1111AA11 */ + 1, /* U+0968 - U+096F : 0x11111111 */ + 1, /* U+0970 - U+0977 : 0x11111111 */ + 1, /* U+0978 - U+097F : 0x11111111 */ + 64, /* U+0980 - U+0987 : 0x111111A1 */ + 1, /* U+0988 - U+098F : 0x11111111 */ + 1, /* U+0990 - U+0997 : 0x11111111 */ + 1, /* U+0998 - U+099F : 0x11111111 */ + 1, /* U+09A0 - U+09A7 : 0x11111111 */ + 1, /* U+09A8 - U+09AF : 0x11111111 */ + 1, /* U+09B0 - U+09B7 : 0x11111111 */ + 59, /* U+09B8 - U+09BF : 0x111A1111 */ + 62, /* U+09C0 - U+09C7 : 0x111AAAA1 */ + 65, /* U+09C8 - U+09CF : 0x11A11111 */ + 1, /* U+09D0 - U+09D7 : 0x11111111 */ + 1, /* U+09D8 - U+09DF : 0x11111111 */ + 63, /* U+09E0 - U+09E7 : 0x1111AA11 */ + 1, /* U+09E8 - U+09EF : 0x11111111 */ + 66, /* U+09F0 - U+09F7 : 0x11117711 */ + 1, /* U+09F8 - U+09FF : 0x11111111 */ + 67, /* U+0A00 - U+0A07 : 0x11111A11 */ + 1, /* U+0A08 - U+0A0F : 0x11111111 */ + 1, /* U+0A10 - U+0A17 : 0x11111111 */ + 1, /* U+0A18 - U+0A1F : 0x11111111 */ + 1, /* U+0A20 - U+0A27 : 0x11111111 */ + 1, /* U+0A28 - U+0A2F : 0x11111111 */ + 1, /* U+0A30 - U+0A37 : 0x11111111 */ + 59, /* U+0A38 - U+0A3F : 0x111A1111 */ + 68, /* U+0A40 - U+0A47 : 0xA1111AA1 */ + 69, /* U+0A48 - U+0A4F : 0x11AAA11A */ + 1, /* U+0A50 - U+0A57 : 0x11111111 */ + 1, /* U+0A58 - U+0A5F : 0x11111111 */ + 1, /* U+0A60 - U+0A67 : 0x11111111 */ + 1, /* U+0A68 - U+0A6F : 0x11111111 */ + 40, /* U+0A70 - U+0A77 : 0x111111AA */ + 1, /* U+0A78 - U+0A7F : 0x11111111 */ + 58, /* U+0A80 - U+0A87 : 0x11111AA1 */ + 1, /* U+0A88 - U+0A8F : 0x11111111 */ + 1, /* U+0A90 - U+0A97 : 0x11111111 */ + 1, /* U+0A98 - U+0A9F : 0x11111111 */ + 1, /* U+0AA0 - U+0AA7 : 0x11111111 */ + 1, /* U+0AA8 - U+0AAF : 0x11111111 */ + 1, /* U+0AB0 - U+0AB7 : 0x11111111 */ + 59, /* U+0AB8 - U+0ABF : 0x111A1111 */ + 70, /* U+0AC0 - U+0AC7 : 0xA1AAAAA1 */ + 61, /* U+0AC8 - U+0ACF : 0x11A1111A */ + 1, /* U+0AD0 - U+0AD7 : 0x11111111 */ + 1, /* U+0AD8 - U+0ADF : 0x11111111 */ + 1, /* U+0AE0 - U+0AE7 : 0x11111111 */ + 1, /* U+0AE8 - U+0AEF : 0x11111111 */ + 1, /* U+0AF0 - U+0AF7 : 0x11111111 */ + 1, /* U+0AF8 - U+0AFF : 0x11111111 */ + 64, /* U+0B00 - U+0B07 : 0x111111A1 */ + 1, /* U+0B08 - U+0B0F : 0x11111111 */ + 1, /* U+0B10 - U+0B17 : 0x11111111 */ + 1, /* U+0B18 - U+0B1F : 0x11111111 */ + 1, /* U+0B20 - U+0B27 : 0x11111111 */ + 1, /* U+0B28 - U+0B2F : 0x11111111 */ + 1, /* U+0B30 - U+0B37 : 0x11111111 */ + 71, /* U+0B38 - U+0B3F : 0xA11A1111 */ + 72, /* U+0B40 - U+0B47 : 0x1111AAA1 */ + 65, /* U+0B48 - U+0B4F : 0x11A11111 */ + 73, /* U+0B50 - U+0B57 : 0x1A111111 */ + 1, /* U+0B58 - U+0B5F : 0x11111111 */ + 1, /* U+0B60 - U+0B67 : 0x11111111 */ + 1, /* U+0B68 - U+0B6F : 0x11111111 */ + 1, /* U+0B70 - U+0B77 : 0x11111111 */ + 1, /* U+0B78 - U+0B7F : 0x11111111 */ + 67, /* U+0B80 - U+0B87 : 0x11111A11 */ + 1, /* U+0B88 - U+0B8F : 0x11111111 */ + 1, /* U+0B90 - U+0B97 : 0x11111111 */ + 1, /* U+0B98 - U+0B9F : 0x11111111 */ + 1, /* U+0BA0 - U+0BA7 : 0x11111111 */ + 1, /* U+0BA8 - U+0BAF : 0x11111111 */ + 1, /* U+0BB0 - U+0BB7 : 0x11111111 */ + 1, /* U+0BB8 - U+0BBF : 0x11111111 */ + 74, /* U+0BC0 - U+0BC7 : 0x1111111A */ + 65, /* U+0BC8 - U+0BCF : 0x11A11111 */ + 1, /* U+0BD0 - U+0BD7 : 0x11111111 */ + 1, /* U+0BD8 - U+0BDF : 0x11111111 */ + 1, /* U+0BE0 - U+0BE7 : 0x11111111 */ + 1, /* U+0BE8 - U+0BEF : 0x11111111 */ + 1, /* U+0BF0 - U+0BF7 : 0x11111111 */ + 1, /* U+0BF8 - U+0BFF : 0x11111111 */ + 1, /* U+0C00 - U+0C07 : 0x11111111 */ + 1, /* U+0C08 - U+0C0F : 0x11111111 */ + 1, /* U+0C10 - U+0C17 : 0x11111111 */ + 1, /* U+0C18 - U+0C1F : 0x11111111 */ + 1, /* U+0C20 - U+0C27 : 0x11111111 */ + 1, /* U+0C28 - U+0C2F : 0x11111111 */ + 1, /* U+0C30 - U+0C37 : 0x11111111 */ + 75, /* U+0C38 - U+0C3F : 0xAA111111 */ + 76, /* U+0C40 - U+0C47 : 0xAA11111A */ + 77, /* U+0C48 - U+0C4F : 0x11AAAA1A */ + 78, /* U+0C50 - U+0C57 : 0x1AA11111 */ + 1, /* U+0C58 - U+0C5F : 0x11111111 */ + 1, /* U+0C60 - U+0C67 : 0x11111111 */ + 1, /* U+0C68 - U+0C6F : 0x11111111 */ + 1, /* U+0C70 - U+0C77 : 0x11111111 */ + 1, /* U+0C78 - U+0C7F : 0x11111111 */ + 1, /* U+0C80 - U+0C87 : 0x11111111 */ + 1, /* U+0C88 - U+0C8F : 0x11111111 */ + 1, /* U+0C90 - U+0C97 : 0x11111111 */ + 1, /* U+0C98 - U+0C9F : 0x11111111 */ + 1, /* U+0CA0 - U+0CA7 : 0x11111111 */ + 1, /* U+0CA8 - U+0CAF : 0x11111111 */ + 1, /* U+0CB0 - U+0CB7 : 0x11111111 */ + 79, /* U+0CB8 - U+0CBF : 0xA1111111 */ + 73, /* U+0CC0 - U+0CC7 : 0x1A111111 */ + 80, /* U+0CC8 - U+0CCF : 0x11AA1111 */ + 1, /* U+0CD0 - U+0CD7 : 0x11111111 */ + 1, /* U+0CD8 - U+0CDF : 0x11111111 */ + 1, /* U+0CE0 - U+0CE7 : 0x11111111 */ + 1, /* U+0CE8 - U+0CEF : 0x11111111 */ + 1, /* U+0CF0 - U+0CF7 : 0x11111111 */ + 1, /* U+0CF8 - U+0CFF : 0x11111111 */ + 1, /* U+0D00 - U+0D07 : 0x11111111 */ + 1, /* U+0D08 - U+0D0F : 0x11111111 */ + 1, /* U+0D10 - U+0D17 : 0x11111111 */ + 1, /* U+0D18 - U+0D1F : 0x11111111 */ + 1, /* U+0D20 - U+0D27 : 0x11111111 */ + 1, /* U+0D28 - U+0D2F : 0x11111111 */ + 1, /* U+0D30 - U+0D37 : 0x11111111 */ + 1, /* U+0D38 - U+0D3F : 0x11111111 */ + 72, /* U+0D40 - U+0D47 : 0x1111AAA1 */ + 65, /* U+0D48 - U+0D4F : 0x11A11111 */ + 1, /* U+0D50 - U+0D57 : 0x11111111 */ + 1, /* U+0D58 - U+0D5F : 0x11111111 */ + 1, /* U+0D60 - U+0D67 : 0x11111111 */ + 1, /* U+0D68 - U+0D6F : 0x11111111 */ + 1, /* U+0D70 - U+0D77 : 0x11111111 */ + 1, /* U+0D78 - U+0D7F : 0x11111111 */ + 1, /* U+0D80 - U+0D87 : 0x11111111 */ + 1, /* U+0D88 - U+0D8F : 0x11111111 */ + 1, /* U+0D90 - U+0D97 : 0x11111111 */ + 1, /* U+0D98 - U+0D9F : 0x11111111 */ + 1, /* U+0DA0 - U+0DA7 : 0x11111111 */ + 1, /* U+0DA8 - U+0DAF : 0x11111111 */ + 1, /* U+0DB0 - U+0DB7 : 0x11111111 */ + 1, /* U+0DB8 - U+0DBF : 0x11111111 */ + 1, /* U+0DC0 - U+0DC7 : 0x11111111 */ + 67, /* U+0DC8 - U+0DCF : 0x11111A11 */ + 81, /* U+0DD0 - U+0DD7 : 0x1A1AAA11 */ + 1, /* U+0DD8 - U+0DDF : 0x11111111 */ + 1, /* U+0DE0 - U+0DE7 : 0x11111111 */ + 1, /* U+0DE8 - U+0DEF : 0x11111111 */ + 1, /* U+0DF0 - U+0DF7 : 0x11111111 */ + 1, /* U+0DF8 - U+0DFF : 0x11111111 */ + 1, /* U+0E00 - U+0E07 : 0x11111111 */ + 1, /* U+0E08 - U+0E0F : 0x11111111 */ + 1, /* U+0E10 - U+0E17 : 0x11111111 */ + 1, /* U+0E18 - U+0E1F : 0x11111111 */ + 1, /* U+0E20 - U+0E27 : 0x11111111 */ + 1, /* U+0E28 - U+0E2F : 0x11111111 */ + 82, /* U+0E30 - U+0E37 : 0xAAAA11A1 */ + 83, /* U+0E38 - U+0E3F : 0x71111AAA */ + 79, /* U+0E40 - U+0E47 : 0xA1111111 */ + 34, /* U+0E48 - U+0E4F : 0x1AAAAAAA */ + 1, /* U+0E50 - U+0E57 : 0x11111111 */ + 1, /* U+0E58 - U+0E5F : 0x11111111 */ + 1, /* U+0E60 - U+0E67 : 0x11111111 */ + 1, /* U+0E68 - U+0E6F : 0x11111111 */ + 1, /* U+0E70 - U+0E77 : 0x11111111 */ + 1, /* U+0E78 - U+0E7F : 0x11111111 */ + 1, /* U+0E80 - U+0E87 : 0x11111111 */ + 1, /* U+0E88 - U+0E8F : 0x11111111 */ + 1, /* U+0E90 - U+0E97 : 0x11111111 */ + 1, /* U+0E98 - U+0E9F : 0x11111111 */ + 1, /* U+0EA0 - U+0EA7 : 0x11111111 */ + 1, /* U+0EA8 - U+0EAF : 0x11111111 */ + 82, /* U+0EB0 - U+0EB7 : 0xAAAA11A1 */ + 84, /* U+0EB8 - U+0EBF : 0x111AA1AA */ + 1, /* U+0EC0 - U+0EC7 : 0x11111111 */ + 85, /* U+0EC8 - U+0ECF : 0x11AAAAAA */ + 1, /* U+0ED0 - U+0ED7 : 0x11111111 */ + 1, /* U+0ED8 - U+0EDF : 0x11111111 */ + 1, /* U+0EE0 - U+0EE7 : 0x11111111 */ + 1, /* U+0EE8 - U+0EEF : 0x11111111 */ + 1, /* U+0EF0 - U+0EF7 : 0x11111111 */ + 1, /* U+0EF8 - U+0EFF : 0x11111111 */ + 1, /* U+0F00 - U+0F07 : 0x11111111 */ + 1, /* U+0F08 - U+0F0F : 0x11111111 */ + 1, /* U+0F10 - U+0F17 : 0x11111111 */ + 40, /* U+0F18 - U+0F1F : 0x111111AA */ + 1, /* U+0F20 - U+0F27 : 0x11111111 */ + 1, /* U+0F28 - U+0F2F : 0x11111111 */ + 86, /* U+0F30 - U+0F37 : 0xA1A11111 */ + 87, /* U+0F38 - U+0F3F : 0x119999A1 */ + 1, /* U+0F40 - U+0F47 : 0x11111111 */ + 1, /* U+0F48 - U+0F4F : 0x11111111 */ + 1, /* U+0F50 - U+0F57 : 0x11111111 */ + 1, /* U+0F58 - U+0F5F : 0x11111111 */ + 1, /* U+0F60 - U+0F67 : 0x11111111 */ + 1, /* U+0F68 - U+0F6F : 0x11111111 */ + 60, /* U+0F70 - U+0F77 : 0xAAAAAAA1 */ + 34, /* U+0F78 - U+0F7F : 0x1AAAAAAA */ + 88, /* U+0F80 - U+0F87 : 0xAA1AAAAA */ + 1, /* U+0F88 - U+0F8F : 0x11111111 */ + 10, /* U+0F90 - U+0F97 : 0xAAAAAAAA */ + 60, /* U+0F98 - U+0F9F : 0xAAAAAAA1 */ + 10, /* U+0FA0 - U+0FA7 : 0xAAAAAAAA */ + 10, /* U+0FA8 - U+0FAF : 0xAAAAAAAA */ + 10, /* U+0FB0 - U+0FB7 : 0xAAAAAAAA */ + 89, /* U+0FB8 - U+0FBF : 0x111AAAAA */ + 73, /* U+0FC0 - U+0FC7 : 0x1A111111 */ + 1, /* U+0FC8 - U+0FCF : 0x11111111 */ + 1, /* U+0FD0 - U+0FD7 : 0x11111111 */ + 1, /* U+0FD8 - U+0FDF : 0x11111111 */ + 1, /* U+0FE0 - U+0FE7 : 0x11111111 */ + 1, /* U+0FE8 - U+0FEF : 0x11111111 */ + 1, /* U+0FF0 - U+0FF7 : 0x11111111 */ + 1, /* U+0FF8 - U+0FFF : 0x11111111 */ + 1, /* U+1000 - U+1007 : 0x11111111 */ + 1, /* U+1008 - U+100F : 0x11111111 */ + 1, /* U+1010 - U+1017 : 0x11111111 */ + 1, /* U+1018 - U+101F : 0x11111111 */ + 1, /* U+1020 - U+1027 : 0x11111111 */ + 90, /* U+1028 - U+102F : 0xAAA11111 */ + 91, /* U+1030 - U+1037 : 0xAA111A1A */ + 64, /* U+1038 - U+103F : 0x111111A1 */ + 1, /* U+1040 - U+1047 : 0x11111111 */ + 1, /* U+1048 - U+104F : 0x11111111 */ + 1, /* U+1050 - U+1057 : 0x11111111 */ + 40, /* U+1058 - U+105F : 0x111111AA */ + 1, /* U+1060 - U+1067 : 0x11111111 */ + 1, /* U+1068 - U+106F : 0x11111111 */ + 1, /* U+1070 - U+1077 : 0x11111111 */ + 1, /* U+1078 - U+107F : 0x11111111 */ + 1, /* U+1080 - U+1087 : 0x11111111 */ + 1, /* U+1088 - U+108F : 0x11111111 */ + 1, /* U+1090 - U+1097 : 0x11111111 */ + 1, /* U+1098 - U+109F : 0x11111111 */ + 1, /* U+10A0 - U+10A7 : 0x11111111 */ + 1, /* U+10A8 - U+10AF : 0x11111111 */ + 1, /* U+10B0 - U+10B7 : 0x11111111 */ + 1, /* U+10B8 - U+10BF : 0x11111111 */ + 1, /* U+10C0 - U+10C7 : 0x11111111 */ + 1, /* U+10C8 - U+10CF : 0x11111111 */ + 1, /* U+10D0 - U+10D7 : 0x11111111 */ + 1, /* U+10D8 - U+10DF : 0x11111111 */ + 1, /* U+10E0 - U+10E7 : 0x11111111 */ + 1, /* U+10E8 - U+10EF : 0x11111111 */ + 1, /* U+10F0 - U+10F7 : 0x11111111 */ + 1, /* U+10F8 - U+10FF : 0x11111111 */ + 1, /* U+1100 - U+1107 : 0x11111111 */ + 1, /* U+1108 - U+110F : 0x11111111 */ + 1, /* U+1110 - U+1117 : 0x11111111 */ + 1, /* U+1118 - U+111F : 0x11111111 */ + 1, /* U+1120 - U+1127 : 0x11111111 */ + 1, /* U+1128 - U+112F : 0x11111111 */ + 1, /* U+1130 - U+1137 : 0x11111111 */ + 1, /* U+1138 - U+113F : 0x11111111 */ + 1, /* U+1140 - U+1147 : 0x11111111 */ + 1, /* U+1148 - U+114F : 0x11111111 */ + 1, /* U+1150 - U+1157 : 0x11111111 */ + 1, /* U+1158 - U+115F : 0x11111111 */ + 1, /* U+1160 - U+1167 : 0x11111111 */ + 1, /* U+1168 - U+116F : 0x11111111 */ + 1, /* U+1170 - U+1177 : 0x11111111 */ + 1, /* U+1178 - U+117F : 0x11111111 */ + 1, /* U+1180 - U+1187 : 0x11111111 */ + 1, /* U+1188 - U+118F : 0x11111111 */ + 1, /* U+1190 - U+1197 : 0x11111111 */ + 1, /* U+1198 - U+119F : 0x11111111 */ + 1, /* U+11A0 - U+11A7 : 0x11111111 */ + 1, /* U+11A8 - U+11AF : 0x11111111 */ + 1, /* U+11B0 - U+11B7 : 0x11111111 */ + 1, /* U+11B8 - U+11BF : 0x11111111 */ + 1, /* U+11C0 - U+11C7 : 0x11111111 */ + 1, /* U+11C8 - U+11CF : 0x11111111 */ + 1, /* U+11D0 - U+11D7 : 0x11111111 */ + 1, /* U+11D8 - U+11DF : 0x11111111 */ + 1, /* U+11E0 - U+11E7 : 0x11111111 */ + 1, /* U+11E8 - U+11EF : 0x11111111 */ + 1, /* U+11F0 - U+11F7 : 0x11111111 */ + 1, /* U+11F8 - U+11FF : 0x11111111 */ + 1, /* U+1200 - U+1207 : 0x11111111 */ + 1, /* U+1208 - U+120F : 0x11111111 */ + 1, /* U+1210 - U+1217 : 0x11111111 */ + 1, /* U+1218 - U+121F : 0x11111111 */ + 1, /* U+1220 - U+1227 : 0x11111111 */ + 1, /* U+1228 - U+122F : 0x11111111 */ + 1, /* U+1230 - U+1237 : 0x11111111 */ + 1, /* U+1238 - U+123F : 0x11111111 */ + 1, /* U+1240 - U+1247 : 0x11111111 */ + 1, /* U+1248 - U+124F : 0x11111111 */ + 1, /* U+1250 - U+1257 : 0x11111111 */ + 1, /* U+1258 - U+125F : 0x11111111 */ + 1, /* U+1260 - U+1267 : 0x11111111 */ + 1, /* U+1268 - U+126F : 0x11111111 */ + 1, /* U+1270 - U+1277 : 0x11111111 */ + 1, /* U+1278 - U+127F : 0x11111111 */ + 1, /* U+1280 - U+1287 : 0x11111111 */ + 1, /* U+1288 - U+128F : 0x11111111 */ + 1, /* U+1290 - U+1297 : 0x11111111 */ + 1, /* U+1298 - U+129F : 0x11111111 */ + 1, /* U+12A0 - U+12A7 : 0x11111111 */ + 1, /* U+12A8 - U+12AF : 0x11111111 */ + 1, /* U+12B0 - U+12B7 : 0x11111111 */ + 1, /* U+12B8 - U+12BF : 0x11111111 */ + 1, /* U+12C0 - U+12C7 : 0x11111111 */ + 1, /* U+12C8 - U+12CF : 0x11111111 */ + 1, /* U+12D0 - U+12D7 : 0x11111111 */ + 1, /* U+12D8 - U+12DF : 0x11111111 */ + 1, /* U+12E0 - U+12E7 : 0x11111111 */ + 1, /* U+12E8 - U+12EF : 0x11111111 */ + 1, /* U+12F0 - U+12F7 : 0x11111111 */ + 1, /* U+12F8 - U+12FF : 0x11111111 */ + 1, /* U+1300 - U+1307 : 0x11111111 */ + 1, /* U+1308 - U+130F : 0x11111111 */ + 1, /* U+1310 - U+1317 : 0x11111111 */ + 1, /* U+1318 - U+131F : 0x11111111 */ + 1, /* U+1320 - U+1327 : 0x11111111 */ + 1, /* U+1328 - U+132F : 0x11111111 */ + 1, /* U+1330 - U+1337 : 0x11111111 */ + 1, /* U+1338 - U+133F : 0x11111111 */ + 1, /* U+1340 - U+1347 : 0x11111111 */ + 1, /* U+1348 - U+134F : 0x11111111 */ + 1, /* U+1350 - U+1357 : 0x11111111 */ + 1, /* U+1358 - U+135F : 0x11111111 */ + 1, /* U+1360 - U+1367 : 0x11111111 */ + 1, /* U+1368 - U+136F : 0x11111111 */ + 1, /* U+1370 - U+1377 : 0x11111111 */ + 1, /* U+1378 - U+137F : 0x11111111 */ + 1, /* U+1380 - U+1387 : 0x11111111 */ + 1, /* U+1388 - U+138F : 0x11111111 */ + 1, /* U+1390 - U+1397 : 0x11111111 */ + 1, /* U+1398 - U+139F : 0x11111111 */ + 1, /* U+13A0 - U+13A7 : 0x11111111 */ + 1, /* U+13A8 - U+13AF : 0x11111111 */ + 1, /* U+13B0 - U+13B7 : 0x11111111 */ + 1, /* U+13B8 - U+13BF : 0x11111111 */ + 1, /* U+13C0 - U+13C7 : 0x11111111 */ + 1, /* U+13C8 - U+13CF : 0x11111111 */ + 1, /* U+13D0 - U+13D7 : 0x11111111 */ + 1, /* U+13D8 - U+13DF : 0x11111111 */ + 1, /* U+13E0 - U+13E7 : 0x11111111 */ + 1, /* U+13E8 - U+13EF : 0x11111111 */ + 1, /* U+13F0 - U+13F7 : 0x11111111 */ + 1, /* U+13F8 - U+13FF : 0x11111111 */ + 1, /* U+1400 - U+1407 : 0x11111111 */ + 1, /* U+1408 - U+140F : 0x11111111 */ + 1, /* U+1410 - U+1417 : 0x11111111 */ + 1, /* U+1418 - U+141F : 0x11111111 */ + 1, /* U+1420 - U+1427 : 0x11111111 */ + 1, /* U+1428 - U+142F : 0x11111111 */ + 1, /* U+1430 - U+1437 : 0x11111111 */ + 1, /* U+1438 - U+143F : 0x11111111 */ + 1, /* U+1440 - U+1447 : 0x11111111 */ + 1, /* U+1448 - U+144F : 0x11111111 */ + 1, /* U+1450 - U+1457 : 0x11111111 */ + 1, /* U+1458 - U+145F : 0x11111111 */ + 1, /* U+1460 - U+1467 : 0x11111111 */ + 1, /* U+1468 - U+146F : 0x11111111 */ + 1, /* U+1470 - U+1477 : 0x11111111 */ + 1, /* U+1478 - U+147F : 0x11111111 */ + 1, /* U+1480 - U+1487 : 0x11111111 */ + 1, /* U+1488 - U+148F : 0x11111111 */ + 1, /* U+1490 - U+1497 : 0x11111111 */ + 1, /* U+1498 - U+149F : 0x11111111 */ + 1, /* U+14A0 - U+14A7 : 0x11111111 */ + 1, /* U+14A8 - U+14AF : 0x11111111 */ + 1, /* U+14B0 - U+14B7 : 0x11111111 */ + 1, /* U+14B8 - U+14BF : 0x11111111 */ + 1, /* U+14C0 - U+14C7 : 0x11111111 */ + 1, /* U+14C8 - U+14CF : 0x11111111 */ + 1, /* U+14D0 - U+14D7 : 0x11111111 */ + 1, /* U+14D8 - U+14DF : 0x11111111 */ + 1, /* U+14E0 - U+14E7 : 0x11111111 */ + 1, /* U+14E8 - U+14EF : 0x11111111 */ + 1, /* U+14F0 - U+14F7 : 0x11111111 */ + 1, /* U+14F8 - U+14FF : 0x11111111 */ + 1, /* U+1500 - U+1507 : 0x11111111 */ + 1, /* U+1508 - U+150F : 0x11111111 */ + 1, /* U+1510 - U+1517 : 0x11111111 */ + 1, /* U+1518 - U+151F : 0x11111111 */ + 1, /* U+1520 - U+1527 : 0x11111111 */ + 1, /* U+1528 - U+152F : 0x11111111 */ + 1, /* U+1530 - U+1537 : 0x11111111 */ + 1, /* U+1538 - U+153F : 0x11111111 */ + 1, /* U+1540 - U+1547 : 0x11111111 */ + 1, /* U+1548 - U+154F : 0x11111111 */ + 1, /* U+1550 - U+1557 : 0x11111111 */ + 1, /* U+1558 - U+155F : 0x11111111 */ + 1, /* U+1560 - U+1567 : 0x11111111 */ + 1, /* U+1568 - U+156F : 0x11111111 */ + 1, /* U+1570 - U+1577 : 0x11111111 */ + 1, /* U+1578 - U+157F : 0x11111111 */ + 1, /* U+1580 - U+1587 : 0x11111111 */ + 1, /* U+1588 - U+158F : 0x11111111 */ + 1, /* U+1590 - U+1597 : 0x11111111 */ + 1, /* U+1598 - U+159F : 0x11111111 */ + 1, /* U+15A0 - U+15A7 : 0x11111111 */ + 1, /* U+15A8 - U+15AF : 0x11111111 */ + 1, /* U+15B0 - U+15B7 : 0x11111111 */ + 1, /* U+15B8 - U+15BF : 0x11111111 */ + 1, /* U+15C0 - U+15C7 : 0x11111111 */ + 1, /* U+15C8 - U+15CF : 0x11111111 */ + 1, /* U+15D0 - U+15D7 : 0x11111111 */ + 1, /* U+15D8 - U+15DF : 0x11111111 */ + 1, /* U+15E0 - U+15E7 : 0x11111111 */ + 1, /* U+15E8 - U+15EF : 0x11111111 */ + 1, /* U+15F0 - U+15F7 : 0x11111111 */ + 1, /* U+15F8 - U+15FF : 0x11111111 */ + 1, /* U+1600 - U+1607 : 0x11111111 */ + 1, /* U+1608 - U+160F : 0x11111111 */ + 1, /* U+1610 - U+1617 : 0x11111111 */ + 1, /* U+1618 - U+161F : 0x11111111 */ + 1, /* U+1620 - U+1627 : 0x11111111 */ + 1, /* U+1628 - U+162F : 0x11111111 */ + 1, /* U+1630 - U+1637 : 0x11111111 */ + 1, /* U+1638 - U+163F : 0x11111111 */ + 1, /* U+1640 - U+1647 : 0x11111111 */ + 1, /* U+1648 - U+164F : 0x11111111 */ + 1, /* U+1650 - U+1657 : 0x11111111 */ + 1, /* U+1658 - U+165F : 0x11111111 */ + 1, /* U+1660 - U+1667 : 0x11111111 */ + 1, /* U+1668 - U+166F : 0x11111111 */ + 1, /* U+1670 - U+1677 : 0x11111111 */ + 1, /* U+1678 - U+167F : 0x11111111 */ + 92, /* U+1680 - U+1687 : 0x1111111E */ + 1, /* U+1688 - U+168F : 0x11111111 */ + 1, /* U+1690 - U+1697 : 0x11111111 */ + 93, /* U+1698 - U+169F : 0x11199111 */ + 1, /* U+16A0 - U+16A7 : 0x11111111 */ + 1, /* U+16A8 - U+16AF : 0x11111111 */ + 1, /* U+16B0 - U+16B7 : 0x11111111 */ + 1, /* U+16B8 - U+16BF : 0x11111111 */ + 1, /* U+16C0 - U+16C7 : 0x11111111 */ + 1, /* U+16C8 - U+16CF : 0x11111111 */ + 1, /* U+16D0 - U+16D7 : 0x11111111 */ + 1, /* U+16D8 - U+16DF : 0x11111111 */ + 1, /* U+16E0 - U+16E7 : 0x11111111 */ + 1, /* U+16E8 - U+16EF : 0x11111111 */ + 1, /* U+16F0 - U+16F7 : 0x11111111 */ + 1, /* U+16F8 - U+16FF : 0x11111111 */ + 1, /* U+1700 - U+1707 : 0x11111111 */ + 1, /* U+1708 - U+170F : 0x11111111 */ + 1, /* U+1710 - U+1717 : 0x11111111 */ + 1, /* U+1718 - U+171F : 0x11111111 */ + 1, /* U+1720 - U+1727 : 0x11111111 */ + 1, /* U+1728 - U+172F : 0x11111111 */ + 1, /* U+1730 - U+1737 : 0x11111111 */ + 1, /* U+1738 - U+173F : 0x11111111 */ + 1, /* U+1740 - U+1747 : 0x11111111 */ + 1, /* U+1748 - U+174F : 0x11111111 */ + 1, /* U+1750 - U+1757 : 0x11111111 */ + 1, /* U+1758 - U+175F : 0x11111111 */ + 1, /* U+1760 - U+1767 : 0x11111111 */ + 1, /* U+1768 - U+176F : 0x11111111 */ + 1, /* U+1770 - U+1777 : 0x11111111 */ + 1, /* U+1778 - U+177F : 0x11111111 */ + 1, /* U+1780 - U+1787 : 0x11111111 */ + 1, /* U+1788 - U+178F : 0x11111111 */ + 1, /* U+1790 - U+1797 : 0x11111111 */ + 1, /* U+1798 - U+179F : 0x11111111 */ + 1, /* U+17A0 - U+17A7 : 0x11111111 */ + 1, /* U+17A8 - U+17AF : 0x11111111 */ + 79, /* U+17B0 - U+17B7 : 0xA1111111 */ + 85, /* U+17B8 - U+17BF : 0x11AAAAAA */ + 73, /* U+17C0 - U+17C7 : 0x1A111111 */ + 60, /* U+17C8 - U+17CF : 0xAAAAAAA1 */ + 94, /* U+17D0 - U+17D7 : 0x1111AAAA */ + 95, /* U+17D8 - U+17DF : 0x11117111 */ + 1, /* U+17E0 - U+17E7 : 0x11111111 */ + 1, /* U+17E8 - U+17EF : 0x11111111 */ + 1, /* U+17F0 - U+17F7 : 0x11111111 */ + 1, /* U+17F8 - U+17FF : 0x11111111 */ + 9, /* U+1800 - U+1807 : 0x99999999 */ + 96, /* U+1808 - U+180F : 0x1BBBB999 */ + 1, /* U+1810 - U+1817 : 0x11111111 */ + 1, /* U+1818 - U+181F : 0x11111111 */ + 1, /* U+1820 - U+1827 : 0x11111111 */ + 1, /* U+1828 - U+182F : 0x11111111 */ + 1, /* U+1830 - U+1837 : 0x11111111 */ + 1, /* U+1838 - U+183F : 0x11111111 */ + 1, /* U+1840 - U+1847 : 0x11111111 */ + 1, /* U+1848 - U+184F : 0x11111111 */ + 1, /* U+1850 - U+1857 : 0x11111111 */ + 1, /* U+1858 - U+185F : 0x11111111 */ + 1, /* U+1860 - U+1867 : 0x11111111 */ + 1, /* U+1868 - U+186F : 0x11111111 */ + 1, /* U+1870 - U+1877 : 0x11111111 */ + 1, /* U+1878 - U+187F : 0x11111111 */ + 1, /* U+1880 - U+1887 : 0x11111111 */ + 1, /* U+1888 - U+188F : 0x11111111 */ + 1, /* U+1890 - U+1897 : 0x11111111 */ + 1, /* U+1898 - U+189F : 0x11111111 */ + 1, /* U+18A0 - U+18A7 : 0x11111111 */ + 64, /* U+18A8 - U+18AF : 0x111111A1 */ + 1, /* U+18B0 - U+18B7 : 0x11111111 */ + 1, /* U+18B8 - U+18BF : 0x11111111 */ + 1, /* U+18C0 - U+18C7 : 0x11111111 */ + 1, /* U+18C8 - U+18CF : 0x11111111 */ + 1, /* U+18D0 - U+18D7 : 0x11111111 */ + 1, /* U+18D8 - U+18DF : 0x11111111 */ + 1, /* U+18E0 - U+18E7 : 0x11111111 */ + 1, /* U+18E8 - U+18EF : 0x11111111 */ + 1, /* U+18F0 - U+18F7 : 0x11111111 */ + 1, /* U+18F8 - U+18FF : 0x11111111 */ +}; + +static PRUint8 gBidiCatIdx3[352] = { + 1, /* U+1E00 - U+1E07 : 0x11111111 */ + 1, /* U+1E08 - U+1E0F : 0x11111111 */ + 1, /* U+1E10 - U+1E17 : 0x11111111 */ + 1, /* U+1E18 - U+1E1F : 0x11111111 */ + 1, /* U+1E20 - U+1E27 : 0x11111111 */ + 1, /* U+1E28 - U+1E2F : 0x11111111 */ + 1, /* U+1E30 - U+1E37 : 0x11111111 */ + 1, /* U+1E38 - U+1E3F : 0x11111111 */ + 1, /* U+1E40 - U+1E47 : 0x11111111 */ + 1, /* U+1E48 - U+1E4F : 0x11111111 */ + 1, /* U+1E50 - U+1E57 : 0x11111111 */ + 1, /* U+1E58 - U+1E5F : 0x11111111 */ + 1, /* U+1E60 - U+1E67 : 0x11111111 */ + 1, /* U+1E68 - U+1E6F : 0x11111111 */ + 1, /* U+1E70 - U+1E77 : 0x11111111 */ + 1, /* U+1E78 - U+1E7F : 0x11111111 */ + 1, /* U+1E80 - U+1E87 : 0x11111111 */ + 1, /* U+1E88 - U+1E8F : 0x11111111 */ + 1, /* U+1E90 - U+1E97 : 0x11111111 */ + 1, /* U+1E98 - U+1E9F : 0x11111111 */ + 1, /* U+1EA0 - U+1EA7 : 0x11111111 */ + 1, /* U+1EA8 - U+1EAF : 0x11111111 */ + 1, /* U+1EB0 - U+1EB7 : 0x11111111 */ + 1, /* U+1EB8 - U+1EBF : 0x11111111 */ + 1, /* U+1EC0 - U+1EC7 : 0x11111111 */ + 1, /* U+1EC8 - U+1ECF : 0x11111111 */ + 1, /* U+1ED0 - U+1ED7 : 0x11111111 */ + 1, /* U+1ED8 - U+1EDF : 0x11111111 */ + 1, /* U+1EE0 - U+1EE7 : 0x11111111 */ + 1, /* U+1EE8 - U+1EEF : 0x11111111 */ + 1, /* U+1EF0 - U+1EF7 : 0x11111111 */ + 1, /* U+1EF8 - U+1EFF : 0x11111111 */ + 1, /* U+1F00 - U+1F07 : 0x11111111 */ + 1, /* U+1F08 - U+1F0F : 0x11111111 */ + 1, /* U+1F10 - U+1F17 : 0x11111111 */ + 1, /* U+1F18 - U+1F1F : 0x11111111 */ + 1, /* U+1F20 - U+1F27 : 0x11111111 */ + 1, /* U+1F28 - U+1F2F : 0x11111111 */ + 1, /* U+1F30 - U+1F37 : 0x11111111 */ + 1, /* U+1F38 - U+1F3F : 0x11111111 */ + 1, /* U+1F40 - U+1F47 : 0x11111111 */ + 1, /* U+1F48 - U+1F4F : 0x11111111 */ + 1, /* U+1F50 - U+1F57 : 0x11111111 */ + 1, /* U+1F58 - U+1F5F : 0x11111111 */ + 1, /* U+1F60 - U+1F67 : 0x11111111 */ + 1, /* U+1F68 - U+1F6F : 0x11111111 */ + 1, /* U+1F70 - U+1F77 : 0x11111111 */ + 1, /* U+1F78 - U+1F7F : 0x11111111 */ + 1, /* U+1F80 - U+1F87 : 0x11111111 */ + 1, /* U+1F88 - U+1F8F : 0x11111111 */ + 1, /* U+1F90 - U+1F97 : 0x11111111 */ + 1, /* U+1F98 - U+1F9F : 0x11111111 */ + 1, /* U+1FA0 - U+1FA7 : 0x11111111 */ + 1, /* U+1FA8 - U+1FAF : 0x11111111 */ + 1, /* U+1FB0 - U+1FB7 : 0x11111111 */ + 97, /* U+1FB8 - U+1FBF : 0x91911111 */ + 98, /* U+1FC0 - U+1FC7 : 0x11111199 */ + 32, /* U+1FC8 - U+1FCF : 0x99911111 */ + 1, /* U+1FD0 - U+1FD7 : 0x11111111 */ + 32, /* U+1FD8 - U+1FDF : 0x99911111 */ + 1, /* U+1FE0 - U+1FE7 : 0x11111111 */ + 32, /* U+1FE8 - U+1FEF : 0x99911111 */ + 1, /* U+1FF0 - U+1FF7 : 0x11111111 */ + 99, /* U+1FF8 - U+1FFF : 0x19911111 */ + 14, /* U+2000 - U+2007 : 0xEEEEEEEE */ + 100, /* U+2008 - U+200F : 0x21BBBEEE */ + 9, /* U+2010 - U+2017 : 0x99999999 */ + 9, /* U+2018 - U+201F : 0x99999999 */ + 9, /* U+2020 - U+2027 : 0x99999999 */ + 101, /* U+2028 - U+202F : 0xEFFFFFCE */ + 102, /* U+2030 - U+2037 : 0x99977777 */ + 9, /* U+2038 - U+203F : 0x99999999 */ + 103, /* U+2040 - U+2047 : 0x19999999 */ + 33, /* U+2048 - U+204F : 0x11999999 */ + 1, /* U+2050 - U+2057 : 0x11111111 */ + 1, /* U+2058 - U+205F : 0x11111111 */ + 1, /* U+2060 - U+2067 : 0x11111111 */ + 104, /* U+2068 - U+206F : 0xBBBBBB11 */ + 105, /* U+2070 - U+2077 : 0x55551115 */ + 106, /* U+2078 - U+207F : 0x19997755 */ + 5, /* U+2080 - U+2087 : 0x55555555 */ + 106, /* U+2088 - U+208F : 0x19997755 */ + 1, /* U+2090 - U+2097 : 0x11111111 */ + 1, /* U+2098 - U+209F : 0x11111111 */ + 7, /* U+20A0 - U+20A7 : 0x77777777 */ + 7, /* U+20A8 - U+20AF : 0x77777777 */ + 1, /* U+20B0 - U+20B7 : 0x11111111 */ + 1, /* U+20B8 - U+20BF : 0x11111111 */ + 1, /* U+20C0 - U+20C7 : 0x11111111 */ + 1, /* U+20C8 - U+20CF : 0x11111111 */ + 10, /* U+20D0 - U+20D7 : 0xAAAAAAAA */ + 10, /* U+20D8 - U+20DF : 0xAAAAAAAA */ + 94, /* U+20E0 - U+20E7 : 0x1111AAAA */ + 1, /* U+20E8 - U+20EF : 0x11111111 */ + 1, /* U+20F0 - U+20F7 : 0x11111111 */ + 1, /* U+20F8 - U+20FF : 0x11111111 */ + 107, /* U+2100 - U+2107 : 0x19999199 */ + 98, /* U+2108 - U+210F : 0x11111199 */ + 108, /* U+2110 - U+2117 : 0x99191111 */ + 109, /* U+2118 - U+211F : 0x99111119 */ + 110, /* U+2120 - U+2127 : 0x91919999 */ + 111, /* U+2128 - U+212F : 0x17111191 */ + 41, /* U+2130 - U+2137 : 0x11111911 */ + 41, /* U+2138 - U+213F : 0x11111911 */ + 1, /* U+2140 - U+2147 : 0x11111111 */ + 1, /* U+2148 - U+214F : 0x11111111 */ + 22, /* U+2150 - U+2157 : 0x99999111 */ + 9, /* U+2158 - U+215F : 0x99999999 */ + 1, /* U+2160 - U+2167 : 0x11111111 */ + 1, /* U+2168 - U+216F : 0x11111111 */ + 1, /* U+2170 - U+2177 : 0x11111111 */ + 1, /* U+2178 - U+217F : 0x11111111 */ + 1, /* U+2180 - U+2187 : 0x11111111 */ + 1, /* U+2188 - U+218F : 0x11111111 */ + 9, /* U+2190 - U+2197 : 0x99999999 */ + 9, /* U+2198 - U+219F : 0x99999999 */ + 9, /* U+21A0 - U+21A7 : 0x99999999 */ + 9, /* U+21A8 - U+21AF : 0x99999999 */ + 9, /* U+21B0 - U+21B7 : 0x99999999 */ + 9, /* U+21B8 - U+21BF : 0x99999999 */ + 9, /* U+21C0 - U+21C7 : 0x99999999 */ + 9, /* U+21C8 - U+21CF : 0x99999999 */ + 9, /* U+21D0 - U+21D7 : 0x99999999 */ + 9, /* U+21D8 - U+21DF : 0x99999999 */ + 9, /* U+21E0 - U+21E7 : 0x99999999 */ + 9, /* U+21E8 - U+21EF : 0x99999999 */ + 112, /* U+21F0 - U+21F7 : 0x11119999 */ + 1, /* U+21F8 - U+21FF : 0x11111111 */ + 9, /* U+2200 - U+2207 : 0x99999999 */ + 9, /* U+2208 - U+220F : 0x99999999 */ + 113, /* U+2210 - U+2217 : 0x99997799 */ + 9, /* U+2218 - U+221F : 0x99999999 */ + 9, /* U+2220 - U+2227 : 0x99999999 */ + 9, /* U+2228 - U+222F : 0x99999999 */ + 9, /* U+2230 - U+2237 : 0x99999999 */ + 9, /* U+2238 - U+223F : 0x99999999 */ + 9, /* U+2240 - U+2247 : 0x99999999 */ + 9, /* U+2248 - U+224F : 0x99999999 */ + 9, /* U+2250 - U+2257 : 0x99999999 */ + 9, /* U+2258 - U+225F : 0x99999999 */ + 9, /* U+2260 - U+2267 : 0x99999999 */ + 9, /* U+2268 - U+226F : 0x99999999 */ + 9, /* U+2270 - U+2277 : 0x99999999 */ + 9, /* U+2278 - U+227F : 0x99999999 */ + 9, /* U+2280 - U+2287 : 0x99999999 */ + 9, /* U+2288 - U+228F : 0x99999999 */ + 9, /* U+2290 - U+2297 : 0x99999999 */ + 9, /* U+2298 - U+229F : 0x99999999 */ + 9, /* U+22A0 - U+22A7 : 0x99999999 */ + 9, /* U+22A8 - U+22AF : 0x99999999 */ + 9, /* U+22B0 - U+22B7 : 0x99999999 */ + 9, /* U+22B8 - U+22BF : 0x99999999 */ + 9, /* U+22C0 - U+22C7 : 0x99999999 */ + 9, /* U+22C8 - U+22CF : 0x99999999 */ + 9, /* U+22D0 - U+22D7 : 0x99999999 */ + 9, /* U+22D8 - U+22DF : 0x99999999 */ + 9, /* U+22E0 - U+22E7 : 0x99999999 */ + 9, /* U+22E8 - U+22EF : 0x99999999 */ + 98, /* U+22F0 - U+22F7 : 0x11111199 */ + 1, /* U+22F8 - U+22FF : 0x11111111 */ + 9, /* U+2300 - U+2307 : 0x99999999 */ + 9, /* U+2308 - U+230F : 0x99999999 */ + 9, /* U+2310 - U+2317 : 0x99999999 */ + 9, /* U+2318 - U+231F : 0x99999999 */ + 9, /* U+2320 - U+2327 : 0x99999999 */ + 9, /* U+2328 - U+232F : 0x99999999 */ + 33, /* U+2330 - U+2337 : 0x11999999 */ + 1, /* U+2338 - U+233F : 0x11111111 */ + 1, /* U+2340 - U+2347 : 0x11111111 */ + 1, /* U+2348 - U+234F : 0x11111111 */ + 1, /* U+2350 - U+2357 : 0x11111111 */ + 1, /* U+2358 - U+235F : 0x11111111 */ + 1, /* U+2360 - U+2367 : 0x11111111 */ + 1, /* U+2368 - U+236F : 0x11111111 */ + 1, /* U+2370 - U+2377 : 0x11111111 */ + 114, /* U+2378 - U+237F : 0x99919111 */ + 9, /* U+2380 - U+2387 : 0x99999999 */ + 9, /* U+2388 - U+238F : 0x99999999 */ + 115, /* U+2390 - U+2397 : 0x99199999 */ + 116, /* U+2398 - U+239F : 0x11111999 */ + 1, /* U+23A0 - U+23A7 : 0x11111111 */ + 1, /* U+23A8 - U+23AF : 0x11111111 */ + 1, /* U+23B0 - U+23B7 : 0x11111111 */ + 1, /* U+23B8 - U+23BF : 0x11111111 */ + 1, /* U+23C0 - U+23C7 : 0x11111111 */ + 1, /* U+23C8 - U+23CF : 0x11111111 */ + 1, /* U+23D0 - U+23D7 : 0x11111111 */ + 1, /* U+23D8 - U+23DF : 0x11111111 */ + 1, /* U+23E0 - U+23E7 : 0x11111111 */ + 1, /* U+23E8 - U+23EF : 0x11111111 */ + 1, /* U+23F0 - U+23F7 : 0x11111111 */ + 1, /* U+23F8 - U+23FF : 0x11111111 */ + 9, /* U+2400 - U+2407 : 0x99999999 */ + 9, /* U+2408 - U+240F : 0x99999999 */ + 9, /* U+2410 - U+2417 : 0x99999999 */ + 9, /* U+2418 - U+241F : 0x99999999 */ + 103, /* U+2420 - U+2427 : 0x19999999 */ + 1, /* U+2428 - U+242F : 0x11111111 */ + 1, /* U+2430 - U+2437 : 0x11111111 */ + 1, /* U+2438 - U+243F : 0x11111111 */ + 9, /* U+2440 - U+2447 : 0x99999999 */ + 116, /* U+2448 - U+244F : 0x11111999 */ + 1, /* U+2450 - U+2457 : 0x11111111 */ + 1, /* U+2458 - U+245F : 0x11111111 */ + 5, /* U+2460 - U+2467 : 0x55555555 */ + 5, /* U+2468 - U+246F : 0x55555555 */ + 5, /* U+2470 - U+2477 : 0x55555555 */ + 5, /* U+2478 - U+247F : 0x55555555 */ + 5, /* U+2480 - U+2487 : 0x55555555 */ + 5, /* U+2488 - U+248F : 0x55555555 */ + 5, /* U+2490 - U+2497 : 0x55555555 */ + 117, /* U+2498 - U+249F : 0x11115555 */ + 1, /* U+24A0 - U+24A7 : 0x11111111 */ + 1, /* U+24A8 - U+24AF : 0x11111111 */ + 1, /* U+24B0 - U+24B7 : 0x11111111 */ + 1, /* U+24B8 - U+24BF : 0x11111111 */ + 1, /* U+24C0 - U+24C7 : 0x11111111 */ + 1, /* U+24C8 - U+24CF : 0x11111111 */ + 1, /* U+24D0 - U+24D7 : 0x11111111 */ + 1, /* U+24D8 - U+24DF : 0x11111111 */ + 1, /* U+24E0 - U+24E7 : 0x11111111 */ + 118, /* U+24E8 - U+24EF : 0x11111511 */ + 1, /* U+24F0 - U+24F7 : 0x11111111 */ + 1, /* U+24F8 - U+24FF : 0x11111111 */ + 9, /* U+2500 - U+2507 : 0x99999999 */ + 9, /* U+2508 - U+250F : 0x99999999 */ + 9, /* U+2510 - U+2517 : 0x99999999 */ + 9, /* U+2518 - U+251F : 0x99999999 */ + 9, /* U+2520 - U+2527 : 0x99999999 */ + 9, /* U+2528 - U+252F : 0x99999999 */ + 9, /* U+2530 - U+2537 : 0x99999999 */ + 9, /* U+2538 - U+253F : 0x99999999 */ + 9, /* U+2540 - U+2547 : 0x99999999 */ + 9, /* U+2548 - U+254F : 0x99999999 */ + 9, /* U+2550 - U+2557 : 0x99999999 */ + 9, /* U+2558 - U+255F : 0x99999999 */ + 9, /* U+2560 - U+2567 : 0x99999999 */ + 9, /* U+2568 - U+256F : 0x99999999 */ + 9, /* U+2570 - U+2577 : 0x99999999 */ + 9, /* U+2578 - U+257F : 0x99999999 */ + 9, /* U+2580 - U+2587 : 0x99999999 */ + 9, /* U+2588 - U+258F : 0x99999999 */ + 33, /* U+2590 - U+2597 : 0x11999999 */ + 1, /* U+2598 - U+259F : 0x11111111 */ + 9, /* U+25A0 - U+25A7 : 0x99999999 */ + 9, /* U+25A8 - U+25AF : 0x99999999 */ + 9, /* U+25B0 - U+25B7 : 0x99999999 */ + 9, /* U+25B8 - U+25BF : 0x99999999 */ + 9, /* U+25C0 - U+25C7 : 0x99999999 */ + 9, /* U+25C8 - U+25CF : 0x99999999 */ + 9, /* U+25D0 - U+25D7 : 0x99999999 */ + 9, /* U+25D8 - U+25DF : 0x99999999 */ + 9, /* U+25E0 - U+25E7 : 0x99999999 */ + 9, /* U+25E8 - U+25EF : 0x99999999 */ + 9, /* U+25F0 - U+25F7 : 0x99999999 */ + 1, /* U+25F8 - U+25FF : 0x11111111 */ + 9, /* U+2600 - U+2607 : 0x99999999 */ + 9, /* U+2608 - U+260F : 0x99999999 */ + 112, /* U+2610 - U+2617 : 0x11119999 */ + 119, /* U+2618 - U+261F : 0x99999991 */ + 9, /* U+2620 - U+2627 : 0x99999999 */ + 9, /* U+2628 - U+262F : 0x99999999 */ + 9, /* U+2630 - U+2637 : 0x99999999 */ + 9, /* U+2638 - U+263F : 0x99999999 */ + 9, /* U+2640 - U+2647 : 0x99999999 */ + 9, /* U+2648 - U+264F : 0x99999999 */ + 9, /* U+2650 - U+2657 : 0x99999999 */ + 9, /* U+2658 - U+265F : 0x99999999 */ + 9, /* U+2660 - U+2667 : 0x99999999 */ + 9, /* U+2668 - U+266F : 0x99999999 */ + 98, /* U+2670 - U+2677 : 0x11111199 */ + 1, /* U+2678 - U+267F : 0x11111111 */ + 1, /* U+2680 - U+2687 : 0x11111111 */ + 1, /* U+2688 - U+268F : 0x11111111 */ + 1, /* U+2690 - U+2697 : 0x11111111 */ + 1, /* U+2698 - U+269F : 0x11111111 */ + 1, /* U+26A0 - U+26A7 : 0x11111111 */ + 1, /* U+26A8 - U+26AF : 0x11111111 */ + 1, /* U+26B0 - U+26B7 : 0x11111111 */ + 1, /* U+26B8 - U+26BF : 0x11111111 */ + 1, /* U+26C0 - U+26C7 : 0x11111111 */ + 1, /* U+26C8 - U+26CF : 0x11111111 */ + 1, /* U+26D0 - U+26D7 : 0x11111111 */ + 1, /* U+26D8 - U+26DF : 0x11111111 */ + 1, /* U+26E0 - U+26E7 : 0x11111111 */ + 1, /* U+26E8 - U+26EF : 0x11111111 */ + 1, /* U+26F0 - U+26F7 : 0x11111111 */ + 1, /* U+26F8 - U+26FF : 0x11111111 */ + 120, /* U+2700 - U+2707 : 0x99199991 */ + 121, /* U+2708 - U+270F : 0x99991199 */ + 9, /* U+2710 - U+2717 : 0x99999999 */ + 9, /* U+2718 - U+271F : 0x99999999 */ + 9, /* U+2720 - U+2727 : 0x99999999 */ + 119, /* U+2728 - U+272F : 0x99999991 */ + 9, /* U+2730 - U+2737 : 0x99999999 */ + 9, /* U+2738 - U+273F : 0x99999999 */ + 9, /* U+2740 - U+2747 : 0x99999999 */ + 110, /* U+2748 - U+274F : 0x91919999 */ + 122, /* U+2750 - U+2757 : 0x19111999 */ + 103, /* U+2758 - U+275F : 0x19999999 */ + 119, /* U+2760 - U+2767 : 0x99999991 */ + 1, /* U+2768 - U+276F : 0x11111111 */ + 123, /* U+2770 - U+2777 : 0x99111111 */ + 9, /* U+2778 - U+277F : 0x99999999 */ + 9, /* U+2780 - U+2787 : 0x99999999 */ + 9, /* U+2788 - U+278F : 0x99999999 */ + 124, /* U+2790 - U+2797 : 0x11199999 */ + 9, /* U+2798 - U+279F : 0x99999999 */ + 9, /* U+27A0 - U+27A7 : 0x99999999 */ + 9, /* U+27A8 - U+27AF : 0x99999999 */ + 119, /* U+27B0 - U+27B7 : 0x99999991 */ + 103, /* U+27B8 - U+27BF : 0x19999999 */ + 1, /* U+27C0 - U+27C7 : 0x11111111 */ + 1, /* U+27C8 - U+27CF : 0x11111111 */ + 1, /* U+27D0 - U+27D7 : 0x11111111 */ + 1, /* U+27D8 - U+27DF : 0x11111111 */ + 1, /* U+27E0 - U+27E7 : 0x11111111 */ + 1, /* U+27E8 - U+27EF : 0x11111111 */ + 1, /* U+27F0 - U+27F7 : 0x11111111 */ + 1, /* U+27F8 - U+27FF : 0x11111111 */ + 9, /* U+2800 - U+2807 : 0x99999999 */ + 9, /* U+2808 - U+280F : 0x99999999 */ + 9, /* U+2810 - U+2817 : 0x99999999 */ + 9, /* U+2818 - U+281F : 0x99999999 */ + 9, /* U+2820 - U+2827 : 0x99999999 */ + 9, /* U+2828 - U+282F : 0x99999999 */ + 9, /* U+2830 - U+2837 : 0x99999999 */ + 9, /* U+2838 - U+283F : 0x99999999 */ + 9, /* U+2840 - U+2847 : 0x99999999 */ + 9, /* U+2848 - U+284F : 0x99999999 */ + 9, /* U+2850 - U+2857 : 0x99999999 */ + 9, /* U+2858 - U+285F : 0x99999999 */ + 9, /* U+2860 - U+2867 : 0x99999999 */ + 9, /* U+2868 - U+286F : 0x99999999 */ + 9, /* U+2870 - U+2877 : 0x99999999 */ + 9, /* U+2878 - U+287F : 0x99999999 */ + 9, /* U+2880 - U+2887 : 0x99999999 */ + 9, /* U+2888 - U+288F : 0x99999999 */ + 9, /* U+2890 - U+2897 : 0x99999999 */ + 9, /* U+2898 - U+289F : 0x99999999 */ + 9, /* U+28A0 - U+28A7 : 0x99999999 */ + 9, /* U+28A8 - U+28AF : 0x99999999 */ + 9, /* U+28B0 - U+28B7 : 0x99999999 */ + 9, /* U+28B8 - U+28BF : 0x99999999 */ + 9, /* U+28C0 - U+28C7 : 0x99999999 */ + 9, /* U+28C8 - U+28CF : 0x99999999 */ + 9, /* U+28D0 - U+28D7 : 0x99999999 */ + 9, /* U+28D8 - U+28DF : 0x99999999 */ + 9, /* U+28E0 - U+28E7 : 0x99999999 */ + 9, /* U+28E8 - U+28EF : 0x99999999 */ + 9, /* U+28F0 - U+28F7 : 0x99999999 */ + 9, /* U+28F8 - U+28FF : 0x99999999 */ +}; + +static PRUint8 gBidiCatIdx4[176] = { + 9, /* U+2E80 - U+2E87 : 0x99999999 */ + 9, /* U+2E88 - U+2E8F : 0x99999999 */ + 9, /* U+2E90 - U+2E97 : 0x99999999 */ + 26, /* U+2E98 - U+2E9F : 0x99999199 */ + 9, /* U+2EA0 - U+2EA7 : 0x99999999 */ + 9, /* U+2EA8 - U+2EAF : 0x99999999 */ + 9, /* U+2EB0 - U+2EB7 : 0x99999999 */ + 9, /* U+2EB8 - U+2EBF : 0x99999999 */ + 9, /* U+2EC0 - U+2EC7 : 0x99999999 */ + 9, /* U+2EC8 - U+2ECF : 0x99999999 */ + 9, /* U+2ED0 - U+2ED7 : 0x99999999 */ + 9, /* U+2ED8 - U+2EDF : 0x99999999 */ + 9, /* U+2EE0 - U+2EE7 : 0x99999999 */ + 9, /* U+2EE8 - U+2EEF : 0x99999999 */ + 112, /* U+2EF0 - U+2EF7 : 0x11119999 */ + 1, /* U+2EF8 - U+2EFF : 0x11111111 */ + 9, /* U+2F00 - U+2F07 : 0x99999999 */ + 9, /* U+2F08 - U+2F0F : 0x99999999 */ + 9, /* U+2F10 - U+2F17 : 0x99999999 */ + 9, /* U+2F18 - U+2F1F : 0x99999999 */ + 9, /* U+2F20 - U+2F27 : 0x99999999 */ + 9, /* U+2F28 - U+2F2F : 0x99999999 */ + 9, /* U+2F30 - U+2F37 : 0x99999999 */ + 9, /* U+2F38 - U+2F3F : 0x99999999 */ + 9, /* U+2F40 - U+2F47 : 0x99999999 */ + 9, /* U+2F48 - U+2F4F : 0x99999999 */ + 9, /* U+2F50 - U+2F57 : 0x99999999 */ + 9, /* U+2F58 - U+2F5F : 0x99999999 */ + 9, /* U+2F60 - U+2F67 : 0x99999999 */ + 9, /* U+2F68 - U+2F6F : 0x99999999 */ + 9, /* U+2F70 - U+2F77 : 0x99999999 */ + 9, /* U+2F78 - U+2F7F : 0x99999999 */ + 9, /* U+2F80 - U+2F87 : 0x99999999 */ + 9, /* U+2F88 - U+2F8F : 0x99999999 */ + 9, /* U+2F90 - U+2F97 : 0x99999999 */ + 9, /* U+2F98 - U+2F9F : 0x99999999 */ + 9, /* U+2FA0 - U+2FA7 : 0x99999999 */ + 9, /* U+2FA8 - U+2FAF : 0x99999999 */ + 9, /* U+2FB0 - U+2FB7 : 0x99999999 */ + 9, /* U+2FB8 - U+2FBF : 0x99999999 */ + 9, /* U+2FC0 - U+2FC7 : 0x99999999 */ + 9, /* U+2FC8 - U+2FCF : 0x99999999 */ + 33, /* U+2FD0 - U+2FD7 : 0x11999999 */ + 1, /* U+2FD8 - U+2FDF : 0x11111111 */ + 1, /* U+2FE0 - U+2FE7 : 0x11111111 */ + 1, /* U+2FE8 - U+2FEF : 0x11111111 */ + 9, /* U+2FF0 - U+2FF7 : 0x99999999 */ + 112, /* U+2FF8 - U+2FFF : 0x11119999 */ + 125, /* U+3000 - U+3007 : 0x1119999E */ + 9, /* U+3008 - U+300F : 0x99999999 */ + 9, /* U+3010 - U+3017 : 0x99999999 */ + 9, /* U+3018 - U+301F : 0x99999999 */ + 21, /* U+3020 - U+3027 : 0x11111119 */ + 126, /* U+3028 - U+302F : 0xAAAAAA11 */ + 109, /* U+3030 - U+3037 : 0x99111119 */ + 123, /* U+3038 - U+303F : 0x99111111 */ + 1, /* U+3040 - U+3047 : 0x11111111 */ + 1, /* U+3048 - U+304F : 0x11111111 */ + 1, /* U+3050 - U+3057 : 0x11111111 */ + 1, /* U+3058 - U+305F : 0x11111111 */ + 1, /* U+3060 - U+3067 : 0x11111111 */ + 1, /* U+3068 - U+306F : 0x11111111 */ + 1, /* U+3070 - U+3077 : 0x11111111 */ + 1, /* U+3078 - U+307F : 0x11111111 */ + 1, /* U+3080 - U+3087 : 0x11111111 */ + 1, /* U+3088 - U+308F : 0x11111111 */ + 1, /* U+3090 - U+3097 : 0x11111111 */ + 127, /* U+3098 - U+309F : 0x11199AA1 */ + 1, /* U+30A0 - U+30A7 : 0x11111111 */ + 1, /* U+30A8 - U+30AF : 0x11111111 */ + 1, /* U+30B0 - U+30B7 : 0x11111111 */ + 1, /* U+30B8 - U+30BF : 0x11111111 */ + 1, /* U+30C0 - U+30C7 : 0x11111111 */ + 1, /* U+30C8 - U+30CF : 0x11111111 */ + 1, /* U+30D0 - U+30D7 : 0x11111111 */ + 1, /* U+30D8 - U+30DF : 0x11111111 */ + 1, /* U+30E0 - U+30E7 : 0x11111111 */ + 1, /* U+30E8 - U+30EF : 0x11111111 */ + 1, /* U+30F0 - U+30F7 : 0x11111111 */ + 128, /* U+30F8 - U+30FF : 0x11119111 */ + 1, /* U+3100 - U+3107 : 0x11111111 */ + 1, /* U+3108 - U+310F : 0x11111111 */ + 1, /* U+3110 - U+3117 : 0x11111111 */ + 1, /* U+3118 - U+311F : 0x11111111 */ + 1, /* U+3120 - U+3127 : 0x11111111 */ + 1, /* U+3128 - U+312F : 0x11111111 */ + 1, /* U+3130 - U+3137 : 0x11111111 */ + 1, /* U+3138 - U+313F : 0x11111111 */ + 1, /* U+3140 - U+3147 : 0x11111111 */ + 1, /* U+3148 - U+314F : 0x11111111 */ + 1, /* U+3150 - U+3157 : 0x11111111 */ + 1, /* U+3158 - U+315F : 0x11111111 */ + 1, /* U+3160 - U+3167 : 0x11111111 */ + 1, /* U+3168 - U+316F : 0x11111111 */ + 1, /* U+3170 - U+3177 : 0x11111111 */ + 1, /* U+3178 - U+317F : 0x11111111 */ + 1, /* U+3180 - U+3187 : 0x11111111 */ + 1, /* U+3188 - U+318F : 0x11111111 */ + 1, /* U+3190 - U+3197 : 0x11111111 */ + 1, /* U+3198 - U+319F : 0x11111111 */ + 1, /* U+31A0 - U+31A7 : 0x11111111 */ + 1, /* U+31A8 - U+31AF : 0x11111111 */ + 1, /* U+31B0 - U+31B7 : 0x11111111 */ + 1, /* U+31B8 - U+31BF : 0x11111111 */ + 1, /* U+31C0 - U+31C7 : 0x11111111 */ + 1, /* U+31C8 - U+31CF : 0x11111111 */ + 1, /* U+31D0 - U+31D7 : 0x11111111 */ + 1, /* U+31D8 - U+31DF : 0x11111111 */ + 1, /* U+31E0 - U+31E7 : 0x11111111 */ + 1, /* U+31E8 - U+31EF : 0x11111111 */ + 1, /* U+31F0 - U+31F7 : 0x11111111 */ + 1, /* U+31F8 - U+31FF : 0x11111111 */ + 1, /* U+3200 - U+3207 : 0x11111111 */ + 1, /* U+3208 - U+320F : 0x11111111 */ + 1, /* U+3210 - U+3217 : 0x11111111 */ + 1, /* U+3218 - U+321F : 0x11111111 */ + 1, /* U+3220 - U+3227 : 0x11111111 */ + 1, /* U+3228 - U+322F : 0x11111111 */ + 1, /* U+3230 - U+3237 : 0x11111111 */ + 1, /* U+3238 - U+323F : 0x11111111 */ + 1, /* U+3240 - U+3247 : 0x11111111 */ + 1, /* U+3248 - U+324F : 0x11111111 */ + 1, /* U+3250 - U+3257 : 0x11111111 */ + 1, /* U+3258 - U+325F : 0x11111111 */ + 1, /* U+3260 - U+3267 : 0x11111111 */ + 1, /* U+3268 - U+326F : 0x11111111 */ + 1, /* U+3270 - U+3277 : 0x11111111 */ + 1, /* U+3278 - U+327F : 0x11111111 */ + 1, /* U+3280 - U+3287 : 0x11111111 */ + 1, /* U+3288 - U+328F : 0x11111111 */ + 1, /* U+3290 - U+3297 : 0x11111111 */ + 1, /* U+3298 - U+329F : 0x11111111 */ + 1, /* U+32A0 - U+32A7 : 0x11111111 */ + 1, /* U+32A8 - U+32AF : 0x11111111 */ + 1, /* U+32B0 - U+32B7 : 0x11111111 */ + 1, /* U+32B8 - U+32BF : 0x11111111 */ + 1, /* U+32C0 - U+32C7 : 0x11111111 */ + 1, /* U+32C8 - U+32CF : 0x11111111 */ + 1, /* U+32D0 - U+32D7 : 0x11111111 */ + 1, /* U+32D8 - U+32DF : 0x11111111 */ + 1, /* U+32E0 - U+32E7 : 0x11111111 */ + 1, /* U+32E8 - U+32EF : 0x11111111 */ + 1, /* U+32F0 - U+32F7 : 0x11111111 */ + 1, /* U+32F8 - U+32FF : 0x11111111 */ + 1, /* U+3300 - U+3307 : 0x11111111 */ + 1, /* U+3308 - U+330F : 0x11111111 */ + 1, /* U+3310 - U+3317 : 0x11111111 */ + 1, /* U+3318 - U+331F : 0x11111111 */ + 1, /* U+3320 - U+3327 : 0x11111111 */ + 1, /* U+3328 - U+332F : 0x11111111 */ + 1, /* U+3330 - U+3337 : 0x11111111 */ + 1, /* U+3338 - U+333F : 0x11111111 */ + 1, /* U+3340 - U+3347 : 0x11111111 */ + 1, /* U+3348 - U+334F : 0x11111111 */ + 1, /* U+3350 - U+3357 : 0x11111111 */ + 1, /* U+3358 - U+335F : 0x11111111 */ + 1, /* U+3360 - U+3367 : 0x11111111 */ + 1, /* U+3368 - U+336F : 0x11111111 */ + 1, /* U+3370 - U+3377 : 0x11111111 */ + 1, /* U+3378 - U+337F : 0x11111111 */ + 1, /* U+3380 - U+3387 : 0x11111111 */ + 1, /* U+3388 - U+338F : 0x11111111 */ + 1, /* U+3390 - U+3397 : 0x11111111 */ + 1, /* U+3398 - U+339F : 0x11111111 */ + 1, /* U+33A0 - U+33A7 : 0x11111111 */ + 1, /* U+33A8 - U+33AF : 0x11111111 */ + 1, /* U+33B0 - U+33B7 : 0x11111111 */ + 1, /* U+33B8 - U+33BF : 0x11111111 */ + 1, /* U+33C0 - U+33C7 : 0x11111111 */ + 1, /* U+33C8 - U+33CF : 0x11111111 */ + 1, /* U+33D0 - U+33D7 : 0x11111111 */ + 1, /* U+33D8 - U+33DF : 0x11111111 */ + 1, /* U+33E0 - U+33E7 : 0x11111111 */ + 1, /* U+33E8 - U+33EF : 0x11111111 */ + 1, /* U+33F0 - U+33F7 : 0x11111111 */ + 1, /* U+33F8 - U+33FF : 0x11111111 */ +}; + +static PRUint8 gBidiCatIdx5[160] = { + 1, /* U+A000 - U+A007 : 0x11111111 */ + 1, /* U+A008 - U+A00F : 0x11111111 */ + 1, /* U+A010 - U+A017 : 0x11111111 */ + 1, /* U+A018 - U+A01F : 0x11111111 */ + 1, /* U+A020 - U+A027 : 0x11111111 */ + 1, /* U+A028 - U+A02F : 0x11111111 */ + 1, /* U+A030 - U+A037 : 0x11111111 */ + 1, /* U+A038 - U+A03F : 0x11111111 */ + 1, /* U+A040 - U+A047 : 0x11111111 */ + 1, /* U+A048 - U+A04F : 0x11111111 */ + 1, /* U+A050 - U+A057 : 0x11111111 */ + 1, /* U+A058 - U+A05F : 0x11111111 */ + 1, /* U+A060 - U+A067 : 0x11111111 */ + 1, /* U+A068 - U+A06F : 0x11111111 */ + 1, /* U+A070 - U+A077 : 0x11111111 */ + 1, /* U+A078 - U+A07F : 0x11111111 */ + 1, /* U+A080 - U+A087 : 0x11111111 */ + 1, /* U+A088 - U+A08F : 0x11111111 */ + 1, /* U+A090 - U+A097 : 0x11111111 */ + 1, /* U+A098 - U+A09F : 0x11111111 */ + 1, /* U+A0A0 - U+A0A7 : 0x11111111 */ + 1, /* U+A0A8 - U+A0AF : 0x11111111 */ + 1, /* U+A0B0 - U+A0B7 : 0x11111111 */ + 1, /* U+A0B8 - U+A0BF : 0x11111111 */ + 1, /* U+A0C0 - U+A0C7 : 0x11111111 */ + 1, /* U+A0C8 - U+A0CF : 0x11111111 */ + 1, /* U+A0D0 - U+A0D7 : 0x11111111 */ + 1, /* U+A0D8 - U+A0DF : 0x11111111 */ + 1, /* U+A0E0 - U+A0E7 : 0x11111111 */ + 1, /* U+A0E8 - U+A0EF : 0x11111111 */ + 1, /* U+A0F0 - U+A0F7 : 0x11111111 */ + 1, /* U+A0F8 - U+A0FF : 0x11111111 */ + 1, /* U+A100 - U+A107 : 0x11111111 */ + 1, /* U+A108 - U+A10F : 0x11111111 */ + 1, /* U+A110 - U+A117 : 0x11111111 */ + 1, /* U+A118 - U+A11F : 0x11111111 */ + 1, /* U+A120 - U+A127 : 0x11111111 */ + 1, /* U+A128 - U+A12F : 0x11111111 */ + 1, /* U+A130 - U+A137 : 0x11111111 */ + 1, /* U+A138 - U+A13F : 0x11111111 */ + 1, /* U+A140 - U+A147 : 0x11111111 */ + 1, /* U+A148 - U+A14F : 0x11111111 */ + 1, /* U+A150 - U+A157 : 0x11111111 */ + 1, /* U+A158 - U+A15F : 0x11111111 */ + 1, /* U+A160 - U+A167 : 0x11111111 */ + 1, /* U+A168 - U+A16F : 0x11111111 */ + 1, /* U+A170 - U+A177 : 0x11111111 */ + 1, /* U+A178 - U+A17F : 0x11111111 */ + 1, /* U+A180 - U+A187 : 0x11111111 */ + 1, /* U+A188 - U+A18F : 0x11111111 */ + 1, /* U+A190 - U+A197 : 0x11111111 */ + 1, /* U+A198 - U+A19F : 0x11111111 */ + 1, /* U+A1A0 - U+A1A7 : 0x11111111 */ + 1, /* U+A1A8 - U+A1AF : 0x11111111 */ + 1, /* U+A1B0 - U+A1B7 : 0x11111111 */ + 1, /* U+A1B8 - U+A1BF : 0x11111111 */ + 1, /* U+A1C0 - U+A1C7 : 0x11111111 */ + 1, /* U+A1C8 - U+A1CF : 0x11111111 */ + 1, /* U+A1D0 - U+A1D7 : 0x11111111 */ + 1, /* U+A1D8 - U+A1DF : 0x11111111 */ + 1, /* U+A1E0 - U+A1E7 : 0x11111111 */ + 1, /* U+A1E8 - U+A1EF : 0x11111111 */ + 1, /* U+A1F0 - U+A1F7 : 0x11111111 */ + 1, /* U+A1F8 - U+A1FF : 0x11111111 */ + 1, /* U+A200 - U+A207 : 0x11111111 */ + 1, /* U+A208 - U+A20F : 0x11111111 */ + 1, /* U+A210 - U+A217 : 0x11111111 */ + 1, /* U+A218 - U+A21F : 0x11111111 */ + 1, /* U+A220 - U+A227 : 0x11111111 */ + 1, /* U+A228 - U+A22F : 0x11111111 */ + 1, /* U+A230 - U+A237 : 0x11111111 */ + 1, /* U+A238 - U+A23F : 0x11111111 */ + 1, /* U+A240 - U+A247 : 0x11111111 */ + 1, /* U+A248 - U+A24F : 0x11111111 */ + 1, /* U+A250 - U+A257 : 0x11111111 */ + 1, /* U+A258 - U+A25F : 0x11111111 */ + 1, /* U+A260 - U+A267 : 0x11111111 */ + 1, /* U+A268 - U+A26F : 0x11111111 */ + 1, /* U+A270 - U+A277 : 0x11111111 */ + 1, /* U+A278 - U+A27F : 0x11111111 */ + 1, /* U+A280 - U+A287 : 0x11111111 */ + 1, /* U+A288 - U+A28F : 0x11111111 */ + 1, /* U+A290 - U+A297 : 0x11111111 */ + 1, /* U+A298 - U+A29F : 0x11111111 */ + 1, /* U+A2A0 - U+A2A7 : 0x11111111 */ + 1, /* U+A2A8 - U+A2AF : 0x11111111 */ + 1, /* U+A2B0 - U+A2B7 : 0x11111111 */ + 1, /* U+A2B8 - U+A2BF : 0x11111111 */ + 1, /* U+A2C0 - U+A2C7 : 0x11111111 */ + 1, /* U+A2C8 - U+A2CF : 0x11111111 */ + 1, /* U+A2D0 - U+A2D7 : 0x11111111 */ + 1, /* U+A2D8 - U+A2DF : 0x11111111 */ + 1, /* U+A2E0 - U+A2E7 : 0x11111111 */ + 1, /* U+A2E8 - U+A2EF : 0x11111111 */ + 1, /* U+A2F0 - U+A2F7 : 0x11111111 */ + 1, /* U+A2F8 - U+A2FF : 0x11111111 */ + 1, /* U+A300 - U+A307 : 0x11111111 */ + 1, /* U+A308 - U+A30F : 0x11111111 */ + 1, /* U+A310 - U+A317 : 0x11111111 */ + 1, /* U+A318 - U+A31F : 0x11111111 */ + 1, /* U+A320 - U+A327 : 0x11111111 */ + 1, /* U+A328 - U+A32F : 0x11111111 */ + 1, /* U+A330 - U+A337 : 0x11111111 */ + 1, /* U+A338 - U+A33F : 0x11111111 */ + 1, /* U+A340 - U+A347 : 0x11111111 */ + 1, /* U+A348 - U+A34F : 0x11111111 */ + 1, /* U+A350 - U+A357 : 0x11111111 */ + 1, /* U+A358 - U+A35F : 0x11111111 */ + 1, /* U+A360 - U+A367 : 0x11111111 */ + 1, /* U+A368 - U+A36F : 0x11111111 */ + 1, /* U+A370 - U+A377 : 0x11111111 */ + 1, /* U+A378 - U+A37F : 0x11111111 */ + 1, /* U+A380 - U+A387 : 0x11111111 */ + 1, /* U+A388 - U+A38F : 0x11111111 */ + 1, /* U+A390 - U+A397 : 0x11111111 */ + 1, /* U+A398 - U+A39F : 0x11111111 */ + 1, /* U+A3A0 - U+A3A7 : 0x11111111 */ + 1, /* U+A3A8 - U+A3AF : 0x11111111 */ + 1, /* U+A3B0 - U+A3B7 : 0x11111111 */ + 1, /* U+A3B8 - U+A3BF : 0x11111111 */ + 1, /* U+A3C0 - U+A3C7 : 0x11111111 */ + 1, /* U+A3C8 - U+A3CF : 0x11111111 */ + 1, /* U+A3D0 - U+A3D7 : 0x11111111 */ + 1, /* U+A3D8 - U+A3DF : 0x11111111 */ + 1, /* U+A3E0 - U+A3E7 : 0x11111111 */ + 1, /* U+A3E8 - U+A3EF : 0x11111111 */ + 1, /* U+A3F0 - U+A3F7 : 0x11111111 */ + 1, /* U+A3F8 - U+A3FF : 0x11111111 */ + 1, /* U+A400 - U+A407 : 0x11111111 */ + 1, /* U+A408 - U+A40F : 0x11111111 */ + 1, /* U+A410 - U+A417 : 0x11111111 */ + 1, /* U+A418 - U+A41F : 0x11111111 */ + 1, /* U+A420 - U+A427 : 0x11111111 */ + 1, /* U+A428 - U+A42F : 0x11111111 */ + 1, /* U+A430 - U+A437 : 0x11111111 */ + 1, /* U+A438 - U+A43F : 0x11111111 */ + 1, /* U+A440 - U+A447 : 0x11111111 */ + 1, /* U+A448 - U+A44F : 0x11111111 */ + 1, /* U+A450 - U+A457 : 0x11111111 */ + 1, /* U+A458 - U+A45F : 0x11111111 */ + 1, /* U+A460 - U+A467 : 0x11111111 */ + 1, /* U+A468 - U+A46F : 0x11111111 */ + 1, /* U+A470 - U+A477 : 0x11111111 */ + 1, /* U+A478 - U+A47F : 0x11111111 */ + 1, /* U+A480 - U+A487 : 0x11111111 */ + 1, /* U+A488 - U+A48F : 0x11111111 */ + 9, /* U+A490 - U+A497 : 0x99999999 */ + 9, /* U+A498 - U+A49F : 0x99999999 */ + 121, /* U+A4A0 - U+A4A7 : 0x99991199 */ + 9, /* U+A4A8 - U+A4AF : 0x99999999 */ + 129, /* U+A4B0 - U+A4B7 : 0x99919999 */ + 9, /* U+A4B8 - U+A4BF : 0x99999999 */ + 130, /* U+A4C0 - U+A4C7 : 0x19199919 */ + 1, /* U+A4C8 - U+A4CF : 0x11111111 */ + 1, /* U+A4D0 - U+A4D7 : 0x11111111 */ + 1, /* U+A4D8 - U+A4DF : 0x11111111 */ + 1, /* U+A4E0 - U+A4E7 : 0x11111111 */ + 1, /* U+A4E8 - U+A4EF : 0x11111111 */ + 1, /* U+A4F0 - U+A4F7 : 0x11111111 */ + 1, /* U+A4F8 - U+A4FF : 0x11111111 */ +}; + +static PRUint8 gBidiCatIdx6[224] = { + 1, /* U+F900 - U+F907 : 0x11111111 */ + 1, /* U+F908 - U+F90F : 0x11111111 */ + 1, /* U+F910 - U+F917 : 0x11111111 */ + 1, /* U+F918 - U+F91F : 0x11111111 */ + 1, /* U+F920 - U+F927 : 0x11111111 */ + 1, /* U+F928 - U+F92F : 0x11111111 */ + 1, /* U+F930 - U+F937 : 0x11111111 */ + 1, /* U+F938 - U+F93F : 0x11111111 */ + 1, /* U+F940 - U+F947 : 0x11111111 */ + 1, /* U+F948 - U+F94F : 0x11111111 */ + 1, /* U+F950 - U+F957 : 0x11111111 */ + 1, /* U+F958 - U+F95F : 0x11111111 */ + 1, /* U+F960 - U+F967 : 0x11111111 */ + 1, /* U+F968 - U+F96F : 0x11111111 */ + 1, /* U+F970 - U+F977 : 0x11111111 */ + 1, /* U+F978 - U+F97F : 0x11111111 */ + 1, /* U+F980 - U+F987 : 0x11111111 */ + 1, /* U+F988 - U+F98F : 0x11111111 */ + 1, /* U+F990 - U+F997 : 0x11111111 */ + 1, /* U+F998 - U+F99F : 0x11111111 */ + 1, /* U+F9A0 - U+F9A7 : 0x11111111 */ + 1, /* U+F9A8 - U+F9AF : 0x11111111 */ + 1, /* U+F9B0 - U+F9B7 : 0x11111111 */ + 1, /* U+F9B8 - U+F9BF : 0x11111111 */ + 1, /* U+F9C0 - U+F9C7 : 0x11111111 */ + 1, /* U+F9C8 - U+F9CF : 0x11111111 */ + 1, /* U+F9D0 - U+F9D7 : 0x11111111 */ + 1, /* U+F9D8 - U+F9DF : 0x11111111 */ + 1, /* U+F9E0 - U+F9E7 : 0x11111111 */ + 1, /* U+F9E8 - U+F9EF : 0x11111111 */ + 1, /* U+F9F0 - U+F9F7 : 0x11111111 */ + 1, /* U+F9F8 - U+F9FF : 0x11111111 */ + 1, /* U+FA00 - U+FA07 : 0x11111111 */ + 1, /* U+FA08 - U+FA0F : 0x11111111 */ + 1, /* U+FA10 - U+FA17 : 0x11111111 */ + 1, /* U+FA18 - U+FA1F : 0x11111111 */ + 1, /* U+FA20 - U+FA27 : 0x11111111 */ + 1, /* U+FA28 - U+FA2F : 0x11111111 */ + 1, /* U+FA30 - U+FA37 : 0x11111111 */ + 1, /* U+FA38 - U+FA3F : 0x11111111 */ + 1, /* U+FA40 - U+FA47 : 0x11111111 */ + 1, /* U+FA48 - U+FA4F : 0x11111111 */ + 1, /* U+FA50 - U+FA57 : 0x11111111 */ + 1, /* U+FA58 - U+FA5F : 0x11111111 */ + 1, /* U+FA60 - U+FA67 : 0x11111111 */ + 1, /* U+FA68 - U+FA6F : 0x11111111 */ + 1, /* U+FA70 - U+FA77 : 0x11111111 */ + 1, /* U+FA78 - U+FA7F : 0x11111111 */ + 1, /* U+FA80 - U+FA87 : 0x11111111 */ + 1, /* U+FA88 - U+FA8F : 0x11111111 */ + 1, /* U+FA90 - U+FA97 : 0x11111111 */ + 1, /* U+FA98 - U+FA9F : 0x11111111 */ + 1, /* U+FAA0 - U+FAA7 : 0x11111111 */ + 1, /* U+FAA8 - U+FAAF : 0x11111111 */ + 1, /* U+FAB0 - U+FAB7 : 0x11111111 */ + 1, /* U+FAB8 - U+FABF : 0x11111111 */ + 1, /* U+FAC0 - U+FAC7 : 0x11111111 */ + 1, /* U+FAC8 - U+FACF : 0x11111111 */ + 1, /* U+FAD0 - U+FAD7 : 0x11111111 */ + 1, /* U+FAD8 - U+FADF : 0x11111111 */ + 1, /* U+FAE0 - U+FAE7 : 0x11111111 */ + 1, /* U+FAE8 - U+FAEF : 0x11111111 */ + 1, /* U+FAF0 - U+FAF7 : 0x11111111 */ + 1, /* U+FAF8 - U+FAFF : 0x11111111 */ + 1, /* U+FB00 - U+FB07 : 0x11111111 */ + 1, /* U+FB08 - U+FB0F : 0x11111111 */ + 1, /* U+FB10 - U+FB17 : 0x11111111 */ + 131, /* U+FB18 - U+FB1F : 0x2A211111 */ + 2, /* U+FB20 - U+FB27 : 0x22222222 */ + 132, /* U+FB28 - U+FB2F : 0x22222272 */ + 2, /* U+FB30 - U+FB37 : 0x22222222 */ + 2, /* U+FB38 - U+FB3F : 0x22222222 */ + 2, /* U+FB40 - U+FB47 : 0x22222222 */ + 2, /* U+FB48 - U+FB4F : 0x22222222 */ + 3, /* U+FB50 - U+FB57 : 0x33333333 */ + 3, /* U+FB58 - U+FB5F : 0x33333333 */ + 3, /* U+FB60 - U+FB67 : 0x33333333 */ + 3, /* U+FB68 - U+FB6F : 0x33333333 */ + 3, /* U+FB70 - U+FB77 : 0x33333333 */ + 3, /* U+FB78 - U+FB7F : 0x33333333 */ + 3, /* U+FB80 - U+FB87 : 0x33333333 */ + 3, /* U+FB88 - U+FB8F : 0x33333333 */ + 3, /* U+FB90 - U+FB97 : 0x33333333 */ + 3, /* U+FB98 - U+FB9F : 0x33333333 */ + 3, /* U+FBA0 - U+FBA7 : 0x33333333 */ + 3, /* U+FBA8 - U+FBAF : 0x33333333 */ + 3, /* U+FBB0 - U+FBB7 : 0x33333333 */ + 3, /* U+FBB8 - U+FBBF : 0x33333333 */ + 3, /* U+FBC0 - U+FBC7 : 0x33333333 */ + 3, /* U+FBC8 - U+FBCF : 0x33333333 */ + 3, /* U+FBD0 - U+FBD7 : 0x33333333 */ + 3, /* U+FBD8 - U+FBDF : 0x33333333 */ + 3, /* U+FBE0 - U+FBE7 : 0x33333333 */ + 3, /* U+FBE8 - U+FBEF : 0x33333333 */ + 3, /* U+FBF0 - U+FBF7 : 0x33333333 */ + 3, /* U+FBF8 - U+FBFF : 0x33333333 */ + 3, /* U+FC00 - U+FC07 : 0x33333333 */ + 3, /* U+FC08 - U+FC0F : 0x33333333 */ + 3, /* U+FC10 - U+FC17 : 0x33333333 */ + 3, /* U+FC18 - U+FC1F : 0x33333333 */ + 3, /* U+FC20 - U+FC27 : 0x33333333 */ + 3, /* U+FC28 - U+FC2F : 0x33333333 */ + 3, /* U+FC30 - U+FC37 : 0x33333333 */ + 3, /* U+FC38 - U+FC3F : 0x33333333 */ + 3, /* U+FC40 - U+FC47 : 0x33333333 */ + 3, /* U+FC48 - U+FC4F : 0x33333333 */ + 3, /* U+FC50 - U+FC57 : 0x33333333 */ + 3, /* U+FC58 - U+FC5F : 0x33333333 */ + 3, /* U+FC60 - U+FC67 : 0x33333333 */ + 3, /* U+FC68 - U+FC6F : 0x33333333 */ + 3, /* U+FC70 - U+FC77 : 0x33333333 */ + 3, /* U+FC78 - U+FC7F : 0x33333333 */ + 3, /* U+FC80 - U+FC87 : 0x33333333 */ + 3, /* U+FC88 - U+FC8F : 0x33333333 */ + 3, /* U+FC90 - U+FC97 : 0x33333333 */ + 3, /* U+FC98 - U+FC9F : 0x33333333 */ + 3, /* U+FCA0 - U+FCA7 : 0x33333333 */ + 3, /* U+FCA8 - U+FCAF : 0x33333333 */ + 3, /* U+FCB0 - U+FCB7 : 0x33333333 */ + 3, /* U+FCB8 - U+FCBF : 0x33333333 */ + 3, /* U+FCC0 - U+FCC7 : 0x33333333 */ + 3, /* U+FCC8 - U+FCCF : 0x33333333 */ + 3, /* U+FCD0 - U+FCD7 : 0x33333333 */ + 3, /* U+FCD8 - U+FCDF : 0x33333333 */ + 3, /* U+FCE0 - U+FCE7 : 0x33333333 */ + 3, /* U+FCE8 - U+FCEF : 0x33333333 */ + 3, /* U+FCF0 - U+FCF7 : 0x33333333 */ + 3, /* U+FCF8 - U+FCFF : 0x33333333 */ + 3, /* U+FD00 - U+FD07 : 0x33333333 */ + 3, /* U+FD08 - U+FD0F : 0x33333333 */ + 3, /* U+FD10 - U+FD17 : 0x33333333 */ + 3, /* U+FD18 - U+FD1F : 0x33333333 */ + 3, /* U+FD20 - U+FD27 : 0x33333333 */ + 3, /* U+FD28 - U+FD2F : 0x33333333 */ + 3, /* U+FD30 - U+FD37 : 0x33333333 */ + 133, /* U+FD38 - U+FD3F : 0x99333333 */ + 3, /* U+FD40 - U+FD47 : 0x33333333 */ + 3, /* U+FD48 - U+FD4F : 0x33333333 */ + 3, /* U+FD50 - U+FD57 : 0x33333333 */ + 3, /* U+FD58 - U+FD5F : 0x33333333 */ + 3, /* U+FD60 - U+FD67 : 0x33333333 */ + 3, /* U+FD68 - U+FD6F : 0x33333333 */ + 3, /* U+FD70 - U+FD77 : 0x33333333 */ + 3, /* U+FD78 - U+FD7F : 0x33333333 */ + 3, /* U+FD80 - U+FD87 : 0x33333333 */ + 3, /* U+FD88 - U+FD8F : 0x33333333 */ + 3, /* U+FD90 - U+FD97 : 0x33333333 */ + 3, /* U+FD98 - U+FD9F : 0x33333333 */ + 3, /* U+FDA0 - U+FDA7 : 0x33333333 */ + 3, /* U+FDA8 - U+FDAF : 0x33333333 */ + 3, /* U+FDB0 - U+FDB7 : 0x33333333 */ + 3, /* U+FDB8 - U+FDBF : 0x33333333 */ + 3, /* U+FDC0 - U+FDC7 : 0x33333333 */ + 3, /* U+FDC8 - U+FDCF : 0x33333333 */ + 3, /* U+FDD0 - U+FDD7 : 0x33333333 */ + 3, /* U+FDD8 - U+FDDF : 0x33333333 */ + 3, /* U+FDE0 - U+FDE7 : 0x33333333 */ + 3, /* U+FDE8 - U+FDEF : 0x33333333 */ + 3, /* U+FDF0 - U+FDF7 : 0x33333333 */ + 3, /* U+FDF8 - U+FDFF : 0x33333333 */ + 1, /* U+FE00 - U+FE07 : 0x11111111 */ + 1, /* U+FE08 - U+FE0F : 0x11111111 */ + 1, /* U+FE10 - U+FE17 : 0x11111111 */ + 1, /* U+FE18 - U+FE1F : 0x11111111 */ + 94, /* U+FE20 - U+FE27 : 0x1111AAAA */ + 1, /* U+FE28 - U+FE2F : 0x11111111 */ + 9, /* U+FE30 - U+FE37 : 0x99999999 */ + 9, /* U+FE38 - U+FE3F : 0x99999999 */ + 124, /* U+FE40 - U+FE47 : 0x11199999 */ + 119, /* U+FE48 - U+FE4F : 0x99999991 */ + 134, /* U+FE50 - U+FE57 : 0x99891898 */ + 135, /* U+FE58 - U+FE5F : 0x79999999 */ + 136, /* U+FE60 - U+FE67 : 0x19997799 */ + 137, /* U+FE68 - U+FE6F : 0x11119779 */ + 3, /* U+FE70 - U+FE77 : 0x33333333 */ + 3, /* U+FE78 - U+FE7F : 0x33333333 */ + 3, /* U+FE80 - U+FE87 : 0x33333333 */ + 3, /* U+FE88 - U+FE8F : 0x33333333 */ + 3, /* U+FE90 - U+FE97 : 0x33333333 */ + 3, /* U+FE98 - U+FE9F : 0x33333333 */ + 3, /* U+FEA0 - U+FEA7 : 0x33333333 */ + 3, /* U+FEA8 - U+FEAF : 0x33333333 */ + 3, /* U+FEB0 - U+FEB7 : 0x33333333 */ + 3, /* U+FEB8 - U+FEBF : 0x33333333 */ + 3, /* U+FEC0 - U+FEC7 : 0x33333333 */ + 3, /* U+FEC8 - U+FECF : 0x33333333 */ + 3, /* U+FED0 - U+FED7 : 0x33333333 */ + 3, /* U+FED8 - U+FEDF : 0x33333333 */ + 3, /* U+FEE0 - U+FEE7 : 0x33333333 */ + 3, /* U+FEE8 - U+FEEF : 0x33333333 */ + 3, /* U+FEF0 - U+FEF7 : 0x33333333 */ + 55, /* U+FEF8 - U+FEFF : 0xB3333333 */ + 138, /* U+FF00 - U+FF07 : 0x99777991 */ + 19, /* U+FF08 - U+FF0F : 0x68787999 */ + 5, /* U+FF10 - U+FF17 : 0x55555555 */ + 20, /* U+FF18 - U+FF1F : 0x99999855 */ + 21, /* U+FF20 - U+FF27 : 0x11111119 */ + 1, /* U+FF28 - U+FF2F : 0x11111111 */ + 1, /* U+FF30 - U+FF37 : 0x11111111 */ + 22, /* U+FF38 - U+FF3F : 0x99999111 */ + 21, /* U+FF40 - U+FF47 : 0x11111119 */ + 1, /* U+FF48 - U+FF4F : 0x11111111 */ + 1, /* U+FF50 - U+FF57 : 0x11111111 */ + 139, /* U+FF58 - U+FF5F : 0x19999111 */ + 140, /* U+FF60 - U+FF67 : 0x11999991 */ + 1, /* U+FF68 - U+FF6F : 0x11111111 */ + 1, /* U+FF70 - U+FF77 : 0x11111111 */ + 1, /* U+FF78 - U+FF7F : 0x11111111 */ + 1, /* U+FF80 - U+FF87 : 0x11111111 */ + 1, /* U+FF88 - U+FF8F : 0x11111111 */ + 1, /* U+FF90 - U+FF97 : 0x11111111 */ + 1, /* U+FF98 - U+FF9F : 0x11111111 */ + 1, /* U+FFA0 - U+FFA7 : 0x11111111 */ + 1, /* U+FFA8 - U+FFAF : 0x11111111 */ + 1, /* U+FFB0 - U+FFB7 : 0x11111111 */ + 1, /* U+FFB8 - U+FFBF : 0x11111111 */ + 1, /* U+FFC0 - U+FFC7 : 0x11111111 */ + 1, /* U+FFC8 - U+FFCF : 0x11111111 */ + 1, /* U+FFD0 - U+FFD7 : 0x11111111 */ + 1, /* U+FFD8 - U+FFDF : 0x11111111 */ + 141, /* U+FFE0 - U+FFE7 : 0x17799977 */ + 103, /* U+FFE8 - U+FFEF : 0x19999999 */ + 1, /* U+FFF0 - U+FFF7 : 0x11111111 */ + 142, /* U+FFF8 - U+FFFF : 0x1199BBB1 */ +}; + +static PRUint32 gBidiCatPat[143] = { + 0x00000000, /* 0 */ + 0x11111111, /* 1 */ + 0x22222222, /* 2 */ + 0x33333333, /* 3 */ + 0x44444444, /* 4 */ + 0x55555555, /* 5 */ + 0x66666666, /* 6 */ + 0x77777777, /* 7 */ + 0x88888888, /* 8 */ + 0x99999999, /* 9 */ + 0xAAAAAAAA, /* 10 */ + 0xBBBBBBBB, /* 11 */ + 0xCCCCCCCC, /* 12 */ + 0xDDDDDDDD, /* 13 */ + 0xEEEEEEEE, /* 14 */ + 0xFFFFFFFF, /* 15 */ + 0xBBCEDCDB, /* 16 */ + 0xDCCCBBBB, /* 17 */ + 0x9977799E, /* 18 */ + 0x68787999, /* 19 */ + 0x99999855, /* 20 */ + 0x11111119, /* 21 */ + 0x99999111, /* 22 */ + 0xB9999111, /* 23 */ + 0xBBCBBBBB, /* 24 */ + 0x99777798, /* 25 */ + 0x99999199, /* 26 */ + 0x99195577, /* 27 */ + 0x99999159, /* 28 */ + 0x91111111, /* 29 */ + 0x11111991, /* 30 */ + 0x99999911, /* 31 */ + 0x99911111, /* 32 */ + 0x11999999, /* 33 */ + 0x1AAAAAAA, /* 34 */ + 0x11111AAA, /* 35 */ + 0x11991111, /* 36 */ + 0x19111111, /* 37 */ + 0x91991111, /* 38 */ + 0x1AAAA111, /* 39 */ + 0x111111AA, /* 40 */ + 0x11111911, /* 41 */ + 0xAAAAAAA2, /* 42 */ + 0xAAAAA2AA, /* 43 */ + 0xA2AAA2AA, /* 44 */ + 0x222A2AA2, /* 45 */ + 0x33383333, /* 46 */ + 0xAAAAA333, /* 47 */ + 0x33AAAAAA, /* 48 */ + 0x33344744, /* 49 */ + 0x3333333A, /* 50 */ + 0xAA333333, /* 51 */ + 0xA33AAAAA, /* 52 */ + 0x33AAAA9A, /* 53 */ + 0x33333355, /* 54 */ + 0xB3333333, /* 55 */ + 0x333333A3, /* 56 */ + 0x33333AAA, /* 57 */ + 0x11111AA1, /* 58 */ + 0x111A1111, /* 59 */ + 0xAAAAAAA1, /* 60 */ + 0x11A1111A, /* 61 */ + 0x111AAAA1, /* 62 */ + 0x1111AA11, /* 63 */ + 0x111111A1, /* 64 */ + 0x11A11111, /* 65 */ + 0x11117711, /* 66 */ + 0x11111A11, /* 67 */ + 0xA1111AA1, /* 68 */ + 0x11AAA11A, /* 69 */ + 0xA1AAAAA1, /* 70 */ + 0xA11A1111, /* 71 */ + 0x1111AAA1, /* 72 */ + 0x1A111111, /* 73 */ + 0x1111111A, /* 74 */ + 0xAA111111, /* 75 */ + 0xAA11111A, /* 76 */ + 0x11AAAA1A, /* 77 */ + 0x1AA11111, /* 78 */ + 0xA1111111, /* 79 */ + 0x11AA1111, /* 80 */ + 0x1A1AAA11, /* 81 */ + 0xAAAA11A1, /* 82 */ + 0x71111AAA, /* 83 */ + 0x111AA1AA, /* 84 */ + 0x11AAAAAA, /* 85 */ + 0xA1A11111, /* 86 */ + 0x119999A1, /* 87 */ + 0xAA1AAAAA, /* 88 */ + 0x111AAAAA, /* 89 */ + 0xAAA11111, /* 90 */ + 0xAA111A1A, /* 91 */ + 0x1111111E, /* 92 */ + 0x11199111, /* 93 */ + 0x1111AAAA, /* 94 */ + 0x11117111, /* 95 */ + 0x1BBBB999, /* 96 */ + 0x91911111, /* 97 */ + 0x11111199, /* 98 */ + 0x19911111, /* 99 */ + 0x21BBBEEE, /* 100 */ + 0xEFFFFFCE, /* 101 */ + 0x99977777, /* 102 */ + 0x19999999, /* 103 */ + 0xBBBBBB11, /* 104 */ + 0x55551115, /* 105 */ + 0x19997755, /* 106 */ + 0x19999199, /* 107 */ + 0x99191111, /* 108 */ + 0x99111119, /* 109 */ + 0x91919999, /* 110 */ + 0x17111191, /* 111 */ + 0x11119999, /* 112 */ + 0x99997799, /* 113 */ + 0x99919111, /* 114 */ + 0x99199999, /* 115 */ + 0x11111999, /* 116 */ + 0x11115555, /* 117 */ + 0x11111511, /* 118 */ + 0x99999991, /* 119 */ + 0x99199991, /* 120 */ + 0x99991199, /* 121 */ + 0x19111999, /* 122 */ + 0x99111111, /* 123 */ + 0x11199999, /* 124 */ + 0x1119999E, /* 125 */ + 0xAAAAAA11, /* 126 */ + 0x11199AA1, /* 127 */ + 0x11119111, /* 128 */ + 0x99919999, /* 129 */ + 0x19199919, /* 130 */ + 0x2A211111, /* 131 */ + 0x22222272, /* 132 */ + 0x99333333, /* 133 */ + 0x99891898, /* 134 */ + 0x79999999, /* 135 */ + 0x19997799, /* 136 */ + 0x11119779, /* 137 */ + 0x99777991, /* 138 */ + 0x19999111, /* 139 */ + 0x11999991, /* 140 */ + 0x17799977, /* 141 */ + 0x1199BBB1, /* 142 */ +}; + +static eBidiCategory GetBidiCat(PRUnichar u) +{ + PRUint32 pat; + PRUint16 patidx; + + /* Handle blocks which use index table mapping */ + + /* Handle U+0000 to U+07FF */ + if (u<=((PRUnichar)0x07FF)) { + patidx = gBidiCatIdx1 [( u >> 3 )]; + if (patidx < 0x10) + return (eBidiCategory)patidx; + else { + pat = gBidiCatPat[patidx]; + return (eBidiCategory)((pat >> ((u % 8) * 4)) & 0x0F); + } + } + + /* Handle U+0900 to U+18FF */ + if ((((PRUnichar)0x0900)<=u)&&(u<=((PRUnichar)0x18FF))) { + patidx = gBidiCatIdx2 [( (u -(PRUnichar) 0x0900) >> 3 )]; + if (patidx < 0x10) + return (eBidiCategory)patidx; + else { + pat = gBidiCatPat[patidx]; + return (eBidiCategory)((pat >> ((u % 8) * 4)) & 0x0F); + } + } + + /* Handle U+1E00 to U+28FF */ + if ((((PRUnichar)0x1E00)<=u)&&(u<=((PRUnichar)0x28FF))) { + patidx = gBidiCatIdx3 [( (u -(PRUnichar) 0x1E00) >> 3 )]; + if (patidx < 0x10) + return (eBidiCategory)patidx; + else { + pat = gBidiCatPat[patidx]; + return (eBidiCategory)((pat >> ((u % 8) * 4)) & 0x0F); + } + } + + /* Handle U+2E80 to U+33FF */ + if ((((PRUnichar)0x2E80)<=u)&&(u<=((PRUnichar)0x33FF))) { + patidx = gBidiCatIdx4 [( (u -(PRUnichar) 0x2E80) >> 3 )]; + if (patidx < 0x10) + return (eBidiCategory)patidx; + else { + pat = gBidiCatPat[patidx]; + return (eBidiCategory)((pat >> ((u % 8) * 4)) & 0x0F); + } + } + + /* Handle U+A000 to U+A4FF */ + if ((((PRUnichar)0xA000)<=u)&&(u<=((PRUnichar)0xA4FF))) { + patidx = gBidiCatIdx5 [( (u -(PRUnichar) 0xA000) >> 3 )]; + if (patidx < 0x10) + return (eBidiCategory)patidx; + else { + pat = gBidiCatPat[patidx]; + return (eBidiCategory)((pat >> ((u % 8) * 4)) & 0x0F); + } + } + + /* Handle U+F900 to U+FFFF */ + if (((PRUnichar)0xF900)<=u) { + patidx = gBidiCatIdx6 [( (u -(PRUnichar) 0xF900) >> 3 )]; + if (patidx < 0x10) + return (eBidiCategory)patidx; + else { + pat = gBidiCatPat[patidx]; + return (eBidiCategory)((pat >> ((u % 8) * 4)) & 0x0F); + } + } + + return eBidiCat_L; /* UNDEFINE = L */ +}; +/* total data size = 2252 */ diff --git a/mozilla/layout/base/src/makefile.win b/mozilla/layout/base/src/makefile.win index 35292378987..c90e04ecb92 100644 --- a/mozilla/layout/base/src/makefile.win +++ b/mozilla/layout/base/src/makefile.win @@ -69,6 +69,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsStyleChangeList.obj \ !ifdef IBMBIDI .\$(OBJDIR)\nsBidiPresUtils.obj \ + .\$(OBJDIR)\nsBidi.obj \ !endif $(NULL) diff --git a/mozilla/layout/base/src/nsBidi.cpp b/mozilla/layout/base/src/nsBidi.cpp new file mode 100644 index 00000000000..d8782adca2a --- /dev/null +++ b/mozilla/layout/base/src/nsBidi.cpp @@ -0,0 +1,2342 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * IBM Corporation. Portions created by IBM are + * Copyright (C) 2000 IBM Corporation. All + * Rights Reserved. + * + * This module is based on the ICU (International Components for Unicode) + * + * Copyright (C) 2000, International Business Machines + * Corporation and others. All Rights Reserved. + * + * Contributor(s): Simon Montagu + */ +#ifdef IBMBIDI + +#include "prmem.h" +#include "nsBidi.h" +#include "nsBidiUtils.h" +#include "bidicattable.h" +#include "symmtable.h" + +static nsCharType ebc2ucd[15] = { + eCharType_OtherNeutral, /* Placeholder -- there will never be a 0 index value */ + eCharType_LeftToRight, + eCharType_RightToLeft, + eCharType_RightToLeftArabic, + eCharType_ArabicNumber, + eCharType_EuropeanNumber, + eCharType_EuropeanNumberSeparator, + eCharType_EuropeanNumberTerminator, + eCharType_CommonNumberSeparator, + eCharType_OtherNeutral, + eCharType_DirNonSpacingMark, + eCharType_BoundaryNeutral, + eCharType_BlockSeparator, + eCharType_SegmentSeparator, + eCharType_WhiteSpaceNeutral +}; + +static nsCharType cc2ucd[5] = { + eCharType_LeftToRightEmbedding, + eCharType_RightToLeftEmbedding, + eCharType_PopDirectionalFormat, + eCharType_LeftToRightOverride, + eCharType_RightToLeftOverride +}; + +/* Comparing the description of the Bidi algorithm with this implementation + is easier with the same names for the Bidi types in the code as there. +*/ +enum { + L = eCharType_LeftToRight, + R = eCharType_RightToLeft, + EN = eCharType_EuropeanNumber, + ES = eCharType_EuropeanNumberSeparator, + ET = eCharType_EuropeanNumberTerminator, + AN = eCharType_ArabicNumber, + CS = eCharType_CommonNumberSeparator, + B = eCharType_BlockSeparator, + S = eCharType_SegmentSeparator, + WS = eCharType_WhiteSpaceNeutral, + O_N = eCharType_OtherNeutral, + LRE = eCharType_LeftToRightEmbedding, + LRO = eCharType_LeftToRightOverride, + AL = eCharType_RightToLeftArabic, + RLE = eCharType_RightToLeftEmbedding, + RLO = eCharType_RightToLeftOverride, + PDF = eCharType_PopDirectionalFormat, + NSM = eCharType_DirNonSpacingMark, + BN = eCharType_BoundaryNeutral, + dirPropCount +}; + +/* to avoid some conditional statements, use tiny constant arrays */ +static Flags flagLR[2]={ DIRPROP_FLAG(L), DIRPROP_FLAG(R) }; +static Flags flagE[2]={ DIRPROP_FLAG(LRE), DIRPROP_FLAG(RLE) }; +static Flags flagO[2]={ DIRPROP_FLAG(LRO), DIRPROP_FLAG(RLO) }; + +#define DIRPROP_FLAG_LR(level) flagLR[(level)&1] +#define DIRPROP_FLAG_E(level) flagE[(level)&1] +#define DIRPROP_FLAG_O(level) flagO[(level)&1] + +/* + * General implementation notes: + * + * Throughout the implementation, there are comments like (W2) that refer to + * rules of the Bidi algorithm in its version 5, in this example to the second + * rule of the resolution of weak types. + * + * For handling surrogate pairs, where two UChar's form one "abstract" (or UTF-32) + * character according to UTF-16, the second UChar gets the directional property of + * the entire character assigned, while the first one gets a BN, a boundary + * neutral, type, which is ignored by most of the algorithm according to + * rule (X9) and the implementation suggestions of the Bidi algorithm. + * + * Later, AdjustWSLevels() will set the level for each BN to that of the + * following character (UChar), which results in surrogate pairs getting the + * same level on each of their surrogates. + * + * In a UTF-8 implementation, the same thing could be done: the last byte of + * a multi-byte sequence would get the "real" property, while all previous + * bytes of that sequence would get BN. + * + * It is not possible to assign all those parts of a character the same real + * property because this would fail in the resolution of weak types with rules + * that look at immediately surrounding types. + * + * As a related topic, this implementation does not remove Boundary Neutral + * types from the input, but ignores them whereever this is relevant. + * For example, the loop for the resolution of the weak types reads + * types until it finds a non-BN. + * Also, explicit embedding codes are neither changed into BN nor removed. + * They are only treated the same way real BNs are. + * As stated before, AdjustWSLevels() takes care of them at the end. + * For the purpose of conformance, the levels of all these codes + * do not matter. + * + * Note that this implementation never modifies the dirProps + * after the initial setup. + * + * + * In this implementation, the resolution of weak types (Wn), + * neutrals (Nn), and the assignment of the resolved level (In) + * are all done in one single loop, in ResolveImplicitLevels(). + * Changes of dirProp values are done on the fly, without writing + * them back to the dirProps array. + * + * + * This implementation contains code that allows to bypass steps of the + * algorithm that are not needed on the specific paragraph + * in order to speed up the most common cases considerably, + * like text that is entirely LTR, or RTL text without numbers. + * + * Most of this is done by setting a bit for each directional property + * in a flags variable and later checking for whether there are + * any LTR characters or any RTL characters, or both, whether + * there are any explicit embedding codes, etc. + * + * If the (Xn) steps are performed, then the flags are re-evaluated, + * because they will then not contain the embedding codes any more + * and will be adjusted for override codes, so that subsequently + * more bypassing may be possible than what the initial flags suggested. + * + * If the text is not mixed-directional, then the + * algorithm steps for the weak type resolution are not performed, + * and all levels are set to the paragraph level. + * + * If there are no explicit embedding codes, then the (Xn) steps + * are not performed. + * + * If embedding levels are supplied as a parameter, then all + * explicit embedding codes are ignored, and the (Xn) steps + * are not performed. + * + * White Space types could get the level of the run they belong to, + * and are checked with a test of (flags&MASK_EMBEDDING) to + * consider if the paragraph direction should be considered in + * the flags variable. + * + * If there are no White Space types in the paragraph, then + * (L1) is not necessary in AdjustWSLevels(). + */ +nsBidi::nsBidi() +{ + Init(); + + mMayAllocateText=PR_TRUE; + mMayAllocateRuns=PR_TRUE; +} + +nsBidi::nsBidi(PRUint32 aMaxLength, PRUint32 aMaxRunCount) +{ + Init(); + nsresult rv = NS_OK; + + /* allocate memory for arrays as requested */ + if(aMaxLength>0) { + if( !GETINITIALDIRPROPSMEMORY(aMaxLength) || + !GETINITIALLEVELSMEMORY(aMaxLength) + ) { + mMayAllocateText=PR_FALSE; + rv = NS_ERROR_OUT_OF_MEMORY; + } + } else { + mMayAllocateText=PR_TRUE; + } + + if(aMaxRunCount>0) { + if(aMaxRunCount==1) { + /* use simpleRuns[] */ + mRunsSize=sizeof(Run); + } else if(!GETINITIALRUNSMEMORY(aMaxRunCount)) { + mMayAllocateRuns=PR_FALSE; + rv = NS_ERROR_OUT_OF_MEMORY; + } + } else { + mMayAllocateRuns=PR_TRUE; + } + + if(NS_FAILED(rv)) { + Free(); + } +} + +nsBidi::~nsBidi() +{ + Free(); +} + +void nsBidi::Init() +{ + /* reset the object, all pointers NULL, all flags PR_FALSE, all sizes 0 */ + mLength = 0; + mParaLevel = 0; + mFlags = 0; + mDirection = NSBIDI_LTR; + mTrailingWSStart = 0; + + mDirPropsSize = 0; + mLevelsSize = 0; + mRunsSize = 0; + mRunCount = -1; + + mDirProps=NULL; + mLevels=NULL; + mRuns=NULL; + + mDirPropsMemory=NULL; + mLevelsMemory=NULL; + mRunsMemory=NULL; + + mMayAllocateText=PR_FALSE; + mMayAllocateRuns=PR_FALSE; + +} + +/* + * We are allowed to allocate memory if aMemory==NULL or + * aMayAllocate==PR_TRUE for each array that we need. + * We also try to grow and shrink memory as needed if we + * allocate it. + * + * Assume aSizeNeeded>0. + * If *aMemory!=NULL, then assume *aSize>0. + * + * ### this realloc() may unnecessarily copy the old data, + * which we know we don't need any more; + * is this the best way to do this?? + */ +PRBool nsBidi::GetMemory(void **aMemory, PRSize *aSize, PRBool aMayAllocate, PRSize aSizeNeeded) +{ + /* check for existing memory */ + if(*aMemory==NULL) { + /* we need to allocate memory */ + if(!aMayAllocate) { + return PR_FALSE; + } else { + *aMemory=PR_MALLOC(aSizeNeeded); + if (*aMemory!=NULL) { + *aSize=aSizeNeeded; + return PR_TRUE; + } else { + *aSize=0; + return PR_FALSE; + } + } + } else { + /* there is some memory, is it enough or too much? */ + if(aSizeNeeded>*aSize && !aMayAllocate) { + /* not enough memory, and we must not allocate */ + return PR_FALSE; + } else if(aSizeNeeded!=*aSize && aMayAllocate) { + /* we may try to grow or shrink */ + void *memory=PR_REALLOC(*aMemory, aSizeNeeded); + + if(memory!=NULL) { + *aMemory=memory; + *aSize=aSizeNeeded; + return PR_TRUE; + } else { + /* we failed to grow */ + return PR_FALSE; + } + } else { + /* we have at least enough memory and must not allocate */ + return PR_TRUE; + } + } +} + +void nsBidi::Free() +{ + PR_FREEIF(mDirPropsMemory); + PR_FREEIF(mLevelsMemory); + PR_FREEIF(mRunsMemory); +} + +/* SetPara ------------------------------------------------------------ */ + +nsresult nsBidi::SetPara(const PRUnichar *aText, PRInt32 aLength, + nsBidiLevel aParaLevel, nsBidiLevel *aEmbeddingLevels) +{ + nsBidiDirection direction; + + /* check the argument values */ + if(aText==NULL || + (NSBIDI_MAX_EXPLICIT_LEVEL=NSBIDI_MAX_EXPLICIT_LEVEL */ + PRUint32 countOver60=0, countOver61=0; /* count overflows of explicit levels */ + + /* recalculate the flags */ + flags=0; + + /* since we assume that this is a single paragraph, we ignore (X8) */ + for(i=0; i0) { + --countOver61; + } else if(countOver60>0 && (embeddingLevel&~NSBIDI_LEVEL_OVERRIDE)!=NSBIDI_MAX_EXPLICIT_LEVEL) { + /* handle LRx overflows from level 60 */ + --countOver60; + } else if(stackTop>0) { + /* this is the pop operation; it also pops level 61 while countOver60>0 */ + --stackTop; + embeddingLevel=stack[stackTop]; + /* } else { (underflow) */ + } + flags|=DIRPROP_FLAG(BN); + break; + case B: + /* + * We do not really expect to see a paragraph separator (B), + * but we should do something reasonable with it, + * especially at the end of the text. + */ + stackTop=0; + countOver60=countOver61=0; + embeddingLevel=level=mParaLevel; + flags|=DIRPROP_FLAG(B); + break; + case BN: + /* BN, LRE, RLE, and PDF are supposed to be removed (X9) */ + /* they will get their levels set correctly in AdjustWSLevels() */ + flags|=DIRPROP_FLAG(BN); + break; + default: + /* all other types get the "real" level */ + if(level!=embeddingLevel) { + level=embeddingLevel; + if(level&NSBIDI_LEVEL_OVERRIDE) { + flags|=DIRPROP_FLAG_O(level)|DIRPROP_FLAG_MULTI_RUNS; + } else { + flags|=DIRPROP_FLAG_E(level)|DIRPROP_FLAG_MULTI_RUNS; + } + } + if(!(level&NSBIDI_LEVEL_OVERRIDE)) { + flags|=DIRPROP_FLAG(dirProp); + } + break; + } + + /* + * We need to set reasonable levels even on BN codes and + * explicit codes because we will later look at same-level runs (X10). + */ + levels[i]=level; + } + if(flags&MASK_EMBEDDING) { + flags|=DIRPROP_FLAG_LR(mParaLevel); + } + + /* subsequently, ignore the explicit codes and BN (X9) */ + + /* again, determine if the text is mixed-directional or single-directional */ + mFlags=flags; + direction=DirectionFromFlags(flags); + } + return direction; +} + +/* + * Use a pre-specified embedding levels array: + * + * Adjust the directional properties for overrides (->LEVEL_OVERRIDE), + * ignore all explicit codes (X9), + * and check all the preset levels. + * + * Recalculate the flags to have them reflect the real properties + * after taking the explicit embeddings into account. + */ +nsresult nsBidi::CheckExplicitLevels(nsBidiDirection *aDirection) +{ + const DirProp *dirProps=mDirProps; + nsBidiLevel *levels=mLevels; + + PRInt32 i, length=mLength; + Flags flags=0; /* collect all directionalities in the text */ + nsBidiLevel level, paraLevel=mParaLevel; + + for(i=0; i>=EN_SHIFT; + /* + * Technically, this should be done before the switch() in the form + * if(nextDirProp==NSM) { + * dirProps[next]=nextDirProp=dirProp; + * } + * + * - effectively one iteration ahead. + * However, whether the next dirProp is NSM or is equal to the current dirProp + * does not change the outcome of any condition in (W2)..(W7). + */ + break; + default: + break; + } + + /* here, it is always [prev,this,next]dirProp!=BN; it may be next>i+1 */ + + /* perform (Nn) - here, only L, R, EN, AN, and neutrals are left */ + /* this is one iteration late for the neutrals */ + if(DIRPROP_FLAG(dirProp)&MASK_N) { + if(neutralStart<0) { + /* start of a sequence of neutrals */ + neutralStart=i; + beforeNeutral=prevDirProp; + } + } else /* not a neutral, can be only one of { L, R, EN, AN } */ { + /* + * Note that all levels[] values are still the same at this + * point because this function is called for an entire + * same-level run. + * Therefore, we need to read only one actual level. + */ + nsBidiLevel level=levels[i]; + + if(neutralStart>=0) { + nsBidiLevel final; + /* end of a sequence of neutrals (dirProp is "afterNeutral") */ + if(beforeNeutral==L) { + if(dirProp==L) { + final=0; /* make all neutrals L (N1) */ + } else { + final=level; /* make all neutrals "e" (N2) */ + } + } else /* beforeNeutral is one of { R, EN, AN } */ { + if(dirProp==L) { + final=level; /* make all neutrals "e" (N2) */ + } else { + final=1; /* make all neutrals R (N1) */ + } + } + /* perform (In) on the sequence of neutrals */ + if((level^final)&1) { + /* do something only if we need to _change_ the level */ + do { + ++levels[neutralStart]; + } while(++neutralStart=0) { + /* + * Note that all levels[] values are still the same at this + * point because this function is called for an entire + * same-level run. + * Therefore, we need to read only one actual level. + */ + nsBidiLevel level=levels[neutralStart], final; + + /* end of a sequence of neutrals (aEOR is "afterNeutral") */ + if(beforeNeutral==L) { + if(aEOR==L) { + final=0; /* make all neutrals L (N1) */ + } else { + final=level; /* make all neutrals "e" (N2) */ + } + } else /* beforeNeutral is one of { R, EN, AN } */ { + if(aEOR==L) { + final=level; /* make all neutrals "e" (N2) */ + } else { + final=1; /* make all neutrals R (N1) */ + } + } + /* perform (In) on the sequence of neutrals */ + if((level^final)&1) { + /* do something only if we need to _change_ the level */ + do { + ++levels[neutralStart]; + } while(++neutralStart0) { + /* reset a sequence of WS/BN before eop and B/S to the paragraph paraLevel */ + while(i>0 && DIRPROP_FLAG(dirProps[--i])&MASK_WS) { + levels[i]=paraLevel; + } + + /* reset BN to the next character's paraLevel until B/S, which restarts above loop */ + /* here, i+1 is guaranteed to be 0) { + flag=DIRPROP_FLAG(dirProps[--i]); + if(flag&MASK_BN_EXPLICIT) { + levels[i]=levels[i+1]; + } else if(flag&MASK_B_S) { + levels[i]=paraLevel; + break; + } + } + } + } + + /* now remove the NSBIDI_LEVEL_OVERRIDE flags, if any */ + /* (a separate loop can be optimized more easily by a compiler) */ + if(mFlags&MASK_OVERRIDE) { + for(i=mTrailingWSStart; i>0;) { + levels[--i]&=~NSBIDI_LEVEL_OVERRIDE; + } + } +} +#ifdef FULL_BIDI_ENGINE + +/* -------------------------------------------------------------------------- */ + +nsresult nsBidi::GetDirection(nsBidiDirection* aDirection) +{ + *aDirection = mDirection; + return NS_OK; +} + +nsresult nsBidi::GetLength(PRInt32* aLength) +{ + *aLength = mLength; + return NS_OK; +} + +nsresult nsBidi::GetParaLevel(nsBidiLevel* aParaLevel) +{ + *aParaLevel = mParaLevel; + return NS_OK; +} + +/* + * General remarks about the functions in this section: + * + * These functions deal with the aspects of potentially mixed-directional + * text in a single paragraph or in a line of a single paragraph + * which has already been processed according to + * the Unicode 3.0 Bidi algorithm as defined in + * http://www.unicode.org/unicode/reports/tr9/ , version 5, + * also described in The Unicode Standard, Version 3.0 . + * + * This means that there is a nsBidi object with a levels + * and a dirProps array. + * paraLevel and direction are also set. + * Only if the length of the text is zero, then levels==dirProps==NULL. + * + * The overall directionality of the paragraph + * or line is used to bypass the reordering steps if possible. + * Even purely RTL text does not need reordering there because + * the getLogical/VisualIndex() functions can compute the + * index on the fly in such a case. + * + * The implementation of the access to same-level-runs and of the reordering + * do attempt to provide better performance and less memory usage compared to + * a direct implementation of especially rule (L2) with an array of + * one (32-bit) integer per text character. + * + * Here, the levels array is scanned as soon as necessary, and a vector of + * same-level-runs is created. Reordering then is done on this vector. + * For each run of text positions that were resolved to the same level, + * only 8 bytes are stored: the first text position of the run and the visual + * position behind the run after reordering. + * One sign bit is used to hold the directionality of the run. + * This is inefficient if there are many very short runs. If the average run + * length is <2, then this uses more memory. + * + * In a further attempt to save memory, the levels array is never changed + * after all the resolution rules (Xn, Wn, Nn, In). + * Many functions have to consider the field trailingWSStart: + * if it is less than length, then there is an implicit trailing run + * at the paraLevel, + * which is not reflected in the levels array. + * This allows a line nsBidi object to use the same levels array as + * its paragraph parent object. + * + * When a nsBidi object is created for a line of a paragraph, then the + * paragraph's levels and dirProps arrays are reused by way of setting + * a pointer into them, not by copying. This again saves memory and forbids to + * change the now shared levels for (L1). + */ +nsresult nsBidi::SetLine(nsIBidi* aParaBidi, PRInt32 aStart, PRInt32 aLimit) +{ + nsBidi* pParent = (nsBidi*)aParaBidi; + PRInt32 length; + + /* check the argument values */ + if(pParent==NULL) { + return NS_ERROR_INVALID_POINTER; + } else if(aStart<0 || aStart>aLimit || aLimit>pParent->mLength) { + return NS_ERROR_INVALID_ARG; + } + + /* set members from our aParaBidi parent */ + length=mLength=aLimit-aStart; + mParaLevel=pParent->mParaLevel; + + mRuns=NULL; + mFlags=0; + + if(length>0) { + mDirProps=pParent->mDirProps+aStart; + mLevels=pParent->mLevels+aStart; + mRunCount=-1; + + if(pParent->mDirection!=NSBIDI_MIXED) { + /* the parent is already trivial */ + mDirection=pParent->mDirection; + + /* + * The parent's levels are all either + * implicitly or explicitly ==paraLevel; + * do the same here. + */ + if(pParent->mTrailingWSStart<=aStart) { + mTrailingWSStart=0; + } else if(pParent->mTrailingWSStartmTrailingWSStart-aStart; + } else { + mTrailingWSStart=length; + } + } else { + const nsBidiLevel *levels=mLevels; + PRInt32 i, trailingWSStart; + nsBidiLevel level; + Flags flags=0; + + SetTrailingWSStart(); + trailingWSStart=mTrailingWSStart; + + /* recalculate pLineBidi->direction */ + if(trailingWSStart==0) { + /* all levels are at paraLevel */ + mDirection=(nsBidiDirection)(mParaLevel&1); + } else { + /* get the level of the first character */ + level=levels[0]&1; + + /* if there is anything of a different level, then the line is mixed */ + if(trailingWSStart0 && DIRPROP_FLAG(dirProps[start-1])&MASK_WS) { + --start; + } + + /* if the WS run can be merged with the previous run then do so here */ + while(start>0 && levels[start-1]==paraLevel) { + --start; + } + + mTrailingWSStart=start; +} + +nsresult nsBidi::GetLevelAt(PRInt32 aCharIndex, nsBidiLevel* aLevel) +{ + /* return paraLevel if in the trailing WS run, otherwise the real level */ + if(aCharIndex<0 || mLength<=aCharIndex) { + *aLevel = 0; + } else if(mDirection!=NSBIDI_MIXED || aCharIndex>=mTrailingWSStart) { + *aLevel = mParaLevel; + } else { + *aLevel = mLevels[aCharIndex]; + } + return NS_OK; +} + +nsresult nsBidi::GetLevels(nsBidiLevel** aLevels) +{ + PRInt32 start, length; + + length = mLength; + if(length<=0) { + *aLevels = NULL; + return NS_ERROR_INVALID_ARG; + } + + start = mTrailingWSStart; + if(start==length) { + /* the current levels array reflects the WS run */ + *aLevels = mLevels; + return NS_OK; + } + + /* + * After the previous if(), we know that the levels array + * has an implicit trailing WS run and therefore does not fully + * reflect itself all the levels. + * This must be a nsBidi object for a line, and + * we need to create a new levels array. + */ + + if(GETLEVELSMEMORY(length)) { + nsBidiLevel *levels=mLevelsMemory; + + if(start>0 && levels!=mLevels) { + memcpy(levels, mLevels, start); + } + memset(levels+start, mParaLevel, length-start); + + /* this new levels array is set for the line and reflects the WS run */ + mTrailingWSStart=length; + *aLevels=mLevels=levels; + return NS_OK; + } else { + /* out of memory */ + *aLevels = NULL; + return NS_ERROR_OUT_OF_MEMORY; + } +} +#endif // FULL_BIDI_ENGINE + +nsresult nsBidi::GetCharTypeAt(PRInt32 aCharIndex, nsCharType* pType) +{ + if(aCharIndex<0 || mLength<=aCharIndex) { + return NS_ERROR_INVALID_ARG; + } + *pType = (nsCharType)mDirProps[aCharIndex]; + return NS_OK; +} + +nsresult nsBidi::GetLogicalRun(PRInt32 aLogicalStart, PRInt32 *aLogicalLimit, nsBidiLevel *aLevel) +{ + PRInt32 length = mLength; + + if(aLogicalStart<0 || length<=aLogicalStart) { + return NS_ERROR_INVALID_ARG; + } + + if(mDirection!=NSBIDI_MIXED || aLogicalStart>=mTrailingWSStart) { + if(aLogicalLimit!=NULL) { + *aLogicalLimit=length; + } + if(aLevel!=NULL) { + *aLevel=mParaLevel; + } + } else { + nsBidiLevel *levels=mLevels; + nsBidiLevel level=levels[aLogicalStart]; + + /* search for the end of the run */ + length=mTrailingWSStart; + while(++aLogicalStart=mRunCount + ) { + *aDirection = NSBIDI_LTR; + return NS_OK; + } else { + PRInt32 start=mRuns[aRunIndex].logicalStart; + if(aLogicalStart!=NULL) { + *aLogicalStart=GET_INDEX(start); + } + if(aLength!=NULL) { + if(aRunIndex>0) { + *aLength=mRuns[aRunIndex].visualLimit- + mRuns[aRunIndex-1].visualLimit; + } else { + *aLength=mRuns[0].visualLimit; + } + } + *aDirection = (nsBidiDirection)GET_ODD_BIT(start); + return NS_OK; + } +} + +/* compute the runs array --------------------------------------------------- */ + +/* + * Compute the runs array from the levels array. + * After GetRuns() returns PR_TRUE, runCount is guaranteed to be >0 + * and the runs are reordered. + * Odd-level runs have visualStart on their visual right edge and + * they progress visually to the left. + */ +PRBool nsBidi::GetRuns() +{ + if(mDirection!=NSBIDI_MIXED) { + /* simple, single-run case - this covers length==0 */ + GetSingleRun(mParaLevel); + } else /* NSBIDI_MIXED, length>0 */ { + /* mixed directionality */ + PRInt32 length=mLength, limit=length; + + /* + * If there are WS characters at the end of the line + * and the run preceding them has a level different from + * paraLevel, then they will form their own run at paraLevel (L1). + * Count them separately. + * We need some special treatment for this in order to not + * modify the levels array which a line nsBidi object shares + * with its paragraph parent and its other line siblings. + * In other words, for the trailing WS, it may be + * levels[]!=paraLevel but we have to treat it like it were so. + */ + limit=mTrailingWSStart; + if(limit==0) { + /* there is only WS on this line */ + GetSingleRun(mParaLevel); + } else { + nsBidiLevel *levels=mLevels; + PRInt32 i, runCount; + nsBidiLevel level=NSBIDI_DEFAULT_LTR; /* initialize with no valid level */ + + /* count the runs, there is at least one non-WS run, and limit>0 */ + runCount=0; + for(i=0; i1 || limit1 */ + if(GETRUNSMEMORY(runCount)) { + runs=mRunsMemory; + } else { + return PR_FALSE; + } + + /* set the runs */ + /* this could be optimized, e.g.: 464->444, 484->444, 575->555, 595->555 */ + /* however, that would take longer and make other functions more complicated */ + runIndex=0; + + /* search for the run ends */ + start=0; + level=levels[0]; + if(levelmaxLevel) { + maxLevel=level; + } + + /* initialize visualLimit values with the run lengths */ + for(i=1; imaxLevel) { + maxLevel=level; + } + ++runIndex; + } + } + + /* finish the last run at i==limit */ + runs[runIndex].logicalStart=start; + runs[runIndex].visualLimit=limit-start; + ++runIndex; + + if(limit1 and maxLevel>=minLevel>=paraLevel. + * All the visualStart fields=logical start before reordering. + * The "odd" bits are not set yet. + * + * Reordering with this data structure lends itself to some handy shortcuts: + * + * Since each run is moved but not modified, and since at the initial maxLevel + * each sequence of same-level runs consists of only one run each, we + * don't need to do anything there and can predecrement maxLevel. + * In many simple cases, the reordering is thus done entirely in the + * index mapping. + * Also, reordering occurs only down to the lowest odd level that occurs, + * which is minLevel|1. However, if the lowest level itself is odd, then + * in the last reordering the sequence of the runs at this level or higher + * will be all runs, and we don't need the elaborate loop to search for them. + * This is covered by ++minLevel instead of minLevel|=1 followed + * by an extra reorder-all after the reorder-some loop. + * About a trailing WS run: + * Such a run would need special treatment because its level is not + * reflected in levels[] if this is not a paragraph object. + * Instead, all characters from trailingWSStart on are implicitly at + * paraLevel. + * However, for all maxLevel>paraLevel, this run will never be reordered + * and does not need to be taken into account. maxLevel==paraLevel is only reordered + * if minLevel==paraLevel is odd, which is done in the extra segment. + * This means that for the main reordering loop we don't need to consider + * this run and can --runCount. If it is later part of the all-runs + * reordering, then runCount is adjusted accordingly. + */ +void nsBidi::ReorderLine(nsBidiLevel aMinLevel, nsBidiLevel aMaxLevel) +{ + Run *runs; + nsBidiLevel *levels; + PRInt32 firstRun, endRun, limitRun, runCount, + temp, trailingWSStart=mTrailingWSStart; + + /* nothing to do? */ + if(aMaxLevel<=(aMinLevel|1)) { + return; + } + + /* + * Reorder only down to the lowest odd level + * and reorder at an odd aMinLevel in a separate, simpler loop. + * See comments above for why aMinLevel is always incremented. + */ + ++aMinLevel; + + runs=mRuns; + levels=mLevels; + runCount=mRunCount; + + /* do not include the WS run at paraLevel<=old aMinLevel except in the simple loop */ + if(mTrailingWSStart=aMinLevel) { + firstRun=0; + + /* loop for all sequences of runs */ + for(;;) { + /* look for a sequence of runs that are all at >=aMaxLevel */ + /* look for the first run of such a sequence */ + while(firstRun=runCount) { + break; /* no more such runs */ + } + + /* look for the limit run of such a sequence (the run behind it) */ + for(limitRun=firstRun; ++limitRun=aMaxLevel;) {} + + /* Swap the entire sequence of runs from firstRun to limitRun-1. */ + endRun=limitRun-1; + while(firstRun=maxLevel */ + /* look for the first index of such a sequence */ + while(start=aLength) { + break; /* no more such runs */ + } + + /* look for the limit of such a sequence (the index behind it) */ + for(limit=start; ++limit=maxLevel;) {} + + /* + * Swap the entire interval of indexes from start to limit-1. + * We don't need to swap the levels for the purpose of this + * algorithm: the sequence of levels that we look at does not + * move anyway. + */ + end=limit-1; + while(start=minLevel); + + return NS_OK; +} + +PRBool nsBidi::PrepareReorder(const nsBidiLevel *aLevels, PRInt32 aLength, + PRInt32 *aIndexMap, + nsBidiLevel *aMinLevel, nsBidiLevel *aMaxLevel) +{ + PRInt32 start; + nsBidiLevel level, minLevel, maxLevel; + + if(aLevels==NULL || aLength<=0) { + return PR_FALSE; + } + + /* determine minLevel and maxLevel */ + minLevel=NSBIDI_MAX_EXPLICIT_LEVEL+1; + maxLevel=0; + for(start=aLength; start>0;) { + level=aLevels[--start]; + if(level>NSBIDI_MAX_EXPLICIT_LEVEL+1) { + return PR_FALSE; + } + if(levelmaxLevel) { + maxLevel=level; + } + } + *aMinLevel=minLevel; + *aMaxLevel=maxLevel; + + /* initialize the index map */ + for(start=aLength; start>0;) { + --start; + aIndexMap[start]=start; + } + + return PR_TRUE; +} + +#ifdef FULL_BIDI_ENGINE +/* API functions for logical<->visual mapping ------------------------------- */ + +nsresult nsBidi::GetVisualIndex(PRInt32 aLogicalIndex, PRInt32* aVisualIndex) { + if(aLogicalIndex<0 || mLength<=aLogicalIndex) { + return NS_ERROR_INVALID_ARG; + } else { + /* we can do the trivial cases without the runs array */ + switch(mDirection) { + case NSBIDI_LTR: + *aVisualIndex = aLogicalIndex; + return NS_OK; + case NSBIDI_RTL: + *aVisualIndex = mLength-aLogicalIndex-1; + return NS_OK; + default: + if(mRunCount<0 && !GetRuns()) { + return NS_ERROR_OUT_OF_MEMORY; + } else { + Run *runs=mRuns; + PRInt32 i, visualStart=0, offset, length; + + /* linear search for the run, search on the visual runs */ + for(i=0;; ++i) { + length=runs[i].visualLimit-visualStart; + offset=aLogicalIndex-GET_INDEX(runs[i].logicalStart); + if(offset>=0 && offset=runs[i].visualLimit; ++i) {} + } else { + /* binary search for the run */ + PRInt32 start=0, limit=runCount; + + /* the middle if() will guaranteed find the run, we don't need a loop limit */ + for(;;) { + i=(start+limit)/2; + if(aVisualIndex>=runs[i].visualLimit) { + start=i+1; + } else if(i==0 || aVisualIndex>=runs[i-1].visualLimit) { + break; + } else { + limit=i; + } + } + } + + start=runs[i].logicalStart; + if(IS_EVEN_RUN(start)) { + /* LTR */ + /* the offset in runs[i] is aVisualIndex-runs[i-1].visualLimit */ + if(i>0) { + aVisualIndex-=runs[i-1].visualLimit; + } + *aLogicalIndex = GET_INDEX(start)+aVisualIndex; + return NS_OK; + } else { + /* RTL */ + *aLogicalIndex = GET_INDEX(start)+runs[i].visualLimit-aVisualIndex-1; + return NS_OK; + } + } + } + } +} + +nsresult nsBidi::GetLogicalMap(PRInt32 *aIndexMap) +{ + nsBidiLevel *levels; + nsresult rv; + + /* GetLevels() checks all of its and our arguments */ + rv = GetLevels(&levels); + if(NS_FAILED(rv)) { + return rv; + } else if(aIndexMap==NULL) { + return NS_ERROR_INVALID_ARG; + } else { + return ReorderLogical(levels, mLength, aIndexMap); + } +} + +nsresult nsBidi::GetVisualMap(PRInt32 *aIndexMap) +{ + PRInt32* runCount=NULL; + nsresult rv; + + /* CountRuns() checks all of its and our arguments */ + rv = CountRuns(runCount); + if(NS_FAILED(rv)) { + return rv; + } else if(aIndexMap==NULL) { + return NS_ERROR_INVALID_ARG; + } else { + /* fill a visual-to-logical index map using the runs[] */ + Run *runs=mRuns, *runsLimit=runs+mRunCount; + PRInt32 logicalStart, visualStart, visualLimit; + + visualStart=0; + for(; runslogicalStart; + visualLimit=runs->visualLimit; + if(IS_EVEN_RUN(logicalStart)) { + do { /* LTR */ + *aIndexMap++ = logicalStart++; + } while(++visualStart=maxLevel */ + /* look for the first index of such a sequence */ + while(start=aLength) { + break; /* no more such sequences */ + } + + /* look for the limit of such a sequence (the index behind it) */ + for(limit=start; ++limit=maxLevel;) {} + + /* + * sos=start of sequence, eos=end of sequence + * + * The closed (inclusive) interval from sos to eos includes all the logical + * and visual indexes within this sequence. They are logically and + * visually contiguous and in the same range. + * + * For each run, the new visual index=sos+eos-old visual index; + * we pre-add sos+eos into sumOfSosEos -> + * new visual index=sumOfSosEos-old visual index; + */ + sumOfSosEos=start+limit-1; + + /* reorder each index in the sequence */ + do { + aIndexMap[start]=sumOfSosEos-aIndexMap[start]; + } while(++start=minLevel); + + return NS_OK; +} + +nsresult nsBidi::InvertMap(const PRInt32 *aSrcMap, PRInt32 *aDestMap, PRInt32 aLength) +{ + if(aSrcMap!=NULL && aDestMap!=NULL) { + aSrcMap+=aLength; + while(aLength>0) { + aDestMap[*--aSrcMap]=--aLength; + } + } + return NS_OK; +} + +#endif // FULL_BIDI_ENGINE +PRInt32 nsBidi::doWriteReverse(const PRUnichar *src, PRInt32 srcLength, + PRUnichar *dest, PRUint16 options) { + /* + * RTL run - + * + * RTL runs need to be copied to the destination in reverse order + * of code points, not code units, to keep Unicode characters intact. + * + * The general strategy for this is to read the source text + * in backward order, collect all code units for a code point + * (and optionally following combining characters, see below), + * and copy all these code units in ascending order + * to the destination for this run. + * + * Several options request whether combining characters + * should be kept after their base characters, + * whether Bidi control characters should be removed, and + * whether characters should be replaced by their mirror-image + * equivalent Unicode characters. + */ + PRInt32 i, j, destSize; + PRUint32 c; + + /* optimize for several combinations of options */ + switch(options&(NSBIDI_REMOVE_BIDI_CONTROLS|NSBIDI_DO_MIRRORING|NSBIDI_KEEP_BASE_COMBINING)) { + case 0: + /* + * With none of the "complicated" options set, the destination + * run will have the same length as the source run, + * and there is no mirroring and no keeping combining characters + * with their base characters. + */ + destSize=srcLength; + + /* preserve character integrity */ + do { + /* i is always after the last code unit known to need to be kept in this segment */ + i=srcLength; + + /* collect code units for one base character */ + UTF_BACK_1(src, 0, srcLength); + + /* copy this base character */ + j=srcLength; + do { + *dest++=src[j++]; + } while(j0); + break; + case NSBIDI_KEEP_BASE_COMBINING: + /* + * Here, too, the destination + * run will have the same length as the source run, + * and there is no mirroring. + * We do need to keep combining characters with their base characters. + */ + destSize=srcLength; + + /* preserve character integrity */ + do { + /* i is always after the last code unit known to need to be kept in this segment */ + i=srcLength; + + /* collect code units and modifier letters for one base character */ + do { + UTF_PREV_CHAR(src, 0, srcLength, c); + } while(srcLength>0 && IsBidiCategory(c, eBidiCat_NSM)); + + /* copy this "user character" */ + j=srcLength; + do { + *dest++=src[j++]; + } while(j0); + break; + default: + /* + * With several "complicated" options set, this is the most + * general and the slowest copying of an RTL run. + * We will do mirroring, remove Bidi controls, and + * keep combining characters with their base characters + * as requested. + */ + if(!(options&NSBIDI_REMOVE_BIDI_CONTROLS)) { + i=srcLength; + } else { + /* we need to find out the destination length of the run, + which will not include the Bidi control characters */ + PRInt32 length=srcLength; + PRUnichar ch; + + i=0; + do { + ch=*src++; + if (!IsBidiControl(ch)) { + ++i; + } + } while(--length>0); + src-=srcLength; + } + destSize=i; + + /* preserve character integrity */ + do { + /* i is always after the last code unit known to need to be kept in this segment */ + i=srcLength; + + /* collect code units for one base character */ + UTF_PREV_CHAR(src, 0, srcLength, c); + if(options&NSBIDI_KEEP_BASE_COMBINING) { + /* collect modifier letters for this base character */ + while(srcLength>0 && IsBidiCategory(c, eBidiCat_NSM)) { + UTF_PREV_CHAR(src, 0, srcLength, c); + } + } + + if(options&NSBIDI_REMOVE_BIDI_CONTROLS && IsBidiControl(c)) { + /* do not copy this Bidi control character */ + continue; + } + + /* copy this "user character" */ + j=srcLength; + if(options&NSBIDI_DO_MIRRORING) { + /* mirror only the base character */ + c = SymmSwap((PRUnichar)c); + + PRInt32 k=0; + UTF_APPEND_CHAR_UNSAFE(dest, k, c); + dest+=k; + j+=k; + } + while(j0); + break; + } /* end of switch */ + return destSize; +} + +nsresult nsBidi::WriteReverse(const PRUnichar *aSrc, PRInt32 aSrcLength, PRUnichar *aDest, PRUint16 aOptions, PRInt32 *aDestSize) +{ + if( aSrc==NULL || aSrcLength<0 || + aDest==NULL + ) { + return NS_ERROR_INVALID_ARG; + } + + /* do input and output overlap? */ + if( aSrc>=aDest && aSrc=aSrc && aDest0) { + *aDestSize = doWriteReverse(aSrc, aSrcLength, aDest, aOptions); + } + return NS_OK; +} + +eBidiCategory nsBidi::GetBidiCategory(PRUnichar aChar) +{ + eBidiCategory oResult = GetBidiCat(aChar); + if (eBidiCat_CC == oResult) + oResult = (eBidiCategory)(aChar & 0xFF); /* Control codes have special treatment to keep the tables smaller */ + return oResult; +} + +PRBool nsBidi::IsBidiCategory(PRUnichar aChar, eBidiCategory aBidiCategory) +{ + return (GetBidiCategory(aChar) == aBidiCategory); +} + +#define LRM_CHAR 0x200e +PRBool nsBidi::IsBidiControl(PRUnichar aChar) +{ + // This method is used when stripping Bidi control characters for + // display, so it will return TRUE for LRM and RLM as well as the + // characters with category eBidiCat_CC + return (eBidiCat_CC == GetBidiCat(aChar) || ((aChar)&0xfffe)==LRM_CHAR); +} + +nsCharType nsBidi::GetCharType(PRUnichar aChar) +{ + nsCharType oResult; + eBidiCategory bCat = GetBidiCat(aChar); + if (eBidiCat_CC != bCat) { + NS_ASSERTION(bCat < (sizeof(ebc2ucd)/sizeof(nsCharType)), "size mismatch"); + if(bCat < (sizeof(ebc2ucd)/sizeof(nsCharType))) + oResult = ebc2ucd[bCat]; + else + oResult = ebc2ucd[0]; // something is very wrong, but we need to return a value + } else { + NS_ASSERTION((aChar-0x202a) < (sizeof(cc2ucd)/sizeof(nsCharType)), "size mismatch"); + if((aChar-0x202a) < (sizeof(cc2ucd)/sizeof(nsCharType))) + oResult = cc2ucd[aChar - 0x202a]; + else + oResult = ebc2ucd[0]; // something is very wrong, but we need to return a value + } + return oResult; +} + +PRUnichar nsBidi::SymmSwap(PRUnichar aChar) +{ + return Mirrored(aChar); +} + +#endif // IBMBIDI diff --git a/mozilla/layout/base/src/nsBidiPresUtils.cpp b/mozilla/layout/base/src/nsBidiPresUtils.cpp index fff7325a3e6..71467878d8e 100644 --- a/mozilla/layout/base/src/nsBidiPresUtils.cpp +++ b/mozilla/layout/base/src/nsBidiPresUtils.cpp @@ -49,7 +49,7 @@ #include "nsIFrameManager.h" #include "nsBidiFrames.h" #include "nsITextFrame.h" -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" static const PRUnichar kSpace = 0x0020; static const PRUnichar kLineSeparator = 0x2028; @@ -64,6 +64,19 @@ static const PRUnichar kPDF = 0x202C; static const PRUnichar ALEF = 0x05D0; #endif +#define CHAR_IS_HEBREW(c) ((0x0590 <= (c)) && ((c)<= 0x05FF)) +// Note: The above code are moved from gfx/src/windows/nsRenderingContextWin.cpp + +#define ARABIC_TO_HINDI_DIGIT_INCREMENT (START_HINDI_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)) +#define NUM_TO_HINDI(c) \ + ((((c)>=START_ARABIC_DIGITS) && ((c)<=END_ARABIC_DIGITS)) ? \ + ((c) + (PRUint16)ARABIC_TO_HINDI_DIGIT_INCREMENT): \ + (c)) + extern nsresult NS_NewContinuingTextFrame(nsIPresShell* aPresShell, nsIFrame** aResult); extern nsresult @@ -73,10 +86,9 @@ nsBidiPresUtils::nsBidiPresUtils() : mArraySize(8), mIndexMap(nsnull), mLevels(nsnull), mSuccess(NS_ERROR_FAILURE), - mBidiEngine(nsnull), - mUnicodeUtils(nsnull) + mBidiEngine(nsnull) { - mBidiEngine = do_GetService("@mozilla.org/intl/bidi;1"); + mBidiEngine = new nsBidi(); if (mBidiEngine) { mSuccess = NS_OK; } @@ -861,12 +873,6 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, PRBool aIsBidiSystem) { nsresult rv = NS_OK; - if (!mUnicodeUtils) { - mUnicodeUtils = do_GetService("@mozilla.org/intl/unicharbidiutil;1"); - if (!mUnicodeUtils) { - return NS_ERROR_FAILURE; - } - } // ahmed //adjusted for correct numeral shaping PRUint32 bidiOptions; @@ -874,11 +880,11 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, switch (GET_BIDI_OPTION_NUMERAL(bidiOptions)) { case IBMBIDI_NUMERAL_HINDI: - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); break; case IBMBIDI_NUMERAL_ARABIC: - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); break; case IBMBIDI_NUMERAL_REGULAR: @@ -886,11 +892,11 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, switch (aCharType) { case eCharType_EuropeanNumber: - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); break; case eCharType_ArabicNumber: - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); break; default: @@ -900,9 +906,9 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, case IBMBIDI_NUMERAL_HINDICONTEXT: if ( ( (GET_BIDI_OPTION_DIRECTION(bidiOptions)==IBMBIDI_TEXTDIRECTION_RTL) && (IS_ARABIC_DIGIT (aText[0])) ) || (eCharType_ArabicNumber == aCharType) ) - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_HINDI); else if (eCharType_EuropeanNumber == aCharType) - mUnicodeUtils->HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); + HandleNumbers(aText,aTextLength,IBMBIDI_NUMERAL_ARABIC); break; default: @@ -940,7 +946,7 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext, } } if (doShape) { - rv = mUnicodeUtils->ArabicShaping(aText, aTextLength, buffer, (PRUint32 *)&newLen); + rv = ArabicShaping(aText, aTextLength, buffer, (PRUint32 *)&newLen); if (NS_SUCCEEDED(rv) ) { aTextLength = newLen; memcpy(aText, buffer, aTextLength * sizeof(PRUnichar) ); @@ -1044,12 +1050,11 @@ nsBidiPresUtils::CalculateCharType(PRInt32& aOffset, aOffset = offset; } -nsresult nsBidiPresUtils::GetBidiEngine(nsIBidi** aBidiEngine) +nsresult nsBidiPresUtils::GetBidiEngine(nsBidi** aBidiEngine) { nsresult rv = NS_ERROR_FAILURE; if (mBidiEngine) { *aBidiEngine = mBidiEngine; - NS_ADDREF(*aBidiEngine); rv = NS_OK; } return rv; @@ -1136,4 +1141,40 @@ nsresult nsBidiPresUtils::RenderText(PRUnichar* aText, return NS_OK; } +nsresult nsBidiPresUtils::HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag) +{ + PRUint32 i; + // IBMBIDI_NUMERAL_REGULAR * + // IBMBIDI_NUMERAL_HINDICONTEXT + // IBMBIDI_NUMERAL_ARABIC + // IBMBIDI_NUMERAL_HINDI + mNumflag=aNumFlag; + + switch (aNumFlag) { + case IBMBIDI_NUMERAL_HINDI: + for (i=0;iIsArabicEncoding(arabicCharset); if (arabicCharset) { - nsCOMPtr bidiUtils = do_GetService("@mozilla.org/intl/unicharbidiutil;1"); + nsBidiPresUtils* bidiUtils; PRUint32 bidiOptions; PRBool isVisual; PRBool isBidiSystem; - + + context->GetBidiUtils(&bidiUtils); context->GetBidi(&bidiOptions); context->IsVisualMode(isVisual); context->GetIsBidiSystem(isBidiSystem); @@ -147,10 +149,10 @@ nsresult nsCopySupport::HTMLCopy(nsISelection *aSel, nsIDocument *aDoc, PRInt16 nsAutoString newBuffer; if (isBidiSystem) { if (GET_BIDI_OPTION_DIRECTION(bidiOptions) == IBMBIDI_TEXTDIRECTION_RTL) { - bidiUtils->Conv_FE_06(buffer, newBuffer); + Conv_FE_06(buffer, newBuffer); } else { - bidiUtils->Conv_FE_06_WithReverse(buffer, newBuffer); + Conv_FE_06_WithReverse(buffer, newBuffer); } } else { //nonbidisystem @@ -165,7 +167,7 @@ nsresult nsCopySupport::HTMLCopy(nsISelection *aSel, nsIDocument *aDoc, PRInt16 if (bidiCharset.EqualsIgnoreCase("UTF-8") || (!isVisual)) { if ( (GET_BIDI_OPTION_CLIPBOARDTEXTMODE(bidiOptions) == IBMBIDI_CLIPBOARDTEXTMODE_VISUAL) || (!isBidiSystem) ) { nsAutoString newBuffer; - bidiUtils->Conv_06_FE_WithReverse(buffer, newBuffer, GET_BIDI_OPTION_DIRECTION(bidiOptions)); + Conv_06_FE_WithReverse(buffer, newBuffer, GET_BIDI_OPTION_DIRECTION(bidiOptions)); bidiUtils->HandleNumbers(newBuffer, buffer); } } diff --git a/mozilla/layout/base/src/nsPresContext.h b/mozilla/layout/base/src/nsPresContext.h index 4b7042cf95c..6a93504dc18 100644 --- a/mozilla/layout/base/src/nsPresContext.h +++ b/mozilla/layout/base/src/nsPresContext.h @@ -51,7 +51,7 @@ #include "nsIObserver.h" #include "nsILookAndFeel.h" #ifdef IBMBIDI -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" #endif #include "nsHashtable.h" diff --git a/mozilla/intl/unicharutil/src/symmtable.h b/mozilla/layout/base/src/symmtable.h similarity index 100% rename from mozilla/intl/unicharutil/src/symmtable.h rename to mozilla/layout/base/src/symmtable.h diff --git a/mozilla/layout/base/symmtable.h b/mozilla/layout/base/symmtable.h new file mode 100644 index 00000000000..36345898a58 --- /dev/null +++ b/mozilla/layout/base/symmtable.h @@ -0,0 +1,151 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is IBM code. + * + * The Initial Developer of the Original Code is IBM. + * Portions created by IBM are + * Copyright (C) International Business Machines + * Corporation, 2000. All Rights Reserved. + */ +/* + DO NOT EDIT THIS DOCUMENT !!! THIS DOCUMENT IS GENERATED BY + mozilla/intl/unicharutil/tools/gensymmtable.pl + */ + +/* Block U00__ */ +const static PRUint8 symmtable_00[256] = { +/* _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _A _B _C _D _E _F */ +/* 0_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 1_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 2_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0x1, 0x1, 0, 0, 0, 0, 0, 0, +/* 3_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2, 0, 0x2, 0, +/* 4_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 5_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x6, 0, 0x6, 0, 0, +/* 6_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 7_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x6, 0, 0x6, 0, 0, +/* 8_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 9_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* A_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10, 0, 0, 0, 0, +/* B_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10, 0, 0, 0, 0, +/* C_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* D_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* E_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* F_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + +/* Block U20__ */ +const static PRUint8 symmtable_20[256] = { +/* _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _A _B _C _D _E _F */ +/* 0_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 1_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 2_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 3_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x3, 0x3, 0, 0, 0, 0, 0, +/* 4_ */ 0, 0, 0, 0, 0, 0x3, 0x3, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 5_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 6_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 7_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x3, 0x3, 0, +/* 8_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x3, 0x3, 0, +/* 9_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* A_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* B_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* C_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* D_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* E_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* F_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + +/* Block U22__ */ +const static PRUint8 symmtable_22[256] = { +/* _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _A _B _C _D _E _F */ +/* 0_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0x3, 0x5, 0x7, 0x3, 0x5, 0x7, 0, 0, +/* 1_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 2_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 3_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1, 0x1, 0, 0, +/* 4_ */ 0, 0, 0, 0x8e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 5_ */ 0, 0, 0x1, 0x1, 0x1, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 6_ */ 0, 0, 0, 0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0, 0, 0x1, 0x1, +/* 7_ */ 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, +/* 8_ */ 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0, 0, 0, 0x1f, +/* 9_ */ 0x1f, 0x3, 0x3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* A_ */ 0, 0, 0x1, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* B_ */ 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, +/* C_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x3, 0x3, 0x7, 0x7, 0x8e, 0, 0, +/* D_ */ 0x1, 0x1, 0, 0, 0, 0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, +/* E_ */ 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0, 0, +/* F_ */ 0x1, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + +/* Block U23__ */ +const static PRUint8 symmtable_23[256] = { +/* _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _A _B _C _D _E _F */ +/* 0_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0x1, 0x1, 0x1, 0x1, 0, 0, 0, 0, +/* 1_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 2_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x3, 0x3, 0, 0, 0, 0, 0, +/* 3_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 4_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 5_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 6_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 7_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 8_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 9_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* A_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* B_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* C_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* D_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* E_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* F_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + +/* Block U30__ */ +const static PRUint8 symmtable_30[256] = { +/* _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _A _B _C _D _E _F */ +/* 0_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, +/* 1_ */ 0x1, 0x1, 0, 0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0, 0, 0, 0, +/* 2_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 3_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 4_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 5_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 6_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 7_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 8_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 9_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* A_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* B_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* C_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* D_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* E_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* F_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + +static PRUnichar Mirrored(PRUnichar u) +{ + switch (u & 0xFF00) { + // XOR the character with the bitmap in the conversion table to give the symmetric equivalent + case 0: + u ^= symmtable_00[u & 0xff]; + break; + case 0x2000: + u ^= symmtable_20[u & 0xff]; + break; + case 0x2200: + u ^= symmtable_22[u & 0xff]; + break; + case 0x2300: + u ^= symmtable_23[u & 0xff]; + break; + case 0x3000: + u ^= symmtable_30[u & 0xff]; + break; + } + return u; +} diff --git a/mozilla/layout/generic/nsLineLayout.cpp b/mozilla/layout/generic/nsLineLayout.cpp index bcd5cef6ea0..6b8f5993d47 100644 --- a/mozilla/layout/generic/nsLineLayout.cpp +++ b/mozilla/layout/generic/nsLineLayout.cpp @@ -62,7 +62,7 @@ #include "nsHTMLAtoms.h" #include "nsTextFragment.h" #ifdef IBMBIDI -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" #include "nsIFormControlFrame.h" #include "nsITextFrame.h" #define FIX_FOR_BUG_40882 diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 959513d786a..d622e1fdaf9 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -97,7 +97,7 @@ #include "nsITextFrame.h" //ahmed -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" //ahmed end #endif // IBMBIDI diff --git a/mozilla/layout/html/base/src/nsLineLayout.cpp b/mozilla/layout/html/base/src/nsLineLayout.cpp index bcd5cef6ea0..6b8f5993d47 100644 --- a/mozilla/layout/html/base/src/nsLineLayout.cpp +++ b/mozilla/layout/html/base/src/nsLineLayout.cpp @@ -62,7 +62,7 @@ #include "nsHTMLAtoms.h" #include "nsTextFragment.h" #ifdef IBMBIDI -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" #include "nsIFormControlFrame.h" #include "nsITextFrame.h" #define FIX_FOR_BUG_40882 diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 959513d786a..d622e1fdaf9 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -97,7 +97,7 @@ #include "nsITextFrame.h" //ahmed -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" //ahmed end #endif // IBMBIDI diff --git a/mozilla/layout/html/forms/src/nsFormFrame.cpp b/mozilla/layout/html/forms/src/nsFormFrame.cpp index c4b1b10c851..53bbbe42e01 100644 --- a/mozilla/layout/html/forms/src/nsFormFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFormFrame.cpp @@ -96,13 +96,6 @@ PRBool nsFormFrame::gInitPasswordManager = PR_FALSE; //---------------------------------------------------------------------- -//ahmed 15-1 -#ifdef IBMBIDI -#include "nsIUBidiUtils.h" -//static NS_DEFINE_CID(kUBidiUtilCID, NS_UNICHARBIDIUTIL_CID); -#endif -//end - NS_IMETHODIMP nsFormFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr) { diff --git a/mozilla/layout/macbuild/layout.xml b/mozilla/layout/macbuild/layout.xml index b683932b7f4..17ef3745a97 100644 --- a/mozilla/layout/macbuild/layout.xml +++ b/mozilla/layout/macbuild/layout.xml @@ -2026,6 +2026,13 @@ Text Debug + + Name + nsBidi.cpp + MacOS + Text + Debug + Name nsBidiFrames.cpp @@ -2970,6 +2977,11 @@ nsBidiPresUtils.cpp MacOS + + Name + nsBidi.cpp + MacOS + Name nsBidiFrames.cpp @@ -5045,6 +5057,13 @@ Text Debug + + Name + nsBidi.cpp + MacOS + Text + Debug + Name nsBidiFrames.cpp @@ -5989,6 +6008,11 @@ nsBidiPresUtils.cpp MacOS + + Name + nsBidi.cpp + MacOS + Name nsBidiFrames.cpp @@ -6232,6 +6256,12 @@ nsBidiPresUtils.cpp MacOS + + layout.shlb + Name + nsBidi.cpp + MacOS + build diff --git a/mozilla/layout/style/nsStyleContext.cpp b/mozilla/layout/style/nsStyleContext.cpp index f8ce6021ebd..3badfe8fc8b 100644 --- a/mozilla/layout/style/nsStyleContext.cpp +++ b/mozilla/layout/style/nsStyleContext.cpp @@ -55,10 +55,6 @@ #include "nsRuleNode.h" -#ifdef IBMBIDI -#include "nsIUBidiUtils.h" -#endif - #ifdef DEBUG // #define NOISY_DEBUG #endif diff --git a/mozilla/layout/style/nsStyleStruct.cpp b/mozilla/layout/style/nsStyleStruct.cpp index 4efb4816291..59fbef0e21f 100644 --- a/mozilla/layout/style/nsStyleStruct.cpp +++ b/mozilla/layout/style/nsStyleStruct.cpp @@ -53,7 +53,7 @@ #include "prenv.h" #ifdef IBMBIDI -#include "nsIUBidiUtils.h" +#include "nsBidiUtils.h" #endif inline PRBool IsFixedUnit(nsStyleUnit aUnit, PRBool aEnumOK) diff --git a/mozilla/intl/unicharutil/tools/BidiMirroring.txt b/mozilla/layout/tools/BidiMirroring.txt similarity index 100% rename from mozilla/intl/unicharutil/tools/BidiMirroring.txt rename to mozilla/layout/tools/BidiMirroring.txt diff --git a/mozilla/intl/unicharutil/tools/genbidicattable.pl b/mozilla/layout/tools/genbidicattable.pl similarity index 94% rename from mozilla/intl/unicharutil/tools/genbidicattable.pl rename to mozilla/layout/tools/genbidicattable.pl index e814a88c37f..9638e75bab2 100644 --- a/mozilla/intl/unicharutil/tools/genbidicattable.pl +++ b/mozilla/layout/tools/genbidicattable.pl @@ -1,345 +1,343 @@ -#!/usr/local/bin/perl -# -# The contents of this file are subject to the Mozilla Public -# License Version 1.1 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS -# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -# implied. See the License for the specific language governing -# rights and limitations under the License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is IBM -# Corporation. Portions created by IBM are -# Copyright (C) 2000 IBM Corporation. All -# Rights Reserved. -# -# Contributor(s): -# - -###################################################################### -# -# Initial global variable -# -###################################################################### - -%gcount = (); -%pat = (); - -%map = ( - "L" => "1", # Left-to-Right - "R" => "2", # Right-to-Left - "AL" => "3", # Right-to-Left Arabic - "AN" => "4", # Arabic Number - "EN" => "5", # European Number - "ES" => "6", # European Number Separator - "ET" => "7", # European Number Terminator - "CS" => "8", # Common Number Separator - "ON" => "9", # Other Neutrals - "NSM" => "10", # Non-Spacing Mark - "BN" => "11", # Boundary Neutral - "B" => "12", # Paragraph Separator - "S" => "13", # Segment Separator - "WS" => "14", # Whitespace - "LRE" => "15", # Left-to-Right Embedding - "RLE" => "15", # Right-to-Left Embedding - "PDF" => "15", # Pop Directional Format - "LRO" => "15", # Left-to-Right Override - "RLO" => "15" # Right-to-Left Override -); - -%special = (); - -###################################################################### -# -# Open the unicode database file -# -###################################################################### -open ( UNICODATA , "< UnicodeData-Latest.txt") - || die "cannot find UnicodeData-Latest.txt"; - -###################################################################### -# -# Open the output file -# -###################################################################### -open ( OUT , "> ../src/bidicattable.h") - || die "cannot open output ../src/bidicattable.h file"; - -###################################################################### -# -# Generate license and header -# -###################################################################### -$npl = <) { - chop; - ###################################################################### - # - # Get value from fields - # - ###################################################################### - @f = split(/;/ , $_); - $c = $f[0]; # The unicode value - $n = $f[1]; # The unicode name - $g = $f[2]; # The General Category - $b = $f[4]; # The Bidi Category - - if(( substr($n, 0, 1) ne "<") || ($n eq "")) - { - # - # print $g; - # - - $gcount{$b}++; - $bidicategory{$c} = $b; - } else { - - # Handle special block - @pair=split(/, /, $n ); - $catnum = $map{$b}; - - # printf "[%s][%s] => %d\n", $pair[0], $pair[1], $catnum; - if( $pair[1] eq "First>") { - $sl{$pair[0]} = $c; - $sc{$pair[0]} = $catnum; - } elsif ( $pair[1] eq "Last>") { - $sh{$pair[0]} = $c; - if($sc{$pair[0]} ne $catnum) - { - print "WARNING !!!! error in handling special block\n\n"; - } - } else { - print "WARNING !!!! error in handling special block\n\n"; - } - } -} - -# XXX - How can this be made more flexible as new blocks are added to the UCDB? - -@range = ( - 0x0000, 0x07ff, - 0x0900, 0x18ff, - 0x1e00, 0x28ff, - 0x2e80, 0x33ff, - 0xa000, 0xa4ff, - 0xf900, 0xffff -); - - -$totaldata = 0; - -$tt=($#range+1) / 2; -@patarray = (); - - -# This should improve performance: put all the patterns like 0x11111111, 0x22222222 etc at the beginning of the table. -# Since there are a lot of blocks with the same category, we should be able to save a lot of time extracting the digits -for (0..15) { - $pattern = "0x".(sprintf("%X", $_) x 8); - $patarray[$_] = $pattern; - $pat{$pattern} = $_; -} - -$newidx = 0x10; - -for($t = 1; $t <= $tt; $t++) -{ - $tl = $range[($t-1) * 2]; - $th = $range[($t-1) * 2 + 1]; - $ts = ( $th - $tl ) >> 3; - $totaldata += $ts + 1; - printf OUT "static PRUint8 gBidiCatIdx%d[%d] = {\n", $t, $ts + 1; - for($i = ($tl >> 3); $i <= ($th >> 3) ; $i ++ ) - { - $data = 0; - - for($j = 0; $j < 8 ; $j++) - { - #defaults for unassigned characters -- see table 3.7 in the Unicode Bidi Algorithm - $test = ($i << 3) + $j; - if ((($test >= 0x0590) && ($test <= 0x5FF)) - || (($test >= 0xFB1D) && ($test <= 0xFB4F))) - { - $default = $map{"R"}; - } elsif ((($test >= 0x0600) && ($test <= 0x7BF)) - || (($test >= 0xFB50) && ($test <= 0xFDFF)) - || (($test >= 0xFE70) && ($test <= 0xFEFF))) - { - $default = $map{"AL"}; - } else - { - $default = $map{"L"}; - } - $k = sprintf("%04X", (($i << 3) + $j)); - - $cat = $bidicategory{$k}; - if( $cat eq "") - { - $data = $data + ($default << (4*$j)); - } else { - $data = $data + ($map{$cat} << (4*$j)); - } - - } - $pattern = sprintf("0x%08X", $data); - - $idx = $pat{$pattern}; - unless( exists($pat{$pattern})){ - $idx = $newidx++; - $patarray[$idx] = $pattern; - $pat{$pattern} = $idx; - } - - printf OUT " %3d, /* U+%04X - U+%04X : %s */\n" , - $idx, ($i << 3),((($i +1)<< 3)-1), $pattern ; - - - } - printf OUT "};\n\n"; - - if($t ne $tt) - { - $tl = $range[($t-1) * 2 + 1] + 1; - $th = $range[$t * 2] - 1; - for($i = ($tl >> 3); $i <= ($th >> 3) ; $i ++ ) - { - $data = 0; - for($j = 0; $j < 8 ; $j++) - { - $k = sprintf("%04X", (($i << 3) + $j)); - - $cat = $bidicategory{$k}; - if( $cat ne "") - { - $data = $data + ($map{$cat} << (4*$j)); - } - } - $pattern = sprintf("0x%08X", $data); - if($data ne 0) - { - print "WARNING, Unicode Database now contain characters" . - "which we have not consider, change this program !!!\n\n"; - printf "Problem- U+%04X - U+%04X range\n", ($i << 3),((($i +1)<< 3)-1); - } - } - } -} - - -if($newidx > 255) -{ - die "We have more than 255 patterns !!! - $newidx\n\n" . - "This program is now broken!!!\n\n\n"; - -} -printf OUT "static PRUint32 gBidiCatPat[$newidx] = {\n"; -for($i = 0 ; $i < $newidx; $i++) -{ - printf OUT " %s, /* $i */\n", $patarray[$i] ; -} -printf OUT "};\n\n"; -$totaldata += $newidx * 4; - -printf OUT "static eBidiCategory GetBidiCat(PRUnichar u)\n{\n"; -printf OUT " PRUint32 pat;\n"; -printf OUT " PRUint16 patidx;\n\n"; -printf OUT " /* Handle blocks which use index table mapping */ \n\n"; -for($t = 1; $t <= $tt; $t++) -{ - $tl = $range[($t-1) * 2]; - $th = $range[($t-1) * 2 + 1]; - if ($tl == 0) { - printf OUT " /* Handle U+%04X to U+%04X */\n", $tl, $th; - printf OUT " if (u<=((PRUnichar)0x%04X)) {\n", $th; - printf OUT " patidx = gBidiCatIdx%d [( u >> 3 )];\n", $t; - } elsif ($th == 0xFFFF) { - printf OUT " /* Handle U+%04X to U+%04X */\n", $tl, $th; - printf OUT " if (((PRUnichar)0x%04X)<=u) {\n", $tl; - printf OUT " patidx = gBidiCatIdx%d [( (u -(PRUnichar) 0x%04X) >> 3 )];\n", $t, $tl; - } else { - printf OUT " /* Handle U+%04X to U+%04X */\n", $tl, $th; - printf OUT " if ((((PRUnichar)0x%04X)<=u)&&(u<=((PRUnichar)0x%04X))) {\n", $tl, $th; - printf OUT " patidx = gBidiCatIdx%d [( (u -(PRUnichar) 0x%04X) >> 3 )];\n", $t, $tl; - } - printf OUT " if (patidx < 0x10)\n"; - printf OUT " return (eBidiCategory)patidx;\n"; - printf OUT " else {\n"; - printf OUT " pat = gBidiCatPat[patidx];\n"; - printf OUT " return (eBidiCategory)((pat >> ((u % 8) * 4)) & 0x0F);\n"; - printf OUT " }\n"; - printf OUT " }\n\n"; -} - -@special = keys(%sh); -$sp = 0; -foreach $s ( sort(@special) ) { - # don't bother to define the special blocks unless they have a different - # value from the default they would be given if they were undefined - unless ($sc{$s} == $map{"L"}) { - unless ($sp++) { - %by_value = reverse %map; - printf OUT " /* Handle blocks which share the same category */\n\n"; - } - printf OUT " /* Handle %s block */\n", substr($s, 1); - printf OUT " if((((PRUnichar)0x%s)<=u)&&(u<=((PRUnichar)0x%s))) \n", $sl{$s}, $sh{$s}; - printf OUT " return eBidiCat_$by_value{$sc{$s}}; \n\n"; - } -} - - - -printf OUT " return eBidiCat_L; /* UNDEFINE = L */\n};\n"; - -printf OUT "/* total data size = $totaldata */\n"; -printf OUT "\n#endif /* IBMBIDI */\n"; -print "total = $totaldata\n"; - -###################################################################### -# -# Close files -# -###################################################################### -close(UNIDATA); -close(OUT); - +#!/usr/local/bin/perl +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is IBM +# Corporation. Portions created by IBM are +# Copyright (C) 2000 IBM Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +###################################################################### +# +# Initial global variable +# +###################################################################### + +%gcount = (); +%pat = (); + +%map = ( + "L" => "1", # Left-to-Right + "R" => "2", # Right-to-Left + "AL" => "3", # Right-to-Left Arabic + "AN" => "4", # Arabic Number + "EN" => "5", # European Number + "ES" => "6", # European Number Separator + "ET" => "7", # European Number Terminator + "CS" => "8", # Common Number Separator + "ON" => "9", # Other Neutrals + "NSM" => "10", # Non-Spacing Mark + "BN" => "11", # Boundary Neutral + "B" => "12", # Paragraph Separator + "S" => "13", # Segment Separator + "WS" => "14", # Whitespace + "LRE" => "15", # Left-to-Right Embedding + "RLE" => "15", # Right-to-Left Embedding + "PDF" => "15", # Pop Directional Format + "LRO" => "15", # Left-to-Right Override + "RLO" => "15" # Right-to-Left Override +); + +%special = (); + +###################################################################### +# +# Open the unicode database file +# +###################################################################### +open ( UNICODATA , "< UnicodeData-Latest.txt") + || die "cannot find UnicodeData-Latest.txt"; + +###################################################################### +# +# Open the output file +# +###################################################################### +open ( OUT , "> ../base/src/bidicattable.h") + || die "cannot open output ../base/src/bidicattable.h file"; + +###################################################################### +# +# Generate license and header +# +###################################################################### +$npl = <) { + chop; + ###################################################################### + # + # Get value from fields + # + ###################################################################### + @f = split(/;/ , $_); + $c = $f[0]; # The unicode value + $n = $f[1]; # The unicode name + $g = $f[2]; # The General Category + $b = $f[4]; # The Bidi Category + + if(( substr($n, 0, 1) ne "<") || ($n eq "")) + { + # + # print $g; + # + + $gcount{$b}++; + $bidicategory{$c} = $b; + } else { + + # Handle special block + @pair=split(/, /, $n ); + $catnum = $map{$b}; + + # printf "[%s][%s] => %d\n", $pair[0], $pair[1], $catnum; + if( $pair[1] eq "First>") { + $sl{$pair[0]} = $c; + $sc{$pair[0]} = $catnum; + } elsif ( $pair[1] eq "Last>") { + $sh{$pair[0]} = $c; + if($sc{$pair[0]} ne $catnum) + { + print "WARNING !!!! error in handling special block\n\n"; + } + } else { + print "WARNING !!!! error in handling special block\n\n"; + } + } +} + +# XXX - How can this be made more flexible as new blocks are added to the UCDB? + +@range = ( + 0x0000, 0x07ff, + 0x0900, 0x18ff, + 0x1e00, 0x28ff, + 0x2e80, 0x33ff, + 0xa000, 0xa4ff, + 0xf900, 0xffff +); + + +$totaldata = 0; + +$tt=($#range+1) / 2; +@patarray = (); + + +# This should improve performance: put all the patterns like 0x11111111, 0x22222222 etc at the beginning of the table. +# Since there are a lot of blocks with the same category, we should be able to save a lot of time extracting the digits +for (0..15) { + $pattern = "0x".(sprintf("%X", $_) x 8); + $patarray[$_] = $pattern; + $pat{$pattern} = $_; +} + +$newidx = 0x10; + +for($t = 1; $t <= $tt; $t++) +{ + $tl = $range[($t-1) * 2]; + $th = $range[($t-1) * 2 + 1]; + $ts = ( $th - $tl ) >> 3; + $totaldata += $ts + 1; + printf OUT "static PRUint8 gBidiCatIdx%d[%d] = {\n", $t, $ts + 1; + for($i = ($tl >> 3); $i <= ($th >> 3) ; $i ++ ) + { + $data = 0; + + for($j = 0; $j < 8 ; $j++) + { + #defaults for unassigned characters -- see table 3.7 in the Unicode Bidi Algorithm + $test = ($i << 3) + $j; + if ((($test >= 0x0590) && ($test <= 0x5FF)) + || (($test >= 0xFB1D) && ($test <= 0xFB4F))) + { + $default = $map{"R"}; + } elsif ((($test >= 0x0600) && ($test <= 0x7BF)) + || (($test >= 0xFB50) && ($test <= 0xFDFF)) + || (($test >= 0xFE70) && ($test <= 0xFEFF))) + { + $default = $map{"AL"}; + } else + { + $default = $map{"L"}; + } + $k = sprintf("%04X", (($i << 3) + $j)); + + $cat = $bidicategory{$k}; + if( $cat eq "") + { + $data = $data + ($default << (4*$j)); + } else { + $data = $data + ($map{$cat} << (4*$j)); + } + + } + $pattern = sprintf("0x%08X", $data); + + $idx = $pat{$pattern}; + unless( exists($pat{$pattern})){ + $idx = $newidx++; + $patarray[$idx] = $pattern; + $pat{$pattern} = $idx; + } + + printf OUT " %3d, /* U+%04X - U+%04X : %s */\n" , + $idx, ($i << 3),((($i +1)<< 3)-1), $pattern ; + + + } + printf OUT "};\n\n"; + + if($t ne $tt) + { + $tl = $range[($t-1) * 2 + 1] + 1; + $th = $range[$t * 2] - 1; + for($i = ($tl >> 3); $i <= ($th >> 3) ; $i ++ ) + { + $data = 0; + for($j = 0; $j < 8 ; $j++) + { + $k = sprintf("%04X", (($i << 3) + $j)); + + $cat = $bidicategory{$k}; + if( $cat ne "") + { + $data = $data + ($map{$cat} << (4*$j)); + } + } + $pattern = sprintf("0x%08X", $data); + if($data ne 0) + { + print "WARNING, Unicode Database now contain characters" . + "which we have not consider, change this program !!!\n\n"; + printf "Problem- U+%04X - U+%04X range\n", ($i << 3),((($i +1)<< 3)-1); + } + } + } +} + + +if($newidx > 255) +{ + die "We have more than 255 patterns !!! - $newidx\n\n" . + "This program is now broken!!!\n\n\n"; + +} +printf OUT "static PRUint32 gBidiCatPat[$newidx] = {\n"; +for($i = 0 ; $i < $newidx; $i++) +{ + printf OUT " %s, /* $i */\n", $patarray[$i] ; +} +printf OUT "};\n\n"; +$totaldata += $newidx * 4; + +printf OUT "static eBidiCategory GetBidiCat(PRUnichar u)\n{\n"; +printf OUT " PRUint32 pat;\n"; +printf OUT " PRUint16 patidx;\n\n"; +printf OUT " /* Handle blocks which use index table mapping */ \n\n"; +for($t = 1; $t <= $tt; $t++) +{ + $tl = $range[($t-1) * 2]; + $th = $range[($t-1) * 2 + 1]; + if ($tl == 0) { + printf OUT " /* Handle U+%04X to U+%04X */\n", $tl, $th; + printf OUT " if (u<=((PRUnichar)0x%04X)) {\n", $th; + printf OUT " patidx = gBidiCatIdx%d [( u >> 3 )];\n", $t; + } elsif ($th == 0xFFFF) { + printf OUT " /* Handle U+%04X to U+%04X */\n", $tl, $th; + printf OUT " if (((PRUnichar)0x%04X)<=u) {\n", $tl; + printf OUT " patidx = gBidiCatIdx%d [( (u -(PRUnichar) 0x%04X) >> 3 )];\n", $t, $tl; + } else { + printf OUT " /* Handle U+%04X to U+%04X */\n", $tl, $th; + printf OUT " if ((((PRUnichar)0x%04X)<=u)&&(u<=((PRUnichar)0x%04X))) {\n", $tl, $th; + printf OUT " patidx = gBidiCatIdx%d [( (u -(PRUnichar) 0x%04X) >> 3 )];\n", $t, $tl; + } + printf OUT " if (patidx < 0x10)\n"; + printf OUT " return (eBidiCategory)patidx;\n"; + printf OUT " else {\n"; + printf OUT " pat = gBidiCatPat[patidx];\n"; + printf OUT " return (eBidiCategory)((pat >> ((u % 8) * 4)) & 0x0F);\n"; + printf OUT " }\n"; + printf OUT " }\n\n"; +} + +@special = keys(%sh); +$sp = 0; +foreach $s ( sort(@special) ) { + # don't bother to define the special blocks unless they have a different + # value from the default they would be given if they were undefined + unless ($sc{$s} == $map{"L"}) { + unless ($sp++) { + %by_value = reverse %map; + printf OUT " /* Handle blocks which share the same category */\n\n"; + } + printf OUT " /* Handle %s block */\n", substr($s, 1); + printf OUT " if((((PRUnichar)0x%s)<=u)&&(u<=((PRUnichar)0x%s))) \n", $sl{$s}, $sh{$s}; + printf OUT " return eBidiCat_$by_value{$sc{$s}}; \n\n"; + } +} + + + +printf OUT " return eBidiCat_L; /* UNDEFINE = L */\n};\n"; + +printf OUT "/* total data size = $totaldata */\n"; +print "total = $totaldata\n"; + +###################################################################### +# +# Close files +# +###################################################################### +close(UNIDATA); +close(OUT); + diff --git a/mozilla/intl/unicharutil/tools/gensymmtable.pl b/mozilla/layout/tools/gensymmtable.pl similarity index 93% rename from mozilla/intl/unicharutil/tools/gensymmtable.pl rename to mozilla/layout/tools/gensymmtable.pl index c39f08a8d8f..fca4edfe74e 100644 --- a/mozilla/intl/unicharutil/tools/gensymmtable.pl +++ b/mozilla/layout/tools/gensymmtable.pl @@ -1,117 +1,114 @@ -#!/usr/local/bin/perl -# -# The contents of this file are subject to the Mozilla Public -# License Version 1.1 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS -# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -# implied. See the License for the specific language governing -# rights and limitations under the License. -# -# The Original Code is IBM code. -# -# The Initial Developer of the Original Code is IBM. -# Portions created by IBM are -# Copyright (C) International Business Machines -# Corporation, 2000. All Rights Reserved. -# -# Contributor(s): Simon Montagu -# - -# This program generates the header file symmtable.h from the Unicode -# informative data file BidiMirroring.txt. -# See the comments in that file for details of its structure and contents. -# -# At the moment we only handle cases where there is another Unicode -# character whose glyph can serve as at least an adequate version of -# the mirror image of the original character's glyph. This leaves open -# the problem of how to provide mirrored glyphs for characters where -# this is not the case. - -# Process the input file -$ucp = "[0-9a-fA-F]{4}"; # Unicode code point (4 successive hex digits) as a pattern to match -open ( UNICODATA , "< BidiMirroring.txt") - || die "Cannot find BidiMirroring.txt.\ -The file should be avaiable here:\ -http://www.unicode.org/Public/UNIDATA/BidiMirroring.txt\n"; - -while () { - chop; - if (/^($ucp); ($ucp) # (.+)/) { # If the line looks like this pattern - # (example: 0028; 0029 # LEFT PARENTHESIS) - @table[hex($1)]=hex($1) ^ hex($2); # Enter the character XOR its symmetric pair in the table - @isblock[hex(substr($1, 0, 2))]=1; # Remember this block - } -} -close(UNICODATA); - -# Generate license and header -open ( OUT , "> ../src/symmtable.h") - || die "cannot open output ../src/symmtable.h file"; -$npl = <) { + chop; + if (/^($ucp); ($ucp) # (.+)/) { # If the line looks like this pattern + # (example: 0028; 0029 # LEFT PARENTHESIS) + @table[hex($1)]=hex($1) ^ hex($2); # Enter the character XOR its symmetric pair in the table + @isblock[hex(substr($1, 0, 2))]=1; # Remember this block + } +} +close(UNICODATA); + +# Generate license and header +open ( OUT , "> ../base/src/symmtable.h") + || die "cannot open output ../base/src/symmtable.h file"; +$npl = <