From 176fe80425f7526876d3ac92fa3518144dc40a07 Mon Sep 17 00:00:00 2001 From: Simon Schubert <2@0x2c.org> Date: Sun, 16 Aug 2015 23:52:42 +0200 Subject: [PATCH] SVG plot: output invisible text in addition to plotting Fixes: lp:1544918 * https://bugs.launchpad.net/kicad/+bug/1544918 --- common/plotters/SVG_plotter.cpp | 64 ++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/common/plotters/SVG_plotter.cpp b/common/plotters/SVG_plotter.cpp index 761f3c6258..9c3f595c2e 100644 --- a/common/plotters/SVG_plotter.cpp +++ b/common/plotters/SVG_plotter.cpp @@ -674,7 +674,69 @@ void SVG_PLOTTER::Text( const wxPoint& aPos, SetColor( aColor ); SetCurrentLineWidth( aWidth ); - // TODO: see if the postscript native text code can be used in SVG plotter + int width = currentPenWidth; + + if( aWidth <= 0 && aBold ) + width = GetPenSizeForBold( std::min( aSize.x, aSize.y ) ); + + if( aWidth <= 0 ) + width = currentPenWidth; + + wxPoint text_pos = aPos; + const char *hjust = "start"; + + switch( aH_justify ) + { + case GR_TEXT_HJUSTIFY_CENTER: + hjust = "middle"; + break; + + case GR_TEXT_HJUSTIFY_RIGHT: + hjust = "end"; + break; + + case GR_TEXT_HJUSTIFY_LEFT: + hjust = "start"; + break; + } + + switch( aV_justify ) + { + case GR_TEXT_VJUSTIFY_CENTER: + text_pos.y += aSize.y / 2; + break; + + case GR_TEXT_VJUSTIFY_TOP: + text_pos.y += aSize.y; + break; + + case GR_TEXT_VJUSTIFY_BOTTOM: + break; + } + + wxSize text_size; + text_size.x = GraphicTextWidth( aText, aSize, aItalic, width ); + text_size.y = aSize.x * 4/3; // Hershey font height to em size conversion + DPOINT anchor_pos_dev = userToDeviceCoordinates( aPos ); + DPOINT text_pos_dev = userToDeviceCoordinates( text_pos ); + DPOINT sz_dev = userToDeviceSize( text_size ); + + if( aOrient != 0 ) { + fprintf( outputFile, + "\n", + - aOrient * 0.1, anchor_pos_dev.x, anchor_pos_dev.y ); + } + + fprintf( outputFile, + "%s\n", + text_pos_dev.x, text_pos_dev.y, + sz_dev.x, sz_dev.y, + hjust, TO_UTF8( XmlEsc( aText ) ) ); + + if( aOrient != 0 ) + fputs( "\n", outputFile ); fprintf( outputFile, "%s\n",