switching implementation new core system (ATS)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38949 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -23,119 +23,10 @@
|
||||
|
||||
#include "wx/fontutil.h"
|
||||
#include "wx/fontmap.h"
|
||||
#include "wx/fontutil.h"
|
||||
#include "wx/encinfo.h"
|
||||
|
||||
#include "wx/mac/private.h"
|
||||
|
||||
|
||||
class wxFontEnumeratorHelper
|
||||
{
|
||||
public:
|
||||
wxFontEnumeratorHelper(wxFontEnumerator *fontEnum);
|
||||
|
||||
// control what exactly are we enumerating
|
||||
bool SetEncoding(wxFontEncoding encoding);
|
||||
void SetFixedOnly(bool fixedOnly)
|
||||
{ m_fixedOnly = fixedOnly; }
|
||||
|
||||
// call to start enumeration
|
||||
void DoEnumerate();
|
||||
|
||||
private:
|
||||
// the object we forward calls to OnFont() to
|
||||
wxFontEnumerator *m_fontEnum;
|
||||
|
||||
// if != -1, enum only fonts which have this encoding
|
||||
int m_charset;
|
||||
|
||||
// if not empty, enum only the fonts with this facename
|
||||
wxString m_facename;
|
||||
|
||||
// if true, enum only fixed fonts
|
||||
bool m_fixedOnly;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontEnumeratorHelper
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFontEnumeratorHelper::wxFontEnumeratorHelper(wxFontEnumerator *fontEnum)
|
||||
{
|
||||
m_fontEnum = fontEnum;
|
||||
m_charset = -1;
|
||||
m_fixedOnly = false;
|
||||
}
|
||||
|
||||
bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
|
||||
{
|
||||
wxNativeEncodingInfo info;
|
||||
if ( !wxGetNativeFontEncoding( encoding, &info ) )
|
||||
{
|
||||
if ( !wxFontMapper::Get()->GetAltForEncoding( encoding, &info ) )
|
||||
// no such encodings at all
|
||||
return false;
|
||||
}
|
||||
|
||||
m_charset = info.charset;
|
||||
m_facename = info.facename;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxFontEnumeratorHelper::DoEnumerate()
|
||||
{
|
||||
MenuHandle menu;
|
||||
short lines;
|
||||
|
||||
menu = NewMenu( 32000, "\pFont" );
|
||||
AppendResMenu( menu, 'FONT' );
|
||||
lines = CountMenuItems( menu );
|
||||
|
||||
for ( int i = 1; i < lines + 1; i ++ )
|
||||
{
|
||||
wxString c_name ;
|
||||
#if TARGET_API_MAC_CARBON
|
||||
CFStringRef menutext ;
|
||||
c_name = wxEmptyString ;
|
||||
if ( CopyMenuItemTextAsCFString (menu, i, &menutext) == noErr )
|
||||
{
|
||||
c_name = wxMacCFStringHolder(menutext).AsString(wxLocale::GetSystemEncoding());
|
||||
}
|
||||
#else
|
||||
Str255 p_name;
|
||||
GetMenuItemText( menu, i, p_name );
|
||||
c_name = wxMacMakeStringFromPascal( p_name );
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
if ( m_fixedOnly )
|
||||
{
|
||||
// check that it's a fixed pitch font:
|
||||
// there is *no* error here: the flag name is misleading!
|
||||
if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH )
|
||||
// not a fixed pitch font
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( m_charset != -1 )
|
||||
{
|
||||
// check that we have the right encoding
|
||||
if ( lf->lfCharSet != m_charset )
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_fontEnum->OnFacename( c_name );
|
||||
}
|
||||
|
||||
DisposeMenu( menu );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontEnumerator
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -143,15 +34,71 @@ void wxFontEnumeratorHelper::DoEnumerate()
|
||||
bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
|
||||
bool fixedWidthOnly)
|
||||
{
|
||||
wxFontEnumeratorHelper fe(this);
|
||||
if ( fe.SetEncoding(encoding) )
|
||||
//
|
||||
// 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)
|
||||
{
|
||||
fe.SetFixedOnly(fixedWidthOnly);
|
||||
// Get the next font in the iteration.
|
||||
status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef );
|
||||
if(status == noErr)
|
||||
{
|
||||
// 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 ;
|
||||
}
|
||||
|
||||
if ( encoding != wxFONTENCODING_SYSTEM )
|
||||
{
|
||||
TextEncoding fontFamiliyEncoding = ATSFontFamilyGetEncoding(theATSFontFamilyRef) ;
|
||||
if ( fontFamiliyEncoding != macEncoding )
|
||||
continue ;
|
||||
}
|
||||
|
||||
// TODO: determine fixed widths ...
|
||||
|
||||
fe.DoEnumerate();
|
||||
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<73>t changed.
|
||||
{
|
||||
// reset the iterator
|
||||
status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
|
||||
kATSOptionFlagsUnRestrictedScope,
|
||||
&theFontFamilyIterator);
|
||||
fontFamilies.Clear() ;
|
||||
}
|
||||
}
|
||||
// else: no such fonts, unknown encoding
|
||||
|
||||
ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
|
||||
|
||||
for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
|
||||
{
|
||||
if ( OnFacename( fontFamilies[i] ) == false )
|
||||
break ;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user