32 #include <wx/zstream.h> 33 #include <wx/mstream.h> 50 bool is_ascii7 =
true;
52 for(
size_t ii = 0; ii < aText.Len(); ii++ )
54 if( aText[ii] >= 0x7F )
65 for(
unsigned ii = 0; ii < aText.Len(); ii++ )
67 unsigned int code = aText[ii];
90 for(
size_t ii = 0; ii < aText.Len(); ii++ )
92 unsigned int code = aText[ii];
94 sprintf( buffer,
"%4.4X", code );
123 double aScale,
bool aMirror )
150 wxASSERT_MSG( aWidth > 0,
"Plotter called to set negative pen width" );
162 fprintf(
workFile,
"%g %g %g rg %g %g %g RG\n",
181 fprintf(
workFile,
"[%d %d %d %d] 0 d\n",
198 fprintf(
workFile,
"%g %g %g %g re %c\n", p1_dev.
x, p1_dev.
y,
226 double magic = radius * 0.551784;
230 "%g %g %g %g %g %g c " 231 "%g %g %g %g %g %g c " 232 "%g %g %g %g %g %g c " 233 "%g %g %g %g %g %g c %c\n",
234 pos_dev.
x - radius, pos_dev.
y,
236 pos_dev.
x - radius, pos_dev.
y + magic,
237 pos_dev.
x - magic, pos_dev.
y + radius,
238 pos_dev.
x, pos_dev.
y + radius,
240 pos_dev.
x + magic, pos_dev.
y + radius,
241 pos_dev.
x + radius, pos_dev.
y + magic,
242 pos_dev.
x + radius, pos_dev.
y,
244 pos_dev.
x + radius, pos_dev.
y - magic,
245 pos_dev.
x + magic, pos_dev.
y - radius,
246 pos_dev.
x, pos_dev.
y - radius,
248 pos_dev.
x - magic, pos_dev.
y - radius,
249 pos_dev.
x - radius, pos_dev.
y - magic,
250 pos_dev.
x - radius, pos_dev.
y,
270 const int delta = 50;
272 if( StAngle > EndAngle )
273 std::swap( StAngle, EndAngle );
281 fprintf(
workFile,
"%g %g m ", pos_dev.
x, pos_dev.
y );
282 for(
int ii = StAngle + delta; ii < EndAngle; ii += delta )
287 fprintf(
workFile,
"%g %g l ", pos_dev.
x, pos_dev.
y );
293 fprintf(
workFile,
"%g %g l ", pos_dev.
x, pos_dev.
y );
304 fprintf(
workFile,
"%g %g l b\n", pos_dev.
x, pos_dev.
y );
310 FILL_TYPE aFill,
int aWidth,
void * aData )
314 if( aCornerList.size() <= 1 )
320 fprintf(
workFile,
"%g %g m\n", pos.
x, pos.
y );
322 for(
unsigned ii = 1; ii < aCornerList.size(); ii++ )
325 fprintf(
workFile,
"%g %g l\n", pos.
x, pos.
y );
354 pos_dev.
x, pos_dev.
y,
355 ( plume==
'D' ) ?
'l' :
'm' );
364 double aScaleFactor )
367 wxSize pix_size( aImage.GetWidth(), aImage.GetHeight() );
370 DPOINT drawsize( aScaleFactor * pix_size.x,
371 aScaleFactor * pix_size.y );
374 wxPoint start( aPos.x - drawsize.x / 2,
375 aPos.y + drawsize.y / 2);
389 fprintf(
workFile,
"q %g 0 0 %g %g %g cm\n",
392 dev_start.
x, dev_start.
y );
404 "ID\n",
m_colorMode ?
"/RGB" :
"/G", pix_size.x, pix_size.y );
408 for(
int y = 0; y < pix_size.y; y++ )
410 for(
int x = 0; x < pix_size.x; x++ )
412 unsigned char r = aImage.GetRed( x, y ) & 0xFF;
413 unsigned char g = aImage.GetGreen( x, y ) & 0xFF;
414 unsigned char b = aImage.GetBlue( x, y ) & 0xFF;
417 if( aImage.HasAlpha() )
419 unsigned char alpha = aImage.GetAlpha( x, y ) & 0xFF;
423 float a = 1.0 - ( (float) alpha / 255.0 );
424 r = ( int )( r + ( a * 0xFF ) ) & 0xFF;
425 g = ( int )( g + ( a * 0xFF ) ) & 0xFF;
426 b = ( int )( b + ( a * 0xFF ) ) & 0xFF;
430 if( aImage.HasMask() )
432 if( r == aImage.GetMaskRed() && g == aImage.GetMaskGreen()
433 && b == aImage.GetMaskBlue() )
451 unsigned char grey =
KiROUND( r * 0.2126 + g * 0.7152 + b * 0.0722 );
503 "<< /Length %d 0 R >>\n" 504 "stream\n", handle + 1 );
509 "<< /Length %d 0 R /Filter /FlateDecode >>\n" 510 "stream\n", handle + 1 );
525 long stream_len = ftell(
workFile );
535 unsigned char *inbuf =
new unsigned char[stream_len];
537 int rc = fread( inbuf, 1, stream_len,
workFile );
538 wxASSERT( rc == stream_len );
550 out_count = stream_len;
556 wxMemoryOutputStream memos(
NULL, std::max( 2000l, stream_len ) ) ;
566 wxZlibOutputStream zos( memos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB );
568 zos.Write( inbuf, stream_len );
571 wxStreamBuffer* sb = memos.GetOutputStreamBuffer();
573 out_count = sb->Tell();
574 fwrite( sb->GetBufferStart(), 1, out_count,
m_outputFile );
606 "%g 0 0 %g 0 0 cm 1 J 1 j 0 0 0 rg 0 0 0 RG %g w\n",
628 const double BIGPTsPERMIL = 0.072;
636 " /ProcSet [/PDF /Text /ImageC /ImageB]\n" 638 "/MediaBox [0 0 %d %d]\n" 643 int( ceil( psPaperSize.x * BIGPTsPERMIL ) ),
644 int( ceil( psPaperSize.y * BIGPTsPERMIL ) ),
697 {
"/Helvetica",
"/KicadFont", 0 },
698 {
"/Helvetica-Oblique",
"/KicadFontI", 0 },
699 {
"/Helvetica-Bold",
"/KicadFontB", 0 },
700 {
"/Helvetica-BoldOblique",
"/KicadFontBI", 0 }
706 for(
int i = 0; i < 4; i++ )
716 " /Encoding /WinAnsiEncoding\n" 718 fontdefs[i].psname );
726 for(
int i = 0; i < 4; i++ )
729 fontdefs[i].rsname, fontdefs[i].font_handle );
756 time_t ltime = time(
NULL );
757 strftime( date_buf, 250,
"D:%Y%m%d%H%M%S",
758 localtime( <ime ) );
769 "/Producer (KiCad PDF)\n" 770 "/CreationDate (%s)\n" 788 "/PageMode /UseNone\n" 789 "/PageLayout /SinglePage\n" 800 "0000000000 65535 f \n", (
long)
xrefTable.size() );
802 for(
unsigned i = 1; i <
xrefTable.size(); i++ )
810 "<< /Size %lu /Root %d 0 R /Info %d 0 R >>\n" 814 (
unsigned long)
xrefTable.size(), catalogHandle, infoDictHandle, xref_start );
825 const wxString& aText,
833 bool aMultilineAllowed,
837 if( aSize.x == 0 || aSize.y == 0 )
844 const char *fontname = aItalic ? ( aBold ?
"/KicadFontBI" :
"/KicadFontI" )
845 : ( aBold ?
"/KicadFontB" :
"/KicadFont" );
848 double ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f;
849 double wideningFactor, heightFactor;
852 aV_justify, aWidth, aItalic, aBold,
853 &wideningFactor, &ctm_a, &ctm_b, &ctm_c,
854 &ctm_d, &ctm_e, &ctm_f, &heightFactor );
863 fprintf(
workFile,
"q %f %f %f %f %g %g cm BT %s %g Tf %d Tr %g Tz ",
864 ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f,
865 fontname, heightFactor, render_mode, wideningFactor * 100 );
869 fprintf(
workFile,
"%s Tj ET\n", txt_pdf.c_str() );
875 PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth,
876 aItalic, aBold, aMultilineAllowed );
double GetDotMarkLenIU() const
void closePdfStream()
Finish the current PDF stream (writes the deferred length, too)
FILL_TYPE
The set of fill types used in plotting or drawing enclosed areas.
virtual bool EndPlot() override
virtual void StartPage()
Starts a new page in the PDF document.
FILE * m_outputFile
Output file.
virtual void PenTo(const wxPoint &pos, char plume) override
moveto/lineto primitive, moves the 'pen' to the specified direction
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.
std::vector< int > pageHandles
Font resource dictionary.
virtual void SetDash(PLOT_DASH_TYPE dashed) override
PDF supports dashed lines.
virtual void Arc(const wxPoint ¢re, double StAngle, double EndAngle, int rayon, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH) override
The PDF engine can't directly plot arcs, it uses the base emulation.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH) override
Rectangles in PDF.
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.
wxString workFilename
Handle to the deferred stream length.
double GetDashGapLenIU() const
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
virtual void ClosePage()
Close the current page in the PDF document (and emit its compressed stream)
int streamLengthHandle
Handle of the page content object.
static const int USE_DEFAULT_LINE_WIDTH
int startPdfStream(int handle=-1)
Starts a PDF stream (for the page).
int startPdfObject(int handle=-1)
Open a new PDF object and returns the handle if the parameter is -1.
virtual void SetViewport(const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
PDF can have multiple pages, so SetPageSettings can be called with the outputFile open (but not insid...
virtual void SetColor(COLOR4D color) override
The SetColor implementation is split with the subclasses: The PSLIKE computes the rgb values,...
std::string encodeStringForPlotter(const wxString &aUnicode) override
convert a wxString unicode string to a char string compatible with the accepted string PDF format (co...
RENDER_SETTINGS * m_renderSettings
const wxSize & GetSizeMils() const
virtual DPOINT userToDeviceSize(const wxSize &size)
Modifies size according to the plotter scale factors (wxSize version, returns a DPOINT)
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_TYPE aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=NULL) override
Polygon plotting for PDF.
void closePdfObject()
Close the current PDF object.
PLOT_DASH_TYPE
Dashed line types.
Plotting engines similar to ps (PostScript, Gerber, svg)
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modifies coordinates according to the orientation, scale factor, and offsets trace.
int fontResDictHandle
Handle to the root of the page tree object.
double cosdecideg(double r, double a)
Circle generation utility: computes r * cos(a) Where a is in decidegrees, not in radians.
double sindecideg(double r, double a)
Circle generation utility: computes r * sin(a) Where a is in decidegrees, not in radians.
virtual void emitSetRGBColor(double r, double g, double b) override
PDF supports colors fully.
std::vector< long > xrefTable
Temporary file to construct the stream before zipping.
double GetDashMarkLenIU() const
double plotScaleAdjX
Fine user scale adjust ( = 1.0 if no correction)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
int GetDefaultPenWidth() const
virtual bool OpenFile(const wxString &aFullFilename) override
Open or create the plot file aFullFilename.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
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 It computes the transformation matrix to generate ...
virtual bool StartPlot() override
The PDF engine supports multiple pages; the first one is opened 'for free' the following are to be cl...
static const int DO_NOT_SET_LINE_WIDTH
int allocPdfObject()
Allocate a new handle in the table of the PDF object.
virtual void Circle(const wxPoint &pos, int diametre, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH) override
Circle drawing for PDF.
int pageStreamHandle
Handles to the page objects.
virtual void SetCurrentLineWidth(int width, void *aData=NULL) override
Pen width setting for PDF.
A color representation with 4 components: red, green, blue, alpha.
virtual void PlotImage(const wxImage &aImage, const wxPoint &aPos, double aScaleFactor) override
PDF images are handles as inline, not XObject streams...