Commit 42b4cae4 authored by charras's avatar charras
Browse files

commit hershey patch

parent 8ff28f7b
Loading
Loading
Loading
Loading
+4 −22
Original line number Original line Diff line number Diff line
@@ -175,6 +175,7 @@ EDA_TextStruct::EDA_TextStruct( const wxString& text )
    m_VJustify  = GR_TEXT_VJUSTIFY_CENTER;          /* Justifications Horiz et Vert du texte */
    m_VJustify  = GR_TEXT_VJUSTIFY_CENTER;          /* Justifications Horiz et Vert du texte */
    m_Width     = 0;                                /* thickness */
    m_Width     = 0;                                /* thickness */
    m_Italic    = false;                            /* true = italic shape */
    m_Italic    = false;                            /* true = italic shape */
    m_Bold      = false;
    m_MultilineAllowed = false;                     // Set to true only for texts that can use multiline.
    m_MultilineAllowed = false;                     // Set to true only for texts that can use multiline.
    m_Text = text;
    m_Text = text;
}
}
@@ -191,13 +192,9 @@ EDA_TextStruct::~EDA_TextStruct()
 * @param aLine : the line of text to consider.
 * @param aLine : the line of text to consider.
 * For single line text, this parameter is always m_Text
 * For single line text, this parameter is always m_Text
 */
 */
int EDA_TextStruct::LenSize( const wxString& aLine )
int EDA_TextStruct::LenSize( const wxString& aLine ) const
{
{
    int nbchar = aLine.Len();
    return TextWidth(aLine, m_Size.x, m_Italic, m_Bold ) + m_Width;

    int len = ( ( (10 * m_Size.x ) / 9 ) + m_Width ) * nbchar;

    return len;
}
}




@@ -328,21 +325,6 @@ bool EDA_TextStruct::HitTest( EDA_Rect& refArea )
    return false;
    return false;
}
}



/*********************************************/
int EDA_TextStruct::Pitch( int aMinTickness )
/*********************************************/

/**
 * Function Pitch
 * @return distance between 2 characters
 * @param aMinTickness = min segments tickness
 */
{
    return ( (m_Size.x * 10) / 9 ) + MAX( m_Width, aMinTickness );
}


/***************************************************************/
/***************************************************************/
void EDA_TextStruct::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
void EDA_TextStruct::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
                           const wxPoint& aOffset, EDA_Colors aColor,
                           const wxPoint& aOffset, EDA_Colors aColor,
@@ -455,7 +437,7 @@ void EDA_TextStruct::DrawOneLineOfText( WinEDA_DrawPanel* aPanel, wxDC* aDC,
    DrawGraphicText( aPanel, aDC,
    DrawGraphicText( aPanel, aDC,
                     aOffset + aPos, aColor, aText,
                     aOffset + aPos, aColor, aText,
                     m_Orient, size,
                     m_Orient, size,
                     m_HJustify, m_VJustify, width, m_Italic, true );
                     m_HJustify, m_VJustify, width, m_Italic, m_Bold );
}
}




+16 −11
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ void InitPlotParametresPS( wxPoint offset, Ki_PageDescr* sheet,
    g_Plot_XScale = aXScale;
    g_Plot_XScale = aXScale;
    g_Plot_YScale = aYScale;
    g_Plot_YScale = aYScale;
    g_Plot_CurrentPenWidth = -1;
    g_Plot_CurrentPenWidth = -1;
    g_Plot_PenState = 'Z';
}
}




@@ -211,18 +212,22 @@ void LineTo_PS( wxPoint pos, int plume )
/* Routine to draw to a new position
/* Routine to draw to a new position
 */
 */
{
{
    if( plume == 'Z' )
    char Line[256];
    if( plume == 'Z' ) {
	if (g_Plot_PenState != 'Z') {
	    fputs( "stroke\n", g_Plot_PlotOutputFile );
	    g_Plot_PenState = 'Z';
	}
        return;
        return;
    }


    UserToDeviceCoordinate( pos );
    UserToDeviceCoordinate( pos );
    if( plume == 'D' )
    if (g_Plot_PenState == 'Z') {
    {
	fputs( "newpath\n", g_Plot_PlotOutputFile );
        char Line[256];
        sprintf( Line, "%d %d %d %d line\n",
            g_Plot_LastPenPosition.x, g_Plot_LastPenPosition.y, pos.x, pos.y );
        fputs( Line, g_Plot_PlotOutputFile );
    }
    }
    g_Plot_LastPenPosition = pos;
    sprintf( Line, "%d %d %sto\n", pos.x, pos.y, (plume=='D')?"line":"move" );
    fputs( Line, g_Plot_PlotOutputFile );
    g_Plot_PenState = plume;
}
}




