r=mkaply, r/sr=attinasi
Don't show Bidi control characters in the browser


git-svn-id: svn://10.0.0.236/trunk@108059 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mkaply%us.ibm.com 2001-11-14 14:21:52 +00:00
parent bdd0f4956c
commit b6110d2c3c
10 changed files with 268 additions and 68 deletions

View File

@ -933,7 +933,7 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext,
if (doReverse) {
rv = mBidiEngine->WriteReverse(aText, aTextLength, buffer,
NSBIDI_REMOVE_BIDI_CONTROLS | NSBIDI_DO_MIRRORING, &newLen);
NSBIDI_DO_MIRRORING, &newLen);
if (NS_SUCCEEDED(rv) ) {
aTextLength = newLen;
nsCRT::memcpy(aText, buffer, aTextLength * sizeof(PRUnichar) );
@ -947,9 +947,6 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext,
}
}
}
else {
StripBidiControlCharacters(aText, aTextLength);
}
return rv;
}
@ -1047,29 +1044,6 @@ nsBidiPresUtils::CalculateCharType(PRInt32& aOffset,
aOffset = offset;
}
void
nsBidiPresUtils::StripBidiControlCharacters(PRUnichar* aText,
PRInt32& aTextLength) const
{
if ( (nsnull == aText) || (aTextLength < 1) ) {
return;
}
PRInt32 stripLen = 0;
PRBool isBidiControl;
for (PRInt32 i = 0; i < aTextLength; i++) {
mUnicodeUtils->IsBidiControl(aText[i], &isBidiControl);
if (isBidiControl) {
++stripLen;
}
else {
aText[i - stripLen] = aText[i];
}
}
aTextLength -= stripLen;
}
nsresult nsBidiPresUtils::GetBidiEngine(nsIBidi** aBidiEngine)
{
nsresult rv = NS_ERROR_FAILURE;

View File

@ -162,8 +162,6 @@ private:
PRUint8& aCharType,
PRUint8& aPrevCharType) const;
void StripBidiControlCharacters(PRUnichar* aText,
PRInt32& aTextLength) const;
nsAutoString mBuffer;
nsVoidArray mLogicalFrames;
nsVoidArray mVisualFrames;

View File

@ -162,8 +162,6 @@ private:
PRUint8& aCharType,
PRUint8& aPrevCharType) const;
void StripBidiControlCharacters(PRUnichar* aText,
PRInt32& aTextLength) const;
nsAutoString mBuffer;
nsVoidArray mLogicalFrames;
nsVoidArray mVisualFrames;

View File

@ -933,7 +933,7 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext,
if (doReverse) {
rv = mBidiEngine->WriteReverse(aText, aTextLength, buffer,
NSBIDI_REMOVE_BIDI_CONTROLS | NSBIDI_DO_MIRRORING, &newLen);
NSBIDI_DO_MIRRORING, &newLen);
if (NS_SUCCEEDED(rv) ) {
aTextLength = newLen;
nsCRT::memcpy(aText, buffer, aTextLength * sizeof(PRUnichar) );
@ -947,9 +947,6 @@ nsBidiPresUtils::FormatUnicodeText(nsIPresContext* aPresContext,
}
}
}
else {
StripBidiControlCharacters(aText, aTextLength);
}
return rv;
}
@ -1047,29 +1044,6 @@ nsBidiPresUtils::CalculateCharType(PRInt32& aOffset,
aOffset = offset;
}
void
nsBidiPresUtils::StripBidiControlCharacters(PRUnichar* aText,
PRInt32& aTextLength) const
{
if ( (nsnull == aText) || (aTextLength < 1) ) {
return;
}
PRInt32 stripLen = 0;
PRBool isBidiControl;
for (PRInt32 i = 0; i < aTextLength; i++) {
mUnicodeUtils->IsBidiControl(aText[i], &isBidiControl);
if (isBidiControl) {
++stripLen;
}
else {
aText[i - stripLen] = aText[i];
}
}
aTextLength -= stripLen;
}
nsresult nsBidiPresUtils::GetBidiEngine(nsIBidi** aBidiEngine)
{
nsresult rv = NS_ERROR_FAILURE;

View File

@ -1488,6 +1488,9 @@ nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX,
if (0 != (mState & TEXT_SKIP_LEADING_WS)) {
PRBool isWhitespace, wasTransformed;
PRInt32 wordLen, contentLen;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
aTX.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed);
// we trip this assertion in bug 31053, but I think it's unnecessary
//NS_ASSERTION(isWhitespace, "mState and content are out of sync");
@ -1525,6 +1528,9 @@ nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX,
PRBool isWhitespace, wasTransformed;
PRInt32 wordLen, contentLen;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
// Get the next word
bp = aTX.GetNextWord(inWord, &wordLen, &contentLen, &isWhitespace, &wasTransformed);
if (nsnull == bp) {
@ -2245,7 +2251,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext,
charType, level & 1, isBidiSystem);
}
}
if (0 != textLength) { // textLength might change due to the bidi formattimg
if (0 < textLength) { // textLength might change due to the bidi formattimg
#endif // IBMBIDI
if (!displaySelection || !isSelected ) //draw text normally
{
@ -2313,11 +2319,16 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext,
nscolor currentFGColor = iter.CurrentForeGroundColor();
nscolor currentBKColor;
if (NS_SUCCEEDED(aRenderingContext.GetWidth(currenttext, currentlength,newWidth)))//ADJUST FOR CHAR SPACING
{
#ifdef IBMBIDI
if (currentlength > 0
&& NS_SUCCEEDED(aRenderingContext.GetWidth(currenttext, currentlength,newWidth)))//ADJUST FOR CHAR SPACING
{
if (isRightToLeftOnBidiPlatform)
currentX -= newWidth;
#else // not IBMBIDI
if (NS_SUCCEEDED(aRenderingContext.GetWidth(currenttext, currentlength,newWidth)))//ADJUST FOR CHAR SPACING
{
#endif
if (iter.CurrentBackGroundColor(currentBKColor) && !isPaginated)
{//DRAW RECT HERE!!!
@ -2338,7 +2349,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext,
}
#ifdef IBMBIDI
if (!isRightToLeftOnBidiPlatform)
if (!isRightToLeftOnBidiPlatform)
#endif
currentX+=newWidth;//increment twips X start
@ -3981,6 +3992,9 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
keepSearching = PR_TRUE;
tx.Init(this, mContent, aPos->mStartOffset);
aPos->mContentOffset = mContentOffset;//initialize
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset : -1;
#endif // IBMBIDI
if (tx.GetPrevWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace,
PR_FALSE) &&
(aPos->mStartOffset - contentLen >= mContentOffset) ){
@ -3993,11 +4007,17 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
aPos->mEatingWS = PR_FALSE;//if no real word then
}
else{
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset : -1;
#endif // IBMBIDI
while (isWhitespace &&
tx.GetPrevWord(PR_FALSE, &wordLen, &contentLen,
&isWhitespace, PR_FALSE)){
aPos->mContentOffset -= contentLen;
aPos->mEatingWS = PR_TRUE;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset : -1;
#endif // IBMBIDI
}
aPos->mEatingWS = !isWhitespace;//nowhite space, just eat chars.
keepSearching = aPos->mContentOffset <= mContentOffset;
@ -4024,6 +4044,9 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
tx.Init(this, mContent, aPos->mStartOffset );
aPos->mContentOffset = mContentOffset + mContentLength;//initialize
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
if (tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE) &&
(aPos->mStartOffset + contentLen <= (mContentLength + mContentOffset))){
@ -4034,7 +4057,11 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
if ( sWordSelectEatSpaceAfter ) {
keepSearching = PR_TRUE;
aPos->mEatingWS = PR_TRUE;
if (!isWhitespace){
if (!isWhitespace){
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI)
? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
while (tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
{
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
@ -4043,12 +4070,20 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
aPos->mContentOffset += contentLen;
else
break;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI)
? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
}
keepSearching = PR_FALSE;
found = PR_TRUE;
}
else //we just need to jump the space, done here
{
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI)
? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
while(tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
{
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
@ -4058,6 +4093,9 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
aPos->mContentOffset += contentLen;
else
break;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
}
keepSearching = PR_FALSE;
found = PR_TRUE;
@ -4422,6 +4460,9 @@ nsTextFrame::MeasureText(nsIPresContext* aPresContext,
char* bp1;
PRUnichar* bp2;
};
#ifdef IBMBIDI
wordLen = start;
#endif // IBMBIDI
bp2 = aTx.GetNextWord(aTextData.mInWord, &wordLen, &contentLen, &isWhitespace,
&wasTransformed, textRun.mNumSegments == 0);
#ifdef IBMBIDI
@ -5453,6 +5494,9 @@ nsTextFrame::ComputeWordFragmentDimensions(nsIPresContext* aPresContext,
PRBool isWhitespace, wasTransformed;
PRInt32 wordLen, contentLen;
nsTextDimensions dimensions;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
PRUnichar* bp = tx.GetNextWord(PR_TRUE, &wordLen, &contentLen, &isWhitespace, &wasTransformed);
if (!bp) {
//empty text node, but we need to continue lookahead measurement

View File

@ -146,8 +146,15 @@ nsTextTransformer::Shutdown()
// For now, we have only a couple of characters to strip out. If we get
// any more, change this to use a bitset to lookup into.
// CH_SHY - soft hyphen (discretionary hyphen)
#ifdef IBMBIDI
// added BIDI formatting codes
#define IS_DISCARDED(_ch) \
(((_ch) == CH_SHY) || ((_ch) == '\r') || IS_BIDI_CONTROL(_ch))
#else
#define IS_DISCARDED(_ch) \
(((_ch) == CH_SHY) || ((_ch) == '\r'))
#endif
#define MAX_UNIBYTE 127
@ -454,9 +461,23 @@ nsTextTransformer::ScanNormalUnicodeText_F(PRBool aForLineBreak,
const nsTextFragment* frag = mFrag;
const PRUnichar* cp0 = frag->Get2b();
PRInt32 fragLen = frag->GetLength();
#ifdef IBMBIDI
if (*aWordLen > 0 && *aWordLen < fragLen) {
fragLen = *aWordLen;
}
#endif
PRInt32 offset = mOffset;
PRUnichar firstChar = frag->CharAt(offset++);
#ifdef IBMBIDI
// Need to strip BIDI controls even when those are 'firstChars'.
// This doesn't seem to produce bug 14280 (or similar bugs).
while (offset < fragLen && IS_BIDI_CONTROL(firstChar) ) {
firstChar = frag->CharAt(offset++);
}
#endif // IBMBIDI
if (firstChar > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE);
// Only evaluate complex breaking logic if there are more characters
@ -771,6 +792,11 @@ nsTextTransformer::GetNextWord(PRBool aInWord,
{
const nsTextFragment* frag = mFrag;
PRInt32 fragLen = frag->GetLength();
#ifdef IBMBIDI
if (*aWordLenResult > 0 && *aWordLenResult < fragLen) {
fragLen = *aWordLenResult;
}
#endif
PRInt32 offset = mOffset;
PRInt32 wordLen = 0;
PRBool isWhitespace = PR_FALSE;
@ -831,6 +857,9 @@ nsTextTransformer::GetNextWord(PRBool aInWord,
}
}
else if (frag->Is2b()) {
#ifdef IBMBIDI
wordLen = *aWordLenResult;
#endif
offset = ScanNormalUnicodeText_F(aForLineBreak, &wordLen, aWasTransformed);
}
else {
@ -869,6 +898,9 @@ nsTextTransformer::GetNextWord(PRBool aInWord,
isWhitespace = PR_TRUE;
}
else if (frag->Is2b()) {
#ifdef IBMBIDI
wordLen = *aWordLenResult;
#endif
offset = ScanNormalUnicodeText_F(aForLineBreak, &wordLen, aWasTransformed);
}
else {
@ -1048,11 +1080,25 @@ nsTextTransformer::ScanNormalUnicodeText_B(PRBool aForLineBreak,
PRInt32 offset = mOffset - 1;
PRUnichar firstChar = frag->CharAt(offset);
#ifdef IBMBIDI
PRInt32 limit = (*aWordLen > 0) ? *aWordLen : 0;
while (offset > limit && IS_BIDI_CONTROL(firstChar) ) {
firstChar = frag->CharAt(--offset);
}
#endif
mTransformBuf.mBuffer[mTransformBuf.mBufferLen - 1] = firstChar;
if (firstChar > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE);
PRInt32 numChars = 1;
#ifdef IBMBIDI
if (offset > limit) {
#else
if (offset > 0) {
#endif
const PRUnichar* cp = cp0 + offset;
PRBool breakBetween = PR_FALSE;
if (aForLineBreak) {
@ -1207,7 +1253,12 @@ nsTextTransformer::GetPrevWord(PRBool aInWord,
if((! aForLineBreak) && (eNormal != mMode))
mMode = eNormal;
#ifdef IBMBIDI
PRInt32 limit = (*aWordLenResult > 0) ? *aWordLenResult : 0;
while (--offset >= limit) {
#else
while (--offset >= 0) {
#endif
PRUnichar firstChar = frag->CharAt(offset);
// Eat up any discarded characters before dispatching
@ -1229,6 +1280,9 @@ nsTextTransformer::GetPrevWord(PRBool aInWord,
mTransformBuf.mBuffer[mTransformBuf.mBufferLen - 1] = ' ';
offset--;
} else if (frag->Is2b()) {
#ifdef IBMBIDI
wordLen = *aWordLenResult;
#endif
offset = ScanNormalUnicodeText_B(aForLineBreak, &wordLen);
}
else {
@ -1261,6 +1315,9 @@ nsTextTransformer::GetPrevWord(PRBool aInWord,
isWhitespace = PR_TRUE;
}
else if (frag->Is2b()) {
#ifdef IBMBIDI
wordLen = *aWordLenResult;
#endif
offset = ScanNormalUnicodeText_B(aForLineBreak, &wordLen);
}
else {
@ -1465,6 +1522,9 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker,
int* expectedResults = st->modes[preMode].data;
int resultsLen = st->modes[preMode].length;
#ifdef IBMBIDI
wordLen = -1;
#endif
while ((bp = tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &ws, &transformed))) {
if (gNoisy) {
nsAutoString tmp(bp, wordLen);
@ -1479,6 +1539,9 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker,
break;
}
expectedResults++;
#ifdef IBMBIDI
wordLen = -1;
#endif
}
if (expectedResults != st->modes[preMode].data + resultsLen) {
if (st->modes[preMode].data[0] != 0) {
@ -1496,6 +1559,9 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker,
tx.Init2(&frag, frag.GetLength(), NS_STYLE_WHITESPACE_NORMAL,
NS_STYLE_TEXT_TRANSFORM_NONE);
expectedResults = st->modes[preMode].data + resultsLen;
#ifdef IBMBIDI
wordLen = -1;
#endif
while ((bp = tx.GetPrevWord(PR_FALSE, &wordLen, &contentLen, &ws))) {
--expectedResults;
if (gNoisy) {
@ -1510,6 +1576,9 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker,
error = PR_TRUE;
break;
}
#ifdef IBMBIDI
wordLen = -1;
#endif
}
if (expectedResults != st->modes[preMode].data) {
if (st->modes[preMode].data[0] != 0) {

View File

@ -54,6 +54,21 @@ class nsIWordBreaker;
#define CH_ZWNJ 8204 //<!ENTITY zwnj CDATA "&#8204;" -- zero width non-joiner, U+200C NEW RFC 2070#define CH_SHY 173
#define CH_SHY 173
#ifdef IBMBIDI
#define CH_ZWJ 8205 //<!ENTITY zwj CDATA "&#8205;" -- zero width joiner, U+200D NEW RFC 2070 -->
#define CH_LRM 8206 //<!ENTITY lrm CDATA "&#8206;" -- left-to-right mark, U+200E NEW RFC 2070 -->
#define CH_RLM 8207 //<!ENTITY rlm CDATA "&#8207;" -- right-to-left mark, U+200F NEW RFC 2070 -->
#define CH_LRE 8234 //<!CDATA "&#8234;" -- left-to-right embedding, U+202A -->
#define CH_RLE 8235 //<!CDATA "&#8235;" -- right-to-left embedding, U+202B -->
#define CH_PDF 8236 //<!CDATA "&#8236;" -- pop directional format, U+202C -->
#define CH_LRO 8237 //<!CDATA "&#8237;" -- left-to-right override, U+202D -->
#define CH_RLO 8238 //<!CDATA "&#8238;" -- right-to-left override, U+202E -->
#define IS_BIDI_CONTROL(_ch) \
(((_ch) >= CH_ZWNJ && (_ch) <= CH_RLM) \
|| ((_ch) >= CH_LRE && (_ch) <= CH_RLO))
#endif // IBMBIDI
#define NS_TEXT_TRANSFORMER_AUTO_WORD_BUF_SIZE 128 // used to be 256
// Indicates whether the transformed text should be left as ascii

View File

@ -1488,6 +1488,9 @@ nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX,
if (0 != (mState & TEXT_SKIP_LEADING_WS)) {
PRBool isWhitespace, wasTransformed;
PRInt32 wordLen, contentLen;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
aTX.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed);
// we trip this assertion in bug 31053, but I think it's unnecessary
//NS_ASSERTION(isWhitespace, "mState and content are out of sync");
@ -1525,6 +1528,9 @@ nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX,
PRBool isWhitespace, wasTransformed;
PRInt32 wordLen, contentLen;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
// Get the next word
bp = aTX.GetNextWord(inWord, &wordLen, &contentLen, &isWhitespace, &wasTransformed);
if (nsnull == bp) {
@ -2245,7 +2251,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext,
charType, level & 1, isBidiSystem);
}
}
if (0 != textLength) { // textLength might change due to the bidi formattimg
if (0 < textLength) { // textLength might change due to the bidi formattimg
#endif // IBMBIDI
if (!displaySelection || !isSelected ) //draw text normally
{
@ -2313,11 +2319,16 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext,
nscolor currentFGColor = iter.CurrentForeGroundColor();
nscolor currentBKColor;
if (NS_SUCCEEDED(aRenderingContext.GetWidth(currenttext, currentlength,newWidth)))//ADJUST FOR CHAR SPACING
{
#ifdef IBMBIDI
if (currentlength > 0
&& NS_SUCCEEDED(aRenderingContext.GetWidth(currenttext, currentlength,newWidth)))//ADJUST FOR CHAR SPACING
{
if (isRightToLeftOnBidiPlatform)
currentX -= newWidth;
#else // not IBMBIDI
if (NS_SUCCEEDED(aRenderingContext.GetWidth(currenttext, currentlength,newWidth)))//ADJUST FOR CHAR SPACING
{
#endif
if (iter.CurrentBackGroundColor(currentBKColor) && !isPaginated)
{//DRAW RECT HERE!!!
@ -2338,7 +2349,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext,
}
#ifdef IBMBIDI
if (!isRightToLeftOnBidiPlatform)
if (!isRightToLeftOnBidiPlatform)
#endif
currentX+=newWidth;//increment twips X start
@ -3981,6 +3992,9 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
keepSearching = PR_TRUE;
tx.Init(this, mContent, aPos->mStartOffset);
aPos->mContentOffset = mContentOffset;//initialize
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset : -1;
#endif // IBMBIDI
if (tx.GetPrevWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace,
PR_FALSE) &&
(aPos->mStartOffset - contentLen >= mContentOffset) ){
@ -3993,11 +4007,17 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
aPos->mEatingWS = PR_FALSE;//if no real word then
}
else{
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset : -1;
#endif // IBMBIDI
while (isWhitespace &&
tx.GetPrevWord(PR_FALSE, &wordLen, &contentLen,
&isWhitespace, PR_FALSE)){
aPos->mContentOffset -= contentLen;
aPos->mEatingWS = PR_TRUE;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset : -1;
#endif // IBMBIDI
}
aPos->mEatingWS = !isWhitespace;//nowhite space, just eat chars.
keepSearching = aPos->mContentOffset <= mContentOffset;
@ -4024,6 +4044,9 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
tx.Init(this, mContent, aPos->mStartOffset );
aPos->mContentOffset = mContentOffset + mContentLength;//initialize
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
if (tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE) &&
(aPos->mStartOffset + contentLen <= (mContentLength + mContentOffset))){
@ -4034,7 +4057,11 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
if ( sWordSelectEatSpaceAfter ) {
keepSearching = PR_TRUE;
aPos->mEatingWS = PR_TRUE;
if (!isWhitespace){
if (!isWhitespace){
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI)
? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
while (tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
{
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
@ -4043,12 +4070,20 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
aPos->mContentOffset += contentLen;
else
break;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI)
? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
}
keepSearching = PR_FALSE;
found = PR_TRUE;
}
else //we just need to jump the space, done here
{
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI)
? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
while(tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
{
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
@ -4058,6 +4093,9 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
aPos->mContentOffset += contentLen;
else
break;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
}
keepSearching = PR_FALSE;
found = PR_TRUE;
@ -4422,6 +4460,9 @@ nsTextFrame::MeasureText(nsIPresContext* aPresContext,
char* bp1;
PRUnichar* bp2;
};
#ifdef IBMBIDI
wordLen = start;
#endif // IBMBIDI
bp2 = aTx.GetNextWord(aTextData.mInWord, &wordLen, &contentLen, &isWhitespace,
&wasTransformed, textRun.mNumSegments == 0);
#ifdef IBMBIDI
@ -5453,6 +5494,9 @@ nsTextFrame::ComputeWordFragmentDimensions(nsIPresContext* aPresContext,
PRBool isWhitespace, wasTransformed;
PRInt32 wordLen, contentLen;
nsTextDimensions dimensions;
#ifdef IBMBIDI
wordLen = (mState & NS_FRAME_IS_BIDI) ? mContentOffset + mContentLength : -1;
#endif // IBMBIDI
PRUnichar* bp = tx.GetNextWord(PR_TRUE, &wordLen, &contentLen, &isWhitespace, &wasTransformed);
if (!bp) {
//empty text node, but we need to continue lookahead measurement

View File

@ -146,8 +146,15 @@ nsTextTransformer::Shutdown()
// For now, we have only a couple of characters to strip out. If we get
// any more, change this to use a bitset to lookup into.
// CH_SHY - soft hyphen (discretionary hyphen)
#ifdef IBMBIDI
// added BIDI formatting codes
#define IS_DISCARDED(_ch) \
(((_ch) == CH_SHY) || ((_ch) == '\r') || IS_BIDI_CONTROL(_ch))
#else
#define IS_DISCARDED(_ch) \
(((_ch) == CH_SHY) || ((_ch) == '\r'))
#endif
#define MAX_UNIBYTE 127
@ -454,9 +461,23 @@ nsTextTransformer::ScanNormalUnicodeText_F(PRBool aForLineBreak,
const nsTextFragment* frag = mFrag;
const PRUnichar* cp0 = frag->Get2b();
PRInt32 fragLen = frag->GetLength();
#ifdef IBMBIDI
if (*aWordLen > 0 && *aWordLen < fragLen) {
fragLen = *aWordLen;
}
#endif
PRInt32 offset = mOffset;
PRUnichar firstChar = frag->CharAt(offset++);
#ifdef IBMBIDI
// Need to strip BIDI controls even when those are 'firstChars'.
// This doesn't seem to produce bug 14280 (or similar bugs).
while (offset < fragLen && IS_BIDI_CONTROL(firstChar) ) {
firstChar = frag->CharAt(offset++);
}
#endif // IBMBIDI
if (firstChar > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE);
// Only evaluate complex breaking logic if there are more characters
@ -771,6 +792,11 @@ nsTextTransformer::GetNextWord(PRBool aInWord,
{
const nsTextFragment* frag = mFrag;
PRInt32 fragLen = frag->GetLength();
#ifdef IBMBIDI
if (*aWordLenResult > 0 && *aWordLenResult < fragLen) {
fragLen = *aWordLenResult;
}
#endif
PRInt32 offset = mOffset;
PRInt32 wordLen = 0;
PRBool isWhitespace = PR_FALSE;
@ -831,6 +857,9 @@ nsTextTransformer::GetNextWord(PRBool aInWord,
}
}
else if (frag->Is2b()) {
#ifdef IBMBIDI
wordLen = *aWordLenResult;
#endif
offset = ScanNormalUnicodeText_F(aForLineBreak, &wordLen, aWasTransformed);
}
else {
@ -869,6 +898,9 @@ nsTextTransformer::GetNextWord(PRBool aInWord,
isWhitespace = PR_TRUE;
}
else if (frag->Is2b()) {
#ifdef IBMBIDI
wordLen = *aWordLenResult;
#endif
offset = ScanNormalUnicodeText_F(aForLineBreak, &wordLen, aWasTransformed);
}
else {
@ -1048,11 +1080,25 @@ nsTextTransformer::ScanNormalUnicodeText_B(PRBool aForLineBreak,
PRInt32 offset = mOffset - 1;
PRUnichar firstChar = frag->CharAt(offset);
#ifdef IBMBIDI
PRInt32 limit = (*aWordLen > 0) ? *aWordLen : 0;
while (offset > limit && IS_BIDI_CONTROL(firstChar) ) {
firstChar = frag->CharAt(--offset);
}
#endif
mTransformBuf.mBuffer[mTransformBuf.mBufferLen - 1] = firstChar;
if (firstChar > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE);
PRInt32 numChars = 1;
#ifdef IBMBIDI
if (offset > limit) {
#else
if (offset > 0) {
#endif
const PRUnichar* cp = cp0 + offset;
PRBool breakBetween = PR_FALSE;
if (aForLineBreak) {
@ -1207,7 +1253,12 @@ nsTextTransformer::GetPrevWord(PRBool aInWord,
if((! aForLineBreak) && (eNormal != mMode))
mMode = eNormal;
#ifdef IBMBIDI
PRInt32 limit = (*aWordLenResult > 0) ? *aWordLenResult : 0;
while (--offset >= limit) {
#else
while (--offset >= 0) {
#endif
PRUnichar firstChar = frag->CharAt(offset);
// Eat up any discarded characters before dispatching
@ -1229,6 +1280,9 @@ nsTextTransformer::GetPrevWord(PRBool aInWord,
mTransformBuf.mBuffer[mTransformBuf.mBufferLen - 1] = ' ';
offset--;
} else if (frag->Is2b()) {
#ifdef IBMBIDI
wordLen = *aWordLenResult;
#endif
offset = ScanNormalUnicodeText_B(aForLineBreak, &wordLen);
}
else {
@ -1261,6 +1315,9 @@ nsTextTransformer::GetPrevWord(PRBool aInWord,
isWhitespace = PR_TRUE;
}
else if (frag->Is2b()) {
#ifdef IBMBIDI
wordLen = *aWordLenResult;
#endif
offset = ScanNormalUnicodeText_B(aForLineBreak, &wordLen);
}
else {
@ -1465,6 +1522,9 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker,
int* expectedResults = st->modes[preMode].data;
int resultsLen = st->modes[preMode].length;
#ifdef IBMBIDI
wordLen = -1;
#endif
while ((bp = tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &ws, &transformed))) {
if (gNoisy) {
nsAutoString tmp(bp, wordLen);
@ -1479,6 +1539,9 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker,
break;
}
expectedResults++;
#ifdef IBMBIDI
wordLen = -1;
#endif
}
if (expectedResults != st->modes[preMode].data + resultsLen) {
if (st->modes[preMode].data[0] != 0) {
@ -1496,6 +1559,9 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker,
tx.Init2(&frag, frag.GetLength(), NS_STYLE_WHITESPACE_NORMAL,
NS_STYLE_TEXT_TRANSFORM_NONE);
expectedResults = st->modes[preMode].data + resultsLen;
#ifdef IBMBIDI
wordLen = -1;
#endif
while ((bp = tx.GetPrevWord(PR_FALSE, &wordLen, &contentLen, &ws))) {
--expectedResults;
if (gNoisy) {
@ -1510,6 +1576,9 @@ nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker,
error = PR_TRUE;
break;
}
#ifdef IBMBIDI
wordLen = -1;
#endif
}
if (expectedResults != st->modes[preMode].data) {
if (st->modes[preMode].data[0] != 0) {

View File

@ -54,6 +54,21 @@ class nsIWordBreaker;
#define CH_ZWNJ 8204 //<!ENTITY zwnj CDATA "&#8204;" -- zero width non-joiner, U+200C NEW RFC 2070#define CH_SHY 173
#define CH_SHY 173
#ifdef IBMBIDI
#define CH_ZWJ 8205 //<!ENTITY zwj CDATA "&#8205;" -- zero width joiner, U+200D NEW RFC 2070 -->
#define CH_LRM 8206 //<!ENTITY lrm CDATA "&#8206;" -- left-to-right mark, U+200E NEW RFC 2070 -->
#define CH_RLM 8207 //<!ENTITY rlm CDATA "&#8207;" -- right-to-left mark, U+200F NEW RFC 2070 -->
#define CH_LRE 8234 //<!CDATA "&#8234;" -- left-to-right embedding, U+202A -->
#define CH_RLE 8235 //<!CDATA "&#8235;" -- right-to-left embedding, U+202B -->
#define CH_PDF 8236 //<!CDATA "&#8236;" -- pop directional format, U+202C -->
#define CH_LRO 8237 //<!CDATA "&#8237;" -- left-to-right override, U+202D -->
#define CH_RLO 8238 //<!CDATA "&#8238;" -- right-to-left override, U+202E -->
#define IS_BIDI_CONTROL(_ch) \
(((_ch) >= CH_ZWNJ && (_ch) <= CH_RLM) \
|| ((_ch) >= CH_LRE && (_ch) <= CH_RLO))
#endif // IBMBIDI
#define NS_TEXT_TRANSFORMER_AUTO_WORD_BUF_SIZE 128 // used to be 256
// Indicates whether the transformed text should be left as ascii