UnicodeManager Class Reference

Class for containing all Unicode related methods. More...

#include <unicdman.h>

Inheritance diagram for UnicodeManager:

CCObject SimpleCCObject List of all members.

Static Public Member Functions

static UINT32 ComposeMultiBytes (BYTE LeadChar, BYTE TrailChar)
static void DecomposeMultiBytes (UINT32 MBChar, BYTE *LeadChar, BYTE *TrailChar)
 Platform independent way of testing for lead bytes. Note: It's inline, in the header One standard (correct!) way for composing the lead and trail bytes Note: It's inline, in the header One standard (correct!) way for decomposing the lead and trail bytes.
static BOOL IsDBCSLeadByte (BYTE TestChar)
static UINT32 UnicodeToMultiByte (WCHAR UnicodeChar)
 Converts a single unicode character into it's multi-byte equivelent. BUT what about two composed characters? Oh...
static WCHAR MultiByteToUnicode (UINT32 MBChar)
 Converts a single multi-byte character into it's unicode equivelent. BUT what about two composed characters? Oh... Unimplemented as no one will cope with two chars being returned...
static BOOL IsUnicodeCompleteOS ()
static BOOL IsDBCSOS ()
static UINT32 GetFontCharSet ()
 Reads what value the system is using for the character sets of its fonts.

Detailed Description

Class for containing all Unicode related methods.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/7/96

Definition at line 116 of file unicdman.h.


Member Function Documentation

static UINT32 UnicodeManager::ComposeMultiBytes BYTE  LeadChar,
BYTE  TrailChar
[inline, static]
 

Definition at line 121 of file unicdman.h.

00121 {return (LeadChar<<8) + TrailChar;}

void UnicodeManager::DecomposeMultiBytes UINT32  MBChar,
BYTE *  LeadChar,
BYTE *  TrailChar
[static]
 

Platform independent way of testing for lead bytes. Note: It's inline, in the header One standard (correct!) way for composing the lead and trail bytes Note: It's inline, in the header One standard (correct!) way for decomposing the lead and trail bytes.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/7/96
Parameters:
MBChar - the composed multibyte character [INPUTS]
LeadChar - Lead multichar byte [OUTPUTS] TrailChar - Trail multichar byte
Returns:
-

Definition at line 146 of file unicdman.cpp.

00147 {
00148     ERROR3IF(LeadChar==NULL || TrailChar==NULL, "Output pointers were NULL");
00149 
00150     if (LeadChar!=NULL || TrailChar!=NULL)
00151     {
00152         *LeadChar = (MBChar >> 8) & 0xFF;
00153         *TrailChar = MBChar & 0xFF;
00154     }
00155 }

UINT32 UnicodeManager::GetFontCharSet  )  [static]
 

Reads what value the system is using for the character sets of its fonts.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/7/96
Parameters:
- [INPUTS] Ouptuts: -
Returns:
UINT32 representing the font character set of the system

Definition at line 337 of file unicdman.cpp.

00338 {
00339     if( IsDBCSOS() )
00340         return SHIFTJIS_CHARSET;
00341     else
00342         return ANSI_CHARSET;
00343 
00344 //  UINT32 CharSet = 0;
00345 //  
00346 //  // This appears to be the only way of doing this.  It's ugly as we have to create a DC.
00347 //  if (!IsWindows31())
00348 //  {
00349 //      CWnd* pWnd = CWnd::GetDesktopWindow();
00350 //      if (pWnd!=NULL && pWnd->GetDC()!=NULL)
00351 //          CharSet = ::GetTextCharset(pWnd->GetDC()->GetSafeHdc());
00352 //  }
00353 //
00354 //  return CharSet;
00355 }

static BOOL UnicodeManager::IsDBCSLeadByte BYTE  TestChar  )  [inline, static]
 

Definition at line 127 of file unicdman.h.

00127 { return false; }

BOOL UnicodeManager::IsDBCSOS  )  [static]
 

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/6/99
Returns:
TRUE if running on a DBCS enabled OS

Definition at line 316 of file unicdman.cpp.

00317 {
00318 #if defined(__WXMSW__)
00319     return ::GetSystemMetrics(SM_DBCSENABLED);
00320 #elif defined(__WXGTK__)
00321     return true;
00322 #endif
00323 }

BOOL UnicodeManager::IsUnicodeCompleteOS  )  [static]
 

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/10/95
Returns:
TRUE if running on a Unicode Complete OS

Definition at line 298 of file unicdman.cpp.

00299 {
00300 #if defined(__WXMSW__)
00301     return IsWin32NT();
00302 #elif defined(__WXGTK__)
00303     return true;
00304 #endif
00305 }

WCHAR UnicodeManager::MultiByteToUnicode UINT32  MBChar  )  [static]
 

Converts a single multi-byte character into it's unicode equivelent. BUT what about two composed characters? Oh... Unimplemented as no one will cope with two chars being returned...

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/10/95
Parameters:
MBChar - a single multi-byte character [INPUTS] Ouptuts: -
Returns:
The unicode value that represents MBChar

