Add PDFWriter debug mode (ie: uncompressed output).

Fixes https://gitlab.com/kicad/code/kicad/issues/5593
This commit is contained in:
Jeff Young 2020-11-06 10:32:14 +00:00
parent 05b5d2de00
commit 69c1171320
3 changed files with 54 additions and 24 deletions

View File

@ -139,6 +139,8 @@ static const wxChar MinPlotPenWidth[] = wxT( "MinPlotPenWidth" );
static const wxChar DebugZoneFiller[] = wxT( "DebugZoneFiller" ); static const wxChar DebugZoneFiller[] = wxT( "DebugZoneFiller" );
static const wxChar DebugPDFWriter[] = wxT( "DebugPDFWriter" );
static const wxChar SkipBoundingBoxFpLoad[] = wxT( "SkipBoundingBoxFpLoad" ); static const wxChar SkipBoundingBoxFpLoad[] = wxT( "SkipBoundingBoxFpLoad" );
} // namespace KEYS } // namespace KEYS
@ -237,6 +239,7 @@ ADVANCED_CFG::ADVANCED_CFG()
m_MinPlotPenWidth = 0.0212; // 1 pixel at 1200dpi. m_MinPlotPenWidth = 0.0212; // 1 pixel at 1200dpi.
m_DebugZoneFiller = false; m_DebugZoneFiller = false;
m_DebugPDFWriter = false;
m_SkipBoundingBoxOnFpLoad = false; m_SkipBoundingBoxOnFpLoad = false;
@ -317,6 +320,9 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DebugZoneFiller, configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DebugZoneFiller,
&m_DebugZoneFiller, false ) ); &m_DebugZoneFiller, false ) );
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DebugPDFWriter,
&m_DebugPDFWriter, false ) );
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::SkipBoundingBoxFpLoad, configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::SkipBoundingBoxFpLoad,
&m_SkipBoundingBoxOnFpLoad, false ) ); &m_SkipBoundingBoxOnFpLoad, false ) );

View File

@ -28,15 +28,15 @@
*/ */
#include <trigo.h> #include <trigo.h>
#include <eda_base_frame.h> #include <algorithm>
#include <eda_item.h> //#include <eda_base_frame.h>
//#include <eda_item.h>
#include <wx/zstream.h> #include <wx/zstream.h>
#include <wx/mstream.h> #include <wx/mstream.h>
#include <macros.h> //#include <macros.h>
#include <math/util.h> // for KiROUND //#include <math/util.h> // for KiROUND
#include <render_settings.h> #include <render_settings.h>
#include <advanced_config.h>
#include <algorithm>
#include "plotters_pslike.h" #include "plotters_pslike.h"
@ -552,9 +552,19 @@ int PDF_PLOTTER::startPdfStream(int handle)
// This is guaranteed to be handle+1 but needs to be allocated since // This is guaranteed to be handle+1 but needs to be allocated since
// you could allocate more object during stream preparation // you could allocate more object during stream preparation
streamLengthHandle = allocPdfObject(); streamLengthHandle = allocPdfObject();
if( ADVANCED_CFG::GetCfg().m_DebugPDFWriter )
{
fprintf( outputFile,
"<< /Length %d 0 R >>\n" // Length is deferred
"stream\n", handle + 1 );
}
else
{
fprintf( outputFile, fprintf( outputFile,
"<< /Length %d 0 R /Filter /FlateDecode >>\n" // Length is deferred "<< /Length %d 0 R /Filter /FlateDecode >>\n" // Length is deferred
"stream\n", handle + 1 ); "stream\n", handle + 1 );
}
// Open a temporary file to accumulate the stream // Open a temporary file to accumulate the stream
workFilename = wxFileName::CreateTempFileName( "" ); workFilename = wxFileName::CreateTempFileName( "" );
@ -592,6 +602,15 @@ void PDF_PLOTTER::closePdfStream()
workFile = 0; workFile = 0;
::wxRemoveFile( workFilename ); ::wxRemoveFile( workFilename );
unsigned out_count;
if( ADVANCED_CFG::GetCfg().m_DebugPDFWriter )
{
out_count = stream_len;
fwrite( inbuf, out_count, 1, outputFile );
}
else
{
// NULL means memos owns the memory, but provide a hint on optimum size needed. // NULL means memos owns the memory, but provide a hint on optimum size needed.
wxMemoryOutputStream memos( NULL, std::max( 2000l, stream_len ) ) ; wxMemoryOutputStream memos( NULL, std::max( 2000l, stream_len ) ) ;
@ -613,9 +632,9 @@ void PDF_PLOTTER::closePdfStream()
wxStreamBuffer* sb = memos.GetOutputStreamBuffer(); wxStreamBuffer* sb = memos.GetOutputStreamBuffer();
unsigned out_count = sb->Tell(); out_count = sb->Tell();
fwrite( sb->GetBufferStart(), 1, out_count, outputFile ); fwrite( sb->GetBufferStart(), 1, out_count, outputFile );
}
fputs( "endstream\n", outputFile ); fputs( "endstream\n", outputFile );
closePdfObject(); closePdfObject();

View File

@ -142,6 +142,11 @@ public:
*/ */
bool m_DebugZoneFiller; bool m_DebugZoneFiller;
/**
* A mode that writes PDF's without compression.
*/
bool m_DebugPDFWriter;
/** /**
* Skip bounding box calculation when loading footprints * Skip bounding box calculation when loading footprints
*/ */