@@ -272,11 +277,11 @@ void PrintHeaderPS( FILE* file, const wxString& Creator,
        "/rect0 { rectstroke } bind def\n",
        "/rect0 { rectstroke } bind def\n",
        "/rect1 { rectfill } bind def\n",
        "/rect1 { rectfill } bind def\n",
        "/rect2 { rectfill } bind def\n",
        "/rect2 { rectfill } bind def\n",
	"/linemode0 { 0 setlinecap 0 setlinejoin 0 setlinewidth } bind def\n",
	"/linemode1 { 1 setlinecap 1 setlinejoin } bind def\n",
        "gsave\n",
        "gsave\n",
        "72 72 scale\t\t\t% Talk inches\n",
        "72 72 scale\t\t\t% Talk inches\n",
        "1 setlinecap\n",
        "linemode1\n",
        "1 setlinejoin\n",
        "1 setlinewidth\n",
        NULL
        NULL
    };
    };


+30 −14
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@




// Variables partagees avec Common plot Postscript et HPLG Routines
// Variables partagees avec Common plot Postscript et HPLG Routines
wxPoint g_Plot_LastPenPosition;
wxPoint g_Plot_PlotOffset;
wxPoint g_Plot_PlotOffset;
FILE*   g_Plot_PlotOutputFile;
FILE*   g_Plot_PlotOutputFile;
double  g_Plot_XScale, g_Plot_YScale;
double  g_Plot_XScale, g_Plot_YScale;
@@ -81,6 +80,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
    void              (*FctPlume)( wxPoint pos, int state );
    void              (*FctPlume)( wxPoint pos, int state );
    int               UpperLimit = VARIABLE_BLOCK_START_POSITION;
    int               UpperLimit = VARIABLE_BLOCK_START_POSITION;
    bool italic = false;
    bool italic = false;
    bool bold = false;
    bool thickness = 0; //@todo : use current pen
    bool thickness = 0; //@todo : use current pen


    switch( format_plot )
    switch( format_plot )
@@ -121,6 +121,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
    pos.x = ref.x; pos.y = yg;
    pos.x = ref.x; pos.y = yg;
    FctPlume( pos,'D' );
    FctPlume( pos,'D' );
    FctPlume(ref,'D');
    FctPlume(ref,'D');
    FctPlume(ref,'Z');
#else
#else


    for( ii = 0; ii < 2; ii++ )
    for( ii = 0; ii < 2; ii++ )
@@ -136,6 +137,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
        ref.x += GRID_REF_W * conv_unit; ref.y += GRID_REF_W * conv_unit;
        ref.x += GRID_REF_W * conv_unit; ref.y += GRID_REF_W * conv_unit;
        xg -= GRID_REF_W * conv_unit; yg -= GRID_REF_W * conv_unit;
        xg -= GRID_REF_W * conv_unit; yg -= GRID_REF_W * conv_unit;
    }
    }
    FctPlume(ref,'Z');
#endif
#endif


    /* trace des reperes */
    /* trace des reperes */
@@ -162,7 +164,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
		PlotGraphicText(format_plot, pos, color,
		PlotGraphicText(format_plot, pos, color,
				msg, TEXT_ORIENT_VERT, text_size,
				msg, TEXT_ORIENT_VERT, text_size,
                        	GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_BOTTOM,
                        	GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_BOTTOM,
                            thickness, italic );
                            thickness, italic, false, false );


        	break;
        	break;
    	    case WS_SEGMENT_LU:
    	    case WS_SEGMENT_LU:
@@ -170,6 +172,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
    		pos.x = (ref.x - WsItem->m_Endx) * conv_unit;
    		pos.x = (ref.x - WsItem->m_Endx) * conv_unit;
    		pos.y = (yg - WsItem->m_Endy) * conv_unit;
    		pos.y = (yg - WsItem->m_Endy) * conv_unit;
		FctPlume(pos, 'D');
		FctPlume(pos, 'D');
		FctPlume(ref,'Z');
    		break;
    		break;
	}
	}
    }
    }
@@ -185,6 +188,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
        	pos.x = (ref.x + WsItem->m_Endx) * conv_unit;
        	pos.x = (ref.x + WsItem->m_Endx) * conv_unit;
        	pos.y = (ref.y + WsItem->m_Endy) * conv_unit;
        	pos.y = (ref.y + WsItem->m_Endy) * conv_unit;
        	FctPlume(pos, 'D');
        	FctPlume(pos, 'D');
		FctPlume(ref,'Z');
        	break;
        	break;
	}
	}
    }
    }
