← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] fix position of text and refdes from PCAD import

 

Hello. Patch that fix a size and a proportional of font.  
![](https://link.nylas.com/open/ac7n0u7eu8cj6vjow9ajimqdr/019b9ecac7464751a90d
673f85ca7ca6)

> On Feb 26 2016, at 8:18 pm, Eldar Khayrullin
<eldar.khayrullin@xxxxxxx> wrote:  
Add patch for carret return symbol in text

>

>> On Feb 25 2016, at 10:36 pm, Eldar Khayrullin
<eldar.khayrullin@xxxxxxx> wrote:  
Next I will fix some other import bugs:

>>

>>   * carret return symbol \r -> ?

>>   * size and proportional of text

>>   * etc

>>

>>> On Feb 25 2016, at 10:30 pm, Eldar Khayrullin
<eldar.khayrullin@xxxxxxx> wrote:  
Patch for position text with only justify from imported file. More accuary.

>>>

>>>> On Feb 25 2016, at 9:05 pm, Eldar Khayrullin
<eldar.khayrullin@xxxxxxx> wrote:  
And it apply only for free text not to refdes and value...

>>>>

>>>>> On Feb 25 2016, at 9:01 pm, Eldar Khayrullin
<eldar.khayrullin@xxxxxxx> wrote:  
I find that I can select horizontal and vertical justification of Kicad text
but vertical justify don't accessible from GUI. Can I use vertical justify?

>>>>>

>>>>>> On Feb 25 2016, at 7:02 pm, Eldar Khayrullin
<eldar.khayrullin@xxxxxxx> wrote:  
I think about this. But in the begining I'll try to use easy way: using
parametr 'extent' and calculate more pretty scale from PCAD to Kicad height
and width  

>>>>>>

>>>>>>> On Feb 25 2016, at 2:59 am, Piotr Esden-Tempski
<piotr@xxxxxxxxx> wrote:  

>>>>>>>

>>>>>>> Regarding variable width font. I ran into the issue when I was trying
to generate symbols for KiCad. To solve it I have generated a table with glyph
widths from the C code used in KiCad itself. You can find my python table
here: <https://github.com/esden/stm32-kicad-
lib/blob/master/script/kicadlibgen.py>

>>>>>>>

>>>>>>>  

>>>>>>>

>>>>>>> You might need to rescale the font size to match the KiCad font. So if
you had a similar glyph size table for the PCAD font you might be able to
generate the new text to fit into the same space as the original.

>>>>>>>

>>>>>>>  

>>>>>>>

>>>>>>> I hope this is helpful in some way.

>>>>>>>

>>>>>>>  

>>>>>>>

>>>>>>> If you want the code that I used to generate the glyph width table
with let me know.

>>>>>>>

>>>>>>>  

>>>>>>>

>>>>>>> Cheers,

>>>>>>>

>>>>>>> Esden

>>>>>>>

>>>>>>>  

>>>>>>>

>>>>>>>  

>>>>>>>

>>>>>>>> On Feb 24, 2016, at 9:57 AM, Eldar Khayrullin
&lt;[eldar.khayrullin@xxxxxxx](mailto:eldar.khayrullin@xxxxxxx)&gt; wrote:

>>>>>>>>

>>>>>>>>  

>>>>>>>>

>>>>>>>> Ok, glad to help.  

>>>>>>>>

>>>>>>>>> On Feb 24 2016, at 8:55 pm, Wayne Stambaugh
&lt;[stambaughw@xxxxxxxxx](mailto:stambaughw@xxxxxxxxx)&gt; wrote:  

>>>>>>>>>

>>>>>>>>> If the differences are due to variable font width issues then there
is  
not much we can do about that. Thanks for fixing this.

>>>>>>>>>

