From 2b106a2b34d201a619cc15aa8f96aab219af8d85 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 18 Sep 2023 12:38:09 +0100 Subject: [PATCH] Handle flipped horiz/vert justifications in FIELDS_GRID_TABLE. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15677 (cherry picked from commit 6f6256509372a67ced6f188e3c48017fa1d73512) --- eeschema/fields_grid_table.cpp | 40 +++++++++++++++++++++++++++------- eeschema/lib_field.h | 6 +++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index 4e54be3e7d..f4fe58588a 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -580,7 +580,7 @@ wxString FIELDS_GRID_TABLE::GetValue( int aRow, int aCol ) return StringFromBool( field.IsNameShown() ); case FDC_H_ALIGN: - switch ( field.GetHorizJustify() ) + switch ( field.GetEffectiveHorizJustify() ) { case GR_TEXT_H_ALIGN_LEFT: return _( "Left" ); case GR_TEXT_H_ALIGN_CENTER: return _( "Center" ); @@ -590,7 +590,7 @@ wxString FIELDS_GRID_TABLE::GetValue( int aRow, int aCol ) break; case FDC_V_ALIGN: - switch ( field.GetVertJustify() ) + switch ( field.GetEffectiveVertJustify() ) { case GR_TEXT_V_ALIGN_TOP: return _( "Top" ); case GR_TEXT_V_ALIGN_CENTER: return _( "Center" ); @@ -727,28 +727,52 @@ void FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue break; case FDC_H_ALIGN: + { + GR_TEXT_H_ALIGN_T horizontalJustification; + if( value == _( "Left" ) ) - field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT ); + horizontalJustification = GR_TEXT_H_ALIGN_LEFT; else if( value == _( "Center" ) ) - field.SetHorizJustify( GR_TEXT_H_ALIGN_CENTER ); + horizontalJustification = GR_TEXT_H_ALIGN_CENTER; else if( value == _( "Right" ) ) - field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT ); + horizontalJustification = GR_TEXT_H_ALIGN_RIGHT; else wxFAIL_MSG( wxT( "unknown horizontal alignment: " ) + value ); + // Note that we must set justifications before we can ask if they're flipped. If the old + // justification is center then it won't know (whereas if the new justification is center + // the we don't care). + field.SetHorizJustify( horizontalJustification ); + + if( field.IsHorizJustifyFlipped() ) + field.SetHorizJustify( EDA_TEXT::MapHorizJustify( - horizontalJustification ) ); + break; + } case FDC_V_ALIGN: + { + GR_TEXT_V_ALIGN_T verticalJustification; + if( value == _( "Top" ) ) - field.SetVertJustify( GR_TEXT_V_ALIGN_TOP ); + verticalJustification = GR_TEXT_V_ALIGN_TOP; else if( value == _( "Center" ) ) - field.SetVertJustify( GR_TEXT_V_ALIGN_CENTER ); + verticalJustification = GR_TEXT_V_ALIGN_CENTER; else if( value == _( "Bottom" ) ) - field.SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM ); + verticalJustification = GR_TEXT_V_ALIGN_BOTTOM; else wxFAIL_MSG( wxT( "unknown vertical alignment: " ) + value); + // Note that we must set justifications before we can ask if they're flipped. If the old + // justification is center then it won't know (whereas if the new justification is center + // the we don't care). + field.SetVertJustify( verticalJustification ); + + if( field.IsVertJustifyFlipped() ) + field.SetVertJustify( EDA_TEXT::MapVertJustify( -verticalJustification ) ); + break; + } case FDC_ITALIC: field.SetItalic( BoolFromString( value ) ); diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index cb2fa57a41..cb972f7989 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -118,6 +118,12 @@ public: KIFONT::FONT* getDrawFont() const override; + bool IsHorizJustifyFlipped() const { return false; } + bool IsVertJustifyFlipped() const { return false; } + + GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const { return GetHorizJustify(); } + GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const { return GetVertJustify(); } + /** * Copy parameters of this field to another field. Pointers are not copied. *