@@ -202,13 +206,14 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
            FctPlume( pos, 'U' );
            FctPlume( pos, 'U' );
            pos.x = ii * conv_unit; pos.y = (ref.y + GRID_REF_W) * conv_unit;
            pos.x = ii * conv_unit; pos.y = (ref.y + GRID_REF_W) * conv_unit;
            FctPlume( pos, 'D' );
            FctPlume( pos, 'D' );
	    FctPlume(ref,'Z');
        }
        }
        pos.x = (ii - gxpas / 2) * conv_unit;
        pos.x = (ii - gxpas / 2) * conv_unit;
        pos.y = (ref.y + GRID_REF_W / 2) * conv_unit;
        pos.y = (ref.y + GRID_REF_W / 2) * conv_unit;
        PlotGraphicText( format_plot, pos, color,
        PlotGraphicText( format_plot, pos, color,
            msg, TEXT_ORIENT_HORIZ, text_size,
            msg, TEXT_ORIENT_HORIZ, text_size,
            GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
            GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
            thickness, italic );
            thickness, italic, false );


        if( ii < xg - PAS_REF / 2 )
        if( ii < xg - PAS_REF / 2 )
        {
        {
@@ -216,13 +221,14 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
            FctPlume( pos, 'U' );
            FctPlume( pos, 'U' );
            pos.x = ii * conv_unit; pos.y = (yg - GRID_REF_W) * conv_unit;
            pos.x = ii * conv_unit; pos.y = (yg - GRID_REF_W) * conv_unit;
            FctPlume( pos, 'D' );
            FctPlume( pos, 'D' );
	    FctPlume(ref,'Z');
        }
        }
        pos.x = (ii - gxpas / 2) * conv_unit;
        pos.x = (ii - gxpas / 2) * conv_unit;
        pos.y = (yg - GRID_REF_W / 2) * conv_unit;
        pos.y = (yg - GRID_REF_W / 2) * conv_unit;
        PlotGraphicText( format_plot, pos, color,
        PlotGraphicText( format_plot, pos, color,
            msg, TEXT_ORIENT_HORIZ, text_size,
            msg, TEXT_ORIENT_HORIZ, text_size,
            GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
            GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
            thickness, italic );
            thickness, italic, false );
    }
    }


    /* Trace des reperes selon l'axe Y */
    /* Trace des reperes selon l'axe Y */
@@ -237,13 +243,14 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
            FctPlume( pos, 'U' );
            FctPlume( pos, 'U' );
            pos.x = (ref.x + GRID_REF_W) * conv_unit; pos.y = ii * conv_unit;
            pos.x = (ref.x + GRID_REF_W) * conv_unit; pos.y = ii * conv_unit;
            FctPlume( pos, 'D' );
            FctPlume( pos, 'D' );
	    FctPlume(ref,'Z');
        }
        }
        pos.x = (ref.x + GRID_REF_W / 2) * conv_unit;
        pos.x = (ref.x + GRID_REF_W / 2) * conv_unit;
        pos.y = (ii - gypas / 2) * conv_unit;
        pos.y = (ii - gypas / 2) * conv_unit;
        PlotGraphicText( format_plot, pos, color,
        PlotGraphicText( format_plot, pos, color,
            msg, TEXT_ORIENT_HORIZ, text_size,
            msg, TEXT_ORIENT_HORIZ, text_size,
            GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
            GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
            thickness, italic );
            thickness, italic, false );


        if( ii < yg - PAS_REF / 2 )
        if( ii < yg - PAS_REF / 2 )
        {
        {
@@ -251,12 +258,13 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
            FctPlume( pos, 'U' );
            FctPlume( pos, 'U' );
            pos.x = (xg - GRID_REF_W) * conv_unit; pos.y = ii * conv_unit;
            pos.x = (xg - GRID_REF_W) * conv_unit; pos.y = ii * conv_unit;
            FctPlume( pos, 'D' );
            FctPlume( pos, 'D' );
	    FctPlume(ref,'Z');
        }
        }
        pos.x = (xg - GRID_REF_W / 2) * conv_unit;
        pos.x = (xg - GRID_REF_W / 2) * conv_unit;
        pos.y = (ii - gypas / 2) * conv_unit;
        pos.y = (ii - gypas / 2) * conv_unit;
        PlotGraphicText( format_plot, pos, color, msg, TEXT_ORIENT_HORIZ, text_size,
        PlotGraphicText( format_plot, pos, color, msg, TEXT_ORIENT_HORIZ, text_size,
            GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
            GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
            thickness, italic );
            thickness, italic, false );
    }
    }
#endif
#endif


@@ -285,7 +293,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
		    if(WsItem->m_Legende) msg = WsItem->m_Legende;
		    if(WsItem->m_Legende) msg = WsItem->m_Legende;
		    PlotGraphicText(format_plot, pos, color, msg, TEXT_ORIENT_HORIZ,text_size,
		    PlotGraphicText(format_plot, pos, color, msg, TEXT_ORIENT_HORIZ,text_size,
				    GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
				    GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                    thickness, italic );
                    thickness, italic, false, false );
		    break;
		    break;
		case WS_SIZESHEET:
		case WS_SIZESHEET:
		    break;
		    break;
