From 406e7acaac03730e4b692ba945f14c9eb7a5a2a7 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 9 Feb 2024 12:37:01 +0000 Subject: [PATCH] Handle nested text variable references in title block. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16919 (cherry picked from commit 33d93b79a318bded2cdf71504bc26f43254898d6) --- common/drawing_sheet/ds_painter.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/common/drawing_sheet/ds_painter.cpp b/common/drawing_sheet/ds_painter.cpp index 4994687c55..ffb248cbdc 100644 --- a/common/drawing_sheet/ds_painter.cpp +++ b/common/drawing_sheet/ds_painter.cpp @@ -113,7 +113,7 @@ void DS_DRAW_ITEM_LIST::GetTextVars( wxArrayString* aVars ) wxString DS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase ) { std::function wsResolver = - [ this ]( wxString* token ) -> bool + [&]( wxString* token ) -> bool { bool tokenUpdated = false; @@ -166,10 +166,24 @@ wxString DS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase ) } else if( m_titleBlock ) { - // no need for tokenUpdated; TITLE_BLOCK::TextVarResolver() does a full - // resolve if( m_titleBlock->TextVarResolver( token, m_project ) ) + { + // No need for tokenUpdated; TITLE_BLOCK::TextVarResolver() already goes + // up to the project. + // + // However, the title block may have variables in it itself, so we need + // to run the worksheet resolver again. + // + const TITLE_BLOCK* savedTitleBlock = m_titleBlock; + + m_titleBlock = nullptr; + { + *token = ExpandTextVars( *token, &wsResolver ); + } + m_titleBlock = savedTitleBlock; + return true; + } } else if( m_properties && m_properties->count( *token ) ) {