From 7678983e38f93c42fccef3a41b97d8e263149f49 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 3 Dec 2013 11:00:52 +0100 Subject: [PATCH] Fixed non ASCII characters drawing using GAL. --- common/gal/stroke_font.cpp | 14 +++++++------- common/worksheet_viewitem.cpp | 2 +- include/gal/graphics_abstraction_layer.h | 2 +- include/gal/stroke_font.h | 4 ++-- pcbnew/pcb_painter.cpp | 13 ++++++------- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/common/gal/stroke_font.cpp b/common/gal/stroke_font.cpp index 2ec1b43a0d..bf4b7a09bc 100644 --- a/common/gal/stroke_font.cpp +++ b/common/gal/stroke_font.cpp @@ -142,7 +142,7 @@ BOX2D STROKE_FONT::computeBoundingBox( const GLYPH& aGLYPH, const VECTOR2D& aGLY } -void STROKE_FONT::Draw( std::string aText, const VECTOR2D& aPosition, double aRotationAngle ) +void STROKE_FONT::Draw( std::wstring aText, const VECTOR2D& aPosition, double aRotationAngle ) { // By default overbar is turned off m_overbar = false; @@ -156,7 +156,7 @@ void STROKE_FONT::Draw( std::string aText, const VECTOR2D& aPosition, double aRo // Split multiline strings into separate ones and draw them line by line size_t newlinePos = aText.find( '\n' ); - if( newlinePos != std::string::npos ) + if( newlinePos != std::wstring::npos ) { VECTOR2D nextlinePosition = VECTOR2D( 0.0, m_glyphSize.y * LINE_HEIGHT_RATIO ); @@ -233,7 +233,7 @@ void STROKE_FONT::Draw( std::string aText, const VECTOR2D& aPosition, double aRo m_gal->SetLineWidth( m_gal->GetLineWidth() * 1.3 ); } - for( std::string::const_iterator chIt = aText.begin(); chIt != aText.end(); chIt++ ) + for( std::wstring::const_iterator chIt = aText.begin(); chIt != aText.end(); chIt++ ) { if( *chIt == '~' ) { @@ -244,7 +244,7 @@ void STROKE_FONT::Draw( std::string aText, const VECTOR2D& aPosition, double aRo GLYPH_LIST::iterator glyphIt = m_glyphs.begin(); std::deque::iterator bbIt = m_glyphBoundingBoxes.begin(); - unsigned dd = (unsigned) ((unsigned char) *chIt ) - (unsigned) ' '; + unsigned dd = *chIt - ' '; if( dd >= m_glyphBoundingBoxes.size() ) dd = '?' - ' '; @@ -292,17 +292,17 @@ void STROKE_FONT::Draw( std::string aText, const VECTOR2D& aPosition, double aRo } -VECTOR2D STROKE_FONT::computeTextSize( const std::string& aText ) const +VECTOR2D STROKE_FONT::computeTextSize( const std::wstring& aText ) const { VECTOR2D result = VECTOR2D( 0.0, m_glyphSize.y ); - for( std::string::const_iterator chIt = aText.begin(); chIt != aText.end(); chIt++ ) + for( std::wstring::const_iterator chIt = aText.begin(); chIt != aText.end(); chIt++ ) { if( *chIt == '~' ) continue; std::deque::const_iterator bbIt = m_glyphBoundingBoxes.begin(); - unsigned dd = (unsigned) ((unsigned char)*chIt) - (unsigned) ' '; + unsigned dd = *chIt - ' '; if( dd >= m_glyphBoundingBoxes.size() ) dd = '?' - ' '; diff --git a/common/worksheet_viewitem.cpp b/common/worksheet_viewitem.cpp index 5ad38bc46a..7ecf6de8d7 100644 --- a/common/worksheet_viewitem.cpp +++ b/common/worksheet_viewitem.cpp @@ -191,7 +191,7 @@ void WORKSHEET_VIEWITEM::draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) ); aGal->SetLineWidth( aItem->GetThickness() ); 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 ); } diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index f374979531..e5f35eb191 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -277,7 +277,7 @@ public: * @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, + inline virtual void StrokeText( const std::wstring& aText, const VECTOR2D& aPosition, double aRotationAngle ) { strokeFont.Draw( aText, aPosition, aRotationAngle ); diff --git a/include/gal/stroke_font.h b/include/gal/stroke_font.h index 50882ee142..5ea5dc4fea 100644 --- a/include/gal/stroke_font.h +++ b/include/gal/stroke_font.h @@ -73,7 +73,7 @@ public: * @param aPosition is the text position in world coordinates. * @param aRotationAngle is the text rotation angle. */ - void Draw( std::string aText, const VECTOR2D& aPosition, double aRotationAngle ); + void Draw( std::wstring aText, const VECTOR2D& aPosition, double aRotationAngle ); /** * @brief Set the scale factor of the font for the glyph size. @@ -180,7 +180,7 @@ private: * @param aText is the text string. * @return is the text size. */ - VECTOR2D computeTextSize( const std::string& aText ) const; + VECTOR2D computeTextSize( const std::wstring& aText ) const; static const double LINE_HEIGHT_RATIO; }; diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 692f73f5e7..5c06adbb85 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -280,7 +280,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) if( !net ) 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 double textOrientation = -atan( line.y / line.x ); double textSize = std::min( static_cast( width ), length / netName.length() ); @@ -456,7 +456,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) VECTOR2D namesize( tsize, tsize ); m_gal->SetGlyphSize( namesize ); 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 ); } @@ -474,8 +474,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) m_gal->SetGlyphSize( numsize ); m_gal->SetLineWidth( numsize.x / 12.0 ); - m_gal->StrokeText( std::string( aPad->GetPadName().mb_str() ), - textpos, 0.0 ); + m_gal->StrokeText( std::wstring( aPad->GetPadName().wc_str() ), textpos, 0.0 ); } m_gal->Restore(); @@ -720,7 +719,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer ) m_gal->SetStrokeColor( strokeColor ); m_gal->SetLineWidth( aText->GetThickness() ); m_gal->SetTextAttributes( aText ); - m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation ); + m_gal->StrokeText( std::wstring( aText->GetText().wc_str() ), position, orientation ); } @@ -736,7 +735,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) m_gal->SetStrokeColor( strokeColor ); m_gal->SetLineWidth( aText->GetThickness() ); m_gal->SetTextAttributes( aText ); - m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation ); + m_gal->StrokeText( std::wstring( aText->GetText().wc_str() ), position, orientation ); } @@ -836,7 +835,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer ) m_gal->SetLineWidth( text.GetThickness() ); 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 ); }