@@ -294,14 +302,14 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
		    msg << screen->m_ScreenNumber;
		    msg << screen->m_ScreenNumber;
		    PlotGraphicText(format_plot, pos, color, msg, TEXT_ORIENT_HORIZ,text_size,
		    PlotGraphicText(format_plot, pos, color, msg, TEXT_ORIENT_HORIZ,text_size,
				    GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
				    GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                    thickness, italic );
                    thickness, italic, false, false );
		    break;
		    break;
		case WS_SHEETS:
		case WS_SHEETS:
		    if(WsItem->m_Legende) msg = WsItem->m_Legende;
		    if(WsItem->m_Legende) msg = WsItem->m_Legende;
		    msg << screen->m_NumberOfScreen;
		    msg << screen->m_NumberOfScreen;
		    PlotGraphicText(format_plot, pos, color, msg, TEXT_ORIENT_HORIZ,text_size,
		    PlotGraphicText(format_plot, pos, color, msg, TEXT_ORIENT_HORIZ,text_size,
				    GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
				    GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                    thickness, italic );
                    thickness, italic, false, false );
		    break;
		    break;
		case WS_COMPANY_NAME:
		case WS_COMPANY_NAME:
		    break;
		    break;
@@ -322,6 +330,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
		    pos.x = (ref.x - WsItem->m_Endx) * conv_unit;
		    pos.x = (ref.x - WsItem->m_Endx) * conv_unit;
		    pos.y = (ref.y - WsItem->m_Endy)  * conv_unit;
		    pos.y = (ref.y - WsItem->m_Endy)  * conv_unit;
		    FctPlume(pos, 'D');
		    FctPlume(pos, 'D');
		    FctPlume(ref,'Z');
		    break;
		    break;
	    }
	    }
	}
	}
@@ -339,14 +348,14 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
		    if(WsItem->m_Legende) msg = WsItem->m_Legende;
		    if(WsItem->m_Legende) msg = WsItem->m_Legende;
		    PlotGraphicText(format_plot, pos, color, msg, TEXT_ORIENT_HORIZ,text_size,
		    PlotGraphicText(format_plot, pos, color, msg, TEXT_ORIENT_HORIZ,text_size,
				    GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
				    GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                    thickness, italic );
                    thickness, italic, false, false );
		    break;
		    break;
		case WS_IDENTSHEET_D:
		case WS_IDENTSHEET_D:
		    if(WsItem->m_Legende) msg = WsItem->m_Legende;
		    if(WsItem->m_Legende) msg = WsItem->m_Legende;
		    msg << screen->m_ScreenNumber;
		    msg << screen->m_ScreenNumber;
		    PlotGraphicText(format_plot, pos, color, msg, TEXT_ORIENT_HORIZ,text_size,
		    PlotGraphicText(format_plot, pos, color, msg, TEXT_ORIENT_HORIZ,text_size,
				    GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
				    GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                    thickness, italic );
                    thickness, italic, false, false );
		    break;
		    break;
		case WS_LEFT_SEGMENT_D:
		case WS_LEFT_SEGMENT_D:
		case WS_SEGMENT_D:
		case WS_SEGMENT_D:
@@ -354,6 +363,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
		    pos.x = (ref.x - WsItem->m_Endx) * conv_unit;
		    pos.x = (ref.x - WsItem->m_Endx) * conv_unit;
		    pos.y = (ref.y - WsItem->m_Endy) * conv_unit;
		    pos.y = (ref.y - WsItem->m_Endy) * conv_unit;
		    FctPlume(pos, 'D');
		    FctPlume(pos, 'D');
		    FctPlume(ref,'Z');
		    break;
		    break;
	    }
	    }
	}
	}
@@ -366,6 +376,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
    {
    {
        pos.x = (ref.x - WsItem->m_Posx) * conv_unit;
        pos.x = (ref.x - WsItem->m_Posx) * conv_unit;
        pos.y = (ref.y - WsItem->m_Posy) * conv_unit;
        pos.y = (ref.y - WsItem->m_Posy) * conv_unit;
	 bold = false;
        if( WsItem->m_Legende )
        if( WsItem->m_Legende )
            msg = WsItem->m_Legende;
            msg = WsItem->m_Legende;
        else
        else
@@ -375,10 +386,12 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
        {
        {
        case WS_DATE:
        case WS_DATE:
            msg += screen->m_Date;
            msg += screen->m_Date;
	     bold = true;
            break;
            break;


        case WS_REV:
        case WS_REV:
            msg += screen->m_Revision;
            msg += screen->m_Revision;
	     bold = true;
            break;
            break;


        case WS_KICAD_VERSION:
        case WS_KICAD_VERSION:
@@ -409,10 +422,12 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
            msg += screen->m_Company;
            msg += screen->m_Company;
            if( !msg.IsEmpty() )
            if( !msg.IsEmpty() )
                UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
                UpperLimit = MAX( UpperLimit, WsItem->m_Posy + SIZETEXT );
	     bold = true;
            break;
            break;


        case WS_TITLE:
        case WS_TITLE:
            msg += screen->m_Title;
            msg += screen->m_Title;
	     bold = true;
            break;
            break;


        case WS_COMMENT1:
        case WS_COMMENT1:
@@ -456,6 +471,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
            auxpos.y = (ref.y - WsItem->m_Endy) * conv_unit;;
            auxpos.y = (ref.y - WsItem->m_Endy) * conv_unit;;
            FctPlume( pos, 'U' );
            FctPlume( pos, 'U' );
            FctPlume( auxpos, 'D' );
            FctPlume( auxpos, 'D' );
	    FctPlume(ref,'Z');
        }
        }
            break;
            break;
        }
        }
