FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Calculation from Font-Size (pt) to Pixel ?
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Calculation from Font-Size (pt) to Pixel ?
Posted: Wed Feb 17, 2010 10:57 AM
Hello,

is there a clean Solution, to calculate Pixeldimension in Relation to Font - Pt ?
There was a lot of testing, to find the values / adjustment for SAY's from Source
in Relation to the Font-Style / Size.
( you can Download the Fonttool again ( Rel. 1.4b ), with some more fixes pointing out to this Problem )
I tested some Solutions from the Internet, but it was not 100 %

My calculation for Font : Bold, Italic, Underline


A Solution from Internet :

*is the font-size given in pt, you can calculate the font-size in px by:
*fspx = 1.3333*fspt;
*e.g.
*a font-size specified with: font-size:10pt;
*will lead to a font-size of 13.3333px.
*A font-size, specified with: font-size:2.5em;
*is leading to a font-size, which is 2.5 times that of the bodies font-size.
*e.g.
*you specified the font-size of a div to 1.5 em, you can calculate its
*pixel-value by:
*fsdivpx = 1.3333*fsbodypt*fsdivem
*or
*fsdivpx = fsbodypx*fsdivem
*in both cases is the result 20px

Best Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 90
Joined: Wed Nov 07, 2007 08:56 AM
Re: Calculation from Font-Size (pt) to Pixel ?
Posted: Wed Feb 17, 2010 11:33 AM

It's more complicated.

You need to know DPI (x or y) of the device (screen in this case) for convert the two values.

Example
FontSize px = ?
FontSize pt = 14
DPI = 96 (standard screen dpi resolution)
Point in a inch = 72

FontSize (in px) = FontSize(in pt) * DpiX / 72 = 14 * 96 / 72 = 18.667 px

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Calculation from Font-Size (pt) to Pixel ?
Posted: Wed Feb 17, 2010 11:39 AM
Patrizio,

Thank You very much.
Is it possible for You, to test it with the Tools
and tell me Your results on Your Computer ?

My working Solution ( maybe some changes needed )
Code (fw): Select all Collapse
// cTEXTFONT2 = Prompt

//--------------- TEXT-Width  ------------------// 
 
FUNCTION TEXT_W( oSay, oTFont ) 
hDC1 := oSay:GetDC()

IF aFTYPE[6] = .F. // Italic
   nTXTWIDTH :=  2 + INT( GettextWidth( hDC1, ALLTRIM(cTEXTFONT2), oTFont:hFont, )  / 2 )
ELSE
   nTXTWIDTH :=  5 + INT( GettextWidth( hDC1, ALLTRIM(cTEXTFONT2), oTFont:hFont, )  / 2 )
ENDIF
oSay:ReleaseDC()

SAYTEXT := '@ 10,10 Say oSay Prompt "' + ALLTRIM(cTEXTFONT2) + '" OF oDlg SIZE ' ;
   + ALLTRIM(STR(nTXTHEIGHT)) + "," + ALLTRIM(STR(nTXTWIDTH)) + " Pixel Font oFont" 

RETURN ( NIL )

 //--------------- TEXT-Height  ------------------// 
 
FUNCTION TEXT_H( oTFont ) 

IF aFTYPE[7] = .F. // Underline
   nTXTHEIGHT :=  2 + INT( Abs( oTFont:nHeight ) / 2 )
ELSE
   nTXTHEIGHT :=  10 + INT( Abs( oTFont:nHeight ) / 2 )
ENDIF
SAYTEXT := '@ 10,10 Say oSay Prompt "' + ALLTRIM(cTEXTFONT2) + '" OF oDlg SIZE ' ;
   + ALLTRIM(STR(nTXTHEIGHT)) + "," + ALLTRIM(STR(nTXTWIDTH)) + " Pixel Font oFont" 

RETURN ( NIL )


Best Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 90
Joined: Wed Nov 07, 2007 08:56 AM
Re: Calculation from Font-Size (pt) to Pixel ?
Posted: Wed Feb 17, 2010 11:46 AM
With

Code (fw): Select all Collapse
oFont := TFont():New( "Arial",21,-47,.F.,.T.,0,0,0,.T..T.)
oSay:SetColor( 16777215, 128 )


The preview say Size: 33 x 92
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Calculation from Font-Size (pt) to Pixel ?
Posted: Wed Feb 17, 2010 12:10 PM
The Result of Your settings on my Computer
I hope, it looks the same :



Best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.

Continue the discussion