Add reset text attributes function to GAL - use for arc tool

Independent drawing functions (that don't expect any particular state to
be set up fo them) on the GAL need to reset the GAL properties they
use. This adds GAL::ResetTextAttributes() to make this easier.

This is important, as failing to reset mirroring can cause asserts in
OpenGL.

This is used in the Ruler tool (which previously did it one attribute at
a time) and also the Arc layout assistant, which previously failed to
reset mirroring.

Also reset on GAL construction, as these members appear to be
uninitialised.
This commit is contained in:
John Beard 2017-03-30 15:44:38 +08:00 committed by Maciej Suminski
parent 9b876d9d98
commit c3ff34e0df
4 changed files with 30 additions and 3 deletions

View File

@ -70,6 +70,9 @@ GAL::GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions ) :
forceDisplayCursor = false;
SetCursorEnabled( false );
// Initialize text properties
ResetTextAttributes();
strokeFont.LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize );
// subscribe for settings updates
@ -147,6 +150,21 @@ void GAL::SetTextAttributes( const EDA_TEXT* aText )
}
void GAL::ResetTextAttributes()
{
// Tiny but non-zero - this will always need setting
// there is no built-in default
SetGlyphSize( { 1.0, 1.0 } );
SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER );
SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );
SetFontBold( false );
SetFontItalic( false );
SetTextMirrored( false );
}
VECTOR2D GAL::GetTextLineSize( const UTF8& aText ) const
{
// Compute the X and Y size of a given text.

View File

@ -131,6 +131,8 @@ void ARC_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
gal.SetIsStroke( true );
gal.SetIsFill( true );
gal.ResetTextAttributes();
// constant text size on screen
SetConstantGlyphHeight( gal, 12.0 );

View File

@ -238,9 +238,8 @@ void RULER_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
gal.SetIsStroke( true );
gal.SetIsFill( false );
gal.SetStrokeColor( PreviewOverlayDefaultColor() );
gal.SetFontBold( false );
gal.SetFontItalic( false );
gal.SetTextMirrored( false );
gal.ResetTextAttributes();
// draw the main line from the origin to cursor
gal.DrawLine( origin, end );

View File

@ -361,6 +361,14 @@ public:
*/
virtual void SetTextAttributes( const EDA_TEXT* aText );
/**
* Reset text attributes to default styling
*
* Normally, custom attributes will be set individually after this,
* otherwise you can use SetTextAttributes()
*/
void ResetTextAttributes();
/**
* @brief Set the font glyph size.
*