]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/graphics.cpp
forward ported changes in 2.8.7 from WX_2_8_BRNACH
[wxWidgets.git] / src / msw / graphics.cpp
index a9a929568241513f1caf2b17d035693e48b8c16e..c7489e54a3d6e1f2dbbcc46b933013a423ccde9e 100644 (file)
@@ -80,7 +80,7 @@ static inline double RadToDeg(double deg) { return (deg * 180.0) / M_PI; }
 #include <commdlg.h>
 #endif
 
-class WXDLLIMPEXP_CORE wxGDIPlusPathData : public wxGraphicsPathData
+class wxGDIPlusPathData : public wxGraphicsPathData
 {
 public :
     wxGDIPlusPathData(wxGraphicsRenderer* renderer, GraphicsPath* path = NULL);
@@ -148,7 +148,7 @@ private :
     GraphicsPath* m_path;
 };
 
-class WXDLLIMPEXP_CORE wxGDIPlusMatrixData : public wxGraphicsMatrixData
+class wxGDIPlusMatrixData : public wxGraphicsMatrixData
 {
 public :
     wxGDIPlusMatrixData(wxGraphicsRenderer* renderer, Matrix* matrix = NULL) ;
@@ -205,7 +205,7 @@ private:
     Matrix* m_matrix ;
 } ;
 
-class WXDLLIMPEXP_CORE wxGDIPlusPenData : public wxGraphicsObjectRefData
+class wxGDIPlusPenData : public wxGraphicsObjectRefData
 {
 public:
     wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen );
@@ -224,7 +224,7 @@ protected :
     wxDouble m_width;
 };
 
-class WXDLLIMPEXP_CORE wxGDIPlusBrushData : public wxGraphicsObjectRefData
+class wxGDIPlusBrushData : public wxGraphicsObjectRefData
 {
 public:
     wxGDIPlusBrushData( wxGraphicsRenderer* renderer );
@@ -246,7 +246,7 @@ private :
     GraphicsPath* m_brushPath;
 };
 
-class WXDLLIMPEXP_CORE wxGDIPlusFontData : public wxGraphicsObjectRefData
+class wxGDIPlusFontData : public wxGraphicsObjectRefData
 {
 public:
     wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col );
@@ -259,7 +259,7 @@ private :
     Font* m_font;
 };
 
-class WXDLLIMPEXP_CORE wxGDIPlusContext : public wxGraphicsContext
+class wxGDIPlusContext : public wxGraphicsContext
 {
 public:
     wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc );
@@ -303,6 +303,7 @@ public:
     virtual void GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height,
         wxDouble *descent, wxDouble *externalLeading ) const;
     virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const;
+    virtual bool ShouldOffset() const;
 
 private:
     void    Init();
@@ -667,7 +668,7 @@ void wxGDIPlusPathData::GetCurrentPoint( wxDouble* x, wxDouble* y) const
 void wxGDIPlusPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double startAngle, double endAngle, bool clockwise )
 {
     double sweepAngle = endAngle - startAngle ;
-    if( abs(sweepAngle) >= 2*M_PI)
+    if( fabs(sweepAngle) >= 2*M_PI)
     {
         sweepAngle = 2 * M_PI;
     }
@@ -1042,7 +1043,7 @@ void wxGDIPlusContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y,
                 helper->GetPixelFormat(),&data);
 
             image = new Bitmap(data.Width, data.Height, data.Stride,
-                PixelFormat32bppARGB , (BYTE*) data.Scan0);
+                PixelFormat32bppPARGB , (BYTE*) data.Scan0);
 
             helper->UnlockBits(&data);
         }
@@ -1122,11 +1123,11 @@ void wxGDIPlusContext::GetTextExtent( const wxString &str, wxDouble *width, wxDo
         f->GetSize() / ffamily.GetEmHeight(FontStyleRegular);
 
     if ( height )
-        *height = rHeight * factorY + 0.5 ;
+        *height = rHeight * factorY;
     if ( descent )
-        *descent = rDescent * factorY + 0.5 ;
+        *descent = rDescent * factorY;
     if ( externalLeading )
-        *externalLeading = (rHeight - rAscent - rDescent) * factorY + 0.5 ;
+        *externalLeading = (rHeight - rAscent - rDescent) * factorY;
     // measuring empty strings is not guaranteed, so do it by hand
     if ( str.IsEmpty())
     {
@@ -1141,12 +1142,14 @@ void wxGDIPlusContext::GetTextExtent( const wxString &str, wxDouble *width, wxDo
         StringFormat strFormat;
         CharacterRange strRange(0,wcslen(s));
         strFormat.SetMeasurableCharacterRanges(1,&strRange);
+        strFormat.SetFormatFlags(StringFormatFlagsMeasureTrailingSpaces);
+
         Region region ;
         m_context->MeasureCharacterRanges(s, -1 , f,layoutRect, &strFormat,1,&region) ;
         RectF bbox ;
         region.GetBounds(&bbox,m_context);
         if ( width )
-            *width = bbox.GetRight()-bbox.GetLeft()+0.5;
+            *width = bbox.GetRight()-bbox.GetLeft();
     }
 }
 
@@ -1175,6 +1178,7 @@ void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble
         ranges[i].Length = 1 ;
     }
     strFormat.SetMeasurableCharacterRanges(len,ranges);
+    strFormat.SetFormatFlags(StringFormatFlagsMeasureTrailingSpaces);
     m_context->MeasureCharacterRanges(ws, -1 , f,layoutRect, &strFormat,1,regions) ;
 
     RectF bbox ;
@@ -1185,6 +1189,18 @@ void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble
     }
 }
 
+bool wxGDIPlusContext::ShouldOffset() const
+{     
+    int penwidth = 0 ;
+    if ( !m_pen.IsNull() )
+    {
+        penwidth = (int)((wxGDIPlusPenData*)m_pen.GetRefData())->GetWidth();
+        if ( penwidth == 0 )
+            penwidth = 1;
+    }
+    return ( penwidth % 2 ) == 1;
+}
+
 void* wxGDIPlusContext::GetNativeContext()
 {
     return m_context;
@@ -1213,7 +1229,7 @@ wxGraphicsMatrix wxGDIPlusContext::GetTransform() const
 // wxGDIPlusRenderer declaration
 //-----------------------------------------------------------------------------
 
-class WXDLLIMPEXP_CORE wxGDIPlusRenderer : public wxGraphicsRenderer
+class wxGDIPlusRenderer : public wxGraphicsRenderer
 {
 public :
     wxGDIPlusRenderer()
@@ -1273,6 +1289,7 @@ protected :
     void EnsureIsLoaded();
     void Load();
     void Unload();
+    friend class wxGDIPlusRendererModule;
 
 private :
     bool m_loaded;
@@ -1313,7 +1330,11 @@ void wxGDIPlusRenderer::Load()
 void wxGDIPlusRenderer::Unload()
 {
     if ( m_gditoken )
+    {
         GdiplusShutdown(m_gditoken);
+        m_gditoken = NULL;
+    }
+    m_loaded = false;
 }
 
 wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc)
@@ -1445,4 +1466,17 @@ wxGraphicsFont wxGDIPlusRenderer::CreateFont( const wxFont &font , const wxColou
         return wxNullGraphicsFont;
 }
 
+// Shutdown GDI+ at app exit, before possible dll unload
+class wxGDIPlusRendererModule : public wxModule
+{
+public:
+    virtual bool OnInit() { return true; }
+    virtual void OnExit() { gs_GDIPlusRenderer.Unload(); }
+
+private:
+    DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule, wxModule)
+
 #endif  // wxUSE_GRAPHICS_CONTEXT