>>>>>>>>> On 2/24/2016 11:57 AM, Eldar Khayrullin wrote:  
&gt; PCAD stroke font isn't fixed width font and KiCad font too.  
&gt; I look for possible and try to solve this with more easy way  
&gt;  
&gt; On Feb 24 2016, at 7:51 pm, Wayne Stambaugh
&lt;[stambaughw@xxxxxxxxx](mailto:stambaughw@xxxxxxxxx)&gt;  
&gt; wrote:  
&gt;  
&gt; Eldar,  
&gt;  
&gt; Are you planning on actually determining the appropriate PCAD units for  
&gt; text so that this can be converted accurately? While you patch makes  
&gt; things better, I would prefer that we convert boards as accurately as  
&gt; possible. I know we don't handle different fonts but there should be no  
&gt; reason not to get the text position, height, and with correct.  
&gt;  
&gt; Wayne  
&gt;  
&gt; On 2/24/2016 11:34 AM, Eldar Khayrullin wrote:  
&gt; &gt; Thank you. Not ideal yet, but more truely  
&gt; &gt;  
&gt; &gt; On Feb 24 2016, at 3:00 pm, jp charras
&lt;[jp.charras@xxxxxxxxxx](mailto:jp.charras@xxxxxxxxxx)&gt; wrote:  
&gt; &gt;  
&gt; &gt; Le 23/02/2016 13:36, Eldar Khayrullin a écrit :  
&gt; &gt; &gt; Result  
&gt; &gt; &gt;  
&gt; &gt; &gt;&gt; On Feb 23 2016, at 3:29 pm, Eldar Khayrullin  
&gt; &gt; &gt;
&amp;lt;[eldar.khayrullin@xxxxxxx](mailto:eldar.khayrullin@xxxxxxx)&amp;gt;
wrote:  
&gt; &gt; &gt; Apply Justify of text and flipped flag of text from import
file.  
&gt; &gt;  
&gt; &gt; I committed your patches.  
&gt; &gt; AFAIK, they look good for me.  
&gt; &gt; Thanks.  
&gt; &gt;  
&gt; &gt;  
&gt; &gt; \--  
&gt; &gt; Jean-Pierre CHARRAS  
&gt; &gt;  
&gt; &gt; _______________________________________________  
&gt; &gt; Mailing list: <https://launchpad.net/~kicad-developers>  
&gt; &gt; Post to : [kicad-developers@xxxxxxxxxxxxxxxxxxx](mailto:kicad-
developers@xxxxxxxxxxxxxxxxxxx)  
&gt; &gt; Unsubscribe : <https://launchpad.net/~kicad-developers>  
&gt; &gt; More help : <https://help.launchpad.net/ListHelp>  
&gt; &gt;  
&gt; &gt;  
&gt; &gt;  
&gt; &gt; _______________________________________________  
&gt; &gt; Mailing list: <https://launchpad.net/~kicad-developers>  
&gt; &gt; Post to : [kicad-developers@xxxxxxxxxxxxxxxxxxx](mailto:kicad-
developers@xxxxxxxxxxxxxxxxxxx)  
&gt; &gt; Unsubscribe : <https://launchpad.net/~kicad-developers>  
&gt; &gt; More help : <https://help.launchpad.net/ListHelp>  
&gt; &gt;  
&gt;  
&gt; _______________________________________________  
&gt; Mailing list: <https://launchpad.net/~kicad-developers>  
&gt; Post to : [kicad-developers@xxxxxxxxxxxxxxxxxxx](mailto:kicad-
developers@xxxxxxxxxxxxxxxxxxx)  
&gt; Unsubscribe : <https://launchpad.net/~kicad-developers>  
&gt; More help : <https://help.launchpad.net/ListHelp>  
&gt;

>>>>>>>>

>>>>>>>> _______________________________________________  
Mailing list: <https://launchpad.net/~kicad-developers>  
Post to     : [kicad-developers@xxxxxxxxxxxxxxxxxxx](mailto:kicad-
developers@xxxxxxxxxxxxxxxxxxx)  
Unsubscribe : <https://launchpad.net/~kicad-developers>  
More help   : <https://help.launchpad.net/ListHelp>  

>>>>>>>

>>>>>>>  

>From 572c3589d4a09fdca26d3794b9082f67f88f8492 Mon Sep 17 00:00:00 2001
From: Eldar Khayrullin <eldar.khayrullin@xxxxxxx>
Date: Sat, 27 Feb 2016 12:43:04 +0300
Subject: [PATCH 3/3] pcad2kicadpcb: fix a proportional of font

