Commit 45cd2756 authored by Orson 's avatar Orson Committed by Dick Hollenbeck

merge lp:~cern-kicad/kicad/bugfix_1256302 from Orson

parents 7985a4b1 a2f6faf1
This diff is collapsed.
...@@ -191,7 +191,7 @@ void WORKSHEET_VIEWITEM::draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const ...@@ -191,7 +191,7 @@ void WORKSHEET_VIEWITEM::draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const
aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) ); aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) );
aGal->SetLineWidth( aItem->GetThickness() ); aGal->SetLineWidth( aItem->GetThickness() );
aGal->SetTextAttributes( aItem ); aGal->SetTextAttributes( aItem );
aGal->StrokeText( std::string( aItem->GetText().mb_str() ), position, 0.0 ); aGal->StrokeText( std::wstring( aItem->GetText().wc_str() ), position, 0.0 );
} }
......
...@@ -277,7 +277,7 @@ public: ...@@ -277,7 +277,7 @@ public:
* @param aPosition is the text position in world coordinates. * @param aPosition is the text position in world coordinates.
* @param aRotationAngle is the text rotation angle. * @param aRotationAngle is the text rotation angle.
*/ */
inline virtual void StrokeText( const std::string& aText, const VECTOR2D& aPosition, inline virtual void StrokeText( const wxString& aText, const VECTOR2D& aPosition,
double aRotationAngle ) double aRotationAngle )
{ {
strokeFont.Draw( aText, aPosition, aRotationAngle ); strokeFont.Draw( aText, aPosition, aRotationAngle );
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* *
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
* Copyright (C) 2012 Kicad Developers, see change_log.txt for contributors. * Copyright (C) 2012 Kicad Developers, see change_log.txt for contributors.
* Copyright (C) 2013 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* Stroke font class * Stroke font class
* *
...@@ -39,7 +41,7 @@ namespace KIGFX ...@@ -39,7 +41,7 @@ namespace KIGFX
class GAL; class GAL;
typedef std::deque< std::deque<VECTOR2D> > GLYPH; typedef std::deque< std::deque<VECTOR2D> > GLYPH;
typedef std::deque<GLYPH> GLYPH_LIST; typedef std::vector<GLYPH> GLYPH_LIST;
/** /**
* @brief Class STROKE_FONT implements stroke font drawing. * @brief Class STROKE_FONT implements stroke font drawing.
...@@ -52,11 +54,6 @@ public: ...@@ -52,11 +54,6 @@ public:
/// Constructor /// Constructor
STROKE_FONT( GAL* aGal ); STROKE_FONT( GAL* aGal );
/// Destructor
~STROKE_FONT();
// TODO Load font from a text file
/** /**
* @brief Load the new stroke font. * @brief Load the new stroke font.
* *
...@@ -73,17 +70,7 @@ public: ...@@ -73,17 +70,7 @@ public:
* @param aPosition is the text position in world coordinates. * @param aPosition is the text position in world coordinates.
* @param aRotationAngle is the text rotation angle. * @param aRotationAngle is the text rotation angle.
*/ */
void Draw( std::string aText, const VECTOR2D& aPosition, double aRotationAngle ); void Draw( const wxString& aText, const VECTOR2D& aPosition, double aRotationAngle );
/**
* @brief Set the scale factor of the font for the glyph size.
*
* @param aScaleFactor is the scale factor of the font.
*/
inline void SetScaleFactor( const double aScaleFactor )
{
m_scaleFactor = aScaleFactor;
}
/** /**
* @brief Set the glyph size. * @brief Set the glyph size.
...@@ -158,13 +145,19 @@ public: ...@@ -158,13 +145,19 @@ public:
private: private:
GAL* m_gal; ///< Pointer to the GAL GAL* m_gal; ///< Pointer to the GAL
GLYPH_LIST m_glyphs; ///< Glyph list GLYPH_LIST m_glyphs; ///< Glyph list
std::deque<BOX2D> m_glyphBoundingBoxes; ///< Bounding boxes of the glyphs std::vector<BOX2D> m_glyphBoundingBoxes; ///< Bounding boxes of the glyphs
double m_scaleFactor; ///< Scale factor for the glyph
VECTOR2D m_glyphSize; ///< Size of the glyphs VECTOR2D m_glyphSize; ///< Size of the glyphs
EDA_TEXT_HJUSTIFY_T m_horizontalJustify; ///< Horizontal justification EDA_TEXT_HJUSTIFY_T m_horizontalJustify; ///< Horizontal justification
EDA_TEXT_VJUSTIFY_T m_verticalJustify; ///< Vertical justification EDA_TEXT_VJUSTIFY_T m_verticalJustify; ///< Vertical justification
bool m_bold, m_italic, m_mirrored, m_overbar; ///< Properties of text bool m_bold, m_italic, m_mirrored, m_overbar; ///< Properties of text
/**
* @brief Returns a single line height using current settings.
*
* @return The line height.
*/
int getInterline() const;
/** /**
* @brief Compute the bounding box of a given glyph. * @brief Compute the bounding box of a given glyph.
* *
...@@ -174,15 +167,50 @@ private: ...@@ -174,15 +167,50 @@ private:
*/ */
BOX2D computeBoundingBox( const GLYPH& aGlyph, const VECTOR2D& aGlyphBoundingX ) const; BOX2D computeBoundingBox( const GLYPH& aGlyph, const VECTOR2D& aGlyphBoundingX ) const;
/**
* @brief Draws a single line of text. Multiline texts should be split before using the
* function.
*
* @param aText is the text to be drawn.
*/
void drawSingleLineText( const wxString& aText );
/** /**
* @brief Compute the size of a given text. * @brief Compute the size of a given text.
* *
* @param aText is the text string. * @param aText is the text string.
* @return is the text size. * @return is the text size.
*/ */
VECTOR2D computeTextSize( const std::string& aText ) const; VECTOR2D computeTextSize( const wxString& aText ) const;
/**
* @brief Returns number of lines for a given text.
*
* @param aText is the text to be checked.
* @return Number of lines of aText.
*/
unsigned int linesCount( const wxString& aText ) const
{
wxString::const_iterator it, itEnd;
unsigned int lines = 1;
for( it = aText.begin(), itEnd = aText.end(); it != itEnd; ++it )
{
if( *it == '\n' )
++lines;
}
return lines;
}
///> Factor that determines relative height of overbar.
static const double OVERBAR_HEIGHT;
///> Factor that determines relative line width for bold text.
static const double BOLD_FACTOR;
static const double LINE_HEIGHT_RATIO; ///> Scale factor for the glyph
static const double HERSHEY_SCALE;
}; };
} // namespace KIGFX } // namespace KIGFX
......
...@@ -280,7 +280,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) ...@@ -280,7 +280,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
if( !net ) if( !net )
return; return;
std::string netName = std::string( net->GetShortNetname().mb_str() ); std::wstring netName = std::wstring( net->GetShortNetname().wc_str() );
VECTOR2D textPosition = start + line / 2.0; // center of the track VECTOR2D textPosition = start + line / 2.0; // center of the track
double textOrientation = -atan( line.y / line.x ); double textOrientation = -atan( line.y / line.x );
double textSize = std::min( static_cast<double>( width ), length / netName.length() ); double textSize = std::min( static_cast<double>( width ), length / netName.length() );
...@@ -456,7 +456,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) ...@@ -456,7 +456,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
VECTOR2D namesize( tsize, tsize ); VECTOR2D namesize( tsize, tsize );
m_gal->SetGlyphSize( namesize ); m_gal->SetGlyphSize( namesize );
m_gal->SetLineWidth( namesize.x / 12.0 ); m_gal->SetLineWidth( namesize.x / 12.0 );
m_gal->StrokeText( std::string( aPad->GetShortNetname().mb_str() ), m_gal->StrokeText( std::wstring( aPad->GetShortNetname().wc_str() ),
textpos, 0.0 ); textpos, 0.0 );
} }
...@@ -474,8 +474,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) ...@@ -474,8 +474,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
m_gal->SetGlyphSize( numsize ); m_gal->SetGlyphSize( numsize );
m_gal->SetLineWidth( numsize.x / 12.0 ); m_gal->SetLineWidth( numsize.x / 12.0 );
m_gal->StrokeText( std::string( aPad->GetPadName().mb_str() ), m_gal->StrokeText( std::wstring( aPad->GetPadName().wc_str() ), textpos, 0.0 );
textpos, 0.0 );
} }
m_gal->Restore(); m_gal->Restore();
...@@ -720,7 +719,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer ) ...@@ -720,7 +719,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer )
m_gal->SetStrokeColor( strokeColor ); m_gal->SetStrokeColor( strokeColor );
m_gal->SetLineWidth( aText->GetThickness() ); m_gal->SetLineWidth( aText->GetThickness() );
m_gal->SetTextAttributes( aText ); m_gal->SetTextAttributes( aText );
m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation ); m_gal->StrokeText( aText->GetText(), position, orientation );
} }
...@@ -736,7 +735,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) ...@@ -736,7 +735,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
m_gal->SetStrokeColor( strokeColor ); m_gal->SetStrokeColor( strokeColor );
m_gal->SetLineWidth( aText->GetThickness() ); m_gal->SetLineWidth( aText->GetThickness() );
m_gal->SetTextAttributes( aText ); m_gal->SetTextAttributes( aText );
m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation ); m_gal->StrokeText( aText->GetText(), position, orientation );
} }
...@@ -836,7 +835,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer ) ...@@ -836,7 +835,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer )
m_gal->SetLineWidth( text.GetThickness() ); m_gal->SetLineWidth( text.GetThickness() );
m_gal->SetTextAttributes( &text ); m_gal->SetTextAttributes( &text );
m_gal->StrokeText( std::string( text.GetText().mb_str() ), position, orientation ); m_gal->StrokeText( std::wstring( text.GetText().wc_str() ), position, orientation );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment