From 0040c290edd14e3f9f953783cfdc7bb6b8f8d960 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 --- 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 afe7d9581d..2ee51f2aba 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -2085,9 +2085,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(); @@ -2120,8 +2121,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; @@ -2136,7 +2147,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 ); } } @@ -2243,18 +2254,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. @@ -2271,6 +2270,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() ) @@ -2283,7 +2296,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 7b6f92f482..10336c71a9 100644 --- a/pcbnew/pcb_textbox.cpp +++ b/pcbnew/pcb_textbox.cpp @@ -243,13 +243,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 05c9f9ac97..a26638fe06 100644 --- a/pcbnew/pcb_textbox.h +++ b/pcbnew/pcb_textbox.h @@ -87,6 +87,7 @@ public: int GetMarginBottom() const { return m_marginBottom; } VECTOR2I GetDrawPos() const override; + VECTOR2I GetDrawPos( bool aIsFlipped ) const; void SetTextAngle( const EDA_ANGLE& aAngle ) override;