From 36239806112e3f866c528a504e61a36e3269fa02 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 4 Dec 2018 20:01:47 +0100 Subject: [PATCH] DXF importer: fix incorrect line thickness of imported texts. --- pcbnew/import_gfx/dxf_import_plugin.cpp | 11 +++++++---- pcbnew/import_gfx/graphics_importer.h | 2 +- pcbnew/import_gfx/graphics_importer_buffer.cpp | 6 +++--- pcbnew/import_gfx/graphics_importer_buffer.h | 11 ++++++----- pcbnew/import_gfx/graphics_importer_pcbnew.cpp | 4 ++-- pcbnew/import_gfx/graphics_importer_pcbnew.h | 2 +- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pcbnew/import_gfx/dxf_import_plugin.cpp b/pcbnew/import_gfx/dxf_import_plugin.cpp index 3badead7ac..086f4f1de5 100644 --- a/pcbnew/import_gfx/dxf_import_plugin.cpp +++ b/pcbnew/import_gfx/dxf_import_plugin.cpp @@ -361,7 +361,8 @@ void DXF_IMPORT_PLUGIN::addText( const DL_TextData& aData ) double textHeight = mapDim( aData.height ); // The 0.9 factor gives a better height/width ratio with our font double charWidth = textHeight * 0.9; - double textWidth = charWidth * text.length(); // Rough approximation + double textWidth = charWidth * text.length(); // Rough approximation + double textThickness = textHeight/8.0; // Use a reasonable line thickness for this text VECTOR2D bottomLeft(0.0, 0.0); VECTOR2D bottomRight(0.0, 0.0); @@ -447,7 +448,7 @@ void DXF_IMPORT_PLUGIN::addText( const DL_TextData& aData ) double cosine = cos(angleInRads); double sine = sin(angleInRads); - m_internalImporter.AddText( refPoint, text, textHeight, charWidth, angle, + m_internalImporter.AddText( refPoint, text, textHeight, charWidth, textThickness, angle, hJustify, vJustify ); // Calculate the boundary box and update the image limits: @@ -484,7 +485,8 @@ void DXF_IMPORT_PLUGIN::addMText( const DL_MTextData& aData ) double textHeight = mapDim( aData.height ); // The 0.9 factor gives a better height/width ratio with our font double charWidth = textHeight * 0.9; - double textWidth = charWidth * text.length(); // Rough approximation + double textWidth = charWidth * text.length(); // Rough approximation + double textThickness = textHeight/8.0; // Use a reasonable line thickness for this text VECTOR2D bottomLeft(0.0, 0.0); VECTOR2D bottomRight(0.0, 0.0); @@ -599,7 +601,8 @@ void DXF_IMPORT_PLUGIN::addMText( const DL_MTextData& aData ) double cosine = cos(angleInRads); double sine = sin(angleInRads); - m_internalImporter.AddText( textpos, text, textHeight, charWidth, angle, hJustify, vJustify ); + m_internalImporter.AddText( textpos, text, textHeight, charWidth, + textThickness, angle, hJustify, vJustify ); bottomLeft.x = bottomLeft.x * cosine - bottomLeft.y * sine; bottomLeft.y = bottomLeft.x * sine + bottomLeft.y * cosine; diff --git a/pcbnew/import_gfx/graphics_importer.h b/pcbnew/import_gfx/graphics_importer.h index b3e4ba6040..882b54667b 100644 --- a/pcbnew/import_gfx/graphics_importer.h +++ b/pcbnew/import_gfx/graphics_importer.h @@ -223,7 +223,7 @@ public: * @param aWidth is the segment thickness in mm. Use -1 for default line thickness */ virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText, - double aHeight, double aWidth, double aOrientation, + double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) = 0; /** diff --git a/pcbnew/import_gfx/graphics_importer_buffer.cpp b/pcbnew/import_gfx/graphics_importer_buffer.cpp index 068681bd05..2c5872e2fb 100644 --- a/pcbnew/import_gfx/graphics_importer_buffer.cpp +++ b/pcbnew/import_gfx/graphics_importer_buffer.cpp @@ -58,11 +58,11 @@ void GRAPHICS_IMPORTER_BUFFER::AddPolygon( const std::vector< VECTOR2D >& aVerti void GRAPHICS_IMPORTER_BUFFER::AddText( const VECTOR2D& aOrigin, const wxString& aText, - double aHeight, double aWidth, double aOrientation, + double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) { - m_shapes.push_back( make_shape< IMPORTED_TEXT >( aOrigin, aText, aHeight, aWidth, aOrientation, - aHJustify, aVJustify ) ); + m_shapes.push_back( make_shape< IMPORTED_TEXT >( aOrigin, aText, aHeight, aWidth, + aThickness, aOrientation, aHJustify, aVJustify ) ); } diff --git a/pcbnew/import_gfx/graphics_importer_buffer.h b/pcbnew/import_gfx/graphics_importer_buffer.h index abe5bc32c3..cfc5a50419 100644 --- a/pcbnew/import_gfx/graphics_importer_buffer.h +++ b/pcbnew/import_gfx/graphics_importer_buffer.h @@ -121,10 +121,10 @@ class IMPORTED_TEXT : public IMPORTED_SHAPE { public: IMPORTED_TEXT( const VECTOR2D& aOrigin, const wxString& aText, - double aHeight, double aWidth, double aOrientation, + double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) : m_origin( aOrigin ), m_text( aText ), - m_height( aHeight ), m_width( aWidth ), + m_height( aHeight ), m_width( aWidth ), m_thickness( aThickness ), m_orientation( aOrientation ), m_hJustify( aHJustify ), m_vJustify( aVJustify ) { @@ -132,8 +132,8 @@ public: void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override { - aImporter.AddText( m_origin, m_text, m_height, m_width, m_orientation, - m_hJustify, m_vJustify ); + aImporter.AddText( m_origin, m_text, m_height, m_width, + m_thickness, m_orientation, m_hJustify, m_vJustify ); } private: @@ -141,6 +141,7 @@ private: const wxString m_text; double m_height; double m_width; + double m_thickness; double m_orientation; EDA_TEXT_HJUSTIFY_T m_hJustify; EDA_TEXT_VJUSTIFY_T m_vJustify; @@ -183,7 +184,7 @@ public: void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) override; void AddText( const VECTOR2D& aOrigin, const wxString& aText, - double aHeight, double aWidth, double aOrientation, + double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) override; void AddSpline( const VECTOR2D& aStart, const VECTOR2D& BezierControl1, diff --git a/pcbnew/import_gfx/graphics_importer_pcbnew.cpp b/pcbnew/import_gfx/graphics_importer_pcbnew.cpp index 0bd273f42e..fb3378dccb 100644 --- a/pcbnew/import_gfx/graphics_importer_pcbnew.cpp +++ b/pcbnew/import_gfx/graphics_importer_pcbnew.cpp @@ -129,14 +129,14 @@ void GRAPHICS_IMPORTER_PCBNEW::AddPolygon( const std::vector< VECTOR2D >& aVerti void GRAPHICS_IMPORTER_PCBNEW::AddText( const VECTOR2D& aOrigin, const wxString& aText, - double aHeight, double aWidth, double aOrientation, + double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) { unique_ptr boardItem; EDA_TEXT* textItem; tie( boardItem, textItem ) = createText(); boardItem->SetLayer( GetLayer() ); - textItem->SetThickness( MapLineWidth( aWidth ) ); + textItem->SetThickness( MapLineWidth( aThickness ) ); textItem->SetTextPos( MapCoordinate( aOrigin ) ); textItem->SetTextAngle( aOrientation ); textItem->SetTextWidth( aWidth * ImportScalingFactor() ); diff --git a/pcbnew/import_gfx/graphics_importer_pcbnew.h b/pcbnew/import_gfx/graphics_importer_pcbnew.h index bb7ff6a3f5..1f073b5f92 100644 --- a/pcbnew/import_gfx/graphics_importer_pcbnew.h +++ b/pcbnew/import_gfx/graphics_importer_pcbnew.h @@ -67,7 +67,7 @@ public: void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) override; void AddText( const VECTOR2D& aOrigin, const wxString& aText, - double aHeight, double aWidth, double aOrientation, + double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) override; void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,