From e8924057386a149b8f685f30b9f353a9de40b9e7 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Tue, 4 Jul 2023 13:29:42 +0300 Subject: [PATCH] Altium PCB import: read and apply TrueType font names to text. --- common/plugins/altium/altium_parser.h | 15 +++++++++++++++ pcbnew/plugins/altium/altium_parser_pcb.cpp | 6 +++++- pcbnew/plugins/altium/altium_parser_pcb.h | 1 + pcbnew/plugins/altium/altium_pcb.cpp | 5 +++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/common/plugins/altium/altium_parser.h b/common/plugins/altium/altium_parser.h index 8b41321598..678ccbb7f5 100644 --- a/common/plugins/altium/altium_parser.h +++ b/common/plugins/altium/altium_parser.h @@ -170,6 +170,21 @@ public: } } + int ReadBytes( char* aOut, size_t aSize ) + { + if( aSize > GetRemainingBytes() ) + { + m_error = true; + return 0; + } + else + { + memcpy( aOut, m_pos, aSize ); + m_pos += aSize; + return aSize; + } + } + int32_t ReadKicadUnit() { return ConvertToKicadUnit( Read() ); diff --git a/pcbnew/plugins/altium/altium_parser_pcb.cpp b/pcbnew/plugins/altium/altium_parser_pcb.cpp index b3c418f1fc..cb0d81229f 100644 --- a/pcbnew/plugins/altium/altium_parser_pcb.cpp +++ b/pcbnew/plugins/altium/altium_parser_pcb.cpp @@ -904,7 +904,11 @@ ATEXT6::ATEXT6( ALTIUM_PARSER& aReader, std::map& aStringTab aReader.Skip( 2 ); isBold = aReader.Read() != 0; isItalic = aReader.Read() != 0; - aReader.Skip( 64 ); // font_name + + char fontData[64] = { 0 }; + aReader.ReadBytes( fontData, sizeof( fontData ) ); + fontname = wxString( fontData, wxMBConvUTF16LE(), sizeof( fontData ) ); + isInverted = aReader.Read() != 0; aReader.Skip( 4 ); uint32_t stringIndex = aReader.Read(); diff --git a/pcbnew/plugins/altium/altium_parser_pcb.h b/pcbnew/plugins/altium/altium_parser_pcb.h index dd79ba633e..c94bcc4718 100644 --- a/pcbnew/plugins/altium/altium_parser_pcb.h +++ b/pcbnew/plugins/altium/altium_parser_pcb.h @@ -687,6 +687,7 @@ struct ATEXT6 bool isDesignator; ALTIUM_TEXT_TYPE fonttype; + wxString fontname; wxString text; diff --git a/pcbnew/plugins/altium/altium_pcb.cpp b/pcbnew/plugins/altium/altium_pcb.cpp index 13126a7e57..f397a13d55 100644 --- a/pcbnew/plugins/altium/altium_pcb.cpp +++ b/pcbnew/plugins/altium/altium_pcb.cpp @@ -3132,8 +3132,9 @@ void ALTIUM_PCB::ConvertTexts6ToEdaTextSettings( const ATEXT6& aElem, EDA_TEXT* { if( aElem.fonttype == ALTIUM_TEXT_TYPE::TRUETYPE ) { - // TODO: why is this required? Somehow, truetype size is calculated differently - aEdaText->SetTextSize( VECTOR2I( aElem.height / 2, aElem.height / 2 ) ); + // TODO: why is this required? Somehow, truetype size is calculated differently (tuned to Arial) + aEdaText->SetTextSize( VECTOR2I( aElem.height * 0.63, aElem.height * 0.63 ) ); + aEdaText->SetFont( KIFONT::FONT::GetFont( aElem.fontname, aElem.isBold, aElem.isItalic ) ); } else {