KiCad PCB EDA Suite
SVG_plotter.cpp
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
10  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 /* Some info on basic items SVG format, used here:
31  * The root element of all SVG files is the <svg> element.
32  *
33  * The <g> element is used to group SVG shapes together.
34  * Once grouped you can transform the whole group of shapes as if it was a single shape.
35  * This is an advantage compared to a nested <svg> element
36  * which cannot be the target of transformation by itself.
37  *
38  * The <rect> element represents a rectangle.
39  * Using this element you can draw rectangles of various width, height,
40  * with different stroke (outline) and fill colors, with sharp or rounded corners etc.
41  *
42  * <svg xmlns="http://www.w3.org/2000/svg"
43  * xmlns:xlink="http://www.w3.org/1999/xlink">
44  *
45  * <rect x="10" y="10" height="100" width="100"
46  * style="stroke:#006600; fill: #00cc00"/>
47  *
48  * </svg>
49  *
50  * The <circle> element is used to draw circles.
51  * <circle cx="40" cy="40" r="24" style="stroke:#006600; fill:#00cc00"/>
52  *
53  * The <ellipse> element is used to draw ellipses.
54  * An ellipse is a circle that does not have equal height and width.
55  * Its radius in the x and y directions are different, in other words.
56  * <ellipse cx="40" cy="40" rx="30" ry="15"
57  * style="stroke:#006600; fill:#00cc00"/>
58  *
59  * The <line> element is used to draw lines.
60  *
61  * <line x1="0" y1="10" x2="0" y2="100" style="stroke:#006600;"/>
62  * <line x1="10" y1="10" x2="100" y2="100" style="stroke:#006600;"/>
63  *
64  * The <polyline> element is used to draw multiple connected lines
65  * Here is a simple example:
66  *
67  * <polyline points="0,0 30,0 15,30" style="stroke:#006600;"/>
68  *
69  * The <polygon> element is used to draw with multiple (3 or more) sides / edges.
70  * Here is a simple example:
71  *
72  * <polygon points="0,0 50,0 25,50" style="stroke:#660000; fill:#cc3333;"/>
73  *
74  * The <path> element is used to draw advanced shapes combined from lines and arcs,
75  * with or without fill.
76  * It is probably the most advanced and versatile SVG shape of them all.
77  * It is probably also the hardest element to master.
78  * <path d="M50,50
79  * A30,30 0 0,1 35,20
80  * L100,100
81  * M110,110
82  * L100,0"
83  * style="stroke:#660000; fill:none;"/>
84  *
85  * Draw an elliptic arc: it is one of basic path command:
86  * <path d="M(startx,starty) A(radiusx,radiusy)
87  * rotation-axe-x
88  * flag_arc_large,flag_sweep endx,endy">
89  * flag_arc_large: 0 = small arc > 180 deg, 1 = large arc > 180 deg
90  * flag_sweep : 0 = CCW, 1 = CW
91  * The center of ellipse is automatically calculated.
92  */
93 #include <fctsys.h>
94 #include <trigo.h>
95 #include <eda_base_frame.h>
96 #include <eda_rect.h>
97 #include <base_struct.h>
98 #include <common.h>
99 #include <plotter.h>
100 #include <macros.h>
101 #include <kicad_string.h>
102 
103 
104 
111 static wxString XmlEsc( const wxString& aStr, bool isAttribute = false )
112 {
113  wxString escaped;
114 
115  escaped.reserve( aStr.length() );
116 
117  for( wxString::const_iterator it = aStr.begin(); it != aStr.end(); ++it )
118  {
119  const wxChar c = *it;
120 
121  switch( c )
122  {
123  case wxS( '<' ):
124  escaped.append( wxS( "&lt;" ) );
125  break;
126  case wxS( '>' ):
127  escaped.append( wxS( "&gt;" ) );
128  break;
129  case wxS( '&' ):
130  escaped.append( wxS( "&amp;" ) );
131  break;
132  case wxS( '\r' ):
133  escaped.append( wxS( "&#xD;" ) );
134  break;
135  default:
136  if( isAttribute )
137  {
138  switch( c )
139  {
140  case wxS( '"' ):
141  escaped.append( wxS( "&quot;" ) );
142  break;
143  case wxS( '\t' ):
144  escaped.append( wxS( "&#x9;" ) );
145  break;
146  case wxS( '\n' ):
147  escaped.append( wxS( "&#xA;" ));
148  break;
149  default:
150  escaped.append(c);
151  }
152  }
153  else
154  escaped.append(c);
155  }
156  }
157 
158  return escaped;
159 }
160 
161 
163 {
164  m_graphics_changed = true;
166  m_fillMode = NO_FILL; // or FILLED_SHAPE or FILLED_WITH_BG_BODYCOLOR
167  m_pen_rgb_color = 0; // current color value (black)
168  m_brush_rgb_color = 0; // current color value (black)
169  m_dashed = false;
170 }
171 
172 
173 void SVG_PLOTTER::SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
174  double aScale, bool aMirror )
175 {
176  m_plotMirror = aMirror;
177  m_yaxisReversed = true; // unlike other plotters, SVG has Y axis reversed
178  plotOffset = aOffset;
179  plotScale = aScale;
180  m_IUsPerDecimil = aIusPerDecimil;
181  iuPerDeviceUnit = 1.0 / aIusPerDecimil;
182  /* Compute the paper size in IUs */
184  paperSize.x *= 10.0 * aIusPerDecimil;
185  paperSize.y *= 10.0 * aIusPerDecimil;
186  SetDefaultLineWidth( 100 * aIusPerDecimil ); // arbitrary default
187 }
188 
189 
191 {
193 
194  if( m_graphics_changed )
195  setSVGPlotStyle();
196 }
197 
198 
200 {
201  if( m_fillMode != fill )
202  {
203  m_graphics_changed = true;
204  m_fillMode = fill;
205  }
206 }
207 
208 
209 void SVG_PLOTTER::setSVGPlotStyle( bool aIsGroup, const std::string& aExtraStyle )
210 {
211  if( aIsGroup )
212  fputs( "</g>\n<g ", outputFile );
213 
214  // output the background fill color
215  fprintf( outputFile, "style=\"fill:#%6.6lX; ", m_brush_rgb_color );
216 
217  switch( m_fillMode )
218  {
219  case NO_FILL:
220  fputs( "fill-opacity:0.0; ", outputFile );
221  break;
222 
223  case FILLED_SHAPE:
224  fputs( "fill-opacity:1.0; ", outputFile );
225  break;
226 
228  fputs( "fill-opacity:0.6; ", outputFile );
229  break;
230  }
231 
232  double pen_w = userToDeviceSize( GetCurrentLineWidth() );
233  fprintf( outputFile, "\nstroke:#%6.6lX; stroke-width:%g; stroke-opacity:1; \n",
234  m_pen_rgb_color, pen_w );
235  fputs( "stroke-linecap:round; stroke-linejoin:round;", outputFile );
236 
237  switch( m_dashed )
238  {
239  case PLOTDASHTYPE_DASH:
240  fprintf( outputFile, "stroke-dasharray:%g,%g;",
242  break;
243  case PLOTDASHTYPE_DOT:
244  fprintf( outputFile, "stroke-dasharray:%g,%g;",
246  break;
248  fprintf( outputFile, "stroke-dasharray:%g,%g,%g,%g;",
250  break;
251  }
252 
253  if( aExtraStyle.length() )
254  {
255  fputs( aExtraStyle.c_str(), outputFile );
256  }
257 
258  fputs( "\"", outputFile );
259 
260  if( aIsGroup )
261  {
262  fputs( ">", outputFile );
263  m_graphics_changed = false;
264  }
265 
266  fputs( "\n", outputFile );
267 }
268 
269 /* Set the current line width (in IUs) for the next plot
270  */
271 void SVG_PLOTTER::SetCurrentLineWidth( int width, void* aData )
272 {
273  int pen_width;
274 
275  if( width >= 0 )
276  pen_width = width;
277  else
278  pen_width = defaultPenWidth;
279 
280  if( pen_width != currentPenWidth )
281  {
282  m_graphics_changed = true;
283  currentPenWidth = pen_width;
284  }
285 
286  if( m_graphics_changed )
287  setSVGPlotStyle();
288 }
289 
290 
291 void SVG_PLOTTER::StartBlock( void* aData )
292 {
293  std::string* idstr = reinterpret_cast<std::string*>( aData );
294 
295  fputs( "<g ", outputFile );
296  if( idstr )
297  fprintf( outputFile, "id=\"%s\"", idstr->c_str() );
298 
299  fprintf( outputFile, ">\n" );
300 }
301 
302 
303 void SVG_PLOTTER::EndBlock( void* aData )
304 {
305  fprintf( outputFile, "</g>\n" );
306 
307  m_graphics_changed = true;
308 }
309 
310 
311 /* initialize m_red, m_green, m_blue ( 0 ... 255)
312  * from reduced values r, g ,b ( 0.0 to 1.0 )
313  */
314 void SVG_PLOTTER::emitSetRGBColor( double r, double g, double b )
315 {
316  int red = (int) ( 255.0 * r );
317  int green = (int) ( 255.0 * g );
318  int blue = (int) ( 255.0 * b );
319  long rgb_color = (red << 16) | (green << 8) | blue;
320 
321  if( m_pen_rgb_color != rgb_color )
322  {
323  m_graphics_changed = true;
324  m_pen_rgb_color = rgb_color;
325 
326  // Currently, use the same color for brush and pen
327  // (i.e. to draw and fill a contour)
328  m_brush_rgb_color = rgb_color;
329  }
330 }
331 
332 
336 void SVG_PLOTTER::SetDash( int dashed )
337 {
338  if( m_dashed != dashed )
339  {
340  m_graphics_changed = true;
341  m_dashed = dashed;
342  }
343 
344  if( m_graphics_changed )
345  setSVGPlotStyle();
346 }
347 
348 
349 void SVG_PLOTTER::Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, int width )
350 {
351  EDA_RECT rect( p1, wxSize( p2.x -p1.x, p2.y -p1.y ) );
352  rect.Normalize();
353  DPOINT org_dev = userToDeviceCoordinates( rect.GetOrigin() );
354  DPOINT end_dev = userToDeviceCoordinates( rect.GetEnd() );
355  DSIZE size_dev = end_dev - org_dev;
356  // Ensure size of rect in device coordinates is > 0
357  // I don't know if this is a SVG issue or a Inkscape issue, but
358  // Inkscape has problems with negative or null values for width and/or height, so avoid them
359  DBOX rect_dev( org_dev, size_dev);
360  rect_dev.Normalize();
361 
362  setFillMode( fill );
364 
365  // Rectangles having a 0 size value for height or width are just not drawn on Inscape,
366  // so use a line when happens.
367  if( rect_dev.GetSize().x == 0.0 || rect_dev.GetSize().y == 0.0 ) // Draw a line
368  fprintf( outputFile,
369  "<line x1=\"%g\" y1=\"%g\" x2=\"%g\" y2=\"%g\" />\n",
370  rect_dev.GetPosition().x, rect_dev.GetPosition().y,
371  rect_dev.GetEnd().x, rect_dev.GetEnd().y
372  );
373 
374  else
375  fprintf( outputFile,
376  "<rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" rx=\"%g\" />\n",
377  rect_dev.GetPosition().x, rect_dev.GetPosition().y,
378  rect_dev.GetSize().x, rect_dev.GetSize().y,
379  0.0 // radius of rounded corners
380  );
381 }
382 
383 
384 void SVG_PLOTTER::Circle( const wxPoint& pos, int diametre, FILL_T fill, int width )
385 {
386  DPOINT pos_dev = userToDeviceCoordinates( pos );
387  double radius = userToDeviceSize( diametre / 2.0 );
388 
389  setFillMode( fill );
391 
392  // If diameter is less than width, switch to filled mode
393  if( fill == NO_FILL && diametre < width )
394  {
396  SetCurrentLineWidth( 0 );
397 
398  radius = userToDeviceSize( ( diametre / 2.0 ) + ( width / 2.0 ) );
399  }
400 
401  fprintf( outputFile,
402  "<circle cx=\"%g\" cy=\"%g\" r=\"%g\" /> \n",
403  pos_dev.x, pos_dev.y, radius );
404 }
405 
406 
407 void SVG_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius,
408  FILL_T fill, int width )
409 {
410  /* Draws an arc of a circle, centred on (xc,yc), with starting point
411  * (x1, y1) and ending at (x2, y2). The current pen is used for the outline
412  * and the current brush for filling the shape.
413  *
414  * The arc is drawn in an anticlockwise direction from the start point to
415  * the end point
416  */
417 
418  if( radius <= 0 )
419  {
420  Circle( centre, width, FILLED_SHAPE, 0 );
421  return;
422  }
423 
424  if( StAngle > EndAngle )
425  std::swap( StAngle, EndAngle );
426 
427  // Calculate start point.
428  DPOINT centre_dev = userToDeviceCoordinates( centre );
429  double radius_dev = userToDeviceSize( radius );
430 
431  if( !m_yaxisReversed ) // Should be never the case
432  {
433  double tmp = StAngle;
434  StAngle = -EndAngle;
435  EndAngle = -tmp;
436  }
437 
438  if( m_plotMirror )
439  {
441  {
442  StAngle = 1800.0 -StAngle;
443  EndAngle = 1800.0 -EndAngle;
444  std::swap( StAngle, EndAngle );
445  }
446  else
447  {
448  StAngle = -StAngle;
449  EndAngle = -EndAngle;
450  }
451  }
452 
453  DPOINT start;
454  start.x = radius_dev;
455  RotatePoint( &start.x, &start.y, StAngle );
456  DPOINT end;
457  end.x = radius_dev;
458  RotatePoint( &end.x, &end.y, EndAngle );
459  start += centre_dev;
460  end += centre_dev;
461 
462  double theta1 = DECIDEG2RAD( StAngle );
463 
464  if( theta1 < 0 )
465  theta1 = theta1 + M_PI * 2;
466 
467  double theta2 = DECIDEG2RAD( EndAngle );
468 
469  if( theta2 < 0 )
470  theta2 = theta2 + M_PI * 2;
471 
472  if( theta2 < theta1 )
473  theta2 = theta2 + M_PI * 2;
474 
475  int flg_arc = 0; // flag for large or small arc. 0 means less than 180 degrees
476 
477  if( fabs( theta2 - theta1 ) > M_PI )
478  flg_arc = 1;
479 
480  int flg_sweep = 0; // flag for sweep always 0
481 
482  // Draw a single arc: an arc is one of 3 curve commands (2 other are 2 bezier curves)
483  // params are start point, radius1, radius2, X axe rotation,
484  // flag arc size (0 = small arc > 180 deg, 1 = large arc > 180 deg),
485  // sweep arc ( 0 = CCW, 1 = CW),
486  // end point
487  if( fill != NO_FILL )
488  {
489  // Filled arcs (in eeschema) consist of the pie wedge and a stroke only on the arc
490  // This needs to be drawn in two steps.
491  setFillMode( fill );
492  SetCurrentLineWidth( 0 );
493 
494  fprintf( outputFile, "<path d=\"M%g %g A%g %g 0.0 %d %d %g %g L %g %g Z\" />\n",
495  start.x, start.y, radius_dev, radius_dev,
496  flg_arc, flg_sweep,
497  end.x, end.y, centre_dev.x, centre_dev.y );
498  }
499 
500  setFillMode( NO_FILL );
502  fprintf( outputFile, "<path d=\"M%g %g A%g %g 0.0 %d %d %g %g \" />\n",
503  start.x, start.y, radius_dev, radius_dev,
504  flg_arc, flg_sweep,
505  end.x, end.y );
506 }
507 
508 
509 void SVG_PLOTTER::BezierCurve( const wxPoint& aStart, const wxPoint& aControl1,
510  const wxPoint& aControl2, const wxPoint& aEnd,
511  int aTolerance, int aLineThickness )
512 {
513 #if 1
514  setFillMode( NO_FILL );
515  SetCurrentLineWidth( aLineThickness );
516 
517  DPOINT start = userToDeviceCoordinates( aStart );
518  DPOINT ctrl1 = userToDeviceCoordinates( aControl1 );
519  DPOINT ctrl2 = userToDeviceCoordinates( aControl2 );
520  DPOINT end = userToDeviceCoordinates( aEnd );
521 
522  // Generate a cubic curve: start point and 3 other control points.
523  fprintf( outputFile, "<path d=\"M%g,%g C%g,%g %g,%g %g,%g\" />\n",
524  start.x, start.y, ctrl1.x, ctrl1.y,
525  ctrl2.x, ctrl2.y, end.x, end.y );
526 #else
527  PLOTTER::BezierCurve( aStart, aControl1,aControl2, aEnd,aTolerance, aLineThickness );
528 #endif
529 }
530 
531 
532 void SVG_PLOTTER::PlotPoly( const std::vector<wxPoint>& aCornerList,
533  FILL_T aFill, int aWidth, void * aData )
534 {
535  if( aCornerList.size() <= 1 )
536  return;
537 
538  setFillMode( aFill );
539  SetCurrentLineWidth( aWidth );
540  fprintf( outputFile, "<path ");
541 
542  switch( aFill )
543  {
544  case NO_FILL:
545  setSVGPlotStyle( false, "fill:none" );
546  break;
547 
549  case FILLED_SHAPE:
550  setSVGPlotStyle( false, "fill-rule:evenodd;" );
551  break;
552  }
553 
554  DPOINT pos = userToDeviceCoordinates( aCornerList[0] );
555  fprintf( outputFile, "d=\"M %g,%g\n", pos.x, pos.y );
556 
557  for( unsigned ii = 1; ii < aCornerList.size() - 1; ii++ )
558  {
559  pos = userToDeviceCoordinates( aCornerList[ii] );
560  fprintf( outputFile, "%g,%g\n", pos.x, pos.y );
561  }
562 
563  // If the cornerlist ends where it begins, then close the poly
564  if( aCornerList.front() == aCornerList.back() )
565  fprintf( outputFile, "Z\" /> \n" );
566  else
567  {
568  pos = userToDeviceCoordinates( aCornerList.back() );
569  fprintf( outputFile, "%g,%g\n\" /> \n", pos.x, pos.y );
570  }
571 }
572 
573 
577 void SVG_PLOTTER::PlotImage( const wxImage& aImage, const wxPoint& aPos,
578  double aScaleFactor )
579 {
580  // in svg file we must insert a link to a png image file to plot an image
581  // the image itself is not included in the svg file.
582  // So we prefer skip the image, and just draw a rectangle,
583  // like other plotters which do not support images
584 
585  PLOTTER::PlotImage( aImage, aPos, aScaleFactor );
586 
587 }
588 
589 
590 void SVG_PLOTTER::PenTo( const wxPoint& pos, char plume )
591 {
592  if( plume == 'Z' )
593  {
594  if( penState != 'Z' )
595  {
596  fputs( "\" />\n", outputFile );
597  penState = 'Z';
598  penLastpos.x = -1;
599  penLastpos.y = -1;
600  }
601 
602  return;
603  }
604 
605  if( penState == 'Z' ) // here plume = 'D' or 'U'
606  {
607  DPOINT pos_dev = userToDeviceCoordinates( pos );
608 
609  // Ensure we do not use a fill mode when moving tne pen,
610  // in SVG mode (i;e. we are plotting only basic lines, not a filled area
611  if( m_fillMode != NO_FILL )
612  {
613  setFillMode( NO_FILL );
614  setSVGPlotStyle();
615  }
616 
617  fprintf( outputFile, "<path d=\"M%d %d\n",
618  (int) pos_dev.x, (int) pos_dev.y );
619  }
620  else if( penState != plume || pos != penLastpos )
621  {
622  DPOINT pos_dev = userToDeviceCoordinates( pos );
623  fprintf( outputFile, "L%d %d\n",
624  (int) pos_dev.x, (int) pos_dev.y );
625  }
626 
627  penState = plume;
628  penLastpos = pos;
629 }
630 
631 
637 {
638  wxASSERT( outputFile );
639  wxString msg;
640 
641  static const char* header[] =
642  {
643  "<?xml version=\"1.0\" standalone=\"no\"?>\n",
644  " <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n",
645  " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \n",
646  "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" \n",
647  NULL
648  };
649 
650  // Write header.
651  for( int ii = 0; header[ii] != NULL; ii++ )
652  {
653  fputs( header[ii], outputFile );
654  }
655 
656  // Write viewport pos and size
657  wxPoint origin; // TODO set to actual value
658  fprintf( outputFile,
659  " width=\"%gcm\" height=\"%gcm\" viewBox=\"%d %d %d %d \">\n",
660  (double) paperSize.x / m_IUsPerDecimil * 2.54 / 10000,
661  (double) paperSize.y / m_IUsPerDecimil * 2.54 / 10000,
662  origin.x, origin.y,
663  (int) ( paperSize.x / m_IUsPerDecimil ),
664  (int) ( paperSize.y / m_IUsPerDecimil) );
665 
666  // Write title
667  char date_buf[250];
668  time_t ltime = time( NULL );
669  strftime( date_buf, 250, "%Y/%m/%d %H:%M:%S",
670  localtime( &ltime ) );
671 
672  fprintf( outputFile,
673  "<title>SVG Picture created as %s date %s </title>\n",
674  TO_UTF8( XmlEsc( wxFileName( filename ).GetFullName() ) ), date_buf );
675  // End of header
676  fprintf( outputFile, " <desc>Picture generated by %s </desc>\n",
677  TO_UTF8( XmlEsc( creator ) ) );
678 
679  // output the pen and brush color (RVB values in hex) and opacity
680  double opacity = 1.0; // 0.0 (transparent to 1.0 (solid)
681  fprintf( outputFile,
682  "<g style=\"fill:#%6.6lX; fill-opacity:%g;stroke:#%6.6lX; stroke-opacity:%g;\n",
683  m_brush_rgb_color, opacity, m_pen_rgb_color, opacity );
684 
685  // output the pen cap and line joint
686  fputs( "stroke-linecap:round; stroke-linejoin:round; \"\n", outputFile );
687  fputs( " transform=\"translate(0 0) scale(1 1)\">\n", outputFile );
688  return true;
689 }
690 
691 
693 {
694  fputs( "</g> \n</svg>\n", outputFile );
695  fclose( outputFile );
696  outputFile = NULL;
697 
698  return true;
699 }
700 
701 
702 void SVG_PLOTTER::Text( const wxPoint& aPos,
703  const COLOR4D aColor,
704  const wxString& aText,
705  double aOrient,
706  const wxSize& aSize,
707  enum EDA_TEXT_HJUSTIFY_T aH_justify,
708  enum EDA_TEXT_VJUSTIFY_T aV_justify,
709  int aWidth,
710  bool aItalic,
711  bool aBold,
712  bool aMultilineAllowed,
713  void* aData )
714 {
715  setFillMode( NO_FILL );
716  SetColor( aColor );
717  SetCurrentLineWidth( aWidth );
718 
719  int width = currentPenWidth;
720 
721  if( aWidth <= 0 && aBold )
722  width = GetPenSizeForBold( std::min( aSize.x, aSize.y ) );
723 
724  if( aWidth <= 0 )
726 
727  wxPoint text_pos = aPos;
728  const char *hjust = "start";
729 
730  switch( aH_justify )
731  {
733  hjust = "middle";
734  break;
735 
737  hjust = "end";
738  break;
739 
741  hjust = "start";
742  break;
743  }
744 
745  switch( aV_justify )
746  {
748  text_pos.y += aSize.y / 2;
749  break;
750 
752  text_pos.y += aSize.y;
753  break;
754 
756  break;
757  }
758 
759  wxSize text_size;
760  text_size.x = GraphicTextWidth( aText, aSize, aItalic, width );
761  text_size.y = aSize.x * 4/3; // Hershey font height to em size conversion
762  DPOINT anchor_pos_dev = userToDeviceCoordinates( aPos );
763  DPOINT text_pos_dev = userToDeviceCoordinates( text_pos );
764  DPOINT sz_dev = userToDeviceSize( text_size );
765 
766  if( aOrient != 0 ) {
767  fprintf( outputFile,
768  "<g transform=\"rotate(%g %g %g)\">\n",
769  - aOrient * 0.1, anchor_pos_dev.x, anchor_pos_dev.y );
770  }
771 
772  fprintf( outputFile,
773  "<text x=\"%g\" y=\"%g\"\n"
774  "textLength=\"%g\" font-size=\"%g\" lengthAdjust=\"spacingAndGlyphs\"\n"
775  "text-anchor=\"%s\" opacity=\"0\">%s</text>\n",
776  text_pos_dev.x, text_pos_dev.y,
777  sz_dev.x, sz_dev.y,
778  hjust, TO_UTF8( XmlEsc( aText ) ) );
779 
780  if( aOrient != 0 )
781  fputs( "</g>\n", outputFile );
782 
783  fprintf( outputFile,
784  "<g class=\"stroked-text\"><desc>%s</desc>\n",
785  TO_UTF8( XmlEsc( aText ) ) );
786  PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify,
787  aWidth, aItalic, aBold, aMultilineAllowed );
788  fputs( "</g>", outputFile );
789 }
double GetDotMarkLenIU() const
Definition: plotter.cpp:138
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:44
virtual void PlotImage(const wxImage &aImage, const wxPoint &aPos, double aScaleFactor) override
Postscript-likes at the moment are the only plot engines supporting bitmaps...
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
int GetPenSizeForBold(int aTextSize)
Function GetPensizeForBold.
Definition: gr_text.cpp:49
const Vec GetEnd() const
Definition: box2.h:193
FILL_T m_fillMode
Definition: plotter.h:1002
void setFillMode(FILL_T fill)
function setFillMode() prepare parameters for setSVGPlotStyle()
int color
Definition: DXF_plotter.cpp:62
virtual void PenTo(const wxPoint &pos, char plume) override
moveto/lineto primitive, moves the 'pen' to the specified direction
void setSVGPlotStyle(bool aIsGroup=true, const std::string &aExtraStyle={})
function setSVGPlotStyle() output the string which define pen and brush color, shape,...
virtual void BezierCurve(const wxPoint &aStart, const wxPoint &aControl1, const wxPoint &aControl2, const wxPoint &aEnd, int aTolerance, int aLineThickness=USE_DEFAULT_LINE_WIDTH)
Generic fallback: Cubic Bezier curve rendered as a polyline In Kicad the bezier curves have 4 control...
Definition: plotter.cpp:202
int GraphicTextWidth(const wxString &aText, const wxSize &aSize, bool aItalic, bool aBold)
Function GraphicTextWidth.
Definition: gr_text.cpp:90
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:206
char penState
Current pen state: 'U', 'D' or 'Z' (see PenTo)
Definition: plotter.h:586
double m_IUsPerDecimil
Definition: plotter.h:563
wxPoint plotOffset
Plot offset (in IUs)
Definition: plotter.h:569
wxPoint penLastpos
Last pen positions; set to -1,-1 when the pen is at rest.
Definition: plotter.h:588
static wxString XmlEsc(const wxString &aStr, bool isAttribute=false)
Function XmlEsc translates '<' to "<", '>' to ">" and so on, according to the spec: http://www....
PAGE_INFO pageInfo
Definition: plotter.h:592
This file contains miscellaneous commonly used macros and functions.
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
virtual void Text(const wxPoint &aPos, const COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=NULL)
Draws text with the plotter.
Definition: gr_text.cpp:215
double GetDashGapLenIU() const
Definition: plotter.cpp:150
virtual int GetCurrentLineWidth() const
Definition: plotter.h:152
virtual void Text(const wxPoint &aPos, const COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=NULL) override
Draws text with the plotter.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
virtual bool EndPlot() override
bool m_yaxisReversed
true to mirror horizontally (else vertically)
Definition: plotter.h:575
const wxPoint GetEnd() const
Definition: eda_rect.h:116
virtual void SetColor(COLOR4D color) override
The SetColor implementation is split with the subclasses: The PSLIKE computes the rgb values,...
bool m_plotMirror
X axis orientation (SVG) and plot mirrored (only for PS, PDF HPGL and SVG)
Definition: plotter.h:573
virtual void SetDefaultLineWidth(int width) override
Set the default line width.
Definition: PS_plotter.cpp:52
long m_pen_rgb_color
Definition: plotter.h:1004
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
virtual void Arc(const wxPoint &centre, double StAngle, double EndAngle, int rayon, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
Generic fallback: arc rendered as a polyline.
BOX2< Vec > & Normalize()
Function Normalize ensures that the height ant width are positive.
Definition: box2.h:127
virtual void SetColor(COLOR4D color) override
The SetColor implementation is split with the subclasses: The PSLIKE computes the rgb values,...
Definition: PS_plotter.cpp:59
Base window classes and related definitions.
double plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
Definition: plotter.h:557
virtual bool StartPlot() override
The code within this function creates SVG files header.
const wxSize & GetSizeMils() const
Definition: page_info.h:142
virtual DPOINT userToDeviceSize(const wxSize &size)
Modifies size according to the plotter scale factors (wxSize version, returns a DPOINT)
Definition: plotter.cpp:123
virtual void SetCurrentLineWidth(int width, void *aData=NULL) override
Set the line width for the next drawing.
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:51
const Vec & GetPosition() const
Definition: box2.h:192
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modifies coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:98
void Normalize()
Function Normalize ensures that the height ant width are positive.
virtual void PlotImage(const wxImage &aImage, const wxPoint &aPos, double aScaleFactor)
Function PlotImage Only Postscript plotters can plot bitmaps for plotters that cannot plot a bitmap,...
Definition: plotter.cpp:230
virtual void SetTextMode(PlotTextMode mode) override
PS and PDF fully implement native text (for the Latin-1 subset)
Definition: plotter.h:699
int currentPenWidth
Definition: plotter.h:584
int defaultPenWidth
true to generate a negative image (PS mode mainly)
Definition: plotter.h:583
double GetDashMarkLenIU() const
Definition: plotter.cpp:144
bool m_graphics_changed
Definition: plotter.h:1010
long m_brush_rgb_color
Definition: plotter.h:1008
virtual void EndBlock(void *aData) override
calling this function allows one to define the end of a group of drawing items the group is started b...
FILE * outputFile
true if the Y axis is top to bottom (SVG)
Definition: plotter.h:578
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
double DECIDEG2RAD(double deg)
Definition: trigo.h:214
virtual void emitSetRGBColor(double r, double g, double b) override
function emitSetRGBColor() initialize m_pen_rgb_color from reduced values r, g ,b ( reduced values ar...
The common library.
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:42
virtual void SetDash(int dashed) override
SVG supports dashed lines.
virtual void StartBlock(void *aData) override
calling this function allows one to define the beginning of a group of drawing items (used in SVG for...
const Vec & GetSize() const
Definition: box2.h:187
double iuPerDeviceUnit
Device scale (from IUs to plotter device units - usually decimils)
Definition: plotter.h:566
wxString filename
Definition: plotter.h:590
float width
Definition: nanosvg.h:157
virtual void BezierCurve(const wxPoint &aStart, const wxPoint &aControl1, const wxPoint &aControl2, const wxPoint &aEnd, int aTolerance, int aLineThickness=USE_DEFAULT_LINE_WIDTH) override
Generic fallback: Cubic Bezier curve rendered as a polyline In Kicad the bezier curves have 4 control...
wxString creator
Definition: plotter.h:589
wxSize paperSize
Paper size in IU - not in mils.
Definition: plotter.h:594
bool m_mirrorIsHorizontal
Definition: plotter.h:574
int m_dashed
Definition: plotter.h:1013
#define min(a, b)
Definition: auxiliary.h:85
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=NULL) override
Function PlotPoly.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39