Fix variable naming in pdf plotter

This commit is contained in:
Roberto Fernandez Bautista 2022-05-15 13:59:23 +01:00 committed by Jeff Young
parent 20ed9b475b
commit 366b0ab08b
2 changed files with 98 additions and 98 deletions

View File

@ -140,7 +140,7 @@ void PDF_PLOTTER::SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
void PDF_PLOTTER::SetCurrentLineWidth( int aWidth, void* aData ) void PDF_PLOTTER::SetCurrentLineWidth( int aWidth, void* aData )
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
if( aWidth == DO_NOT_SET_LINE_WIDTH ) if( aWidth == DO_NOT_SET_LINE_WIDTH )
return; return;
@ -153,7 +153,7 @@ void PDF_PLOTTER::SetCurrentLineWidth( int aWidth, void* aData )
wxASSERT_MSG( aWidth > 0, "Plotter called to set negative pen width" ); wxASSERT_MSG( aWidth > 0, "Plotter called to set negative pen width" );
if( aWidth != m_currentPenWidth ) if( aWidth != m_currentPenWidth )
fprintf( workFile, "%g w\n", userToDeviceSize( aWidth ) ); fprintf( m_workFile, "%g w\n", userToDeviceSize( aWidth ) );
m_currentPenWidth = aWidth; m_currentPenWidth = aWidth;
} }
@ -161,7 +161,7 @@ void PDF_PLOTTER::SetCurrentLineWidth( int aWidth, void* aData )
void PDF_PLOTTER::emitSetRGBColor( double r, double g, double b, double a ) void PDF_PLOTTER::emitSetRGBColor( double r, double g, double b, double a )
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
// PDF treats all colors as opaque, so the best we can do with alpha is generate an // PDF treats all colors as opaque, so the best we can do with alpha is generate an
// appropriate blended color assuming white paper. // appropriate blended color assuming white paper.
@ -172,60 +172,60 @@ void PDF_PLOTTER::emitSetRGBColor( double r, double g, double b, double a )
b = ( b * a ) + ( 1 - a ); b = ( b * a ) + ( 1 - a );
} }
fprintf( workFile, "%g %g %g rg %g %g %g RG\n", r, g, b, r, g, b ); fprintf( m_workFile, "%g %g %g rg %g %g %g RG\n", r, g, b, r, g, b );
} }
void PDF_PLOTTER::SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle ) void PDF_PLOTTER::SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle )
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
switch( aLineStyle ) switch( aLineStyle )
{ {
case PLOT_DASH_TYPE::DASH: case PLOT_DASH_TYPE::DASH:
fprintf( workFile, "[%d %d] 0 d\n", fprintf( m_workFile, "[%d %d] 0 d\n",
(int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) ); (int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break; break;
case PLOT_DASH_TYPE::DOT: case PLOT_DASH_TYPE::DOT:
fprintf( workFile, "[%d %d] 0 d\n", fprintf( m_workFile, "[%d %d] 0 d\n",
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) ); (int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break; break;
case PLOT_DASH_TYPE::DASHDOT: case PLOT_DASH_TYPE::DASHDOT:
fprintf( workFile, "[%d %d %d %d] 0 d\n", fprintf( m_workFile, "[%d %d %d %d] 0 d\n",
(int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ), (int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ),
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) ); (int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break; break;
case PLOT_DASH_TYPE::DASHDOTDOT: case PLOT_DASH_TYPE::DASHDOTDOT:
fprintf( workFile, "[%d %d %d %d %d %d] 0 d\n", fprintf( m_workFile, "[%d %d %d %d %d %d] 0 d\n",
(int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ), (int) GetDashMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ),
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ), (int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ),
(int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) ); (int) GetDotMarkLenIU( aLineWidth ), (int) GetDashGapLenIU( aLineWidth ) );
break; break;
default: default:
fputs( "[] 0 d\n", workFile ); fputs( "[] 0 d\n", m_workFile );
} }
} }
void PDF_PLOTTER::Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T fill, int width ) void PDF_PLOTTER::Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T fill, int width )
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
VECTOR2D p1_dev = userToDeviceCoordinates( p1 ); VECTOR2D p1_dev = userToDeviceCoordinates( p1 );
VECTOR2D p2_dev = userToDeviceCoordinates( p2 ); VECTOR2D p2_dev = userToDeviceCoordinates( p2 );
SetCurrentLineWidth( width ); SetCurrentLineWidth( width );
fprintf( workFile, "%g %g %g %g re %c\n", p1_dev.x, p1_dev.y, fprintf( m_workFile, "%g %g %g %g re %c\n", p1_dev.x, p1_dev.y,
p2_dev.x - p1_dev.x, p2_dev.y - p1_dev.y, fill == FILL_T::NO_FILL ? 'S' : 'B' ); p2_dev.x - p1_dev.x, p2_dev.y - p1_dev.y, fill == FILL_T::NO_FILL ? 'S' : 'B' );
} }
void PDF_PLOTTER::Circle( const VECTOR2I& pos, int diametre, FILL_T aFill, int width ) void PDF_PLOTTER::Circle( const VECTOR2I& pos, int diametre, FILL_T aFill, int width )
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
VECTOR2D pos_dev = userToDeviceCoordinates( pos ); VECTOR2D pos_dev = userToDeviceCoordinates( pos );
double radius = userToDeviceSize( diametre / 2.0 ); double radius = userToDeviceSize( diametre / 2.0 );
@ -249,7 +249,7 @@ void PDF_PLOTTER::Circle( const VECTOR2I& pos, int diametre, FILL_T aFill, int w
double magic = radius * 0.551784; // You don't want to know where this come from double magic = radius * 0.551784; // You don't want to know where this come from
// This is the convex hull for the bezier approximated circle // This is the convex hull for the bezier approximated circle
fprintf( workFile, "%g %g m " fprintf( m_workFile, "%g %g m "
"%g %g %g %g %g %g c " "%g %g %g %g %g %g c "
"%g %g %g %g %g %g c " "%g %g %g %g %g %g c "
"%g %g %g %g %g %g c " "%g %g %g %g %g %g c "
@ -279,7 +279,7 @@ void PDF_PLOTTER::Circle( const VECTOR2I& pos, int diametre, FILL_T aFill, int w
void PDF_PLOTTER::Arc( const VECTOR2I& aCenter, const VECTOR2I& aStart, const VECTOR2I& aEnd, void PDF_PLOTTER::Arc( const VECTOR2I& aCenter, const VECTOR2I& aStart, const VECTOR2I& aEnd,
FILL_T aFill, int aWidth, int aMaxError ) FILL_T aFill, int aWidth, int aMaxError )
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
/* /*
* Arcs are not so easily approximated by beziers (in the general case), so we approximate * Arcs are not so easily approximated by beziers (in the general case), so we approximate
@ -304,7 +304,7 @@ void PDF_PLOTTER::Arc( const VECTOR2I& aCenter, const VECTOR2I& aStart, const VE
SetCurrentLineWidth( aWidth ); SetCurrentLineWidth( aWidth );
VECTOR2D pos_dev = userToDeviceCoordinates( start ); VECTOR2D pos_dev = userToDeviceCoordinates( start );
fprintf( workFile, "%g %g m ", pos_dev.x, pos_dev.y ); fprintf( m_workFile, "%g %g m ", pos_dev.x, pos_dev.y );
for( EDA_ANGLE ii = delta; startAngle + ii < endAngle; ii += delta ) for( EDA_ANGLE ii = delta; startAngle + ii < endAngle; ii += delta )
{ {
@ -312,22 +312,22 @@ void PDF_PLOTTER::Arc( const VECTOR2I& aCenter, const VECTOR2I& aStart, const VE
RotatePoint( pt, aCenter, -ii ); RotatePoint( pt, aCenter, -ii );
pos_dev = userToDeviceCoordinates( pt ); pos_dev = userToDeviceCoordinates( pt );
fprintf( workFile, "%g %g l ", pos_dev.x, pos_dev.y ); fprintf( m_workFile, "%g %g l ", pos_dev.x, pos_dev.y );
} }
pos_dev = userToDeviceCoordinates( end ); pos_dev = userToDeviceCoordinates( end );
fprintf( workFile, "%g %g l ", pos_dev.x, pos_dev.y ); fprintf( m_workFile, "%g %g l ", pos_dev.x, pos_dev.y );
// The arc is drawn... if not filled we stroke it, otherwise we finish // The arc is drawn... if not filled we stroke it, otherwise we finish
// closing the pie at the center // closing the pie at the center
if( aFill == FILL_T::NO_FILL ) if( aFill == FILL_T::NO_FILL )
{ {
fputs( "S\n", workFile ); fputs( "S\n", m_workFile );
} }
else else
{ {
pos_dev = userToDeviceCoordinates( aCenter ); pos_dev = userToDeviceCoordinates( aCenter );
fprintf( workFile, "%g %g l b\n", pos_dev.x, pos_dev.y ); fprintf( m_workFile, "%g %g l b\n", pos_dev.x, pos_dev.y );
} }
} }
@ -335,7 +335,7 @@ void PDF_PLOTTER::Arc( const VECTOR2I& aCenter, const VECTOR2I& aStart, const VE
void PDF_PLOTTER::Arc( const VECTOR2I& aCenter, const EDA_ANGLE& aStartAngle, void PDF_PLOTTER::Arc( const VECTOR2I& aCenter, const EDA_ANGLE& aStartAngle,
const EDA_ANGLE& aEndAngle, int aRadius, FILL_T aFill, int aWidth ) const EDA_ANGLE& aEndAngle, int aRadius, FILL_T aFill, int aWidth )
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
if( aRadius <= 0 ) if( aRadius <= 0 )
{ {
@ -365,31 +365,31 @@ void PDF_PLOTTER::Arc( const VECTOR2I& aCenter, const EDA_ANGLE& aStartAngle,
start.x = aCenter.x + KiROUND( aRadius * (-startAngle).Cos() ); start.x = aCenter.x + KiROUND( aRadius * (-startAngle).Cos() );
start.y = aCenter.y + KiROUND( aRadius * (-startAngle).Sin() ); start.y = aCenter.y + KiROUND( aRadius * (-startAngle).Sin() );
VECTOR2D pos_dev = userToDeviceCoordinates( start ); VECTOR2D pos_dev = userToDeviceCoordinates( start );
fprintf( workFile, "%g %g m ", pos_dev.x, pos_dev.y ); fprintf( m_workFile, "%g %g m ", pos_dev.x, pos_dev.y );
for( EDA_ANGLE ii = startAngle + delta; ii < endAngle; ii += delta ) for( EDA_ANGLE ii = startAngle + delta; ii < endAngle; ii += delta )
{ {
end.x = aCenter.x + KiROUND( aRadius * (-ii).Cos() ); end.x = aCenter.x + KiROUND( aRadius * (-ii).Cos() );
end.y = aCenter.y + KiROUND( aRadius * (-ii).Sin() ); end.y = aCenter.y + KiROUND( aRadius * (-ii).Sin() );
pos_dev = userToDeviceCoordinates( end ); pos_dev = userToDeviceCoordinates( end );
fprintf( workFile, "%g %g l ", pos_dev.x, pos_dev.y ); fprintf( m_workFile, "%g %g l ", pos_dev.x, pos_dev.y );
} }
end.x = aCenter.x + KiROUND( aRadius * (-endAngle).Cos() ); end.x = aCenter.x + KiROUND( aRadius * (-endAngle).Cos() );
end.y = aCenter.y + KiROUND( aRadius * (-endAngle).Sin() ); end.y = aCenter.y + KiROUND( aRadius * (-endAngle).Sin() );
pos_dev = userToDeviceCoordinates( end ); pos_dev = userToDeviceCoordinates( end );
fprintf( workFile, "%g %g l ", pos_dev.x, pos_dev.y ); fprintf( m_workFile, "%g %g l ", pos_dev.x, pos_dev.y );
// The arc is drawn... if not filled we stroke it, otherwise we finish // The arc is drawn... if not filled we stroke it, otherwise we finish
// closing the pie at the center // closing the pie at the center
if( aFill == FILL_T::NO_FILL ) if( aFill == FILL_T::NO_FILL )
{ {
fputs( "S\n", workFile ); fputs( "S\n", m_workFile );
} }
else else
{ {
pos_dev = userToDeviceCoordinates( aCenter ); pos_dev = userToDeviceCoordinates( aCenter );
fprintf( workFile, "%g %g l b\n", pos_dev.x, pos_dev.y ); fprintf( m_workFile, "%g %g l b\n", pos_dev.x, pos_dev.y );
} }
} }
@ -397,7 +397,7 @@ void PDF_PLOTTER::Arc( const VECTOR2I& aCenter, const EDA_ANGLE& aStartAngle,
void PDF_PLOTTER::PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill, int aWidth, void PDF_PLOTTER::PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill, int aWidth,
void* aData ) void* aData )
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
if( aCornerList.size() <= 1 ) if( aCornerList.size() <= 1 )
return; return;
@ -405,28 +405,28 @@ void PDF_PLOTTER::PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFi
SetCurrentLineWidth( aWidth ); SetCurrentLineWidth( aWidth );
VECTOR2D pos = userToDeviceCoordinates( aCornerList[0] ); VECTOR2D pos = userToDeviceCoordinates( aCornerList[0] );
fprintf( workFile, "%g %g m\n", pos.x, pos.y ); fprintf( m_workFile, "%g %g m\n", pos.x, pos.y );
for( unsigned ii = 1; ii < aCornerList.size(); ii++ ) for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
{ {
pos = userToDeviceCoordinates( aCornerList[ii] ); pos = userToDeviceCoordinates( aCornerList[ii] );
fprintf( workFile, "%g %g l\n", pos.x, pos.y ); fprintf( m_workFile, "%g %g l\n", pos.x, pos.y );
} }
// Close path and stroke(/fill) // Close path and stroke(/fill)
fprintf( workFile, "%c\n", aFill == FILL_T::NO_FILL ? 'S' : 'b' ); fprintf( m_workFile, "%c\n", aFill == FILL_T::NO_FILL ? 'S' : 'b' );
} }
void PDF_PLOTTER::PenTo( const VECTOR2I& pos, char plume ) void PDF_PLOTTER::PenTo( const VECTOR2I& pos, char plume )
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
if( plume == 'Z' ) if( plume == 'Z' )
{ {
if( m_penState != 'Z' ) if( m_penState != 'Z' )
{ {
fputs( "S\n", workFile ); fputs( "S\n", m_workFile );
m_penState = 'Z'; m_penState = 'Z';
m_penLastpos.x = -1; m_penLastpos.x = -1;
m_penLastpos.y = -1; m_penLastpos.y = -1;
@ -438,7 +438,7 @@ void PDF_PLOTTER::PenTo( const VECTOR2I& pos, char plume )
if( m_penState != plume || pos != m_penLastpos ) if( m_penState != plume || pos != m_penLastpos )
{ {
VECTOR2D pos_dev = userToDeviceCoordinates( pos ); VECTOR2D pos_dev = userToDeviceCoordinates( pos );
fprintf( workFile, "%g %g %c\n", fprintf( m_workFile, "%g %g %c\n",
pos_dev.x, pos_dev.y, pos_dev.x, pos_dev.y,
( plume=='D' ) ? 'l' : 'm' ); ( plume=='D' ) ? 'l' : 'm' );
} }
@ -450,7 +450,7 @@ void PDF_PLOTTER::PenTo( const VECTOR2I& pos, char plume )
void PDF_PLOTTER::PlotImage( const wxImage& aImage, const VECTOR2I& aPos, double aScaleFactor ) void PDF_PLOTTER::PlotImage( const wxImage& aImage, const VECTOR2I& aPos, double aScaleFactor )
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
VECTOR2I pix_size( aImage.GetWidth(), aImage.GetHeight() ); VECTOR2I pix_size( aImage.GetWidth(), aImage.GetHeight() );
// Requested size (in IUs) // Requested size (in IUs)
@ -470,7 +470,7 @@ void PDF_PLOTTER::PlotImage( const wxImage& aImage, const VECTOR2I& aPos, double
3) restore the CTM 3) restore the CTM
4) profit 4) profit
*/ */
fprintf( workFile, "q %g 0 0 %g %g %g cm\n", // Step 1 fprintf( m_workFile, "q %g 0 0 %g %g %g cm\n", // Step 1
userToDeviceSize( drawsize.x ), userToDeviceSize( drawsize.x ),
userToDeviceSize( drawsize.y ), userToDeviceSize( drawsize.y ),
dev_start.x, dev_start.y ); dev_start.x, dev_start.y );
@ -479,7 +479,7 @@ void PDF_PLOTTER::PlotImage( const wxImage& aImage, const VECTOR2I& aPos, double
A real ugly construct (compared with the elegance of the PDF A real ugly construct (compared with the elegance of the PDF
format). Also it accepts some 'abbreviations', which is stupid format). Also it accepts some 'abbreviations', which is stupid
since the content stream is usually compressed anyway... */ since the content stream is usually compressed anyway... */
fprintf( workFile, fprintf( m_workFile,
"BI\n" "BI\n"
" /BPC 8\n" " /BPC 8\n"
" /CS %s\n" " /CS %s\n"
@ -525,39 +525,39 @@ void PDF_PLOTTER::PlotImage( const wxImage& aImage, const VECTOR2I& aPos, double
// As usual these days, stdio buffering has to suffeeeeerrrr // As usual these days, stdio buffering has to suffeeeeerrrr
if( m_colorMode ) if( m_colorMode )
{ {
putc( r, workFile ); putc( r, m_workFile );
putc( g, workFile ); putc( g, m_workFile );
putc( b, workFile ); putc( b, m_workFile );
} }
else else
{ {
// Greyscale conversion (CIE 1931) // Greyscale conversion (CIE 1931)
unsigned char grey = KiROUND( r * 0.2126 + g * 0.7152 + b * 0.0722 ); unsigned char grey = KiROUND( r * 0.2126 + g * 0.7152 + b * 0.0722 );
putc( grey, workFile ); putc( grey, m_workFile );
} }
} }
} }
fputs( "EI Q\n", workFile ); // Finish step 2 and do step 3 fputs( "EI Q\n", m_workFile ); // Finish step 2 and do step 3
} }
int PDF_PLOTTER::allocPdfObject() int PDF_PLOTTER::allocPdfObject()
{ {
xrefTable.push_back( 0 ); m_xrefTable.push_back( 0 );
return xrefTable.size() - 1; return m_xrefTable.size() - 1;
} }
int PDF_PLOTTER::startPdfObject(int handle) int PDF_PLOTTER::startPdfObject(int handle)
{ {
wxASSERT( m_outputFile ); wxASSERT( m_outputFile );
wxASSERT( !workFile ); wxASSERT( !m_workFile );
if( handle < 0) if( handle < 0)
handle = allocPdfObject(); handle = allocPdfObject();
xrefTable[handle] = ftell( m_outputFile ); m_xrefTable[handle] = ftell( m_outputFile );
fprintf( m_outputFile, "%d 0 obj\n", handle ); fprintf( m_outputFile, "%d 0 obj\n", handle );
return handle; return handle;
} }
@ -566,7 +566,7 @@ int PDF_PLOTTER::startPdfObject(int handle)
void PDF_PLOTTER::closePdfObject() void PDF_PLOTTER::closePdfObject()
{ {
wxASSERT( m_outputFile ); wxASSERT( m_outputFile );
wxASSERT( !workFile ); wxASSERT( !m_workFile );
fputs( "endobj\n", m_outputFile ); fputs( "endobj\n", m_outputFile );
} }
@ -574,12 +574,12 @@ void PDF_PLOTTER::closePdfObject()
int PDF_PLOTTER::startPdfStream( int handle ) int PDF_PLOTTER::startPdfStream( int handle )
{ {
wxASSERT( m_outputFile ); wxASSERT( m_outputFile );
wxASSERT( !workFile ); wxASSERT( !m_workFile );
handle = startPdfObject( handle ); handle = startPdfObject( handle );
// This is guaranteed to be handle+1 but needs to be allocated since // This is guaranteed to be handle+1 but needs to be allocated since
// you could allocate more object during stream preparation // you could allocate more object during stream preparation
streamLengthHandle = allocPdfObject(); m_streamLengthHandle = allocPdfObject();
if( ADVANCED_CFG::GetCfg().m_DebugPDFWriter ) if( ADVANCED_CFG::GetCfg().m_DebugPDFWriter )
{ {
@ -595,18 +595,18 @@ int PDF_PLOTTER::startPdfStream( int handle )
} }
// Open a temporary file to accumulate the stream // Open a temporary file to accumulate the stream
workFilename = wxFileName::CreateTempFileName( "" ); m_workFilename = wxFileName::CreateTempFileName( "" );
workFile = wxFopen( workFilename, wxT( "w+b" ) ); m_workFile = wxFopen( m_workFilename, wxT( "w+b" ) );
wxASSERT( workFile ); wxASSERT( m_workFile );
return handle; return handle;
} }
void PDF_PLOTTER::closePdfStream() void PDF_PLOTTER::closePdfStream()
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
long stream_len = ftell( workFile ); long stream_len = ftell( m_workFile );
if( stream_len < 0 ) if( stream_len < 0 )
{ {
@ -615,17 +615,17 @@ void PDF_PLOTTER::closePdfStream()
} }
// Rewind the file, read in the page stream and DEFLATE it // Rewind the file, read in the page stream and DEFLATE it
fseek( workFile, 0, SEEK_SET ); fseek( m_workFile, 0, SEEK_SET );
unsigned char *inbuf = new unsigned char[stream_len]; unsigned char *inbuf = new unsigned char[stream_len];
int rc = fread( inbuf, 1, stream_len, workFile ); int rc = fread( inbuf, 1, stream_len, m_workFile );
wxASSERT( rc == stream_len ); wxASSERT( rc == stream_len );
ignore_unused( rc ); ignore_unused( rc );
// We are done with the temporary file, junk it // We are done with the temporary file, junk it
fclose( workFile ); fclose( m_workFile );
workFile = nullptr; m_workFile = nullptr;
::wxRemoveFile( workFilename ); ::wxRemoveFile( m_workFilename );
unsigned out_count; unsigned out_count;
@ -663,7 +663,7 @@ void PDF_PLOTTER::closePdfStream()
closePdfObject(); closePdfObject();
// Writing the deferred length as an indirect object // Writing the deferred length as an indirect object
startPdfObject( streamLengthHandle ); startPdfObject( m_streamLengthHandle );
fprintf( m_outputFile, "%u\n", out_count ); fprintf( m_outputFile, "%u\n", out_count );
closePdfObject(); closePdfObject();
} }
@ -672,7 +672,7 @@ void PDF_PLOTTER::closePdfStream()
void PDF_PLOTTER::StartPage() void PDF_PLOTTER::StartPage()
{ {
wxASSERT( m_outputFile ); wxASSERT( m_outputFile );
wxASSERT( !workFile ); wxASSERT( !m_workFile );
// Compute the paper size in IUs // Compute the paper size in IUs
m_paperSize = m_pageInfo.GetSizeMils(); m_paperSize = m_pageInfo.GetSizeMils();
@ -680,13 +680,13 @@ void PDF_PLOTTER::StartPage()
m_paperSize.y *= 10.0 / m_iuPerDeviceUnit; m_paperSize.y *= 10.0 / m_iuPerDeviceUnit;
// Open the content stream; the page object will go later // Open the content stream; the page object will go later
pageStreamHandle = startPdfStream(); m_pageStreamHandle = startPdfStream();
/* Now, until ClosePage *everything* must be wrote in workFile, to be /* Now, until ClosePage *everything* must be wrote in workFile, to be
compressed later in closePdfStream */ compressed later in closePdfStream */
// Default graphic settings (coordinate system, default color and line style) // Default graphic settings (coordinate system, default color and line style)
fprintf( workFile, fprintf( m_workFile,
"%g 0 0 %g 0 0 cm 1 J 1 j 0 0 0 rg 0 0 0 RG %g w\n", "%g 0 0 %g 0 0 cm 1 J 1 j 0 0 0 rg 0 0 0 RG %g w\n",
0.0072 * plotScaleAdjX, 0.0072 * plotScaleAdjY, 0.0072 * plotScaleAdjX, 0.0072 * plotScaleAdjY,
userToDeviceSize( m_renderSettings->GetDefaultPenWidth() ) ); userToDeviceSize( m_renderSettings->GetDefaultPenWidth() ) );
@ -695,13 +695,13 @@ void PDF_PLOTTER::StartPage()
void PDF_PLOTTER::ClosePage() void PDF_PLOTTER::ClosePage()
{ {
wxASSERT( workFile ); wxASSERT( m_workFile );
// Close the page stream (and compress it) // Close the page stream (and compress it)
closePdfStream(); closePdfStream();
// Emit the page object and put it in the page list for later // Emit the page object and put it in the page list for later
pageHandles.push_back( startPdfObject() ); m_pageHandles.push_back( startPdfObject() );
/* Page size is in 1/72 of inch (default user space units) /* Page size is in 1/72 of inch (default user space units)
Works like the bbox in postscript but there is no need for Works like the bbox in postscript but there is no need for
@ -722,15 +722,15 @@ void PDF_PLOTTER::ClosePage()
"/MediaBox [0 0 %d %d]\n" "/MediaBox [0 0 %d %d]\n"
"/Contents %d 0 R\n" "/Contents %d 0 R\n"
">>\n", ">>\n",
pageTreeHandle, m_pageTreeHandle,
fontResDictHandle, m_fontResDictHandle,
int( ceil( psPaperSize.x * BIGPTsPERMIL ) ), int( ceil( psPaperSize.x * BIGPTsPERMIL ) ),
int( ceil( psPaperSize.y * BIGPTsPERMIL ) ), int( ceil( psPaperSize.y * BIGPTsPERMIL ) ),
pageStreamHandle ); m_pageStreamHandle );
closePdfObject(); closePdfObject();
// Mark the page stream as idle // Mark the page stream as idle
pageStreamHandle = 0; m_pageStreamHandle = 0;
} }
@ -739,8 +739,8 @@ bool PDF_PLOTTER::StartPlot()
wxASSERT( m_outputFile ); wxASSERT( m_outputFile );
// First things first: the customary null object // First things first: the customary null object
xrefTable.clear(); m_xrefTable.clear();
xrefTable.push_back( 0 ); m_xrefTable.push_back( 0 );
/* The header (that's easy!). The second line is binary junk required /* The header (that's easy!). The second line is binary junk required
to make the file binary from the beginning (the important thing is to make the file binary from the beginning (the important thing is
@ -748,11 +748,11 @@ bool PDF_PLOTTER::StartPlot()
fputs( "%PDF-1.5\n%\200\201\202\203\n", m_outputFile ); fputs( "%PDF-1.5\n%\200\201\202\203\n", m_outputFile );
/* Allocate an entry for the page tree root, it will go in every page parent entry */ /* Allocate an entry for the page tree root, it will go in every page parent entry */
pageTreeHandle = allocPdfObject(); m_pageTreeHandle = allocPdfObject();
/* In the same way, the font resource dictionary is used by every page /* In the same way, the font resource dictionary is used by every page
(it *could* be inherited via the Pages tree */ (it *could* be inherited via the Pages tree */
fontResDictHandle = allocPdfObject(); m_fontResDictHandle = allocPdfObject();
/* Now, the PDF is read from the end, (more or less)... so we start /* Now, the PDF is read from the end, (more or less)... so we start
with the page stream for page 1. Other more important stuff is written with the page stream for page 1. Other more important stuff is written
@ -803,7 +803,7 @@ bool PDF_PLOTTER::EndPlot()
} }
// Named font dictionary (was allocated, now we emit it) // Named font dictionary (was allocated, now we emit it)
startPdfObject( fontResDictHandle ); startPdfObject( m_fontResDictHandle );
fputs( "<<\n", m_outputFile ); fputs( "<<\n", m_outputFile );
for( int i = 0; i < 4; i++ ) for( int i = 0; i < 4; i++ )
@ -818,18 +818,18 @@ bool PDF_PLOTTER::EndPlot()
/* The page tree: it's a B-tree but luckily we only have few pages! /* The page tree: it's a B-tree but luckily we only have few pages!
So we use just an array... The handle was allocated at the beginning, So we use just an array... The handle was allocated at the beginning,
now we instantiate the corresponding object */ now we instantiate the corresponding object */
startPdfObject( pageTreeHandle ); startPdfObject( m_pageTreeHandle );
fputs( "<<\n" fputs( "<<\n"
"/Type /Pages\n" "/Type /Pages\n"
"/Kids [\n", m_outputFile ); "/Kids [\n", m_outputFile );
for( unsigned i = 0; i < pageHandles.size(); i++ ) for( unsigned i = 0; i < m_pageHandles.size(); i++ )
fprintf( m_outputFile, "%d 0 R\n", pageHandles[i] ); fprintf( m_outputFile, "%d 0 R\n", m_pageHandles[i] );
fprintf( m_outputFile, fprintf( m_outputFile,
"]\n" "]\n"
"/Count %ld\n" "/Count %ld\n"
">>\n", (long) pageHandles.size() ); ">>\n", (long) m_pageHandles.size() );
closePdfObject(); closePdfObject();
// The info dictionary // The info dictionary
@ -867,7 +867,7 @@ bool PDF_PLOTTER::EndPlot()
"/Version /1.5\n" "/Version /1.5\n"
"/PageMode /UseNone\n" "/PageMode /UseNone\n"
"/PageLayout /SinglePage\n" "/PageLayout /SinglePage\n"
">>\n", pageTreeHandle ); ">>\n", m_pageTreeHandle );
closePdfObject(); closePdfObject();
/* Emit the xref table (format is crucial to the byte, each entry must /* Emit the xref table (format is crucial to the byte, each entry must
@ -877,11 +877,11 @@ bool PDF_PLOTTER::EndPlot()
fprintf( m_outputFile, fprintf( m_outputFile,
"xref\n" "xref\n"
"0 %ld\n" "0 %ld\n"
"0000000000 65535 f \n", (long) xrefTable.size() ); "0000000000 65535 f \n", (long) m_xrefTable.size() );
for( unsigned i = 1; i < xrefTable.size(); i++ ) for( unsigned i = 1; i < m_xrefTable.size(); i++ )
{ {
fprintf( m_outputFile, "%010ld 00000 n \n", xrefTable[i] ); fprintf( m_outputFile, "%010ld 00000 n \n", m_xrefTable[i] );
} }
// Done the xref, go for the trailer // Done the xref, go for the trailer
@ -891,7 +891,7 @@ bool PDF_PLOTTER::EndPlot()
"startxref\n" "startxref\n"
"%ld\n" // The offset we saved before "%ld\n" // The offset we saved before
"%%%%EOF\n", "%%%%EOF\n",
(unsigned long) xrefTable.size(), catalogHandle, infoDictHandle, xref_start ); (unsigned long) m_xrefTable.size(), catalogHandle, infoDictHandle, xref_start );
fclose( m_outputFile ); fclose( m_outputFile );
m_outputFile = nullptr; m_outputFile = nullptr;
@ -940,16 +940,16 @@ void PDF_PLOTTER::Text( const VECTOR2I& aPos,
coordinate system will be used for the overlining. Also the %f coordinate system will be used for the overlining. Also the %f
for the trig part of the matrix to avoid %g going in exponential for the trig part of the matrix to avoid %g going in exponential
format (which is not supported) */ format (which is not supported) */
fprintf( 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 %g %g cm BT %s %g Tf %d Tr %g Tz ",
ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f, ctm_a, ctm_b, ctm_c, ctm_d, ctm_e, ctm_f,
fontname, heightFactor, render_mode, wideningFactor * 100 ); fontname, heightFactor, render_mode, wideningFactor * 100 );
// The text must be escaped correctly // The text must be escaped correctly
std:: string txt_pdf = encodeStringForPlotter( aText ); std:: string txt_pdf = encodeStringForPlotter( aText );
fprintf( workFile, "%s Tj ET\n", txt_pdf.c_str() ); fprintf( m_workFile, "%s Tj ET\n", txt_pdf.c_str() );
// Restore the CTM // Restore the CTM
fputs( "Q\n", workFile ); fputs( "Q\n", m_workFile );
// Plot the stroked text (if requested) // Plot the stroked text (if requested)
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,

View File

@ -240,11 +240,11 @@ class PDF_PLOTTER : public PSLIKE_PLOTTER
{ {
public: public:
PDF_PLOTTER() : PDF_PLOTTER() :
pageTreeHandle( 0 ), m_pageTreeHandle( 0 ),
fontResDictHandle( 0 ), m_fontResDictHandle( 0 ),
pageStreamHandle( 0 ), m_pageStreamHandle( 0 ),
streamLengthHandle( 0 ), m_streamLengthHandle( 0 ),
workFile( nullptr ) m_workFile( nullptr )
{ {
} }
@ -406,14 +406,14 @@ protected:
*/ */
void closePdfStream(); void closePdfStream();
int pageTreeHandle; /// Handle to the root of the page tree object int m_pageTreeHandle; ///< Handle to the root of the page tree object
int fontResDictHandle; /// Font resource dictionary int m_fontResDictHandle; ///< Font resource dictionary
std::vector<int> pageHandles;/// Handles to the page objects std::vector<int> m_pageHandles; ///< Handles to the page objects
int pageStreamHandle; /// Handle of the page content object int m_pageStreamHandle; ///< Handle of the page content object
int streamLengthHandle; /// Handle to the deferred stream length int m_streamLengthHandle; ///< Handle to the deferred stream length
wxString workFilename; wxString m_workFilename;
FILE* workFile; /// Temporary file to construct the stream before zipping FILE* m_workFile; ///< Temporary file to construct the stream before zipping
std::vector<long> xrefTable; /// The PDF xref offset table std::vector<long> m_xrefTable; ///< The PDF xref offset table
}; };