📄 vmreportpage.cpp
字号:
/*****************************************************************************/
/* SOURCE FILE */
/*****************************************************************************/
/*
$Archive: $
$Revision: $
$Date: $
$Author: $
Description: This is the main workhorse to the print lib
This file is based on a project found on the web at:
http://www.codeproject.com/printing/printlib.asp
by
Richard Stringer
However, this file has been significantly reformatted and
modified for the needs of integrating this work into the
TOOL / XMLForms project, so may not resemble the original
files very much at all.
*/
static char OBJECT_ID[] = "$Revision: $ : $Date: $";
/*****************************************************************************/
#include "../../../stdafx.h"
#include "VMReportPage.h"
// turn off: "conversion from 'double' to 'int', possible loss of data"
//
#pragma warning ( disable : 4244 )
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::VMPage
DESCRIPTION: ctor
INPUT: rectDraw - the area to print to
pDC - display context
nMapMode - mapping mode
OUTPUT:
RETURNS: none
*/
VMPage::VMPage( RECT rectDraw, CDC* pDC, int nMapMode, double dblZoomFactor )
{
if ( nMapMode != MM_TEXT && nMapMode != MM_ANISOTROPIC )
{
nMapMode = MM_TEXT;
}
pDC->SetMapMode( nMapMode );
m_PrtDesc.tm = &tm;
StateInd = -1;
m_PrintMode = GetPrinterMode( pDC );
if ( nMapMode == MM_ANISOTROPIC )
{
pDC->SetWindowOrg( 0, 0 );
// if you change these numbers you must also change them in maxWidth
// and maxLength for ConvertToMappedUnits() conversion to be correct
//
pDC->SetWindowExt( 1000, 1000 );
pDC->SetViewportOrg( rectDraw.left,rectDraw.top );
pDC->SetViewportExt( rectDraw.right, rectDraw.bottom );
// SEE ABOVE
//
m_PrtDesc.n_maxWidth = 1000;
m_PrtDesc.n_maxLength = 1000;
m_PrtDesc.rc.left = 0;
m_PrtDesc.rc.top = 0;
// SEE ABOVE
//
m_PrtDesc.rc.right = 1000;
m_PrtDesc.rc.bottom = 1000;
}
else
{
m_PrtDesc.n_maxWidth = rectDraw.right;
m_PrtDesc.n_maxLength = rectDraw.bottom;
m_PrtDesc.rc.left = rectDraw.left;
m_PrtDesc.rc.top = rectDraw.top;
m_PrtDesc.rc.right = rectDraw.right;
m_PrtDesc.rc.bottom = rectDraw.bottom;
}
// all the textmetrics we need
//
m_dblZoomFactor = dblZoomFactor;
m_PixPerInchX = pDC->GetDeviceCaps( LOGPIXELSX );
m_PixPerInchY = pDC->GetDeviceCaps( LOGPIXELSY );
m_PixPerInchX /= dblZoomFactor;
m_PixPerInchY /= dblZoomFactor;
// determine how many inches wide and deep the rectangle is
//
m_WidthInches = rectDraw.right / (double)m_PixPerInchX;
m_LengthInches = rectDraw.bottom / (double)m_PixPerInchY;
m_PrtDesc.pDC=pDC;
// default font stuff
//
m_PrtDesc.FontName = "Times New Roman";
m_PrtDesc.PointSize = 8;
m_PrtDesc.m_NextCharPos = 0;
// default print flags
//
m_PrtDesc.uFillFlags = FILL_NONE;
m_PrtDesc.uTextFlags = TEXT_NOCLIP | TEXT_LEFT;
m_PrtDesc.uPenFlags = PEN_SOLID;
// do not change this value
//
m_PrtDesc.m_MinDisplacement = 10;
// modify to increase line spacing but should be no smaller than this
//
m_Spacing = 1.0;
pUserFunc = NULL;
// Test Stuff
//
m_PrtDesc.MarginOffset = 0;
if ( m_PrintMode == DMORIENT_LANDSCAPE )
{
if ( m_WidthInches > 10.9 ) // we got a fax driver here
{
double Diff = m_WidthInches - 10.5;
Diff = ConvertToMappedUnits( Diff, HORZRES );
m_PrtDesc.MarginOffset = (int)( Diff / 2 );
}
}
else
{
if ( m_WidthInches > 8.0 ) // we got a fax driver here
{
double Diff = m_WidthInches - 8.0;
Diff = ConvertToMappedUnits( Diff, HORZRES );
m_PrtDesc.MarginOffset = (int)( Diff / 2 );
}
}
}
/* End of function "VMPage::VMPage"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::~VMPage
DESCRIPTION: dtor. clears allocations, if any
INPUT: void
OUTPUT: none
RETURNS: none
*/
VMPage::~VMPage( void )
{
VMPrintRegion* pRegion;
for( int y = 0; y < m_RegionList.GetSize(); ++y )
{
pRegion =(VMPrintRegion*)m_RegionList[ y ];
delete pRegion;
}
m_RegionList.RemoveAll();
}
/* End of function "VMPage::~VMPage"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::SetUserFunction
DESCRIPTION: Sets the adress of the user supplied function to be called
for the virtual info printing functions
INPUT: ptr - pointer to a function of type PF_REMOTE
OUTPUT: none
RETURNS: void
*/
void VMPage::SetUserFunction( PF_REMOTE ptr )
{
pUserFunc = ptr;
}
/* End of function "VMPage::SetUserFunction"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::GetPrinterMode
DESCRIPTION: returns the current print mode
INPUT: pDC - pointer to output display context
OUTPUT: none
RETURNS: either DMORIENT_LANDSACPE or DMORIENT_PORTRAIT
*/
int VMPage::GetPrinterMode( CDC* pDC )
{
int Mode;
if ( !pDC->IsPrinting() )
{
return( 0 );
}
MYPRINTDLG* pPrintDlg = new MYPRINTDLG;
AfxGetApp()->GetPrinterDeviceDefaults( (struct tagPDA*) pPrintDlg );
DEVMODE* lpDevMode = (DEVMODE*)::GlobalLock( pPrintDlg->hDevMode );
Mode = lpDevMode->dmOrientation;
::GlobalUnlock( pPrintDlg->hDevMode );
delete pPrintDlg;
return( Mode );
}
/* End of function "VMPage::GetPrinterMode"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::SaveState
DESCRIPTION: Saves the current printer variables to a psuedo stack
INPUT: void
OUTPUT: none
RETURNS: void
*/
void VMPage::SaveState( void )
{
m_SaveState[ ++StateInd ] = m_PrtDesc;
}
/* End of function "VMPage::SaveState"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::RestoreState
DESCRIPTION: Restores printer variables saved by above
INPUT: void
OUTPUT: none
RETURNS: void
*/
void VMPage::RestoreState( void )
{
if ( StateInd == -1 )
{
return;
}
m_PrtDesc = m_SaveState[ StateInd-- ];
}
/* End of function "VMPage::RestoreState"
/*****************************************************************************/
///////////////////////////////////////////////////////////////////////////////
//
// V A R I A B L E A C C E S S R O U T I N E S
//
///////////////////////////////////////////////////////////////////////////////
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::SetRightMargin
DESCRIPTION: Changes the width of the default allowable printing area
INPUT: w - The new right side coordinates in mapping units.
If 0 there is no change. If -1 margin is set to
maximum allowable size
OUTPUT: none
RETURNS: The previous coordinates
*/
int VMPage::SetRightMargin( int w )
{
int temp = m_PrtDesc.rc.right;
if ( w > 0 )
{
m_PrtDesc.rc.right = w;
}
else
if( w == -1 )
{
m_PrtDesc.rc.right = m_PrtDesc.n_maxWidth;
}
return( temp );
}
/* End of function "VMPage::SetRightMargin"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::SetRightMargin
DESCRIPTION: See above
INPUT: w - Same as above except units are in inches
OUTPUT: none
RETURNS: See above
*/
double VMPage::SetRightMargin( double w )
{
int temp = m_PrtDesc.rc.right;
if ( w > 0 )
{
m_PrtDesc.rc.right = ConvertToMappedUnits( w, HORZRES );
}
else
if ( w== -1 )
{
m_PrtDesc.rc.right = m_PrtDesc.n_maxWidth;
}
return( ConvertToInches( temp, HORZRES ) );
}
/* End of function "VMPage::SetRightMargin"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::SetBottomMargin
DESCRIPTION: Sets new coordinates for allowable printing rectangle depth
INPUT: w - The new coordinate in mapping units. If 0 there is
no change. If -1 margin is set to maximum allowable size
OUTPUT: none
RETURNS: The old coordinate
*/
int VMPage::SetBottomMargin( int w )
{
int temp = m_PrtDesc.rc.bottom;
if ( w > 0 )
{
m_PrtDesc.rc.bottom = w;
}
else
if( w == -1 )
{
m_PrtDesc.rc.right = m_PrtDesc.n_maxLength;
}
return( temp );
}
/* End of function "VMPage::SetBottomMargin"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::SetBottomMargin
DESCRIPTION: See above
INPUT: w - Same as above except units are in inches
OUTPUT: none
RETURNS: See above
*/
double VMPage::SetBottomMargin( double w )
{
int temp = m_PrtDesc.rc.bottom;
if ( w > 0 )
{
m_PrtDesc.rc.bottom = ConvertToMappedUnits( w, VERTRES );
}
else
if( w == -1 )
{
m_PrtDesc.rc.right = m_PrtDesc.n_maxLength;
}
return( ConvertToInches( temp, VERTRES ) );
}
/* End of function "VMPage::SetBottomMargin"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::SetLineSpacing
DESCRIPTION: Changes the space returned for the next logical line
INPUT: Spacing - The constant applied to the fontsize to produce
the spacing. The formula is:
ConvertToMappedUnits( PointSize / 72.0, VERTRES ) * ( m_Spacing - 1 ) )
OUTPUT: none
RETURNS: The old spacing factor
*/
double VMPage::SetLineSpacing( double Spacing )
{
double temp = m_Spacing;
if ( Spacing > 0 )
{
m_Spacing = Spacing;
}
return( temp );
}
/* End of function "VMPage::SetLineSpacing"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::SetFont
DESCRIPTION: Changes the font face used for printing
INPUT: FontName - pointer to the new face name. IE Courier
OUTPUT: none
RETURNS: the old font face
*/
LPCSTR VMPage::SetFont( LPCSTR FontName )
{
static char buff[ 40 ];
strcpy( buff, m_PrtDesc.FontName );
if ( FontName != NULL )
{
m_PrtDesc.FontName=FontName;
}
return( buff );
}
/* End of function "VMPage::SetFont"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMPage::SetColor
DESCRIPTION: Sets The text Color if the device supports colored text
INPUT: Color - The color
OUTPUT: none
RETURNS: The old color
*/
COLORREF VMPage::SetColor( COLORREF Color )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -