From c54ebdecd2d3019633a31a5f38b3745f8976f2ac Mon Sep 17 00:00:00 2001 From: Dhinesh Date: Tue, 8 Oct 2024 00:22:18 +0530 Subject: [PATCH] Fix missing text and graphics in PDFs generated by "Plot to PDF" The "Plot to PDF" function was producing PDF files that lacked text and graphic items in viewers like Adobe and Foxit. This issue was caused by the use of the %g format specifier for floating-point numbers defined in the PDF specification when writing text and drawing shapes in the PDF. This incorrect format led to a "Too Few Operands" error during rendering. To resolve this issue, all floating-point numbers must be specified in fixed-point format according to the PDF specification wherever the issue was generated. Fixes #16465 (cherry picked from commit 8851cd77ab2fb0e910d604171b1e0abfda825f1c) --- common/plotters/PDF_plotter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/plotters/PDF_plotter.cpp b/common/plotters/PDF_plotter.cpp index c4a6a28c04..b6ac58e4d2 100644 --- a/common/plotters/PDF_plotter.cpp +++ b/common/plotters/PDF_plotter.cpp @@ -401,12 +401,12 @@ void PDF_PLOTTER::PlotPoly( const std::vector& aCornerList, FILL_T aFi SetCurrentLineWidth( aWidth ); VECTOR2D pos = userToDeviceCoordinates( aCornerList[0] ); - fprintf( m_workFile, "%g %g m\n", pos.x, pos.y ); + fprintf( m_workFile, "%f %f m\n", pos.x, pos.y ); for( unsigned ii = 1; ii < aCornerList.size(); ii++ ) { pos = userToDeviceCoordinates( aCornerList[ii] ); - fprintf( m_workFile, "%g %g l\n", pos.x, pos.y ); + fprintf( m_workFile, "%f %f l\n", pos.x, pos.y ); } // Close path and stroke and/or fill @@ -439,7 +439,7 @@ void PDF_PLOTTER::PenTo( const VECTOR2I& pos, char plume ) if( m_penState != plume || pos != m_penLastpos ) { VECTOR2D pos_dev = userToDeviceCoordinates( pos ); - fprintf( m_workFile, "%g %g %c\n", + fprintf( m_workFile, "%f %f %c\n", pos_dev.x, pos_dev.y, ( plume=='D' ) ? 'l' : 'm' ); } @@ -1664,7 +1664,7 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos, coordinate system will be used for the overlining. Also the %f for the trig part of the matrix to avoid %g going in exponential format (which is not supported) */ - fprintf( m_workFile, "q %f %f %f %f %g %g cm BT %s %g Tf %d Tr %g Tz ", + fprintf( m_workFile, "q %f %f %f %f %f %f cm BT %s %g Tf %d Tr %g Tz ", ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f, fontname, heightFactor, render_mode, wideningFactor * 100 );