From b143ce6b0fa8c7edc96d74cfdb46b45b56f54d14 Mon Sep 17 00:00:00 2001
From: Maciej Suminski <maciej.suminski@cern.ch>
Date: Mon, 2 May 2016 15:56:12 +0200
Subject: [PATCH] Moved text settings from STROKE_FONT to GAL.

---
 common/drawtxt.cpp                        |   4 +-
 common/eda_text.cpp                       |   4 +-
 common/gal/graphics_abstraction_layer.cpp |  12 +--
 common/gal/stroke_font.cpp                |  55 +++++------
 include/gal/graphics_abstraction_layer.h  | 113 +++++++++++++++++++---
 include/gal/stroke_font.h                 |  77 +--------------
 pcbnew/pcb_painter.cpp                    |  12 +--
 7 files changed, 139 insertions(+), 138 deletions(-)

diff --git a/common/drawtxt.cpp b/common/drawtxt.cpp
index 3fbe4909e3..7ab163f8d4 100644
--- a/common/drawtxt.cpp
+++ b/common/drawtxt.cpp
@@ -87,8 +87,8 @@ int Clamp_Text_PenSize( int aPenSize, wxSize aSize, bool aBold )
 
 int GraphicTextWidth( const wxString& aText, const wxSize& aSize, bool aItalic, bool aBold )
 {
-    basic_gal.SetItalic( aItalic );
-    basic_gal.SetBold( aBold );
+    basic_gal.SetFontItalic( aItalic );
+    basic_gal.SetFontBold( aBold );
     basic_gal.SetGlyphSize( VECTOR2D( aSize ) );
 
     VECTOR2D tsize = basic_gal.GetTextLineSize( aText );
diff --git a/common/eda_text.cpp b/common/eda_text.cpp
index e48df1e92f..adf5c78ea7 100644
--- a/common/eda_text.cpp
+++ b/common/eda_text.cpp
@@ -97,8 +97,8 @@ void EDA_TEXT::SetOrientation( double aOrientation )
 
 int EDA_TEXT::LenSize( const wxString& aLine ) const
 {
-    basic_gal.SetItalic( m_Italic );
-    basic_gal.SetBold( m_Bold );
+    basic_gal.SetFontItalic( m_Italic );
+    basic_gal.SetFontBold( m_Bold );
     basic_gal.SetGlyphSize( VECTOR2D( m_Size ) );
 
     VECTOR2D tsize = basic_gal.GetTextLineSize( aLine );
diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp
index cf316ff1b9..b77ad4f83e 100644
--- a/common/gal/graphics_abstraction_layer.cpp
+++ b/common/gal/graphics_abstraction_layer.cpp
@@ -76,12 +76,12 @@ GAL::~GAL()
 
 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() );
+    SetGlyphSize( VECTOR2D( aText->GetSize() ) );
+    SetHorizontalJustify( aText->GetHorizJustify() );
+    SetVerticalJustify( aText->GetVertJustify() );
+    SetFontBold( aText->IsBold() );
+    SetFontItalic( aText->IsItalic() );
+    SetTextMirrored( aText->IsMirrored() );
 }
 
 VECTOR2D GAL::GetTextLineSize( const UTF8& aText ) const
diff --git a/common/gal/stroke_font.cpp b/common/gal/stroke_font.cpp
index c2796e672e..8359c16440 100644
--- a/common/gal/stroke_font.cpp
+++ b/common/gal/stroke_font.cpp
@@ -39,16 +39,8 @@ const double STROKE_FONT::STROKE_FONT_SCALE = 1.0 / 21.0;
 const double STROKE_FONT::ITALIC_TILT = 1.0 / 8;
 
 STROKE_FONT::STROKE_FONT( GAL* aGal ) :
-    m_gal( aGal ),
-    m_bold( false ),
-    m_italic( false ),
-    m_mirrored( false ),
-    m_overbar( false )
+    m_gal( aGal )
 {
-    // Default values
-    m_glyphSize = VECTOR2D( 10.0, 10.0 );
-    m_verticalJustify   = GR_TEXT_VJUSTIFY_BOTTOM;
-    m_horizontalJustify = GR_TEXT_HJUSTIFY_LEFT;
 }
 
 
