Esempio n. 1
0
static const wxUint16* GetEncTable(wxFontEncoding enc)
{
#ifdef __WXMAC__
    if( enc >= wxFONTENCODING_MACMIN && enc <= wxFONTENCODING_MACMAX )
    {
        int i = enc-wxFONTENCODING_MACMIN ;
        if ( gMacEncodingsInited[i] == false )
        {
            TECObjectRef converter ;
            TextEncodingBase code = wxMacGetSystemEncFromFontEnc( enc ) ;
            TextEncodingBase unicode = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
            OSStatus status = TECCreateConverter(&converter,code,unicode);
            char s[2] ;
            s[1] = 0 ;
            ByteCount byteInLen, byteOutLen ;
            for( unsigned char c = 255 ; c >= 128 ; --c )
            {
                s[0] = c ;
                status = TECConvertText(converter, (ConstTextPtr) &s , 1, &byteInLen,
                (TextPtr) &gMacEncodings[i][c-128] , 2, &byteOutLen);
            }
            status = TECDisposeConverter(converter);
            gMacEncodingsInited[i]=true;
        }
        return gMacEncodings[i] ;
    }
#endif

    for (int i = 0; encodings_list[i].table != NULL; i++)
    {
        if (encodings_list[i].encoding == enc)
            return encodings_list[i].table;
    }
    return NULL;
}
Esempio n. 2
0
static const wxUint16* GetEncTable(wxFontEncoding enc)
{
#ifdef __WXMAC__
    if( enc >= wxFONTENCODING_MACMIN && enc <= wxFONTENCODING_MACMAX )
    {
        int i = enc-wxFONTENCODING_MACMIN ;
        if ( gMacEncodingsInited[i] == false )
        {
            // create
            CFStringEncoding cfencoding = wxMacGetSystemEncFromFontEnc( enc ) ;
            if( !CFStringIsEncodingAvailable( cfencoding ) )
                return NULL;

            memset( gMacEncodings[i] , 0 , 128 * 2 );
            char s[2] = { 0 , 0 };
            CFRange firstchar = CFRangeMake( 0, 1 );
            for( unsigned char c = 255 ; c >= 128 ; --c )
            {
                s[0] = c ;
                wxCFStringRef cfref( CFStringCreateWithCStringNoCopy( NULL, s, cfencoding , kCFAllocatorNull ) );
                CFStringGetCharacters( cfref, firstchar, (UniChar*)  &gMacEncodings[i][c-128] );
            }
            gMacEncodingsInited[i]=true;
        }
        return gMacEncodings[i] ;
    }
#endif

    for (int i = 0; encodings_list[i].table != NULL; i++)
    {
        if (encodings_list[i].encoding == enc)
            return encodings_list[i].table;
    }
    return NULL;
}
Esempio n. 3
0
wxCFStringRef::wxCFStringRef( const wxString &st , wxFontEncoding WXUNUSED_IN_UNICODE(encoding) )
{
    if (st.IsEmpty())
    {
        reset( wxCFRetain( CFSTR("") ) );
    }
    else
    {
        wxString str = st ;
        wxMacConvertNewlines13To10( &str ) ;
#if wxUSE_UNICODE
#if wxUSE_UNICODE_WCHAR
        // native = wchar_t 4 bytes for us
        const wchar_t * const data = str.wc_str();
        const size_t size = str.length()*sizeof(wchar_t);
        CFStringBuiltInEncodings cfencoding = kCFStringEncodingUTF32Native;
#elif wxUSE_UNICODE_UTF8
        // native = utf8
        const char * const data = str.utf8_str();
        const size_t size = str.utf8_length();
        CFStringBuiltInEncodings cfencoding = kCFStringEncodingUTF8;
#else
    #error "unsupported Unicode representation"
#endif

        reset( CFStringCreateWithBytes( kCFAllocatorDefault,
            (const UInt8*)data, size, cfencoding, false /* no BOM */ ) );
#else // not wxUSE_UNICODE
        reset( CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
            wxMacGetSystemEncFromFontEnc( encoding ) ) );
#endif
    }
}
Esempio n. 4
0
// converts this string into a carbon foundation string with optional pc 2 mac encoding
void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
{
    Release() ; 
    if (st.IsEmpty())
    {
        m_cfs = CFSTR("") ;
        CFRetain( m_cfs ) ;
    }
    else
    {
        wxString str = st ;
        wxMacConvertNewlines13To10( &str ) ;
#if wxUSE_UNICODE
#if SIZEOF_WCHAR_T == 2
        m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
            (UniChar*)str.wc_str() , str.Len() );
#else
        wxMBConvUTF16BE converter ;
        size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
        UniChar *unibuf = new UniChar[ unicharlen / sizeof(UniChar) + 1 ] ;
        converter.WC2MB( (char*)unibuf , str.wc_str() , unicharlen ) ;
        m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault ,
            unibuf , unicharlen / sizeof(UniChar) ) ;
        delete[] unibuf ;
