Handle tabs to align text visually
This processes the \t character to place the next character aligned with the next 4-space visual column. Fixes: lp:1769193 * https://bugs.launchpad.net/kicad/+bug/1769193
This commit is contained in:
parent
b74bccbb13
commit
541d4358b8
|
@ -304,19 +304,33 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText )
|
||||||
auto processedText = ProcessOverbars( aText );
|
auto processedText = ProcessOverbars( aText );
|
||||||
const auto& text = processedText.first;
|
const auto& text = processedText.first;
|
||||||
const auto& overbars = processedText.second;
|
const auto& overbars = processedText.second;
|
||||||
int i = 0;
|
int overbar_index = 0;
|
||||||
|
|
||||||
for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
|
for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
|
||||||
{
|
{
|
||||||
int dd = *chIt - ' ';
|
int dd = *chIt - ' ';
|
||||||
|
|
||||||
|
// Handle tabs as locked to the nearest 4th column (counting in spaces)
|
||||||
|
// The choice of spaces is somewhat arbitrary but sufficient for aligning text
|
||||||
|
if( *chIt == '\t' )
|
||||||
|
{
|
||||||
|
double fourSpaces = 4.0 * glyphSize.x * m_glyphBoundingBoxes[0].GetEnd().x;
|
||||||
|
double addlSpace = fourSpaces - std::fmod( xOffset, fourSpaces );
|
||||||
|
|
||||||
|
// Add the remaining space (between 0 and 3 spaces)
|
||||||
|
xOffset += addlSpace;
|
||||||
|
|
||||||
|
// Set the character to ' ' instead of the '?' for tab
|
||||||
|
dd = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if( dd >= (int) m_glyphBoundingBoxes.size() || dd < 0 )
|
if( dd >= (int) m_glyphBoundingBoxes.size() || dd < 0 )
|
||||||
dd = '?' - ' ';
|
dd = '?' - ' ';
|
||||||
|
|
||||||
GLYPH& glyph = m_glyphs[dd];
|
GLYPH& glyph = m_glyphs[dd];
|
||||||
BOX2D& bbox = m_glyphBoundingBoxes[dd];
|
BOX2D& bbox = m_glyphBoundingBoxes[dd];
|
||||||
|
|
||||||
if( overbars[i] )
|
if( overbars[overbar_index] )
|
||||||
{
|
{
|
||||||
double overbar_start_x = xOffset;
|
double overbar_start_x = xOffset;
|
||||||
double overbar_start_y = - computeOverbarVerticalPosition();
|
double overbar_start_y = - computeOverbarVerticalPosition();
|
||||||
|
@ -368,7 +382,7 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText )
|
||||||
}
|
}
|
||||||
|
|
||||||
xOffset += glyphSize.x * bbox.GetEnd().x;
|
xOffset += glyphSize.x * bbox.GetEnd().x;
|
||||||
++i;
|
++overbar_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_gal->Restore();
|
m_gal->Restore();
|
||||||
|
|
Loading…
Reference in New Issue