About font. Differences beetween FWH font and Windows font

About font. Differences beetween FWH font and Windows font

Postby Marco Turco » Tue Oct 28, 2008 6:13 pm

Hi all,
I need to know the exact font size needed to print a certain number o chars.

I made the following function with these parameters:
- cFontName, that is the font name
- n_ColRequired that is the number of chars that I want to print in a single printer row
- nMaxSize, the size of the paper

It seem to runs, however I receive a font number value different that the same I use in Word to print the same number of chars.
I need to know the font in a Microsoft Word-like format

Any ideas ?

Thanks in advance
------------


? GetFontSize("Arial",136,"210")

Function GetFontSize(cFontName,n_ColRequired,nMaxSize)

oPrn:=PrintBegin("")
aPoints:=oPrn:Cmtr2Pix(0,nMaxSize/10)

for nFontWidth:=90 to 1 step -1
oFont:=Tfont():New(cFontName,-nFontWidth)
oPrn:SetFont(oFont)
llv:=oPrn:GetTextWidth(replicate("B",n_ColRequired),oFont)
llv2:=oPrn:Pix2mmtr(0,llv)

if llv2[2]<nMaxSize &&
exit
endif
oFont:End()
sysrefresh()
next
oPrn:End()
return(nFontWidth)
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby James Bott » Tue Oct 28, 2008 6:31 pm

Marco,

It depends on how Word is calculating this number. In your example you are using a string of "B" characters to estimate the width of a string consisting of an string of the same number of characters, but not the same characters. You need to know how Word does the calculation to get the same value. You could just try substituting other characters for the "B" in your calculation until you get something close to what Word gives.

Actually, are you saying that you can get this value from Word, or that you are just measuring the width of the string that is being printed from Word?

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Marco Turco » Tue Oct 28, 2008 7:18 pm

Hi James,
thanks for your reply.

This difference is not Word-related but windows-related,
if I use WordPad the problem is the same.

See this sample image where I put 107 chars in a A4 row.
www.softwarexp.co.uk/beta/wordpad.png

If I require the font size I need to put 107 chars in an A4 row with the self-contained routine I did than I receive 58 as font size instead of 10.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby James Bott » Tue Oct 28, 2008 8:21 pm

Marco,

>This difference is not Word-related but windows-related,
>if I use WordPad the problem is the same.

>See this sample image where I put 107 chars in a A4 row.
>www.softwarexp.co.uk/beta/wordpad.png

OK, I see you are measuring the length of the 107 characters and they are not all "B"s as you are using in your calculation.

>If I require the font size I need to put 107 chars in an A4 row with the self-contained routine I did than I receive 58 as font size instead of 10.

First you need to use the same 107 characters that you are using in the picture instead of 107 "B"s. Also your function is returning the font width NOT the font size in points (which is what you are comparing the width value to).

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 89 guests