From c3ff34e0df89d93f6fbe16a64acbf298dd21883d Mon Sep 17 00:00:00 2001 From: John Beard Date: Thu, 30 Mar 2017 15:44:38 +0800 Subject: [PATCH] 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. --- common/gal/graphics_abstraction_layer.cpp | 18 ++++++++++++++++++ common/preview_items/arc_assistant.cpp | 2 ++ common/preview_items/ruler_item.cpp | 5 ++--- include/gal/graphics_abstraction_layer.h | 8 ++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index 24f6fe7e7f..af3d04b607 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -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. diff --git a/common/preview_items/arc_assistant.cpp b/common/preview_items/arc_assistant.cpp index 1e3504b7df..43739a6665 100644 --- a/common/preview_items/arc_assistant.cpp +++ b/common/preview_items/arc_assistant.cpp @@ -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 ); diff --git a/common/preview_items/ruler_item.cpp b/common/preview_items/ruler_item.cpp index 234db1a768..76f3c3bd27 100644 --- a/common/preview_items/ruler_item.cpp +++ b/common/preview_items/ruler_item.cpp @@ -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 ); diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 9dced85aa2..00e5bc94ec 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -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. *