diff --git a/common/common.cpp b/common/common.cpp index de5c9dab97..8b808b701e 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 @@ -353,7 +353,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 bcc4b55c0d..562b1c7c6e 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 @@ -38,7 +38,8 @@ #include #include -#include // for IsGotoPageHref +#include // ResolveUriByEnvVars +#include // for IsGotoPageHref #include #include #include @@ -1333,6 +1334,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 ) ); @@ -1341,6 +1345,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 b7614adc7c..c6b82853b6 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 89c8a7f67d..a7818635b2 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 e4f97d60d7..9ad3d526f8 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 @@ -134,8 +134,10 @@ void SCH_PLOTTER::createPDFFile( const SCH_PLOT_OPTS& aPlotOpts, 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( !aPlotOpts.m_blackAndWhite ); plotter->SetCreator( wxT( "Eeschema-PDF" ) ); diff --git a/eeschema/sch_plotter.h b/eeschema/sch_plotter.h index 1c53ac5aea..1cca5e20de 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 b39a7e5520..668c19285f 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 @@ -106,7 +106,7 @@ KICOMMON_API bool IsTextVar( const wxString& aSource ); /** * Replace any environment and/or text variables in URIs */ -KICOMMON_API const wxString ResolveUriByEnvVars( const wxString& aUri, PROJECT* aProject ); +KICOMMON_API const wxString ResolveUriByEnvVars( const wxString& aUri, const PROJECT* aProject ); KICOMMON_API long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec ); diff --git a/include/plotters/plotter.h b/include/plotters/plotter.h index 3f423d2ba5..3117d4416d 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 @@ -108,7 +108,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(); @@ -679,6 +679,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 f32d04438c..0411e9befe 100644 --- a/pcbnew/plot_board_layers.cpp +++ b/pcbnew/plot_board_layers.cpp @@ -1193,6 +1193,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; @@ -1215,7 +1217,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: