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)?
BCC5.82/BCC7.3
xHarbour/Harbour
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)?
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.
James Bott wrote:oFont:= oFont:nWidth * (80/132)
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
#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#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 nilAh, ok. The reason it works in your sample is that in TReport class the font is recreated with the new width.
EMG
James, Enrico, thanks for the enlightening discussion ![]()
#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
//----------------------------------------------------------------------------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