From 086b9907c28bd0552c5cd661dd36e82a6c03a83f Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Wed, 5 Mar 2025 21:28:56 -0500 Subject: [PATCH] Convert fputs to fmt::print to get exceptions on io fail --- common/plotters/SVG_plotter.cpp | 61 +++++++++++++++------------------ 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/common/plotters/SVG_plotter.cpp b/common/plotters/SVG_plotter.cpp index ea4fbb6422..80c647fc2a 100644 --- a/common/plotters/SVG_plotter.cpp +++ b/common/plotters/SVG_plotter.cpp @@ -220,13 +220,13 @@ void SVG_PLOTTER::setFillMode( FILL_T fill ) void SVG_PLOTTER::setSVGPlotStyle( int aLineWidth, bool aIsGroup, const std::string& aExtraStyle ) { if( aIsGroup ) - fputs( "\n\n", m_outputFile ); + fmt::print( m_outputFile, ">" ); m_graphics_changed = false; } - fputs( "\n", m_outputFile ); + fmt::print( m_outputFile, "\n" ); } @@ -603,7 +603,7 @@ void SVG_PLOTTER::PlotPoly( const std::vector& aCornerList, FILL_T aFi setFillMode( aFill ); SetCurrentLineWidth( aWidth ); - fputs( "& aCornerList, FILL_T aFi // If the corner list ends where it begins, then close the poly if( aCornerList.front() == aCornerList.back() ) { - fputs( "Z\" /> \n", m_outputFile ); + fmt::print( m_outputFile, "Z\" /> \n" ); } else { @@ -693,7 +693,7 @@ void SVG_PLOTTER::PlotImage( const wxImage& aImage, const VECTOR2I& aPos, double fmt::print( m_outputFile, "{}", static_cast( encoded[i] ) ); if( ( i % 64 ) == 63 ) - fputs( "\n", m_outputFile ); + fmt::print( m_outputFile, "\n" ); } fmt::print( m_outputFile, @@ -710,7 +710,7 @@ void SVG_PLOTTER::PenTo( const VECTOR2I& pos, char plume ) { if( m_penState != 'Z' ) { - fputs( "\" />\n", m_outputFile ); + fmt::print( m_outputFile, "\" />\n" ); m_penState = 'Z'; m_penLastpos.x = -1; m_penLastpos.y = -1; @@ -756,24 +756,17 @@ bool SVG_PLOTTER::StartPlot( const wxString& aPageNumber ) { wxASSERT( m_outputFile ); - static const char* header[] = - { - "\n", - " \n", - "\n" + " \n" + "\n", m_outputFile ); + fmt::print( m_outputFile, "stroke-linecap:round; stroke-linejoin:round;\"\n" ); + fmt::print( m_outputFile, " transform=\"translate(0 0) scale(1 1)\">\n" ); return true; } bool SVG_PLOTTER::EndPlot() { - fputs( " \n\n", m_outputFile ); + fmt::print( m_outputFile, " \n\n" ); fclose( m_outputFile ); m_outputFile = nullptr; @@ -919,7 +912,7 @@ void SVG_PLOTTER::Text( const VECTOR2I& aPos, TO_UTF8( XmlEsc( aText ) ) ); if( !aOrient.IsZero() ) - fputs( "\n", m_outputFile ); + fmt::print( m_outputFile, "\n" ); } // Output the text again as graphics with a tag (for non-WYSIWYG search and for @@ -932,7 +925,7 @@ void SVG_PLOTTER::Text( const VECTOR2I& aPos, PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, aBold, aMultilineAllowed, aFont, aFontMetrics ); - fputs( "", m_outputFile ); + fmt::print( m_outputFile, "" ); } }