Converting bidi utilities to non-XPCOM interfaces. Bug 120818; r=mkaply, nhotta; sr=attinasi

This commit is contained in:
smontagu%netscape.com 2002-02-19 20:41:32 +00:00
Родитель 8e426d1ebc
Коммит 37ebf6848d
59 изменённых файлов: 7505 добавлений и 1657 удалений

Просмотреть файл

@ -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<nsIUBidiUtils> 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);
}
}

Просмотреть файл

@ -127,7 +127,7 @@
#include "nsXULAtoms.h"
#ifdef IBMBIDI
#include "nsIUBidiUtils.h"
#include "nsBidiUtils.h"
#endif
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);

Просмотреть файл

@ -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);

Просмотреть файл

@ -55,10 +55,6 @@
#include "nsRuleNode.h"
#ifdef IBMBIDI
#include "nsIUBidiUtils.h"
#endif
#ifdef DEBUG
// #define NOISY_DEBUG
#endif

Просмотреть файл

@ -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<nsIUBidiUtils> 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();

Просмотреть файл

@ -132,7 +132,7 @@
#include "nsIPrompt.h"
//AHMED 12-2
#ifdef IBMBIDI
#include "nsIUBidiUtils.h"
#include "nsBidiUtils.h"
#endif
#define DETECTOR_CONTRACTID_MAX 127

Просмотреть файл

@ -988,6 +988,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
</FILELIST>
<LINKORDER>
<FILEREF>
@ -1060,6 +1067,11 @@
<PATH>nsXBLAtoms.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
</TARGET>
<TARGET>
@ -1997,6 +2009,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
</FILELIST>
<LINKORDER>
<FILEREF>
@ -2069,6 +2088,11 @@
<PATH>nsXBLAtoms.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
</TARGET>
</TARGETLIST>
@ -2158,6 +2182,12 @@
<PATH>nsHTMLUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>contentsharedDebug.o</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<FILEREF>
<TARGETNAME>contentsharedDebug.o</TARGETNAME>

Просмотреть файл

@ -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

Просмотреть файл

@ -58,5 +58,9 @@ ifdef MOZ_SVG
EXPORTS += nsSVGAtomList.h nsSVGAtoms.h
endif
ifdef IBMBIDI
EXPORTS += nsBidiUtils.h
endif
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -46,6 +46,9 @@ EXPORTS = \
!ifdef MOZ_SVG
nsSVGAtomList.h \
nsSVGAtoms.h \
!endif
!ifdef IBMBIDI
nsBidiUtils.h \
!endif
nsXBLAtomList.h \
nsXBLAtoms.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 <mahar@eg.ibm.com>
* Lina Kemmel <lkemmel@il.ibm.com>
* Simon Montagu <smontagu@netscape.com>
*
*/
#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__ */

Просмотреть файл

@ -58,6 +58,7 @@ CPPSRCS = \
nsXBLAtoms.cpp \
nsStyleCoord.cpp \
nsStyleStruct.cpp \
nsBidiUtils.cpp \
$(NULL)
ifdef MOZ_SVG

Просмотреть файл

@ -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

Просмотреть файл

@ -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 <mahar@eg.ibm.com>
* Lina Kemmel <lkemmel@il.ibm.com>
* Simon Montagu <smontagu@netscape.com>
* Roozbeh Pournader <roozbeh@sharif.edu>
*/
#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;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 HandleNum() which is called for clipboard handling
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::HandleNumbers(const nsString aSrc, nsString & aDst)
{
aDst = aSrc;
return HandleNumbers((PRUnichar *)aDst.get(),aDst.Length(),mNumflag);
}
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.
#ifdef FULL_ARABIC_SHAPING
// Start Unreview Code
PRUnichar *aSrcUnichars = (PRUnichar *)aSrc.get();
PRUint32 i, size = aSrc.Length();
aDst.Truncate();
@ -499,20 +333,11 @@ NS_IMETHODIMP nsBidiUtilsImp::Conv_FE_06(const nsString aSrc, nsString & aDst)
aDst += aSrcUnichars[i]; // copy it even if it is not in FE range
}
}// for : loop the buffer
#else
aDst= aSrc;
#endif
return NS_OK;
}
/////////////////////////////////////////////////////////////////////
NS_IMETHODIMP nsBidiUtilsImp::Conv_FE_06_WithReverse(const nsString aSrc, nsString & aDst)
nsresult 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.
#ifdef FULL_ARABIC_SHAPING
// Start Unreview Code
PRUnichar *aSrcUnichars = (PRUnichar *)aSrc.get();
PRBool foundArabic = PR_FALSE;
PRUint32 i,endArabic, beginArabic, size = aSrc.Length();
@ -522,7 +347,7 @@ NS_IMETHODIMP nsBidiUtilsImp::Conv_FE_06_WithReverse(const nsString aSrc, nsStri
break; // no need to convert char after the NULL
while( (IS_FE_CHAR(aSrcUnichars[endArabic]))||
(CHAR_IS_ARABIC(aSrcUnichars[endArabic]))||
(IS_ARABIC_CHAR(aSrcUnichars[endArabic]))||
(IS_ARABIC_DIGIT(aSrcUnichars[endArabic]))||
(aSrcUnichars[endArabic]==0x0020))
{
@ -544,7 +369,7 @@ NS_IMETHODIMP nsBidiUtilsImp::Conv_FE_06_WithReverse(const nsString aSrc, nsStri
} // if expands to 2 char
} else {
// do we need to check the following if ?
if((CHAR_IS_ARABIC(aSrcUnichars[i]))||
if((IS_ARABIC_CHAR(aSrcUnichars[i]))||
(IS_ARABIC_DIGIT(aSrcUnichars[i]))||
(aSrcUnichars[i]==0x0020))
aDst += aSrcUnichars[i];
@ -555,22 +380,13 @@ NS_IMETHODIMP nsBidiUtilsImp::Conv_FE_06_WithReverse(const nsString aSrc, nsStri
}
foundArabic=PR_FALSE;
}// for : loop the buffer
#else
aDst= aSrc;
#endif
return NS_OK;
}
////////////////////////////////////////////////////////////
//ahmed
NS_IMETHODIMP nsBidiUtilsImp::Conv_06_FE_WithReverse(const nsString aSrc,
nsString & aDst,PRUint32 aDir)
nsresult Conv_06_FE_WithReverse(const nsString& aSrc,
nsString& aDst,
PRUint32 aDir)
{
// 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
PRUnichar *aSrcUnichars = (PRUnichar *)aSrc.get();
PRUint32 i,beginArabic, endArabic, size = aSrc.Length();
aDst.Truncate();
@ -580,7 +396,7 @@ nsString & aDst,PRUint32 aDir)
break; // no need to convert char after the NULL
while( (IS_06_CHAR(aSrcUnichars[endArabic])) ||
(CHAR_IS_ARABIC(aSrcUnichars[endArabic])) ||
(IS_ARABIC_CHAR(aSrcUnichars[endArabic])) ||
(aSrcUnichars[endArabic]==0x0020) ||
(IS_ARABIC_DIGIT(aSrcUnichars[endArabic])) )
{
@ -641,10 +457,6 @@ nsString & aDst,PRUint32 aDir)
}
foundArabic=PR_FALSE;
}// for : loop the buffer
#else
aDst= aSrc;
#endif
return NS_OK;
}
#endif // IBMBIDI
#endif //IBMBIDI

Просмотреть файл

@ -53,7 +53,7 @@
#include "prenv.h"
#ifdef IBMBIDI
#include "nsIUBidiUtils.h"
#include "nsBidiUtils.h"
#endif
inline PRBool IsFixedUnit(nsStyleUnit aUnit, PRBool aEnumOK)

Просмотреть файл

@ -41,7 +41,7 @@
#include "nsReadableUtils.h"
#include "nsMemory.h"
#ifdef IBMBIDI
#include "nsIUBidiUtils.h"
#include "nsBidiUtils.h"
#endif
// Static buffer used for newline fragments

Просмотреть файл

@ -1011,20 +1011,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiUtilsImp.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiImp.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
</FILELIST>
<LINKORDER>
<FILEREF>
@ -1087,16 +1073,6 @@
<PATH>nsSaveAsCharset.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiUtilsImp.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiImp.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
</TARGET>
<TARGET>
@ -2057,20 +2033,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiUtilsImp.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiImp.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
</FILELIST>
<LINKORDER>
<FILEREF>
@ -2133,16 +2095,6 @@
<PATH>nsSaveAsCharset.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiUtilsImp.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiImp.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
</TARGET>
</TARGETLIST>
@ -2190,18 +2142,6 @@
<PATH>nsEntityConverter.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>unicharutil.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiUtilsImp.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>unicharutil.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiImp.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<GROUP><NAME>NS Libraries</NAME>
<GROUP><NAME>Optimized</NAME>

Просмотреть файл

@ -6,5 +6,3 @@ nsIUGenDetailCategory.h
nsUnicharUtilCIID.h
nsHankakuToZenkakuCID.h
nsArabicBasicLToPFormBVCID.h
nsIBidi.h
nsIUBidiUtils.h

Просмотреть файл

@ -37,8 +37,6 @@ EXPORTS = \
nsUnicharUtilCIID.h \
nsHankakuToZenkakuCID.h \
nsArabicBasicLToPFormBVCID.h \
nsIUBidiUtils.h \
nsIBidi.h \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -31,8 +31,6 @@ EXPORTS = \
nsHankakuToZenkakuCID.h \
nsArabicBasicLToPFormBVCID.h \
nsUnicharUtilCIID.h \
nsIUBidiUtils.h \
nsIBidi.h \
$(NULL)
MODULE=unicharutil

Просмотреть файл

@ -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) \

Просмотреть файл

@ -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= \

Просмотреть файл

@ -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<length;
* they update the offset
*/
/* fast versions, no error-checking */
#define UTF16_APPEND_CHAR_UNSAFE(s, i, c){ \
if((PRUint32)(c)<=0xffff) { \
(s)[(i)++]=(PRUnichar)(c); \
} else { \
(s)[(i)++]=(PRUnichar)((c)>>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 0<i<=length;
* they update the offset
*/
/* fast versions, no error-checking */
/*
* Get a single code point from an offset that points behind the last
* of the code units that belong to that code point.
* Assume 0<=i<length.
*/
#define UTF16_PREV_CHAR_UNSAFE(s, i, c) { \
(c)=(s)[--(i)]; \
if(IS_SECOND_SURROGATE(c)) { \
(c)=GET_UTF_32((s)[--(i)], (c)); \
} \
}
#define UTF16_BACK_1_UNSAFE(s, i) { \
if(IS_SECOND_SURROGATE((s)[--(i)])) { \
--(i); \
} \
}
#define UTF16_BACK_N_UNSAFE(s, i, n) { \
PRInt32 __N=(n); \
while(__N>0) { \
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 <code>SetPara()</code>
* or the Bidi properties of a line of a paragraph by
* <code>GetLine()</code>.<p>
* This object can be reused for as long as it is not destroyed.<p>
* <code>SetPara()</code> will allocate additional memory for
* internal structures as necessary.
*
*/
nsBidi();
/** @brief Preallocating constructor
* Allocate an <code>nsBidi</code>
* object with preallocated memory for internal structures. This
* constructor provides an <code>nsBidi</code> object like
* the default constructor, but it also
* preallocates memory for internal structures according to the sizings
* supplied by the caller.<p> Subsequent functions will not allocate
* any more memory, and are thus guaranteed not to fail because of lack
* of memory.<p> The preallocation can be limited to some of the
* internal memory by setting some values to 0 here. That means that
* if, e.g., <code>aMaxRunCount</code> cannot be reasonably
* predetermined and should not be set to <code>aMaxLength</code> (the
* only failproof value) to avoid wasting memory, then
* <code>aMaxRunCount</code> 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.<p>
* The number of runs depends on the actual text and maybe anywhere between
* 1 and <code>aMaxLength</code>. It is typically small.<p>
*/
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

Просмотреть файл

@ -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__ */

Просмотреть файл

@ -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)

Просмотреть файл

@ -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 */

Просмотреть файл

