diff --git a/common/common.cpp b/common/common.cpp index 2786d207d7..7e36ac337e 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2014-2020 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -347,7 +347,7 @@ const wxString ExpandEnvVarSubstitutions( const wxString& aString, const PROJECT } -const wxString ResolveUriByEnvVars( const wxString& aUri, PROJECT* aProject ) +const wxString ResolveUriByEnvVars( const wxString& aUri, const PROJECT* aProject ) { wxString uri = ExpandTextVars( aUri, aProject ); diff --git a/common/plotters/PDF_plotter.cpp b/common/plotters/PDF_plotter.cpp index d95be91778..27f775f566 100644 --- a/common/plotters/PDF_plotter.cpp +++ b/common/plotters/PDF_plotter.cpp @@ -7,7 +7,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 1992-2012 Lorenzo Marcantonio, l.marcantonio@logossrl.com - * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -37,7 +37,8 @@ #include #include -#include // for IsGotoPageHref +#include // ResolveUriByEnvVars +#include // for IsGotoPageHref #include #include #include @@ -1332,6 +1333,9 @@ bool PDF_PLOTTER::EndPlot() { wxString href = property.substr( property.Find( "http:" ) ); + if( m_project ) + href = ResolveUriByEnvVars( href, m_project ); + js += wxString::Format( wxT( "[\"%s\", \"%s\"],\n" ), EscapeString( property, CTX_JS_STR ), EscapeString( href, CTX_JS_STR ) ); @@ -1340,6 +1344,20 @@ bool PDF_PLOTTER::EndPlot() { wxString href = property.substr( property.Find( "https:" ) ); + if( m_project ) + href = ResolveUriByEnvVars( href, m_project ); + + js += wxString::Format( wxT( "[\"%s\", \"%s\"],\n" ), + EscapeString( property, CTX_JS_STR ), + EscapeString( href, CTX_JS_STR ) ); + } + else if( property.Find( "file:" ) >= 0 ) + { + wxString href = property.substr( property.Find( "file:" ) ); + + if( m_project ) + href = ResolveUriByEnvVars( href, m_project ); + js += wxString::Format( wxT( "[\"%s\", \"%s\"],\n" ), EscapeString( property, CTX_JS_STR ), EscapeString( href, CTX_JS_STR ) ); diff --git a/common/plotters/SVG_plotter.cpp b/common/plotters/SVG_plotter.cpp index ab640ef976..faa63e97f5 100644 --- a/common/plotters/SVG_plotter.cpp +++ b/common/plotters/SVG_plotter.cpp @@ -162,7 +162,8 @@ static wxString XmlEsc( const wxString& aStr, bool isAttribute = false ) } -SVG_PLOTTER::SVG_PLOTTER() +SVG_PLOTTER::SVG_PLOTTER( const PROJECT* aProject ) : + PSLIKE_PLOTTER( aProject ) { m_graphics_changed = true; SetTextMode( PLOT_TEXT_MODE::STROKE ); diff --git a/common/plotters/plotter.cpp b/common/plotters/plotter.cpp index 34e72cf877..a18e5f84e8 100644 --- a/common/plotters/plotter.cpp +++ b/common/plotters/plotter.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -44,7 +44,8 @@ #include #include // for KiROUND -PLOTTER::PLOTTER( ) +PLOTTER::PLOTTER( const PROJECT* aProject ) : + m_project( aProject ) { m_plotScale = 1; m_currentPenWidth = -1; // To-be-set marker diff --git a/eeschema/sch_plotter.cpp b/eeschema/sch_plotter.cpp index d1618ec0e1..32884cb492 100644 --- a/eeschema/sch_plotter.cpp +++ b/eeschema/sch_plotter.cpp @@ -4,7 +4,7 @@ * Copyright (C) 1992-2018 Jean-Pierre Charras jp.charras at wanadoo.fr * Copyright (C) 1992-2010 Lorenzo Marcantonio * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -132,8 +132,10 @@ void SCH_PLOTTER::createPDFFile( const SCH_PLOT_SETTINGS& aPlotSettings, sheetList.push_back( m_schematic->CurrentSheet() ); } + wxCHECK( m_schematic, /* void */ ); + // Allocate the plotter and set the job level parameter - PDF_PLOTTER* plotter = new PDF_PLOTTER(); + PDF_PLOTTER* plotter = new PDF_PLOTTER( &m_schematic->Prj() ); plotter->SetRenderSettings( aRenderSettings ); plotter->SetColorMode( !aPlotSettings.m_blackAndWhite ); plotter->SetCreator( wxT( "Eeschema-PDF" ) ); diff --git a/eeschema/sch_plotter.h b/eeschema/sch_plotter.h index 155d49f5c6..e1e9992d92 100644 --- a/eeschema/sch_plotter.h +++ b/eeschema/sch_plotter.h @@ -4,7 +4,7 @@ * Copyright (C) 1992-2018 Jean-Pierre Charras jp.charras at wanadoo.fr * Copyright (C) 1992-2010 Lorenzo Marcantonio * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/include/common.h b/include/common.h index 9f2f7bb936..3f1d040866 100644 --- a/include/common.h +++ b/include/common.h @@ -4,7 +4,7 @@ * Copyright (C) 2014-2020 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2007-2015 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -104,8 +104,7 @@ bool IsTextVar( const wxString& aSource ); /** * Replace any environment and/or text variables in URIs */ -const wxString ResolveUriByEnvVars( const wxString& aUri, PROJECT* aProject ); - +const wxString ResolveUriByEnvVars( const wxString& aUri, const PROJECT* aProject ); long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec ); diff --git a/include/plotters/plotter.h b/include/plotters/plotter.h index 32785ce98e..698a25715d 100644 --- a/include/plotters/plotter.h +++ b/include/plotters/plotter.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -107,7 +107,7 @@ public: static const int DO_NOT_SET_LINE_WIDTH = -2; // Skip selection static const int USE_DEFAULT_LINE_WIDTH = -1; // use the default pen - PLOTTER(); + PLOTTER( const PROJECT* aProject = nullptr ); virtual ~PLOTTER(); @@ -675,6 +675,8 @@ protected: // variables used in most of plotters: wxArrayString m_headerExtraLines; // a set of string to print in header file RENDER_SETTINGS* m_renderSettings; + + const PROJECT* m_project; }; diff --git a/include/plotters/plotters_pslike.h b/include/plotters/plotters_pslike.h index a6e757350a..673ae23fba 100644 --- a/include/plotters/plotters_pslike.h +++ b/include/plotters/plotters_pslike.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -35,7 +35,8 @@ class PSLIKE_PLOTTER : public PLOTTER { public: - PSLIKE_PLOTTER() : + PSLIKE_PLOTTER( const PROJECT* aProject = nullptr) : + PLOTTER( aProject ), plotScaleAdjX( 1 ), plotScaleAdjY( 1 ), m_textMode( PLOT_TEXT_MODE::PHANTOM ) @@ -143,7 +144,8 @@ protected: class PS_PLOTTER : public PSLIKE_PLOTTER { public: - PS_PLOTTER() + PS_PLOTTER( const PROJECT* aProject = nullptr ) : + PSLIKE_PLOTTER( aProject ) { // The phantom plot in postscript is an hack and reportedly // crashes Adobe's own postscript interpreter! @@ -238,7 +240,8 @@ protected: class PDF_PLOTTER : public PSLIKE_PLOTTER { public: - PDF_PLOTTER() : + PDF_PLOTTER( const PROJECT* aProject = nullptr ) : + PSLIKE_PLOTTER( aProject ), m_pageTreeHandle( 0 ), m_fontResDictHandle( 0 ), m_imgResDictHandle( 0 ), @@ -518,7 +521,7 @@ protected: class SVG_PLOTTER : public PSLIKE_PLOTTER { public: - SVG_PLOTTER(); + SVG_PLOTTER( const PROJECT* aProject = nullptr ); static wxString GetDefaultFileExtension() { diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp index 4d173d3bac..faf8e7707a 100644 --- a/pcbnew/plot_board_layers.cpp +++ b/pcbnew/plot_board_layers.cpp @@ -1146,6 +1146,8 @@ PLOTTER* StartPlotBoard( BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aL const wxString& aLayerName, const wxString& aFullFileName, const wxString& aSheetName, const wxString& aSheetPath ) { + wxCHECK( aBoard && aPlotOpts, nullptr ); + // Create the plotter driver and set the few plotter specific options PLOTTER* plotter = nullptr; @@ -1168,7 +1170,7 @@ PLOTTER* StartPlotBoard( BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aL break; case PLOT_FORMAT::PDF: - plotter = new PDF_PLOTTER(); + plotter = new PDF_PLOTTER( aBoard->GetProject() ); break; case PLOT_FORMAT::HPGL: