mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 10:13:19 +02:00
EasyEDA Std import: support multiline text on PCB.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/17171 (cherry picked from commit 0dab086f0cd0de34eea110165c23f2ba36278646)
This commit is contained in:
parent
5f4c7a52e4
commit
39a0a81832
@ -27,6 +27,7 @@
|
|||||||
#include <bezier_curves.h>
|
#include <bezier_curves.h>
|
||||||
#include <ki_exception.h>
|
#include <ki_exception.h>
|
||||||
#include <wx/translation.h>
|
#include <wx/translation.h>
|
||||||
|
#include <eda_text.h>
|
||||||
|
|
||||||
|
|
||||||
double EASYEDA_PARSER_BASE::Convert( const wxString& aValue )
|
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>
|
std::vector<SHAPE_LINE_CHAIN>
|
||||||
EASYEDA_PARSER_BASE::ParseLineChains( const wxString& data, int aArcMinSegLen, bool aForceClosed )
|
EASYEDA_PARSER_BASE::ParseLineChains( const wxString& data, int aArcMinSegLen, bool aForceClosed )
|
||||||
{
|
{
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
#include <math/vector2d.h>
|
#include <math/vector2d.h>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
|
||||||
|
class EDA_TEXT;
|
||||||
|
|
||||||
class EASYEDA_PARSER_BASE
|
class EASYEDA_PARSER_BASE
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -58,6 +60,8 @@ public:
|
|||||||
return ScalePos( aVec - m_relOrigin );
|
return ScalePos( aVec - m_relOrigin );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TransformTextToBaseline( EDA_TEXT* textItem, const wxString& baselineAlign, bool invertY );
|
||||||
|
|
||||||
std::vector<SHAPE_LINE_CHAIN> ParseLineChains( const wxString& aData, int aArcMinSegLen,
|
std::vector<SHAPE_LINE_CHAIN> ParseLineChains( const wxString& aData, int aArcMinSegLen,
|
||||||
bool aForceClosed );
|
bool aForceClosed );
|
||||||
|
|
||||||
|
@ -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,
|
VECTOR2I HelperGeneratePowerPortGraphics( LIB_SYMBOL* aKsymbol, EASYEDA::POWER_FLAG_STYLE aStyle,
|
||||||
REPORTER* aReporter )
|
REPORTER* aReporter )
|
||||||
{
|
{
|
||||||
@ -936,7 +894,7 @@ void SCH_EASYEDA_PARSER::ParseSymbolShapes( LIB_SYMBOL* aSymbol
|
|||||||
|
|
||||||
textItem->SetTextSize( VECTOR2I( ktextSize, ktextSize ) );
|
textItem->SetTextSize( VECTOR2I( ktextSize, ktextSize ) );
|
||||||
|
|
||||||
TransformToBaseline( textItem, baselineAlign, true );
|
TransformTextToBaseline( textItem, baselineAlign, true );
|
||||||
|
|
||||||
if( added )
|
if( added )
|
||||||
aSymbol->AddDrawItem( dynamic_cast<LIB_ITEM*>( textItem ) );
|
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 ) );
|
valField->SetTextSize( VECTOR2I( ktextSize, ktextSize ) );
|
||||||
|
|
||||||
//TransformToBaseline( valField, wxS( "" ), true );
|
//TransformTextToBaseline( valField, wxS( "" ), true );
|
||||||
|
|
||||||
createdItems.push_back( std::move( schSym ) );
|
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 ) );
|
textItem->SetTextSize( VECTOR2I( ktextSize, ktextSize ) );
|
||||||
|
|
||||||
TransformToBaseline( textItem.get(), baselineAlign, false );
|
TransformTextToBaseline( textItem.get(), baselineAlign, false );
|
||||||
|
|
||||||
createdItems.push_back( std::move( textItem ) );
|
createdItems.push_back( std::move( textItem ) );
|
||||||
}
|
}
|
||||||
|
@ -816,7 +816,7 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
|
|||||||
text->SetTextAngleDegrees( rot );
|
text->SetTextAngleDegrees( rot );
|
||||||
|
|
||||||
text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
|
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] );
|
PCB_LAYER_ID layer = LayerToKi( arr[7] );
|
||||||
text->SetLayer( layer );
|
text->SetLayer( layer );
|
||||||
@ -827,7 +827,9 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
|
|||||||
double height = ConvertSize( arr[9] ) * 0.8;
|
double height = ConvertSize( arr[9] ) * 0.8;
|
||||||
text->SetTextSize( VECTOR2I( height, height ) );
|
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
|
//arr[11] // Geometry data
|
||||||
|
|
||||||
@ -837,6 +839,8 @@ void PCB_IO_EASYEDA_PARSER::ParseToBoardItemContainer(
|
|||||||
if( !font.IsEmpty() )
|
if( !font.IsEmpty() )
|
||||||
text->SetFont( KIFONT::FONT::GetFont( font ) );
|
text->SetFont( KIFONT::FONT::GetFont( font ) );
|
||||||
|
|
||||||
|
TransformTextToBaseline( text, wxEmptyString, false );
|
||||||
|
|
||||||
if( add )
|
if( add )
|
||||||
aContainer->Add( text, ADD_MODE::APPEND );
|
aContainer->Add( text, ADD_MODE::APPEND );
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user