diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 83b27656cb..ae12919f38 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -94,13 +94,7 @@ EDA_TEXT::EDA_TEXT( const wxString& text ) : { int sz = Mils2iu( DEFAULT_SIZE_TEXT ); SetTextSize( wxSize( sz, sz ) ); - m_shown_text_has_text_var_refs = false; - - if( !text.IsEmpty() ) - { - m_shown_text = UnescapeString( text ); - m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) ); - } + cacheShownText(); } @@ -108,8 +102,7 @@ EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText ) : m_text( aText.m_text ), m_e( aText.m_e ) { - m_shown_text = UnescapeString( m_text ); - m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) ); + cacheShownText(); } @@ -121,8 +114,7 @@ EDA_TEXT::~EDA_TEXT() void EDA_TEXT::SetText( const wxString& aText ) { m_text = aText; - m_shown_text = UnescapeString( aText ); - m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) ); + cacheShownText(); } @@ -178,13 +170,27 @@ int EDA_TEXT::GetEffectiveTextPenWidth( int aDefaultWidth ) const bool EDA_TEXT::Replace( const wxFindReplaceData& aSearchData ) { bool retval = EDA_ITEM::Replace( aSearchData, m_text ); - m_shown_text = UnescapeString( m_text ); - m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) ); + cacheShownText(); return retval; } +void EDA_TEXT::cacheShownText() +{ + if( m_text.IsEmpty() || m_text == wxT( "~" ) ) // ~ is legacy empty-string token + { + m_shown_text = wxEmptyString; + m_shown_text_has_text_var_refs = false; + } + else + { + m_shown_text = UnescapeString( m_text ); + m_shown_text_has_text_var_refs = m_shown_text.Contains( wxT( "${" ) ); + } +} + + int EDA_TEXT::LenSize( const wxString& aLine, int aThickness ) const { basic_gal.SetFontItalic( IsItalic() ); diff --git a/include/eda_text.h b/include/eda_text.h index 628dfa0818..c5170dc61e 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -374,6 +374,8 @@ public: virtual double GetDrawRotation() const; private: + void cacheShownText(); + /** * Print each line of this EDA_TEXT.. *