How to count printer font size?

Just starting out? Need help? Post your questions and find answers here.
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

How to count printer font size?

Post by omit59 »

I can't get this working!

How to count right size for printer font?

I have been using this:
- Fontsize 12 points
- Printer 600 DPI
- 1 point = 1/72 inch
->
size = 12 * 600/72
LoadFont(0, "Arial", size)

but the return size is bigger than expected (from Wordpad, Word etc.)

Help please!

Timo
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Looks okay to me.

Remember that the windows font sizes are not very precise in the way that they are defined.

Are you sure the printer dpi is 600?

Code: Select all

GetDeviceCaps_(hDC,#LOGPIXELSX)
GetDeviceCaps_(hDC,#LOGPIXELSY)
I may look like a mule, but I'm not a complete ass.
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post by omit59 »

@srod,

yes, printer DPI is 600 (GetDeviceCaps_),
and when you compare results on paper,
printings from PB Arial 10point ~ Word Arial 12-13point

Difference is so big that I must be doing something wrong :cry:

Timo
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Can you post the code which outputs to the printer and I'll give it a whirl here and compare with MS Word etc?
I may look like a mule, but I'm not a complete ass.
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post by omit59 »

@srod,

Here's the sample code:

Code: Select all

Procedure FontPoint(point.f, PrinterDPIY.l)
  result = point/72 * PrinterDPIY
  ProcedureReturn result
EndProcedure

If PrintRequester()

  If StartPrinting("Test")
  
    printer_DC.l = StartDrawing(PrinterOutput())
    If printer_DC.l
      GLPrinterDPIX.l = GetDeviceCaps_(printer_DC,#LOGPIXELSX)
      GLPrinterDPIY.l = GetDeviceCaps_(printer_DC,#LOGPIXELSY)
      StopDrawing()
    EndIf

    Debug LoadFont(0, "Arial", FontPoint(10, GLPrinterDPIY))
    Debug LoadFont(1, "Arial", FontPoint(12, GLPrinterDPIY))
    Debug LoadFont(2, "Arial", FontPoint(14, GLPrinterDPIY))
    Debug LoadFont(3, "Arial", FontPoint(16, GLPrinterDPIY))

    printer_DC.l = StartDrawing(PrinterOutput())
    If printer_DC.l

      DrawingFont(FontID(0))
      DrawText(0, y,"Arial 10")
      y1 = TextHeight("Arial") * 2
      y + y1

      DrawingFont(FontID(1))
      DrawText(0, y,"Arial 12")
      y + y1

      DrawingFont(FontID(2))
      DrawText(0, y,"Arial 14")
      y + y1

      DrawingFont(FontID(3))
      DrawText(0, y,"Arial 16")
      y + y1

      StopDrawing()
    EndIf
  
    StopPrinting()
  EndIf
EndIf
Thanks in advance!

Timo
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You'll need to use:

Code: Select all

Procedure FontPoint(point, PrinterDPIY.l) 
  result = -(point * PrinterDPIY)/72
  ProcedureReturn result
EndProcedure 
This makes a little difference, but there remains some discrepancy between the output of ths PB code and MS word etc. There must be some difference between the way PB creates the fonts and MS word etc.
I may look like a mule, but I'm not a complete ass.
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post by omit59 »

@srod,

Yes, this is better but still there is quite a big difference on some fontsizes..

But anyway thanks for your help,
lets hope someone will find some kind of solution for this (Fred?).

Timo
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

Does...

Code: Select all

Procedure FontPoint(point, PrinterDPIY.l) 
  ; result = -(point * PrinterDPIY)/72 
  result = -MulDiv_(PrinterDPIY, point, 72)
  ProcedureReturn result 
EndProcedure
...do any better?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Same result as before here Xombie.

I wonder if MS Word removes the internal leading space from it's font height calculations?
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

- 1 point = 1/72 inch
No. How many points there are per inch can be changed. In Windows, the default setting is 96. So 1 point is 1/96 inch. But this can be changed, usually this is done only for visually impaired users.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Trond, I think you're confusing dpi (for which many screens default to 96 per inch) and typographic points for which, by definition, there are 72 per inch.

From the Win help file:
For the MM_TEXT mapping mode, you can use the following formula to specify a height for a font with a given point size:

lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72)
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Uhum dum bum.
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Actually if you change 72 to 96 in the equation you'll get the same printed size in PB and Word..
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

As it stands, PB's original output is a little larger than that from Word. Changing the 72 to 96 will obviously reduce the size of the font in the PB output and so it could just be coincidence etc.

Anyhow, on those systems whose screens are using 120 dpi (for example) you'll end up reducing the size further if you switch 96 for 120 etc.
I may look like a mule, but I'm not a complete ass.
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post by omit59 »

@srod, trond

I don't know if this helps, but...
Link: http://support.microsoft.com/kb/74299

What about this, is it wrong?

Code: Select all


 If PrintRequester()

  If StartPrinting("Test")

    size = 10
    LoadFont(0, "Arial", size)
    
    printer_DC.l = StartDrawing(PrinterOutput())
    If printer_DC.l
      tm.TEXTMETRIC      
      GLPrinterDPIX.l = GetDeviceCaps_(printer_DC,#LOGPIXELSX)
      GLPrinterDPIY.l = GetDeviceCaps_(printer_DC,#LOGPIXELSY)
      
      DrawingFont(FontID(0))
      GetTextMetrics_(printer_DC,tm)
      fontsize = size - (tm\tmInternalLeading / tm\tmHeight * size)
      StopDrawing()
    EndIf

    FreeFont(0)
    LoadFont(0, "Arial", -MulDiv_(GLPrinterDPIY, fontsize, 72))
    
    printer_DC.l = StartDrawing(PrinterOutput())
    If printer_DC.l

      DrawingFont(FontID(0))
      DrawText(0, 0,"Arial " + Str(size))

      StopDrawing()
    EndIf
 
    StopPrinting()
  EndIf
EndIf 
Comments, please!

Timo
Post Reply