From 90236fac1017ce0c19c44c2811329f4d2dbdd07d Mon Sep 17 00:00:00 2001 From: "smontagu%smontagu.org" Date: Sun, 4 Jul 2004 10:51:33 +0000 Subject: [PATCH] Improve the CHAR_IS_BIDI macro. Bug 240943, patch from an idea by Peter Kirk, r+sr=roc git-svn-id: svn://10.0.0.236/trunk@158733 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/shared/public/nsBidiUtils.h | 22 +++++++++++++++---- mozilla/content/shared/src/nsTextFragment.cpp | 2 +- mozilla/layout/base/nsBidiUtils.h | 22 +++++++++++++++---- .../layout/xul/base/src/nsTextBoxFrame.cpp | 14 ++++++------ 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/mozilla/content/shared/public/nsBidiUtils.h b/mozilla/content/shared/public/nsBidiUtils.h index fa687898711..441769c8c3d 100644 --- a/mozilla/content/shared/public/nsBidiUtils.h +++ b/mozilla/content/shared/public/nsBidiUtils.h @@ -221,9 +221,23 @@ #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) || IS_ARABIC_SEPARATOR(c))) -#define IS_CYPRIOT_CHAR(c) ((0x10800 <= (c)) && ((c) <=0x1083F)) -#define CHAR_IS_BIDI(c) ( (IS_HINDI_DIGIT(c) ) || (IS_HEBREW_CHAR(c) ) \ - || (IS_06_CHAR(c) ) || (IS_FE_CHAR(c) ) \ - || (IS_CYPRIOT_CHAR(c) ) ) +/** + * The codepoint ranges in the following macros are based on the blocks + * allocated, or planned to be allocated, to right-to-left characters in the + * BMP (Basic Multilingual Plane) and SMP (Supplementary Multilingual Plane) + * according to + * http://unicode.org/Public/UNIDATA/extracted/DerivedBidiClass.txt and + * http://www.unicode.org/roadmaps/ + */ + +#define IS_IN_BMP_RTL_BLOCK(c) ((0x590 <= (c)) && ((c) <= 0x8ff)) +#define IS_RTL_PRESENTATION_FORM(c) (((0xfb1d <= (c)) && ((c) <= 0xfdff)) || \ + ((0xfe70 <= (c)) && ((c) <= 0xfefc))) +#define IS_IN_SMP_RTL_BLOCK(c) ((0x10800 <= (c)) && ((c) <= 0x10fff)) +#define UCS2_CHAR_IS_BIDI(c) ((IS_IN_BMP_RTL_BLOCK(c)) || \ + (IS_RTL_PRESENTATION_FORM(c))) +#define UTF32_CHAR_IS_BIDI(c) ((IS_IN_BMP_RTL_BLOCK(c)) || \ + (IS_RTL_PRESENTATION_FORM(c)) || \ + (IS_IN_SMP_RTL_BLOCK(c))) #endif /* nsBidiUtils_h__ */ diff --git a/mozilla/content/shared/src/nsTextFragment.cpp b/mozilla/content/shared/src/nsTextFragment.cpp index c770e454d8f..094504822b3 100644 --- a/mozilla/content/shared/src/nsTextFragment.cpp +++ b/mozilla/content/shared/src/nsTextFragment.cpp @@ -359,7 +359,7 @@ nsTextFragment::SetBidiFlag() PRUnichar ch2 = *cp++; utf32Char = SURROGATE_TO_UCS4(ch1, ch2); } - if (CHAR_IS_BIDI(utf32Char) ) { + if (UTF32_CHAR_IS_BIDI(utf32Char) ) { mState.mIsBidi = PR_TRUE; break; } diff --git a/mozilla/layout/base/nsBidiUtils.h b/mozilla/layout/base/nsBidiUtils.h index fa687898711..441769c8c3d 100644 --- a/mozilla/layout/base/nsBidiUtils.h +++ b/mozilla/layout/base/nsBidiUtils.h @@ -221,9 +221,23 @@ #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) || IS_ARABIC_SEPARATOR(c))) -#define IS_CYPRIOT_CHAR(c) ((0x10800 <= (c)) && ((c) <=0x1083F)) -#define CHAR_IS_BIDI(c) ( (IS_HINDI_DIGIT(c) ) || (IS_HEBREW_CHAR(c) ) \ - || (IS_06_CHAR(c) ) || (IS_FE_CHAR(c) ) \ - || (IS_CYPRIOT_CHAR(c) ) ) +/** + * The codepoint ranges in the following macros are based on the blocks + * allocated, or planned to be allocated, to right-to-left characters in the + * BMP (Basic Multilingual Plane) and SMP (Supplementary Multilingual Plane) + * according to + * http://unicode.org/Public/UNIDATA/extracted/DerivedBidiClass.txt and + * http://www.unicode.org/roadmaps/ + */ + +#define IS_IN_BMP_RTL_BLOCK(c) ((0x590 <= (c)) && ((c) <= 0x8ff)) +#define IS_RTL_PRESENTATION_FORM(c) (((0xfb1d <= (c)) && ((c) <= 0xfdff)) || \ + ((0xfe70 <= (c)) && ((c) <= 0xfefc))) +#define IS_IN_SMP_RTL_BLOCK(c) ((0x10800 <= (c)) && ((c) <= 0x10fff)) +#define UCS2_CHAR_IS_BIDI(c) ((IS_IN_BMP_RTL_BLOCK(c)) || \ + (IS_RTL_PRESENTATION_FORM(c))) +#define UTF32_CHAR_IS_BIDI(c) ((IS_IN_BMP_RTL_BLOCK(c)) || \ + (IS_RTL_PRESENTATION_FORM(c)) || \ + (IS_IN_SMP_RTL_BLOCK(c))) #endif /* nsBidiUtils_h__ */ diff --git a/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp b/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp index d99b17e0184..ccbe43e39d1 100644 --- a/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp @@ -507,12 +507,12 @@ nsTextBoxFrame::CalculateTitleForWidth(nsIPresContext* aPresContext, #ifdef IBMBIDI PRInt32 length = mTitle.Length(); for (PRInt32 i = 0; i < length; i++) { - if ((CHAR_IS_BIDI(mTitle.CharAt(i)) ) || + if ((UCS2_CHAR_IS_BIDI(mTitle.CharAt(i)) ) || ((IS_HIGH_SURROGATE(mTitle.CharAt(i))) && (++i < length) && (IS_LOW_SURROGATE(mTitle.CharAt(i))) && - (CHAR_IS_BIDI(SURROGATE_TO_UCS4(mTitle.CharAt(i-1), - mTitle.CharAt(i)))))) { + (UTF32_CHAR_IS_BIDI(SURROGATE_TO_UCS4(mTitle.CharAt(i-1), + mTitle.CharAt(i)))))) { mState |= NS_FRAME_IS_BIDI; break; } @@ -562,7 +562,7 @@ nsTextBoxFrame::CalculateTitleForWidth(nsIPresContext* aPresContext, twidth += cwidth; #ifdef IBMBIDI - if (CHAR_IS_BIDI(ch) ) { + if (UCS2_CHAR_IS_BIDI(ch) ) { mState |= NS_FRAME_IS_BIDI; } #endif // IBMBIDI @@ -592,7 +592,7 @@ nsTextBoxFrame::CalculateTitleForWidth(nsIPresContext* aPresContext, twidth += cwidth; #ifdef IBMBIDI - if (CHAR_IS_BIDI(ch) ) { + if (UCS2_CHAR_IS_BIDI(ch) ) { mState |= NS_FRAME_IS_BIDI; } #endif // IBMBIDI @@ -636,7 +636,7 @@ nsTextBoxFrame::CalculateTitleForWidth(nsIPresContext* aPresContext, leftString.Insert(ch, leftString.Length()); #ifdef IBMBIDI - if (CHAR_IS_BIDI(ch)) + if (UCS2_CHAR_IS_BIDI(ch)) mState |= NS_FRAME_IS_BIDI; #endif @@ -652,7 +652,7 @@ nsTextBoxFrame::CalculateTitleForWidth(nsIPresContext* aPresContext, rightString.Insert(ch, 0); #ifdef IBMBIDI - if (CHAR_IS_BIDI(ch)) + if (UCS2_CHAR_IS_BIDI(ch)) mState |= NS_FRAME_IS_BIDI; #endif }