fix bug 70028. r=ftang sr=erik
add bidi utility interface and implementation
Not building yet, should not affect the build
This commit is contained in:
ftang%netscape.com 2001-02-27 02:06:55 +00:00
parent c6dba7aacb
commit 09f7abdf07
5 changed files with 2784 additions and 0 deletions

View File

@ -0,0 +1,255 @@
/* -*- 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 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 nsIUBidiUtils_h__
#define nsIUBidiUtils_h__
#include "nsISupports.h"
#include "nscore.h"
#include "nsString.h"
// Include nsIBidi.h for UcharDirection 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 UCharDirection (compatible with ICU)
*/
NS_IMETHOD GetDirection(PRUnichar aChar, UCharDirection* oResult) = 0 ;
/**
* Give a Unichar, return the symmetric equivalent
*/
NS_IMETHOD SymmSwap(PRUnichar* aChar) = 0 ;
/**
* 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
*/
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;
};
// --------------------------------------------------
// 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
typedef PRUint32 nsBidiOptions;
#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 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_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) ((0xfe70 <= (c)) && ((c)<= 0xfeFF))
#define IS_ARABIC_CHAR(c) ((0x0600 <= (c)) && ((c)<= 0x06FF))
#define IS_ARABIC_ALPHABETIC(c) (IS_ARABIC_CHAR(c) && !IS_HINDI_DIGIT(c))
#define CHAR_IS_BIDI(c) ( (IS_HINDI_DIGIT(c) ) || (IS_HEBREW_CHAR(c) ) \
|| (IS_06_CHAR(c) ) || (IS_FE_CHAR(c) ) )
#endif /* nsIUbidiUtils_h__ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,354 @@
/* -*- 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 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):
*/
#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_DEFINE_IID(kIUBidiUtilsIID, NS_IUBIDIUTILS_IID);
NS_IMPL_ISUPPORTS(nsBidiUtilsImp, kIUBidiUtilsIID);
static UCharDirection ebc2ucd[15] = {
U_OTHER_NEUTRAL, /* Placeholder -- there will never be a 0 index value */
U_LEFT_TO_RIGHT,
U_RIGHT_TO_LEFT,
U_RIGHT_TO_LEFT_ARABIC,
U_ARABIC_NUMBER,
U_EUROPEAN_NUMBER,
U_EUROPEAN_NUMBER_SEPARATOR,
U_EUROPEAN_NUMBER_TERMINATOR,
U_COMMON_NUMBER_SEPARATOR,
U_OTHER_NEUTRAL,
U_DIR_NON_SPACING_MARK,
U_BOUNDARY_NEUTRAL,
U_BLOCK_SEPARATOR,
U_SEGMENT_SEPARATOR,
U_WHITE_SPACE_NEUTRAL
};
static UCharDirection cc2ucd[5] = {
U_LEFT_TO_RIGHT_EMBEDDING,
U_RIGHT_TO_LEFT_EMBEDDING,
U_POP_DIRECTIONAL_FORMAT,
U_LEFT_TO_RIGHT_OVERRIDE,
U_RIGHT_TO_LEFT_OVERRIDE
};
// the Array Index = FE_CHAR - FE_TO_06_OFFSET
#define FE_TO_06_OFFSET 0xfe70
static PRUint16 FE_TO_06 [][2] = {
{0x064a,0x0000},{0x064a,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},
{0x0000,0x0000},{0x0000,0x0000},{0x0000,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
};
#define PresentationFormB(c, form) \
(((0x0622<=(c)) && ((c)<=0x063A)) ? \
(0xFE00|(gArabicMap1[(c)-0x0622] + (form))) : \
(((0x0641<=(c)) && ((c)<=0x064A)) ? \
(0xFE00|(gArabicMap2[(c)-0x0641] + (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)) \
static PRInt8 gJoiningClass[] = {
eRJ, eRJ, eRJ, eRJ, eDJ, eRJ, // 0620-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 // 0650-0652
};
#define GetJoiningClass(c) \
(((0x0622 <= (c)) && ((c) <= 0x0652)) ? \
(gJoiningClass[(c) - 0x0622]) : \
((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
};
#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()
{
NS_INIT_REFCNT();
PR_AtomicIncrement(&g_InstanceCount);
}
nsBidiUtilsImp::~nsBidiUtilsImp()
{
PR_AtomicDecrement(&g_InstanceCount);
}
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::GetDirection(PRUnichar aChar, UCharDirection* oResult)
{
eBidiCategory bCat = GetBidiCat(aChar);
if (eBidiCat_CC != bCat) {
NS_ASSERTION(bCat < (sizeof(ebc2ucd)/sizeof(UCharDirection)), "size mismatch");
if(bCat < (sizeof(ebc2ucd)/sizeof(UCharDirection)))
*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(UCharDirection)), "size mismatch");
if((aChar-0x202a) < (sizeof(cc2ucd)/sizeof(UCharDirection)))
*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.
for(*aBufLen = 0;*aBufLen < aLen; *aBufLen++)
aBuf[*aBufLen] = aString[*aBufLen];
return NS_OK;
}
NS_IMETHODIMP nsBidiUtilsImp::HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag)
{
PRUint32 i;
// IBMBIDI_NUMERAL_REGULAR *
// IBMBIDI_NUMERAL_HINDICONTEXT
// IBMBIDI_NUMERAL_ARABIC
// IBMBIDI_NUMERAL_HINDI
switch (aNumFlag) {
case IBMBIDI_NUMERAL_HINDI:
for (i=0;i<aSize;i++)
aBuffer[i] = NUM_TO_HINDI(aBuffer[i]);
break;
case IBMBIDI_NUMERAL_ARABIC:
for (i=0;i<aSize;i++)
aBuffer[i] = NUM_TO_ARABIC(aBuffer[i]);
break;
default : // IBMBIDI_NUMERAL_REGULAR, IBMBIDI_NUMERAL_HINDICONTEXT
for (i=1;i<aSize;i++) {
if (IS_ARABIC_CHAR(aBuffer[i-1]))
aBuffer[i] = NUM_TO_HINDI(aBuffer[i]);
else
aBuffer[i] = NUM_TO_ARABIC(aBuffer[i]);
}
break;
}
return NS_OK;
}
NS_IMETHODIMP nsBidiUtilsImp::Conv_FE_06(const nsString aSrc, nsString & aDst)
{
// 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.
aDst = aSrc;
return NS_OK;
}
NS_IMETHODIMP nsBidiUtilsImp::HandleNumbers(const nsString aSrc, nsString & aDst)
{
// 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.
aDst = aSrc;
return NS_OK;
}
NS_IMETHODIMP nsBidiUtilsImp::Conv_06_FE_WithReverse(const nsString aSrc, nsString & aDst,PRUint32 mDir)
{
// 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.
aDst = aSrc;
return NS_OK;
}
NS_IMETHODIMP nsBidiUtilsImp::Conv_FE_06_WithReverse(const nsString aSrc, nsString & aDst)
{
// 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.
aDst = aSrc;
return NS_OK;
}

View File

@ -0,0 +1,78 @@
/* -*- 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 UCharDirection (compatible with ICU)
*/
NS_IMETHOD GetDirection(PRUnichar aChar, UCharDirection* 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 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);
NS_IMETHOD HandleNumbers(const nsString aSrc, nsString & aDst );
};
#endif /* nsBidiUtilsImp_h__ */

View File

@ -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, 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 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;
}