I hope that someone can help me with the strange problem that I have.
I am printing the text on the page using DrawText function. The text is big
enough so it may go across several pages. And the strange thing is that when
I do Zoom in the Print Preview, size of the font changes so the boundary box
of the resulting text is different for different zooms! And on the page
itself it looks like different portion of the text is displayed per page for
every zoom coefficient.
I wonder if someone knows what is the catch here?
Thanks in advance.
A replacement for DrawText is implemented in my coming book (September
2000), which is device independent (works both for printer and screen)
and resolution independent (works for different zoom scale, different
printer resolution). It generates true WSYIWYG output.
Feng Yuan
Windows Graphics Programming: Win32 GDI and DirectDraw
http://www.amazon.com/exec/obidos/ASIN/0130869856
Simple solution: I'll paste my code.
The problem sounds like it's because the fact that the TrueType hinting
engine gets in the way of your text output to screen at differing
resolutions. So a small font will actually be bigger than it would be on the
output device, even if you set everything up in your screen DC to match your
printer DC.
So the solution is: you take the expected width (using the printer DC, call
GetTextExtentPoint32), and you take the width of the same text as displayed
on the screen (which will be bigger). You then plot the text
character-by-character onscreen, occasionally snipping a pixel or two
(moving back one, so they overlap) before drawing the next one.
Make sure you're using SetBKMode(ETO_TRANSPARENT) for this stuff... and wipe
the background rectangle manually with a FillRect call.
Simon Cooke
Lead Engineer, Team Generations®
////////////////////////////
// Fit text into the printer's expected text width onscreen.
// If we're displaying on the screen, because the hinting engine can
// expand our fonts we display in chunks and move
// our x-displacement so that we approximate the printer positioning of the
// text. Uses an error-displacement term. SimonC
//
// Affects the current TextAlign setting.
//
// hdc = screen dc. x,y = position to draw at. text = text to draw. chars =
no' of characters to draw, printerWidth = width it would be if printed
instead of displayed
////////////////////////////
void WYSIWYGTextOut(HDC hdc, int x, int y, LPCTSTR text, int chars, int
printerWidth) {
POINT ploc;
SIZE TextSize;
// force TextOut to use the current drawing location for
// text display.
SetTextAlign(hdc, TA_UPDATECP | TA_BASELINE);
// move the drawing location to the start of the text string
MoveToEx(hdc, x, y, NULL);
// measure the SCREEN width of the text
GetTextExtentPoint32(hdc, text, chars, &TextSize);
// get the delta - how much the screen is > than the printer width
int diff = TextSize.cx - printerWidth;
// If the difference between displayed text and printed text width is
// nothing, or the displayed text is *SMALLER* than the printed text
// (unlikely) we don't worry about it and just splat the text to the
// screen. Otherwise, we use our chunk algorithm.
if (diff > 0) {
// spit it out in chunks
int count = chars;
// while we've still got more characters to draw...
while (count > 0) {
// find the number of characters that can be drawn
// before we have to move our drawing location left by
// one pixel
int run = count/diff;
// If it's more than the number of chars left, just draw the lot
if (run > count) run = count;
// draw the current chunk
TextOut(hdc, 0, 0, text, run);
// Get the current position (by moving it - strange, but it works)
MoveToEx(hdc, 0, 0, &ploc);
// Move the position to the last position, but left by a pixel
MoveToEx(hdc, ploc.x-1, ploc.y, NULL);
// We now have one less pixel to adjust,
// "run" less characters to print, and
// we adjust our text pointer to the start of the new text.
diff--;
count-= run;
text+= run;
}
}
else { // just splat it out; we can't chunk it without more (unnecessary)
work
TextOut(hdc, 0, 0, text, chars);
}
// Put TextOut back into absolute location mode.
SetTextAlign(hdc, TA_NOUPDATECP | TA_BASELINE);
}
So where is the link to this code or do we need to buy the book?
--
russ.
http://www.gipsysoft.com/ - Free Win32 Source code for all.