Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Private Attributes
nsUnicodeToTIS620 Class Reference

#include <nsUnicodeToTIS620.h>

Inheritance diagram for nsUnicodeToTIS620:
Inheritance graph
[legend]
Collaboration diagram for nsUnicodeToTIS620:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { kOnError_Signal, kOnError_CallBack, kOnError_Replace }

Public Member Functions

 nsUnicodeToTIS620 ()
 Class constructor.
virtual ~nsUnicodeToTIS620 ()
NS_IMETHOD Convert (const PRUnichar *aSrc, PRInt32 *aSrcLength, char *aDest, PRInt32 *aDestLength)
 Converts the data from Unicode to a Charset.
NS_IMETHOD Finish (char *aDest, PRInt32 *aDestLength)
 Finishes the conversion.
NS_IMETHOD GetMaxLength (const PRUnichar *aSrc, PRInt32 aSrcLength, PRInt32 *aDestLength)
 Returns a quick estimation of the size of the buffer needed to hold the converted data.
NS_IMETHOD Reset ()
 Resets the charset converter so it may be recycled for a completely different and urelated buffer of data.
NS_IMETHOD SetOutputErrorBehavior (PRInt32 aBehavior, nsIUnicharEncoder *aEncoder, PRUnichar aChar)
 Specify what to do when a character cannot be mapped into the dest charset.
NS_IMETHOD FillInfo (PRUint32 *aInfo)

Private Attributes

PRUint8 mState
PRInt32 mByteOff
PRInt32 mCharOff
nsCOMPtr< nsILEmCtlObj

Detailed Description

Definition at line 57 of file nsUnicodeToTIS620.h.


Member Enumeration Documentation

anonymous enum [inherited]
Enumerator:
kOnError_Signal 
kOnError_CallBack 
kOnError_Replace 

Definition at line 136 of file nsIUnicodeEncoder.h.

       {
    kOnError_Signal,        // on an error, stop and signal
    kOnError_CallBack,      // on an error, call the error handler
    kOnError_Replace       // on an error, replace with a different character
  };

Constructor & Destructor Documentation

Class constructor.

Definition at line 60 of file nsUnicodeToTIS620.cpp.

{
  static   NS_DEFINE_CID(kLECID, NS_ULE_CID);
  nsresult rv;

  mCtlObj = do_CreateInstance(kLECID, &rv);
  if (NS_FAILED(rv)) {
#ifdef DEBUG_prabhath
    // No other error handling needed here since we
    // handle absence of mCtlObj in Convert
    printf("ERROR: Cannot create instance of component " NS_ULE_PROGID " [%x].\n", rv);
#endif
    NS_WARNING("Thai Text Layout Will Not Be Supported\n");
    mCtlObj = nsnull;
  }
}

Here is the call graph for this function:

Definition at line 77 of file nsUnicodeToTIS620.cpp.

{
  // Maybe convert nsILE to a service
  // No NS_IF_RELEASE(mCtlObj) of nsCOMPtr;
}

Member Function Documentation

NS_IMETHODIMP nsUnicodeToTIS620::Convert ( const PRUnichar aSrc,
PRInt32 aSrcLength,
char *  aDest,
PRInt32 aDestLength 
) [virtual]

Converts the data from Unicode to a Charset.

About the byte ordering:

  • The input stream is Unicode, having the byte order which is internal for the machine on which the converter is running on.
  • For output, if the converter cares (that depends of the charset, for example a singlebyte will ignore the byte ordering) it should assume network order. If necessary and requested, we can add a method SetOutputByteOrder() so that the reverse order can be used, too. That method would have as default the assumed network order.

Unless there is not enough output space, this method must consume all the available input data! We don't have partial input for the Unicode charset. And for the last converted char, even if there is not enought output space, a partial ouput must be done until all available space will be used. The rest of the output should be buffered until more space becomes available. But this is not also true about the error handling method!!! So be very, very careful...

Parameters:
aSrc[IN] the source data buffer
aSrcLength[IN/OUT] the length of source data buffer; after conversion will contain the number of Unicode characters read
aDest[OUT] the destination data buffer
aDestLength[IN/OUT] the length of the destination data buffer; after conversion will contain the number of bytes written
Returns:
NS_OK_UENC_MOREOUTPUT if only a partial conversion was done; more output space is needed to continue NS_ERROR_UENC_NOMAPPING if character without mapping was encountered and the behavior was set to "signal".

Implements nsIUnicodeEncoder.

Reimplemented in nsUnicodeToThaiTTF.

Definition at line 88 of file nsUnicodeToTIS620.cpp.

