Back to index

lightning-sunbird  0.9+nobinonly
nsUnicodeToSunIndic.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  * ucvhi : nsUnicodeToSunIndic.h
00003  *
00004  * ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is mozilla.org code. The Initial Developer of the Original Code is Sun Microsystems, Inc.  Portions created by SUN are Copyright (C) 2000 SUN Microsystems, Inc. All Rights Reserved.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Sun Microsystems, Inc.
00021  * Portions created by the Initial Developer are Copyright (C) 2000
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   Prabhat Hegde (prabhat.hegde@sun.com)
00026  *   Jungshik Shin (jshin@mailmaps.org)
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either of the GNU General Public License Version 2 or later (the "GPL"),
00030  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 #include "nsCOMPtr.h"
00042 #include "nsCtlCIID.h"
00043 #include "nsILE.h"
00044 #include "nsULE.h"
00045 #include "nsUnicodeToSunIndic.h"
00046 
00047 NS_IMPL_ISUPPORTS2(nsUnicodeToSunIndic, nsIUnicodeEncoder, nsICharRepresentable)
00048 
00049 NS_IMETHODIMP
00050 nsUnicodeToSunIndic::SetOutputErrorBehavior(PRInt32           aBehavior,
00051                                             nsIUnicharEncoder *aEncoder,
00052                                             PRUnichar         aChar)
00053 {
00054   if (aBehavior == kOnError_CallBack && aEncoder == nsnull)
00055      return NS_ERROR_NULL_POINTER;
00056   mErrEncoder = aEncoder;
00057   mErrBehavior = aBehavior;
00058   mErrChar = aChar;
00059   return NS_OK;
00060 }
00061 
00062 // constructor and destructor
00063 nsUnicodeToSunIndic::nsUnicodeToSunIndic()
00064 {
00065   static   NS_DEFINE_CID(kLECID, NS_ULE_CID);
00066   nsresult rv;
00067 
00068   mCtlObj = do_CreateInstance(kLECID, &rv);
00069   if (NS_FAILED(rv)) {
00070 
00071 #ifdef DEBUG_prabhath
00072     // No other error handling needed here since we
00073     // handle absence of mCtlObj in Convert
00074     printf("ERROR: Cannot create instance of component " NS_ULE_PROGID " [%x].\n", rv);
00075 #endif
00076 
00077     NS_WARNING("Indian Text Shaping Will Not Be Supported\n");
00078     mCtlObj = nsnull;
00079   }
00080 }
00081 
00082 nsUnicodeToSunIndic::~nsUnicodeToSunIndic()
00083 {
00084   // Maybe convert nsILE to a service
00085   //NS_IF_RELEASE(mCtlObj);
00086 }
00087 
00088 /*
00089  * This method converts the unicode to this font index.
00090  * Note: ConversionBufferFullException is not handled
00091  *       since this class is only used for character display.
00092  */
00093 NS_IMETHODIMP nsUnicodeToSunIndic::Convert(const PRUnichar* input,
00094                                            PRInt32*         aSrcLength,
00095                                            char*            output,
00096                                            PRInt32*         aDestLength)
00097 {
00098   PRSize outLen;
00099 
00100   if (mCtlObj == nsnull) {
00101 #ifdef DEBUG_prabhath
00102   printf("Debug/Test Case of No Hindi pango shaper Object\n");
00103   // Comment out mCtlObj == nsnull for test purposes
00104   printf("ERROR: No Hindi Text Layout Implementation");
00105 #endif
00106 
00107     NS_WARNING("cannot get default converter for Hindi");
00108     return NS_ERROR_FAILURE;
00109   }
00110 
00111   mCharOff = mByteOff = 0;
00112   mCtlObj->GetPresentationForm(input, *aSrcLength, "sun.unicode.india-0",
00113                                &output[mByteOff], &outLen, PR_TRUE);
00114   *aDestLength = outLen;
00115   return NS_OK;
00116 }
00117 
00118 NS_IMETHODIMP nsUnicodeToSunIndic::Finish(char *output, PRInt32 *aDestLength)
00119 {
00120   // Finish does'nt have to do much as Convert already flushes
00121   // to output buffer
00122   mByteOff = mCharOff = 0;
00123   return NS_OK;
00124 }
00125 
00126 //================================================================
00127 NS_IMETHODIMP nsUnicodeToSunIndic::Reset()
00128 {
00129   mByteOff = mCharOff = 0;
00130   return NS_OK;
00131 }
00132 
00133 //================================================================
00134 NS_IMETHODIMP nsUnicodeToSunIndic::GetMaxLength(const PRUnichar * aSrc,
00135                                                 PRInt32 aSrcLength,
00136                                                 PRInt32 * aDestLength)
00137 {
00138   *aDestLength = (aSrcLength + 1) *  2; // Each Hindi character can generate
00139                                         // atmost two presentation forms
00140   return NS_OK;
00141 }
00142 
00143 //================================================================
00144 NS_IMETHODIMP nsUnicodeToSunIndic::FillInfo(PRUint32* aInfo)
00145 {
00146   PRUint16 i;
00147 
00148   // 00-0x7f
00149   for (i = 0;i <= 0x7f; i++)
00150     SET_REPRESENTABLE(aInfo, i);
00151 
00152   // \u904, \u90a, \u93b, \u94e, \u94f are Undefined
00153   for (i = 0x0901; i <= 0x0903; i++)
00154     SET_REPRESENTABLE(aInfo, i);
00155 
00156   for (i = 0x0905; i <= 0x0939; i++)
00157     SET_REPRESENTABLE(aInfo, i);
00158 
00159   for (i = 0x093c; i <= 0x094d; i++)
00160     SET_REPRESENTABLE(aInfo, i);
00161 
00162   for (i = 0x0950; i <= 0x0954; i++)
00163     SET_REPRESENTABLE(aInfo, i);
00164 
00165   for (i = 0x0958; i <= 0x0970; i++)
00166     SET_REPRESENTABLE(aInfo, i);
00167  
00168   // ZWJ and ZWNJ support & coverage need to be added.
00169   return NS_OK;
00170 }