From 5c2300022b9446831c44e1c89e893e4ad236e61e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 22 Jun 2024 23:53:53 +0100 Subject: [PATCH] Don't flip alignment of non-side-specific text. Fixes https://gitlab.com/kicad/code/kicad/-/issues/18235 (cherry picked from commit 0040c290edd14e3f9f953783cfdc7bb6b8f8d960) --- pcbnew/pcb_painter.cpp | 49 ++++++++++++++++++++++++++---------------- pcbnew/pcb_textbox.cpp | 8 ++++++- pcbnew/pcb_textbox.h | 1 + 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index c530e26ee4..9f2cd3a5f6 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -2061,9 +2061,10 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer ) return; } - TEXT_ATTRIBUTES attrs = aText->GetAttributes(); - const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer ); - bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill; + const KIFONT::METRICS& metrics = aText->GetFontMetrics(); + TEXT_ATTRIBUTES attrs = aText->GetAttributes(); + const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer ); + bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill; KIFONT::FONT* font = aText->GetFont(); @@ -2096,8 +2097,18 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer ) if( m_gal->IsFlippedX() && !( aText->GetLayerSet() & LSET::SideSpecificMask() ).any() ) { + VECTOR2I textPos = aText->GetTextPos(); + VECTOR2I textWidth = VECTOR2I( aText->GetTextBox().GetWidth(), 0 ); + RotatePoint( textWidth, textPos, aText->GetDrawRotation() ); + + if( attrs.m_Mirrored ) + textPos -= textWidth; + else + textPos += textWidth; + attrs.m_Mirrored = !attrs.m_Mirrored; - attrs.m_Halign = static_cast( -attrs.m_Halign ); + strokeText( resolvedText, textPos, attrs, metrics ); + return; } std::vector>* cache = nullptr; @@ -2112,7 +2123,7 @@ void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer ) } else { - strokeText( resolvedText, aText->GetTextPos(), attrs, aText->GetFontMetrics() ); + strokeText( resolvedText, aText->GetTextPos(), attrs, metrics ); } } @@ -2204,18 +2215,6 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer ) } } - if( resolvedText.Length() == 0 ) - return; - - TEXT_ATTRIBUTES attrs = aTextBox->GetAttributes(); - attrs.m_StrokeWidth = getLineThickness( aTextBox->GetEffectiveTextPenWidth() ); - - if( m_gal->IsFlippedX() && !( aTextBox->GetLayerSet() & LSET::SideSpecificMask() ).any() ) - { - attrs.m_Mirrored = !attrs.m_Mirrored; - attrs.m_Halign = static_cast( -attrs.m_Halign ); - } - if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) { // For now, the textbox is a filled shape. @@ -2232,6 +2231,20 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer ) #endif } + if( resolvedText.Length() == 0 ) + return; + + const KIFONT::METRICS& metrics = aTextBox->GetFontMetrics(); + TEXT_ATTRIBUTES attrs = aTextBox->GetAttributes(); + attrs.m_StrokeWidth = getLineThickness( aTextBox->GetEffectiveTextPenWidth() ); + + if( m_gal->IsFlippedX() && !( aTextBox->GetLayerSet() & LSET::SideSpecificMask() ).any() ) + { + attrs.m_Mirrored = !attrs.m_Mirrored; + strokeText( resolvedText, aTextBox->GetDrawPos( true ), attrs, metrics ); + return; + } + std::vector>* cache = nullptr; if( font->IsOutline() ) @@ -2244,7 +2257,7 @@ void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer ) } else { - strokeText( resolvedText, aTextBox->GetDrawPos(), attrs, aTextBox->GetFontMetrics() ); + strokeText( resolvedText, aTextBox->GetDrawPos(), attrs, metrics ); } } diff --git a/pcbnew/pcb_textbox.cpp b/pcbnew/pcb_textbox.cpp index e3b37bee6c..db2302e24d 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -237,13 +237,19 @@ std::vector PCB_TEXTBOX::GetAnchorAndOppositeCorner() const VECTOR2I PCB_TEXTBOX::GetDrawPos() const +{ + return GetDrawPos( false ); +} + + +VECTOR2I PCB_TEXTBOX::GetDrawPos( bool aIsFlipped ) const { std::vector corners = GetAnchorAndOppositeCorner(); GR_TEXT_H_ALIGN_T effectiveAlignment = GetHorizJustify(); VECTOR2I textAnchor; VECTOR2I offset; - if( IsMirrored() ) + if( IsMirrored() != aIsFlipped ) { switch( GetHorizJustify() ) { diff --git a/pcbnew/pcb_textbox.h b/pcbnew/pcb_textbox.h index 65424dc7e9..70e76d5771 100644 --- a/pcbnew/pcb_textbox.h +++ b/pcbnew/pcb_textbox.h @@ -77,6 +77,7 @@ public: int GetTextMargin() const; VECTOR2I GetDrawPos() const override; + VECTOR2I GetDrawPos( bool aIsFlipped ) const; void SetTextAngle( const EDA_ANGLE& aAngle ) override;