Page 1 of 2
How to count printer font size?
Posted: Tue Jan 23, 2007 9:54 am
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
Posted: Tue Jan 23, 2007 12:07 pm
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)
Posted: Tue Jan 23, 2007 12:33 pm
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
Timo
Posted: Tue Jan 23, 2007 12:45 pm
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?
Posted: Tue Jan 23, 2007 1:05 pm
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
Posted: Tue Jan 23, 2007 1:25 pm
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.
Posted: Tue Jan 23, 2007 1:46 pm
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
Posted: Tue Jan 23, 2007 8:30 pm
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?
Posted: Tue Jan 23, 2007 8:40 pm
by srod
Same result as before here Xombie.
I wonder if MS Word removes the internal leading space from it's font height calculations?
Posted: Tue Jan 23, 2007 9:01 pm
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.
Posted: Tue Jan 23, 2007 9:10 pm
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)
Posted: Tue Jan 23, 2007 9:39 pm
by Trond
Uhum dum bum.
Posted: Tue Jan 23, 2007 10:57 pm
by Pupil
Actually if you change 72 to 96 in the equation you'll get the same printed size in PB and Word..
Posted: Tue Jan 23, 2007 11:02 pm
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.
Posted: Wed Jan 24, 2007 9:22 am
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