#endif
#else // not wxUSE_UNICODE
        m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
            wxMacGetSystemEncFromFontEnc( encoding ) ) ;
#endif
    }
    m_release = true ;
}
Esempio n. 5
0
wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding)
{
    if ( m_cfs == NULL )
        return wxEmptyString ;

    Size cflen = CFStringGetLength( m_cfs )  ;
    size_t noChars ;
    wxChar* buf = NULL ;

#if wxUSE_UNICODE
#if SIZEOF_WCHAR_T == 2
    buf = new wxChar[ cflen + 1 ] ;
    CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) buf ) ;
    noChars = cflen ;
#else
    UniChar* unibuf = new UniChar[ cflen + 1 ] ;
    CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ;
    unibuf[cflen] = 0 ;
    wxMBConvUTF16 converter ;
    noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ;
    wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Unable to count the number of characters in this string!") );
    buf = new wxChar[ noChars + 1 ] ;
    noChars = converter.MB2WC( buf , (const char*)unibuf , noChars + 1 ) ;
    wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Conversion of string failed!") );
    delete[] unibuf ;
#endif
#else
    CFIndex cStrLen ;
    CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
        '?' , false , NULL , 0 , &cStrLen ) ;
    buf = new wxChar[ cStrLen + 1 ] ;
    CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
        '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
    noChars = cStrLen ;
#endif

    buf[noChars] = 0 ;
    wxMacConvertNewlines10To13( buf ) ;
    wxString result(buf) ;
    delete[] buf ;
    return result ;
}
Esempio n. 6
0
wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding)
{
    Size cflen = CFStringGetLength( m_cfs )  ;
    size_t noChars ;
    wxChar* buf = NULL ;

#if wxUSE_UNICODE
#if SIZEOF_WCHAR_T == 2
    buf = new wxChar[ cflen + 1 ] ;
    CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) buf ) ;
    noChars = cflen ;
#else
    UniChar* unibuf = new UniChar[ cflen + 1 ] ;
    CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ;
    unibuf[cflen] = 0 ;
    wxMBConvUTF16BE converter ;
    noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ;
    buf = new wxChar[ noChars + 1 ] ;
    converter.MB2WC( buf , (const char*)unibuf , noChars ) ;
    delete[] unibuf ;
#endif
#else
    CFIndex cStrLen ;
    CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
        '?' , false , NULL , 0 , &cStrLen ) ;
    buf = new wxChar[ cStrLen + 1 ] ;
    CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
        '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
    noChars = cStrLen ;
#endif

    buf[noChars] = 0 ;
    wxMacConvertNewlines10To13( buf ) ;
    wxString result(buf) ;
    delete[] buf ;
    return result ;
}
Esempio n. 7
0
wxString wxCFStringRef::AsString(wxFontEncoding WXUNUSED_IN_UNICODE(encoding))
{
    if ( !get() )
        return wxEmptyString ;

    Size cflen = CFStringGetLength( get() )  ;
    char* buf = NULL ;

    CFStringEncoding cfencoding = 0;
    wxString result;    
#if wxUSE_UNICODE
  #if wxUSE_UNICODE_WCHAR
    cfencoding = kCFStringEncodingUTF32Native;
  #elif wxUSE_UNICODE_UTF8
    cfencoding = kCFStringEncodingUTF8;
  #else
    #error "unsupported unicode representation"
  #endif
#else
    cfencoding = wxMacGetSystemEncFromFontEnc( encoding );
#endif

    CFIndex cStrLen ;
    CFStringGetBytes( get() , CFRangeMake(0, cflen) , cfencoding ,
        '?' , false , NULL , 0 , &cStrLen ) ;
    buf = new char[ cStrLen ] ;
    CFStringGetBytes( get() , CFRangeMake(0, cflen) , cfencoding,
        '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
    
#if wxUSE_UNICODE
  #if wxUSE_UNICODE_WCHAR
    result = wxString( (const wchar_t*) buf , cStrLen/4);
  #elif wxUSE_UNICODE_UTF8
    result = wxString::FromUTF8( buf, cStrLen );
  #else
    #error "unsupported unicode representation"
  #endif
#else
    result = wxString(buf, cStrLen) ;
#endif
    
    delete[] buf ;
    wxMacConvertNewlines10To13( &result);
    return result ;
}
Esempio n. 8
0
// converts this string into a carbon foundation string with optional pc 2 mac encoding
void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
{
    Release() ;
    if (st.IsEmpty())
    {
        m_cfs = CFSTR("") ;
        CFRetain( m_cfs ) ;
    }
    else
    {
        wxString str = st ;
        wxMacConvertNewlines13To10( &str ) ;
#if wxUSE_UNICODE
#if SIZEOF_WCHAR_T == 2
        m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
            (UniChar*)str.wc_str() , str.Len() );
#else
        wxMBConvUTF16 converter ;
        size_t unicharbytes = converter.FromWChar( NULL , 0 , str.wc_str() , str.Length() ) ;
        wxASSERT( unicharbytes != wxCONV_FAILED );
        if ( unicharbytes == wxCONV_FAILED )
        {
            // create an empty string
            m_cfs = CFSTR("") ;
            CFRetain( m_cfs ) ;
        }
        else
        {
            // unicharbytes: number of bytes needed for UTF-16 encoded string (without terminating null)
            // unichars: number of UTF-16 characters (without terminating null)
            size_t unichars = unicharbytes /  sizeof(UniChar) ;
            UniChar *unibuf = new UniChar[ unichars ] ;
            converter.FromWChar( (char*)unibuf , unicharbytes , str.wc_str() , str.Length() ) ;
            m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault , unibuf , unichars ) ;
            delete[] unibuf ;
        }
#endif
#else // not wxUSE_UNICODE
        m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
            wxMacGetSystemEncFromFontEnc( encoding ) ) ;
