David Woods wrote:
I think your problem is that while your screen device context may be 92./,
you can't assume that your printer's device context will match that. Your
HP inkjet probably uses 300./ (mine does), while your dot matrix may use
72./ or something else. That's why print is so small on the HP inkjet and
so large on the dot matrix. Your Epson ink jet must use 92./ by default.
That might make sense if it is an older model, but I don't really know since
I'm not familiar with Epson ink jets in general.
Here's the code I use to compensate:
def OnPrintPage(self, page):
""" This method actually builds the requested page for presentation
to the screen or printer """
# Get the Device Context
dc = self.GetDC()
# Determine the Print Scaling Factors by comparing the dimensions of
the Device Context
# (which has the printer's resolution times the paper size) with the
Graphic's (from the
# PrepareData() function) resolution (which is screen resolution
times paper size).
# Determine the size of the DC and the Graphic
(dcX, dcY) = dc.GetSizeTuple()
graphicX = self.graphic.GetWidth()
graphicY = self.graphic.GetHeight()
# Scaling Factors are the DC dimensions divided by the Graphics
dimensions
scaleX = float(dcX)/graphicX
scaleY = float(dcY)/graphicY
# Apply the scaling factors to the Device Context. If you don't do
this, the screen will look
# fine but the printer version will be very, very tiny.
dc.SetUserScale(scaleX, scaleY)
My self.graphic variable is a wxBitmap I create at the printer's papersize *
96./ in a PrepareData() method not included here, so self.graphic represents
an abstract graphic of what I want to print at 96./. Actually, I think
screen resolution is 72./, so for print preview gets scaled by 0.75 before
being displayed. self.GetDC() gets the printer's Device Context at the
printer's resolution. This code then determines the scaling factor, which
will be 1 for printers that use 96./ (96/96 = 1.0), 3.125 for 300./ printers
(300/96 = 3.125), and 0.75 for 72./ printers (72/96 = 0.75). The point is,
the printer resolution doesn't matter, nor does the size of my original
graphic that I'm printing, as my code detects them and scales things
appropriately by passing these calculated values to the dc.SetUserScale()
method.
The example in the Demo does all of this, but I struggled with it for a
while too. I hope my example makes it a little clearer for you.
David Woods
Wisconsin Center for Education Research
University of Wisconsin, Madison
From: Steve Williams [mailto:stevewilliams@wwc.com]
Sent: Tuesday, October 14, 2003 6:18 PM
To: wxPython-users@lists.wxwindows.org
Subject: Re: [wxPython-users] Help! Cannot control point size in
printout.
Robin Dunn wrote:
viking viking wrote:
hi, i'm trying to use wxFont to set point size, use the same PC
print to different windows default printers, but the result of printing
is not the same!
1.HP(ink-jet) character size is very small,
2.Epson(dot-matrix) character size is very big, 3.Epson(ink-jet)
character size is correct,
Do you set the scaling factors for each printer based on the size of
each DC?
Both wxPython 2.4.1.2 and wxPython 2.4.2.4 ignore SetUserScale for font
size in wxFont and pen width in wxPen.
I create a scale factor equal to 92./ PPIPrinterWidth and then do
wxFont(int(FontSize / ScaleFactor),...)
and
wxPen(Color,int(PenWidth / ScaleFactor),...)
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
David,
I know about SetUserScale. Yes, you must calculate the UserScaling factors from the Graphics dimensions (in, say, inches) and the canvas dimensions (in pixels) in order for the x,y, width and height parameters to work properly in DC.DrawText, DC.DrawBox, etc.
But, as I said before, wxFont and wxPen ignore SetUserScale in recent versions of wxPython. Why things work in the demo is beyond me.
The justification for the scaling calculation is as follows:
1) In the real world a 'point' (as in 10-point type for a type size) is 1 / 72 of an inch. That's the way printer people talk.
2) In computers a 'point' is 1 / 92 of an inch. That's the way computer people talk.
3) The dimensional analysis of
wxFont_Size_In_Points * 92. / PPIPerInch
is
(Font_Size / Point) * (Points / Inch) / (Pixels / Inch)
= (Font_Size / Point) * (Points / Pixel)
= Font_Size / Pixel
where the pixels are for the target device (screen, printer, etc.).
So the effect of the scaling is to convert font size in points to font size in target pixels.
Steve
···
-----Original Message-----