28#include <wx/filename.h>
29#include <wx/mstream.h>
30#include <wx/zstream.h>
31#include <wx/wfstream.h>
32#include <wx/datstrm.h>
33#include <wx/tokenzr.h>
47#include <fmt/format.h>
48#include <fmt/chrono.h>
49#include <fmt/ranges.h>
63#define GLM_ENABLE_EXPERIMENTAL
65#include <glm/gtx/euler_angles.hpp>
77 bool is_ascii7 =
true;
79 for(
size_t ii = 0; ii < aText.Len(); ii++ )
81 if( aText[ii] >= 0x7F )
92 for(
size_t ii = 0; ii < aText.Len(); ii++ )
94 unsigned int code = aText[ii];
96 if( code ==
'(' || code ==
')' || code ==
'\\' )
100 result +=
static_cast<char>( code );
102 else if( code < 0x20 )
106 result += fmt::format(
"\\{:03o}", code );
110 result +=
static_cast<char>( code );
121 for(
size_t ii = 0; ii < aText.Len(); ii++ )
123 unsigned int code = aText[ii];
136 std::string buf = fmt::format(
"{:g}", aValue );
140 if( buf.find(
'e' ) != std::string::npos || buf.find(
'E' ) != std::string::npos )
141 buf = fmt::format(
"{:.10f}", aValue );
143 if( buf.find(
'.' ) != std::string::npos )
146 while( buf.size() > 1 && buf.back() ==
'0' )
150 if( !buf.empty() && buf.back() ==
'.' )
165 result.reserve( aBytes.size() * 4 + 2 );
168 for(
unsigned char byte : aBytes )
170 if(
byte ==
'(' ||
byte ==
')' ||
byte ==
'\\' )
173 result.push_back(
static_cast<char>(
byte ) );
175 else if( byte < 32 || byte > 126 )
177 fmt::format_to( std::back_inserter(
result ),
"\\{:03o}",
byte );
181 result.push_back(
static_cast<char>(
byte ) );
233 wxASSERT_MSG( aWidth > 0,
"Plotter called to set negative pen width" );
257 fmt::println(
m_workFile,
"{} {} {} rg {} {} {} RG",
269 fmt::println(
m_workFile,
"/GS{} gs", extGStateHandle );
280 std::vector<int> pattern;
311 bool allZero = std::all_of( pattern.begin(), pattern.end(), [](
int v ) { return v == 0; } );
313 if( pattern.empty() || allZero )
319 fmt::println(
m_workFile,
"[{}] 0 d", fmt::join( pattern,
" " ) );
332 if( aCornerRadius > 0 )
337 rect.SetRadius( aCornerRadius );
344 if( size.
x == 0 && size.
y == 0 )
356 std::vector<VECTOR2I> cornerList;
358 cornerList.emplace_back( p1.
x, p1.
y );
359 cornerList.emplace_back( p2.
x, p1.
y );
360 cornerList.emplace_back( p2.
x, p2.
y );
361 cornerList.emplace_back( p1.
x, p2.
y );
362 cornerList.emplace_back( p1.
x, p1.
y );
364 PlotPoly( cornerList, fill, width,
nullptr );
377 paintOp = width > 0 ?
'B' :
'f';
379 fmt::println(
m_workFile,
"{} {} {} {} re {}",
401 char paintOp = aFill ==
FILL_T::NO_FILL ?
's' : ( width == 0 ?
'f' :
'b' );
416 double magic =
radius * 0.551784;
421 "{} {} {} {} {} {} c "
422 "{} {} {} {} {} {} c "
423 "{} {} {} {} {} {} c "
424 "{} {} {} {} {} {} c {}",
448 const EDA_ANGLE& aAngle,
double aRadius )
450 std::vector<VECTOR2D>
path;
457 EDA_ANGLE endAngle = startAngle - aAngle;
462 if( startAngle > endAngle )
463 std::swap( startAngle, endAngle );
466 start.
x =
KiROUND( aCenter.
x + aRadius * ( -startAngle ).Cos() );
467 start.
y =
KiROUND( aCenter.
y + aRadius * ( -startAngle ).Sin() );
472 end.x =
KiROUND( aCenter.
x + aRadius * ( -ii ).Cos() );
473 end.y =
KiROUND( aCenter.
y + aRadius * ( -ii ).Sin() );
477 end.x =
KiROUND( aCenter.
x + aRadius * ( -endAngle ).Cos() );
478 end.y =
KiROUND( aCenter.
y + aRadius * ( -endAngle ).Sin() );
498 std::vector<VECTOR2D>
path =
arcPath( aCenter, aStartAngle, aAngle, aRadius );
500 if(
path.size() >= 2 )
505 for(
int ii = 1; ii < (int)
path.size(); ++ii )
532 if( aCornerList.size() <= 1 )
543 for(
unsigned ii = 1; ii < aCornerList.size(); ii++ )
552 else if( aWidth == 0 )
566 std::set<size_t> handledArcs;
567 std::vector<VECTOR2D>
path;
573 size_t arcIndex = aLineChain.
ArcIndex( ii );
575 if( !handledArcs.contains( arcIndex ) )
577 handledArcs.insert( arcIndex );
582 for(
const VECTOR2D& pt : std::ranges::reverse_view( arc_path ) )
583 path.emplace_back( pt );
594 if(
path.size() <= 1 )
600 for(
int ii = 1; ii < (int)
path.size(); ++ii )
609 else if( aWidth == 0 )
639 plume ==
'D' ?
'l' :
'm' );
650 VECTOR2I pix_size( aImage.GetWidth(), aImage.GetHeight() );
653 VECTOR2D drawsize( aScaleFactor * pix_size.
x, aScaleFactor * pix_size.
y );
656 VECTOR2I start( aPos.
x - drawsize.
x / 2, aPos.
y + drawsize.
y / 2 );
660 auto findHandleForImage =
661 [&](
const wxImage& aCurrImage ) ->
int
665 if(
image.IsSameAs( aCurrImage ) )
668 if(
image.GetWidth() != aCurrImage.GetWidth() )
671 if(
image.GetHeight() != aCurrImage.GetHeight() )
674 if(
image.GetType() != aCurrImage.GetType() )
677 if(
image.HasAlpha() != aCurrImage.HasAlpha() )
680 if(
image.HasMask() != aCurrImage.HasMask()
681 ||
image.GetMaskRed() != aCurrImage.GetMaskRed()
682 ||
image.GetMaskGreen() != aCurrImage.GetMaskGreen()
683 ||
image.GetMaskBlue() != aCurrImage.GetMaskBlue() )
688 int pixCount =
image.GetWidth() *
image.GetHeight();
690 if( memcmp(
image.GetData(), aCurrImage.GetData(), pixCount * 3 ) != 0 )
693 if(
image.HasAlpha() && memcmp(
image.GetAlpha(), aCurrImage.GetAlpha(), pixCount ) != 0 )
702 int imgHandle = findHandleForImage( aImage );
704 if( imgHandle == -1 )
720 fmt::println(
m_workFile,
"q {} 0 0 {} {} {} cm",
730 fmt::println(
m_workFile,
"/Im{} Do", imgHandle );
748 wxASSERT_MSG( aHandle < 0,
"PDF object handle given was not previously allocated" );
778 fmt::print(
m_outputFile,
"<< /Length {} 0 R >>\nstream\n",
783 fmt::print(
m_outputFile,
"<< /Length {} 0 R /Filter /FlateDecode >>\nstream\n",
809 unsigned char *inbuf =
new unsigned char[stream_len];
811 int rc = fread( inbuf, 1, stream_len,
m_workFile );
812 wxASSERT( rc == stream_len );
824 out_count = stream_len;
830 wxMemoryOutputStream memos(
nullptr, std::max( 2000l, stream_len ) ) ;
840 wxZlibOutputStream zos( memos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB );
842 zos.Write( inbuf, stream_len );
845 wxStreamBuffer* sb = memos.GetOutputStreamBuffer();
847 out_count = sb->Tell();
848 fwrite( sb->GetBufferStart(), 1, out_count,
m_outputFile );
863 const wxString& aParentPageNumber,
const wxString& aParentPageName )
869 m_pageName = aPageName.IsEmpty() ? wxString::Format(
_(
"Page %s" ),
871 : wxString::Format(
_(
"%s (Page %s)" ),
876 : wxString::Format(
_(
"%s (Page %s)" ),
902 "{} 0 0 {} 0 0 cm 1 J 1 j 0 0 0 rg 0 0 0 RG {} w",
910void WriteImageStream(
const wxImage& aImage, wxDataOutputStream& aOut,
const wxColor& bg,
bool colorMode )
912 int w = aImage.GetWidth();
913 int h = aImage.GetHeight();
915 for(
int y = 0; y < h; y++ )
917 for(
int x = 0; x < w; x++ )
919 unsigned char r = aImage.GetRed( x, y ) & 0xFF;
920 unsigned char g = aImage.GetGreen( x, y ) & 0xFF;
921 unsigned char b = aImage.GetBlue( x, y ) & 0xFF;
923 if( aImage.HasMask() )
925 if( r == aImage.GetMaskRed() && g == aImage.GetMaskGreen() && b == aImage.GetMaskBlue() )
942 unsigned char grey =
KiROUND( r * 0.2126 + g * 0.7152 + b * 0.0722 );
953 int w = aImage.GetWidth();
954 int h = aImage.GetHeight();
956 if( aImage.HasMask() )
958 for(
int y = 0; y < h; y++ )
960 for(
int x = 0; x < w; x++ )
962 unsigned char a = 255;
963 unsigned char r = aImage.GetRed( x, y );
964 unsigned char g = aImage.GetGreen( x, y );
965 unsigned char b = aImage.GetBlue( x, y );
967 if( r == aImage.GetMaskRed() && g == aImage.GetMaskGreen() && b == aImage.GetMaskBlue() )
974 else if( aImage.HasAlpha() )
977 aOut.Write8( aImage.GetAlpha(), size );
996 const double PTsPERMIL = 0.072;
999 auto iuToPdfUserSpace =
1013 retval.
x = ( psPaperSize.
x - pos.
x );
1022 std::vector<int> annotHandles;
1028 const BOX2I& box = linkPair.first;
1029 const wxString& url = linkPair.second;
1036 userSpaceBox.
SetEnd( topRight );
1045 const BOX2I& box = menuPair.first;
1046 const std::vector<wxString>& urls = menuPair.second;
1053 userSpaceBox.
SetEnd( topRight );
1060 int annot3DHandle = -1;
1065 annotHandles.push_back( annot3DHandle );
1069 int annotArrayHandle = -1;
1072 if( annotHandles.size() > 0 )
1075 bool isFirst =
true;
1079 for(
int handle : annotHandles )
1102 " /ProcSet [/PDF /Text /ImageC /ImageB]\n"
1104 " /XObject {} 0 R\n"
1105 " /ExtGState {} 0 R >>\n"
1106 "/MediaBox [0 0 {} {}]\n",
1117 if( annotHandles.size() > 0 )
1118 fmt::print(
m_outputFile,
"/Annots {} 0 R", annotArrayHandle );
1131 "/Rect [0 0 {} {}]\n"
1132 "/NM (3D Annotation)\n"
1135 "/3DA<</A/PO/D/PC/TB true/NP true>>\n"
1156 std::stack<OUTLINE_NODE*> nodes;
1159 while( !nodes.empty() )
1173 nodes.push( child );
1185 for(
const std::pair<BOX2I, wxString>& bookmarkPair : groupVector )
1187 const BOX2I& box = bookmarkPair.first;
1188 const wxString& ref = bookmarkPair.second;
1193 actionHandle =
emitGoToAction( pageHandle, bottomLeft, topRight );
1198 std::sort( groupOutlineNode->
children.begin(), groupOutlineNode->
children.end(),
1201 return a->title < b->title;
1214 return StartPlot( aPageNumber, wxEmptyString );
1251 fmt::print(
m_outputFile,
"%PDF-1.5\n%\200\201\202\203\n" );
1280 "<</S /GoTo /D [{} 0 R /FitR {} {} {} {}]\n"
1290 return actionHandle;
1300 "<</S /GoTo /D [{} 0 R /Fit]\n"
1306 return actionHandle;
1313 int prevHandle = -1;
1314 int nextHandle = -1;
1316 for( std::vector<OUTLINE_NODE*>::iterator it = node->
children.begin(); it != node->
children.end(); it++ )
1318 if( it >= node->
children.end() - 1 )
1321 nextHandle = ( *( it + 1 ) )->entryHandle;
1325 prevHandle = ( *it )->entryHandle;
1329 if( parentHandle != -1 )
1341 fmt::println(
m_outputFile,
"/Next {} 0 R", nextNode );
1344 fmt::println(
m_outputFile,
"/Prev {} 0 R", prevNode );
1348 int32_t count = -1 *
static_cast<int32_t
>( node->
children.size() );
1364 const wxString& aTitle )
1385 "<< /Type /Outlines\n"
1425 if( !glyph.m_stream.empty() )
1426 fmt::print(
m_workFile,
"{}\n", glyph.m_stream );
1429 glyph.m_charProcHandle = charProcHandle;
1436 fmt::println(
m_outputFile,
" /{} {} 0 R", glyph.m_name, glyph.m_charProcHandle );
1451 double fontMatrixScale = 1.0 / subset.
UnitsPerEm();
1459 "<<\n/Type /Font\n/Subtype /Type3\n/Name {}\n/FontBBox [ {} {} {} {} ]\n",
1466 "/FontMatrix [ {} 0 0 {} 0 0 ]\n/CharProcs {} 0 R\n",
1471 "/Encoding << /Type /Encoding /Differences {} >>\n",
1474 "/FirstChar {}\n/LastChar {}\n/Widths {}\n",
1479 "/ToUnicode {} 0 R\n/Resources << /ProcSet [/PDF /Text] >>\n>>\n",
1494 if( !subsetPtr || !subsetPtr->HasGlyphs() )
1497 const std::vector<uint8_t>& fontData = subsetPtr->FontFileData();
1499 if( fontData.empty() )
1503 subsetPtr->SetFontFileHandle( fontFileHandle );
1505 if( !fontData.empty() )
1506 fwrite( fontData.data(), fontData.size(), 1,
m_workFile );
1510 std::string cidMap = subsetPtr->BuildCIDToGIDStream();
1512 subsetPtr->SetCIDMapHandle( cidMapHandle );
1514 if( !cidMap.empty() )
1515 fwrite( cidMap.data(), cidMap.size(), 1,
m_workFile );
1519 std::string toUnicode = subsetPtr->BuildToUnicodeCMap();
1521 subsetPtr->SetToUnicodeHandle( toUnicodeHandle );
1523 if( !toUnicode.empty() )
1529 subsetPtr->SetFontDescriptorHandle( descriptorHandle );
1532 "<<\n/Type /FontDescriptor\n/FontName /{}\n/Flags {}\n/ItalicAngle {}\n/Ascent {}\n/Descent {}\n"
1533 "/CapHeight {}\n/StemV {}\n/FontBBox [ {} {} {} {} ]\n/FontFile2 {} 0 R\n>>\n",
1534 subsetPtr->BaseFontName(),
1545 subsetPtr->FontFileHandle() );
1549 subsetPtr->SetCIDFontHandle( cidFontHandle );
1551 std::string widths = subsetPtr->BuildWidthsArray();
1554 "<<\n/Type /Font\n/Subtype /CIDFontType2\n/BaseFont /{}\n"
1555 "/CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >>\n"
1556 "/FontDescriptor {} 0 R\n/W {}\n/CIDToGIDMap {} 0 R\n>>\n",
1557 subsetPtr->BaseFontName(),
1558 subsetPtr->FontDescriptorHandle(),
1560 subsetPtr->CIDMapHandle() );
1564 subsetPtr->SetFontHandle( fontHandle );
1567 "<<\n/Type /Font\n/Subtype /Type0\n/BaseFont /{}\n/Encoding /Identity-H\n"
1568 "/DescendantFonts [ {} 0 R ]\n/ToUnicode {} 0 R\n>>\n",
1569 subsetPtr->BaseFontName(),
1570 subsetPtr->CIDFontHandle(),
1571 subsetPtr->ToUnicodeHandle() );
1590 {
"/Helvetica",
"/KicadFont", 0 },
1591 {
"/Helvetica-Oblique",
"/KicadFontI", 0 },
1592 {
"/Helvetica-Bold",
"/KicadFontB", 0 },
1593 {
"/Helvetica-BoldOblique",
"/KicadFontBI", 0 }
1598 for(
auto& font : base14 )
1604 " /Subtype /Type1\n"
1605 " /Encoding /WinAnsiEncoding\n"
1617 for(
const auto& font : base14 )
1618 fmt::println(
m_outputFile,
" {} {} 0 R", font.rsname, font.handle );
1625 if( subsetPtr && subsetPtr->FontHandle() >= 0 )
1626 fmt::println(
m_outputFile,
" {} {} 0 R", subsetPtr->ResourceName(), subsetPtr->FontHandle() );
1649 fmt::print(
m_outputFile,
" /Im{} {} 0 R\n", imgHandle, imgHandle );
1673 fmt::println(
m_outputFile,
" /GS{} {} 0 R", handle, handle );
1694 "/BitsPerComponent 8\n"
1698 "/Filter /FlateDecode\n"
1705 if( smaskHandle != -1 )
1706 fmt::println(
m_outputFile,
"/SMask {} 0 R", smaskHandle );
1714 wxFFileOutputStream ffos( outputFFile );
1715 wxZlibOutputStream zos( ffos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB );
1716 wxDataOutputStream dos( zos );
1722 long imgStreamSize = ftell(
m_outputFile ) - imgStreamStart;
1731 if( smaskHandle != -1 )
1741 "/BitsPerComponent 8\n"
1742 "/ColorSpace /DeviceGray\n"
1746 "/Filter /FlateDecode\n"
1757 wxFFileOutputStream ffos( outputFFile );
1758 wxZlibOutputStream zos( ffos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB );
1759 wxDataOutputStream dos( zos );
1764 long smaskStreamSize = ftell(
m_outputFile ) - smaskStreamStart;
1770 fmt::println(
m_outputFile,
"{}", (
unsigned) smaskStreamSize );
1774 outputFFile.Detach();
1779 BOX2D box = linkPair.first;
1780 wxString url = linkPair.second;
1788 "/Rect [{} {} {} {}]\n"
1789 "/Border [16 16 0]\n",
1795 wxString pageNumber;
1796 bool pageFound =
false;
1805 "/Dest [{} 0 R /FitB]\n"
1818 "/A << /Type /Action /S /NOP >>\n"
1828 "/A << /Type /Action /S /URI /URI {} >>\n"
1838 const BOX2D& box = menuPair.first;
1839 const std::vector<wxString>& urls = menuPair.second;
1840 wxString js = wxT(
"ShM([\n" );
1842 for(
const wxString& url : urls )
1844 if( url.StartsWith(
"!" ) )
1846 wxString
property = url.AfterFirst(
'!' );
1848 if( property.Find(
"http:" ) >= 0 )
1850 wxString href =
property.substr( property.Find(
"http:" ) );
1858 else if( property.Find(
"https:" ) >= 0 )
1860 wxString href =
property.substr( property.Find(
"https:" ) );
1868 else if( property.Find(
"file:" ) >= 0 )
1870 wxString href =
property.substr( property.Find(
"file:" ) );
1876 wxString displayText =
property.substr( 0, property.Find(
"file:" ) ) + href;
1884 int eqPos =
property.Find( wxS(
" = " ) );
1886 bool converted =
false;
1888 if( eqPos != wxNOT_FOUND )
1890 href =
property.Mid( eqPos + 3 );
1895 if( href.StartsWith( wxS(
"/" ) ) || href.StartsWith( wxS(
"${" ) )
1896 || ( href.Length() >= 2 && wxIsalpha( href[0] ) && href[1] ==
':' )
1897 || href.StartsWith( wxS(
"\\\\" ) ) )
1899 if( !href.StartsWith( wxS(
"/" ) ) )
1901 href.Replace( wxS(
"\\" ), wxS(
"/" ) );
1903 if( href.StartsWith( wxS(
"//" ) ) )
1904 href = wxS(
"file:" ) + href;
1906 href = wxS(
"file:///" ) + href;
1910 href = wxS(
"file://" ) + href;
1920 js += wxString::Format( wxT(
"[\"%s\", \"%s\"],\n" ),
1930 else if( url.StartsWith(
"#" ) )
1932 wxString pageNumber = url.AfterFirst(
'#' );
1938 wxString menuText = wxString::Format(
_(
"Show Page %s" ), pageNumber );
1940 js += wxString::Format( wxT(
"[\"%s\", \"#%d\"],\n" ),
1942 static_cast<int>( ii ) );
1949 wxString href = url;
1955 if( !href.StartsWith( wxS(
"http:" ) )
1956 && !href.StartsWith( wxS(
"https:" ) )
1957 && !href.StartsWith( wxS(
"file:" ) ) )
1959 if( href.StartsWith( wxS(
"/" ) ) || href.StartsWith( wxS(
"${" ) ) )
1961 href = wxS(
"file://" ) + href;
1963 else if( href.Length() >= 2 && wxIsalpha( href[0] ) && href[1] ==
':' )
1965 href.Replace( wxS(
"\\" ), wxS(
"/" ) );
1966 href = wxS(
"file:///" ) + href;
1968 else if( href.StartsWith( wxS(
"\\\\" ) ) )
1970 href.Replace( wxS(
"\\" ), wxS(
"/" ) );
1971 href = wxS(
"file:" ) + href;
1975 if( href.StartsWith( wxS(
"file:" ) ) )
1978 if( href.StartsWith( wxS(
"http:" ) )
1979 || href.StartsWith( wxS(
"https:" ) )
1980 || href.StartsWith( wxS(
"file:" ) ) )
1982 wxString menuText = wxString::Format(
_(
"Open %s" ), href );
1984 js += wxString::Format( wxT(
"[\"%s\", \"%s\"],\n" ),
1999 "/Rect [{} {} {} {}]\n"
2000 "/Border [16 16 0]\n",
2007 "/A << /Type /Action /S /JavaScript /JS {} >>\n"
2018function ShM(aEntries) {
2020 for (var i = 0; i < aEntries.length; ++i) {
2022 cName: aEntries[i][0],
2023 cReturn: aEntries[i].length > 1 ? aEntries[i][1] : ''
2027 var cChoice = app.popUpMenuEx.apply(app, aParams);
2028 if (cChoice == null || cChoice == '') return;
2030 if (cChoice.substring(0, 1) == '#') {
2031 this.pageNum = parseInt(cChoice.slice(1));
2035 // Fallback: some viewers return cName instead of cReturn
2037 if (url.substring(0, 4) != 'http' && url.substring(0, 4) != 'file') {
2038 var idx = url.indexOf('http');
2039 if (idx < 0) idx = url.indexOf('file:');
2040 if (idx >= 0) url = url.substring(idx);
2044 if (url.substring(0, 8) == 'file:///') app.openDoc(url.substring(7));
2045 else if (url.substring(0, 7) == 'file://') app.openDoc('//' + url.substring(7));
2046 else app.launchURL(url);
2053 " [ (JSInit) << /Type /Action /S /JavaScript /JS {} >> ]\n"
2095 std::time_t time = std::time(
nullptr );
2097#if defined( _WIN32 ) || defined( _MSC_VER )
2098 localtime_s( &tm, &time );
2100 localtime_r( &time, &tm );
2102 std::string dt = fmt::format(
"D:{:%Y:%m:%d:%H:%M:%S}", tm );
2113 "/Producer (KiCad PDF)\n"
2114 "/CreationDate ({})\n"
2129 int outlineHandle = -1;
2137 if( outlineHandle > 0 )
2144 "/PageMode /UseOutlines\n"
2145 "/Outlines {} 0 R\n"
2147 "/PageLayout /SinglePage\n"
2160 "/PageMode /UseNone\n"
2161 "/PageLayout /SinglePage\n"
2172 const std::vector<long>& xrefEntries =
m_xrefTable.Entries();
2177 "0000000000 65535 f \n",
2178 xrefEntries.size() );
2180 for(
unsigned i = 1; i < xrefEntries.size(); i++ )
2181 fmt::print(
m_outputFile,
"{:010d} 00000 n \n", xrefEntries[i] );
2186 "<< /Size {} /Root {} 0 R /Info {} 0 R >>\n"
2204 int aWidth,
bool aItalic,
bool aBold,
bool aMultilineAllowed,
KIFONT::FONT* aFont,
2208 if( aSize.
x == 0 || aSize.
y == 0 )
2211 wxString
text( aText );
2213 if(
text.Contains( wxS(
"@{" ) ) )
2234 int render_mode = 3;
2237 const char *fontname = aItalic ? ( aBold ?
"/KicadFontBI" :
"/KicadFontI" )
2238 : ( aBold ?
"/KicadFontB" :
"/KicadFont" );
2243 double ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f;
2244 double wideningFactor, heightFactor;
2247 bool textMirrored = aSize.
x < 0;
2250 aItalic, aBold, &wideningFactor, &ctm_a, &ctm_b, &ctm_c, &ctm_d, &ctm_e, &ctm_f,
2256 wxStringTokenizer str_tok(
text,
" ", wxTOKEN_RET_DELIMS );
2279 while( str_tok.HasMoreTokens() )
2281 wxString word = str_tok.GetNextToken();
2285 &ctm_a, &ctm_b, &ctm_c, &ctm_d, &ctm_e, &ctm_f, &heightFactor );
2298 if( word.Trim(
false ).Trim(
true ).empty() )
2305 fmt::print(
m_workFile,
"q {:f} {:f} {:f} {:f} {:f} {:f} cm BT {} {:g} Tf {} Tr {:g} Tz ",
2306 ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f,
2310 wideningFactor * 100 );
2313 fmt::println(
m_workFile,
"{} Tj ET", txt_pdf );
2319 PLOTTER::Text( aPos, aColor,
text, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,
2320 aBold, aMultilineAllowed, aFont, aFontMetrics, aData );
2330 bool textMirrored = aSize.
x < 0;
2332 if( aWidth == 0 && aBold )
2341 auto computeAlignedStartPos =
2349 alignAttrs.
m_Size = t_size;
2353 alignAttrs.
m_Bold = aBold;
2364 drawOffset.
x = -drawOffset.
x;
2367 startPos = aPos + drawOffset;
2384 startPos -= box_x / 2;
2389 startPos += box_y / 2;
2403 std::unique_ptr<MARKUP::NODE> markupTree( markupParser.
Parse() );
2407 wxLogTrace(
tracePdfPlotter,
"PDF_PLOTTER::Text: Markup parsing failed, falling back to plain text." );
2409 wxStringTokenizer str_tok(
text,
" ", wxTOKEN_RET_DELIMS );
2410 VECTOR2I pos = computeAlignedStartPos();
2412 while( str_tok.HasMoreTokens() )
2414 wxString word = str_tok.GetNextToken();
2415 pos =
renderWord( word, pos, t_size, aOrient, textMirrored, aWidth, aBold, aItalic, aFont,
2416 aFontMetrics, aV_justify, 0 );
2421 VECTOR2I pos = computeAlignedStartPos();
2424 std::vector<OVERBAR_INFO> overbars;
2425 renderMarkupNode( markupTree.get(), pos, t_size, aOrient, textMirrored, aWidth, aBold, aItalic, aFont,
2426 aFontMetrics, aV_justify, 0, overbars );
2434 const EDA_ANGLE& aOrient,
bool aTextMirrored,
int aWidth,
bool aBold,
bool aItalic,
2438 if( wxGetEnv(
"KICAD_DEBUG_SYN_STYLE",
nullptr ) )
2445 styleFlags = (int) face->style_flags;
2448 wxLogTrace(
tracePdfPlotter,
"renderWord enter word='%s' bold=%d italic=%d textStyle=%u styleFlags=%d",
2449 TO_UTF8( aWord ), (
int) aBold, (
int) aItalic, (
unsigned) aTextStyle, styleFlags );
2472 auto cursorAdvanceX =
2473 [&](
const wxString& aText )
2480 if( aWord == wxT(
" " ) )
2482 VECTOR2I spaceBox( cursorAdvanceX( wxT(
" " ) ), 0 );
2487 VECTOR2I rotatedSpaceBox = spaceBox;
2489 return aPosition + rotatedSpaceBox;
2493 if( aWord.Contains( wxT(
'\t' ) ) )
2495 auto positionedAdvance =
2496 [&](
const wxString& aText )
2498 VECTOR2I advance( cursorAdvanceX( aText ), 0 );
2513 if( !segment.IsEmpty() )
2515 renderWord( segment, aPosition + positionedAdvance( prefix ), aSize, aOrient, aTextMirrored,
2516 aWidth, aBold, aItalic, aFont, aFontMetrics, aV_justify, aTextStyle );
2522 for( wxUniChar c : aWord )
2537 return aPosition + positionedAdvance( aWord );
2551 double ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f;
2552 double wideningFactor, heightFactor;
2555 aWidth, aItalic, aBold, &wideningFactor, &ctm_a, &ctm_b, &ctm_c, &ctm_d, &ctm_e, &ctm_f,
2558 VECTOR2I bbox( cursorAdvanceX( aWord ), 0 );
2564 VECTOR2I nextPos = aPosition + bbox;
2569 std::vector<PDF_OUTLINE_FONT_RUN> outlineRuns;
2579 if( !outlineRuns.empty() )
2582 double baseline_factor = 0.17;
2583 double alignment_multiplier = 1.0;
2586 alignment_multiplier = 2.0;
2588 alignment_multiplier = 4.0;
2591 double lineHeight = font_size_dev.
y;
2596 double baseline_adjustment = lineHeight * baseline_factor * alignment_multiplier;
2598 double adjusted_ctm_e = ctm_e;
2599 double adjusted_ctm_f = ctm_f;
2602 double cos_angle = cos( angle_rad );
2603 double sin_angle = sin( angle_rad );
2605 adjusted_ctm_e = ctm_e - baseline_adjustment * sin_angle;
2606 adjusted_ctm_f = ctm_f + baseline_adjustment * cos_angle;
2608 double adj_c = ctm_c;
2609 double adj_d = ctm_d;
2612 bool syntheticItalicApplied =
false;
2613 double appliedTilt = 0.0;
2614 double syn_c = adj_c;
2615 double syn_d = adj_d;
2616 double syn_a = ctm_a;
2617 double syn_b = ctm_b;
2620 if( std::getenv(
"KICAD_FORCE_SYN_ITALIC" ) )
2624 bool fontIsItalic = aFont->
IsItalic();
2625 bool fontIsBold = aFont->
IsBold();
2633 bool forceSynItalic =
false;
2634 double overrideTilt = 0.0;
2636 if(
const char* envForce = std::getenv(
"KICAD_FORCE_SYN_ITALIC" ) )
2638 if( *envForce !=
'\0' && *envForce !=
'0' )
2639 forceSynItalic =
true;
2642 if(
const char* envTilt = std::getenv(
"KICAD_SYN_ITALIC_TILT" ) )
2644 std::string tiltStr( envTilt );
2648 if( tiltStr.find(
"deg" ) != std::string::npos )
2650 double deg = std::stod( tiltStr );
2651 overrideTilt = tan(
deg *
M_PI / 180.0 );
2655 overrideTilt = std::stod( tiltStr );
2665 wxLogTrace(
tracePdfPlotter,
"Outline path word='%s' runs=%zu wantItalic=%d fontIsItalic=%d "
2666 "fontIsFakeItalic=%d wantBold=%d fontIsBold=%d fontIsFakeBold=%d forceSyn=%d",
2667 TO_UTF8( aWord ), outlineRuns.size(), (
int) wantItalic, (
int) fontIsItalic,
2668 (
int) fontIsFakeItalic, (
int) wantBold, (
int) fontIsBold, (
int) fontIsFakeBold,
2669 (
int) forceSynItalic );
2675 bool realItalicFace = fontIsItalic && !fontIsFakeItalic;
2677 if( wantItalic && ( forceSynItalic || !realItalicFace ) )
2688 double tilt = ( overrideTilt != 0.0 ) ? overrideTilt :
ITALIC_TILT;
2690 if( wideningFactor < 0 )
2693 syn_c = adj_c + tilt * syn_a;
2694 syn_d = adj_d + tilt * syn_b;
2696 syntheticItalicApplied =
true;
2698 wxLogTrace(
tracePdfPlotter,
"Synthetic italic shear applied: tilt=%f a=%f b=%f c->%f d->%f",
2699 tilt, syn_a, syn_b, syn_c, syn_d );
2702 if( wantBold && !fontIsBold )
2709 if( syntheticItalicApplied )
2712 fmt::print(
m_workFile,
"% syn-italic tilt={} a={} b={} c={} d={}\n",
2713 appliedTilt, syn_a, syn_b, syn_c, syn_d );
2716 fmt::print(
m_workFile,
"q {:f} {:f} {:f} {:f} {:f} {:f} cm BT {} Tr {} Tz ",
2717 syn_a, syn_b, syn_c, syn_d, adjusted_ctm_e, adjusted_ctm_f,
2724 run.m_subset->ResourceName(),
2730 static_cast<unsigned char>( ( glyph.
cid >> 8 ) & 0xFF ),
2731 static_cast<unsigned char>( glyph.
cid & 0xFF ) );
2747 wxLogTrace(
tracePdfPlotter,
"Stroke path word='%s' wantItalic=%d aItalic=%d aBold=%d",
2749 (
int) aItalic, (
int) aBold );
2751 std::vector<PDF_STROKE_FONT_RUN> runs;
2757 double fontSize = dev_size.
y;
2759 double adj_c = ctm_c;
2760 double adj_d = ctm_d;
2766 if( wideningFactor < 0 )
2769 adj_c -= ctm_a * tilt;
2770 adj_d -= ctm_b * tilt;
2779 const double xCancelDev = xOffsetEm * dev_size.
x;
2780 const double yCancelDev = yOffsetEm * dev_size.
y;
2781 const double xSign = ( wideningFactor < 0 ) ? -1.0 : 1.0;
2783 const double adj_ctm_e = ctm_e - yCancelDev * adj_c - xSign * xCancelDev * ctm_a;
2784 const double adj_ctm_f = ctm_f - yCancelDev * adj_d - xSign * xCancelDev * ctm_b;
2787 const double tzFactor = wideningFactor < 0 ? -100.0 : 100.0;
2789 fmt::print(
m_workFile,
"q {:f} {:f} {:f} {:f} {:f} {:f} cm BT {} Tr {} Tz ",
2790 ctm_a, ctm_b, adj_c, adj_d, adj_ctm_e, adj_ctm_f,
2797 run.m_subset->ResourceName(),
2813 bool aTextMirrored,
int aWidth,
bool aBaseBold,
bool aBaseItalic,
2816 std::vector<OVERBAR_INFO>& aOverbars )
2821 return nextPosition;
2825 bool drawOverbar =
false;
2828 if( !aNode->is_root() )
2846 if( aNode->has_content() )
2851 wxStringTokenizer str_tok( nodeText,
" ", wxTOKEN_RET_DELIMS );
2853 while( str_tok.HasMoreTokens() )
2855 wxString word = str_tok.GetNextToken();
2856 nextPosition =
renderWord( word, nextPosition, currentSize, aOrient, aTextMirrored, aWidth,
2859 aFont, aFontMetrics, aV_justify, currentStyle );
2865 for(
const std::unique_ptr<MARKUP::NODE>& child : aNode->children )
2869 nextPosition =
renderMarkupNode( child.get(), nextPosition, currentSize, aOrient, aTextMirrored, aWidth,
2870 aBaseBold, aBaseItalic, aFont, aFontMetrics, aV_justify, currentStyle,
2877 aOverbars.push_back( { startPos, endPos, currentSize, aFont->
IsOutline(), aV_justify } );
2881 return nextPosition;
2891 VECTOR2D dir( overbar.endPos.x - overbar.startPos.x, overbar.endPos.y - overbar.startPos.y );
2893 double len = hypot( dir.
x, dir.
y );
2914 if( overbar.isOutline )
2915 barOffset += overbar.fontSize.y * 0.25;
2920 double alignMult = 1.0;
2922 switch( overbar.vAlign )
2926 default: alignMult = 1.0;
break;
2929 if( alignMult > 1.0 )
2932 double baseline_factor = 0.17;
2933 barOffset += ( alignMult - 1.0 ) * ( baseline_factor * overbar.fontSize.y );
2937 double barTrim = overbar.fontSize.x * 0.1;
2940 VECTOR2D startPt( overbar.startPos.x, overbar.startPos.y );
2941 VECTOR2D endPt( overbar.endPos.x, overbar.endPos.y );
2945 VECTOR2D offVec( -barOffset * nrm.
x, -barOffset * nrm.
y );
2947 startPt.
x += dir.
x * barTrim + offVec.
x;
2948 startPt.
y += dir.
y * barTrim + offVec.
y;
2949 endPt.
x -= dir.
x * barTrim - offVec.
x;
2950 endPt.
y -= dir.
y * barTrim - offVec.
y;
2964 const wxString& aText,
2973 if( size.
x == 0 || size.
y == 0 )
2981 aFont, aFontMetrics, aData );
3000 m_bookmarksInPage[aGroupName].push_back( std::make_pair( aLocation, aSymbolReference ) );
3006 std::map<float, int> m_fovMap;
3007 std::vector<int> m_viewHandles;
3012 wxASSERT( view.m_cameraMatrix.size() == 12 );
3015 if( !m_fovMap.contains( view.m_fov ) )
3018 m_fovMap[view.m_fov] = fovHandle;
3032 fovHandle = m_fovMap[view.m_fov];
3046 "/C2W [{:f} {:f} {:f} {:f} {:f} {:f} {:f} {:f} {:f} {:f} {:f} {:f}]\n"
3053 "/C [1.000000 1.000000 1.000000]>>\n"
3056 "/Type /3DLightingScheme\n"
3059 encodedName, encodedName,
3060 view.m_cameraMatrix[0],
3061 view.m_cameraMatrix[1],
3062 view.m_cameraMatrix[2], view.m_cameraMatrix[3], view.m_cameraMatrix[4],
3063 view.m_cameraMatrix[5], view.m_cameraMatrix[6], view.m_cameraMatrix[7],
3064 view.m_cameraMatrix[8], view.m_cameraMatrix[9], view.m_cameraMatrix[10],
3065 view.m_cameraMatrix[11],
3066 view.m_cameraCenter,
3071 m_viewHandles.push_back( viewHandle );
3087 for(
int viewHandle : m_viewHandles )
3094 "/Filter /FlateDecode\n"
3105 size_t model_stored_size = 0;
3108 wxFFileOutputStream ffos( outputFFile );
3109 wxZlibOutputStream zos( ffos, wxZ_BEST_COMPRESSION, wxZLIB_ZLIB );
3111 wxFFileInputStream fileStream( aSourcePath );
3113 if( !fileStream.IsOk() )
3114 wxLogError(
_(
"Failed to open 3D model file: %s" ), aSourcePath );
3116 zos.Write( fileStream );
3121 model_stored_size -= imgStreamStart;
3127 fmt::println(
m_outputFile,
"{}", (
unsigned) model_stored_size );
3130 outputFFile.Detach();
3135 float aCameraDistance,
3137 float aPitchDegrees,
3138 float aRollDegrees )
3140 float yRadians = glm::radians( aYawDegrees );
3141 float xRadians = glm::radians( aPitchDegrees );
3142 float zRadians = glm::radians( aRollDegrees );
3145 glm::mat4 rotationMatrix = glm::eulerAngleYXZ( yRadians, xRadians, zRadians );
3149 glm::vec4 cameraOffset = glm::vec4( 0.0f, 0.0f, aCameraDistance, 1.0f );
3152 cameraOffset = rotationMatrix * cameraOffset;
3155 glm::vec3 cameraPosition = glm::vec3(aTargetPosition.
x, aTargetPosition.
y, aTargetPosition.
z)
3156 - glm::vec3( cameraOffset );
3158 std::vector<float>
result( 12 );
3162 for(
int col = 0; col < 3; ++col )
3164 for(
int row = 0; row < 3; ++row )
3165 result[
index++] =
static_cast<float>( rotationMatrix[col][row] );
3169 result[9] =
static_cast<float>( cameraPosition.x );
3170 result[10] =
static_cast<float>( cameraPosition.y );
3171 result[11] =
static_cast<float>( cameraPosition.z );
void WriteImageStream(const wxImage &aImage, wxDataOutputStream &aOut, const wxColor &bg, bool colorMode)
void WriteImageSMaskStream(const wxImage &aImage, wxDataOutputStream &aOut)
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 BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
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
EDA_ANGLE GetAngle() const
static bool IsGotoPageHref(const wxString &aHref, wxString *aDestination=nullptr)
Check if aHref is a valid internal hyperlink.
High-level wrapper for evaluating mathematical and string expressions in wxString format.
wxString Evaluate(const wxString &aInput)
Main evaluation function - processes input string and evaluates all '@{}' expressions.
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)
virtual bool IsStroke() const
virtual bool IsItalic() const
virtual bool IsBold() const
virtual bool IsOutline() const
VECTOR2I GetAlignedDrawPosition(const wxString &aText, const VECTOR2I &aAnchor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics) const
Return the draw position for the first line of text, using the same alignment rules as GAL rendering ...
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).
virtual double GetSuperSubSizeMultiplier() const =0
Return the factor the text size is multiplied by for a superscript or subscript run.
virtual VECTOR2I GetTextAsGlyphs(BOX2I *aBBox, std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aSize, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle, bool aMirror, const VECTOR2I &aOrigin, TEXT_STYLE_FLAGS aTextStyle) const =0
Convert text string to an array of GLYPHs.
virtual double GetSuperSubBaselineOffset(TEXT_STYLE_FLAGS aTextStyle) const =0
Return the baseline shift of a superscript or subscript run, as a downwards fraction of the reduced g...
double GetOverbarVerticalPosition(double aGlyphHeight) const
Compute the vertical position of an overbar.
Implement outline font drawing.
EMBEDDING_PERMISSION GetEmbeddingPermission() const
A color representation with 4 components: red, green, blue, alpha.
std::unique_ptr< NODE > Parse()
XREF_TABLE m_xrefTable
The PDF xref offset table.
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
int startPdfObject(int aHandle=-1)
Open a new PDF object and returns the handle if the parameter is -1.
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 Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width) override
Circle drawing for PDF.
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Pen width setting for PDF.
double m_currentAlpha
Alpha currently set in the page graphics state (PDF starts each page with 1.0).
int m_streamLengthHandle
Handle to the deferred stream length.
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.
std::string encodeDoubleForPlotter(double aValue) const
Convert a double to a PDF-compatible numeric token (no exponent notation).
int m_fontResDictHandle
Font resource dictionary.
virtual void emitSetRGBColor(double r, double g, double b, double a) override
PDF supports colors fully.
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.
std::map< double, int > m_alphaToExtGStateHandles
Graphics state objects keyed by alpha.
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.
void endPlotEmitResources()
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width, int aCornerRadius=0) override
Rectangles in PDF.
int startPdfStream(int aHandle=-1)
Start a PDF stream (for the page).
VECTOR2I renderMarkupNode(const MARKUP::NODE *aNode, const VECTOR2I &aPosition, const VECTOR2I &aBaseSize, const EDA_ANGLE &aOrient, bool aTextMirrored, int aWidth, bool aBaseBold, bool aBaseItalic, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, enum GR_TEXT_V_ALIGN_T aV_justify, TEXT_STYLE_FLAGS aTextStyle, std::vector< OVERBAR_INFO > &aOverbars)
Recursively render markup nodes with appropriate styling.
virtual void Arc(const VECTOR2D &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, FILL_T aFill, int aWidth) override
The PDF engine can't directly plot arcs so we use polygonization.
void HyperlinkBox(const BOX2I &aBox, const wxString &aDestinationURL) override
Create a clickable hyperlink with a rectangular click area.
virtual void PenTo(const VECTOR2I &pos, char plume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
int m_extGStateResDictHandle
Graphics state resource dictionary.
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...
bool m_usedBase14Fonts
Set when the non-embeddable font fallback references the base-14 /KicadFont* resources.
int getExtGStateHandleForAlpha(double aAlpha)
Return the ExtGState resource handle for the given alpha, allocating a new object the first time that...
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.
std::unique_ptr< PDF_OUTLINE_FONT_MANAGER > m_outlineFontManager
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::unique_ptr< PDF_STROKE_FONT_MANAGER > m_strokeFontManager
void Plot3DModel(const wxString &aSourcePath, const std::vector< PDF_3D_VIEW > &a3DViews)
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.
void PlotImage(const wxImage &aImage, const VECTOR2I &aPos, double aScaleFactor, double aAlpha) override
Plot a bitmap.
VECTOR2I renderWord(const wxString &aWord, const VECTOR2I &aPosition, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, bool aTextMirrored, int aWidth, bool aBold, bool aItalic, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, enum GR_TEXT_V_ALIGN_T aV_justify, TEXT_STYLE_FLAGS aTextStyle)
Render a single word with the given style parameters.
std::string encodeByteString(const std::string &aBytes)
void drawOverbars(const std::vector< OVERBAR_INFO > &aOverbars, const EDA_ANGLE &aOrient, const KIFONT::METRICS &aFontMetrics)
Draw overbar lines above text.
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
static std::vector< float > CreateC2WMatrixFromAngles(const VECTOR3D &aTargetPosition, float aCameraDistance, float aYawDegrees, float aPitchDegrees, float aRollDegrees)
Generates the camera to world matrix for use with a 3D View.
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.
std::vector< VECTOR2D > arcPath(const VECTOR2D &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius)
const std::string & ResourceName() const
std::string BuildDifferencesArray() const
double FontBBoxMaxY() const
double FontBBoxMinY() const
double UnitsPerEm() const
double FontBBoxMinX() const
void SetToUnicodeHandle(int aHandle)
int CharProcsHandle() const
std::string BuildWidthsArray() const
double FontBBoxMaxX() const
void SetFontHandle(int aHandle)
int ToUnicodeHandle() const
void SetCharProcsHandle(int aHandle)
std::string BuildToUnicodeCMap() const
std::vector< GLYPH > & Glyphs()
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.
void LineTo(const VECTOR2I &pos)
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.
virtual int GetCurrentLineWidth() const
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.
EDA_ANGLE GetCentralAngle() const
Get the "central angle" of the arc - this is the angle at the point of the "pie slice".
EDA_ANGLE GetStartAngle() const
const VECTOR2I & GetCenter() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const SHAPE_ARC & Arc(size_t aArc) const
ssize_t ArcIndex(size_t aSegment) const
Return the arc index for the given segment index.
SEG Segment(int aIndex) const
Return a copy of the aIndex-th segment in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
bool IsArcSegment(size_t aSegment) const
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
std::string substr(size_t pos=0, size_t len=npos) const
const wxString ResolveUriByEnvVars(const wxString &aUri, const PROJECT *aProject)
Replace any environment and/or text variables in URIs.
static constexpr EDA_ANGLE ANGLE_0
@ FILLED_SHAPE
Fill with object color.
unsigned int TEXT_STYLE_FLAGS
static constexpr double ITALIC_TILT
Tilt factor for italic style (this is the scaling factor on dY relative coordinates to give a tilted ...
int GetPenSizeForBold(int aTextSize)
double m_PDFStrokeFontXOffset
Horizontal offset factor applied to stroke font glyph coordinates (in EM units) after to compensate m...
double m_PDFStrokeFontYOffset
Vertical offset factor applied to stroke font glyph coordinates (in EM units) after Y inversion to co...
const wxChar *const tracePdfPlotter
Flag to enable PDF plotter debug tracing.
void ignore_unused(const T &)
This file contains miscellaneous commonly used macros and functions.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
std::string FormatPdfUtf16Hex(uint32_t aCodepoint)
Format one Unicode code point as the hex digits of its UTF-16BE representation.
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:...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
LINE_STYLE
Dashed line types.
bool isSuperscript() const
wxString asWxString() const
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.
static EDA_ANGLE deg(double d)
wxString result
Test unit parsing edge cases and error handling.
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.
wxLogTrace helper definitions.
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
VECTOR3< double > VECTOR3D
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)