KiCad PCB EDA Suite
PS_plotter.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #include <eda_base_frame.h>
32 #include <macros.h>
33 #include <math/util.h> // for KiROUND
34 #include <render_settings.h>
35 #include <trigo.h>
36 
37 #include "plotters_pslike.h"
38 
39 
40 /* Forward declaration of the font width metrics
41  (yes extern! this is the way to forward declare variables */
42 extern const double hv_widths[256];
43 extern const double hvb_widths[256];
44 extern const double hvo_widths[256];
45 extern const double hvbo_widths[256];
46 
47 const double PSLIKE_PLOTTER::postscriptTextAscent = 0.718;
48 
49 
50 // return a id used to select a ps macro (see StartPlot() ) from a FILL_TYPE
51 // fill mode, for arc, rect, circle and poly draw primitives
52 static int getFillId( FILL_TYPE aFill )
53 {
54  if( aFill == FILL_TYPE::NO_FILL )
55  return 0;
56 
57  if( aFill == FILL_TYPE::FILLED_SHAPE )
58  return 1;
59 
60  return 2;
61 }
62 
63 
65 {
66  if( m_colorMode )
67  {
68  if( m_negativeMode )
69  emitSetRGBColor( 1 - color.r, 1 - color.g, 1 - color.b );
70  else
71  emitSetRGBColor( color.r, color.g, color.b );
72  }
73  else
74  {
75  /* B/W Mode - Use BLACK or WHITE for all items
76  * note the 2 colors are used in B&W mode, mainly by Pcbnew to draw
77  * holes in white on pads in black
78  */
79  double k = 1; // White
80  if( color != COLOR4D::WHITE )
81  k = 0;
82  if( m_negativeMode )
83  emitSetRGBColor( 1 - k, 1 - k, 1 - k );
84  else
85  emitSetRGBColor( k, k, k );
86  }
87 }
88 
89 
90 void PSLIKE_PLOTTER::FlashPadOval( const wxPoint& aPadPos, const wxSize& aSize,
91  double aPadOrient, OUTLINE_MODE aTraceMode, void* aData )
92 {
93  wxASSERT( m_outputFile );
94  int x0, y0, x1, y1, delta;
95  wxSize size( aSize );
96 
97  // The pad is reduced to an oval by dy > dx
98  if( size.x > size.y )
99  {
100  std::swap( size.x, size.y );
101  aPadOrient = AddAngles( aPadOrient, 900 );
102  }
103 
104  delta = size.y - size.x;
105  x0 = 0;
106  y0 = -delta / 2;
107  x1 = 0;
108  y1 = delta / 2;
109  RotatePoint( &x0, &y0, aPadOrient );
110  RotatePoint( &x1, &y1, aPadOrient );
111 
112  if( aTraceMode == FILLED )
113  ThickSegment( wxPoint( aPadPos.x + x0, aPadPos.y + y0 ),
114  wxPoint( aPadPos.x + x1, aPadPos.y + y1 ), size.x, aTraceMode, nullptr );
115  else
116  sketchOval( aPadPos, size, aPadOrient, -1 );
117 }
118 
119 
120 void PSLIKE_PLOTTER::FlashPadCircle( const wxPoint& aPadPos, int aDiameter,
121  OUTLINE_MODE aTraceMode, void* aData )
122 {
123  if( aTraceMode == FILLED )
124  {
125  Circle( aPadPos, aDiameter, FILL_TYPE::FILLED_SHAPE, 0 );
126  }
127  else // Plot a ring:
128  {
130  int linewidth = GetCurrentLineWidth();
131 
132  // avoid aDiameter <= 1 )
133  if( linewidth > aDiameter-2 )
134  linewidth = aDiameter-2;
135 
136  Circle( aPadPos, aDiameter - linewidth, FILL_TYPE::NO_FILL, linewidth );
137  }
138 
140 }
141 
142 
143 void PSLIKE_PLOTTER::FlashPadRect( const wxPoint& aPadPos, const wxSize& aSize,
144  double aPadOrient, OUTLINE_MODE aTraceMode, void* aData )
145 {
146  static std::vector< wxPoint > cornerList;
147  wxSize size( aSize );
148  cornerList.clear();
149 
150  if( aTraceMode == FILLED )
151  SetCurrentLineWidth( 0 );
152  else
154 
155  size.x -= GetCurrentLineWidth();
156  size.y -= GetCurrentLineWidth();
157 
158  if( size.x < 1 )
159  size.x = 1;
160 
161  if( size.y < 1 )
162  size.y = 1;
163 
164  int dx = size.x / 2;
165  int dy = size.y / 2;
166 
167  wxPoint corner;
168  corner.x = aPadPos.x - dx;
169  corner.y = aPadPos.y + dy;
170  cornerList.push_back( corner );
171  corner.x = aPadPos.x - dx;
172  corner.y = aPadPos.y - dy;
173  cornerList.push_back( corner );
174  corner.x = aPadPos.x + dx;
175  corner.y = aPadPos.y - dy;
176  cornerList.push_back( corner );
177  corner.x = aPadPos.x + dx;
178  corner.y = aPadPos.y + dy,
179  cornerList.push_back( corner );
180 
181  for( unsigned ii = 0; ii < cornerList.size(); ii++ )
182  {
183  RotatePoint( &cornerList[ii], aPadPos, aPadOrient );
184  }
185 
186  cornerList.push_back( cornerList[0] );
187 
188  PlotPoly( cornerList, ( aTraceMode == FILLED ) ? FILL_TYPE::FILLED_SHAPE : FILL_TYPE::NO_FILL,
190 }
191 
192 void PSLIKE_PLOTTER::FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize,
193  int aCornerRadius, double aOrient,
194  OUTLINE_MODE aTraceMode, void* aData )
195 {
196  wxSize size( aSize );
197 
198  if( aTraceMode == FILLED )
199  {
200  SetCurrentLineWidth( 0 );
201  }
202  else
203  {
205  size.x -= GetCurrentLineWidth();
206  size.y -= GetCurrentLineWidth();
207  aCornerRadius -= GetCurrentLineWidth()/2;
208  }
209 
210 
211  SHAPE_POLY_SET outline;
212  TransformRoundChamferedRectToPolygon( outline, aPadPos, size, aOrient, aCornerRadius,
213  0.0, 0, 0, GetPlotterArcHighDef(), ERROR_INSIDE );
214 
215  std::vector< wxPoint > cornerList;
216  // TransformRoundRectToPolygon creates only one convex polygon
217  SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
218  cornerList.reserve( poly.PointCount() );
219 
220  for( int ii = 0; ii < poly.PointCount(); ++ii )
221  cornerList.emplace_back( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
222 
223  // Close polygon
224  cornerList.push_back( cornerList[0] );
225 
226  PlotPoly( cornerList, ( aTraceMode == FILLED ) ? FILL_TYPE::FILLED_SHAPE : FILL_TYPE::NO_FILL,
228 }
229 
230 void PSLIKE_PLOTTER::FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize,
231  double aOrient, SHAPE_POLY_SET* aPolygons,
232  OUTLINE_MODE aTraceMode, void* aData )
233 {
234  wxSize size( aSize );
235 
236  if( aTraceMode == FILLED )
237  {
238  SetCurrentLineWidth( 0 );
239  }
240  else
241  {
243  size.x -= GetCurrentLineWidth();
244  size.y -= GetCurrentLineWidth();
245  }
246 
247 
248  std::vector< wxPoint > cornerList;
249 
250  for( int cnt = 0; cnt < aPolygons->OutlineCount(); ++cnt )
251  {
252  SHAPE_LINE_CHAIN& poly = aPolygons->Outline( cnt );
253  cornerList.clear();
254 
255  for( int ii = 0; ii < poly.PointCount(); ++ii )
256  cornerList.emplace_back( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
257 
258  // Close polygon
259  cornerList.push_back( cornerList[0] );
260 
261  PlotPoly( cornerList, ( aTraceMode == FILLED ) ? FILL_TYPE::FILLED_SHAPE : FILL_TYPE::NO_FILL,
263  }
264 }
265 
266 void PSLIKE_PLOTTER::FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners,
267  double aPadOrient, OUTLINE_MODE aTraceMode, void* aData )
268 {
269  static std::vector< wxPoint > cornerList;
270  cornerList.clear();
271 
272  for( int ii = 0; ii < 4; ii++ )
273  cornerList.push_back( aCorners[ii] );
274 
275  if( aTraceMode == FILLED )
276  {
277  SetCurrentLineWidth( 0 );
278  }
279  else
280  {
282  int w = GetCurrentLineWidth();
283  // offset polygon by w
284  // coord[0] is assumed the lower left
285  // coord[1] is assumed the upper left
286  // coord[2] is assumed the upper right
287  // coord[3] is assumed the lower right
288 
289  /* Trace the outline. */
290  cornerList[0].x += w;
291  cornerList[0].y -= w;
292  cornerList[1].x += w;
293  cornerList[1].y += w;
294  cornerList[2].x -= w;
295  cornerList[2].y += w;
296  cornerList[3].x -= w;
297  cornerList[3].y -= w;
298  }
299 
300  for( int ii = 0; ii < 4; ii++ )
301  {
302  RotatePoint( &cornerList[ii], aPadOrient );
303  cornerList[ii] += aPadPos;
304  }
305 
306  cornerList.push_back( cornerList[0] );
307  PlotPoly( cornerList, ( aTraceMode == FILLED ) ? FILL_TYPE::FILLED_SHAPE : FILL_TYPE::NO_FILL,
309 }
310 
311 
312 void PSLIKE_PLOTTER::FlashRegularPolygon( const wxPoint& aShapePos, int aRadius, int aCornerCount,
313  double aOrient, OUTLINE_MODE aTraceMode, void* aData )
314 {
315  // Do nothing
316  wxASSERT( 0 );
317 }
318 
319 
320 std::string PSLIKE_PLOTTER::encodeStringForPlotter( const wxString& aUnicode )
321 {
322  // Write on a std::string a string escaped for postscript/PDF
323  std::string converted;
324 
325  converted += '(';
326 
327  for( unsigned i = 0; i < aUnicode.Len(); i++ )
328  {
329  // Laziness made me use stdio buffering yet another time...
330  wchar_t ch = aUnicode[i];
331 
332  if( ch < 256 )
333  {
334  switch (ch)
335  {
336  // The ~ shouldn't reach the outside
337  case '~':
338  break;
339  // These characters must be escaped
340  case '(':
341  case ')':
342  case '\\':
343  converted += '\\';
345 
346  default:
347  converted += ch;
348  break;
349  }
350  }
351  }
352 
353  converted += ')';
354 
355  return converted;
356 }
357 
358 
359 int PSLIKE_PLOTTER::returnPostscriptTextWidth( const wxString& aText, int aXSize,
360  bool aItalic, bool aBold )
361 {
362  const double *width_table = aBold ? ( aItalic ? hvbo_widths : hvb_widths )
363  : ( aItalic ? hvo_widths : hv_widths );
364  double tally = 0;
365 
366  for( unsigned i = 0; i < aText.length(); i++ )
367  {
368  wchar_t AsciiCode = aText[i];
369  // Skip the negation marks and untabled points
370  if( AsciiCode != '~' && AsciiCode < 256 )
371  {
372  tally += width_table[AsciiCode];
373  }
374  }
375 
376  // Widths are proportional to height, but height is enlarged by a
377  // scaling factor
378  return KiROUND( aXSize * tally / postscriptTextAscent );
379 }
380 
381 
382 void PSLIKE_PLOTTER::postscriptOverlinePositions( const wxString& aText, int aXSize,
383  bool aItalic, bool aBold,
384  std::vector<int> *pos_pairs )
385 {
386  /* XXX This function is *too* similar to returnPostscriptTextWidth.
387  Consider merging them... */
388  const double *width_table = aBold ? ( aItalic ? hvbo_widths : hvb_widths )
389  : ( aItalic ? hvo_widths : hv_widths );
390  double tally = 0;
391 
392  for( unsigned i = 0; i < aText.length(); i++ )
393  {
394  wchar_t AsciiCode = aText[i];
395  // Skip the negation marks and untabled points
396  if( AsciiCode != '~' && AsciiCode < 256 )
397  {
398  tally += width_table[AsciiCode];
399  }
400  else
401  {
402  if( AsciiCode == '~' )
403  pos_pairs->push_back( KiROUND( aXSize * tally / postscriptTextAscent ) );
404  }
405  }
406 
407  // Special rule: we have to complete the last bar if the ~ aren't matched
408  if( pos_pairs->size() % 2 == 1 )
409  pos_pairs->push_back( KiROUND( aXSize * tally / postscriptTextAscent ) );
410 }
411 
412 
413 void PS_PLOTTER::SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
414  double aScale, bool aMirror )
415 {
416  wxASSERT( !m_outputFile );
417  m_plotMirror = aMirror;
418  m_plotOffset = aOffset;
419  m_plotScale = aScale;
420  m_IUsPerDecimil = aIusPerDecimil;
421  m_iuPerDeviceUnit = 1.0 / aIusPerDecimil;
422  /* Compute the paper size in IUs */
424  m_paperSize.x *= 10.0 * aIusPerDecimil;
425  m_paperSize.y *= 10.0 * aIusPerDecimil;
426 }
427 
428 
429 void PSLIKE_PLOTTER::computeTextParameters( const wxPoint& aPos,
430  const wxString& aText,
431  int aOrient,
432  const wxSize& aSize,
433  bool aMirror,
434  enum EDA_TEXT_HJUSTIFY_T aH_justify,
435  enum EDA_TEXT_VJUSTIFY_T aV_justify,
436  int aWidth,
437  bool aItalic,
438  bool aBold,
439  double *wideningFactor,
440  double *ctm_a,
441  double *ctm_b,
442  double *ctm_c,
443  double *ctm_d,
444  double *ctm_e,
445  double *ctm_f,
446  double *heightFactor )
447 {
448  // Compute the starting position (compensated for alignment)
449  wxPoint start_pos = aPos;
450 
451  // This is an approximation of the text bounds (in IUs)
452  int tw = returnPostscriptTextWidth( aText, aSize.x, aItalic, aWidth );
453  int th = aSize.y;
454  int dx, dy;
455 
456  switch( aH_justify )
457  {
459  dx = -tw / 2;
460  break;
461 
463  dx = -tw;
464  break;
465 
467  dx = 0;
468  break;
469  }
470 
471  switch( aV_justify )
472  {
474  dy = th / 2;
475  break;
476 
478  dy = th;
479  break;
480 
482  dy = 0;
483  break;
484  }
485 
486  RotatePoint( &dx, &dy, aOrient );
487  RotatePoint( &tw, &th, aOrient );
488  start_pos.x += dx;
489  start_pos.y += dy;
490  DPOINT pos_dev = userToDeviceCoordinates( start_pos );
491  DPOINT sz_dev = userToDeviceSize( aSize );
492 
493  // Now returns the final values... the widening factor
494  *wideningFactor = sz_dev.x / sz_dev.y;
495 
496  // Mirrored texts must be plotted as mirrored!
497  if( m_plotMirror )
498  {
499  *wideningFactor = -*wideningFactor;
500  aOrient = -aOrient;
501  }
502 
503  // The CTM transformation matrix
504  double alpha = DECIDEG2RAD( aOrient );
505  double sinalpha = sin( alpha );
506  double cosalpha = cos( alpha );
507 
508  *ctm_a = cosalpha;
509  *ctm_b = sinalpha;
510  *ctm_c = -sinalpha;
511  *ctm_d = cosalpha;
512  *ctm_e = pos_dev.x;
513  *ctm_f = pos_dev.y;
514 
515  // This is because the letters are less than 1 unit high
516  *heightFactor = sz_dev.y / postscriptTextAscent;
517 }
518 
519 
520 void PS_PLOTTER::SetCurrentLineWidth( int aWidth, void* aData )
521 {
522  wxASSERT( m_outputFile );
523 
524  if( aWidth == DO_NOT_SET_LINE_WIDTH )
525  return;
526  else if( aWidth == USE_DEFAULT_LINE_WIDTH )
528  else if( aWidth == 0 )
529  aWidth = 1;
530 
531  wxASSERT_MSG( aWidth > 0, "Plotter called to set negative pen width" );
532 
533  if( aWidth != GetCurrentLineWidth() )
534  fprintf( m_outputFile, "%g setlinewidth\n", userToDeviceSize( aWidth ) );
535 
536  m_currentPenWidth = aWidth;
537 }
538 
539 
540 void PS_PLOTTER::emitSetRGBColor( double r, double g, double b )
541 {
542  wxASSERT( m_outputFile );
543 
544  // XXX why %.3g ? shouldn't %g suffice? who cares...
545  fprintf( m_outputFile, "%.3g %.3g %.3g setrgbcolor\n", r, g, b );
546 }
547 
548 
550 {
551  switch( dashed )
552  {
554  fprintf( m_outputFile, "[%d %d] 0 setdash\n",
555  (int) GetDashMarkLenIU(), (int) GetDashGapLenIU() );
556  break;
557  case PLOT_DASH_TYPE::DOT:
558  fprintf( m_outputFile, "[%d %d] 0 setdash\n",
559  (int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
560  break;
562  fprintf( m_outputFile, "[%d %d %d %d] 0 setdash\n",
563  (int) GetDashMarkLenIU(), (int) GetDashGapLenIU(),
564  (int) GetDotMarkLenIU(), (int) GetDashGapLenIU() );
565  break;
566  default:
567  fputs( "solidline\n", m_outputFile );
568  }
569 }
570 
571 
572 void PS_PLOTTER::Rect( const wxPoint& p1, const wxPoint& p2, FILL_TYPE fill, int width )
573 {
574  DPOINT p1_dev = userToDeviceCoordinates( p1 );
575  DPOINT p2_dev = userToDeviceCoordinates( p2 );
576 
577  SetCurrentLineWidth( width );
578  fprintf( m_outputFile, "%g %g %g %g rect%d\n", p1_dev.x, p1_dev.y,
579  p2_dev.x - p1_dev.x, p2_dev.y - p1_dev.y, getFillId( fill ) );
580 }
581 
582 
583 void PS_PLOTTER::Circle( const wxPoint& pos, int diametre, FILL_TYPE fill, int width )
584 {
585  wxASSERT( m_outputFile );
586  DPOINT pos_dev = userToDeviceCoordinates( pos );
587  double radius = userToDeviceSize( diametre / 2.0 );
588 
589  SetCurrentLineWidth( width );
590  fprintf( m_outputFile, "%g %g %g cir%d\n", pos_dev.x, pos_dev.y, radius, getFillId( fill ) );
591 }
592 
593 
594 void PS_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle,
595  int radius, FILL_TYPE fill, int width )
596 {
597  wxASSERT( m_outputFile );
598 
599  if( radius <= 0 )
600  return;
601 
602  if( StAngle > EndAngle )
603  std::swap( StAngle, EndAngle );
604 
605  SetCurrentLineWidth( width );
606 
607  // Calculate start point.
608  DPOINT centre_dev = userToDeviceCoordinates( centre );
609  double radius_dev = userToDeviceSize( radius );
610 
611  if( m_plotMirror )
612  {
614  {
615  StAngle = 1800.0 -StAngle;
616  EndAngle = 1800.0 -EndAngle;
617  std::swap( StAngle, EndAngle );
618  }
619  else
620  {
621  StAngle = -StAngle;
622  EndAngle = -EndAngle;
623  }
624  }
625 
626  fprintf( m_outputFile, "%g %g %g %g %g arc%d\n", centre_dev.x, centre_dev.y,
627  radius_dev, StAngle / 10.0, EndAngle / 10.0, getFillId( fill ) );
628 }
629 
630 
631 void PS_PLOTTER::PlotPoly( const std::vector< wxPoint >& aCornerList,
632  FILL_TYPE aFill, int aWidth, void * aData )
633 {
634  if( aCornerList.size() <= 1 )
635  return;
636 
637  SetCurrentLineWidth( aWidth );
638 
639  DPOINT pos = userToDeviceCoordinates( aCornerList[0] );
640  fprintf( m_outputFile, "newpath\n%g %g moveto\n", pos.x, pos.y );
641 
642  for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
643  {
644  pos = userToDeviceCoordinates( aCornerList[ii] );
645  fprintf( m_outputFile, "%g %g lineto\n", pos.x, pos.y );
646  }
647 
648  // Close/(fill) the path
649  fprintf( m_outputFile, "poly%d\n", getFillId( aFill ) );
650 }
651 
652 
653 void PS_PLOTTER::PlotImage( const wxImage& aImage, const wxPoint& aPos, double aScaleFactor )
654 {
655  wxSize pix_size; // size of the bitmap in pixels
656  pix_size.x = aImage.GetWidth();
657  pix_size.y = aImage.GetHeight();
658  DPOINT drawsize( aScaleFactor * pix_size.x,
659  aScaleFactor * pix_size.y ); // requested size of image
660 
661  // calculate the bottom left corner position of bitmap
662  wxPoint start = aPos;
663  start.x -= drawsize.x / 2; // left
664  start.y += drawsize.y / 2; // bottom (Y axis reversed)
665 
666  // calculate the top right corner position of bitmap
667  wxPoint end;
668  end.x = start.x + drawsize.x;
669  end.y = start.y - drawsize.y;
670 
671  fprintf( m_outputFile, "/origstate save def\n" );
672  fprintf( m_outputFile, "/pix %d string def\n", pix_size.x );
673 
674  // Locate lower-left corner of image
675  DPOINT start_dev = userToDeviceCoordinates( start );
676  fprintf( m_outputFile, "%g %g translate\n", start_dev.x, start_dev.y );
677  // Map image size to device
678  DPOINT end_dev = userToDeviceCoordinates( end );
679  fprintf( m_outputFile, "%g %g scale\n",
680  std::abs(end_dev.x - start_dev.x), std::abs(end_dev.y - start_dev.y));
681 
682  // Dimensions of source image (in pixels
683  fprintf( m_outputFile, "%d %d 8", pix_size.x, pix_size.y );
684  // Map unit square to source
685  fprintf( m_outputFile, " [%d 0 0 %d 0 %d]\n", pix_size.x, -pix_size.y , pix_size.y);
686  // include image data in ps file
687  fprintf( m_outputFile, "{currentfile pix readhexstring pop}\n" );
688 
689  if( m_colorMode )
690  fputs( "false 3 colorimage\n", m_outputFile );
691  else
692  fputs( "image\n", m_outputFile );
693 
694  // Single data source, 3 colors, Output RGB data (hexadecimal)
695  // (or the same downscaled to gray)
696  int jj = 0;
697 
698  for( int yy = 0; yy < pix_size.y; yy ++ )
699  {
700  for( int xx = 0; xx < pix_size.x; xx++, jj++ )
701  {
702  if( jj >= 16 )
703  {
704  jj = 0;
705  fprintf( m_outputFile, "\n");
706  }
707 
708  int red, green, blue;
709  red = aImage.GetRed( xx, yy) & 0xFF;
710  green = aImage.GetGreen( xx, yy) & 0xFF;
711  blue = aImage.GetBlue( xx, yy) & 0xFF;
712 
713  // PS doesn't support alpha, so premultiply against white background
714  if( aImage.HasAlpha() )
715  {
716  unsigned char alpha = aImage.GetAlpha( xx, yy ) & 0xFF;
717 
718  if( alpha < 0xFF )
719  {
720  float a = 1.0 - ( (float) alpha / 255.0 );
721  red = ( int )( red + ( a * 0xFF ) ) & 0xFF;
722  green = ( int )( green + ( a * 0xFF ) ) & 0xFF;
723  blue = ( int )( blue + ( a * 0xFF ) ) & 0xFF;
724  }
725  }
726 
727  if( aImage.HasMask() )
728  {
729  if( red == aImage.GetMaskRed() && green == aImage.GetMaskGreen()
730  && blue == aImage.GetMaskBlue() )
731  {
732  red = 0xFF;
733  green = 0xFF;
734  blue = 0xFF;
735  }
736  }
737 
738  if( m_colorMode )
739  {
740  fprintf( m_outputFile, "%2.2X%2.2X%2.2X", red, green, blue );
741  }
742  else
743  {
744  // Greyscale conversion (CIE 1931)
745  unsigned char grey = KiROUND( red * 0.2126 + green * 0.7152 + blue * 0.0722 );
746 
747  fprintf( m_outputFile, "%2.2X", grey );
748  }
749  }
750  }
751 
752  fprintf( m_outputFile, "\n");
753  fprintf( m_outputFile, "origstate restore\n" );
754 }
755 
756 
757 void PS_PLOTTER::PenTo( const wxPoint& pos, char plume )
758 {
759  wxASSERT( m_outputFile );
760 
761  if( plume == 'Z' )
762  {
763  if( m_penState != 'Z' )
764  {
765  fputs( "stroke\n", m_outputFile );
766  m_penState = 'Z';
767  m_penLastpos.x = -1;
768  m_penLastpos.y = -1;
769  }
770 
771  return;
772  }
773 
774  if( m_penState == 'Z' )
775  {
776  fputs( "newpath\n", m_outputFile );
777  }
778 
779  if( m_penState != plume || pos != m_penLastpos )
780  {
781  DPOINT pos_dev = userToDeviceCoordinates( pos );
782  fprintf( m_outputFile, "%g %g %sto\n",
783  pos_dev.x, pos_dev.y,
784  ( plume=='D' ) ? "line" : "move" );
785  }
786 
787  m_penState = plume;
788  m_penLastpos = pos;
789 }
790 
791 
793 {
794  wxASSERT( m_outputFile );
795  wxString msg;
796 
797  static const char* PSMacro[] =
798  {
799  "%%BeginProlog\n",
800  "/line { newpath moveto lineto stroke } bind def\n",
801  "/cir0 { newpath 0 360 arc stroke } bind def\n",
802  "/cir1 { newpath 0 360 arc gsave fill grestore stroke } bind def\n",
803  "/cir2 { newpath 0 360 arc gsave fill grestore stroke } bind def\n",
804  "/arc0 { newpath arc stroke } bind def\n",
805  "/arc1 { newpath 4 index 4 index moveto arc closepath gsave fill\n",
806  " grestore stroke } bind def\n",
807  "/arc2 { newpath 4 index 4 index moveto arc closepath gsave fill\n",
808  " grestore stroke } bind def\n",
809  "/poly0 { stroke } bind def\n",
810  "/poly1 { closepath gsave fill grestore stroke } bind def\n",
811  "/poly2 { closepath gsave fill grestore stroke } bind def\n",
812  "/rect0 { rectstroke } bind def\n",
813  "/rect1 { rectfill } bind def\n",
814  "/rect2 { rectfill } bind def\n",
815  "/linemode0 { 0 setlinecap 0 setlinejoin 0 setlinewidth } bind def\n",
816  "/linemode1 { 1 setlinecap 1 setlinejoin } bind def\n",
817  "/dashedline { [200] 100 setdash } bind def\n",
818  "/solidline { [] 0 setdash } bind def\n",
819 
820  // This is for 'hidden' text (search anchors for PDF)
821  "/phantomshow { moveto\n",
822  " /KicadFont findfont 0.000001 scalefont setfont\n",
823  " show } bind def\n",
824 
825  // This is for regular postscript text
826  "/textshow { gsave\n",
827  " findfont exch scalefont setfont concat 1 scale 0 0 moveto show\n",
828  " } bind def\n",
829 
830  // Utility for getting Latin1 encoded fonts
831  "/reencodefont {\n",
832  " findfont dup length dict begin\n",
833  " { 1 index /FID ne\n",
834  " { def }\n",
835  " { pop pop } ifelse\n",
836  " } forall\n",
837  " /Encoding ISOLatin1Encoding def\n",
838  " currentdict\n",
839  " end } bind def\n"
840 
841  // Remap AdobeStandard fonts to Latin1
842  "/KicadFont /Helvetica reencodefont definefont pop\n",
843  "/KicadFont-Bold /Helvetica-Bold reencodefont definefont pop\n",
844  "/KicadFont-Oblique /Helvetica-Oblique reencodefont definefont pop\n",
845  "/KicadFont-BoldOblique /Helvetica-BoldOblique reencodefont definefont pop\n",
846  "%%EndProlog\n",
847  nullptr
848  };
849 
850  time_t time1970 = time( nullptr );
851 
852  fputs( "%!PS-Adobe-3.0\n", m_outputFile ); // Print header
853 
854  fprintf( m_outputFile, "%%%%Creator: %s\n", TO_UTF8( m_creator ) );
855 
856  /* A "newline" character ("\n") is not included in the following string,
857  because it is provided by the ctime() function. */
858  fprintf( m_outputFile, "%%%%CreationDate: %s", ctime( &time1970 ) );
859  fprintf( m_outputFile, "%%%%Title: %s\n", encodeStringForPlotter( m_title ).c_str() );
860  fprintf( m_outputFile, "%%%%Pages: 1\n" );
861  fprintf( m_outputFile, "%%%%PageOrder: Ascend\n" );
862 
863  // Print boundary box in 1/72 pixels per inch, box is in mils
864  const double BIGPTsPERMIL = 0.072;
865 
866  /* The coordinates of the lower left corner of the boundary
867  box need to be "rounded down", but the coordinates of its
868  upper right corner need to be "rounded up" instead. */
869  wxSize psPaperSize = m_pageInfo.GetSizeMils();
870 
871  if( !m_pageInfo.IsPortrait() )
872  psPaperSize.Set( m_pageInfo.GetHeightMils(), m_pageInfo.GetWidthMils() );
873 
874  fprintf( m_outputFile, "%%%%BoundingBox: 0 0 %d %d\n",
875  (int) ceil( psPaperSize.x * BIGPTsPERMIL ),
876  (int) ceil( psPaperSize.y * BIGPTsPERMIL ) );
877 
878  // Specify the size of the sheet and the name associated with that size.
879  // (If the "User size" option has been selected for the sheet size,
880  // identify the sheet size as "Custom" (rather than as "User"), but
881  // otherwise use the name assigned by KiCad for each sheet size.)
882  //
883  // (The Document Structuring Convention also supports sheet weight,
884  // sheet color, and sheet type properties being specified within a
885  // %%DocumentMedia comment, but they are not being specified here;
886  // a zero and two null strings are subsequently provided instead.)
887  //
888  // (NOTE: m_Size.y is *supposed* to be listed before m_Size.x;
889  // the order in which they are specified is not wrong!)
890  // Also note pageSize is given in mils, not in internal units and must be
891  // converted to internal units.
892 
893  if( m_pageInfo.IsCustom() )
894  {
895  fprintf( m_outputFile, "%%%%DocumentMedia: Custom %d %d 0 () ()\n",
896  KiROUND( psPaperSize.x * BIGPTsPERMIL ),
897  KiROUND( psPaperSize.y * BIGPTsPERMIL ) );
898  }
899  else // a standard paper size
900  {
901  fprintf( m_outputFile, "%%%%DocumentMedia: %s %d %d 0 () ()\n",
903  KiROUND( psPaperSize.x * BIGPTsPERMIL ),
904  KiROUND( psPaperSize.y * BIGPTsPERMIL ) );
905  }
906 
907  if( m_pageInfo.IsPortrait() )
908  fprintf( m_outputFile, "%%%%Orientation: Portrait\n" );
909  else
910  fprintf( m_outputFile, "%%%%Orientation: Landscape\n" );
911 
912  fprintf( m_outputFile, "%%%%EndComments\n" );
913 
914  // Now specify various other details.
915 
916  for( int ii = 0; PSMacro[ii] != nullptr; ii++ )
917  {
918  fputs( PSMacro[ii], m_outputFile );
919  }
920 
921  // The following string has been specified here (rather than within
922  // PSMacro[]) to highlight that it has been provided to ensure that the
923  // contents of the postscript file comply with the details specified
924  // within the Document Structuring Convention.
925  fputs( "%%Page: 1 1\n"
926  "%%BeginPageSetup\n"
927  "gsave\n"
928  "0.0072 0.0072 scale\n" // Configure postscript for decimils coordinates
929  "linemode1\n", m_outputFile );
930 
931 
932  // Rototranslate the coordinate to achieve the landscape layout
933  if( !m_pageInfo.IsPortrait() )
934  fprintf( m_outputFile, "%d 0 translate 90 rotate\n", 10 * psPaperSize.x );
935 
936  // Apply the user fine scale adjustments
937  if( plotScaleAdjX != 1.0 || plotScaleAdjY != 1.0 )
938  fprintf( m_outputFile, "%g %g scale\n", plotScaleAdjX, plotScaleAdjY );
939 
940  // Set default line width
941  fprintf( m_outputFile, "%g setlinewidth\n",
943  fputs( "%%EndPageSetup\n", m_outputFile );
944 
945  return true;
946 }
947 
948 
950 {
951  wxASSERT( m_outputFile );
952  fputs( "showpage\n"
953  "grestore\n"
954  "%%EOF\n", m_outputFile );
955  fclose( m_outputFile );
956  m_outputFile = nullptr;
957 
958  return true;
959 }
960 
961 
962 
963 void PS_PLOTTER::Text( const wxPoint& aPos,
964  const COLOR4D& aColor,
965  const wxString& aText,
966  double aOrient,
967  const wxSize& aSize,
968  enum EDA_TEXT_HJUSTIFY_T aH_justify,
969  enum EDA_TEXT_VJUSTIFY_T aV_justify,
970  int aWidth,
971  bool aItalic,
972  bool aBold,
973  bool aMultilineAllowed,
974  void* aData )
975 {
976  SetCurrentLineWidth( aWidth );
977  SetColor( aColor );
978 
979  // Draw the hidden postscript text (if requested)
981  {
982  std::string ps_test = encodeStringForPlotter( aText );
983  DPOINT pos_dev = userToDeviceCoordinates( aPos );
984  fprintf( m_outputFile, "%s %g %g phantomshow\n", ps_test.c_str(), pos_dev.x, pos_dev.y );
985  }
986 
987  PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth,
988  aItalic, aBold, aMultilineAllowed );
989 }
990 
991 
995 const double hv_widths[256] = {
996  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
997  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
998  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
999  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1000  0.278, 0.278, 0.355, 0.556, 0.556, 0.889, 0.667, 0.191,
1001  0.333, 0.333, 0.389, 0.584, 0.278, 0.333, 0.278, 0.278,
1002  0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556,
1003  0.556, 0.556, 0.278, 0.278, 0.584, 0.584, 0.584, 0.556,
1004  1.015, 0.667, 0.667, 0.722, 0.722, 0.667, 0.611, 0.778,
1005  0.722, 0.278, 0.500, 0.667, 0.556, 0.833, 0.722, 0.778,
1006  0.667, 0.778, 0.722, 0.667, 0.611, 0.722, 0.667, 0.944,
1007  0.667, 0.667, 0.611, 0.278, 0.278, 0.278, 0.469, 0.556,
1008  0.333, 0.556, 0.556, 0.500, 0.556, 0.556, 0.278, 0.556,
1009  0.556, 0.222, 0.222, 0.500, 0.222, 0.833, 0.556, 0.556,
1010  0.556, 0.556, 0.333, 0.500, 0.278, 0.556, 0.500, 0.722,
1011  0.500, 0.500, 0.500, 0.334, 0.260, 0.334, 0.584, 0.278,
1012  0.278, 0.278, 0.222, 0.556, 0.333, 1.000, 0.556, 0.556,
1013  0.333, 1.000, 0.667, 0.333, 1.000, 0.278, 0.278, 0.278,
1014  0.278, 0.222, 0.222, 0.333, 0.333, 0.350, 0.556, 1.000,
1015  0.333, 1.000, 0.500, 0.333, 0.944, 0.278, 0.278, 0.667,
1016  0.278, 0.333, 0.556, 0.556, 0.556, 0.556, 0.260, 0.556,
1017  0.333, 0.737, 0.370, 0.556, 0.584, 0.333, 0.737, 0.333,
1018  0.400, 0.584, 0.333, 0.333, 0.333, 0.556, 0.537, 0.278,
1019  0.333, 0.333, 0.365, 0.556, 0.834, 0.834, 0.834, 0.611,
1020  0.667, 0.667, 0.667, 0.667, 0.667, 0.667, 1.000, 0.722,
1021  0.667, 0.667, 0.667, 0.667, 0.278, 0.278, 0.278, 0.278,
1022  0.722, 0.722, 0.778, 0.778, 0.778, 0.778, 0.778, 0.584,
1023  0.778, 0.722, 0.722, 0.722, 0.722, 0.667, 0.667, 0.611,
1024  0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.889, 0.500,
1025  0.556, 0.556, 0.556, 0.556, 0.278, 0.278, 0.278, 0.278,
1026  0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.584,
1027  0.611, 0.556, 0.556, 0.556, 0.556, 0.500, 0.556, 0.500
1028 };
1029 
1030 
1034 const double hvb_widths[256] = {
1035  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1036  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1037  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1038  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1039  0.278, 0.333, 0.474, 0.556, 0.556, 0.889, 0.722, 0.238,
1040  0.333, 0.333, 0.389, 0.584, 0.278, 0.333, 0.278, 0.278,
1041  0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556,
1042  0.556, 0.556, 0.333, 0.333, 0.584, 0.584, 0.584, 0.611,
1043  0.975, 0.722, 0.722, 0.722, 0.722, 0.667, 0.611, 0.778,
1044  0.722, 0.278, 0.556, 0.722, 0.611, 0.833, 0.722, 0.778,
1045  0.667, 0.778, 0.722, 0.667, 0.611, 0.722, 0.667, 0.944,
1046  0.667, 0.667, 0.611, 0.333, 0.278, 0.333, 0.584, 0.556,
1047  0.333, 0.556, 0.611, 0.556, 0.611, 0.556, 0.333, 0.611,
1048  0.611, 0.278, 0.278, 0.556, 0.278, 0.889, 0.611, 0.611,
1049  0.611, 0.611, 0.389, 0.556, 0.333, 0.611, 0.556, 0.778,
1050  0.556, 0.556, 0.500, 0.389, 0.280, 0.389, 0.584, 0.278,
1051  0.278, 0.278, 0.278, 0.556, 0.500, 1.000, 0.556, 0.556,
1052  0.333, 1.000, 0.667, 0.333, 1.000, 0.278, 0.278, 0.278,
1053  0.278, 0.278, 0.278, 0.500, 0.500, 0.350, 0.556, 1.000,
1054  0.333, 1.000, 0.556, 0.333, 0.944, 0.278, 0.278, 0.667,
1055  0.278, 0.333, 0.556, 0.556, 0.556, 0.556, 0.280, 0.556,
1056  0.333, 0.737, 0.370, 0.556, 0.584, 0.333, 0.737, 0.333,
1057  0.400, 0.584, 0.333, 0.333, 0.333, 0.611, 0.556, 0.278,
1058  0.333, 0.333, 0.365, 0.556, 0.834, 0.834, 0.834, 0.611,
1059  0.722, 0.722, 0.722, 0.722, 0.722, 0.722, 1.000, 0.722,
1060  0.667, 0.667, 0.667, 0.667, 0.278, 0.278, 0.278, 0.278,
1061  0.722, 0.722, 0.778, 0.778, 0.778, 0.778, 0.778, 0.584,
1062  0.778, 0.722, 0.722, 0.722, 0.722, 0.667, 0.667, 0.611,
1063  0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.889, 0.556,
1064  0.556, 0.556, 0.556, 0.556, 0.278, 0.278, 0.278, 0.278,
1065  0.611, 0.611, 0.611, 0.611, 0.611, 0.611, 0.611, 0.584,
1066  0.611, 0.611, 0.611, 0.611, 0.611, 0.556, 0.611, 0.556
1067 };
1068 
1069 
1073 const double hvo_widths[256] = {
1074  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1075  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1076  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1077  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1078  0.278, 0.278, 0.355, 0.556, 0.556, 0.889, 0.667, 0.191,
1079  0.333, 0.333, 0.389, 0.584, 0.278, 0.333, 0.278, 0.278,
1080  0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556,
1081  0.556, 0.556, 0.278, 0.278, 0.584, 0.584, 0.584, 0.556,
1082  1.015, 0.667, 0.667, 0.722, 0.722, 0.667, 0.611, 0.778,
1083  0.722, 0.278, 0.500, 0.667, 0.556, 0.833, 0.722, 0.778,
1084  0.667, 0.778, 0.722, 0.667, 0.611, 0.722, 0.667, 0.944,
1085  0.667, 0.667, 0.611, 0.278, 0.278, 0.278, 0.469, 0.556,
1086  0.333, 0.556, 0.556, 0.500, 0.556, 0.556, 0.278, 0.556,
1087  0.556, 0.222, 0.222, 0.500, 0.222, 0.833, 0.556, 0.556,
1088  0.556, 0.556, 0.333, 0.500, 0.278, 0.556, 0.500, 0.722,
1089  0.500, 0.500, 0.500, 0.334, 0.260, 0.334, 0.584, 0.278,
1090  0.278, 0.278, 0.222, 0.556, 0.333, 1.000, 0.556, 0.556,
1091  0.333, 1.000, 0.667, 0.333, 1.000, 0.278, 0.278, 0.278,
1092  0.278, 0.222, 0.222, 0.333, 0.333, 0.350, 0.556, 1.000,
1093  0.333, 1.000, 0.500, 0.333, 0.944, 0.278, 0.278, 0.667,
1094  0.278, 0.333, 0.556, 0.556, 0.556, 0.556, 0.260, 0.556,
1095  0.333, 0.737, 0.370, 0.556, 0.584, 0.333, 0.737, 0.333,
1096  0.400, 0.584, 0.333, 0.333, 0.333, 0.556, 0.537, 0.278,
1097  0.333, 0.333, 0.365, 0.556, 0.834, 0.834, 0.834, 0.611,
1098  0.667, 0.667, 0.667, 0.667, 0.667, 0.667, 1.000, 0.722,
1099  0.667, 0.667, 0.667, 0.667, 0.278, 0.278, 0.278, 0.278,
1100  0.722, 0.722, 0.778, 0.778, 0.778, 0.778, 0.778, 0.584,
1101  0.778, 0.722, 0.722, 0.722, 0.722, 0.667, 0.667, 0.611,
1102  0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.889, 0.500,
1103  0.556, 0.556, 0.556, 0.556, 0.278, 0.278, 0.278, 0.278,
1104  0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.584,
1105  0.611, 0.556, 0.556, 0.556, 0.556, 0.500, 0.556, 0.500
1106 };
1107 
1108 
1112 const double hvbo_widths[256] = {
1113  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1114  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1115  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1116  0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278, 0.278,
1117  0.278, 0.333, 0.474, 0.556, 0.556, 0.889, 0.722, 0.238,
1118  0.333, 0.333, 0.389, 0.584, 0.278, 0.333, 0.278, 0.278,
1119  0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556,
1120  0.556, 0.556, 0.333, 0.333, 0.584, 0.584, 0.584, 0.611,
1121  0.975, 0.722, 0.722, 0.722, 0.722, 0.667, 0.611, 0.778,
1122  0.722, 0.278, 0.556, 0.722, 0.611, 0.833, 0.722, 0.778,
1123  0.667, 0.778, 0.722, 0.667, 0.611, 0.722, 0.667, 0.944,
1124  0.667, 0.667, 0.611, 0.333, 0.278, 0.333, 0.584, 0.556,
1125  0.333, 0.556, 0.611, 0.556, 0.611, 0.556, 0.333, 0.611,
1126  0.611, 0.278, 0.278, 0.556, 0.278, 0.889, 0.611, 0.611,
1127  0.611, 0.611, 0.389, 0.556, 0.333, 0.611, 0.556, 0.778,
1128  0.556, 0.556, 0.500, 0.389, 0.280, 0.389, 0.584, 0.278,
1129  0.278, 0.278, 0.278, 0.556, 0.500, 1.000, 0.556, 0.556,
1130  0.333, 1.000, 0.667, 0.333, 1.000, 0.278, 0.278, 0.278,
1131  0.278, 0.278, 0.278, 0.500, 0.500, 0.350, 0.556, 1.000,
1132  0.333, 1.000, 0.556, 0.333, 0.944, 0.278, 0.278, 0.667,
1133  0.278, 0.333, 0.556, 0.556, 0.556, 0.556, 0.280, 0.556,
1134  0.333, 0.737, 0.370, 0.556, 0.584, 0.333, 0.737, 0.333,
1135  0.400, 0.584, 0.333, 0.333, 0.333, 0.611, 0.556, 0.278,
1136  0.333, 0.333, 0.365, 0.556, 0.834, 0.834, 0.834, 0.611,
1137  0.722, 0.722, 0.722, 0.722, 0.722, 0.722, 1.000, 0.722,
1138  0.667, 0.667, 0.667, 0.667, 0.278, 0.278, 0.278, 0.278,
1139  0.722, 0.722, 0.778, 0.778, 0.778, 0.778, 0.778, 0.584,
1140  0.778, 0.722, 0.722, 0.722, 0.722, 0.667, 0.667, 0.611,
1141  0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.889, 0.556,
1142  0.556, 0.556, 0.556, 0.556, 0.278, 0.278, 0.278, 0.278,
1143  0.611, 0.611, 0.611, 0.611, 0.611, 0.611, 0.611, 0.584,
1144  0.611, 0.611, 0.611, 0.611, 0.611, 0.556, 0.611, 0.556
1145 };
const double hvb_widths[256]
Character widths for Helvetica-Bold.
const double hv_widths[256]
Character widths for Helvetica.
Definition: PS_plotter.cpp:995
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
Definition: PS_plotter.cpp:413
OUTLINE_MODE
Definition: outline_mode.h:24
double GetDotMarkLenIU() const
Definition: plotter.cpp:140
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:61
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_TYPE aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr)=0
Draw a polygon ( filled or not ).
int OutlineCount() const
Return the number of vertices in a given outline/hole.
FILL_TYPE
The set of fill types used in plotting or drawing enclosed areas.
Definition: fill_type.h:28
virtual void emitSetRGBColor(double r, double g, double b) override
Virtual primitive for emitting the setrgbcolor operator.
Definition: PS_plotter.cpp:540
int GetHeightMils() const
Definition: page_info.h:133
virtual void PenTo(const wxPoint &pos, char plume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
Definition: PS_plotter.cpp:757
int color
Definition: DXF_plotter.cpp:60
virtual bool EndPlot() override
Definition: PS_plotter.cpp:949
FILE * m_outputFile
Output file.
Definition: plotter.h:590
double m_iuPerDeviceUnit
Definition: plotter.h:581
virtual void FlashPadRect(const wxPoint &aPadPos, const wxSize &aSize, double aPadOrient, OUTLINE_MODE aTraceMode, void *aData) override
Definition: PS_plotter.cpp:143
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=nullptr) override
Draw text with the plotter.
Definition: PS_plotter.cpp:963
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the current line width (in IUs) for the next plot.
Definition: PS_plotter.cpp:520
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
const wxString & GetType() const
Definition: page_info.h:94
const double hvo_widths[256]
Character widths for Helvetica-Oblique.
bool IsCustom() const
Definition: page_info.cpp:180
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
PLOT_TEXT_MODE m_textMode
How to draw text.
double m_IUsPerDecimil
Definition: plotter.h:579
int PointCount() const
Return the number of points (vertices) in this line chain.
virtual std::string encodeStringForPlotter(const wxString &aUnicode)
convert a wxString unicode string to a char string compatible with the accepted string plotter format...
Definition: PS_plotter.cpp:320
virtual void ThickSegment(const wxPoint &start, const wxPoint &end, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:522
This file contains miscellaneous commonly used macros and functions.
void TransformRoundChamferedRectToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aPosition, const wxSize &aSize, double aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aInflate, int aError, ERROR_LOC aErrorLoc)
Convert a rectangle with rounded corners and/or chamfered corners to a polygon.
virtual void FlashRegularPolygon(const wxPoint &aShapePos, int aDiameter, int aCornerCount, double aOrient, OUTLINE_MODE aTraceMode, void *aData) override
Flash a regular polygon.
Definition: PS_plotter.cpp:312
double GetDashGapLenIU() const
Definition: plotter.cpp:152
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
Definition: plotter.h:573
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
virtual bool StartPlot() override
The code within this function (and the CloseFilePS function) creates postscript files whose contents ...
Definition: PS_plotter.cpp:792
virtual void FlashPadCircle(const wxPoint &aPadPos, int aDiameter, OUTLINE_MODE aTraceMode, void *aData) override
Definition: PS_plotter.cpp:120
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
virtual void SetColor(const COLOR4D &color) override
The SetColor implementation is split with the subclasses: The PSLIKE computes the rgb values,...
Definition: PS_plotter.cpp:64
virtual void FlashPadTrapez(const wxPoint &aPadPos, const wxPoint *aCorners, double aPadOrient, OUTLINE_MODE aTraceMode, void *aData) override
Flash a trapezoidal pad.
Definition: PS_plotter.cpp:266
bool m_plotMirror
Definition: plotter.h:584
bool m_colorMode
Definition: plotter.h:593
int m_currentPenWidth
Definition: plotter.h:595
T AddAngles(T a1, T2 a2)
Add two angles (keeping the result normalized). T2 is here.
Definition: trigo.h:341
virtual void emitSetRGBColor(double r, double g, double b)=0
Virtual primitive for emitting the setrgbcolor operator.
Represent a set of closed polygons.
int returnPostscriptTextWidth(const wxString &aText, int aXSize, bool aItalic, bool aBold)
Sister function for the GraphicTextWidth in drawtxt.cpp Does the same processing (i....
Definition: PS_plotter.cpp:359
SHAPE_LINE_CHAIN & Outline(int aIndex)
wxString m_title
Definition: plotter.h:601
virtual void Arc(const wxPoint &centre, double StAngle, double EndAngle, int rayon, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH) override
Generic fallback: arc rendered as a polyline.
Definition: PS_plotter.cpp:594
wxPoint m_penLastpos
Definition: plotter.h:597
Base window classes and related definitions.
virtual void Circle(const wxPoint &pos, int diametre, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH) override
Definition: PS_plotter.cpp:583
RENDER_SETTINGS * m_renderSettings
Definition: plotter.h:607
const wxSize & GetSizeMils() const
Definition: page_info.h:135
virtual DPOINT userToDeviceSize(const wxSize &size)
Modify size according to the plotter scale factors (wxSize version, returns a DPOINT).
Definition: plotter.cpp:124
bool m_negativeMode
Definition: plotter.h:594
virtual void Circle(const wxPoint &pos, int diametre, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH)=0
PLOT_DASH_TYPE
Dashed line types.
Definition: plotter.h:104
static const double postscriptTextAscent
Height of the postscript font (from the AFM)
Plotting engines similar to ps (PostScript, Gerber, svg)
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:68
Definition: color4d.h:48
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:93
virtual void PlotImage(const wxImage &aImage, const wxPoint &aPos, double aScaleFactor) override
PostScript-likes at the moment are the only plot engines supporting bitmaps.
Definition: PS_plotter.cpp:653
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_TYPE aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr) override
Draw a polygon ( filled or not ).
Definition: PS_plotter.cpp:631
wxPoint m_plotOffset
Definition: plotter.h:583
const double hvbo_widths[256]
Character widths for Helvetica-BoldOblique.
virtual void FlashPadRoundRect(const wxPoint &aPadPos, const wxSize &aSize, int aCornerRadius, double aOrient, OUTLINE_MODE aTraceMode, void *aData) override
Definition: PS_plotter.cpp:192
bool IsPortrait() const
Definition: page_info.h:117
PAGE_INFO m_pageInfo
Definition: plotter.h:602
double GetDashMarkLenIU() const
Definition: plotter.cpp:146
Represent a polyline (an zero-thickness chain of connected line segments).
static int getFillId(FILL_TYPE aFill)
Definition: PS_plotter.cpp:52
double plotScaleAdjX
Fine user scale adjust ( = 1.0 if no correction)
virtual void FlashPadCustom(const wxPoint &aPadPos, const wxSize &aSize, double aOrient, SHAPE_POLY_SET *aPolygons, OUTLINE_MODE aTraceMode, void *aData) override
Definition: PS_plotter.cpp:230
double DECIDEG2RAD(double deg)
Definition: trigo.h:233
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH) override
Definition: PS_plotter.cpp:572
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
int GetPlotterArcHighDef() const
Definition: plotter.h:228
char m_penState
Definition: plotter.h:596
void postscriptOverlinePositions(const wxString &aText, int aXSize, bool aItalic, bool aBold, std::vector< int > *pos_pairs)
Computes the x coordinates for the overlining in a string of text.
Definition: PS_plotter.cpp:382
int GetDefaultPenWidth() const
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=nullptr)
Draw text with the plotter.
Definition: gr_text.cpp:220
void computeTextParameters(const wxPoint &aPos, const wxString &aText, int aOrient, const wxSize &aSize, bool aMirror, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, double *wideningFactor, double *ctm_a, double *ctm_b, double *ctm_c, double *ctm_d, double *ctm_e, double *ctm_f, double *heightFactor)
This is the core for postscript/PDF text alignment.
Definition: PS_plotter.cpp:429
static const int DO_NOT_SET_LINE_WIDTH
Definition: plotter.h:125
wxSize m_paperSize
Definition: plotter.h:603
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
void sketchOval(const wxPoint &pos, const wxSize &size, double orient, int width)
Definition: plotter.cpp:474
int GetWidthMils() const
Definition: page_info.h:130
bool m_mirrorIsHorizontal
Definition: plotter.h:586
virtual void FlashPadOval(const wxPoint &aPadPos, const wxSize &aSize, double aPadOrient, OUTLINE_MODE aTraceMode, void *aData) override
Definition: PS_plotter.cpp:90
wxString m_creator
Definition: plotter.h:599
virtual void SetDash(PLOT_DASH_TYPE dashed) override
PostScript supports dashed lines.
Definition: PS_plotter.cpp:549
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103