Fix a couple of edge cases in text drawing.

Don't accidentally flip the x-axis glyph size when resetting after
a sub- or superscript.

Special-case three tildes in a row.  (We could also do this for
sub- and superscript, but does anyone really need a superscript
^ or a subscript?

Fixes: lp:1851657
* https://bugs.launchpad.net/kicad/+bug/1851657

Fixes: lp:1851880
* https://bugs.launchpad.net/kicad/+bug/1851880
This commit is contained in:
Jeff Young 2019-11-09 20:15:30 +00:00
parent 114ea1f406
commit d6e0ec2f24
1 changed files with 35 additions and 10 deletions

View File

@ -237,7 +237,7 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText, int markupFlags )
{ {
double xOffset; double xOffset;
double yOffset; double yOffset;
VECTOR2D glyphSize( m_gal->GetGlyphSize() ); VECTOR2D baseGlyphSize( m_gal->GetGlyphSize() );
double overbar_italic_comp = computeOverbarVerticalPosition() * ITALIC_TILT; double overbar_italic_comp = computeOverbarVerticalPosition() * ITALIC_TILT;
if( m_gal->IsTextMirrored() ) if( m_gal->IsTextMirrored() )
@ -284,7 +284,7 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText, int markupFlags )
// (m_glyphSize.x) and start drawing from the position where text normally should end // (m_glyphSize.x) and start drawing from the position where text normally should end
// (textSize.x) // (textSize.x)
xOffset = textSize.x - m_gal->GetLineWidth(); xOffset = textSize.x - m_gal->GetLineWidth();
glyphSize.x = -glyphSize.x; baseGlyphSize.x = -baseGlyphSize.x;
} }
else else
{ {
@ -294,8 +294,9 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText, int markupFlags )
// The overbar is indented inward at the beginning of an italicized section, but // The overbar is indented inward at the beginning of an italicized section, but
// must not be indented on subsequent letters to ensure that the bar segments // must not be indented on subsequent letters to ensure that the bar segments
// overlap. // overlap.
bool last_had_overbar = false; bool last_had_overbar = false;
bool in_overbar = false; bool in_overbar = false;
VECTOR2D glyphSize = baseGlyphSize;
yOffset = 0; yOffset = 0;
@ -317,7 +318,7 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText, int markupFlags )
// Set the character to ' ' instead of the '?' for tab // Set the character to ' ' instead of the '?' for tab
dd = 0; dd = 0;
glyphSize = m_gal->GetGlyphSize(); glyphSize = baseGlyphSize;
yOffset = 0; yOffset = 0;
} }
else if( *chIt == '~' ) else if( *chIt == '~' )
@ -328,6 +329,18 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText, int markupFlags )
if( *chIt == '~' ) if( *chIt == '~' )
{ {
// double ~ is really a ~ so go ahead and process the second one // double ~ is really a ~ so go ahead and process the second one
// so what's a triple ~? It could be a real ~ followed by an overbar, or
// it could be an overbar followed by a real ~. The old algorithm did the
// later so we will too....
auto tempIt = chIt;
if( ++tempIt < end && *tempIt == '~' )
{
// eat the first two, toggle overbar, and then process the third
++chIt;
in_overbar = !in_overbar;
}
} }
else else
{ {
@ -347,8 +360,8 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText, int markupFlags )
{ {
// single ^ starts a superscript // single ^ starts a superscript
dd = *chIt - ' '; dd = *chIt - ' ';
glyphSize = m_gal->GetGlyphSize() * 0.8; glyphSize = baseGlyphSize * 0.8;
yOffset = -m_gal->GetGlyphSize().y * 0.3; yOffset = -baseGlyphSize.y * 0.3;
} }
} }
else if( *chIt == '#' && ( markupFlags & ENABLE_SUBSCRIPT_MARKUP ) ) else if( *chIt == '#' && ( markupFlags & ENABLE_SUBSCRIPT_MARKUP ) )
@ -364,14 +377,14 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText, int markupFlags )
{ {
// single _ starts a subscript // single _ starts a subscript
dd = *chIt - ' '; dd = *chIt - ' ';
glyphSize = m_gal->GetGlyphSize() * 0.8; glyphSize = baseGlyphSize * 0.8;
yOffset = m_gal->GetGlyphSize().y * 0.1; yOffset = baseGlyphSize.y * 0.1;
} }
} }
else if( *chIt == ' ' ) else if( *chIt == ' ' )
{ {
// space ends a super- or subscript // space ends a super- or subscript
glyphSize = m_gal->GetGlyphSize(); glyphSize = baseGlyphSize;
yOffset = 0; yOffset = 0;
} }
@ -502,6 +515,18 @@ VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits( const UTF8& aText, const VECT
if( *it == '~' ) if( *it == '~' )
{ {
// double ~ is really a ~ so go ahead and process the second one // double ~ is really a ~ so go ahead and process the second one
// so what's a triple ~? It could be a real ~ followed by an overbar, or
// it could be an overbar followed by a real ~. The old algorithm did the
// later so we will too....
auto tempIt = it;
if( ++tempIt < end && *tempIt == '~' )
{
// eat the first two, toggle overbar, and then process the third
++it;
in_overbar = !in_overbar;
}
} }
else else
{ {