From 0d800500577cd9c2f340adf38d8ff92f06a83045 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Tue, 2 Mar 2021 10:50:39 -0800 Subject: [PATCH] Make wxGCDC behavior with 0-width wxPen consistent with MSW wxDC MSW uses a 1-pixel width in that case. See #19077 --- src/common/dcgraph.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index b5c242dd79..f103a2a0ca 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -518,10 +518,36 @@ void wxGCDCImpl::SetFont( const wxFont &font ) void wxGCDCImpl::SetPen( const wxPen &pen ) { m_pen = pen; - if ( m_graphicContext ) + if (m_graphicContext == NULL) + return; + + wxPenStyle style; + if (!pen.IsOk() || (style = pen.GetStyle()) == wxPENSTYLE_TRANSPARENT) { - m_graphicContext->SetPen( m_pen ); + m_graphicContext->SetPen(wxGraphicsPen()); + return; } + + // 0-width pen is 1 pixel wide with MSW wxDC + const int w = pen.GetWidth(); + const double width = w ? double(w) : 1 / wxMin(m_scaleX, m_scaleY); + + wxGraphicsPenInfo info(pen.GetColour(), width, style); + info.Join(pen.GetJoin()).Cap(pen.GetCap()); + + if (style == wxPENSTYLE_USER_DASH) + { + wxDash* dashes; + if (int n = pen.GetDashes(&dashes)) + info.Dashes(n, dashes); + } + else if (style == wxPENSTYLE_STIPPLE) + { + if (const wxBitmap* stipple = pen.GetStipple()) + info.Stipple(*stipple); + } + + m_graphicContext->SetPen(m_graphicContext->CreatePen(info)); } void wxGCDCImpl::SetBrush( const wxBrush &brush )