PDF plot: match mirror state between hidden and plotted text.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16066
This commit is contained in:
Alex Shvartzkop 2023-11-12 00:48:18 +03:00
parent 39788e7e6c
commit 31e79ef54f
2 changed files with 18 additions and 9 deletions

View File

@ -1409,10 +1409,11 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos,
double wideningFactor, heightFactor; double wideningFactor, heightFactor;
VECTOR2I t_size( std::abs( aSize.x ), std::abs( aSize.y ) ); VECTOR2I t_size( std::abs( aSize.x ), std::abs( aSize.y ) );
bool textMirrored = aSize.x < 0;
computeTextParameters( aPos, aText, aOrient, t_size, m_plotMirror, aH_justify, computeTextParameters( aPos, aText, aOrient, t_size, textMirrored, aH_justify, aV_justify,
aV_justify, aWidth, aItalic, aBold, &wideningFactor, &ctm_a, aWidth, aItalic, aBold, &wideningFactor, &ctm_a, &ctm_b, &ctm_c, &ctm_d,
&ctm_b, &ctm_c, &ctm_d, &ctm_e, &ctm_f, &heightFactor ); &ctm_e, &ctm_f, &heightFactor );
SetColor( aColor ); SetColor( aColor );
SetCurrentLineWidth( aWidth, aData ); SetCurrentLineWidth( aWidth, aData );
@ -1424,6 +1425,10 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos,
aFont = KIFONT::FONT::GetFont(); aFont = KIFONT::FONT::GetFont();
VECTOR2I full_box( aFont->StringBoundaryLimits( aText, t_size, aWidth, aBold, aItalic ) ); VECTOR2I full_box( aFont->StringBoundaryLimits( aText, t_size, aWidth, aBold, aItalic ) );
if( textMirrored )
full_box.x *= -1;
VECTOR2I box_x( full_box.x, 0 ); VECTOR2I box_x( full_box.x, 0 );
VECTOR2I box_y( 0, full_box.y ); VECTOR2I box_y( 0, full_box.y );
@ -1444,13 +1449,17 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos,
{ {
wxString word = str_tok.GetNextToken(); wxString word = str_tok.GetNextToken();
computeTextParameters( pos, word, aOrient, t_size, m_plotMirror, GR_TEXT_H_ALIGN_LEFT, computeTextParameters( pos, word, aOrient, t_size, textMirrored, GR_TEXT_H_ALIGN_LEFT,
GR_TEXT_V_ALIGN_BOTTOM, aWidth, aItalic, aBold, &wideningFactor, &ctm_a, GR_TEXT_V_ALIGN_BOTTOM, aWidth, aItalic, aBold, &wideningFactor,
&ctm_b, &ctm_c, &ctm_d, &ctm_e, &ctm_f, &heightFactor ); &ctm_a, &ctm_b, &ctm_c, &ctm_d, &ctm_e, &ctm_f, &heightFactor );
// Extract the changed width and rotate by the orientation to get the offset for the // Extract the changed width and rotate by the orientation to get the offset for the
// next word // next word
VECTOR2I bbox( aFont->StringBoundaryLimits( word, t_size, aWidth, aBold, aItalic ).x, 0 ); VECTOR2I bbox( aFont->StringBoundaryLimits( word, t_size, aWidth, aBold, aItalic ).x, 0 );
if( textMirrored )
bbox.x *= -1;
RotatePoint( bbox, aOrient ); RotatePoint( bbox, aOrient );
pos += bbox; pos += bbox;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -423,7 +423,7 @@ void PSLIKE_PLOTTER::computeTextParameters( const VECTOR2I& aPos,
// This is an approximation of the text bounds (in IUs) // This is an approximation of the text bounds (in IUs)
int tw = returnPostscriptTextWidth( aText, aSize.x, aItalic, aWidth ); int tw = returnPostscriptTextWidth( aText, aSize.x, aItalic, aWidth );
int th = aSize.y; int th = aSize.y;
int dx, dy; int dx = 0, dy = 0;
switch( aH_justify ) switch( aH_justify )
{ {
@ -450,7 +450,7 @@ void PSLIKE_PLOTTER::computeTextParameters( const VECTOR2I& aPos,
*wideningFactor = sz_dev.x / sz_dev.y; *wideningFactor = sz_dev.x / sz_dev.y;
// Mirrored texts must be plotted as mirrored! // Mirrored texts must be plotted as mirrored!
if( m_plotMirror ) if( m_plotMirror ^ aMirror )
*wideningFactor = -*wideningFactor; *wideningFactor = -*wideningFactor;
// The CTM transformation matrix // The CTM transformation matrix