#endif
    }
    m_release = true ;
}
Esempio n. 9
0
bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
                                          bool fixedWidthOnly)
{
    //
    // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
    //
    
    ATSFontFamilyIterator theFontFamilyIterator = NULL;
    ATSFontFamilyRef theATSFontFamilyRef = 0;
    OSStatus status = noErr;
    
    wxArrayString fontFamilies ;
    
    // Create the iterator
    status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil,
                                         kATSOptionFlagsUnRestrictedScope,
                                         &theFontFamilyIterator );
    
    wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ;
    
    while (status == noErr)
    {
        // Get the next font in the iteration.
        status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef );
        if(status == noErr)
        {
 #ifndef __LP64__
            // TODO CS : Find replacement
            // added CS : avoid showing fonts that won't be displayable
            FMFontStyle intrinsicStyle = 0 ;
            FMFont fontInstance ;
            FMFontFamily fmFamily = FMGetFontFamilyFromATSFontFamilyRef( theATSFontFamilyRef );
            status = FMGetFontFromFontFamilyInstance( fmFamily , 0 , &fontInstance , &intrinsicStyle);
            if ( status != noErr )
            {
                status = noErr;
                continue ;
            }
#endif
            if ( encoding != wxFONTENCODING_SYSTEM )
            {
                TextEncoding fontFamiliyEncoding = ATSFontFamilyGetEncoding(theATSFontFamilyRef) ;
                if ( fontFamiliyEncoding != macEncoding )
                    continue ;
            }
            
            // TODO: determine fixed widths ...

            CFStringRef theName = NULL;
            ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
            wxMacCFStringHolder cfName(theName) ;
            fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding()));
        }
        else if (status == kATSIterationScopeModified) // Make sure the font database hasnÕt changed.
        {
            // reset the iterator
            status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
                                                 kATSOptionFlagsUnRestrictedScope,
                                                 &theFontFamilyIterator);
            fontFamilies.Clear() ;
        }
    }
    ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
    
    for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
    {
        if ( OnFacename( fontFamilies[i] ) == false )
            break ;
    }
    
    return true;
}
Esempio n. 10
0
bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
                                          bool fixedWidthOnly)
{
     wxArrayString fontFamilies ;

    wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ;

    {
        CFArrayRef cfFontFamilies = nil;

#if wxOSX_USE_COCOA_OR_CARBON
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
        if ( UMAGetSystemVersion() >= 0x1060 )
            cfFontFamilies = CTFontManagerCopyAvailableFontFamilyNames();
        else
#endif
        {
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
            //
            // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
            //
            
            CFMutableArrayRef atsfontnames = CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks);;
            
            ATSFontFamilyIterator theFontFamilyIterator = NULL;
            ATSFontFamilyRef theATSFontFamilyRef = 0;
            OSStatus status = noErr;
            
            // Create the iterator
            status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil,
                                                 kATSOptionFlagsUnRestrictedScope,
                                                 &theFontFamilyIterator );
            
            while (status == noErr)
            {
                // Get the next font in the iteration.
                status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef );
                if(status == noErr)
                {
                    CFStringRef theName = NULL;
                    ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
                    CFArrayAppendValue(atsfontnames, theName);
                    CFRelease(theName);
                    
                }
                else if (status == kATSIterationScopeModified) // Make sure the font database hasn't changed.
                {
                    // reset the iterator
                    status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
                                                         kATSOptionFlagsUnRestrictedScope,
                                                         &theFontFamilyIterator);
                    CFArrayRemoveAllValues(atsfontnames);
                }
            }
            ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
            cfFontFamilies = atsfontnames;
#endif
        }
#elif wxOSX_USE_IPHONE
        cfFontFamilies = CopyAvailableFontFamilyNames();
#endif
        
        CFIndex count = CFArrayGetCount(cfFontFamilies);
        for(CFIndex i = 0; i < count; i++)
        {
            CFStringRef fontName = (CFStringRef)CFArrayGetValueAtIndex(cfFontFamilies, i);

            if ( encoding != wxFONTENCODING_SYSTEM || fixedWidthOnly)
            {
                wxCFRef<CTFontRef> font(CTFontCreateWithName(fontName, 12.0, NULL));
                if ( encoding != wxFONTENCODING_SYSTEM )
                {
                    CFStringEncoding fontFamiliyEncoding = CTFontGetStringEncoding(font);
                    if ( fontFamiliyEncoding != macEncoding )
                        continue;
                }
                
                if ( fixedWidthOnly )
                {
                    CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font);
                    if ( (traits & kCTFontMonoSpaceTrait) == 0 )
                        continue;
                }
                
            }
            
            wxCFStringRef cfName(wxCFRetain(fontName)) ;
            fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding()));
        }
        
        CFRelease(cfFontFamilies);
    }
    for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
    {
        if ( OnFacename( fontFamilies[i] ) == false )
            break ;
    }

    return true;
}