CoreText is always available on 10.5+, so using all this code unconditionally, committing Vadim's suggestions with two extensions, see #15580

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75050 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2013-10-19 19:27:29 +00:00
parent f91544e613
commit e39c9f5914
11 changed files with 74 additions and 418 deletions

View File

@@ -142,9 +142,7 @@ public:
return *this;
}
#if wxOSX_USE_CORE_TEXT
void Init(CTFontDescriptorRef descr);
#endif
void Init(const wxNativeFontInfo& info);
void Init(int size,
wxFontFamily family,

View File

@@ -30,7 +30,6 @@
* text rendering system
*/
#define wxOSX_USE_CORE_TEXT 1
#define wxOSX_USE_ATSU_TEXT 1
/*

View File

@@ -41,7 +41,6 @@
* text rendering system
*/
#define wxOSX_USE_CORE_TEXT 1
#define wxOSX_USE_ATSU_TEXT 0
/*

View File

@@ -152,9 +152,7 @@ public:
CGFontRef OSXGetCGFont() const;
#endif
#if wxOSX_USE_CORE_TEXT
CTFontRef OSXGetCTFont() const;
#endif
#if wxOSX_USE_ATSU_TEXT
// Returns an ATSUStyle not ATSUStyle*

View File

@@ -19,7 +19,6 @@
* under a certain platform
*/
#define wxOSX_USE_CORE_TEXT 1
#define wxOSX_USE_ATSU_TEXT 0
#define wxHAS_OPENGL_ES

View File

@@ -50,11 +50,9 @@ public:
wxFontRefData(wxOSXSystemFont font, int size);
#if wxOSX_USE_CORE_TEXT
wxFontRefData( wxUint32 coreTextFontType );
wxFontRefData( CTFontRef font );
wxFontRefData( CTFontDescriptorRef fontdescriptor, int size );
#endif
virtual ~wxFontRefData();
@@ -146,9 +144,6 @@ public:
protected:
// common part of all ctors
void Init();
#if wxOSX_USE_CORE_TEXT
// void Init( CTFontRef font );
#endif
public:
bool m_fontValid;
#if wxOSX_USE_CARBON && wxOSX_USE_ATSU_TEXT
@@ -156,9 +151,7 @@ public:
// information here, as this speeds up and optimizes rendering
ThemeFontID m_macThemeFontID ;
#endif
#if wxOSX_USE_CORE_TEXT
wxCFRef<CTFontRef> m_ctFont;
#endif
#if wxOSX_USE_ATSU_TEXT
void CreateATSUFont();
@@ -184,9 +177,7 @@ wxFontRefData::wxFontRefData(const wxFontRefData& data) : wxGDIRefData()
#if wxOSX_USE_CARBON && wxOSX_USE_ATSU_TEXT
m_macThemeFontID = data.m_macThemeFontID;
#endif
#if wxOSX_USE_CORE_TEXT
m_ctFont = data.m_ctFont;
#endif
m_cgFont = data.m_cgFont;
#if wxOSX_USE_ATSU_TEXT
if ( data.m_macATSUStyle != NULL )
@@ -236,9 +227,7 @@ wxFontRefData::~wxFontRefData()
void wxFontRefData::Free()
{
#if wxOSX_USE_CORE_TEXT
m_ctFont.reset();
#endif
m_cgFont.reset();
#if wxOSX_USE_ATSU_TEXT
#if wxOSX_USE_CARBON
@@ -272,7 +261,6 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size)
wxASSERT( font != wxOSX_SYSTEM_FONT_NONE );
Init();
#if wxOSX_USE_CORE_TEXT
{
CTFontUIFontType uifont = kCTFontSystemFontType;
switch( font )
@@ -309,7 +297,6 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size)
descr.reset( CTFontCopyFontDescriptor( m_ctFont ) );
m_info.Init(descr);
}
#endif
#if wxOSX_USE_ATSU_TEXT
{
#if !wxOSX_USE_CARBON
@@ -464,7 +451,6 @@ void wxFontRefData::MacFindFont()
m_info.EnsureValid();
#if wxOSX_USE_CORE_TEXT
{
CTFontSymbolicTraits traits = 0;
@@ -527,8 +513,6 @@ void wxFontRefData::MacFindFont()
m_cgFont.reset(CTFontCopyGraphicsFont(m_ctFont, NULL));
}
#endif
#if wxOSX_USE_ATSU_TEXT
CreateATSUFont();
#endif
@@ -543,12 +527,8 @@ void wxFontRefData::MacFindFont()
bool wxFontRefData::IsFixedWidth() const
{
#if wxOSX_USE_CORE_TEXT
CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(m_ctFont);
return (traits & kCTFontMonoSpaceTrait) != 0;
#else
return false;
#endif
}
// ----------------------------------------------------------------------------
@@ -852,8 +832,6 @@ wxUint32 wxFont::MacGetATSUAdditionalQDStyles() const
}
#endif
#if wxOSX_USE_CORE_TEXT
CTFontRef wxFont::OSXGetCTFont() const
{
wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
@@ -864,8 +842,6 @@ CTFontRef wxFont::OSXGetCTFont() const
return (CTFontRef)(M_FONTDATA->m_ctFont);
}
#endif
#if wxOSX_USE_COCOA_OR_CARBON
CGFontRef wxFont::OSXGetCGFont() const
@@ -1005,7 +981,6 @@ void wxNativeFontInfo::Init()
m_descriptorValid = false;
}
#if wxOSX_USE_CORE_TEXT
void wxNativeFontInfo::Init(CTFontDescriptorRef descr)
{
Init();
@@ -1028,7 +1003,6 @@ void wxNativeFontInfo::Init(CTFontDescriptorRef descr)
wxCFStringRef familyName( (CFStringRef) CTFontDescriptorCopyAttribute(descr, kCTFontFamilyNameAttribute));
m_faceName = familyName.AsString();
}
#endif
void wxNativeFontInfo::EnsureValid()
{

View File

@@ -76,7 +76,6 @@ wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler),
case kEventFontSelection :
{
bool setup = false ;
#if wxOSX_USE_CORE_TEXT
if ( !setup )
{
CTFontDescriptorRef descr;
@@ -90,7 +89,6 @@ wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler),
setup = true;
}
}
#endif
#if wxOSX_USE_ATSU_TEXT
ATSUFontID fontId = 0 ;
if ( !setup && (cEvent.GetParameter<ATSUFontID>(kEventParamATSUFontID, &fontId) == noErr) )
@@ -240,24 +238,10 @@ int wxFontDialog::ShowModal()
font = m_fontData.m_initialFont ;
}
bool setup = false;
#if wxOSX_USE_CORE_TEXT
if ( !setup )
{
CTFontDescriptorRef descr = (CTFontDescriptorRef) CTFontCopyFontDescriptor( (CTFontRef) font.OSXGetCTFont() );
err = SetFontInfoForSelection (kFontSelectionCoreTextType,1, &descr , NULL);
CFRelease( descr );
setup = true;
}
#endif
#if wxOSX_USE_ATSU_TEXT
if ( !setup )
{
ATSUStyle style = (ATSUStyle)font.MacGetATSUStyle();
err = SetFontInfoForSelection (kFontSelectionATSUIType,1, &style , NULL);
setup = true;
}
#endif
CTFontDescriptorRef descr = (CTFontDescriptorRef) CTFontCopyFontDescriptor( (CTFontRef) font.OSXGetCTFont() );
err = SetFontInfoForSelection (kFontSelectionCoreTextType,1, &descr , NULL);
CFRelease( descr );
// just clicking on ENTER will not send us any font setting event, therefore we have to make sure
// that field is already correct
m_fontData.m_chosenFont = font ;

