More Printing questions..... Merry Christmas
Hello Everyone.
I have been struggling with this item for some time.
For a while I was content to ignore it, but it has finally made it to the
top of my list.
I have an application where the User may choose reporting fonts.
Three fonts. One for the header, one for the body, and one for the footer of
the various reports. I save the LOGFONT structures for later use.
At the time I do a StartDocument I grab the LOGFONT structures I had
previously saved, and CreatePointFontIndirect to create the fonts.
As I walk through the code in debug mode, everything seems to work fine.
However, the printing works perfectly on an HP 9040DN, but no details appear
when I print to a Brother or the HP Photosmart I have. The graphics boxes do
appear though.
Anyway my first question relates to the voodoo-like black magic of scaling
the font.
I want a ten point font. I select a ten point font from the CFontDialog, and
save it. Later, when I want to create the font I call
CreatePointFontIndirect, and I pass a value that is in tenths of a point. So,
now I would pass 100, for my ten point font.
From experience this never worked. After poking through various web sites, I
found someone had success with using a "Cook''s Constant" of 42/13. So, I
have taken my value of 100, and multipled by 42/13. Is this obtuse or am I
off base here? Anyway, this appears to do the trick, at least for the HP
printer.
I checked the Microsoft docs, and they suggest using something along the
lines of -MulDiv(m_lfReportHeader.lfHeight/10,
m_dc.GetDeviceCaps(LOGPIXELSY), 72);
Now, I have tried this with the printers that do not deliver the report as
execpted, and I see no difference. I have not tried this with the HP printer
that is really working.
Here is a code snippet showing how I have created the fonts.
/*
Assign default Report Header Font for the Reports
Note: m_szIniSectionName will refer to the specific Report for the Printer.
m_ProcessIni.m_szIniSectionName will refer to the DEFAULT entries
for the Printer.
*/
LOGFONT lfIniDefaults;
BOOL bFlag=FALSE;
TEXTMETRIC myTextMetrics;
m_ProcessIni.m_szIniKeyName.LoadString(IDS_REPORTHEADERFONT);
bFlag = m_ProcessIni.getKeyValueForFont(&lfIniDefaults,
m_ProcessIni.m_szIniKeyName, m_szIniSectionName);
if (!bFlag) // No font information available from the ini file, so save
DEFAULT
{
m_ProcessIni.setKeyValueForFont(m_plfReportHeader,
m_ProcessIni.m_szIniKeyName, m_szIniSectionName);
}
else
{
m_lfReportHeader = lfIniDefaults;
}
lfIniDefaults = m_lfReportHeader;
lfIniDefaults.lfHeight*=(42/13); // I have no idea why this scaling is
required... But it is. Found this in a news group.
// lfIniDefaults.lfHeight = -MulDiv(m_lfReportHeader.lfHeight/10,
m_dc.GetDeviceCaps(LOGPIXELSY), 72);
/*
Establish Font characteristics for the Report Header lines.
lfIniDefaults Points to a LOGFONT structure that defines the
characteristics
of the logical font.
The lfHeight member of the LOGFONT structure is measured in tenths of a
point
rather than logical units.
(For instance, set lfHeight to 120 to request a 12-point font.)
CreatePointFontIndirect returns non-zero when successful.
If bFlag is zero, we have a problem!
*/
CFont*pOldHeaderFont, *pOldFooterFont, *pOldBodyFont;
m_cfReportHeader.DeleteObject();
bFlag = m_cfReportHeader.CreatePointFontIndirect(&lfIniDefaults, &m_dc);
pOldHeaderFont = m_dc.SelectObject(&m_cfReportHeader);
m_pcfReportHeader = &m_cfReportHeader;
// m_hFontReportHeader is the CGdiObject public data member that stores
the handle
m_hFontReportHeader = (HFONT) pOldHeaderFont->GetSafeHandle();
//m_hFontReportHeader = (HFONT) m_pcfReportHeader->GetSafeHandle();
/* Get Average size of printed text for the Header Font */
m_dc.GetTextMetrics(&myTextMetrics);
m_yLineHeader = myTextMetrics.tmHeight;
Later when I want to use the font in a report, I select the font, and do a
DrawText.
Here is a code snippet:
pcfOriginal =
ts->_this->PrinterControl.m_dc.SelectObject(ts->_this->PrinterControl.m_pcfReportHeader);
iPrintedHeight=ts->_this->PrinterControl.m_dc.DrawText(szHeader,
rclHeader, DT_TOP|DT_CENTER);
iPrintedHeight=ts->_this->PrinterControl.m_dc.DrawText(szSubHeader,
rclSubHeader, DT_TOP|DT_CENTER);
pcfOriginal =
ts->_this->PrinterControl.m_dc.SelectObject(ts->_this->PrinterControl.m_pcfReportFooter);
iPrintedHeight=ts->_this->PrinterControl.m_dc.DrawText(szFooter,
rclFooter, DT_BOTTOM|DT_CENTER);
szBuffer.Format(_T("Page %d"), ++lPageNumber);
iPrintedHeight=ts->_this->PrinterControl.m_dc.DrawText(szBuffer,
rclFooter, DT_BOTTOM|DT_RIGHT);
pcfOriginal =
ts->_this->PrinterControl.m_dc.SelectObject(ts->_this->PrinterControl.m_pcfReportBody);
One last question, I know that the Fonts are applicable for the DC that has
been selected. When the DC is destroyed, and recreated, do the Fonts need to
be recreated? Do I need to destroy and recreate the fonts every time I
destroy and recreate the DC? Should I?
Today, I plan to try to sift through SuperPad. I believe it is the Microsoft
sample which may help me out here.
Thanks for any information, and Merry Christmas!
........Cameron