ADDED: optional PDF metadata from AUTHOR and SUBJECT variables.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17289
This commit is contained in:
Jeff Young 2024-03-13 23:40:18 +00:00
parent 34ec57958d
commit e30b6398b7
21 changed files with 6351 additions and 6051 deletions

View File

@ -34,6 +34,7 @@ JOB_EXPORT_SCH_PLOT::JOB_EXPORT_SCH_PLOT( bool aIsCli, SCH_PLOT_FORMAT aPlotForm
m_HPGLPenSize( 1.0 ),
m_HPGLPaperSizeSelect( JOB_HPGL_PAGE_SIZE::DEFAULT ),
m_PDFPropertyPopups( true ),
m_PDFMetadata( true ),
m_theme(),
m_outputDirectory(),
m_outputFile(),

View File

@ -91,6 +91,7 @@ public:
double m_HPGLPenSize; // for HPGL format only: pen size
JOB_HPGL_PAGE_SIZE m_HPGLPaperSizeSelect;
bool m_PDFPropertyPopups;
bool m_PDFMetadata;
wxString m_theme;
wxString m_outputDirectory;

View File

@ -24,6 +24,7 @@ outputformat
pcbplotparams
pdf_back_fp_property_popups
pdf_front_fp_property_popups
pdf_metadata
plotframeref
plotfptext
plotinvisibletext

View File

@ -1463,10 +1463,14 @@ function ShM(aEntries) {
"/Producer (KiCad PDF)\n"
"/CreationDate (%s)\n"
"/Creator %s\n"
"/Title %s\n",
"/Title %s\n"
"/Author %s\n"
"/Subject %s\n",
date_buf,
encodeStringForPlotter( m_creator ).c_str(),
encodeStringForPlotter( m_title ).c_str() );
encodeStringForPlotter( m_title ).c_str(),
encodeStringForPlotter( m_author ).c_str(),
encodeStringForPlotter( m_subject ).c_str() );
fputs( ">>\n", m_outputFile );
closePdfObject();

View File

