Page 1 of 1
Font size
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Wed Jan 31, 2007 3:52 am
by hua
How to determine a font size that we need to specify to get them very close to the text sizes when printing in dos mode (10cpi, 12cpi, etc)?
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Wed Jan 31, 2007 1:31 pm
by James Bott
Hua,
This is from my notes file.
James
----------------------
DOS Printing Emulation
ASCII printing uses a fixed pitch font and the only one that comes with Windows is Courier New. To emulate standard ASCII 80 characters per line printing define a 12 point font as follows:
define font oFont name "Courier New" size 0,-12
To get 92 characters define a 10 point font (SIZE 0,-10).
Note, however, that DOS ASCII printing uses the same height font regradless of how many characters per line. I.E. 80 chars are the same height as 132 chars (compressed mode). Windows fonts become shorter as the point size is reduced. To maintain the same font height and get more characters per line just define the font as 12 point (SIZE 0,-12) then multiple oFont:nWidth by a correction factor. For example, to get a simulated compressed typeface (132 characters per line):
FONT oFont name "Courier New" size 0,-12
oFont:nWidth:= oFont:nWidth * (80/132)
This will give you the same number of lines per page (66) as you would get with ASCII printing.
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Wed Jan 31, 2007 1:46 pm
by Enrico Maria Giordano
James Bott wrote:oFont:nWidth:= oFont:nWidth * (80/132)
I don't think this will make any difference for the created font. That properties are just informative.
EMG
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Wed Jan 31, 2007 6:34 pm
by James Bott
Enrico,
>I don't think this will make any difference for the created font. That properties are just informative.
Well, it was quite some time ago that I used it, but I do remember it working. Have you tried it? Is, it not working now?
James
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Wed Jan 31, 2007 6:49 pm
by Enrico Maria Giordano
It seems logical that it can't work such way. Once the font is created how you can resize it only assigning a properties of a FWH class that just wraps it?
Anyway, this is a sample:
- Code: Select all Expand view
#include "FiveWin.ch"
FUNCTION MAIN()
LOCAL oPrn, oFnt, oFnt2
LOCAL nHStep, nVStep
PRINT oPrn PREVIEW
DEFINE FONT oFnt NAME "Arial" SIZE 0, -10 OF oPrn
DEFINE FONT oFnt2 NAME "Arial" SIZE 0, -10 OF oPrn
oFnt2:nWidth = oFnt2:nWidth * 100
nHStep = oPrn:nHorzRes() / 80
nVStep = oPrn:nVertRes() / 66
PAGE
oPrn:Say( 0, 0, "This is a test", oFnt )
oPrn:Say( 1 * nVStep, 0, "This is a test", oFnt2 )
ENDPAGE
ENDPRINT
RELEASE FONT oFnt
RELEASE FONT oFnt2
RETURN NIL
EMG
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Thu Feb 01, 2007 8:52 am
by James Bott
Enrico,
Yes, I see that in your sample it doesn't work. Here is a sample that does work. The difference must be in the way the fonts are initialized.
James
- Code: Select all Expand view
#include "fivewin.ch"
#include "report.ch"
function main()
local oReport, oFont
field last, first
use test
DEFINE FONT oFont NAME "ARIAL" SIZE 0,-12
// oFont:nWidth:= oFont:nWidth * (80/132) // simulate compressed font
oFont:nWidth:= oFont:nWidth * 3
REPORT oReport;
TITLE "Font Width Test";
font oFont;
preview
column title "Last" data last
end report
activate report oReport
return nil
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Thu Feb 01, 2007 9:15 am
by Enrico Maria Giordano
Ah, ok. The reason it works in your sample is that in TReport class the font is recreated with the new width.
EMG
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Feb 02, 2007 1:15 am
by hua
James, Enrico, thanks for the enlightening discussion
![Smile :)](./images/smilies/icon_smile.gif)
Re: Font size
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Sep 11, 2009 8:24 am
by hua
I use GetDosFnt() to get a font size that are close to text sizes in text mode and it has serves me well all this while. But now, when one of my user prints on her Epson-LX300+, the font width and height seems to shrink. Printing on other 24-pin printers and inkjets gave me the result I expected. I don't know whether this is because LX-300+ uses 9 pin for its print head or not but I'm stumped.
Any help is appreciated.
TIA
- Code: Select all Expand view
#include "FiveWin.ch"
FUNCTION MAIN()
LOCAL oPrn, oFnt
PRINT oPrn PREVIEW
oFnt := GetDosFnt(oPrn, 12)
PAGE
oPrn:Say( 0, 0, "This is a test", oFnt )
ENDPAGE
ENDPRINT
RELEASE FONT oFnt
RETURN NIL
//---------------------------------------------------------------------------------------
function GetDosFnt(oDev, nCPI, lBold)
// experimental function to mimic cpi
local oFont, nWid, nHgt, oBaseFont
local nLogPixX := oDev:nLogPixelX()
local nLogPixY := oDev:nLogPixelY()
default lBold := .f.
define font oBaseFont name "Courier New" size 0,-12
nHgt := oBaseFont:nHeight
if nCPI==10
nWid := oBaseFont:nWidth*(1.3)
elseif nCPI==12
nWid := oBaseFont:nWidth*(1.136)
elseif nCPI==15
nWid := oBaseFont:nWidth*(0.953)
elseif nCPI==20
nWid := oBaseFont:nWidth*(0.8)
endif
oFont := TFont():New(oBaseFont:cFaceName ,;
Int(nWid*nLogPixX/72) ,;
Int(nHgt*nLogPixY/72) ,;
.F. ,;
lBold ,;
oBaseFont:nEscapement ,;
oBaseFont:nOrientation ,;
oBaseFont:nWeight ,;
oBaseFont:lItalic ,;
oBaseFont:lUnderline ,;
oBaseFont:lStrikeOut ,;
oBaseFont:nCharSet ,;
oBaseFont:nOutPrecision ,;
oBaseFont:nClipPrecision ,;
oBaseFont:nQuality)
oBaseFont:end()
return oFont
//----------------------------------------------------------------------------
Re: Font size
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Sep 11, 2009 2:54 pm
by James Bott
Hua,
It seems that either the font dimensions or the pixels per inch are being reported incorrectly by the printer driver. I would check font dimensions against another printer and also check the pixels per inch against what the documention for that printer says.
You could also try a test print by printing two lines an inch apart and then actually measure them to see what they are.
But in the end, you are probably going to just have to add a correction factor for that printer. You can get the device name and then apply the correction factor if it is that particular printer. Sometimes it is just easier to do this than to try to figure out the actual cause of the problem and you will still have to do it after you find the cause.
James
Re: Font size
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Tue Sep 15, 2009 3:09 am
by hua
Thanks James,
Based on your suggestion I checked out the generated font width and height (i.e. oFnt:nWidth/oFnt:nHeight). I got 14/30 for NEC P2200, 49/100 for a Canon inkjet but an odd 9/12 for the problematic Epson printer. All these values are supposed to be in pixel right?
9/12 look as though it could be the font size in points. Based on this hunch I create a font via oFont := TFont():New( "COURIER NEW", -9, -12 , .F., .F., 0, 0, 400,,,, 0, 3, 2, 1, oPrinter ). It actually solved the problem on the problematic printer but the situation got reversed, now it's the rest of the printers which has problem and only Epson prints it correctly. (BTW, I just noticed if I create a font by using TFont directly, :nWidth and :nHeight has the font size in points i.e. -9 and 12 respectively. I thought they would always be in pixel?)
Anyway, for now it seems the simplest solution for me is to just code 2 method of creating the font depending on the printer model. Would still like to get to the root of the problem though so if anyone has further info to shed it's much appreciated. Thank you