@ -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<nsIUBidiUtils> 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 (i<length) {
if(IS_DEFAULT_LEVEL(mParaLevel)) {
/* determine the paragraph level (P2..P3) */
for(;;) {
uchar=aText[i];
if(!IS_FIRST_SURROGATE(uchar) || i+1==length || !IS_SECOND_SURROGATE(aText[i+1])) {
/* not a surrogate pair */
dirProps[i]=L;
flags|=DIRPROP_FLAG(dirProps[i]=dirProp=GetCharType(uchar));
} else {
/* a surrogate pair */
dirProps[i++]=BN; /* second surrogate in the pair gets the BN type */
dirProps[i]=L;
flags|=DIRPROP_FLAG(BN);
dirProps[i++]=BN; /* first surrogate in the pair gets the BN type */
flags|=DIRPROP_FLAG(dirProps[i]=dirProp=GetCharType(GET_UTF_32(uchar, aText[i])))|DIRPROP_FLAG(BN);
}
++i;
}
} else {
if(IS_DEFAULT_LEVEL(mParaLevel)) {
/* determine the paragraph level (P2..P3) */
for(;;) {
uchar=aText[i];
if(!IS_FIRST_SURROGATE(uchar) || i+1==length || !IS_SECOND_SURROGATE(aText[i+1])) {
/* not a surrogate pair */
bidiUtils->GetCharType(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(i<length) {
uchar=aText[i];
if(!IS_FIRST_SURROGATE(uchar) || i+1==length || !IS_SECOND_SURROGATE(aText[i+1])) {
/* not a surrogate pair */
bidiUtils->GetCharType(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(i<length) {
uchar=aText[i];
if(!IS_FIRST_SURROGATE(uchar) || i+1==length || !IS_SECOND_SURROGATE(aText[i+1])) {
/* not a surrogate pair */
flags|=DIRPROP_FLAG(dirProps[i]=GetCharType(uchar));
} else {
/* a surrogate pair */
dirProps[i++]=BN; /* second surrogate in the pair gets the BN type */
flags|=DIRPROP_FLAG(dirProps[i]=GetCharType(GET_UTF_32(uchar, aText[i])))|DIRPROP_FLAG(BN);
}
++i;
}
if(flags&MASK_EMBEDDING) {
flags|=DIRPROP_FLAG_LR(mParaLevel);
}
mFlags=flags;
}
@ -1173,19 +1165,19 @@ void nsBidi::AdjustWSLevels()
/* -------------------------------------------------------------------------- */
NS_IMETHODIMP nsBidi::GetDirection(nsBidiDirection* aDirection)
nsresult nsBidi::GetDirection(nsBidiDirection* aDirection)
{
*aDirection = mDirection;
return NS_OK;
}
NS_IMETHODIMP nsBidi::GetLength(PRInt32* aLength)
nsresult nsBidi::GetLength(PRInt32* aLength)
{
*aLength = mLength;
return NS_OK;
}
NS_IMETHODIMP nsBidi::GetParaLevel(nsBidiLevel* aParaLevel)
nsresult nsBidi::GetParaLevel(nsBidiLevel* aParaLevel)
{
*aParaLevel = mParaLevel;
return NS_OK;
@ -1240,7 +1232,7 @@ NS_IMETHODIMP nsBidi::GetParaLevel(nsBidiLevel* aParaLevel)
* a pointer into them, not by copying. This again saves memory and forbids to
* change the now shared levels for (L1).
*/
NS_IMETHODIMP nsBidi::SetLine(nsIBidi* aParaBidi, PRInt32 aStart, PRInt32 aLimit)
nsresult nsBidi::SetLine(nsIBidi* aParaBidi, PRInt32 aStart, PRInt32 aLimit)
{
nsBidi* pParent = (nsBidi*)aParaBidi;
PRInt32 length;
@ -1380,7 +1372,7 @@ void nsBidi::SetTrailingWSStart() {
mTrailingWSStart=start;
}
NS_IMETHODIMP nsBidi::GetLevelAt(PRInt32 aCharIndex, nsBidiLevel* aLevel)
nsresult nsBidi::GetLevelAt(PRInt32 aCharIndex, nsBidiLevel* aLevel)
{
/* return paraLevel if in the trailing WS run, otherwise the real level */
if(aCharIndex<0 || mLength<=aCharIndex) {
@ -1393,7 +1385,7 @@ NS_IMETHODIMP nsBidi::GetLevelAt(PRInt32 aCharIndex, nsBidiLevel* aLevel)
return NS_OK;
}
NS_IMETHODIMP nsBidi::GetLevels(nsBidiLevel** aLevels)
nsresult nsBidi::GetLevels(nsBidiLevel** aLevels)
{
PRInt32 start, length;
@ -1438,7 +1430,7 @@ NS_IMETHODIMP nsBidi::GetLevels(nsBidiLevel** aLevels)
}
#endif // FULL_BIDI_ENGINE
NS_IMETHODIMP nsBidi::GetCharTypeAt(PRInt32 aCharIndex, nsCharType* pType)
nsresult nsBidi::GetCharTypeAt(PRInt32 aCharIndex, nsCharType* pType)
{
if(aCharIndex<0 || mLength<=aCharIndex) {
return NS_ERROR_INVALID_ARG;
@ -1447,7 +1439,7 @@ NS_IMETHODIMP nsBidi::GetCharTypeAt(PRInt32 aCharIndex, nsCharType* pType)
return NS_OK;
}
NS_IMETHODIMP nsBidi::GetLogicalRun(PRInt32 aLogicalStart, PRInt32 *aLogicalLimit, nsBidiLevel *aLevel)
nsresult nsBidi::GetLogicalRun(PRInt32 aLogicalStart, PRInt32 *aLogicalLimit, nsBidiLevel *aLevel)
{
PRInt32 length = mLength;
@ -1482,7 +1474,7 @@ NS_IMETHODIMP nsBidi::GetLogicalRun(PRInt32 aLogicalStart, PRInt32 *aLogicalLimi
/* runs API functions ------------------------------------------------------- */
NS_IMETHODIMP nsBidi::CountRuns(PRInt32* aRunCount)
nsresult nsBidi::CountRuns(PRInt32* aRunCount)
{
if(mRunCount<0 && !GetRuns()) {
return NS_ERROR_OUT_OF_MEMORY;
@ -1493,7 +1485,7 @@ NS_IMETHODIMP nsBidi::CountRuns(PRInt32* aRunCount)
}
}
NS_IMETHODIMP nsBidi::GetVisualRun(PRInt32 aRunIndex, PRInt32 *aLogicalStart, PRInt32 *aLength, nsBidiDirection *aDirection)
nsresult nsBidi::GetVisualRun(PRInt32 aRunIndex, PRInt32 *aLogicalStart, PRInt32 *aLength, nsBidiDirection *aDirection)
{
if( aRunIndex<0 ||
mRunCount==-1 && !GetRuns() ||
@ -1803,7 +1795,7 @@ void nsBidi::ReorderLine(nsBidiLevel aMinLevel, nsBidiLevel aMaxLevel)
}
}
NS_IMETHODIMP nsBidi::ReorderVisual(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap)
nsresult nsBidi::ReorderVisual(const nsBidiLevel *aLevels, PRInt32 aLength, PRInt32 *aIndexMap)
{
PRInt32 start, end, limit, temp;
nsBidiLevel minLevel, maxLevel;
@ -1906,7 +1898,7 @@ PRBool nsBidi::PrepareReorder(const nsBidiLevel *aLevels, PRInt32 aLength,
#ifdef FULL_BIDI_ENGINE
/* API functions for logical<->visual 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<nsIUBidiUtils> 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

Просмотреть файл

@ -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<length;
* they update the offset
*/
/* fast versions, no error-checking */
#define UTF16_APPEND_CHAR_UNSAFE(s, i, c){ \
if((PRUint32)(c)<=0xffff) { \
(s)[(i)++]=(PRUnichar)(c); \
} else { \
(s)[(i)++]=(PRUnichar)((c)>>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 0<i<=length;
* they update the offset
*/
/* fast versions, no error-checking */
/*
* Get a single code point from an offset that points behind the last
* of the code units that belong to that code point.
* Assume 0<=i<length.
*/
#define UTF16_PREV_CHAR_UNSAFE(s, i, c) { \
(c)=(s)[--(i)]; \
if(IS_SECOND_SURROGATE(c)) { \
(c)=GET_UTF_32((s)[--(i)], (c)); \
} \
}
#define UTF16_BACK_1_UNSAFE(s, i) { \
if(IS_SECOND_SURROGATE((s)[--(i)])) { \
--(i); \
} \
}
#define UTF16_BACK_N_UNSAFE(s, i, n) { \
PRInt32 __N=(n); \
while(__N>0) { \
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;
* <code>SetPara</code> 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 <code>SetPara()</code>
* or the Bidi properties of a line of a paragraph by
* <code>GetLine()</code>.<p>
* This object can be reused for as long as it is not destroyed.<p>
* <code>SetPara()</code> will allocate additional memory for
* internal structures as necessary.
*
*/
nsBidi();
/** @brief Preallocating constructor
* Allocate an <code>nsBidi</code>
* object with preallocated memory for internal structures. This
* constructor provides an <code>nsBidi</code> object like
* the default constructor, but it also
* preallocates memory for internal structures according to the sizings
* supplied by the caller.<p> Subsequent functions will not allocate
* any more memory, and are thus guaranteed not to fail because of lack
* of memory.<p> The preallocation can be limited to some of the
* internal memory by setting some values to 0 here. That means that
* if, e.g., <code>aMaxRunCount</code> cannot be reasonably
* predetermined and should not be set to <code>aMaxLength</code> (the
* only failproof value) to avoid wasting memory, then
* <code>aMaxRunCount</code> 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.<p>
* The number of runs depends on the actual text and maybe anywhere between
* 1 and <code>aMaxLength</code>. It is typically small.<p>
*/
nsBidi(PRUint32 aMaxLength, PRUint32 aMaxRunCount);
/** @brief Destructor. */
virtual ~nsBidi();
/**
* Perform the Unicode Bidi algorithm. It is defined in the
* <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Technical Report 9</a>,
@ -298,7 +603,7 @@ public:
* <strong>The <code>aEmbeddingLevels</code> array must be
* at least <code>aLength</code> long.</strong>
*/
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.<p>
@ -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 <code>NULL</code> 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.<p>
* The index map will result in <code>aIndexMap[aLogicalIndex]==aVisualIndex</code>.
*/
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.<p>
* The index map will result in <code>aIndexMap[aVisualIndex]==aLogicalIndex</code>.
*/
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 <code>aDest</code>.
*/
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_

Просмотреть файл

@ -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<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 HandleNum() which is called for clipboard handling
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;
}
nsresult nsBidiPresUtils::HandleNumbers(const nsString& aSrc, nsString& aDst)
{
aDst = aSrc;
return HandleNumbers((PRUnichar *)aDst.get(),aDst.Length(),mNumflag);
}
#endif // IBMBIDI

Просмотреть файл

@ -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<nsIBidi> mBidiEngine;
nsCOMPtr<nsIUBidiUtils> mUnicodeUtils;
nsBidi* mBidiEngine;
};
#endif /* nsBidiPresUtils_h___ */

462
layout/base/nsBidiUtils.cpp Normal file
Просмотреть файл

@ -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 <mahar@eg.ibm.com>
* Lina Kemmel <lkemmel@il.ibm.com>
* Simon Montagu <smontagu@netscape.com>
* Roozbeh Pournader <roozbeh@sharif.edu>
*/
#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+aLen-1) {
leftJ = thisJ;
if ((eTr != leftJ) || ((leftJ == eTr) &&
( ( (src-1) >= 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<size;i++) { // i : Source
aSrcUnichars[i];
if (aSrcUnichars[i] == 0x0000)
break; // no need to convert char after the NULL
if (IS_FE_CHAR(aSrcUnichars[i])) {
//ahmed for lamalf
PRUnichar ch = (PresentationToOriginal(aSrcUnichars[i], 1));
if(ch)
aDst += ch;
ch=(PresentationToOriginal(aSrcUnichars[i], 0));
if(ch)
aDst += ch;
else //if it is 00, just output what we have in FExx
aDst += aSrcUnichars[i];
} else {
aDst += aSrcUnichars[i]; // copy it even if it is not in FE range
}
}// for : loop the buffer
return NS_OK;
}
nsresult Conv_FE_06_WithReverse(const nsString& aSrc, nsString& aDst)
{
PRUnichar *aSrcUnichars = (PRUnichar *)aSrc.get();
PRBool foundArabic = PR_FALSE;
PRUint32 i,endArabic, beginArabic, size = aSrc.Length();
aDst.Truncate();
for (endArabic=0;endArabic<size;endArabic++) {
if (aSrcUnichars[endArabic] == 0x0000)
break; // no need to convert char after the NULL
while( (IS_FE_CHAR(aSrcUnichars[endArabic]))||
(IS_ARABIC_CHAR(aSrcUnichars[endArabic]))||
(IS_ARABIC_DIGIT(aSrcUnichars[endArabic]))||
(aSrcUnichars[endArabic]==0x0020))
{
if(! foundArabic ) {
beginArabic=endArabic;
foundArabic= PR_TRUE;
}
endArabic++;
}
if(foundArabic) {
endArabic--;
for (i=endArabic; 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<size;endArabic++) {
if (aSrcUnichars[endArabic] == 0x0000)
break; // no need to convert char after the NULL
while( (IS_06_CHAR(aSrcUnichars[endArabic])) ||
(IS_ARABIC_CHAR(aSrcUnichars[endArabic])) ||
(aSrcUnichars[endArabic]==0x0020) ||
(IS_ARABIC_DIGIT(aSrcUnichars[endArabic])) )
{
if(! foundArabic) {
beginArabic=endArabic;
foundArabic=PR_TRUE;
}
endArabic++;
}
if(foundArabic) {
endArabic--;
PRUnichar buf[8192];
PRUint32 len=8192;
//reverse the buffer for shaping
for(i=beginArabic; i<=endArabic; i++) {
buf[i-beginArabic]=aSrcUnichars[endArabic-i+beginArabic];
}
for(i=0; i<=endArabic-beginArabic; i++) {
aSrcUnichars[i+beginArabic]=buf[i];
}
ArabicShaping(&aSrcUnichars[beginArabic], endArabic-beginArabic+1, buf, &len);
// to reverse the numerals
PRUint32 endNumeral, beginNumeral;
for (endNumeral=0;endNumeral<=len-1;endNumeral++){
PRBool foundNumeral = PR_FALSE;
while((endNumeral < len) && (IS_ARABIC_DIGIT(buf[endNumeral])) ) {
if(!foundNumeral)
{
foundNumeral=PR_TRUE;
beginNumeral=endNumeral;
}
endNumeral++;
}
if(foundNumeral){
endNumeral--;
PRUnichar numbuf[20];
for(i=beginNumeral; i<=endNumeral; i++){
numbuf[i-beginNumeral]=buf[endNumeral-i+beginNumeral];
}
for(i=0;i<=endNumeral-beginNumeral;i++){
buf[i+beginNumeral]=numbuf[i];
}
}
}
if(aDir==1){//ltr
for (i=0;i<=len-1;i++){
aDst+= buf[i];
}
}
else if(aDir==2){//rtl
for (i=0;i<=len-1;i++){
aDst+= buf[len-1-i];
}
}
} else {
aDst += aSrcUnichars[endArabic];
}
foundArabic=PR_FALSE;
}// for : loop the buffer
return NS_OK;
}
#endif //IBMBIDI

200
layout/base/nsBidiUtils.h Normal file
Просмотреть файл

@ -0,0 +1,200 @@
/* -*- 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 <mahar@eg.ibm.com>
* Lina Kemmel <lkemmel@il.ibm.com>
* Simon Montagu <smontagu@netscape.com>
*
*/
#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__ */

Просмотреть файл

@ -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);

Просмотреть файл

@ -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

Просмотреть файл

@ -72,6 +72,7 @@ $(NULL)
ifdef IBMBIDI
EXPORTS += \
nsBidiPresUtils.h \
nsBidi.h \
nsITextFrame.h \
$(NULL)
endif

Просмотреть файл

@ -65,6 +65,7 @@ EXPORTS = \
!ifdef IBMBIDI
nsBidiPresUtils.h \
nsITextFrame.h \
nsBidi.h \
!endif
$(NULL)

1047
layout/base/public/nsBidi.h Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -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<nsIBidi> mBidiEngine;
nsCOMPtr<nsIUBidiUtils> mUnicodeUtils;
nsBidi* mBidiEngine;
};
#endif /* nsBidiPresUtils_h___ */

Просмотреть файл

@ -72,6 +72,7 @@ CPPSRCS = \
ifdef IBMBIDI
CPPSRCS += \
nsBidiPresUtils.cpp \
nsBidi.cpp \
$(NULL)
endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -69,6 +69,7 @@ CPP_OBJS= \
.\$(OBJDIR)\nsStyleChangeList.obj \
!ifdef IBMBIDI
.\$(OBJDIR)\nsBidiPresUtils.obj \
.\$(OBJDIR)\nsBidi.obj \
!endif
$(NULL)

2342
layout/base/src/nsBidi.cpp Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -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<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 HandleNum() which is called for clipboard handling
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;
}
nsresult nsBidiPresUtils::HandleNumbers(const nsString& aSrc, nsString& aDst)
{
aDst = aSrc;
return HandleNumbers((PRUnichar *)aDst.get(),aDst.Length(),mNumflag);
}
#endif // IBMBIDI

Просмотреть файл

@ -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<nsIUBidiUtils> 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);
}
}

Просмотреть файл

@ -51,7 +51,7 @@
#include "nsIObserver.h"
#include "nsILookAndFeel.h"
#ifdef IBMBIDI
#include "nsIUBidiUtils.h"
#include "nsBidiUtils.h"
#endif
#include "nsHashtable.h"

Просмотреть файл

151
layout/base/symmtable.h Normal 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, 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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -97,7 +97,7 @@
#include "nsITextFrame.h"
//ahmed
#include "nsIUBidiUtils.h"
#include "nsBidiUtils.h"
//ahmed end
#endif // IBMBIDI

Просмотреть файл

@ -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

Просмотреть файл

@ -97,7 +97,7 @@
#include "nsITextFrame.h"
//ahmed
#include "nsIUBidiUtils.h"
#include "nsBidiUtils.h"
//ahmed end
#endif // IBMBIDI

Просмотреть файл

@ -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)
{

Просмотреть файл

@ -2026,6 +2026,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidi.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiFrames.cpp</PATH>
@ -2970,6 +2977,11 @@
<PATH>nsBidiPresUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidi.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiFrames.cpp</PATH>
@ -5045,6 +5057,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidi.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiFrames.cpp</PATH>
@ -5989,6 +6008,11 @@
<PATH>nsBidiPresUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidi.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidiFrames.cpp</PATH>
@ -6232,6 +6256,12 @@
<PATH>nsBidiPresUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>layout.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBidi.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<GROUP><NAME>build</NAME>
<FILEREF>

Просмотреть файл

@ -55,10 +55,6 @@
#include "nsRuleNode.h"
#ifdef IBMBIDI
#include "nsIUBidiUtils.h"
#endif
#ifdef DEBUG
// #define NOISY_DEBUG
#endif

Просмотреть файл

@ -53,7 +53,7 @@
#include "prenv.h"
#ifdef IBMBIDI
#include "nsIUBidiUtils.h"
#include "nsBidiUtils.h"
#endif
inline PRBool IsFixedUnit(nsStyleUnit aUnit, PRBool aEnumOK)

Просмотреть файл

@ -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 = <<END_OF_NPL;
/* -*- 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
*/
END_OF_NPL
print OUT $npl;
print OUT "\n#ifdef IBMBIDI\n\n";
print OUT "#include \"nscore.h\" \n\n";
%bidicategory = ();
%sh = ();
%sl = ();
%sc = ();
######################################################################
#
# Process the file line by line
#
######################################################################
while(<UNICODATA>) {
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 "<control>"))
{
#
# 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 = <<END_OF_NPL;
/* -*- 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
*/
END_OF_NPL
print OUT $npl;
print OUT "\n\n#include \"nscore.h\" \n\n";
%bidicategory = ();
%sh = ();
%sl = ();
%sc = ();
######################################################################
#
# Process the file line by line
#
######################################################################
while(<UNICODATA>) {
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 "<control>"))
{
#
# 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);

Просмотреть файл

@ -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 (<UNICODATA>) {
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 = <<END_OF_NPL;
/* -*- 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
*/
END_OF_NPL
print OUT $npl;
print OUT "#ifdef IBMBIDI\n";
# Generate data tables
foreach $block (0 .. 0xff) {
if (@isblock[$block]) {
printf OUT "\n/* Block U%02X__ */\n", $block;
printf OUT "const static PRUint8 symmtable_%02X[256] = {\n", $block;
print OUT "/* ";
foreach $byte (0 .. 0xf) {
printf OUT " _%X ", $byte;
}
print OUT "*/\n";
foreach $row (0 .. 0xf) {
printf OUT "/* %X_ */ ", $row;
foreach $byte (0 .. 0xf) {
$ix = ($block << 8) | ($row << 4) | ($byte);
printf OUT ("%#4x, ", @table[$ix]);
}
print OUT "\n";
}
print OUT "};\n";
}
}
# Generate conversion method
print OUT "\nstatic PRUnichar Mirrored(PRUnichar u)\n{\n";
print OUT " switch (u & 0xFF00) {\n";
print OUT " // XOR the character with the bitmap in the conversion table to give the symmetric equivalent\n";
foreach $block (0 .. 0xff) {
if (1==@isblock[$block]) {
printf OUT " case %#x:\n", $block * 256;
printf OUT " u ^= symmtable_%02X[u & 0xff];\n", $block;
print OUT " break;\n";
}
}
print OUT " }\n return u;\n}\n";
printf OUT "#endif // IBMBIDI\n";
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 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 (<UNICODATA>) {
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 = <<END_OF_NPL;
/* -*- 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
*/
END_OF_NPL
print OUT $npl;
# Generate data tables
foreach $block (0 .. 0xff) {
if (@isblock[$block]) {
printf OUT "\n/* Block U%02X__ */\n", $block;
printf OUT "const static PRUint8 symmtable_%02X[256] = {\n", $block;
print OUT "/* ";
foreach $byte (0 .. 0xf) {
printf OUT " _%X ", $byte;
}
print OUT "*/\n";
foreach $row (0 .. 0xf) {
printf OUT "/* %X_ */ ", $row;
foreach $byte (0 .. 0xf) {
$ix = ($block << 8) | ($row << 4) | ($byte);
printf OUT ("%#4x, ", @table[$ix]);
}
print OUT "\n";
}
print OUT "};\n";
}
}
# Generate conversion method
print OUT "\nstatic PRUnichar Mirrored(PRUnichar u)\n{\n";
print OUT " switch (u & 0xFF00) {\n";
print OUT " // XOR the character with the bitmap in the conversion table to give the symmetric equivalent\n";
foreach $block (0 .. 0xff) {
if (1==@isblock[$block]) {
printf OUT " case %#x:\n", $block * 256;
printf OUT " u ^= symmtable_%02X[u & 0xff];\n", $block;
print OUT " break;\n";
}
}
print OUT " }\n return u;\n}\n";
close(OUT);

Просмотреть файл

@ -64,7 +64,7 @@
#include "nsUnicharUtils.h"
#ifdef IBMBIDI
#include "nsIUBidiUtils.h"
#include "nsBidiUtils.h"
#include "nsBidiPresUtils.h"
#include "nsReadableUtils.h"
#endif // IBMBIDI