@@ -139,7 +131,7 @@ double STROKE_FONT::GetInterline( double aGlyphHeight, double aGlyphThickness )
 
 int STROKE_FONT::getInterline() const
 {
-    return KiROUND( GetInterline( m_glyphSize.y, m_gal->GetLineWidth() ) );
+    return KiROUND( GetInterline( m_gal->GetGlyphSize().y, m_gal->GetLineWidth() ) );
 }
 
 
@@ -181,16 +173,17 @@ void STROKE_FONT::Draw( const UTF8& aText, const VECTOR2D& aPosition, double aRo
     // Single line height
     int lineHeight = getInterline( );
     int lineCount = linesCount( aText );
+    const VECTOR2D& glyphSize = m_gal->GetGlyphSize();
 
     // align the 1st line of text
-    switch( m_verticalJustify )
+    switch( m_gal->GetHorizontalJustify() )
     {
     case GR_TEXT_VJUSTIFY_TOP:
-        m_gal->Translate( VECTOR2D( 0, m_glyphSize.y ) );
+        m_gal->Translate( VECTOR2D( 0, glyphSize.y ) );
         break;
 
     case GR_TEXT_VJUSTIFY_CENTER:
-        m_gal->Translate( VECTOR2D( 0, m_glyphSize.y / 2.0 ) );
+        m_gal->Translate( VECTOR2D( 0, glyphSize.y / 2.0 ) );
         break;
 
     case GR_TEXT_VJUSTIFY_BOTTOM:
@@ -202,7 +195,7 @@ void STROKE_FONT::Draw( const UTF8& aText, const VECTOR2D& aPosition, double aRo
 
     if( lineCount > 1 )
     {
-        switch( m_verticalJustify )
+        switch( m_gal->GetVerticalJustify() )
         {
         case GR_TEXT_VJUSTIFY_TOP:
             break;
@@ -220,7 +213,7 @@ void STROKE_FONT::Draw( const UTF8& aText, const VECTOR2D& aPosition, double aRo
     m_gal->SetIsStroke( true );
     //m_gal->SetIsFill( false );
 
-    if( m_bold )
+    if( m_gal->IsFontBold() )
         m_gal->SetLineWidth( m_gal->GetLineWidth() * BOLD_FACTOR );
 
     // Split multiline strings into separate ones and draw them line by line
@@ -249,13 +242,13 @@ void STROKE_FONT::Draw( const UTF8& aText, const VECTOR2D& aPosition, double aRo
 void STROKE_FONT::drawSingleLineText( const UTF8& aText )
 {
     // By default the overbar is turned off
-    m_overbar = false;
+    bool overbar = false;
 
     double      xOffset;
-    VECTOR2D    glyphSize( m_glyphSize );
+    VECTOR2D    glyphSize( m_gal->GetGlyphSize() );
     double      overbar_italic_comp = computeOverbarVerticalPosition() * ITALIC_TILT;
 
-    if( m_mirrored )
+    if( m_gal->IsTextMirrored() )
         overbar_italic_comp = -overbar_italic_comp;
 
     // Compute the text size
@@ -272,19 +265,19 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText )
     m_gal->Save();
 
     // Adjust the text position to the given horizontal justification
-    switch( m_horizontalJustify )
+    switch( m_gal->GetHorizontalJustify() )
     {
     case GR_TEXT_HJUSTIFY_CENTER:
         m_gal->Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
         break;
 
     case GR_TEXT_HJUSTIFY_RIGHT:
-        if( !m_mirrored )
+        if( !m_gal->IsTextMirrored() )
             m_gal->Translate( VECTOR2D( -textSize.x, 0 ) );
         break;
 
     case GR_TEXT_HJUSTIFY_LEFT:
-        if( m_mirrored )
+        if( m_gal->IsTextMirrored() )
             m_gal->Translate( VECTOR2D( -textSize.x, 0 ) );
         break;
 
@@ -292,13 +285,13 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText )
         break;
     }
 
-    if( m_mirrored )
+    if( m_gal->IsTextMirrored() )
     {
         // In case of mirrored text invert the X scale of points and their X direction
         // (m_glyphSize.x) and start drawing from the position where text normally should end
         // (textSize.x)
         xOffset = textSize.x - m_gal->GetLineWidth();
-        glyphSize.x = -m_glyphSize.x;
+        glyphSize.x = -glyphSize.x;
     }
     else
     {
@@ -319,7 +312,7 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText )
                 break;
 
             if( *chIt != '~' )      // It was a single tilda, it toggles overbar
-                m_overbar = !m_overbar;
+                overbar = !overbar;
 
             // If it is a double tilda, just process the second one
         }
@@ -332,7 +325,7 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText )
         GLYPH& glyph = m_glyphs[dd];
         BOX2D& bbox  = m_glyphBoundingBoxes[dd];
 
-        if( m_overbar )
+        if( overbar )
         {
             double overbar_start_x = xOffset;
             double overbar_start_y = - computeOverbarVerticalPosition();
@@ -365,11 +358,11 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText )
             {
                 VECTOR2D pointPos( pointIt->x * glyphSize.x + xOffset, pointIt->y * glyphSize.y );
 
-                if( m_italic )
+                if( m_gal->IsFontItalic() )
                 {
                     // FIXME should be done other way - referring to the lowest Y value of point
                     // because now italic fonts are translated a bit
-                    if( m_mirrored )
+                    if( m_gal->IsTextMirrored() )
                         pointPos.x += pointPos.y * STROKE_FONT::ITALIC_TILT;
                     else
                         pointPos.x -= pointPos.y * STROKE_FONT::ITALIC_TILT;
@@ -401,13 +394,13 @@ double STROKE_FONT::computeOverbarVerticalPosition() const
 {
     // Compute the Y position of the overbar. This is the distance between
     // the text base line and the overbar axis.
-    return ComputeOverbarVerticalPosition( m_glyphSize.y, m_gal->GetLineWidth() );
+    return ComputeOverbarVerticalPosition( m_gal->GetGlyphSize().y, m_gal->GetLineWidth() );
 }
 
 
 VECTOR2D STROKE_FONT::computeTextLineSize( const UTF8& aText ) const
 {
-    return ComputeStringBoundaryLimits( aText, m_glyphSize, m_gal->GetLineWidth() );
+    return ComputeStringBoundaryLimits( aText, m_gal->GetGlyphSize(), m_gal->GetLineWidth() );
 }
 
 
@@ -415,7 +408,7 @@ VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits( const UTF8& aText, VECTOR2D a
                                         double aGlyphThickness,
                                         double* aTopLimit, double* aBottomLimit ) const
 {
-    VECTOR2D result = VECTOR2D( 0.0, m_glyphSize.y );
+    VECTOR2D result = VECTOR2D( 0.0, m_gal->GetGlyphSize().y );
     double ymax = 0.0;
     double ymin = 0.0;
 
@@ -460,7 +453,7 @@ VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits( const UTF8& aText, VECTOR2D a
     result.x += aGlyphThickness;
 
     // For italic correction, take in account italic tilt
-    if( m_italic )
+    if( m_gal->IsFontItalic() )
         result.x += result.y * STROKE_FONT::ITALIC_TILT;
 
     if( aTopLimit )
diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h
index 230a28bd48..7253f9a15a 100644
--- a/include/gal/graphics_abstraction_layer.h
+++ b/include/gal/graphics_abstraction_layer.h
@@ -314,42 +314,115 @@ public:
      */
     virtual void SetTextAttributes( const EDA_TEXT* aText );
 
-    /// @copydoc STROKE_FONT::SetGlyphSize()
+    /**
+     * @brief Set the font glyph size.
+     *
+     * @param aGlyphSize is the new font glyph size.
+     */
     inline void SetGlyphSize( const VECTOR2D aGlyphSize )
     {
-        strokeFont.SetGlyphSize( aGlyphSize );
+        textProperties.m_glyphSize = aGlyphSize;
     }
 
-    /// @copydoc STROKE_FONT::SetBold()
-    inline void SetBold( const bool aBold )
+    /**
+     * @return the current font glyph size.
+     */
+    const VECTOR2D& GetGlyphSize() const
     {
-        strokeFont.SetBold( aBold );
+        return textProperties.m_glyphSize;
     }
 
-    /// @copydoc STROKE_FONT::SetItalic()
-    inline void SetItalic( const bool aItalic )
+    /**
+     * @brief Set bold property of current font.
+     *
+     * @param aBold tells if the font should be bold or not.
+     */
+    inline void SetFontBold( const bool aBold )
     {
-        strokeFont.SetItalic( aItalic );
+        textProperties.m_bold = aBold;
     }
 
-    /// @copydoc STROKE_FONT::SetMirrored()
-    inline void SetMirrored( const bool aMirrored )
+    /**
+     * @brief Returns true if current font has 'bold' attribute enabled.
+     */
+    inline bool IsFontBold() const
     {
-        strokeFont.SetMirrored( aMirrored );
+        return textProperties.m_bold;
     }
 
-    /// @copydoc STROKE_FONT::SetHorizontalJustify()
+    /**
+     * @brief Set italic property of current font.
+     *
+     * @param aItalic tells if the font should be italic or not.
+     */
+    inline void SetFontItalic( const bool aItalic )
+    {
+        textProperties.m_italic = aItalic;
+    }
+
+    /**
+     * @brief Returns true if current font has 'italic' attribute enabled.
+     */
+    inline bool IsFontItalic() const
+    {
+        return textProperties.m_italic;
+    }
+
+    /**
+     * @brief Set a mirrored property of text.
+     *
+     * @param aMirrored tells if the text should be mirrored or not.
+     */
+    inline void SetTextMirrored( const bool aMirrored )
+    {
+        textProperties.m_mirrored = aMirrored;
+    }
+
+    /**
+     * @brief Returns true if text should displayed mirrored.
+     */
+    inline bool IsTextMirrored() const
+    {
+        return textProperties.m_mirrored;
+    }
+
+    /**
+     * @brief Set the horizontal justify for text drawing.
+     *
+     * @param aHorizontalJustify is the horizontal justify value.
+     */
     inline void SetHorizontalJustify( const EDA_TEXT_HJUSTIFY_T aHorizontalJustify )
     {
-        strokeFont.SetHorizontalJustify( aHorizontalJustify );
+        textProperties.m_horizontalJustify = aHorizontalJustify;
     }
 
-    /// @copydoc STROKE_FONT::SetVerticalJustify()
+    /**
+     * @brief Returns current text horizontal justification setting.
+     */
+    inline EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
+    {
+        return textProperties.m_horizontalJustify;
+    }
+
+    /**
+     * @brief Set the vertical justify for text drawing.
+     *
+     * @param aVerticalJustify is the vertical justify value.
+     */
     inline void SetVerticalJustify( const EDA_TEXT_VJUSTIFY_T aVerticalJustify )
     {
-        strokeFont.SetVerticalJustify( aVerticalJustify );
+        textProperties.m_verticalJustify = aVerticalJustify;
     }
 
+    /**
+     * @brief Returns current text vertical justification setting.
+     */
+    inline EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const
+    {
+        return textProperties.m_verticalJustify;
+    }
+
+
     // --------------
     // Transformation
     // --------------
@@ -929,6 +1002,16 @@ protected:
     /// Depth level on which the grid is drawn
     static const int GRID_DEPTH;
 
+private:
+    struct TEXT_PROPERTIES
+    {
+        VECTOR2D            m_glyphSize;            ///< Size of the glyphs
+        EDA_TEXT_HJUSTIFY_T m_horizontalJustify;    ///< Horizontal justification
+        EDA_TEXT_VJUSTIFY_T m_verticalJustify;      ///< Vertical justification
+        bool                m_bold;
+        bool                m_italic;
+        bool                m_mirrored;
+    } textProperties;
 };
 }    // namespace KIGFX
 
diff --git a/include/gal/stroke_font.h b/include/gal/stroke_font.h
index 67319fcc1c..4d7dc17240 100644
--- a/include/gal/stroke_font.h
+++ b/include/gal/stroke_font.h
@@ -74,74 +74,6 @@ public:
      */
     void Draw( const UTF8& aText, const VECTOR2D& aPosition, double aRotationAngle );
 
-    /**
-     * @brief Set the glyph size.
-     *
-     * @param aGlyphSize is the glyph size.
-     */
-    inline void SetGlyphSize( const VECTOR2D aGlyphSize )
-    {
-        m_glyphSize = aGlyphSize;
-    }
-
-    /**
-     * @return the current glyph size.
-     */
-    VECTOR2D GetGlyphSize() const
-    {
-        return m_glyphSize;
-    }
-
-    /**
-     * @brief Set a bold property of current font.
-     *
-     * @param aBold tells if the font should be bold or not.
-     */
-    inline void SetBold( const bool aBold )
-    {
-        m_bold = aBold;
-    }
-
-    /**
-     * @brief Set an italic property of current font.
-     *
-     * @param aItalic tells if the font should be italic or not.
-     */
-    inline void SetItalic( const bool aItalic )
-    {
-        m_italic = aItalic;
-    }
-
-    /**
-     * @brief Set a mirrored property of text.
-     *
-     * @param aMirrored tells if the text should be mirrored or not.
-     */
-    inline void SetMirrored( const bool aMirrored )
-    {
-        m_mirrored = aMirrored;
-    }
-
-    /**
-     * @brief Set the horizontal justify for text drawing.
-     *
-     * @param aHorizontalJustify is the horizontal justify value.
-     */
-    inline void SetHorizontalJustify( const EDA_TEXT_HJUSTIFY_T aHorizontalJustify )
-    {
-        m_horizontalJustify = aHorizontalJustify;
-    }
-
-    /**
-     * @brief Set the vertical justify for text drawing.
-     *
-     * @param aVerticalJustify is the vertical justify value.
-     */
-    inline void SetVerticalJustify( const EDA_TEXT_VJUSTIFY_T aVerticalJustify )
-    {
-        m_verticalJustify = aVerticalJustify;
-    }
-
     /**
      * Function SetGAL
      * Changes Graphics Abstraction Layer used for drawing items for a new one.
@@ -194,13 +126,6 @@ private:
     GAL*                m_gal;                  ///< Pointer to the GAL
     GLYPH_LIST          m_glyphs;               ///< Glyph list
     std::vector<BOX2D>  m_glyphBoundingBoxes;   ///< Bounding boxes of the glyphs
-    VECTOR2D            m_glyphSize;            ///< Size of the glyphs
-    EDA_TEXT_HJUSTIFY_T m_horizontalJustify;    ///< Horizontal justification
-    EDA_TEXT_VJUSTIFY_T m_verticalJustify;      ///< Vertical justification
-    bool                m_bold;
-    bool                m_italic;
-    bool                m_mirrored;
-    bool                m_overbar;              ///< Properties of text
 
     /**
      * @brief Compute the X and Y size of a given text. The text is expected to be
@@ -216,7 +141,7 @@ private:
      * This is the distance between the text base line and the overbar.
      * @return the relative position of the overbar axis.
      */
-    double   computeOverbarVerticalPosition() const;
+    double computeOverbarVerticalPosition() const;
 
     /**
      * @brief Returns a single line height using current settings.
diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp
index 271e8833b4..774b065a29 100644
--- a/pcbnew/pcb_painter.cpp
+++ b/pcbnew/pcb_painter.cpp
@@ -307,9 +307,9 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
                 m_gal->SetStrokeColor( labelColor );
 
             m_gal->SetLineWidth( width / 10.0 );
-            m_gal->SetBold( false );
-            m_gal->SetItalic( false );
-            m_gal->SetMirrored( false );
+            m_gal->SetFontBold( false );
+            m_gal->SetFontItalic( false );
+            m_gal->SetTextMirrored( false );
             m_gal->SetGlyphSize( VECTOR2D( textSize * 0.7, textSize * 0.7 ) );
             m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER );
             m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );
@@ -487,9 +487,9 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
             // Default font settings
             m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER );
             m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );
-            m_gal->SetBold( false );
-            m_gal->SetItalic( false );
-            m_gal->SetMirrored( false );
+            m_gal->SetFontBold( false );
+            m_gal->SetFontItalic( false );
+            m_gal->SetTextMirrored( false );
 
             // Set a proper color for the label
             const COLOR4D& color  = m_pcbSettings.GetColor( aPad, aPad->GetLayer() );