]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/graphics.cpp
Quote wxExecute() arguments in wxDebugReportUpload when using curl.
[wxWidgets.git] / src / msw / graphics.cpp
index 78f1e4aa0cbe0c6921d8399408f2bb34b9b804d8..98134fb42fdf68b6a518c0bb07c75185bd83d86e 100644 (file)
@@ -78,6 +78,39 @@ inline Color wxColourToColor(const wxColour& col)
     return Color(col.Alpha(), col.Red(), col.Green(), col.Blue());
 }
 
+// Do not use this pointer directly, it's only used by
+// GetDrawTextStringFormat() and the cleanup code in wxGDIPlusRendererModule.
+StringFormat* gs_drawTextStringFormat = NULL;
+
+// Get the string format used for the text drawing and measuring functions:
+// notice that it must be the same one for all of them, otherwise the drawn
+// text might be of different size than what measuring it returned.
+inline StringFormat* GetDrawTextStringFormat()
+{
+    if ( !gs_drawTextStringFormat )
+    {
+        // We create this string format with exactly the same flags as
+        // StringFormat::GenericTypographic() is documented to use in MSDN
+        // except for the last one which doesn't make any difference for
+        // DrawText() but that we do want to use when measuring text.
+        //
+        // The reason for not just using GenericTypographic itself is that it
+        // does something else (what exactly is unfortunately not documented),
+        // which results in string being displayed quite differently from the
+        // default rendering, see #14537.
+        gs_drawTextStringFormat
+            = new StringFormat
+                  (
+                    StringFormatFlagsLineLimit |
+                    StringFormatFlagsNoClip |
+                    StringFormatFlagsNoFitBlackBox |
+                    StringFormatFlagsMeasureTrailingSpaces
+                  );
+    }
+
+    return gs_drawTextStringFormat;
+}
+
 } // anonymous namespace
 
 //-----------------------------------------------------------------------------
@@ -348,6 +381,13 @@ public:
     // stroke lines connecting each of the points
     virtual void StrokeLines( size_t n, const wxPoint2DDouble *points);
 
+    // We don't have any specific implementation for this one in wxMSW but
+    // override it just to avoid warnings about hiding the base class virtual.
+    virtual void StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints)
+    {
+        wxGraphicsContext::StrokeLines(n, beginPoints, endPoints);
+    }
+
     // draws a polygon
     virtual void DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
 
@@ -1752,7 +1792,7 @@ void wxGDIPlusContext::DoDrawText(const wxString& str,
                     -1,                     // length: string is NUL-terminated
                     fontData->GetGDIPlusFont(),
                     PointF(x, y),
-                    StringFormat::GenericTypographic(),
+                    GetDrawTextStringFormat(),
                     fontData->GetGDIPlusBrush()
                );
 }
@@ -1794,11 +1834,9 @@ void wxGDIPlusContext::GetTextExtent( const wxString &str, wxDouble *width, wxDo
     else
     {
         RectF layoutRect(0,0, 100000.0f, 100000.0f);
-        StringFormat strFormat( StringFormat::GenericTypographic() );
-        strFormat.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() );
 
         RectF bounds ;
-        m_context->MeasureString((const wchar_t *) s , wcslen(s) , f, layoutRect, &strFormat, &bounds ) ;
+        m_context->MeasureString((const wchar_t *) s , wcslen(s) , f, layoutRect, GetDrawTextStringFormat(), &bounds ) ;
         if ( width )
             *width = bounds.Width;
         if ( height )
@@ -1822,7 +1860,7 @@ void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble
     wxASSERT_MSG(text.length() == len , wxT("GetPartialTextExtents not yet implemented for multichar situations"));
 
     RectF layoutRect(0,0, 100000.0f, 100000.0f);
-    StringFormat strFormat( StringFormat::GenericTypographic() );
+    StringFormat strFormat( GetDrawTextStringFormat() );
 
     size_t startPosition = 0;
     size_t remainder = len;
@@ -1840,7 +1878,6 @@ void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble
             ranges[i].Length = startPosition+i+1 ;
         }
         strFormat.SetMeasurableCharacterRanges(span,ranges);
-        strFormat.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() );
         m_context->MeasureCharacterRanges(ws, -1 , f,layoutRect, &strFormat,span,regions) ;
 
         RectF bbox ;
@@ -2255,7 +2292,12 @@ class wxGDIPlusRendererModule : public wxModule
 {
 public:
     virtual bool OnInit() { return true; }
-    virtual void OnExit() { gs_GDIPlusRenderer.Unload(); }
+    virtual void OnExit()
+    {
+        wxDELETE(gs_drawTextStringFormat);
+
+        gs_GDIPlusRenderer.Unload();
+    }
 
 private:
     DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule)