font encodings and a first copy implementation wchar_t 32 <-> 16 bit
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25595 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
a9412f8f03
commit
fe92914150
@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
#if wxUSE_GUI
|
#if wxUSE_GUI
|
||||||
#include "wx/mac/uma.h"
|
#include "wx/mac/uma.h"
|
||||||
|
#include "wx/font.h"
|
||||||
|
#else
|
||||||
|
#include "wx/intl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -751,6 +754,14 @@ wxString wxMacMakeStringFromPascal( ConstStringPtr from )
|
|||||||
wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
|
wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
|
||||||
{
|
{
|
||||||
TextEncodingBase enc = 0 ;
|
TextEncodingBase enc = 0 ;
|
||||||
|
if ( encoding == wxFONTENCODING_DEFAULT )
|
||||||
|
{
|
||||||
|
#if wxUSE_GUI
|
||||||
|
encoding = wxFont::GetDefaultEncoding() ;
|
||||||
|
#else
|
||||||
|
encoding = wxLocale::GetSystemEncoding() ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
switch( encoding)
|
switch( encoding)
|
||||||
{
|
{
|
||||||
@ -1061,7 +1072,7 @@ wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding)
|
|||||||
enc = wxFONTENCODING_BULGARIAN;
|
enc = wxFONTENCODING_BULGARIAN;
|
||||||
break ;
|
break ;
|
||||||
*/
|
*/
|
||||||
casekTextEncodingDOSLatinUS :
|
case kTextEncodingDOSLatinUS :
|
||||||
enc = wxFONTENCODING_CP437;
|
enc = wxFONTENCODING_CP437;
|
||||||
break ;
|
break ;
|
||||||
case kTextEncodingDOSLatin1 :
|
case kTextEncodingDOSLatin1 :
|
||||||
@ -1291,8 +1302,8 @@ wxMacUnicodeConverters guard ;
|
|||||||
wxMacUnicodeConverters::wxMacUnicodeConverters()
|
wxMacUnicodeConverters::wxMacUnicodeConverters()
|
||||||
{
|
{
|
||||||
OSStatus status = noErr ;
|
OSStatus status = noErr ;
|
||||||
TextEncoding kUnicode32 = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
|
TextEncoding kUnicode32 = CreateTextEncoding(kTextEncodingUnicodeDefault,kTextEncodingDefaultVariant,kUnicode32BitFormat) ;
|
||||||
TextEncoding kUnicode16 = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
|
TextEncoding kUnicode16 = CreateTextEncoding(kTextEncodingUnicodeDefault,kTextEncodingDefaultVariant,kUnicode16BitFormat) ;
|
||||||
|
|
||||||
status = TECCreateConverter(&s_TECUnicode16To32,
|
status = TECCreateConverter(&s_TECUnicode16To32,
|
||||||
kUnicode16,
|
kUnicode16,
|
||||||
@ -1310,12 +1321,13 @@ wxMacUnicodeConverters::~wxMacUnicodeConverters()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// converts this string into a carbon foundation string with optional pc 2 mac encoding
|
// converts this string into a carbon foundation string with optional pc 2 mac encoding
|
||||||
void wxMacCFStringHolder::Assign( const wxString &st )
|
void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
|
||||||
{
|
{
|
||||||
|
Release() ;
|
||||||
wxString str = st ;
|
wxString str = st ;
|
||||||
wxMacConvertNewlines13To10( &str ) ;
|
wxMacConvertNewlines13To10( &str ) ;
|
||||||
size_t len = str.Len() ;
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
|
size_t len = str.Len() ;
|
||||||
UniChar *unibuf ;
|
UniChar *unibuf ;
|
||||||
#if SIZEOF_WCHAR_T == 2
|
#if SIZEOF_WCHAR_T == 2
|
||||||
unibuf = (UniChar*)str.wc_str() ;
|
unibuf = (UniChar*)str.wc_str() ;
|
||||||
@ -1325,8 +1337,12 @@ void wxMacCFStringHolder::Assign( const wxString &st )
|
|||||||
ByteCount byteInLen = len * SIZEOF_WCHAR_T ;
|
ByteCount byteInLen = len * SIZEOF_WCHAR_T ;
|
||||||
ByteCount byteBufferLen = len * sizeof( UniChar ) ;
|
ByteCount byteBufferLen = len * sizeof( UniChar ) ;
|
||||||
unibuf = (UniChar*) malloc(byteBufferLen) ;
|
unibuf = (UniChar*) malloc(byteBufferLen) ;
|
||||||
|
for( int i = 0 ; i < len ; ++ i )
|
||||||
|
unibuf[i] = (UniChar) str[i] ;
|
||||||
|
/*
|
||||||
status = TECConvertText( s_TECUnicode32To16 , (ConstTextPtr)str.wc_str() , byteInLen, &byteInLen,
|
status = TECConvertText( s_TECUnicode32To16 , (ConstTextPtr)str.wc_str() , byteInLen, &byteInLen,
|
||||||
(TextPtr)unibuf, byteBufferLen, &byteOutLen);
|
(TextPtr)unibuf, byteBufferLen, &byteOutLen);
|
||||||
|
*/
|
||||||
#endif
|
#endif
|
||||||
m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
|
m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
|
||||||
unibuf , len );
|
unibuf , len );
|
||||||
@ -1338,20 +1354,33 @@ void wxMacCFStringHolder::Assign( const wxString &st )
|
|||||||
|
|
||||||
#else // not wxUSE_UNICODE
|
#else // not wxUSE_UNICODE
|
||||||
m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
|
m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
|
||||||
CFStringGetSystemEncoding() ) ;
|
wxMacGetSystemEncFromFontEnc( encoding ) ) ;
|
||||||
#endif
|
#endif
|
||||||
m_release = true ;
|
m_release = true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxMacCFStringHolder::AsString()
|
wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding)
|
||||||
{
|
{
|
||||||
wxString result ;
|
wxString result ;
|
||||||
Size len = CFStringGetLength( m_cfs ) ;
|
Size len = CFStringGetLength( m_cfs ) ;
|
||||||
wxChar* buf = result.GetWriteBuf( len ) ;
|
wxChar* buf = result.GetWriteBuf( len ) ;
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
CFStringGetCharacters( m_cfs , CFRangeMake( 0 , len ) , (UniChar*) buf ) ;
|
UniChar *unibuf ;
|
||||||
|
#if SIZEOF_WCHAR_T == 2
|
||||||
|
unibuf = (UniChar*) buf ;
|
||||||
#else
|
#else
|
||||||
CFStringGetCString( m_cfs , buf , len+1 , CFStringGetSystemEncoding() ) ;
|
unibuf = malloc( len * sizeof( UniChar ) ) ;
|
||||||
|
#endif
|
||||||
|
CFStringGetCharacters( m_cfs , CFRangeMake( 0 , len ) , (UniChar*) unibuf ) ;
|
||||||
|
#if SIZEOF_WCHAR_T == 2
|
||||||
|
// as long as UniChar is the same as wchar_t nothing to do here
|
||||||
|
#else
|
||||||
|
for( int i = 0 ; i < len ; ++ i )
|
||||||
|
buf[i] = (wchar_t) unibuf[i] ;
|
||||||
|
free( unibuf ) ;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
CFStringGetCString( m_cfs , buf , len+1 , wxMacGetSystemEncFromFontEnc( encoding ) ) ;
|
||||||
#endif
|
#endif
|
||||||
buf[len] = 0 ;
|
buf[len] = 0 ;
|
||||||
wxMacConvertNewlines10To13( buf ) ;
|
wxMacConvertNewlines10To13( buf ) ;
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
#if wxUSE_GUI
|
#if wxUSE_GUI
|
||||||
#include "wx/mac/uma.h"
|
#include "wx/mac/uma.h"
|
||||||
|
#include "wx/font.h"
|
||||||
|
#else
|
||||||
|
#include "wx/intl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -751,6 +754,14 @@ wxString wxMacMakeStringFromPascal( ConstStringPtr from )
|
|||||||
wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
|
wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
|
||||||
{
|
{
|
||||||
TextEncodingBase enc = 0 ;
|
TextEncodingBase enc = 0 ;
|
||||||
|
if ( encoding == wxFONTENCODING_DEFAULT )
|
||||||
|
{
|
||||||
|
#if wxUSE_GUI
|
||||||
|
encoding = wxFont::GetDefaultEncoding() ;
|
||||||
|
#else
|
||||||
|
encoding = wxLocale::GetSystemEncoding() ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
switch( encoding)
|
switch( encoding)
|
||||||
{
|
{
|
||||||
@ -1061,7 +1072,7 @@ wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding)
|
|||||||
enc = wxFONTENCODING_BULGARIAN;
|
enc = wxFONTENCODING_BULGARIAN;
|
||||||
break ;
|
break ;
|
||||||
*/
|
*/
|
||||||
casekTextEncodingDOSLatinUS :
|
case kTextEncodingDOSLatinUS :
|
||||||
enc = wxFONTENCODING_CP437;
|
enc = wxFONTENCODING_CP437;
|
||||||
break ;
|
break ;
|
||||||
case kTextEncodingDOSLatin1 :
|
case kTextEncodingDOSLatin1 :
|
||||||
@ -1291,8 +1302,8 @@ wxMacUnicodeConverters guard ;
|
|||||||
wxMacUnicodeConverters::wxMacUnicodeConverters()
|
wxMacUnicodeConverters::wxMacUnicodeConverters()
|
||||||
{
|
{
|
||||||
OSStatus status = noErr ;
|
OSStatus status = noErr ;
|
||||||
TextEncoding kUnicode32 = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
|
TextEncoding kUnicode32 = CreateTextEncoding(kTextEncodingUnicodeDefault,kTextEncodingDefaultVariant,kUnicode32BitFormat) ;
|
||||||
TextEncoding kUnicode16 = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
|
TextEncoding kUnicode16 = CreateTextEncoding(kTextEncodingUnicodeDefault,kTextEncodingDefaultVariant,kUnicode16BitFormat) ;
|
||||||
|
|
||||||
status = TECCreateConverter(&s_TECUnicode16To32,
|
status = TECCreateConverter(&s_TECUnicode16To32,
|
||||||
kUnicode16,
|
kUnicode16,
|
||||||
@ -1310,12 +1321,13 @@ wxMacUnicodeConverters::~wxMacUnicodeConverters()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// converts this string into a carbon foundation string with optional pc 2 mac encoding
|
// converts this string into a carbon foundation string with optional pc 2 mac encoding
|
||||||
void wxMacCFStringHolder::Assign( const wxString &st )
|
void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
|
||||||
{
|
{
|
||||||
|
Release() ;
|
||||||
wxString str = st ;
|
wxString str = st ;
|
||||||
wxMacConvertNewlines13To10( &str ) ;
|
wxMacConvertNewlines13To10( &str ) ;
|
||||||
size_t len = str.Len() ;
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
|
size_t len = str.Len() ;
|
||||||
UniChar *unibuf ;
|
UniChar *unibuf ;
|
||||||
#if SIZEOF_WCHAR_T == 2
|
#if SIZEOF_WCHAR_T == 2
|
||||||
unibuf = (UniChar*)str.wc_str() ;
|
unibuf = (UniChar*)str.wc_str() ;
|
||||||
@ -1325,8 +1337,12 @@ void wxMacCFStringHolder::Assign( const wxString &st )
|
|||||||
ByteCount byteInLen = len * SIZEOF_WCHAR_T ;
|
ByteCount byteInLen = len * SIZEOF_WCHAR_T ;
|
||||||
ByteCount byteBufferLen = len * sizeof( UniChar ) ;
|
ByteCount byteBufferLen = len * sizeof( UniChar ) ;
|
||||||
unibuf = (UniChar*) malloc(byteBufferLen) ;
|
unibuf = (UniChar*) malloc(byteBufferLen) ;
|
||||||
|
for( int i = 0 ; i < len ; ++ i )
|
||||||
|
unibuf[i] = (UniChar) str[i] ;
|
||||||
|
/*
|
||||||
status = TECConvertText( s_TECUnicode32To16 , (ConstTextPtr)str.wc_str() , byteInLen, &byteInLen,
|
status = TECConvertText( s_TECUnicode32To16 , (ConstTextPtr)str.wc_str() , byteInLen, &byteInLen,
|
||||||
(TextPtr)unibuf, byteBufferLen, &byteOutLen);
|
(TextPtr)unibuf, byteBufferLen, &byteOutLen);
|
||||||
|
*/
|
||||||
#endif
|
#endif
|
||||||
m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
|
m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
|
||||||
unibuf , len );
|
unibuf , len );
|
||||||
@ -1338,20 +1354,33 @@ void wxMacCFStringHolder::Assign( const wxString &st )
|
|||||||
|
|
||||||
#else // not wxUSE_UNICODE
|
#else // not wxUSE_UNICODE
|
||||||
m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
|
m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
|
||||||
CFStringGetSystemEncoding() ) ;
|
wxMacGetSystemEncFromFontEnc( encoding ) ) ;
|
||||||
#endif
|
#endif
|
||||||
m_release = true ;
|
m_release = true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxMacCFStringHolder::AsString()
|
wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding)
|
||||||
{
|
{
|
||||||
wxString result ;
|
wxString result ;
|
||||||
Size len = CFStringGetLength( m_cfs ) ;
|
Size len = CFStringGetLength( m_cfs ) ;
|
||||||
wxChar* buf = result.GetWriteBuf( len ) ;
|
wxChar* buf = result.GetWriteBuf( len ) ;
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
CFStringGetCharacters( m_cfs , CFRangeMake( 0 , len ) , (UniChar*) buf ) ;
|
UniChar *unibuf ;
|
||||||
|
#if SIZEOF_WCHAR_T == 2
|
||||||
|
unibuf = (UniChar*) buf ;
|
||||||
#else
|
#else
|
||||||
CFStringGetCString( m_cfs , buf , len+1 , CFStringGetSystemEncoding() ) ;
|
unibuf = malloc( len * sizeof( UniChar ) ) ;
|
||||||
|
#endif
|
||||||
|
CFStringGetCharacters( m_cfs , CFRangeMake( 0 , len ) , (UniChar*) unibuf ) ;
|
||||||
|
#if SIZEOF_WCHAR_T == 2
|
||||||
|
// as long as UniChar is the same as wchar_t nothing to do here
|
||||||
|
#else
|
||||||
|
for( int i = 0 ; i < len ; ++ i )
|
||||||
|
buf[i] = (wchar_t) unibuf[i] ;
|
||||||
|
free( unibuf ) ;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
CFStringGetCString( m_cfs , buf , len+1 , wxMacGetSystemEncFromFontEnc( encoding ) ) ;
|
||||||
#endif
|
#endif
|
||||||
buf[len] = 0 ;
|
buf[len] = 0 ;
|
||||||
wxMacConvertNewlines10To13( buf ) ;
|
wxMacConvertNewlines10To13( buf ) ;
|
||||||
|
Loading…
Reference in New Issue
Block a user