Errors: If the conversion fails then character 128 (box) is returned.

Definition at line 239 of file unicdman.cpp.

00240 {
00241     CHAR                MBArray[3];
00242     WCHAR               ReturnArray[4];
00243     size_t              cch;
00244 
00245     // Convert UINT32 to DBCS
00246     if( IsDBCSLeadByte( ( MBChar >> 8 ) & 0xFF ) )
00247     {
00248         MBArray[0] = (MBChar>>8) & 0xFF;
00249         MBArray[1] = MBChar & 0xFF;
00250         MBArray[2] = 0;
00251         cch = 2;
00252     }
00253     else
00254     {
00255         MBArray[0] = MBChar & 0xFF;
00256         MBArray[1] = 0;
00257         cch = 1;
00258     }
00259     
00260 #if defined(__WXMSW__)
00261     // Get the active code page.
00262     // This is for Win95/98 systems which do not support unicode.
00263     UINT32 nCodePage = GetACP();
00264     ERROR3IF( (!IsValidCodePage(nCodePage)), "UnicodeManager::MultiByteToUnicode - not a valid codepage" );
00265 
00266     // Convert to Unicode
00267     if ( ::MultiByteToWideChar(nCodePage, MB_PRECOMPOSED, MBArray, -1, ReturnArray, 4) )
00268     {
00269         return ReturnArray[0];  // Composed chars then?
00270     }
00271     else
00272     {
00273         ERROR3("MultiByteToWideChar failed");
00274         /*DWORD dwError = GetLastError();
00275         //ERROR3_PF ("Error=%lx", dwError);
00276         char sError[20];
00277         sprintf (sError, "Error=%lx", dwError);
00278         ERROR3 (sError);*/
00279         return 128;
00280     }
00281 #else
00282     mbstate_t           state;
00283     memset(&state, 0, sizeof(mbstate_t));
00284     mbrtowc( ReturnArray, MBArray, cch, &state );
00285     return ReturnArray[0];
00286 #endif
00287 }

UINT32 UnicodeManager::UnicodeToMultiByte WCHAR  UnicodeChar  )  [static]
 

Converts a single unicode character into it's multi-byte equivelent. BUT what about two composed characters? Oh...

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/10/95
Parameters:
UnicodeChar - a single unicode character [INPUTS] Ouptuts: -
Returns:
A single multi-byte character value that represents UnicodeChar

Errors: If the conversion fails then character 128 (box), or the system defualt is returned.

Definition at line 172 of file unicdman.cpp.

00173 {
00174 #if defined(__WXMSW__)
00175     if (UnicodeChar < 128)
00176         return UnicodeChar;
00177         
00178     CHAR Return[20];
00179     LPSTR lpReturn = Return;
00180     INT32 sizeReturn = sizeof lpReturn;
00181 
00182     // Get the active code page.
00183     // This is for Win95/98 systems which do not support unicode.
00184     UINT32 nCodePage = GetACP();
00185     ERROR3IF( (!IsValidCodePage(nCodePage)), "UnicodeManager::UnicodeToMultiByte - not a valid codepage" );
00186 
00187     // COnvert from Unicode
00188     if ( ::WideCharToMultiByte(nCodePage, WC_COMPOSITECHECK | WC_DEFAULTCHAR, &UnicodeChar, 1,
00189                                 lpReturn, sizeReturn, NULL, NULL) )
00190     {
00191         if (IsDBCSLeadByte(Return[0]))
00192             return ((unsigned char)Return[0] << 8) | (unsigned char)Return[1];
00193         else
00194             return (unsigned char)Return[0];
00195     }
00196     else
00197     {
00198         ERROR3("MultiByteToWideChar failed");
00199         return 128;
00200     }
00201 #else
00202     char                psz[MB_CUR_MAX];
00203     switch( wctomb( psz, UnicodeChar ) )
00204     {
00205     case 1:
00206         return (unsigned char)psz[0];
00207 
00208     case 2:
00209         return ( (unsigned char)psz[0] << 8 ) | (unsigned char)psz[1];
00210     
00211     case 4:
00212         printf( "UniCh = %08x\n", ( (unsigned char)psz[0] << 24 ) | 
00213               ( (unsigned char)psz[1] << 16 ) | ( (unsigned char)psz[2] << 8 )  | 
00214                 (unsigned char)psz[3] ); 
00215         return( (unsigned char)psz[0] << 24 ) | ( (unsigned char)psz[1] << 16 ) | 
00216               ( (unsigned char)psz[2] << 8 )  |   (unsigned char)psz[3];
00217     
00218     default:
00219         ERROR3("MultiByteToWideChar failed");
00220         return 128;     
00221     }
00222 #endif
00223 }


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 04:02:39 2007 for Camelot by  doxygen 1.4.4