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;
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,
aV_justify, aWidth, aItalic, aBold, &wideningFactor, &ctm_a,
&ctm_b, &ctm_c, &ctm_d, &ctm_e, &ctm_f, &heightFactor );
computeTextParameters( aPos, aText, aOrient, t_size, textMirrored, aH_justify, aV_justify,
aWidth, aItalic, aBold, &wideningFactor, &ctm_a, &ctm_b, &ctm_c, &ctm_d,
&ctm_e, &ctm_f, &heightFactor );
SetColor( aColor );
SetCurrentLineWidth( aWidth, aData );
@ -1424,6 +1425,10 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos,
aFont = KIFONT::FONT::GetFont();
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_y( 0, full_box.y );
@ -1444,13 +1449,17 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos,
{
wxString word = str_tok.GetNextToken();
computeTextParameters( pos, word, aOrient, t_size, m_plotMirror, GR_TEXT_H_ALIGN_LEFT,
GR_TEXT_V_ALIGN_BOTTOM, aWidth, aItalic, aBold, &wideningFactor, &ctm_a,
&ctm_b, &ctm_c, &ctm_d, &ctm_e, &ctm_f, &heightFactor );
computeTextParameters( pos, word, aOrient, t_size, textMirrored, GR_TEXT_H_ALIGN_LEFT,
GR_TEXT_V_ALIGN_BOTTOM, aWidth, aItalic, aBold, &wideningFactor,
&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
// next word
VECTOR2I bbox( aFont->StringBoundaryLimits( word, t_size, aWidth, aBold, aItalic ).x, 0 );
if( textMirrored )
bbox.x *= -1;
RotatePoint( bbox, aOrient );
pos += bbox;

View File

@ -2,7 +2,7 @@
* 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) 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
* 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)
int tw = returnPostscriptTextWidth( aText, aSize.x, aItalic, aWidth );
int th = aSize.y;
int dx, dy;
int dx = 0, dy = 0;
switch( aH_justify )
{
@ -450,7 +450,7 @@ void PSLIKE_PLOTTER::computeTextParameters( const VECTOR2I& aPos,
*wideningFactor = sz_dev.x / sz_dev.y;
// Mirrored texts must be plotted as mirrored!
if( m_plotMirror )
if( m_plotMirror ^ aMirror )
*wideningFactor = -*wideningFactor;
// The CTM transformation matrix