// implement base class pure virtuals
virtual int GetPointSize() const;
+ virtual wxSize GetPixelSize() const;
virtual int GetFamily() const;
virtual int GetStyle() const;
virtual int GetWeight() const;
#endif
#include "wx/fontutil.h"
-#include "wx/fontutil.h"
+#include "wx/graphics.h"
#include "wx/mac/private.h"
return M_FONTDATA->m_pointSize;
}
+wxSize wxFont::GetPixelSize() const
+{
+#if wxUSE_GRAPHICS_CONTEXT
+ // TODO: consider caching the value
+ wxGraphicsContext* dc = wxGraphicsContext::CreateFromNative((CGContextRef) NULL);
+ dc->SetFont(*(wxFont *)this);
+ wxDouble width, height = 0;
+ dc->GetTextExtent( wxT("g"), &width, &height, NULL, NULL);
+ return wxSize(width, height);
+#else
+ wxFontBase::GetPixelSize();
+#endif
+}
+
int wxFont::GetFamily() const
{
wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( CGContextRef cgcontext )
{
- Init();
- m_cgContext = cgcontext;
- CGContextSaveGState( m_cgContext );
- CGContextSaveGState( m_cgContext );
+ Init();
+ m_cgContext = cgcontext;
+ // FIXME: This check is needed because currently we need to use a DC/GraphicsContext
+ // in order to get font properties, like wxFont::GetPixelSize, but since we don't have
+ // a native window attached to use, I create a wxGraphicsContext with a NULL CGContextRef
+ // for this one operation.
+
+ // When wxFont::GetPixelSize on Mac no longer needs a graphics context, this check
+ // can be removed.
+ if (m_cgContext)
+ {
+ CGContextSaveGState( m_cgContext );
+ CGContextSaveGState( m_cgContext );
+ }
}
wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( WindowRef window )