Help! Cannot control point size in printout.

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,
     why???

    eg. dc.SetFont(wxFont(36, wxMODERN, wxNORMAL, wxNORMAL, false))
              dc.DrawText("test",x_pos,y_pos)

form viking, patrick

···

_________________________________________________________________
靈格風 : 學英語, 免費學普通話, 唔駛返學, 即學即用 http://go.msnserver.com/HK/34087.asp

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?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

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),...)

Both wxPython 2.4.1.2 and wxPython 2.4.2.4 ignore SetUserScale for font
size in wxFont

You also have to be careful with your workaround (multiply the point size
by the scale you are using) since you do not given fonts of the exact
point size you request, but something similar (which is usually larger).

For my calendar control, I initially tried to use the UserScale stuff
and had the same issues and so resorted to asking for the point sizes
appropriately scaled.

In the end I had to make my code do a number of iterations. I needed
to fit the lines of text into a fixed vertical height. I would draw
them all, work out how much over I was, scale the point size accordingly
and try again. It would still often be up to 10% over due to a larger
font being returned than requested. It usually took 3 iterations
before the text would actually fit.

Roger

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

···

-----Original Message-----
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

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-----

Hi all,

I like the new demo's use of wxSTC to provide syntax highlighted (etc.)
code, but I've found a major annoyance: on GTK, you can't use X-windows
Copy & Paste to copy code from the demo. Can this be enabled?

wxPythonGTK 2.2.4
Python 2.3
Redhat Linux 7.2

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

[BTW, looks like your clock is twelve hours off.]

Chris Barker wrote:

Hi all,

I like the new demo's use of wxSTC to provide syntax highlighted (etc.)
code, but I've found a major annoyance: on GTK, you can't use X-windows
Copy & Paste to copy code from the demo. Can this be enabled?

Keep in mind that there is more than one clipboard on X11 systems. There is the PRIMARY SELECTION (normally whatever text is currently selected by the mouse, and this is normally pasted by middle-clicking), the SECONDARY SELECTION (not used much anymore) and the CLIPBOARD (normal copy and paste.) Unfortunatly wxGTK can only be a data provider for either the PRIMARY or the CLIPBOARD, but not both at the same time[1]. In fact, the way wxGTk is currently written if you put something into the PRIMARY it will destory anything currently in the CLIPBOARD. For this reason I decided to only support CLIPBOARD operations in wxSTC and not put the current selection into the PRIMARY like other apps do[2]. So if you do Ctrl-C, Ctrl-V, etc. then other apps that also support the CLIPBOARD should interact correctly. Otherwise you can use something like klipper to move things to/from the PRIMARY for you.

[1] I tried fixing this just before 2.4 was released but when I realized the size of the changes needed I was afraid that I would break something and I didn't want to do that just before a stable release. It could probably be done in 2.5 if somebody has the time.

[2] Although I thought that I was still doing a paste from PRIMARY if the middle button is clicked, but I see that it is not doing that now so I'll have to check into that.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!