View File

@@ -66,8 +66,6 @@ int UMAGetSystemVersion()
}
#define wxOSX_USE_CORE_TEXT 1
#endif
#if wxOSX_USE_COCOA_OR_IPHONE
@@ -146,8 +144,6 @@ CGColorRef wxMacCreateCGColor( const wxColour& col )
return retval;
}
#if wxOSX_USE_CORE_TEXT
CTFontRef wxMacCreateCTFont( const wxFont& font )
{
#ifdef __WXMAC__
@@ -157,8 +153,6 @@ CTFontRef wxMacCreateCTFont( const wxFont& font )
#endif
}
#endif
// CGPattern wrapper class: always allocate on heap, never call destructor
class wxMacCoreGraphicsPattern
@@ -860,9 +854,7 @@ public:
#if wxOSX_USE_ATSU_TEXT
virtual ATSUStyle GetATSUStyle() { return m_macATSUIStyle; }
#endif
#if wxOSX_USE_CORE_TEXT
CTFontRef OSXGetCTFont() const { return m_ctFont ; }
#endif
wxColour GetColour() const { return m_colour ; }
bool GetUnderlined() const { return m_underlined ; }
@@ -875,9 +867,7 @@ private :
#if wxOSX_USE_ATSU_TEXT
ATSUStyle m_macATSUIStyle;
#endif
#if wxOSX_USE_CORE_TEXT
wxCFRef< CTFontRef > m_ctFont;
#endif
#if wxOSX_USE_IPHONE
UIFont* m_uiFont;
#endif
@@ -888,9 +878,7 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere
m_colour = col;
m_underlined = font.GetUnderlined();
#if wxOSX_USE_CORE_TEXT
m_ctFont.reset( wxMacCreateCTFont( font ) );
#endif
#if wxOSX_USE_IPHONE
m_uiFont = CreateUIFont(font);
wxMacCocoaRetain( m_uiFont );
@@ -934,8 +922,6 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere
wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData()
{
#if wxOSX_USE_CORE_TEXT
#endif
#if wxOSX_USE_ATSU_TEXT
if ( m_macATSUIStyle )
{
@@ -2303,79 +2289,51 @@ void wxMacCoreGraphicsContext::DoDrawText( const wxString &str, wxDouble x, wxDo
if (m_composition == wxCOMPOSITION_DEST)
return;
#if wxOSX_USE_CORE_TEXT
{
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
wxCFStringRef text(str, wxLocale::GetSystemEncoding() );
CTFontRef font = fref->OSXGetCTFont();
CGColorRef col = wxMacCreateCGColor( fref->GetColour() );
#if 0
// right now there's no way to get continuous underlines, only words, so we emulate it
CTUnderlineStyle ustyle = fref->GetUnderlined() ? kCTUnderlineStyleSingle : kCTUnderlineStyleNone ;
wxCFRef<CFNumberRef> underlined( CFNumberCreate(NULL, kCFNumberSInt32Type, &ustyle) );
CFStringRef keys[] = { kCTFontAttributeName , kCTForegroundColorAttributeName, kCTUnderlineStyleAttributeName };
CFTypeRef values[] = { font, col, underlined };
#else
CFStringRef keys[] = { kCTFontAttributeName , kCTForegroundColorAttributeName };
CFTypeRef values[] = { font, col };
#endif
wxCFRef<CFDictionaryRef> attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values,
WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) );
wxCFRef<CFAttributedStringRef> attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, attributes) );
wxCFRef<CTLineRef> line( CTLineCreateWithAttributedString(attrtext) );
y += CTFontGetAscent(font);
CGContextSaveGState(m_cgContext);
CGAffineTransform textMatrix = CGContextGetTextMatrix(m_cgContext);
CGContextTranslateCTM(m_cgContext, (CGFloat) x, (CGFloat) y);
CGContextScaleCTM(m_cgContext, 1, -1);
CGContextSetTextMatrix(m_cgContext, CGAffineTransformIdentity);
CTLineDraw( line, m_cgContext );
if ( fref->GetUnderlined() ) {
//AKT: draw horizontal line 1 pixel thick and with 1 pixel gap under baseline
CGFloat width = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
CGPoint points[] = { {0.0, -2.0}, {width, -2.0} };
CGContextSetStrokeColorWithColor(m_cgContext, col);
CGContextSetShouldAntialias(m_cgContext, false);
CGContextSetLineWidth(m_cgContext, 1.0);
CGContextStrokeLineSegments(m_cgContext, points, 2);
}
CGContextRestoreGState(m_cgContext);
CGContextSetTextMatrix(m_cgContext, textMatrix);
CGColorRelease( col );
CheckInvariants();
return;
}
#endif
#if wxOSX_USE_ATSU_TEXT
{
DrawText(str, x, y, 0.0);
return;
}
#endif
#if wxOSX_USE_IPHONE
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
wxCFStringRef text(str, wxLocale::GetSystemEncoding() );
CTFontRef font = fref->OSXGetCTFont();
CGColorRef col = wxMacCreateCGColor( fref->GetColour() );
#if 0
// right now there's no way to get continuous underlines, only words, so we emulate it
CTUnderlineStyle ustyle = fref->GetUnderlined() ? kCTUnderlineStyleSingle : kCTUnderlineStyleNone ;
wxCFRef<CFNumberRef> underlined( CFNumberCreate(NULL, kCFNumberSInt32Type, &ustyle) );
CFStringRef keys[] = { kCTFontAttributeName , kCTForegroundColorAttributeName, kCTUnderlineStyleAttributeName };
CFTypeRef values[] = { font, col, underlined };
#else
CFStringRef keys[] = { kCTFontAttributeName , kCTForegroundColorAttributeName };
CFTypeRef values[] = { font, col };
#endif
wxCFRef<CFDictionaryRef> attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values,
WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) );
wxCFRef<CFAttributedStringRef> attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, attributes) );
wxCFRef<CTLineRef> line( CTLineCreateWithAttributedString(attrtext) );
y += CTFontGetAscent(font);
CGContextSaveGState(m_cgContext);
CGAffineTransform textMatrix = CGContextGetTextMatrix(m_cgContext);
CGColorRef col = wxMacCreateCGColor( fref->GetColour() );
CGContextSetTextDrawingMode (m_cgContext, kCGTextFill);
CGContextSetFillColorWithColor( m_cgContext, col );
CGContextTranslateCTM(m_cgContext, (CGFloat) x, (CGFloat) y);
CGContextScaleCTM(m_cgContext, 1, -1);
CGContextSetTextMatrix(m_cgContext, CGAffineTransformIdentity);
wxCFStringRef text(str, wxLocale::GetSystemEncoding() );
DrawTextInContext( m_cgContext, CGPointMake( x, y ), fref->GetUIFont() , text.AsNSString() );
CTLineDraw( line, m_cgContext );
if ( fref->GetUnderlined() ) {
//AKT: draw horizontal line 1 pixel thick and with 1 pixel gap under baseline
CGFloat width = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
CGPoint points[] = { {0.0, -2.0}, {width, -2.0} };
CGContextSetStrokeColorWithColor(m_cgContext, col);
CGContextSetShouldAntialias(m_cgContext, false);
CGContextSetLineWidth(m_cgContext, 1.0);
CGContextStrokeLineSegments(m_cgContext, points, 2);
}
CGContextRestoreGState(m_cgContext);
CFRelease( col );
#endif
CGContextSetTextMatrix(m_cgContext, textMatrix);
CGColorRelease( col );
CheckInvariants();
}
@@ -2391,103 +2349,9 @@ void wxMacCoreGraphicsContext::DoDrawRotatedText(const wxString &str,
if (m_composition == wxCOMPOSITION_DEST)
return;
#if wxOSX_USE_CORE_TEXT
{
// default implementation takes care of rotation and calls non rotated DrawText afterwards
wxGraphicsContext::DoDrawRotatedText( str, x, y, angle );
return;
}
#endif
#if wxOSX_USE_ATSU_TEXT
{
OSStatus status = noErr;
ATSUTextLayout atsuLayout;
wxMacUniCharBuffer unibuf( str );
UniCharCount chars = unibuf.GetChars();
ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle());
status = ::ATSUCreateTextLayoutWithTextPtr( unibuf.GetBuffer() , 0 , chars , chars , 1 ,
&chars , &style , &atsuLayout );
wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") );
status = ::ATSUSetTransientFontMatching( atsuLayout , true );
wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") );
int iAngle = int( angle * RAD2DEG );
if ( abs(iAngle) > 0 )
{
Fixed atsuAngle = IntToFixed( iAngle );
ATSUAttributeTag atsuTags[] =
{
kATSULineRotationTag ,
};
ByteCount atsuSizes[WXSIZEOF(atsuTags)] =
{
sizeof( Fixed ) ,
};
ATSUAttributeValuePtr atsuValues[WXSIZEOF(atsuTags)] =
{
&atsuAngle ,
};
status = ::ATSUSetLayoutControls(atsuLayout , WXSIZEOF(atsuTags),
atsuTags, atsuSizes, atsuValues );
}
{
ATSUAttributeTag atsuTags[] =
{
kATSUCGContextTag ,
};
ByteCount atsuSizes[WXSIZEOF(atsuTags)] =
{
sizeof( CGContextRef ) ,
};
ATSUAttributeValuePtr atsuValues[WXSIZEOF(atsuTags)] =
{
&m_cgContext ,
};
status = ::ATSUSetLayoutControls(atsuLayout , WXSIZEOF(atsuTags),
atsuTags, atsuSizes, atsuValues );
}
ATSUTextMeasurement textBefore, textAfter;
ATSUTextMeasurement ascent, descent;
status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
&textBefore , &textAfter, &ascent , &descent );
wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") );
Rect rect;
x += (int)(sin(angle) * FixedToFloat(ascent));
y += (int)(cos(angle) * FixedToFloat(ascent));
status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
IntToFixed(x) , IntToFixed(y) , &rect );
wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") );
CGContextSaveGState(m_cgContext);
CGContextTranslateCTM(m_cgContext, (CGFloat) x, (CGFloat) y);
CGContextScaleCTM(m_cgContext, 1, -1);
status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
IntToFixed(0) , IntToFixed(0) );
wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") );
CGContextRestoreGState(m_cgContext);
::ATSUDisposeTextLayout(atsuLayout);
CheckInvariants();
return;
}
#endif
#if wxOSX_USE_IPHONE
// default implementation takes care of rotation and calls non rotated DrawText afterwards
wxGraphicsContext::DoDrawRotatedText( str, x, y, angle );
#endif
CheckInvariants();
}
@@ -2512,100 +2376,33 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid
if (str.empty())
strToMeasure = wxS(" ");
#if wxOSX_USE_CORE_TEXT
{
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
CTFontRef font = fref->OSXGetCTFont();
wxCFStringRef text(strToMeasure, wxLocale::GetSystemEncoding() );
CFStringRef keys[] = { kCTFontAttributeName };
CFTypeRef values[] = { font };
wxCFRef<CFDictionaryRef> attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values,
WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) );
wxCFRef<CFAttributedStringRef> attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, attributes) );
wxCFRef<CTLineRef> line( CTLineCreateWithAttributedString(attrtext) );
CGFloat a, d, l, w;
w = CTLineGetTypographicBounds(line, &a, &d, &l);
if ( !str.empty() )
{
if ( width )
*width = w;
if ( height )
*height = a+d+l;
}
if ( descent )
*descent = d;
if ( externalLeading )
*externalLeading = l;
return;
}
#endif
#if wxOSX_USE_ATSU_TEXT
{
OSStatus status = noErr;
ATSUTextLayout atsuLayout;
wxMacUniCharBuffer unibuf( strToMeasure );
UniCharCount chars = unibuf.GetChars();
ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle());
status = ::ATSUCreateTextLayoutWithTextPtr( unibuf.GetBuffer() , 0 , chars , chars , 1 ,
&chars , &style , &atsuLayout );
wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the text") );
status = ::ATSUSetTransientFontMatching( atsuLayout , true );
wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") );
ATSUTextMeasurement textBefore, textAfter;
ATSUTextMeasurement textAscent, textDescent;
status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
&textBefore , &textAfter, &textAscent , &textDescent );
if ( !str.empty() )
{
if ( width )
*width = FixedToFloat(textAfter - textBefore);
if ( height )
*height = FixedToFloat(textAscent + textDescent);
}
if ( descent )
*descent = FixedToFloat(textDescent);
if ( externalLeading )
*externalLeading = 0;
::ATSUDisposeTextLayout(atsuLayout);
return;
}
#endif
#if wxOSX_USE_IPHONE
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
CTFontRef font = fref->OSXGetCTFont();
wxCFStringRef text(strToMeasure, wxLocale::GetSystemEncoding() );
CGSize sz = MeasureTextInContext( fref->GetUIFont() , text.AsNSString() );
CFStringRef keys[] = { kCTFontAttributeName };
CFTypeRef values[] = { font };
wxCFRef<CFDictionaryRef> attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values,
WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) );
wxCFRef<CFAttributedStringRef> attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, attributes) );
wxCFRef<CTLineRef> line( CTLineCreateWithAttributedString(attrtext) );
CGFloat a, d, l, w;
w = CTLineGetTypographicBounds(line, &a, &d, &l);
if ( !str.empty() )
{
if ( width )
*width = sz.width;
*width = w;
if ( height )
*height = sz.height;
*height = a+d+l;
}
/*
if ( descent )
*descent = FixedToFloat(textDescent);
*descent = d;
if ( externalLeading )
*externalLeading = 0;
*/
#endif
*externalLeading = l;
CheckInvariants();
}
@@ -2619,93 +2416,23 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr
if (text.empty())
return;
#if wxOSX_USE_CORE_TEXT
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
CTFontRef font = fref->OSXGetCTFont();
wxCFStringRef t(text, wxLocale::GetSystemEncoding() );
CFStringRef keys[] = { kCTFontAttributeName };
CFTypeRef values[] = { font };
wxCFRef<CFDictionaryRef> attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values,
WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) );
wxCFRef<CFAttributedStringRef> attrtext( CFAttributedStringCreate(kCFAllocatorDefault, t, attributes) );
wxCFRef<CTLineRef> line( CTLineCreateWithAttributedString(attrtext) );
int chars = text.length();
for ( int pos = 0; pos < (int)chars; pos ++ )
{
wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData();
CTFontRef font = fref->OSXGetCTFont();
wxCFStringRef t(text, wxLocale::GetSystemEncoding() );
CFStringRef keys[] = { kCTFontAttributeName };
CFTypeRef values[] = { font };
wxCFRef<CFDictionaryRef> attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values,
WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) );
wxCFRef<CFAttributedStringRef> attrtext( CFAttributedStringCreate(kCFAllocatorDefault, t, attributes) );
wxCFRef<CTLineRef> line( CTLineCreateWithAttributedString(attrtext) );
int chars = text.length();
for ( int pos = 0; pos < (int)chars; pos ++ )
{
widths[pos] = CTLineGetOffsetForStringIndex( line, pos+1 , NULL );
}
return;
widths[pos] = CTLineGetOffsetForStringIndex( line, pos+1 , NULL );
}
#endif
#if wxOSX_USE_ATSU_TEXT
{
OSStatus status = noErr;
ATSUTextLayout atsuLayout;
wxMacUniCharBuffer unibuf( text );
UniCharCount chars = unibuf.GetChars();
ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle());
status = ::ATSUCreateTextLayoutWithTextPtr( unibuf.GetBuffer() , 0 , chars , chars , 1 ,
&chars , &style , &atsuLayout );
wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the text") );
status = ::ATSUSetTransientFontMatching( atsuLayout , true );
wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") );
// new implementation from JS, keep old one just in case
#if 0
for ( int pos = 0; pos < (int)chars; pos ++ )
{
unsigned long actualNumberOfBounds = 0;
ATSTrapezoid glyphBounds;
// We get a single bound, since the text should only require one. If it requires more, there is an issue
OSStatus result;
result = ATSUGetGlyphBounds( atsuLayout, 0, 0, kATSUFromTextBeginning, pos + 1,
kATSUseDeviceOrigins, 1, &glyphBounds, &actualNumberOfBounds );
if (result != noErr || actualNumberOfBounds != 1 )
return;
widths[pos] = FixedToFloat( glyphBounds.upperRight.x - glyphBounds.upperLeft.x );
//unsigned char uch = s[i];
}
#else
ATSLayoutRecord *layoutRecords = NULL;
ItemCount glyphCount = 0;
// Get the glyph extents
OSStatus err = ::ATSUDirectGetLayoutDataArrayPtrFromTextLayout(atsuLayout,
0,
kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
(void **)
&layoutRecords,
&glyphCount);
wxASSERT(glyphCount == (text.length()+1));
if ( err == noErr && glyphCount == (text.length()+1))
{
for ( int pos = 1; pos < (int)glyphCount ; pos ++ )
{
widths[pos-1] = FixedToFloat( layoutRecords[pos].realPos );
}
}
::ATSUDirectReleaseLayoutDataArrayPtr(NULL,
kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
(void **) &layoutRecords);
#endif
::ATSUDisposeTextLayout(atsuLayout);
}
#endif
#if wxOSX_USE_IPHONE
// TODO core graphics text implementation here
#endif
CheckInvariants();
}

View File

@@ -2853,32 +2853,14 @@ void wxMacDataBrowserListCtrlControl::DrawItem(
HIThemeTextHorizontalFlush hFlush = kHIThemeTextHorizontalFlushLeft;
HIThemeTextInfo info;
bool setup = false;
#if wxOSX_USE_CORE_TEXT
info.version = kHIThemeTextInfoVersionOne;
info.fontID = kThemeViewsFont;
if (font.IsOk())
{
info.fontID = kThemeSpecifiedFont;
info.font = (CTFontRef) font.OSXGetCTFont();
setup = true;
}
#endif
#if wxOSX_USE_ATSU_TEXT
if ( !setup )
{
info.version = kHIThemeTextInfoVersionZero;
info.fontID = kThemeViewsFont;
if (font.IsOk())
{
info.fontID = font.MacGetThemeFontID();
::TextSize( (short)(font.GetPointSize()) ) ;
::TextFace( font.MacGetFontStyle() ) ;
}
}
#endif
wxListItem item;
list->GetColumn(listColumn, item);

View File

@@ -1178,7 +1178,6 @@ void wxMacControl::SuperChangedPosition()
void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack )
{
m_font = font;
#if wxOSX_USE_CORE_TEXT
HIViewPartCode part = 0;
HIThemeTextHorizontalFlush flush = kHIThemeTextHorizontalFlushDefault;
if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL )
@@ -1195,7 +1194,6 @@ void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , l
fontStyle.flags = kControlUseForeColorMask;
::SetControlFontStyle( m_controlRef , &fontStyle );
}
#endif
#if wxOSX_USE_ATSU_TEXT
ControlFontStyleRec fontStyle;
if ( font.MacGetThemeFontID() != kThemeCurrentPortFont )

View File

@@ -40,8 +40,7 @@ bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
wxArrayString fontFamilies ;
wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ;
#if wxOSX_USE_CORE_TEXT
{
CFArrayRef cfFontFamilies = nil;
@@ -127,7 +126,6 @@ bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
CFRelease(cfFontFamilies);
}
#endif
for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
{
if ( OnFacename( fontFamilies[i] ) == false )