34#include <wx/filename.h>
35#include <wx/mstream.h>
36#include <wx/zstream.h>
37#include <wx/wfstream.h>
38#include <wx/datstrm.h>
39#include <wx/tokenzr.h>
49#include <fmt/format.h>
50#include <fmt/chrono.h>
64 bool is_ascii7 =
true;
66 for(
size_t ii = 0; ii < aText.Len(); ii++ )
68 if( aText[ii] >= 0x7F )
79 for(
unsigned ii = 0; ii < aText.Len(); ii++ )
81 unsigned int code = aText[ii];
104 for(
size_t ii = 0; ii < aText.Len(); ii++ )
106 unsigned int code = aText[ii];
107 result += fmt::format(
"{:04X}", code);
134 double aScale,
bool aMirror )
161 wxASSERT_MSG( aWidth > 0,
"Plotter called to set negative pen width" );
178 r = ( r * a ) + ( 1 - a );
179 g = ( g * a ) + ( 1 - a );
180 b = ( b * a ) + ( 1 - a );
183 fmt::println(
m_workFile,
"{:g} {:g} {:g} rg {:g} {:g} {:g} RG", r, g, b, r, g, b );
193 case LINE_STYLE::DASH:
198 case LINE_STYLE::DOT:
203 case LINE_STYLE::DASHDOT:
204 fmt::println(
m_workFile,
"[{} {} {} {}] 0 d",
209 case LINE_STYLE::DASHDOTDOT:
210 fmt::println(
m_workFile,
"[{} {} {} {} {} {}] 0 d",
226 if( fill == FILL_T::NO_FILL && width <= 0 )
233 if( size.
x == 0 && size.
y == 0 )
245 std::vector<VECTOR2I> cornerList;
247 cornerList.emplace_back( p1.
x, p1.
y );
248 cornerList.emplace_back( p2.
x, p1.
y );
249 cornerList.emplace_back( p2.
x, p2.
y );
250 cornerList.emplace_back( p1.
x, p2.
y );
251 cornerList.emplace_back( p1.
x, p1.
y );
253 PlotPoly( cornerList, fill, width,
nullptr );
263 if( fill == FILL_T::NO_FILL )
266 paintOp = width > 0 ?
'B' :
'f';
268 fmt::println(
m_workFile,
"{:g} {:g} {:g} {:g} re {}", p1_dev.
x, p1_dev.
y, p2_dev.
x - p1_dev.
x,
269 p2_dev.
y - p1_dev.
y, paintOp );
277 if( aFill == FILL_T::NO_FILL && width <= 0 )
292 if( aFill == FILL_T::NO_FILL && diametre < width )
294 aFill = FILL_T::FILLED_SHAPE;
300 double magic =
radius * 0.551784;
305 "{:g} {:g} {:g} {:g} {:g} {:g} c "
306 "{:g} {:g} {:g} {:g} {:g} {:g} c "
307 "{:g} {:g} {:g} {:g} {:g} {:g} c "
308 "{:g} {:g} {:g} {:g} {:g} {:g} c {}",
311 pos_dev.
x -
radius, pos_dev.
y + magic,
312 pos_dev.
x - magic, pos_dev.
y +
radius,
315 pos_dev.
x + magic, pos_dev.
y +
radius,
316 pos_dev.
x +
radius, pos_dev.
y + magic,
319 pos_dev.
x +
radius, pos_dev.
y - magic,
320 pos_dev.
x + magic, pos_dev.
y -
radius,
323 pos_dev.
x - magic, pos_dev.
y -
radius,
324 pos_dev.
x -
radius, pos_dev.
y - magic,
327 aFill == FILL_T::NO_FILL ?
's' :
'b' );
338 Circle( aCenter, aWidth, FILL_T::FILLED_SHAPE, 0 );
347 EDA_ANGLE endAngle = startAngle - aAngle;
352 if( startAngle > endAngle )
353 std::swap( startAngle, endAngle );
358 start.
x =
KiROUND( aCenter.
x + aRadius * ( -startAngle ).Cos() );
359 start.
y =
KiROUND( aCenter.
y + aRadius * ( -startAngle ).Sin() );
361 fmt::print(
m_workFile,
"{:g} {:g} m ", pos_dev.
x, pos_dev.
y );
368 fmt::print(
m_workFile,
"{:g} {:g} l ", pos_dev.
x, pos_dev.
y );
371 end.
x =
KiROUND( aCenter.
x + aRadius * ( -endAngle ).Cos() );
372 end.
y =
KiROUND( aCenter.
y + aRadius * ( -endAngle ).Sin() );
374 fmt::print(
m_workFile,
"{:g} {:g} l ", pos_dev.
x, pos_dev.
y );
378 if( aFill == FILL_T::NO_FILL )
385 fmt::println(
m_workFile,
"{:g} {:g} l b", pos_dev.
x, pos_dev.
y );
395 if( aFill == FILL_T::NO_FILL && aWidth <= 0 )
398 if( aCornerList.size() <= 1 )
404 fmt::println(
m_workFile,
"{:f} {:f} m", pos.
x, pos.
y );
406 for(
unsigned ii = 1; ii < aCornerList.size(); ii++ )
409 fmt::println(
m_workFile,
"{:f} {:f} l", pos.
x, pos.
y );
413 if( aFill == FILL_T::NO_FILL )
415 else if( aWidth == 0 )
443 pos_dev.
x, pos_dev.
y,
444 ( plume==
'D' ) ?
'l' :
'm' );
455 VECTOR2I pix_size( aImage.GetWidth(), aImage.GetHeight() );
458 VECTOR2D drawsize( aScaleFactor * pix_size.
x, aScaleFactor * pix_size.
y );
461 VECTOR2I start( aPos.
x - drawsize.
x / 2, aPos.
y + drawsize.
y / 2 );
465 auto findHandleForImage = [&](
const wxImage& aCurrImage ) ->
int
469 if(
image.IsSameAs( aCurrImage ) )
472 if(
image.GetWidth() != aCurrImage.GetWidth() )
475 if(
image.GetHeight() != aCurrImage.GetHeight() )
478 if(
image.GetType() != aCurrImage.GetType() )
481 if(
image.HasAlpha() != aCurrImage.HasAlpha() )
484 if(
image.HasMask() != aCurrImage.HasMask()
485 ||
image.GetMaskRed() != aCurrImage.GetMaskRed()
486 ||
image.GetMaskGreen() != aCurrImage.GetMaskGreen()
487 ||
image.GetMaskBlue() != aCurrImage.GetMaskBlue() )
490 int pixCount =
image.GetWidth() *
image.GetHeight();
492 if( memcmp(
image.GetData(), aCurrImage.GetData(), pixCount * 3 ) != 0 )
496 && memcmp(
image.GetAlpha(), aCurrImage.GetAlpha(), pixCount ) != 0 )
505 int imgHandle = findHandleForImage( aImage );
507 if( imgHandle == -1 )
523 fmt::println(
m_workFile,
"q {:g} 0 0 {:g} {:g} {:g} cm",
526 dev_start.
x, dev_start.
y );
528 fmt::println(
m_workFile,
"/Im{} Do", imgHandle );
575 "<< /Length {} 0 R >>\nstream", handle + 1 );
580 "<< /Length {} 0 R /Filter /FlateDecode >>\n"
581 "stream", handle + 1 );
606 unsigned char *inbuf =
new unsigned char[stream_len];
608 int rc = fread( inbuf, 1, stream_len,
m_workFile );
609 wxASSERT( rc == stream_len );
621 out_count = stream_len;
627 wxMemoryOutputStream memos(
nullptr, std::max( 2000l, stream_len ) ) ;
637 wxZlibOutputStream zos( memos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB );
639 zos.Write( inbuf, stream_len );
642 wxStreamBuffer* sb = memos.GetOutputStreamBuffer();
644 out_count = sb->Tell();
645 fwrite( sb->GetBufferStart(), 1, out_count,
m_outputFile );
660 const wxString& aParentPageNumber,
const wxString& aParentPageName )
667 ? wxString::Format(
_(
"Page %s" ), aPageNumber )
668 : wxString::Format(
_(
"%s (Page %s)" ), aPageName, aPageNumber );
670 ? wxString::Format(
_(
"Page %s" ), aParentPageNumber )
671 : wxString::Format(
_(
"%s (Page %s)" ), aParentPageName, aParentPageNumber );
686 "{:g} 0 0 {:g} 0 0 cm 1 J 1 j 0 0 0 rg 0 0 0 RG {:g} w",
692void WriteImageStream(
const wxImage& aImage, wxDataOutputStream& aOut, wxColor bg,
bool colorMode )
694 int w = aImage.GetWidth();
695 int h = aImage.GetHeight();
697 for(
int y = 0; y < h; y++ )
699 for(
int x = 0; x < w; x++ )
701 unsigned char r = aImage.GetRed( x, y ) & 0xFF;
702 unsigned char g = aImage.GetGreen( x, y ) & 0xFF;
703 unsigned char b = aImage.GetBlue( x, y ) & 0xFF;
705 if( aImage.HasMask() )
707 if( r == aImage.GetMaskRed() && g == aImage.GetMaskGreen()
708 && b == aImage.GetMaskBlue() )
725 unsigned char grey =
KiROUND( r * 0.2126 + g * 0.7152 + b * 0.0722 );
736 int w = aImage.GetWidth();
737 int h = aImage.GetHeight();
739 if( aImage.HasMask() )
741 for(
int y = 0; y < h; y++ )
743 for(
int x = 0; x < w; x++ )
745 unsigned char a = 255;
746 unsigned char r = aImage.GetRed( x, y );
747 unsigned char g = aImage.GetGreen( x, y );
748 unsigned char b = aImage.GetBlue( x, y );
750 if( r == aImage.GetMaskRed() && g == aImage.GetMaskGreen()
751 && b == aImage.GetMaskBlue() )
760 else if( aImage.HasAlpha() )
763 aOut.Write8( aImage.GetAlpha(), size );
778 const double PTsPERMIL = 0.072;
781 auto iuToPdfUserSpace =
794 retval.
x = ( psPaperSize.
x - pos.
x );
803 std::vector<int> hyperlinkHandles;
809 const BOX2I& box = linkPair.first;
810 const wxString& url = linkPair.second;
817 userSpaceBox.
SetEnd( topRight );
826 const BOX2I& box = menuPair.first;
827 const std::vector<wxString>& urls = menuPair.second;
834 userSpaceBox.
SetEnd( topRight );
841 int hyperLinkArrayHandle = -1;
844 if( hyperlinkHandles.size() > 0 )
851 for(
int handle : hyperlinkHandles )
874 " /ProcSet [/PDF /Text /ImageC /ImageB]\n"
876 " /XObject {} 0 R >>\n"
877 "/MediaBox [0 0 {:g} {:g}]\n"
878 "/Contents {} 0 R\n",
886 if( hyperlinkHandles.size() > 0 )
887 fmt::print(
m_outputFile,
"/Annots {} 0 R", hyperLinkArrayHandle );
902 std::stack<OUTLINE_NODE*> nodes;
905 while( !nodes.empty() )
931 for(
const std::pair<BOX2I, wxString>& bookmarkPair : groupVector )
933 const BOX2I& box = bookmarkPair.first;
934 const wxString& ref = bookmarkPair.second;
939 actionHandle =
emitGoToAction( pageHandle, bottomLeft, topRight );
944 std::sort( groupOutlineNode->
children.begin(), groupOutlineNode->
children.end(),
947 return a->title < b->title;
960 return StartPlot( aPageNumber, wxEmptyString );
983 fmt::print(
m_outputFile,
"%PDF-1.5\n%\200\201\202\203\n" );
1011 "<</S /GoTo /D [{} 0 R /FitR {} {} {} {}]\n"
1013 aPageHandle, aBottomLeft.
x, aBottomLeft.
y, aTopRight.
x, aTopRight.
y );
1017 return actionHandle;
1027 "<</S /GoTo /D [{} 0 R /Fit]\n"
1033 return actionHandle;
1041 int prevHandle = -1;
1042 int nextHandle = -1;
1044 for( std::vector<OUTLINE_NODE*>::iterator it = node->
children.begin();
1047 if( it >= node->
children.end() - 1 )
1053 nextHandle = ( *( it + 1 ) )->entryHandle;
1058 prevHandle = ( *it )->entryHandle;
1062 if( parentHandle != -1 )
1075 fmt::println(
m_outputFile,
"/Next {} 0 R", nextNode );
1080 fmt::println(
m_outputFile,
"/Prev {} 0 R", prevNode );
1085 int32_t count = -1 *
static_cast<int32_t
>( node->
children.size() );
1103 const wxString& aTitle )
1124 "<< /Type /Outlines\n"
1160 {
"/Helvetica",
"/KicadFont", 0 },
1161 {
"/Helvetica-Oblique",
"/KicadFontI", 0 },
1162 {
"/Helvetica-Bold",
"/KicadFontB", 0 },
1163 {
"/Helvetica-BoldOblique",
"/KicadFontBI", 0 }
1169 for(
int i = 0; i < 4; i++ )
1173 "<< /BaseFont {}\n /Type /Font\n /Subtype /Type1\n /Encoding /WinAnsiEncoding\n>>",
1174 fontdefs[i].psname );
1182 for(
int i = 0; i < 4; i++ )
1185 fontdefs[i].rsname, fontdefs[i].font_handle );
1197 fmt::print(
m_outputFile,
" /Im{} {} 0 R\n", imgHandle, imgHandle );
1218 "/BitsPerComponent 8\n"
1222 "/Filter /FlateDecode\n"
1227 if( smaskHandle != -1 )
1228 fmt::println(
m_outputFile,
"/SMask {} 0 R", smaskHandle );
1236 wxFFileOutputStream ffos( outputFFile );
1237 wxZlibOutputStream zos( ffos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB );
1238 wxDataOutputStream dos( zos );
1244 long imgStreamSize = ftell(
m_outputFile ) - imgStreamStart;
1253 if( smaskHandle != -1 )
1263 "/BitsPerComponent 8\n"
1264 "/ColorSpace /DeviceGray\n"
1268 "/Filter /FlateDecode\n"
1270 image.GetWidth(),
image.GetHeight(), smaskLenHandle );
1277 wxFFileOutputStream ffos( outputFFile );
1278 wxZlibOutputStream zos( ffos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB );
1279 wxDataOutputStream dos( zos );
1284 long smaskStreamSize = ftell(
m_outputFile ) - smaskStreamStart;
1290 fmt::println(
m_outputFile,
"{}", (
unsigned) smaskStreamSize );
1294 outputFFile.Detach();
1299 BOX2D box = linkPair.first;
1300 wxString url = linkPair.second;
1308 "/Rect [{:g} {:g} {:g} {:g}]\n"
1309 "/Border [16 16 0]\n",
1312 wxString pageNumber;
1313 bool pageFound =
false;
1322 "/Dest [{} 0 R /FitB]\n"
1334 fmt::print(
m_outputFile,
"/A << /Type /Action /S /NOP >>\n"
1344 "/A << /Type /Action /S /URI /URI {} >>\n"
1354 const BOX2D& box = menuPair.first;
1355 const std::vector<wxString>& urls = menuPair.second;
1356 wxString js = wxT(
"ShM([\n" );
1358 for(
const wxString& url : urls )
1360 if( url.StartsWith(
"!" ) )
1362 wxString
property = url.AfterFirst(
'!' );
1364 if( property.Find(
"http:" ) >= 0 )
1366 wxString href =
property.substr( property.Find(
"http:" ) );
1371 js += wxString::Format( wxT(
"[\"%s\", \"%s\"],\n" ),
1375 else if( property.Find(
"https:" ) >= 0 )
1377 wxString href =
property.substr( property.Find(
"https:" ) );
1382 js += wxString::Format( wxT(
"[\"%s\", \"%s\"],\n" ),
1386 else if( property.Find(
"file:" ) >= 0 )
1388 wxString href =
property.substr( property.Find(
"file:" ) );
1395 js += wxString::Format( wxT(
"[\"%s\", \"%s\"],\n" ),
1401 js += wxString::Format( wxT(
"[\"%s\"],\n" ),
1405 else if( url.StartsWith(
"#" ) )
1407 wxString pageNumber = url.AfterFirst(
'#' );
1413 wxString menuText = wxString::Format(
_(
"Show Page %s" ), pageNumber );
1415 js += wxString::Format( wxT(
"[\"%s\", \"#%d\"],\n" ),
1417 static_cast<int>( ii ) );
1422 else if( url.StartsWith(
"http:" ) || url.StartsWith(
"https:" )
1423 || url.StartsWith(
"file:" ) )
1425 wxString href = url;
1430 if( url.StartsWith(
"file:" ) )
1433 wxString menuText = wxString::Format(
_(
"Open %s" ), href );
1435 js += wxString::Format( wxT(
"[\"%s\", \"%s\"],\n" ),
1449 "/Rect [{:g} {:g} {:g} {:g}]\n"
1450 "/Border [16 16 0]\n",
1454 "/A << /Type /Action /S /JavaScript /JS {} >>\n"
1465function ShM(aEntries) {
1467 for (var i in aEntries) {
1469 cName: aEntries[i][0],
1470 cReturn: aEntries[i][1]
1474 var cChoice = app.popUpMenuEx.apply(app, aParams);
1475 if (cChoice != null && cChoice.substring(0, 1) == '#') this.pageNum = parseInt(cChoice.slice(1));
1476 else if (cChoice != null && cChoice.substring(0, 4) == 'http') app.launchURL(cChoice);
1477 else if (cChoice != null && cChoice.substring(0, 4) == 'file') app.openDoc(cChoice.substring(7));
1484 " [ (JSInit) << /Type /Action /S /JavaScript /JS {} >> ]\n"
1512 std::string dt = fmt::format(
"D:{:%Y:%m:%d:%H:%M:%S}", fmt::localtime( std::time(
nullptr ) ) );
1523 "/Producer (KiCad PDF)\n"
1524 "/CreationDate ({})\n"
1544 if( outlineHandle > 0 )
1547 "<<\n/Type /Catalog\n/Pages {} 0 R\n/Version /1.5\n/PageMode /UseOutlines\n/Outlines {} 0 R\n/Names {} 0 R\n/PageLayout /SinglePage\n>>",
1555 "<<\n/Type /Catalog\n/Pages {} 0 R\n/Version /1.5\n/PageMode /UseNone\n/PageLayout /SinglePage\n>>",
1570 for(
unsigned i = 1; i <
m_xrefTable.size(); i++ )
1578 "<< /Size {} /Root {} 0 R /Info {} 0 R >>\n"
1582 m_xrefTable.size(), catalogHandle, infoDictHandle, xref_start );
1593 const wxString& aText,
1601 bool aMultilineAllowed,
1607 if( aSize.
x == 0 || aSize.
y == 0 )
1612 int render_mode = 3;
1615 const char *fontname = aItalic ? ( aBold ?
"/KicadFontBI" :
"/KicadFontI" )
1616 : ( aBold ?
"/KicadFontB" :
"/KicadFont" );
1619 double ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f;
1620 double wideningFactor, heightFactor;
1623 bool textMirrored = aSize.
x < 0;
1626 aWidth, aItalic, aBold, &wideningFactor, &ctm_a, &ctm_b, &ctm_c, &ctm_d,
1627 &ctm_e, &ctm_f, &heightFactor );
1632 wxStringTokenizer str_tok( aText,
" ", wxTOKEN_RET_DELIMS );
1660 while( str_tok.HasMoreTokens() )
1662 wxString word = str_tok.GetNextToken();
1666 &ctm_a, &ctm_b, &ctm_c, &ctm_d, &ctm_e, &ctm_f, &heightFactor );
1671 aBold, aItalic, aFontMetrics ).
x, 0 );
1680 if( word.Trim(
false ).Trim(
true ).empty() )
1687 fmt::print(
m_workFile,
"q {:f} {:f} {:f} {:f} {:f} {:f} cm BT {} {:g} Tf {} Tr {:g} Tz ",
1688 ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f,
1689 fontname, heightFactor, render_mode, wideningFactor * 100 );
1692 fmt::println(
m_workFile,
"{} Tj ET", txt_pdf );
1698 PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,
1699 aBold, aMultilineAllowed, aFont, aFontMetrics );
1705 const wxString& aText,
1714 if( size.
x == 0 || size.
y == 0 )
1739 const wxString &aGroupName )
1742 m_bookmarksInPage[aGroupName].push_back( std::make_pair( aLocation, aSymbolReference ) );
void WriteImageSMaskStream(const wxImage &aImage, wxDataOutputStream &aOut)
void WriteImageStream(const wxImage &aImage, wxDataOutputStream &aOut, wxColor bg, bool colorMode)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
constexpr const Vec & GetPosition() const
constexpr const Vec GetEnd() const
constexpr void SetOrigin(const Vec &pos)
constexpr coord_type GetLeft() const
constexpr coord_type GetRight() const
constexpr void SetEnd(coord_type x, coord_type y)
constexpr coord_type GetTop() const
constexpr coord_type GetBottom() const
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
FONT is an abstract base class for both outline and stroke fonts.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
VECTOR2I StringBoundaryLimits(const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
Compute the boundary limits of aText (the bounding box of all shapes).
A color representation with 4 components: red, green, blue, alpha.
wxColour ToColour() const
int GetDefaultPenWidth() const
virtual const COLOR4D & GetBackgroundColor() const =0
Return current background color settings.
const VECTOR2D & GetSizeMils() const
std::vector< int > m_pageHandles
Handles to the page objects.
FILE * m_workFile
Temporary file to construct the stream before zipping.
wxString m_parentPageName
virtual void ClosePage()
Close the current page in the PDF document (and emit its compressed stream).
void emitOutlineNode(OUTLINE_NODE *aNode, int aParentHandle, int aNextNode, int aPrevNode)
Emits a outline item object and recurses into any children.
std::map< int, wxImage > m_imageHandles
int emitOutline()
Starts emitting the outline object.
virtual bool EndPlot() override
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr) override
Polygon plotting for PDF.
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Pen width setting for PDF.
int m_streamLengthHandle
Handle to the deferred stream length.
void PlotImage(const wxImage &aImage, const VECTOR2I &aPos, double aScaleFactor) override
PDF images are handles as inline, not XObject streams...
int m_jsNamesHandle
Handle for Names dictionary with JS.
virtual void SetDash(int aLineWidth, LINE_STYLE aLineStyle) override
PDF supports dashed lines.
void HyperlinkMenu(const BOX2I &aBox, const std::vector< wxString > &aDestURLs) override
Create a clickable hyperlink menu with a rectangular click area.
virtual bool OpenFile(const wxString &aFullFilename) override
Open or create the plot file aFullFilename.
int m_fontResDictHandle
Font resource dictionary.
virtual void emitSetRGBColor(double r, double g, double b, double a) override
PDF supports colors fully.
int startPdfStream(int handle=-1)
Start a PDF stream (for the page).
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
Rectangles in PDF.
virtual void Arc(const VECTOR2D &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH) override
The PDF engine can't directly plot arcs so we use polygonization.
std::map< int, std::pair< BOX2D, wxString > > m_hyperlinkHandles
Handles for all the hyperlink objects that will be deferred.
int m_pageTreeHandle
Handle to the root of the page tree object.
virtual void Text(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr) override
Draw text with the plotter.
int emitGoToAction(int aPageHandle, const VECTOR2I &aBottomLeft, const VECTOR2I &aTopRight)
Emit an action object that instructs a goto coordinates on a page.
void closePdfStream()
Finish the current PDF stream (writes the deferred length, too).
void Bookmark(const BOX2I &aBox, const wxString &aName, const wxString &aGroupName=wxEmptyString) override
Create a bookmark to a symbol.
std::vector< long > m_xrefTable
The PDF xref offset table.
void HyperlinkBox(const BOX2I &aBox, const wxString &aDestinationURL) override
Create a clickable hyperlink with a rectangular click area.
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
Circle drawing for PDF.
virtual void PenTo(const VECTOR2I &pos, char plume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
std::map< wxString, std::vector< std::pair< BOX2I, wxString > > > m_bookmarksInPage
virtual bool StartPlot(const wxString &aPageNumber) override
The PDF engine supports multiple pages; the first one is opened 'for free' the following are to be cl...
int startPdfObject(int handle=-1)
Open a new PDF object and returns the handle if the parameter is -1.
virtual void StartPage(const wxString &aPageNumber, const wxString &aPageName=wxEmptyString, const wxString &aParentPageNumber=wxEmptyString, const wxString &aParentPageName=wxEmptyString)
Start a new page in the PDF document.
OUTLINE_NODE * addOutlineNode(OUTLINE_NODE *aParent, int aActionHandle, const wxString &aTitle)
Add a new outline node entry.
int m_imgResDictHandle
Image resource dictionary.
std::string encodeStringForPlotter(const wxString &aUnicode) override
convert a wxString unicode string to a char string compatible with the accepted string PDF format (co...
std::vector< wxString > m_pageNumbers
List of user-space page numbers for resolving internal hyperlinks.
int allocPdfObject()
Allocate a new handle in the table of the PDF object.
virtual void SetViewport(const VECTOR2I &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...
std::map< int, std::pair< BOX2D, std::vector< wxString > > > m_hyperlinkMenuHandles
int m_pageStreamHandle
Handle of the page content object.
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr) override
std::vector< std::pair< BOX2I, wxString > > m_hyperlinksInPage
List of loaded hyperlinks in current page.
std::unique_ptr< OUTLINE_NODE > m_outlineRoot
Root outline node.
std::vector< std::pair< BOX2I, std::vector< wxString > > > m_hyperlinkMenusInPage
void closePdfObject()
Close the current PDF object.
int m_totalOutlineNodes
Total number of outline nodes.
double GetDotMarkLenIU(int aLineWidth) const
double GetDashGapLenIU(int aLineWidth) const
const PROJECT * m_project
bool m_mirrorIsHorizontal
static const int USE_DEFAULT_LINE_WIDTH
void MoveTo(const VECTOR2I &pos)
void FinishTo(const VECTOR2I &pos)
virtual VECTOR2D userToDeviceCoordinates(const VECTOR2I &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
virtual VECTOR2D userToDeviceSize(const VECTOR2I &size)
Modify size according to the plotter scale factors (VECTOR2I version, returns a VECTOR2D).
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
FILE * m_outputFile
Output file.
static const int DO_NOT_SET_LINE_WIDTH
RENDER_SETTINGS * m_renderSettings
virtual void Text(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aPenWidth, bool aItalic, bool aBold, bool aMultilineAllowed, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr)
Draw text with the plotter.
double GetDashMarkLenIU(int aLineWidth) const
virtual void SetColor(const COLOR4D &color) override
The SetColor implementation is split with the subclasses: the PSLIKE computes the rgb values,...
double plotScaleAdjX
Fine user scale adjust ( = 1.0 if no correction)
void computeTextParameters(const VECTOR2I &aPos, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, bool aMirror, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_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.
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
const wxString ResolveUriByEnvVars(const wxString &aUri, const PROJECT *aProject)
Replace any environment and/or text variables in URIs.
void ignore_unused(const T &)
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Plotting engines similar to ps (PostScript, Gerber, svg)
wxString NormalizeFileUri(const wxString &aFileUri)
Normalize file path aFileUri to URI convention.
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
LINE_STYLE
Dashed line types.
wxString title
Title of outline node.
std::vector< OUTLINE_NODE * > children
Ordered list of children.
int entryHandle
Allocated handle for this outline entry.
OUTLINE_NODE * AddChild(int aActionHandle, const wxString &aTitle, int aEntryHandle)
int actionHandle
Handle to action.
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D