@@ -465,7 +481,7 @@ void WinEDA_DrawFrame::PlotWorkSheet( int format_plot, BASE_SCREEN* screen )
            PlotGraphicText( format_plot, pos, color,
            PlotGraphicText( format_plot, pos, color,
                msg.GetData(), TEXT_ORIENT_HORIZ, text_size,
                msg.GetData(), TEXT_ORIENT_HORIZ, text_size,
                GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
                thickness, italic );
                thickness, italic, bold );
        }
        }
    }
    }
#endif
#endif
+201 −131
Original line number Original line Diff line number Diff line
@@ -18,7 +18,9 @@
#endif
#endif


#define EDA_DRAWBASE
#define EDA_DRAWBASE
#include "grfonte.h"
#include "hershey.h"

#define HERSHEY_SIZE 32.0


/* Functions to draw / plot a string.
/* Functions to draw / plot a string.
 *  texts have only one line.
 *  texts have only one line.
@@ -47,6 +49,54 @@ int NegableTextLength( const wxString& aText )
}
}




static const char* get_hershey_recipe( int AsciiCode, bool bold )
{
    AsciiCode &= 0x7F;
    if( AsciiCode < 32 )
        AsciiCode = 32;                 /* Clamp control chars */
    AsciiCode -= 32;

    if( bold )
    {
        return hershey_duplex[AsciiCode];
    }
    else
    {
        return hershey_simplex[AsciiCode];
    }
}


int TextWidth( const wxString& aText, int size_h, bool italic, bool bold )
{
    int tally = 0;
    int char_count = aText.length();

    for( int i = 0; i < char_count; i++ )
    {
        int AsciiCode = aText[i];

        if( AsciiCode == '~' ) /* Skip the negation marks */
        {
            continue;
        }

        const char* ptcar = get_hershey_recipe( AsciiCode, bold );
        /* Get metrics */
        int         xsta = *ptcar++ - 'R';
        int         xsto = *ptcar++ - 'R';
        tally += wxRound( size_h * (xsto - xsta) / HERSHEY_SIZE );
    }

    /* Italic correction, 1/8em */
    if( italic )
    {
        tally += wxRound( size_h * 0.125 );
    }
    return tally;
}


