Fix stroke text size calculation and bitmap text overbar

Fixes bug 1 from https://gitlab.com/kicad/code/kicad/-/issues/8591.

Fixes a bug where no overbar would appear in bitmap text.
This commit is contained in:
Mikolaj Wielgus 2021-06-14 00:17:56 +02:00 committed by Jeff Young
parent 0527dc6fe0
commit 2af06a9d60
2 changed files with 27 additions and 12 deletions

View File

@ -1308,8 +1308,6 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition,
wxASSERT_MSG( *chIt != '\n' && *chIt != '\r', wxASSERT_MSG( *chIt != '\n' && *chIt != '\r',
wxT( "No support for multiline bitmap text yet" ) ); wxT( "No support for multiline bitmap text yet" ) );
bool wasOverbar = overbarDepth == -1;
if( *chIt == '~' && overbarDepth == -1 ) if( *chIt == '~' && overbarDepth == -1 )
{ {
UTF8::uni_iter lookahead = chIt; UTF8::uni_iter lookahead = chIt;
@ -1333,18 +1331,15 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition,
if( braceNesting == overbarDepth ) if( braceNesting == overbarDepth )
{ {
drawBitmapOverbar( overbarLength, overbarHeight );
overbarLength = 0;
overbarDepth = -1; overbarDepth = -1;
continue; continue;
} }
} }
if( wasOverbar && overbarDepth == -1 ) if( overbarDepth != -1 )
{
drawBitmapOverbar( overbarLength, overbarHeight );
overbarLength = 0;
}
if( overbarDepth >= 0 )
overbarLength += drawBitmapChar( *chIt ); overbarLength += drawBitmapChar( *chIt );
else else
drawBitmapChar( *chIt ); drawBitmapChar( *chIt );
@ -1353,7 +1348,7 @@ void OPENGL_GAL::BitmapText( const wxString& aText, const VECTOR2D& aPosition,
// Handle the case when overbar is active till the end of the drawn text // Handle the case when overbar is active till the end of the drawn text
m_currentManager->Translate( 0, commonOffset, 0 ); m_currentManager->Translate( 0, commonOffset, 0 );
if( overbarDepth >= 0 && overbarLength > 0 ) if( overbarDepth != -1 && overbarLength > 0 )
drawBitmapOverbar( overbarLength, overbarHeight ); drawBitmapOverbar( overbarLength, overbarHeight );
Restore(); Restore();

View File

@ -540,6 +540,7 @@ VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits( const UTF8& aText, const VECT
double maxX = 0.0, curX = 0.0; double maxX = 0.0, curX = 0.0;
double curScale = 1.0; double curScale = 1.0;
int overbarDepth = -1;
int superSubDepth = -1; int superSubDepth = -1;
int braceNesting = 0; int braceNesting = 0;
@ -565,18 +566,31 @@ VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits( const UTF8& aText, const VECT
} }
else if( (*chIt == '^' || *chIt == '_') && superSubDepth == -1 ) else if( (*chIt == '^' || *chIt == '_') && superSubDepth == -1 )
{ {
auto lookahead = chIt; UTF8::uni_iter lookahead = chIt;
if( ++lookahead != end && *lookahead == '{' ) if( ++lookahead != end && *lookahead == '{' )
{ {
// process superscript // Process superscript
chIt = lookahead; chIt = lookahead;
superSubDepth = braceNesting; superSubDepth = braceNesting;
braceNesting++;
curScale = 0.8; curScale = 0.8;
continue; continue;
} }
} }
else if( *chIt == '~' && overbarDepth == -1 )
{
UTF8::uni_iter lookahead = chIt;
if( ++lookahead != end && *lookahead == '{' )
{
chIt = lookahead;
overbarDepth = braceNesting;
braceNesting++;
continue;
}
}
else if( *chIt == '{' ) else if( *chIt == '{' )
{ {
braceNesting++; braceNesting++;
@ -586,6 +600,12 @@ VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits( const UTF8& aText, const VECT
if( braceNesting > 0 ) if( braceNesting > 0 )
braceNesting--; braceNesting--;
if( braceNesting == overbarDepth )
{
overbarDepth = -1;
continue;
}
if( braceNesting == superSubDepth ) if( braceNesting == superSubDepth )
{ {
superSubDepth = -1; superSubDepth = -1;