From be415dab1db5fe0621bbd930c2a7d7bdaa379c20 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 4 Jul 2013 11:37:43 +0200 Subject: [PATCH] Moved STROKE_FONT from PAINTER to GAL. --- common/gal/graphics_abstraction_layer.cpp | 16 ++++++++++-- common/gal/stroke_font.cpp | 11 --------- common/painter.cpp | 6 ----- include/gal/graphics_abstraction_layer.h | 30 ++++++++++++++++++++++- include/gal/stroke_font.h | 7 ------ include/painter.h | 5 ---- pcbnew/pcb_painter.cpp | 10 +++----- pcbnew/pcb_painter.h | 1 - 8 files changed, 47 insertions(+), 39 deletions(-) diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index f5b984e009..93ce880bf7 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -28,12 +28,12 @@ #include #include -#include using namespace KiGfx; -GAL::GAL() +GAL::GAL() : + strokeFont( this ) { // Set the default values for the internal variables SetIsFill( false ); @@ -47,6 +47,8 @@ GAL::GAL() SetCoarseGrid( 5 ); SetLineWidth( 1.0 ); SetDepthRange( VECTOR2D( -2048, 2047 ) ); + + strokeFont.LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize ); } @@ -156,3 +158,13 @@ void GAL::DrawGrid() SetStrokeColor( savedColor ); } + +void GAL::SetTextAttributes( const EDA_TEXT* aText ) +{ + strokeFont.SetGlyphSize( VECTOR2D( aText->GetSize() ) ); + strokeFont.SetHorizontalJustify( aText->GetHorizJustify() ); + strokeFont.SetVerticalJustify( aText->GetVertJustify() ); + strokeFont.SetBold( aText->IsBold() ); + strokeFont.SetItalic( aText->IsItalic() ); + strokeFont.SetMirrored( aText->IsMirrored() ); +} diff --git a/common/gal/stroke_font.cpp b/common/gal/stroke_font.cpp index 0b74a09e84..bfae39c38a 100644 --- a/common/gal/stroke_font.cpp +++ b/common/gal/stroke_font.cpp @@ -114,17 +114,6 @@ bool STROKE_FONT::LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNe } -void STROKE_FONT::LoadAttributes( const EDA_TEXT* aText ) -{ - SetGlyphSize( VECTOR2D( aText->GetSize() ) ); - SetHorizontalJustify( aText->GetHorizJustify() ); - SetVerticalJustify( aText->GetVertJustify() ); - SetBold( aText->IsBold() ); - SetItalic( aText->IsItalic() ); - SetMirrored( aText->IsMirrored() ); -} - - BOX2D STROKE_FONT::computeBoundingBox( const Glyph& aGlyph, const VECTOR2D& aGlyphBoundingX ) const { BOX2D boundingBox; diff --git a/common/painter.cpp b/common/painter.cpp index dbc53ab965..49c39e24a3 100644 --- a/common/painter.cpp +++ b/common/painter.cpp @@ -25,8 +25,6 @@ */ #include -#include -#include using namespace KiGfx; @@ -70,14 +68,11 @@ void RENDER_SETTINGS::Update() PAINTER::PAINTER( GAL* aGal ) : m_gal( aGal ), m_settings( NULL ) { - m_stroke_font = new STROKE_FONT( aGal ); - m_stroke_font->LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize ); } PAINTER::~PAINTER() { - delete m_stroke_font; delete m_settings; } @@ -85,5 +80,4 @@ PAINTER::~PAINTER() void PAINTER::SetGAL( GAL* aGal ) { m_gal = aGal; - m_stroke_font->SetGAL( aGal ); } diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 1a1e894d25..b87c7de3e1 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -33,8 +33,10 @@ #include #include -#include +#include +#include +#include namespace KiGfx { @@ -260,6 +262,29 @@ public: layerDepth = aLayerDepth; } + // ---- + // Text + // ---- + /** + * @brief Draws a vector type text using preloaded Newstroke font. + * + * @param aText is the text to be drawn. + * @param aPosition is the text position in world coordinates. + * @param aRotationAngle is the text rotation angle. + */ + inline virtual void StrokeText( const std::string& aText, const VECTOR2D& aPosition, + double aRotationAngle ) + { + strokeFont.Draw( aText, aPosition, aRotationAngle ); + } + + /** + * @brief Loads attributes of the given text (bold/italic/underline/mirrored and so on). + * + * @param aText is the text item. + */ + virtual void SetTextAttributes( const EDA_TEXT* aText ); + // -------------- // Transformation // -------------- @@ -696,6 +721,9 @@ protected: VECTOR2D cursorPosition; ///< The cursor position COLOR4D cursorColor; ///< Cursor color + /// Instance of object that stores information about how to draw texts + STROKE_FONT strokeFont; + /// Compute the scaling factor for the world->screen matrix inline void ComputeWorldScale() { diff --git a/include/gal/stroke_font.h b/include/gal/stroke_font.h index 0d394ba613..5b35730d7a 100644 --- a/include/gal/stroke_font.h +++ b/include/gal/stroke_font.h @@ -66,13 +66,6 @@ public: */ bool LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNewStrokeFontSize ); - /** - * @brief Load attributes of a given text, in order to be used during drawing. - * - * @param aText is the text string. - */ - void LoadAttributes( const EDA_TEXT* aText ); - /** * @brief Draw a string. * diff --git a/include/painter.h b/include/painter.h index 184993019f..775137dcbf 100644 --- a/include/painter.h +++ b/include/painter.h @@ -40,7 +40,6 @@ class COLORS_DESIGN_SETTINGS; namespace KiGfx { class GAL; -class STROKE_FONT; class VIEW_ITEM; /** @@ -231,10 +230,6 @@ protected: /// commands used to draw (eg. DrawLine, DrawCircle, etc.) GAL* m_gal; - /// Instance of object that stores information about how to draw texts (including different - /// font display modes [bold/italic/mirror]). - STROKE_FONT* m_stroke_font; - /// Colors and display modes settings that are going to be used when drawing items. RENDER_SETTINGS* m_settings; }; diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 1697d05442..22293d1ad9 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -38,8 +38,6 @@ #include #include #include -#include -#include using namespace KiGfx; @@ -482,8 +480,8 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText ) m_gal->SetStrokeColor( strokeColor ); m_gal->SetLineWidth( aText->GetThickness() ); - m_stroke_font->LoadAttributes( aText ); - m_stroke_font->Draw( std::string( aText->GetText().mb_str() ), position, orientation ); + m_gal->SetTextAttributes( aText ); + m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation ); } @@ -495,8 +493,8 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) m_gal->SetStrokeColor( strokeColor ); m_gal->SetLineWidth( aText->GetThickness() ); - m_stroke_font->LoadAttributes( aText ); - m_stroke_font->Draw( std::string( aText->GetText().mb_str() ), position, orientation ); + m_gal->SetTextAttributes( aText ); + m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation ); } diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index 20a5d4fe67..3e92143ba0 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -52,7 +52,6 @@ class PCB_TARGET; namespace KiGfx { class GAL; -class STROKE_FONT; /** * Class PCB_RENDER_SETTINGS