Board index » cppbuilder » SetMapMode and print preview

SetMapMode and print preview


2007-02-23 09:53:58 PM
cppbuilder26
When actually printing the single page report, the objective is
to fill the page exactly and this is accomplished by altering
the variouse font sizes and line spacing. A 'best guess' is
made based on the amount of data and a loop is entered where
TextWidth and TextHeight are used until the desired results
are reached.
In other samples for generating a preview, I've seen where the
mapping has been changed for screen *and* printer I/O so that
they match - resulting in WYSIWYG.
However, this approach won't work for me because the format
of the report is dependent on what ever printer it's being
printed on (it's DPI and paper size).
What I need is a TBitmap that exactly mimics drawing on it
as if it were the TPrinter's Canvas. This means (I think)
that it needs to sized accordingly and have the same pixel
ratio so that I can use the same methods to format the report.
I'm intentially omiting what I've done so far because I don't
want it to influence anyone who might have suggestions.
Thanks!
~ JD
 
 

Re:SetMapMode and print preview

I'm not getting any love in the C++ graphics group so I'm
re-posting (not cross-posting!) here.
When actually printing the single page report, the objective is
to fill the page exactly and this is accomplished by altering
the variouse font sizes and line spacing. A 'best guess' is
made based on the amount of data and a loop is entered where
TextWidth and TextHeight are used until the desired results
are reached.
In other samples for generating a preview, I've seen where the
mapping has been changed for screen *and* printer I/O so that
they match - resulting in WYSIWYG.
However, this approach won't work for me because the format
of the report is dependent on what ever printer it's being
printed on (it's DPI and paper size).
What I need is a TBitmap that exactly mimics drawing on it
as if it were the TPrinter's Canvas. This means (I think)
that it needs to sized accordingly and have the same pixel
ratio so that I can use the same methods to format the report.
I've intentially omitted what I've done so far because I don't
want it to cantaminate anyone who might have suggestions.
Thanks!
~ JD
 

Re:SetMapMode and print preview

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
What I need is a TBitmap that exactly mimics drawing on it
as if it were the TPrinter's Canvas. This means (I think)
that it needs to sized accordingly and have the same pixel
ratio so that I can use the same methods to format the report.

I've intentially omitted what I've done so far because I don't
want it to cantaminate anyone who might have suggestions.
You don't seem to directly state what you need, so please respond to my
possibly off-target reply!
Just be careful with thinking of the printer as a bitmap - printer pixels
are not always square! Yet Canvas.TextOut draws text in correct aspect
ratio on the printer. So I do recommend drawing and text directly to the
printer canvas, rather than a bitmap.
In your case, mapping to printer may not have much to offer anyway.
To draw your preview image on screen, I recommend using the MM_ANISTROPIC
mapping mode & viewport/window extents combination which lets you use the
identical print code you use on the printer. This requires you find out
your printer page height and width and printer pixels per inch X and Y. In
general, the preview cannot be pixel identical to the printed output,
because it is scaled. However, this is pretty much WYSIWYG preview.
Roger Lascelles
 

{smallsort}

Re:SetMapMode and print preview

"Roger Lascelles" <rogerlasAToptusnet.com.au>wrote in message
Quote
"JD" < XXXX@XXXXX.COM >wrote in message
news:45e18c2a$ XXXX@XXXXX.COM ...

In your case, mapping to printer may not have much to offer anyway.
I should have said:
"Using a mapping mode to scale the image when writing to the printer can be
expected to lose exact-to-the-pixel control. In addition, you likely don't
have a real need for a mapping mode scaling in your particular application."
 

Re:SetMapMode and print preview

"Roger Lascelles" <rogerlasAToptusnet.com.au>wrote:
Quote

I appreciate you comments.
Quote
[...] In addition, you likely don't have a real need for a
mapping mode scaling in your particular application."
I can use GetDeviceCaps to size a TBitmap in inches to match
the paper size and all is well ... as long as the report is
6 or 8 LPI.
My problem is that the report has multiple fonts with
multiple sizes; all of which depend on the amount of
data and the printer's capabilities. As a corner-case,
if you were to use the same data twice but one copy had
an extra punctuation mark, the line-breaks could change
which would change the line count which would change some
or all of the font sizes. In addition, this report can be
1-up, 2-up or 4-up which means that the smallest difference
can be quite noticable.
Perhaps I don't need to use SetMapMode but I need something
and I don't know which way to go.
~ JD
 

Re:SetMapMode and print preview

"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"Roger Lascelles" <rogerlasAToptusnet.com.au>wrote:
>

I appreciate you comments.

>[...] In addition, you likely don't have a real need for a
>mapping mode scaling in your particular application."

I can use GetDeviceCaps to size a TBitmap in inches to match
the paper size and all is well ... as long as the report is
6 or 8 LPI.

My problem is that the report has multiple fonts with
multiple sizes; all of which depend on the amount of
data and the printer's capabilities. As a corner-case,
if you were to use the same data twice but one copy had
an extra punctuation mark, the line-breaks could change
which would change the line count which would change some
or all of the font sizes. In addition, this report can be
1-up, 2-up or 4-up which means that the smallest difference
can be quite noticable.

Perhaps I don't need to use SetMapMode but I need something
and I don't know which way to go.
Sorry for the delay in responding.
If you know how to draw your report on the printer, then I think perhaps
your problem is how to show a print preview on the screen? I recommend that
you use a mapping for the preview - and you don't need it for the printing.
Choose a mapping to the screen which makes your screen look the "same" as
the printer. Now use the same code as you have for the printer to draw on
the mapped screen. BUT you must measure text etc and calculate your text
placements using the real printer DC - but then draw on the mapped DC for
the preview. That way your mapped text will match the screen.
I haven't checked printers.pas to see if you can get a valid printer.handle
(HDC) without calling printer.begindoc, but you can get a printer handle
with CreateDC. Just don't call the API StartDoc() and API StartPage(). I
havent done this and I can't guarantee it, but the idea is to select your
fonts into the DC and do GetTextExtents() etc so you can do the layout
calculation - but without actually doing any TextOut etc.
Roger Lascelles
 

Re:SetMapMode and print preview

"Roger Lascelles" <rogerlasAToptusnet.com.au>wrote:
Quote

If you know how to draw your report on the printer, then I
think perhaps your problem is how to show a print preview on
the screen?
That's it.
Quote
[...] BUT you must measure text etc and calculate your text
placements using the real printer DC
That's what I had dertermined but I'm still messing with
mapping the bitmap.
Quote
I haven't checked printers.pas to see if you can get a valid
printer.handle (HDC) without calling printer.begindoc,
You can. You just need to make sure that you've set the
PrinterIndex.
Thanks
~ JD
 

Re:SetMapMode and print preview

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
>[...] BUT you must measure text etc and calculate your text
>placements using the real printer DC

That's what I had dertermined but I'm still messing with
mapping the bitmap.
Great.
I don't believe you need a bitmap anywhere in this process. But you need a
mapping to your preview.
Shout with details if mapping is a problem.
Roger Lascelles