From 7721d02afe0c81f01103565dbd61b29d3874a5f4 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Fri, 14 Nov 2014 19:19:08 +0100 Subject: [PATCH] gal/stroke_font: made text vertical alignment follow the non-GAL renderer. --- common/gal/stroke_font.cpp | 39 +++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/common/gal/stroke_font.cpp b/common/gal/stroke_font.cpp index 31441f5776..380f7e3dd8 100644 --- a/common/gal/stroke_font.cpp +++ b/common/gal/stroke_font.cpp @@ -98,7 +98,8 @@ bool STROKE_FONT::LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNe // Every coordinate description of the Hershey format has an offset, // it has to be subtracted point.x = (double) ( coordinate[0] - 'R' ) * HERSHEY_SCALE - glyphStartX; - point.y = (double) ( coordinate[1] - 'R' ) * HERSHEY_SCALE; + // -10 is here to keep GAL rendering consistent with the legacy gfx stuff + point.y = (double) ( coordinate[1] - 'R' - 10) * HERSHEY_SCALE; pointList.push_back( point ); } @@ -160,28 +161,44 @@ void STROKE_FONT::Draw( const UTF8& aText, const VECTOR2D& aPosition, double aRo m_gal->Rotate( -aRotationAngle ); // Single line height - int lineHeight = getInterline(); - - // The overall height of all lines of text - double textBlockHeight = lineHeight * ( linesCount( aText ) - 1 ); - + int lineHeight = getInterline( ); + int lineCount = linesCount( aText ); + + // align the 1st line of text switch( m_verticalJustify ) { + case GR_TEXT_VJUSTIFY_TOP: + m_gal->Translate( VECTOR2D( 0, m_glyphSize.y ) ); + break; + case GR_TEXT_VJUSTIFY_CENTER: - m_gal->Translate( VECTOR2D( 0, -textBlockHeight / 2.0 ) ); + m_gal->Translate( VECTOR2D( 0, m_glyphSize.y / 2.0 ) ); break; case GR_TEXT_VJUSTIFY_BOTTOM: - m_gal->Translate( VECTOR2D( 0, -textBlockHeight ) ); - break; - - case GR_TEXT_VJUSTIFY_TOP: break; default: break; } + if( lineCount > 1 ) + { + switch( m_verticalJustify ) + { + case GR_TEXT_VJUSTIFY_TOP: + break; + + case GR_TEXT_VJUSTIFY_CENTER: + m_gal->Translate( VECTOR2D(0, -( lineCount - 1 ) * lineHeight / 2) ); + break; + + case GR_TEXT_VJUSTIFY_BOTTOM: + m_gal->Translate( VECTOR2D(0, -( lineCount - 1 ) * lineHeight ) ); + break; + } + } + m_gal->SetIsStroke( true ); m_gal->SetIsFill( false );