1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
//------------------------------------------------------------------------------------------
void PrintFile(CDC *pDC,CStdioFile &File,DOCINFO &docInfo)
{
//
int nMargins = 150;
int iVerticalSize =pDC->GetDeviceCaps(VERTRES);
iVerticalSize =iVerticalSize-nMargins;
File.SeekToBegin();
CString str;
CRect strRect(0,0,0,0);
CRect rcCalcText(0,0,0,0);
int nStringheight=0,nStringwidth=0, nRowSpace = 0;
TEXTMETRIC tm;
pDC->SetMapMode(MM_TEXT); // Sets the mapping mode
if (pDC->StartDoc(&docInfo) == SP_ERROR)
{
// delete pDC;
return;
}
int nPage=0;
while(File.ReadString(str))
{
int iY = 300;
pDC->StartPage();
nPage++;
for( ; File.ReadString(str) && (iY < iVerticalSize ); )
{
pDC->GetTextMetrics(&tm);
CString strTmp = str;
nRowSpace = tm.tmExternalLeading;
// Calc the Height of the String, that can different
// if using newline etc.
pDC->DrawText(strTmp, rcCalcText, DT_CALCRECT);
nStringheight = rcCalcText.Height();
strRect.left=200;
strRect.right = pDC->GetDeviceCaps(HORZRES);
strRect.top=iY;
strRect.bottom = strRect.top + nStringheight;
CString tab1,tab2;
int tabPos = strTmp.Find("\t");
if ( tabPos != -1 )
{
tab1 = strTmp.Left(tabPos);
tab2 = strTmp.Right(strTmp.GetLength()-tabPos-1);
}
else
tab1 = strTmp;
// Attach header font to the header text.
pDC->SelectObject(&m_HeadingFont);
CPrintInfo Infos;
Infos.m_rectDraw.SetRect(0, 0,
pDC->GetDeviceCaps(HORZRES),
pDC->GetDeviceCaps(VERTRES));
Infos.m_nCurPage=nPage;
PrintPageHeader(pDC,Infos);
// Attach Body font to the body text.
pDC->SelectObject(&m_BodyFont2);
pDC->DrawText( tab1,
strRect,
DT_WORDBREAK | DT_EXPANDTABS);
strRect.left=strRect.right/6*2;
pDC->SelectObject(&m_BodyFont);
pDC->DrawText( tab2,
strRect,
DT_WORDBREAK | DT_EXPANDTABS);
// Calculate the next start position
int x = strRect.bottom;
iY = ( nRowSpace + x);
if ((iY > iVerticalSize)) break;
}
pDC->EndPage();
}
pDC->EndDoc();
} |
Partager