Board index » cppbuilder » Choosing the right print size (TPrinter problem?)

Choosing the right print size (TPrinter problem?)


2005-01-26 12:35:19 AM
cppbuilder49
Hi,
I just want to choose the size of a drawing (say a rectangle) on the
printer, in terms of physical units (e.g. cm or inches) not in pixels.
The TPrinter object of CLX library offers wonderful properties called
XDPI and YDPI for the purpose.
Unfortunately TPrinter of VCL does not have these properties.
Does anyone know how to solve the problem?
Thanks in advance.
Massimo
 
 

Re:Choosing the right print size (TPrinter problem?)

I just used Printer()->Canvas->Font->PixelsPerInch to convert between inches
and pixels. Eg:
int PPI = Printer()->Canvas->Font->PixelsPerInch;
Now to position a rectangle 1 inch from the top and left sides of the paper,
and make it 3 inches high and wide :
Printer()->Canvas->Rectangle(1 * PPI, 1 * PPI, (1 + 3) * PPI, (1 + 3) *
PPI);
Hope this helps.
--
Jonathan
"Massimo Ceraolo" < XXXX@XXXXX.COM >wrote in message
Quote
Hi,
I just want to choose the size of a drawing (say a rectangle) on the
printer, in terms of physical units (e.g. cm or inches) not in pixels.

The TPrinter object of CLX library offers wonderful properties called XDPI
and YDPI for the purpose.

Unfortunately TPrinter of VCL does not have these properties.

Does anyone know how to solve the problem?
Thanks in advance.

Massimo
 

Re:Choosing the right print size (TPrinter problem?)

Quote
I just used Printer()->Canvas->Font->PixelsPerInch to convert between
inches and pixels.
That's a nice trick!
BTW, it looks obvious that horizontal and vertical pixels per inch should be
seen as equal by application software, even for those printers that have
unequal resolutions (such as 1200x2400 dpi).
Otherwise a figure that for software is a square (width and height equal in
pixels) would appear as a rectangle in printed sheets. Or a rectangle made
using a line width, say, of 4 pixels would have different line widths in
pixels for horizontal and vertical lines.
By now I cannot personally check because my home printer (that, if I
remember well, can be set to 1200x2400 dpi) is out of order, but I will
check as soon as I can.
However, the above reasoning makes me I wonder why CLX TPrinter component
considers different XDPI and YDPI values. It is crazy if the application
software has to take into account unequal horizontal and vertical
resolutions!
In fact the Font property you discovered considers just a unique
PixelsPerInch value!
Massimo
 

{smallsort}

Re:Choosing the right print size (TPrinter problem?)

I never even thought about the differing horz and vert resolutions. When I
built a app that did printing, I used that method and seemed to work fine.
I don't know what the printer res was when I tested. I think it must have
been something like 600x600 or 1200x1200.
--
Jonathan
"M. Ceraolo" < XXXX@XXXXX.COM >wrote in message
Quote
>I just used Printer()->Canvas->Font->PixelsPerInch to convert between
>inches and pixels.

That's a nice trick!

BTW, it looks obvious that horizontal and vertical pixels per inch should
be seen as equal by application software, even for those printers that
have unequal resolutions (such as 1200x2400 dpi).
Otherwise a figure that for software is a square (width and height equal
in pixels) would appear as a rectangle in printed sheets. Or a rectangle
made using a line width, say, of 4 pixels would have different line widths
in pixels for horizontal and vertical lines.

By now I cannot personally check because my home printer (that, if I
remember well, can be set to 1200x2400 dpi) is out of order, but I will
check as soon as I can.

However, the above reasoning makes me I wonder why CLX TPrinter component
considers different XDPI and YDPI values. It is crazy if the application
software has to take into account unequal horizontal and vertical
resolutions!
In fact the Font property you discovered considers just a unique
PixelsPerInch value!


Massimo



 

Re:Choosing the right print size (TPrinter problem?)

M. Ceraolo wrote:
Quote
>I just used Printer()->Canvas->Font->PixelsPerInch to convert between
>inches and pixels.

That's a nice trick!

