EasyEDA Std import: support multiline text on PCB.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17171


(cherry picked from commit 0dab086f0c)
This commit is contained in:
Alex Shvartzkop 2024-02-29 03:53:55 +03:00 committed by dsa-t
parent 5f4c7a52e4
commit 39a0a81832
4 changed files with 58 additions and 48 deletions

View File

@ -27,6 +27,7 @@
#include <bezier_curves.h>
#include <ki_exception.h>
#include <wx/translation.h>
#include <eda_text.h>
double EASYEDA_PARSER_BASE::Convert( const wxString& aValue )
@ -66,6 +67,49 @@ double EASYEDA_PARSER_BASE::RelPosY( const wxString& aValue )
}
void EASYEDA_PARSER_BASE::TransformTextToBaseline( EDA_TEXT* textItem,
const wxString& baselineAlign, bool invertY )
{
int upOffset = 0;
if( baselineAlign == wxS( "" ) || baselineAlign == wxS( "auto" )
|| baselineAlign == wxS( "use-script" ) || baselineAlign == wxS( "no-change" )
|| baselineAlign == wxS( "reset-size" ) || baselineAlign == wxS( "alphabetic" )
|| baselineAlign == wxS( "inherit" ) )
{
upOffset = textItem->GetTextSize().y;
}
else if( baselineAlign == wxS( "ideographic" ) || baselineAlign == wxS( "text-after-edge" ) )
{
upOffset = textItem->GetTextSize().y * 1.2;
}
else if( baselineAlign == wxS( "central" ) )
{
upOffset = textItem->GetTextSize().y * 0.5;
}
else if( baselineAlign == wxS( "middle" ) )
{
upOffset = textItem->GetTextSize().y * 0.6;
}
else if( baselineAlign == wxS( "mathematical" ) )
{
upOffset = textItem->GetTextSize().y * 0.1;
}
else if( baselineAlign == wxS( "hanging" ) || baselineAlign == wxS( "text-before-edge" ) )
{
upOffset = 0;
}
VECTOR2I offset( 0, -upOffset );
RotatePoint( offset, textItem->GetTextAngle() );
if( invertY )
offset.y = -offset.y;
textItem->SetTextPos( textItem->GetTextPos() + offset );
}
std::vector<SHAPE_LINE_CHAIN>
EASYEDA_PARSER_BASE::ParseLineChains( const wxString& data, int aArcMinSegLen, bool aForceClosed )
{

View File

@ -29,6 +29,8 @@
#include <math/vector2d.h>
#include <wx/string.h>
class EDA_TEXT;
class EASYEDA_PARSER_BASE
{
public:
@ -58,7 +60,9 @@ public:
return ScalePos( aVec - m_relOrigin );
}
std::vector<SHAPE_LINE_CHAIN> ParseLineChains( const wxString& aData, int aArcMinSegLen,
void TransformTextToBaseline( EDA_TEXT* textItem, const wxString& baselineAlign, bool invertY );
std::vector<SHAPE_LINE_CHAIN> ParseLineChains( const wxString& aData, int aArcMinSegLen,
bool aForceClosed );
protected:

View File

@ -175,48 +175,6 @@ static ELECTRICAL_PINTYPE ConvertElecType( const wxString& aType )
}
static void TransformToBaseline( EDA_TEXT* textItem, const wxString& baselineAlign, bool invertY )
{
int upOffset = 0;
if( baselineAlign == wxS( "" ) || baselineAlign == wxS( "auto" )
|| baselineAlign == wxS( "use-script" ) || baselineAlign == wxS( "no-change" )
|| baselineAlign == wxS( "reset-size" ) || baselineAlign == wxS( "alphabetic" )
|| baselineAlign == wxS( "inherit" ) )
{
upOffset = textItem->GetTextSize().y;
}
else if( baselineAlign == wxS( "ideographic" ) || baselineAlign == wxS( "text-after-edge" ) )
{
upOffset = textItem->GetTextSize().y * 1.2;
}
else if( baselineAlign == wxS( "central" ) )
{
upOffset = textItem->GetTextSize().y * 0.5;
}
else if( baselineAlign == wxS( "middle" ) )
{
upOffset = textItem->GetTextSize().y * 0.6;
}
else if( baselineAlign == wxS( "mathematical" ) )
{
upOffset = textItem->GetTextSize().y * 0.1;
}
else if( baselineAlign == wxS( "hanging" ) || baselineAlign == wxS( "text-before-edge" ) )
{
upOffset = 0;
}
VECTOR2I offset( 0, -upOffset );
RotatePoint( offset, textItem->GetTextAngle() );
if( invertY )
offset.y = -offset.y;
textItem->SetTextPos( textItem->GetTextPos() + offset );
}
VECTOR2I HelperGeneratePowerPortGraphics( LIB_SYMBOL* aKsymbol, EASYEDA::POWER_FLAG_STYLE aStyle,
REPORTER* aReporter )
{
@ -936,7 +894,7 @@ void SCH_EASYEDA_PARSER::ParseSymbolShapes( LIB_SYMBOL* aSymbol
textItem->SetTextSize( VECTOR2I( ktextSize, ktextSize ) );
TransformToBaseline( textItem, baselineAlign, true );
TransformTextToBaseline( textItem, baselineAlign, true );
if( added )
aSymbol->AddDrawItem( dynamic_cast<LIB_ITEM*>( textItem ) );
@ -1299,7 +1257,7 @@ void SCH_EASYEDA_PARSER::ParseSchematic( SCHEMATIC* aSchematic, SCH_SHEET* aRoot
valField->SetTextSize( VECTOR2I( ktextSize, ktextSize ) );
//TransformToBaseline( valField, wxS( "" ), true );
//TransformTextToBaseline( valField, wxS( "" ), true );
createdItems.push_back( std::move( schSym ) );
}
@ -1418,7 +1376,7 @@ void SCH_EASYEDA_PARSER::ParseSchematic( SCHEMATIC* aSchematic, SCH_SHEET* aRoot
textItem->SetTextSize( VECTOR2I( ktextSize, ktextSize ) );
TransformToBaseline( textItem.get(), baselineAlign, false );
TransformTextToBaseline( textItem.get(), baselineAlign, false );
createdItems.push_back( std::move( textItem ) );
}

View File

@ -816,7 +816,7 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
text->SetTextAngleDegrees( rot );
text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
PCB_LAYER_ID layer = LayerToKi( arr[7] );
text->SetLayer( layer );
@ -827,7 +827,9 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
double height = ConvertSize( arr[9] ) * 0.8;
text->SetTextSize( VECTOR2I( height, height ) );
text->SetText( UnescapeHTML( arr[10] ) );
wxString textStr = arr[10];
textStr.Replace( wxS( "\\n" ), wxS( "\n" ) );
text->SetText( UnescapeHTML( textStr ) );
//arr[11] // Geometry data
@ -837,6 +839,8 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
if( !font.IsEmpty() )
text->SetFont( KIFONT::FONT::GetFont( font ) );
TransformTextToBaseline( text, wxEmptyString, false );
if( add )
aContainer->Add( text, ADD_MODE::APPEND );
}