]> git.saurik.com Git - wxWidgets.git/commitdiff
Override GetPixelSize on OS X as the base impl creates a wxScreenDC each time, which...
authorKevin Ollivier <kevino@theolliviers.com>
Thu, 26 Oct 2006 00:22:56 +0000 (00:22 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Thu, 26 Oct 2006 00:22:56 +0000 (00:22 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42416 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/mac/carbon/font.h
src/mac/carbon/font.cpp
src/mac/carbon/graphics.cpp

index 352a9a79f88012a62afb4e64afa28e71f7a8d526..d7a69df50ea057d42e2036758cf989d1e49ec3ff 100644 (file)
@@ -56,6 +56,7 @@ public:
 
     // 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;
index e2c9d4f9a0bcb11b1fa35192d57d94c584ffeedd..75ea3f918ada154f72e5fc9e6464d07c7f51e6f3 100644 (file)
@@ -21,7 +21,7 @@
 #endif
 
 #include "wx/fontutil.h"
-#include "wx/fontutil.h"
+#include "wx/graphics.h"
 
 #include "wx/mac/private.h"
 
@@ -528,6 +528,20 @@ int wxFont::GetPointSize() const
     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") );
index 57e63acbbd6bf9cf216f23ca6a382dab23bdf7df..c9ad6509e16f29e0497b5267e01f6664e71c9375 100755 (executable)
@@ -353,10 +353,20 @@ void wxMacCoreGraphicsContext::Init()
 
 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 )