/* Helper function for drawing character polygons */
/* Helper function for drawing character polygons */
static void DrawGraphicTextPline(
static void DrawGraphicTextPline(
    WinEDA_DrawPanel* aPanel,
    WinEDA_DrawPanel* aPanel,
@@ -80,7 +130,33 @@ static void DrawGraphicTextPline(


static int overbar_position( int size_v, int thickness )
static int overbar_position( int size_v, int thickness )
{
{
    return wxRound( (double)size_v * 1.1 + (double)thickness );
    return wxRound( (double) size_v * 30.0 / HERSHEY_SIZE + (double) thickness );
}


static int clamp_text_pen_size( int width, int size_h, bool bold )
{
    /* As a rule, pen width should not be >1/8em, otherwise the character
     * will be cluttered up in its own fatness */
    /* XXX @todo: Should be handled in the UI and gerber plotter too */
    int maxWidth = wxRound( ABS( size_h ) / 8.0 );

    if( width > maxWidth )
    {
        width = maxWidth;
    }

    /* Special rule for bold text: the width should be at least 1.42 times the
     *  quantum unit, otherwise the line pairs will be visible! */
    if( bold )
    {
        int minWidth = wxRound( ABS( size_h ) * 1.42 / HERSHEY_SIZE + 0.5 );
        if( width < minWidth )
        {
            width = minWidth;
        }
    }
    return width;
}
}




@@ -98,7 +174,7 @@ static int overbar_position( int size_v, int thickness )
 *  @param aWidth = line width (pen width) (default = 0)
 *  @param aWidth = line width (pen width) (default = 0)
 *      if width < 0 : draw segments in sketch mode, width = abs(width)
 *      if width < 0 : draw segments in sketch mode, width = abs(width)
 *  @param aItalic = true to simulate an italic font
 *  @param aItalic = true to simulate an italic font
 *  @param aNegable = true to enable the ~ char for overbarring
 *  @param aBold = true to use a bold font
 *  @param aCallback() = function called (if non null) to draw each segment.
 *  @param aCallback() = function called (if non null) to draw each segment.
 *                  used to draw 3D texts or for plotting, NULL for normal drawings
 *                  used to draw 3D texts or for plotting, NULL for normal drawings
 */
 */
@@ -114,27 +190,26 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
                     enum GRTextVertJustifyType aV_justify,
                     enum GRTextVertJustifyType aV_justify,
                     int aWidth,
                     int aWidth,
                     bool aItalic,
                     bool aItalic,
                     bool aNegable,
                     bool aBold,
                     void (* aCallback)( int x0, int y0, int xf, int yf ) )
                     void (* aCallback)( int x0, int y0, int xf, int yf ) )
/****************************************************************************************************/
/****************************************************************************************************/
{
{
    int     char_count, AsciiCode;
    int     char_count, AsciiCode;
    int     x0, y0;
    int     x0, y0;
    int            size_h, size_v, pitch;
    int     size_h, size_v;
    SH_CODE        f_cod, plume = 'U';
    const SH_CODE* ptcar;
    int     ptr;
    int     ptr;
    int     dx, dy;                         // Draw coordinate for segments to draw. also used in some other calculation
    int     dx, dy;                         // Draw coordinate for segments to draw. also used in some other calculation
    wxPoint current_char_pos;               // Draw coordinates for the current char
    wxPoint current_char_pos;               // Draw coordinates for the current char
    wxPoint overbar_pos;                    // Start point for the current overbar
    wxPoint overbar_pos;                    // Start point for the current overbar
    int     overbars;                       // Number of ~ seen
    int     overbars;                       // Number of ~ seen
    int     overbar_italic_comp;            // Italic compensation for overbar


    #define        BUF_SIZE 100
    #define        BUF_SIZE 100
    wxPoint coord[BUF_SIZE + 1];                // Buffer coordinate used to draw polylines (one char shape)
    wxPoint coord[BUF_SIZE + 1];                // Buffer coordinate used to draw polylines (one char shape)
    bool    sketch_mode    = false;
    bool    sketch_mode    = false;
    bool    italic_reverse = false;             // true for mirrored texts with m_Size.x < 0
    bool    italic_reverse = false;             // true for mirrored texts with m_Size.x < 0


    size_h = aSize.x;
    size_h = aSize.x;                           /* PLEASE NOTE: H is for HORIZONTAL not for HEIGHT */
    size_v = aSize.y;
    size_v = aSize.y;


    if( aWidth < 0 )
    if( aWidth < 0 )
@@ -142,35 +217,25 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
        aWidth = -aWidth;
        aWidth = -aWidth;
        sketch_mode = true;
        sketch_mode = true;
    }
    }
    int thickness = aWidth;
    if( size_h < 0 )       // text is mirrored using size.x < 0 (mirror / Y axis)
    if( aSize.x < 0 )       // text is mirrored using size.x < 0 (mirror / Y axis)
        italic_reverse = true;
        italic_reverse = true;


    if( aNegable )
    aWidth = clamp_text_pen_size( aWidth, size_h, aBold );
    {

    char_count = NegableTextLength( aText );
    char_count = NegableTextLength( aText );
    }
    else
    {
        char_count = aText.Len();
    }
    if( char_count == 0 )
    if( char_count == 0 )
        return;
        return;


    pitch = (10 * size_h ) / 9;    // this is the pitch between chars
    if( pitch > 0 )
        pitch += thickness;
    else
        pitch -= thickness;

    current_char_pos = aPos;
    current_char_pos = aPos;


    dx = TextWidth( aText, size_h, aItalic, aBold );
    dy = size_v;

    /* Do not draw the text if out of draw area! */
    /* Do not draw the text if out of draw area! */
    if( aPanel )
    if( aPanel )
    {
    {
        int xm, ym, ll, xc, yc;
        int xm, ym, ll, xc, yc;
        int textsize = ABS( pitch );
        ll = aPanel->GetScreen()->Scale( ABS( dx ) );
        ll = aPanel->GetScreen()->Scale( textsize * char_count );


        xc = GRMapX( current_char_pos.x );
        xc = GRMapX( current_char_pos.x );
        yc = GRMapY( current_char_pos.y );
        yc = GRMapY( current_char_pos.y );
@@ -196,8 +261,6 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
     * this is the same as the text position only for a left and bottom justified text
     * this is the same as the text position only for a left and bottom justified text
     * In others cases, this position must be calculated from the text position ans size
     * In others cases, this position must be calculated from the text position ans size
     */
     */
    dx = pitch * char_count;
    dy = size_v;                            /* dx, dy = draw offset between first letter and text center */


    switch( aH_justify )
    switch( aH_justify )
    {
    {
@@ -249,11 +312,22 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
        return;
        return;
    }
    }


    if( aItalic )
    {
        overbar_italic_comp = overbar_position( size_v, aWidth ) / 8;
        if( italic_reverse )
        {
            overbar_italic_comp = -overbar_italic_comp;
        }
    }
    else
    {
        overbar_italic_comp = 0;
    };

    overbars = 0;
    overbars = 0;
    ptr = 0;   /* ptr = text index */
    ptr = 0;   /* ptr = text index */
    while( ptr < char_count )
    while( ptr < char_count )
    {
        if( aNegable )
    {
    {
        if( aText[ptr + overbars] == '~' )
        if( aText[ptr + overbars] == '~' )
        {
        {
@@ -264,7 +338,8 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
            {
            {
                /* Starting the overbar */
                /* Starting the overbar */
                overbar_pos    = current_char_pos;
                overbar_pos    = current_char_pos;
                    overbar_pos.y -= overbar_position( size_v, thickness );
                overbar_pos.x += overbar_italic_comp;
                overbar_pos.y -= overbar_position( size_v, aWidth );
                RotatePoint( &overbar_pos, aPos, aOrient );
                RotatePoint( &overbar_pos, aPos, aOrient );
            }
            }
            else
            else
@@ -272,7 +347,8 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
                /* Ending the overbar */
                /* Ending the overbar */
                coord[0]       = overbar_pos;
                coord[0]       = overbar_pos;
                overbar_pos    = current_char_pos;
                overbar_pos    = current_char_pos;
                    overbar_pos.y -= overbar_position( size_v, thickness );
                overbar_pos.x += overbar_italic_comp;
                overbar_pos.y -= overbar_position( size_v, aWidth );
                RotatePoint( &overbar_pos, aPos, aOrient );
                RotatePoint( &overbar_pos, aPos, aOrient );
                coord[1] = overbar_pos;
                coord[1] = overbar_pos;
                /* Plot the overbar segment */
                /* Plot the overbar segment */
@@ -281,84 +357,70 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
            }
            }
            continue; /* Skip ~ processing */
            continue; /* Skip ~ processing */
        }
        }
        }


        AsciiCode = aText.GetChar( ptr + overbars );
        AsciiCode = aText.GetChar( ptr + overbars );


#if defined(wxUSE_UNICODE) && defined(KICAD_CYRILLIC)
        const char* ptcar = get_hershey_recipe( AsciiCode, aBold );
        AsciiCode &= 0x7FF;
        /* Get metrics */
        if( AsciiCode > 0x40F && AsciiCode < 0x450 ) // big small Cyr
        int         xsta = *ptcar++ - 'R';
            AsciiCode = utf8_to_ascii[AsciiCode - 0x410] & 0xFF;
        int         xsto = *ptcar++ - 'R';
        int         point_count = 0;
        bool        endcar = false;
        while( !endcar )
        {
            int hc1, hc2;
            hc1 = *ptcar++;
            if( hc1 )
            {
                hc2 = *ptcar++;
            }
            else
            else
            AsciiCode = AsciiCode & 0xFF;
#else
        AsciiCode &= 0xFF;
#endif
        ptcar = graphic_fonte_shape[AsciiCode];  /* ptcar pointe la description
                                                  *  du caractere a dessiner */

        int  point_count;
        bool endcar;
        for( point_count = 0, endcar = false; !endcar; ptcar++ )
            {
            {
            f_cod = *ptcar;
                /* End of character, insert a synthetic pen up */
                hc1    = ' ';
                hc2    = 'R';
                endcar = true;
            }
            hc1 -= 'R'; hc2 -= 'R'; /* Do the Hershey decode thing: coordinates values are coded as <value> + 'R' */


            /* get code n de la forme selectionnee */
            /* Pen up request */
            switch( f_cod )
            if( hc1 == -50 && hc2 == 0 )
            {
            {
            case 'X':
                if( point_count )
                endcar = true;    /* fin du caractere */
                break;

            case 'U':
                if( point_count && (plume == 'D' ) )
                {
                {
                    if( aWidth <= 1 )
                    if( aWidth <= 1 )
                        aWidth = 0;
                        aWidth = 0;
                    DrawGraphicTextPline( aPanel, aDC, aColor, aWidth,
                    DrawGraphicTextPline( aPanel, aDC, aColor, aWidth,
                                          sketch_mode, point_count, coord, aCallback );
                                          sketch_mode, point_count, coord, aCallback );
                }
                }
                plume = f_cod; point_count = 0;
                point_count = 0;
                break;
            }

            else
            case 'D':
                plume = f_cod;
                break;

            default:
            {
            {
                int y, k1, k2;
                wxPoint currpoint;
                wxPoint currpoint;
                y  = k1 = f_cod;        /* trace sur axe V */
                hc1 -= xsta; hc2 -= 11; /* Align the midpoint */
                k1 = -( (k1 * size_v) / 9 );
                hc1  = wxRound( hc1 * size_h / HERSHEY_SIZE );

                hc2  = wxRound( hc2 * size_v / HERSHEY_SIZE );
                ptcar++;
                f_cod = *ptcar;

                k2 = f_cod;         /* trace sur axe H */
                k2 = (k2 * size_h) / 9;


                // To simulate an italic font, add a x offset depending on the y offset
                // To simulate an italic font, add a x offset depending on the y offset
                if( aItalic )
                if( aItalic )
                    k2 -= italic_reverse ? -k1 / 8 : k1 / 8;
                    hc1 -= wxRound( italic_reverse ? -hc2 / 8.0 : hc2 / 8.0 );
                currpoint.x = k2 + current_char_pos.x;
                currpoint.x = hc1 + current_char_pos.x;
                currpoint.y = k1 + current_char_pos.y;
                currpoint.y = hc2 + current_char_pos.y;


                RotatePoint( &currpoint, aPos, aOrient );
                RotatePoint( &currpoint, aPos, aOrient );
                coord[point_count] = currpoint;
                coord[point_count] = currpoint;
                if( point_count < BUF_SIZE - 1 )
                if( point_count < BUF_SIZE - 1 )
                    point_count++;
                    point_count++;
                break;
            }
            }
            }

            /* end switch */
        }
        }


        /* end draw 1 char */
        /* end draw 1 char */


        ptr++;
        ptr++;
        current_char_pos.x += pitch;    // current_char_pos is now the next position

        // Apply the advance width
        current_char_pos.x += wxRound( size_h * (xsto - xsta) / HERSHEY_SIZE );
    }
    }


    if( overbars % 2 )
    if( overbars % 2 )
@@ -366,7 +428,7 @@ void DrawGraphicText( WinEDA_DrawPanel* aPanel,
        /* Close the last overbar */
        /* Close the last overbar */
        coord[0]       = overbar_pos;
        coord[0]       = overbar_pos;
        overbar_pos    = current_char_pos;
        overbar_pos    = current_char_pos;
        overbar_pos.y  -= overbar_position( size_v, thickness );
        overbar_pos.y -= overbar_position( size_v, aWidth );
        RotatePoint( &overbar_pos, aPos, aOrient );
        RotatePoint( &overbar_pos, aPos, aOrient );
        coord[1] = overbar_pos;
        coord[1] = overbar_pos;
        /* Plot the overbar segment */
        /* Plot the overbar segment */
@@ -384,12 +446,9 @@ static bool s_Plotbegin; // Flag to init plot
/*
/*
 * The call back function
 * The call back function
 */
 */
/**********************/
/****************************************************************/
static void s_Callback_plot( int x0,
static void s_Callback_plot( int x0, int y0,  int xf, int yf )
                             int y0,
/****************************************************************/
                             int xf,
                             int yf )
/**********************/
{
{
    static wxPoint PenLastPos;
    static wxPoint PenLastPos;
    wxPoint        pstart;
    wxPoint        pstart;
@@ -435,7 +494,7 @@ static void s_Callback_plot( int x0,
 *  @param aWidth = line width (pen width) (default = 0)
 *  @param aWidth = line width (pen width) (default = 0)
 *      if width < 0 : draw segments in sketch mode, width = abs(width)
 *      if width < 0 : draw segments in sketch mode, width = abs(width)
 *  @param aItalic = true to simulate an italic font
 *  @param aItalic = true to simulate an italic font
 *  @param aNegable = true to enable the ~ char for overbarring
 *  @param aBold = true to use a bold font
 */
 */
/******************************************************************************************/
/******************************************************************************************/
void PlotGraphicText( int                         aFormat_plot,
void PlotGraphicText( int                         aFormat_plot,
@@ -448,14 +507,24 @@ void PlotGraphicText( int aFormat_plot,
                      enum GRTextVertJustifyType  aV_justify,
                      enum GRTextVertJustifyType  aV_justify,
                      int                         aWidth,
                      int                         aWidth,
                      bool                        aItalic,
                      bool                        aItalic,
                      bool                        aNegable )
                      bool                        aBold )
/******************************************************************************************/
/******************************************************************************************/
{
{
    if( aWidth > 0 )
    {
        aWidth = clamp_text_pen_size( aWidth, aSize.x, aBold );
    }
    else
    {
        aWidth = -clamp_text_pen_size( -aWidth, aSize.x, aBold );
    }

    // Initialise the actual function used to plot lines:
    // Initialise the actual function used to plot lines:
    switch( aFormat_plot )
    switch( aFormat_plot )
    {
    {
    case PLOT_FORMAT_POST:
    case PLOT_FORMAT_POST:
        MovePenFct = LineTo_PS;
        MovePenFct = LineTo_PS;
        SetCurrentLineWidthPS( aWidth );
        break;
        break;


    case PLOT_FORMAT_HPGL:
    case PLOT_FORMAT_HPGL:
@@ -464,6 +533,7 @@ void PlotGraphicText( int aFormat_plot,


    case PLOT_FORMAT_GERBER:
    case PLOT_FORMAT_GERBER:
        MovePenFct = LineTo_GERBER;
        MovePenFct = LineTo_GERBER;
        /* Gerber tool has to be set outside... */
        break;
        break;


    default:
    default:
@@ -477,7 +547,7 @@ void PlotGraphicText( int aFormat_plot,
    DrawGraphicText( NULL, NULL, aPos, aColor, aText,
    DrawGraphicText( NULL, NULL, aPos, aColor, aText,
                     aOrient, aSize,
                     aOrient, aSize,
                     aH_justify, aV_justify,
                     aH_justify, aV_justify,
                     aWidth, aItalic, aNegable,
                     aWidth, aItalic, aBold,
                     s_Callback_plot );
                     s_Callback_plot );


    /* end text : pen UP ,no move */
    /* end text : pen UP ,no move */
+37 −23

File changed.

Preview size limit exceeded, changes collapsed.

Loading