---
 pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp | 14 +++++++++++---
 pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h   |  2 ++
 pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp        |  6 ++----
 pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp          |  3 +--
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
index 1839487..be0328f 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
@@ -37,8 +37,11 @@
 
 namespace PCAD2KICAD {
 
-// PCAD stroke font average ratio of width to height
-const double TEXT_WIDTH_TO_HEIGHT = 0.79;
+// PCAD stroke font average ratio of width to size
+const double TEXT_WIDTH_TO_SIZE_AVERAGE = 0.79;
+// PCAD proportions of stroke font
+const double TEXT_HEIGHT_TO_SIZE = 0.656;
+const double TEXT_WIDTH_TO_SIZE = 0.656;
 
 wxString GetWord( wxString* aStr )
 {
@@ -449,7 +452,7 @@ void SetTextJustify( EDA_TEXT* aText, TTEXT_JUSTIFY aJustify )
 int CalculateTextLengthSize( TTEXTVALUE* aText )
 {
     return KiROUND( (double) aText->text.Len() *
-                    (double) aText->textHeight * TEXT_WIDTH_TO_HEIGHT );
+                    (double) aText->textHeight * TEXT_WIDTH_TO_SIZE_AVERAGE );
 }
 
 void CorrectTextPosition( TTEXTVALUE* aValue )
@@ -545,6 +548,11 @@ void CorrectTextPosition( TTEXTVALUE* aValue )
     }
 }
 
+void SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText, int aTextHeight )
+{
+    aText->SetSize( wxSize( KiROUND( aTextHeight * TEXT_WIDTH_TO_SIZE ),
+                            KiROUND( aTextHeight * TEXT_HEIGHT_TO_SIZE ) ) );
+}
 
 XNODE* FindNode( XNODE* aChild, wxString aTag )
 {
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h
index 5fdeb9b..5d5a812 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h
+++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h
@@ -97,6 +97,8 @@ extern void         SetFontProperty( XNODE*         aNode,
 extern void         SetTextJustify( EDA_TEXT* aText, TTEXT_JUSTIFY aJustify );
 extern int          CalculateTextLengthSize( TTEXTVALUE* aText );
 extern void         CorrectTextPosition( TTEXTVALUE* aValue );
+extern void         SetTextSizeFromStrokeFontHeight( EDA_TEXT* aText,
+                                                     int aTextHeight );
 
 extern XNODE*       FindNode( XNODE* aChild, wxString aTag );
 extern wxString     FindNodeGetContent( XNODE* aChild, wxString aTag );
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
index 5bcf7d9..39ebf79 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
@@ -533,8 +533,7 @@ void PCB_MODULE::AddToBoard()
     ref_text->SetType( TEXTE_MODULE::TEXT_is_REFERENCE );
 
     ref_text->SetPos0( wxPoint( m_name.correctedPositionX, m_name.correctedPositionY ) );
-    ref_text->SetSize( wxSize( KiROUND( m_name.textHeight / 2 ),
-                               KiROUND( m_name.textHeight / 1.5 ) ) );
+    SetTextSizeFromStrokeFontHeight( ref_text, m_name.textHeight );
 
     r = m_name.textRotation - m_rotation;
     ref_text->SetOrientation( r );
@@ -556,8 +555,7 @@ void PCB_MODULE::AddToBoard()
     val_text->SetType( TEXTE_MODULE::TEXT_is_VALUE );
 
     val_text->SetPos0( wxPoint( m_value.correctedPositionX, m_value.correctedPositionY ) );
-    val_text->SetSize( wxSize( KiROUND( m_value.textHeight / 2 ),
-                               KiROUND( m_value.textHeight / 1.5 ) ) );
+    SetTextSizeFromStrokeFontHeight( val_text, m_value.textHeight );
 
     r = m_value.textRotation - m_rotation;
     val_text->SetOrientation( r );
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp
index 2a3e6c2..f2f096c 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp
@@ -110,8 +110,7 @@ void PCB_TEXT::AddToBoard()
 
     pcbtxt->SetText( m_name.text );
 
-    pcbtxt->SetSize( wxSize( KiROUND( m_name.textHeight / 2 ),
-                             KiROUND( m_name.textHeight / 1.1 ) ) );
+    SetTextSizeFromStrokeFontHeight( pcbtxt, m_name.textHeight );
 
     pcbtxt->SetThickness( m_name.textstrokeWidth );
     pcbtxt->SetOrientation( m_name.textRotation );
-- 
2.5.0

Attachment: after.kicad_pcb
Description: Binary data


Follow ups

References