From c7fc091a42fc422600a0c26594e4f95e1f757d6c Mon Sep 17 00:00:00 2001 From: charras Date: Fri, 29 May 2009 15:45:13 +0000 Subject: [PATCH] better size scale factor for Hershey fonts --- common/drawtxt.cpp | 20 ++++++++++++-------- eeschema/class_text-label.cpp | 9 ++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/common/drawtxt.cpp b/common/drawtxt.cpp index 7d0703d89b..e2b8e34bb0 100644 --- a/common/drawtxt.cpp +++ b/common/drawtxt.cpp @@ -19,8 +19,12 @@ #define EDA_DRAWBASE #include "hershey_fonts.h" - -#define HERSHEY_SIZE 32.0 // size factor used to calculate actual size of shapes from hershey fonts +/* factor used to calculate actual size of shapes from hershey fonts (could be adjusted depending on the font name) + * Its value is choosen in order to have letters like M, P .. vertical size equal to the vertical char size parameter + * Of course some shapes can be bigger or smaller than the vertical char size parameter +*/ +#define HERSHEY_SCALE_FACTOR 1/21.0 +double s_HerscheyScaleFactor = HERSHEY_SCALE_FACTOR; /* Functions to draw / plot a string. * texts have only one line. @@ -102,7 +106,7 @@ int ReturnGraphicTextWidth( const wxString& aText, int aXSize, bool italic, bool /* Get metrics */ int xsta = *ptcar++ - 'R'; int xsto = *ptcar++ - 'R'; - tally += wxRound( aXSize * (xsto - xsta) / HERSHEY_SIZE ); + tally += wxRound( aXSize * (xsto - xsta) * s_HerscheyScaleFactor ); } /* Italic correction, 1/8em */ @@ -147,7 +151,7 @@ static void DrawGraphicTextPline( static int overbar_position( int size_v, int thickness ) { - return wxRound( ((double) size_v * 26/HERSHEY_SIZE ) + ((double) thickness * 1.5) ); + return wxRound( ((double) size_v * 26 * s_HerscheyScaleFactor ) + ((double) thickness * 1.5) ); } @@ -167,7 +171,7 @@ static int clamp_text_pen_size( int width, int size_h, bool bold ) * quantum unit, otherwise the line pairs will be visible! */ if( bold ) { - int minWidth = wxRound( ABS( size_h ) * 1.42 / HERSHEY_SIZE + 0.5 ); + int minWidth = wxRound( ABS( size_h ) * 1.42 * s_HerscheyScaleFactor + 0.5 ); if( width < minWidth ) { width = minWidth; @@ -416,8 +420,8 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, { wxPoint currpoint; hc1 -= xsta; hc2 -= 11; /* Align the midpoint */ - hc1 = wxRound( hc1 * size_h / HERSHEY_SIZE ); - hc2 = wxRound( hc2 * size_v / HERSHEY_SIZE ); + hc1 = wxRound( hc1 * size_h * s_HerscheyScaleFactor ); + hc2 = wxRound( hc2 * size_v * s_HerscheyScaleFactor ); // To simulate an italic font, add a x offset depending on the y offset if( aItalic ) @@ -437,7 +441,7 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel, ptr++; // Apply the advance width - current_char_pos.x += wxRound( size_h * (xsto - xsta) / HERSHEY_SIZE ); + current_char_pos.x += wxRound( size_h * (xsto - xsta) * s_HerscheyScaleFactor ); } if( overbars % 2 ) diff --git a/eeschema/class_text-label.cpp b/eeschema/class_text-label.cpp index 534552a9d3..ecaf7e7f36 100644 --- a/eeschema/class_text-label.cpp +++ b/eeschema/class_text-label.cpp @@ -714,8 +714,6 @@ void SCH_HIERLABEL::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offs { static std::vector Poly; EDA_Colors color; - wxPoint text_offset = offset + GetSchematicTextOffset(); - int width = MAX( m_Width, g_DrawMinimunLineWidth ); if( Color >= 0 ) @@ -726,6 +724,7 @@ void SCH_HIERLABEL::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offs GRSetDrawMode( DC, DrawMode ); EXCHG( width, m_Width ); // Set the minimum width + wxPoint text_offset = offset + GetSchematicTextOffset(); EDA_TextStruct::Draw( panel, DC, text_offset, color, DrawMode, FILLED, UNSPECIFIED_COLOR ); EXCHG( width, m_Width ); // set initial value @@ -775,7 +774,7 @@ EDA_Rect SCH_HIERLABEL::GetBoundingBox() dx = dy = 0; int width = MAX( m_Width, g_DrawMinimunLineWidth ); - height = m_Size.y + 2 * TXTMARGE; + height = m_Size.y + width + 2 * TXTMARGE; length = LenSize( m_Text ) + height // add height for triangular shapes + 2 * DANGLING_SYMBOL_SIZE; @@ -829,7 +828,6 @@ void SCH_GLOBALLABEL::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& aO EDA_Colors color; wxPoint text_offset = aOffset + GetSchematicTextOffset(); - int width = MAX( m_Width, g_DrawMinimunLineWidth ); if( Color >= 0 ) color = (EDA_Colors) Color; @@ -838,6 +836,7 @@ void SCH_GLOBALLABEL::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& aO GRSetDrawMode( DC, DrawMode ); + int width = MAX( m_Width, g_DrawMinimunLineWidth ); EXCHG( width, m_Width ); // Set the minimum width EDA_TextStruct::Draw( panel, DC, text_offset, color, DrawMode, FILLED, UNSPECIFIED_COLOR ); EXCHG( width, m_Width ); // set initial value @@ -996,7 +995,7 @@ EDA_Rect SCH_TEXT::GetBoundingBox() y = m_Pos.y; int width = MAX( m_Width, g_DrawMinimunLineWidth ); length = LenSize( m_Text ); - height = m_Size.y; + height = m_Size.y + width; dx = dy = 0; switch( m_SchematicOrientation )