Back to index

lightning-sunbird  0.9+nobinonly
nsUnicodeToLangBoxArabic8.cpp
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 Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 
00039 #include "nsUCConstructors.h"
00040 #include "nsUnicodeToLangBoxArabic8.h"
00041 
00042 #include "nsISupports.h"
00043 
00044 static const unsigned char uni2lbox [] = 
00045  {
00046   0xC1,   /* FE80 */
00047   0xC2 , 
00048   0xC2 , 
00049   0xC3 , 
00050   0xC3 , 
00051   0xC4 , 
00052   0xC4 , 
00053   0xC5 , 
00054   0xC5 , 
00055   0x9F , 
00056   0xC6 , 
00057   0xC0 , 
00058   0xC0 , 
00059   0xC7 ,
00060   0xC7 , 
00061   0xC8 , 
00062   0xC8 , /* FE90 */
00063   0xEB , 
00064   0xEB , 
00065   0xC9 , 
00066   0x8E , /* START TAA MARBUTA FINAL */
00067   0xCA , 
00068   0xCA , 
00069   0xEC , 
00070   0xEC , 
00071   0xCB , 
00072   0xCB , 
00073   0xED , 
00074   0xED , 
00075   0xCC , 
00076   0xCC , 
00077   0xEE , 
00078   0xEE , 
00079   0xCD , 
00080   0xCD , 
00081   0xEF , 
00082   0xEF , 
00083   0xCE ,
00084   0xCE , 
00085   0xF0 , 
00086   0xF0 , 
00087   0xCF , 
00088   0xCF , 
00089   0xD0 , 
00090   0xD0 , 
00091   0xD1 ,
00092   0xD1 , 
00093   0xD2 , 
00094   0xD2 , 
00095   0xD3 , 
00096   0x8F , 
00097   0xF1 , 
00098   0xF1 , 
00099   0xD4 , 
00100   0x90 , 
00101   0xF2 , 
00102   0xF2 , 
00103   0xD5 , 
00104   0x91 , 
00105   0xF3 , 
00106   0xF3 , 
00107   0xD6 ,
00108   0x92 , 
00109   0xF4 , 
00110   0xF4 , 
00111   0xD7 ,
00112   0xD7 , 
00113   0x93 , 
00114   0x93 , 
00115   0xD8 , 
00116   0xD8 , 
00117   0x94 , 
00118   0x94 , 
00119   0xD9 , 
00120   0x96 , 
00121   0xF5 , 
00122   0x95 , 
00123   0xDA ,
00124   0x98 , 
00125   0xF6 , 
00126   0x97 , 
00127   0xE1 , 
00128   0xE1 , 
00129   0xF7 , 
00130   0x99 , 
00131   0xE2 , 
00132   0xE2 , 
00133   0xF8 , 
00134   0x9A , 
00135   0xE3 , 
00136   0xE3 , 
00137   0xF9 , 
00138   0x9B , 
00139   0xE4 , 
00140   0xE4 , 
00141   0xFA , 
00142   0xFA , 
00143   0xE5 , 
00144   0xE5 , 
00145   0xFB , 
00146   0xFB , 
00147   0xE6 , 
00148   0xE6 , 
00149   0xFC , 
00150   0xFC , 
00151   0xE7 , 
00152   0x9D , 
00153   0xFD , 
00154   0x9C , 
00155   0xE8 , 
00156   0xE8 , 
00157   0x8D , 
00158   0xE9 , 
00159   0x9E , 
00160   0xEA , 
00161   0xFE , 
00162   0xFE  /* FEF4 */
00163  };
00164 
00187 static const unsigned char lboxAlefs[] =
00188 {
00189   0xA2,
00190   0xA3,
00191   0xA4,
00192   0xA1
00193 };
00194 
00195 static const unsigned char lboxLams[] = 
00196 {
00197   0xA5,
00198   0xA6
00199 };
00200 
00201 NS_IMETHODIMP nsUnicodeToLangBoxArabic8::Convert(
00202       const PRUnichar * aSrc, PRInt32 * aSrcLength,
00203       char * aDest, PRInt32 * aDestLength)
00204 {
00205    char* dest = aDest;
00206    PRInt32 inlen = 0;
00207 
00208    while (inlen < *aSrcLength) {
00209      PRUnichar aChar = aSrc[inlen];
00210 
00211      if((aChar >= 0x0660) && (aChar <=0x0669)) { /* Hindu Numerals */
00212        *dest++ = (char)(aChar - 0x0660 + 0xB0);
00213      } else if ((aChar >= 0x064B) && (aChar <= 0x0652)) {
00214        *dest++ = (char)(aChar - 0x64B + 0xA8);
00215      } else if(0x060C == aChar) {
00216        *dest++ = (char)0xBA;
00217      } else if(0x061B == aChar) {
00218        *dest++ = (char)0xBB;
00219      } else if(0x061F == aChar) {
00220        *dest++ = (char)0xBF;
00221      } else if(0x0640 == aChar) {
00222        *dest++ = (char)0xE0;
00223      } else if ((aChar>=0xFE80) && (aChar <= 0xFEF4)) {
00224        *dest++ = uni2lbox[aChar-0xFE80];
00225      } else if ((aChar >=0xFEF5) && (aChar <= 0xFEFC)) {
00226        PRUint8 lamAlefType = aChar - 0xFEF5;       // first map to 0-7 range,
00227        PRUint8 alefType = (lamAlefType & 6) >> 1;  // then the high 2 bits give us the type of alef
00228        PRUint8 lamType = lamAlefType & 1;          // and the low bits give us the type of lam
00229 
00230        *dest++ = lboxAlefs[alefType];
00231        *dest++ = lboxLams[lamType];
00232      } else if ((aChar >=0x0001) && (aChar <= 0x007F)) {
00233        *dest++ = (char) (aChar & 0x7F);
00234      } else {
00235        // do nothing
00236      }
00237      inlen++;
00238    }
00239 
00240     *aDestLength = dest - aDest;
00241     return NS_OK;
00242 }
00243 
00244 NS_IMETHODIMP nsUnicodeToLangBoxArabic8::GetMaxLength(
00245 const PRUnichar * aSrc, PRInt32 aSrcLength, 
00246                            PRInt32 * aDestLength) 
00247 {
00248   *aDestLength = 2*aSrcLength;
00249   return NS_OK;
00250 }
00251 
00252 NS_IMETHODIMP nsUnicodeToLangBoxArabic8::Finish(
00253       char * aDest, PRInt32 * aDestLength)
00254 {
00255    *aDestLength=0;
00256    return NS_OK;
00257 }
00258 
00259 NS_IMETHODIMP nsUnicodeToLangBoxArabic8::Reset()
00260 {
00261    return NS_OK;
00262 }
00263 
00264 NS_IMETHODIMP nsUnicodeToLangBoxArabic8::SetOutputErrorBehavior(
00265       PRInt32 aBehavior,
00266       nsIUnicharEncoder * aEncoder, PRUnichar aChar)
00267 {
00268    return NS_ERROR_NOT_IMPLEMENTED;
00269 }
00270 
00271 
00272 NS_IMETHODIMP nsUnicodeToLangBoxArabic8::FillInfo(PRUint32* aInfo)
00273 {
00274    PRUnichar i;
00275 
00276    SET_REPRESENTABLE(aInfo, 0x060c);      
00277    SET_REPRESENTABLE(aInfo, 0x061b);      
00278    SET_REPRESENTABLE(aInfo, 0x061f);      
00279    for(i=0x0621;i<=0x063a;i++)
00280       SET_REPRESENTABLE(aInfo, i);      
00281    for(i=0x0640;i<=0x0652;i++)
00282       SET_REPRESENTABLE(aInfo, i);      
00283    for(i=0x0660;i<=0x0669;i++)
00284       SET_REPRESENTABLE(aInfo, i);      
00285 
00286    // Arabic Pres Form-B
00287    for(i=0xFE80; i < 0xFEFD;i++)
00288      SET_REPRESENTABLE(aInfo, i);
00289 
00290    // ASCII range
00291    for(i=0x0000; i < 0x007f;i++)
00292      SET_REPRESENTABLE(aInfo, i);
00293 
00294    return NS_OK;
00295 }