From e961ca861706bd4162233d9a4f324fe16b92cd14 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Mon, 5 Apr 2021 14:41:50 -0700 Subject: [PATCH] Fix 0-width pen scaling on wxOSX Scaling got inverted in previous commit 52cc838b12 (Implement 0-width pen consistently in wxGraphicsContext, 2021-04-05) --- src/osx/carbon/graphics.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 9bcf06a6b9..762b42653d 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -913,10 +913,10 @@ void wxMacCoreGraphicsPenData::Apply( wxGraphicsContext* context ) double width = m_width; if (width <= 0) { - const double scaleFactor = context->GetContentScaleFactor(); - CGSize s = { scaleFactor, scaleFactor }; + const double f = 1 / context->GetContentScaleFactor(); + CGSize s = { f, f }; s = CGContextConvertSizeToUserSpace(cg, s); - width = 1 / wxMin(fabs(s.width), fabs(s.height)); + width = wxMax(fabs(s.width), fabs(s.height)); } CGContextSetLineWidth( cg, width ); CGContextSetLineJoin( cg , m_join ); @@ -1484,10 +1484,10 @@ public: return true; // no offset if overall scale is not odd integer - const double scaleFactor = GetContentScaleFactor(); - CGSize s = { scaleFactor, scaleFactor }; - s = CGContextConvertSizeToUserSpace(m_cgContext, s); - if (!wxIsSameDouble(fmod(wxMin(fabs(s.width), fabs(s.height)), 2.0), 1.0)) + const wxGraphicsMatrix matrix(GetTransform()); + double x = GetContentScaleFactor(), y = x; + matrix.TransformDistance(&x, &y); + if (!wxIsSameDouble(fmod(wxMin(fabs(x), fabs(y)), 2.0), 1.0)) return false; // offset if pen width is odd integer @@ -1568,10 +1568,9 @@ public : m_offset = offset; if ( m_offset ) { - const CGSize s = { scaleFactor, scaleFactor }; + const double f = 0.5 / scaleFactor; + const CGSize s = { f, f }; m_userOffset = CGContextConvertSizeToUserSpace(m_cg, s); - m_userOffset.width = 0.5 / m_userOffset.width; - m_userOffset.height = 0.5 / m_userOffset.height; CGContextTranslateCTM( m_cg, m_userOffset.width , m_userOffset.height ); } else