Avoid mirroring text when wxDC axes are inverted with GTK3

This was already done for RTL, just extend it to inversion of either axis,
as this is the behavior of MSW and GTK2.
See #22113
This commit is contained in:
Paul Cornett
2022-02-13 10:22:48 -08:00
parent a2076a3dd7
commit eafa248117

View File

@@ -91,7 +91,14 @@ void wxGTKCairoDCImpl::DoDrawText(const wxString& text, int x, int y)
if (text.empty())
return;
if (m_layoutDir == wxLayout_RightToLeft && text.find('\n') != wxString::npos)
cairo_t* cr = static_cast<cairo_t*>(m_graphicContext->GetNativeContext());
if (cr == NULL)
return;
double dx = 1, dy = 1;
cairo_user_to_device_distance(cr, &dx, &dy);
const bool xInverted = dx < 0;
if (xInverted && text.find('\n') != wxString::npos)
{
// RTL needs each line separately to position text properly.
// DrawLabel() will split the text and call back for each line.
@@ -105,13 +112,20 @@ void wxGTKCairoDCImpl::DoDrawText(const wxString& text, int x, int y)
CalcBoundingBox(x, y);
CalcBoundingBox(x + w, y + h);
if (m_layoutDir == wxLayout_RightToLeft)
{
const bool yInverted = dy < 0;
if (xInverted || yInverted)
m_graphicContext->PushState();
if (xInverted)
{
// text is not mirrored
m_graphicContext->Scale(-1, 1);
x = -x - w;
}
if (yInverted)
{
m_graphicContext->Scale(1, -1);
y = -y - h;
}
wxCompositionMode curMode = m_graphicContext->GetCompositionMode();
m_graphicContext->SetCompositionMode(wxCOMPOSITION_OVER);
@@ -123,7 +137,7 @@ void wxGTKCairoDCImpl::DoDrawText(const wxString& text, int x, int y)
m_graphicContext->SetCompositionMode(curMode);
if (m_layoutDir == wxLayout_RightToLeft)
if (xInverted || yInverted)
m_graphicContext->PopState();
}