Back to index

lightning-sunbird  0.9+nobinonly
nsBidiUtils.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * IBM Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Maha Abou El Rous <mahar@eg.ibm.com>
00024  *   Lina Kemmel <lkemmel@il.ibm.com>
00025  *   Simon Montagu <smontagu@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #ifndef nsBidiUtils_h__
00042 #define nsBidiUtils_h__
00043 
00044 #include "nsCOMPtr.h"
00045 #include "nsString.h"
00046 
00056   nsresult ArabicShaping(const PRUnichar* aString, PRUint32 aLen,
00057                          PRUnichar* aBuf, PRUint32* aBufLen,
00058                          PRBool aInputLogical, PRBool aOutputLogical);
00059 
00066   nsresult Conv_FE_06(const nsString& aSrc, nsString& aDst);
00067 
00074   nsresult Conv_FE_06_WithReverse(const nsString& aSrc, nsString& aDst);
00075 
00085   nsresult Conv_06_FE_WithReverse(const nsString& aSrc, nsString& aDst, PRUint32 aDir);
00086 
00097   nsresult HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32  aNumFlag);
00098 
00104   nsresult HandleNumbers(const nsString& aSrc, nsString& aDst);
00105 
00106 // --------------------------------------------------
00107 // IBMBIDI 
00108 // --------------------------------------------------
00109 //
00110 // These values are shared with Preferences dialog
00111 //  ------------------
00112 //  If Pref values are to be changed
00113 //  in the XUL file of Prefs. the values
00114 //  Must be changed here too..
00115 //  ------------------
00116 //
00117 #define IBMBIDI_TEXTDIRECTION_STR       "bidi.direction"
00118 #define IBMBIDI_TEXTTYPE_STR            "bidi.texttype"
00119 #define IBMBIDI_CONTROLSTEXTMODE_STR    "bidi.controlstextmode"
00120 #define IBMBIDI_NUMERAL_STR             "bidi.numeral"
00121 #define IBMBIDI_SUPPORTMODE_STR         "bidi.support"
00122 #define IBMBIDI_CHARSET_STR             "bidi.characterset"
00123 
00124 #define IBMBIDI_TEXTDIRECTION       1
00125 #define IBMBIDI_TEXTTYPE            2
00126 #define IBMBIDI_CONTROLSTEXTMODE    3
00127 #define IBMBIDI_NUMERAL             4
00128 #define IBMBIDI_SUPPORTMODE         5
00129 #define IBMBIDI_CHARSET             6
00130 
00131 //  ------------------
00132 //  Text Direction
00133 //  ------------------
00134 //  bidi.direction
00135 #define IBMBIDI_TEXTDIRECTION_LTR     1 //  1 = directionLTRBidi *
00136 #define IBMBIDI_TEXTDIRECTION_RTL     2 //  2 = directionRTLBidi
00137 //  ------------------
00138 //  Text Type
00139 //  ------------------
00140 //  bidi.texttype
00141 #define IBMBIDI_TEXTTYPE_CHARSET      1 //  1 = charsettexttypeBidi *
00142 #define IBMBIDI_TEXTTYPE_LOGICAL      2 //  2 = logicaltexttypeBidi
00143 #define IBMBIDI_TEXTTYPE_VISUAL       3 //  3 = visualtexttypeBidi
00144 //  ------------------
00145 //  Controls Text Mode
00146 //  ------------------
00147 //  bidi.controlstextmode
00148 #define IBMBIDI_CONTROLSTEXTMODE_LOGICAL   1 //  1 = logicalcontrolstextmodeBidiCmd *
00149 #define IBMBIDI_CONTROLSTEXTMODE_VISUAL    2 //  2 = visualcontrolstextmodeBidi
00150 #define IBMBIDI_CONTROLSTEXTMODE_CONTAINER 3 //  3 = containercontrolstextmodeBidi
00151 //  ------------------
00152 //  Numeral Style
00153 //  ------------------
00154 //  bidi.numeral
00155 #define IBMBIDI_NUMERAL_NOMINAL       0 //  0 = nominalnumeralBidi *
00156 #define IBMBIDI_NUMERAL_REGULAR       1 //  1 = regularcontextnumeralBidi
00157 #define IBMBIDI_NUMERAL_HINDICONTEXT  2 //  2 = hindicontextnumeralBidi
00158 #define IBMBIDI_NUMERAL_ARABIC        3 //  3 = arabicnumeralBidi
00159 #define IBMBIDI_NUMERAL_HINDI         4 //  4 = hindinumeralBidi
00160 //  ------------------
00161 //  Support Mode
00162 //  ------------------
00163 //  bidi.support
00164 #define IBMBIDI_SUPPORTMODE_MOZILLA     1 //  1 = mozillaBidisupport *
00165 #define IBMBIDI_SUPPORTMODE_OSBIDI      2 //  2 = OsBidisupport
00166 #define IBMBIDI_SUPPORTMODE_DISABLE     3 //  3 = disableBidisupport
00167 //  ------------------
00168 //  Charset Mode
00169 //  ------------------
00170 //  bidi.characterset
00171 #define IBMBIDI_CHARSET_BIDI        1 //  1 = doccharactersetBidi *
00172 #define IBMBIDI_CHARSET_DEFAULT     2 //  2 = defaultcharactersetBidi
00173 
00174 #define IBMBIDI_DEFAULT_BIDI_OPTIONS              \
00175         ((IBMBIDI_TEXTDIRECTION_LTR<<0)         | \
00176          (IBMBIDI_TEXTTYPE_CHARSET<<4)          | \
00177          (IBMBIDI_CONTROLSTEXTMODE_LOGICAL<<8)  | \
00178          (IBMBIDI_NUMERAL_NOMINAL<<12)          | \
00179          (IBMBIDI_SUPPORTMODE_MOZILLA<<16)      | \
00180          (IBMBIDI_CHARSET_BIDI<<20))
00181 
00182 
00183 #define GET_BIDI_OPTION_DIRECTION(bo) (((bo)>>0) & 0x0000000F) /* 4 bits for DIRECTION */
00184 #define GET_BIDI_OPTION_TEXTTYPE(bo) (((bo)>>4) & 0x0000000F) /* 4 bits for TEXTTYPE */
00185 #define GET_BIDI_OPTION_CONTROLSTEXTMODE(bo) (((bo)>>8) & 0x0000000F) /* 4 bits for CONTROLTEXTMODE */
00186 #define GET_BIDI_OPTION_NUMERAL(bo) (((bo)>>12) & 0x0000000F) /* 4 bits for NUMERAL */
00187 #define GET_BIDI_OPTION_SUPPORT(bo) (((bo)>>16) & 0x0000000F) /* 4 bits for SUPPORT */
00188 #define GET_BIDI_OPTION_CHARACTERSET(bo) (((bo)>>20) & 0x0000000F) /* 4 bits for CHARACTERSET */
00189 
00190 #define SET_BIDI_OPTION_DIRECTION(bo, dir) {(bo)=((bo) & 0xFFFFFFF0)|(((dir)& 0x0000000F)<<0);}
00191 #define SET_BIDI_OPTION_TEXTTYPE(bo, tt) {(bo)=((bo) & 0xFFFFFF0F)|(((tt)& 0x0000000F)<<4);}
00192 #define SET_BIDI_OPTION_CONTROLSTEXTMODE(bo, cotm) {(bo)=((bo) & 0xFFFFF0FF)|(((cotm)& 0x0000000F)<<8);}
00193 #define SET_BIDI_OPTION_NUMERAL(bo, num) {(bo)=((bo) & 0xFFFF0FFF)|(((num)& 0x0000000F)<<12);}
00194 #define SET_BIDI_OPTION_SUPPORT(bo, sup) {(bo)=((bo) & 0xFFF0FFFF)|(((sup)& 0x0000000F)<<16);}
00195 #define SET_BIDI_OPTION_CHARACTERSET(bo, cs) {(bo)=((bo) & 0xFF0FFFFF)|(((cs)& 0x0000000F)<<20);}
00196 
00197 /* Constants related to the position of numerics in the codepage */
00198 #define START_HINDI_DIGITS              0x0660
00199 #define END_HINDI_DIGITS                0x0669
00200 #define START_ARABIC_DIGITS             0x0030
00201 #define END_ARABIC_DIGITS               0x0039
00202 #define START_FARSI_DIGITS              0x06f0
00203 #define END_FARSI_DIGITS                0x06f9
00204 #define IS_HINDI_DIGIT(u)   ( ( (u) >= START_HINDI_DIGITS )  && ( (u) <= END_HINDI_DIGITS ) )
00205 #define IS_ARABIC_DIGIT(u)  ( ( (u) >= START_ARABIC_DIGITS ) && ( (u) <= END_ARABIC_DIGITS ) )
00206 #define IS_FARSI_DIGIT(u)  ( ( (u) >= START_FARSI_DIGITS ) && ( (u) <= END_FARSI_DIGITS ) )
00207 #define IS_ARABIC_SEPARATOR(u) ( ( (u) == 0x066A ) || ( (u) == 0x066B ) || ( (u) == 0x066C ) )
00208 
00209 #define IS_BIDI_DIACRITIC(u) ( \
00210   ( (u) >= 0x0591 && (u) <= 0x05A1) || ( (u) >= 0x05A3 && (u) <= 0x05B9) \
00211     || ( (u) >= 0x05BB && (u) <= 0x05BD) || ( (u) == 0x05BF) || ( (u) == 0x05C1) \
00212     || ( (u) == 0x05C2) || ( (u) == 0x05C4) \
00213     || ( (u) >= 0x064B && (u) <= 0x0652) || ( (u) == 0x0670) \
00214     || ( (u) >= 0x06D7 && (u) <= 0x06E4) || ( (u) == 0x06E7) || ( (u) == 0x06E8) \
00215     || ( (u) >= 0x06EA && (u) <= 0x06ED) )
00216 
00217 #define IS_HEBREW_CHAR(c) (((0x0590 <= (c)) && ((c)<= 0x05FF)) || (((c) >= 0xfb1d) && ((c) <= 0xfb4f)))
00218 #define IS_06_CHAR(c) ((0x0600 <= (c)) && ((c)<= 0x06FF))
00219 #define IS_FE_CHAR(c) (((0xfb50 <= (c)) && ((c)<= 0xfbFF)) \
00220                        || ((0xfe70 <= (c)) && ((c)<= 0xfeFC)))
00221 #define IS_ARABIC_CHAR(c) ((0x0600 <= (c)) && ((c)<= 0x06FF))
00222 #define IS_ARABIC_ALPHABETIC(c) (IS_ARABIC_CHAR(c) && \
00223                                 !(IS_HINDI_DIGIT(c) || IS_FARSI_DIGIT(c) || IS_ARABIC_SEPARATOR(c)))
00224 #define IS_BIDI_CONTROL_CHAR(c) ((0x202a <= (c)) && ((c)<= 0x202e) \
00225                                 || ((c) == 0x200e) || ((c) == 0x200f))
00226 
00236 #define IS_IN_BMP_RTL_BLOCK(c) ((0x590 <= (c)) && ((c) <= 0x8ff))
00237 #define IS_RTL_PRESENTATION_FORM(c) (((0xfb1d <= (c)) && ((c) <= 0xfdff)) || \
00238                                      ((0xfe70 <= (c)) && ((c) <= 0xfefc)))
00239 #define IS_IN_SMP_RTL_BLOCK(c) ((0x10800 <= (c)) && ((c) <= 0x10fff))
00240 #define UCS2_CHAR_IS_BIDI(c) ((IS_IN_BMP_RTL_BLOCK(c)) || \
00241                               (IS_RTL_PRESENTATION_FORM(c)))
00242 #define UTF32_CHAR_IS_BIDI(c)  ((IS_IN_BMP_RTL_BLOCK(c)) || \
00243                                (IS_RTL_PRESENTATION_FORM(c)) || \
00244                                (IS_IN_SMP_RTL_BLOCK(c)))
00245 #endif  /* nsBidiUtils_h__ */