@ -111,6 +111,7 @@ void DIALOG_PLOT_SCHEMATIC::initDlg()
setOpenFileAfterPlot( cfg->m_PlotPanel.open_file_after_plot );
m_plotPDFPropertyPopups->SetValue( cfg->m_PlotPanel.pdf_property_popups );
m_plotPDFMetadata->SetValue( cfg->m_PlotPanel.pdf_metadata );
// HPGL plot origin and unit system configuration
m_plotOriginOpt->SetSelection( cfg->m_PlotPanel.hpgl_origin );
@ -269,6 +270,7 @@ void DIALOG_PLOT_SCHEMATIC::OnUpdateUI( wxUpdateUIEvent& event )
m_openFileAfterPlot->Enable( fmt == PLOT_FORMAT::PDF );
m_plotPDFPropertyPopups->Enable( fmt == PLOT_FORMAT::PDF );
m_plotPDFMetadata->Enable( fmt == PLOT_FORMAT::PDF );
m_paperSizeOption->Set( paperSizes );
m_paperSizeOption->SetSelection( selection );
@ -308,6 +310,7 @@ void DIALOG_PLOT_SCHEMATIC::getPlotOptions( RENDER_SETTINGS* aSettings )
cfg->m_PlotPanel.hpgl_origin = m_plotOriginOpt->GetSelection();
cfg->m_PlotPanel.hpgl_paper_size = static_cast<int>( m_HPGLPaperSizeSelect );
cfg->m_PlotPanel.pdf_property_popups = m_plotPDFPropertyPopups->GetValue();
cfg->m_PlotPanel.pdf_metadata = m_plotPDFMetadata->GetValue();
cfg->m_PlotPanel.open_file_after_plot = getOpenFileAfterPlot();
// HPGL Pen Size is stored in mm in config
@ -382,6 +385,7 @@ void DIALOG_PLOT_SCHEMATIC::plotSchematic( bool aPlotAll )
plotSettings.m_useBackgroundColor = m_plotBackgroundColor->GetValue();
plotSettings.m_theme = colors->GetFilename();
plotSettings.m_PDFPropertyPopups = m_plotPDFPropertyPopups->GetValue();
plotSettings.m_PDFMetadata = m_plotPDFMetadata->GetValue();
plotSettings.m_HPGLPaperSizeSelect = static_cast<HPGL_PAGE_SIZE>( m_HPGLPaperSizeSelect );
plotSettings.m_HPGLPlotOrigin =
static_cast<HPGL_PLOT_ORIGIN_AND_UNITS>( m_plotOriginOpt->GetSelection() );

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb)
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -116,7 +116,7 @@ DIALOG_PLOT_SCHEMATIC_BASE::DIALOG_PLOT_SCHEMATIC_BASE( wxWindow* parent, wxWind
sbOptions->Add( gbSizer1, 1, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 );
m_optionsSizer->Add( sbOptions, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 );
m_optionsSizer->Add( sbOptions, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 );
wxBoxSizer* bOptionsRight;
bOptionsRight = new wxBoxSizer( wxVERTICAL );
@ -164,6 +164,11 @@ DIALOG_PLOT_SCHEMATIC_BASE::DIALOG_PLOT_SCHEMATIC_BASE( wxWindow* parent, wxWind
m_plotPDFPropertyPopups->SetValue(true);
sbSizer4->Add( m_plotPDFPropertyPopups, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_plotPDFMetadata = new wxCheckBox( sbSizer4->GetStaticBox(), wxID_ANY, _("Generate metadata from AUTHOR && SUBJECT variables"), wxDefaultPosition, wxDefaultSize, 0 );
m_plotPDFMetadata->SetToolTip( _("Generate PDF document properties from AUTHOR and SUBJECT text variables") );
sbSizer4->Add( m_plotPDFMetadata, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
bOptionsRight->Add( sbSizer4, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb)
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -67,6 +67,7 @@ class DIALOG_PLOT_SCHEMATIC_BASE : public DIALOG_SHIM
wxTextCtrl* m_penWidthCtrl;
wxStaticText* m_penWidthUnits;
wxCheckBox* m_plotPDFPropertyPopups;
wxCheckBox* m_plotPDFMetadata;
wxStaticBoxSizer* m_otherOptions;
wxCheckBox* m_openFileAfterPlot;
WX_HTML_REPORT_PANEL* m_MessagesBox;

View File

@ -213,6 +213,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPlot( JOB* aJob )
settings.m_HPGLPenSize = aPlotJob->m_HPGLPenSize;
settings.m_HPGLPlotOrigin = hpglOrigin;
settings.m_PDFPropertyPopups = aPlotJob->m_PDFPropertyPopups;
settings.m_PDFMetadata = aPlotJob->m_PDFMetadata;
settings.m_outputDirectory = aPlotJob->m_outputDirectory;
settings.m_outputFile = aPlotJob->m_outputFile;
settings.m_pageSizeSelect = pageSizeSelect;

View File

@ -497,6 +497,9 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() :
m_params.emplace_back( new PARAM<bool>( "plot.pdf_property_popups",
&m_PlotPanel.pdf_property_popups, true ) );
m_params.emplace_back( new PARAM<bool>( "plot.pdf_metadata",
&m_PlotPanel.pdf_metadata, true ) );
m_params.emplace_back( new PARAM<int>( "plot.hpgl_paper_size",
&m_PlotPanel.hpgl_paper_size, 0 ) );

View File

@ -250,6 +250,7 @@ public:
double hpgl_pen_size;
int hpgl_origin;
bool pdf_property_popups;
bool pdf_metadata;
bool open_file_after_plot;
};

View File

@ -153,6 +153,19 @@ void SCH_PLOTTER::createPDFFile( const SCH_PLOT_SETTINGS& aPlotSettings,
SCH_SCREEN* screen = m_schematic->CurrentSheet().LastScreen();
wxString sheetName = sheetList[i].Last()->GetFields()[SHEETNAME].GetShownText( false );
if( aPlotSettings.m_PDFMetadata )
{
msg = wxS( "AUTHOR" );
if( m_schematic->ResolveTextVar( &sheetList[i], &msg, 0 ) )
plotter->SetAuthor( msg );
msg = wxS( "SUBJECT" );
if( m_schematic->ResolveTextVar( &sheetList[i], &msg, 0 ) )
plotter->SetSubject( msg );
}
if( i == 0 )
{
try

View File

@ -88,6 +88,7 @@ struct SCH_PLOT_SETTINGS
double m_HPGLPenSize; // for HPGL format only: pen size
HPGL_PAGE_SIZE m_HPGLPaperSizeSelect;
bool m_PDFPropertyPopups;
bool m_PDFMetadata;
wxString m_theme;
wxString m_outputDirectory;
@ -104,6 +105,7 @@ struct SCH_PLOT_SETTINGS
m_HPGLPenSize( 1.0 ),
m_HPGLPaperSizeSelect( HPGL_PAGE_SIZE::DEFAULT ),
m_PDFPropertyPopups( false ),
m_PDFMetadata( false ),
m_theme(),
m_outputDirectory(),
m_outputFile(),

View File

@ -151,8 +151,9 @@ public:
virtual void SetDash( int aLineWidth, LINE_STYLE aLineStyle ) = 0;
virtual void SetCreator( const wxString& aCreator ) { m_creator = aCreator; }
virtual void SetTitle( const wxString& aTitle ) { m_title = aTitle; }
virtual void SetAuthor( const wxString& aAuthor ) { m_author = aAuthor; }
virtual void SetSubject( const wxString& aSubject ) { m_subject = aSubject; }
/**
* Add a line to the list of free lines to print at the beginning of the file.
@ -669,6 +670,8 @@ protected: // variables used in most of plotters:
wxString m_creator;
wxString m_filename;
wxString m_title;
wxString m_author;
wxString m_subject;
PAGE_INFO m_pageInfo;
VECTOR2I m_paperSize; // Paper size in IU - not in mils

View File

@ -36,6 +36,7 @@
#define ARG_HPGL_ORIGIN "--origin"
#define ARG_PAGES "--pages"
#define ARG_EXCLUDE_PDF_PROPERTY_POPUPS "--exclude-pdf-property-popups"
#define ARG_EXCLUDE_PDF_METADATA "--exclude-pdf-metadata"
const JOB_HPGL_PLOT_ORIGIN_AND_UNITS hpgl_origin_ops[4] = {
JOB_HPGL_PLOT_ORIGIN_AND_UNITS::PLOTTER_BOT_LEFT,
@ -79,6 +80,10 @@ CLI::SCH_EXPORT_PLOT_COMMAND::SCH_EXPORT_PLOT_COMMAND( const std::string& aName,
m_argParser.add_argument( ARG_EXCLUDE_PDF_PROPERTY_POPUPS )
.help( UTF8STDSTR( _( "Do not generate property popups in PDF" ) ) )
.flag();
m_argParser.add_argument( ARG_EXCLUDE_PDF_METADATA )
.help( UTF8STDSTR( _( "Do not generate PDF metadata from AUTHOR and SUBJECT variables" ) ) )
.flag();
}
if( aPlotFormat == SCH_PLOT_FORMAT::PDF
@ -178,6 +183,7 @@ int CLI::SCH_EXPORT_PLOT_COMMAND::doPerform( KIWAY& aKiway )
else if( m_plotFormat == SCH_PLOT_FORMAT::PDF )
{
plotJob->m_PDFPropertyPopups = !m_argParser.get<bool>( ARG_EXCLUDE_PDF_PROPERTY_POPUPS );
plotJob->m_PDFMetadata = !m_argParser.get<bool>( ARG_EXCLUDE_PDF_METADATA );
}
int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, plotJob.get() );

View File

@ -367,6 +367,7 @@ void DIALOG_PLOT::init_Dialog()
m_PDFColorChoice->SetSelection( m_plotOpts.GetBlackAndWhite() ? 1 : 0 );
m_frontFPPropertyPopups->SetValue( m_plotOpts.m_PDFFrontFPPropertyPopups );
m_backFPPropertyPopups->SetValue( m_plotOpts.m_PDFBackFPPropertyPopups );
m_pdfMetadata->SetValue( m_plotOpts.m_PDFMetadata );
// Initialize a few other parameters, which can also be modified
// from the drill dialog
@ -930,6 +931,7 @@ void DIALOG_PLOT::applyPlotSettings()
tempOptions.SetBlackAndWhite( !!m_PDFColorChoice->GetSelection() );
tempOptions.m_PDFFrontFPPropertyPopups = m_frontFPPropertyPopups->GetValue();
tempOptions.m_PDFBackFPPropertyPopups = m_backFPPropertyPopups->GetValue();
tempOptions.m_PDFMetadata = m_pdfMetadata->GetValue();
}
else
{
@ -1235,6 +1237,21 @@ void DIALOG_PLOT::Plot( wxCommandEvent& event )
if( plotter )
{
plotter->SetTitle( ExpandTextVars( board->GetTitleBlock().GetTitle(), &textResolver ) );
if( m_plotOpts.m_PDFMetadata )
{
msg = wxS( "AUTHOR" );
if( board->ResolveTextVar( &msg, 0 ) )
plotter->SetAuthor( msg );
msg = wxS( "SUBJECT" );
if( board->ResolveTextVar( &msg, 0 ) )
plotter->SetSubject( msg );
}
PlotBoardLayers( board, plotter, plotSequence, m_plotOpts );
PlotInteractiveLayer( board, plotter, m_plotOpts );
plotter->EndPlot();

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -413,6 +413,11 @@ DIALOG_PLOT_BASE::DIALOG_PLOT_BASE( wxWindow* parent, wxWindowID id, const wxStr
m_backFPPropertyPopups = new wxCheckBox( m_PDFOptionsSizer->GetStaticBox(), wxID_ANY, _("Generate property popups for back footprints"), wxDefaultPosition, wxDefaultSize, 0 );
gbSizer4->Add( m_backFPPropertyPopups, wxGBPosition( 2, 0 ), wxGBSpan( 1, 2 ), wxRIGHT|wxLEFT, 5 );
m_pdfMetadata = new wxCheckBox( m_PDFOptionsSizer->GetStaticBox(), wxID_ANY, _("Generate metadata from AUTHOR && SUBJECT variables"), wxDefaultPosition, wxDefaultSize, 0 );
m_pdfMetadata->SetToolTip( _("Generate PDF document properties from AUTHOR and SUBJECT text variables") );
gbSizer4->Add( m_pdfMetadata, wxGBPosition( 3, 0 ), wxGBSpan( 1, 2 ), wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_PDFOptionsSizer->Add( gbSizer4, 1, wxEXPAND|wxBOTTOM, 5 );

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -124,6 +124,7 @@ class DIALOG_PLOT_BASE : public DIALOG_SHIM
wxChoice* m_PDFColorChoice;
wxCheckBox* m_frontFPPropertyPopups;
wxCheckBox* m_backFPPropertyPopups;
wxCheckBox* m_pdfMetadata;
WX_HTML_REPORT_PANEL* m_messagesPanel;
wxBoxSizer* m_sizerButtons;
wxButton* m_buttonDRC;

View File

@ -136,6 +136,7 @@ PCB_PLOT_PARAMS::PCB_PLOT_PARAMS()
m_PDFFrontFPPropertyPopups = true;
m_PDFBackFPPropertyPopups = true;
m_PDFMetadata = true;
// This parameter controls if the NPTH pads will be plotted or not
// it is a "local" parameter
@ -223,6 +224,9 @@ void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter,
KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1,
getTokenName( T_pdf_back_fp_property_popups ),
m_PDFBackFPPropertyPopups );
KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1,
getTokenName( T_pdf_metadata ),
m_PDFMetadata );
// DXF options
KICAD_FORMAT::FormatBool( aFormatter, aNestLevel + 1, getTokenName( T_dxfpolygonmode ),
@ -334,6 +338,9 @@ bool PCB_PLOT_PARAMS::IsSameAs( const PCB_PLOT_PARAMS &aPcbPlotParams ) const
if( m_PDFBackFPPropertyPopups != aPcbPlotParams.m_PDFBackFPPropertyPopups )
return false;
if( m_PDFMetadata != aPcbPlotParams.m_PDFMetadata )
return false;
if( m_A4Output != aPcbPlotParams.m_A4Output )
return false;
@ -577,6 +584,10 @@ void PCB_PLOT_PARAMS_PARSER::Parse( PCB_PLOT_PARAMS* aPcbPlotParams )
aPcbPlotParams->m_PDFFrontFPPropertyPopups = parseBool();
break;
case T_pdf_metadata:
aPcbPlotParams->m_PDFMetadata = parseBool();
break;
case T_dxfpolygonmode:
aPcbPlotParams->m_DXFPolygonMode = parseBool();
break;

View File

@ -192,6 +192,7 @@ public:
public:
bool m_PDFFrontFPPropertyPopups; ///< Generate PDF property popup menus for footprints
bool m_PDFBackFPPropertyPopups; ///< on front and/or back of board
bool m_PDFMetadata; ///< Generate PDF metadata for SUBJECT and AUTHOR
private:
friend class PCB_PLOT_PARAMS_PARSER;