BTW, it looks obvious that horizontal and vertical pixels per inch should be
seen as equal by application software, even for those printers that have
unequal resolutions (such as 1200x2400 dpi).
Otherwise a figure that for software is a square (width and height equal in
pixels) would appear as a rectangle in printed sheets. Or a rectangle made
using a line width, say, of 4 pixels would have different line widths in
pixels for horizontal and vertical lines.

By now I cannot personally check because my home printer (that, if I
remember well, can be set to 1200x2400 dpi) is out of order, but I will
check as soon as I can.

However, the above reasoning makes me I wonder why CLX TPrinter component
considers different XDPI and YDPI values. It is crazy if the application
software has to take into account unequal horizontal and vertical
resolutions!
In fact the Font property you discovered considers just a unique
PixelsPerInch value!


Massimo
If you would take the differance of X and Y resolution into account, use
GetDeviceCaps() instead.
TPrinter *p = Printer();
int xdpi = GetDeviceCaps(p->Handle, LOGPIXELSX);
int ydpi = GetDeviceCaps(p->Handle, LOGPIXELSY);
you can then convert these values to dpmm(dot per millimeter) for easier
calculation with matric print sizes (i.e. A4 and such)
int xdpmm = xdpi / 25.4;
int ydpmm = ydpi / 25.4;
There are many more measurements you can get from GetDeviceCaps(), try to
explore a bit in there.
Regards.
 

Re:Choosing the right print size (TPrinter problem?)

Quote

If you would take the differance of X and Y resolution into account, use
GetDeviceCaps() instead.

TPrinter *p = Printer();
int xdpi = GetDeviceCaps(p->Handle, LOGPIXELSX);
int ydpi = GetDeviceCaps(p->Handle, LOGPIXELSY);
OK.
I tried for the time being on my 300 dpi printer and it gives 300 for
both xdpi and ydpi. I will check again on my "asymmetrical" home printer
when available.
I was always feared about the concept of "logical resolution", and
that's the reason for which I felt discouraged using GetDeviceCaps().
However, after your suggestion, now I've found an interesting Microsoft
article (support.microsoft.com/default.aspx
on the topic.
Although that article discourages the use of logical resolution for
video display, it clarifies that in case of a printer, LOCPIXELSX and
LOGPIXELSY are intended as the real horizontal and vertical dots per
inch, as you correctly suggested.
Now all is clear.
Thanks a lot.
 

Re:Choosing the right print size (TPrinter problem?)

Massimo Ceraolo < XXXX@XXXXX.COM >wrote:
Quote

I tried for the time being on my 300 dpi printer and it
gives 300 for both xdpi and ydpi. I will check again on
my "asymmetrical" home printer when available.
To be clear, the TPrinter object has a problem with the Handle
always being valid. To use GetDeviceCaps with the TPrinter, you
should call BeginDoc first *or* first set the PrinterIndex and
then use it's GetPrinter method followed by it's SetPrinter
method.
~ JD
 

Re:Choosing the right print size (TPrinter problem?)

JD wrote:
Quote

Massimo Ceraolo < XXXX@XXXXX.COM >wrote:
>
>I tried for the time being on my 300 dpi printer and it
>gives 300 for both xdpi and ydpi. I will check again on
>my "asymmetrical" home printer when available.

To be clear, the TPrinter object has a problem with the Handle
always being valid. To use GetDeviceCaps with the TPrinter, you
should call BeginDoc first or first set the PrinterIndex and
then use it's GetPrinter method followed by it's SetPrinter
method.

~ JD
Indeed. I have some times encountered situations where the GetDeviceCaps()
failed due to the printer not initialized or something like that, but it's
rare. To be on the safe side, do a BeginDoc() before using GetDeviceCaps() and
call Abort() afterwords if you do not wish to print at that moment (but it will
cause the printer - Bubble jet printer for my case - to go in to initialization
sequance which is pretty annoying).
Regards.
 

Re:Choosing the right print size (TPrinter problem?)

"ChoyKw" < XXXX@XXXXX.COM >wrote:
Quote

[...] To be on the safe side, do a BeginDoc() before using
GetDeviceCaps() and call Abort() afterwords [...]
That's why I said *or* set the PrinterIndex and then use it's
GetPrinter method followed by it's SetPrinter method first.
~ JD