{
  PRSize outLen = 0;
#ifdef DEBUG_prabhath_no_shaper
  printf("Debug/Test Case of No thai pango shaper Object\n");
  // Comment out mCtlObj == nsnull for test purposes
#endif

  if (mCtlObj == nsnull) {
#ifdef DEBUG_prabhath
    printf("ERROR: No CTL IMPLEMENTATION - Default Thai Conversion");
    // CP874 is the default converter for thai ; 
    // In case mCtlObj is absent (no CTL support), use it to convert.
#endif

    nsCOMPtr<nsICharsetConverterManager> charsetMgr =
        do_GetService(kCharSetManagerCID);
    if (!charsetMgr)
      return NS_ERROR_FAILURE;
    
    nsCOMPtr<nsIUnicodeEncoder> encoder;
    charsetMgr->GetUnicodeEncoderRaw("TIS-620", getter_AddRefs(encoder));
    if (!encoder) {
      NS_WARNING("cannot get default converter for tis-620");
      return NS_ERROR_FAILURE;
    }

    encoder->Convert(input, aSrcLength, output, aDestLength);
    return NS_OK;
  }

  // CTLized shaping conversion starts here
  // No question of starting the conversion from an offset
  mCharOff = mByteOff = 0;

  // Charset tis620-0, tis620.2533-1, tis620.2529-1 & iso8859-11
  // are equivalent and have the same presentation forms

  // tis620-2 is hard-coded since we only generate presentation forms
  // in Windows-Stye as it is the current defacto-standard for the
  // presentation of thai content
  mCtlObj->GetPresentationForm(input, *aSrcLength, "tis620-2",
                               &output[mByteOff], &outLen);

  *aDestLength = outLen;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsICharRepresentable.

Definition at line 165 of file nsUnicodeToTIS620.cpp.

{
  PRUint16 i;

  // 00-0x7f
  for (i = 0;i <= 0x7f; i++)
    SET_REPRESENTABLE(aInfo, i);

  // 0x0e01-0x0e7f
  for (i = 0x0e01; i <= 0xe3a; i++)
    SET_REPRESENTABLE(aInfo, i);

  // U+0E3B - U+0E3E is undefined
  // U+0E3F - U+0E5B
  for (i = 0x0e3f; i <= 0x0e5b; i++)
    SET_REPRESENTABLE(aInfo, i);

  // U+0E5C - U+0E7F Undefined
  return NS_OK;
}
NS_IMETHODIMP nsUnicodeToTIS620::Finish ( char *  aDest,
PRInt32 aDestLength 
) [virtual]

Finishes the conversion.

The converter has the possibility to write some extra data and flush its final state.

Parameters:
aDest[OUT] the destination data buffer
aDestLength[IN/OUT] the length of destination data buffer; after conversion it will contain the number of bytes written
Returns:
NS_OK_UENC_MOREOUTPUT if only a partial conversion was done; more output space is needed to continue

Implements nsIUnicodeEncoder.

Definition at line 139 of file nsUnicodeToTIS620.cpp.

{
  // Finish does'nt have to do much as Convert already flushes
  // to output buffer
  mByteOff = mCharOff = 0;
  return NS_OK;
}
NS_IMETHODIMP nsUnicodeToTIS620::GetMaxLength ( const PRUnichar aSrc,
PRInt32  aSrcLength,
PRInt32 aDestLength 
) [virtual]

Returns a quick estimation of the size of the buffer needed to hold the converted data.

Remember: this estimation is >= with the actual size of the buffer needed. It will be computed for the "worst case"

Parameters:
aSrc[IN] the source data buffer
aSrcLength[IN] the length of source data buffer
aDestLength[OUT] the needed size of the destination buffer
Returns:
NS_OK_UENC_EXACTLENGTH if an exact length was computed NS_OK if all we have is an approximation

Implements nsIUnicodeEncoder.

Reimplemented in nsUnicodeToThaiTTF.

Definition at line 155 of file nsUnicodeToTIS620.cpp.

{
  *aDestLength = (aSrcLength + 1) * 2; // Each Thai character can generate
                                        // atmost two presentation forms
  return NS_OK;
}

Resets the charset converter so it may be recycled for a completely different and urelated buffer of data.

Implements nsIUnicodeEncoder.

Definition at line 148 of file nsUnicodeToTIS620.cpp.

{
  mByteOff = mCharOff = 0;
  return NS_OK;
}

Specify what to do when a character cannot be mapped into the dest charset.

Parameters:
aOrder[IN] the behavior; taken from the enum

Implements nsIUnicodeEncoder.

Reimplemented in nsUnicodeToThaiTTF.

Definition at line 53 of file nsUnicodeToTIS620.cpp.


Member Data Documentation

Definition at line 87 of file nsUnicodeToTIS620.h.

Definition at line 88 of file nsUnicodeToTIS620.h.

Definition at line 90 of file nsUnicodeToTIS620.h.

Definition at line 86 of file nsUnicodeToTIS620.h.


The documentation for this class was generated from the following files: