Fonts Explanation

Fonts Explanation

Postby Ollie » Sun Mar 04, 2007 12:00 pm

DEFINE FONT oFont NAME "Aerial" SIZE 0, - 8 OF oPrn

I understand the above line to be Font size 8.

oFont:nSize() tells me 50
oFont:nWidth() tells me 29.3333
oFont:nHeight() tells me 66.67

but if I :

DEFINE FONT oFont NAME "Aerial" SIZE 29.3333, 66.67 OF oPrn

oFont:nSize() tells me -416.44
oFont:nWidth() tells me 29.3333
oFont:nHeight() tells me 555.5833

Why is that?

I want to store the font (name, size, bold etc) in a DBF file. What am I doing wrong?
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
Ollie
 
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Postby James Bott » Mon Mar 05, 2007 2:11 am

Ollie,

I think there may be some bugs in the font class.

If you do this:

DEFINE FONT oFont NAME "Aerial" SIZE 29.3333, 66.67 OF oPrn

Followed by this:

oFont:nHeight:= 66.67

Which theoretically should have no effect.

Then you get these:

oFont:nSize() returns -49.75
oFont:nWidth() returns 29.3333
oFont:nHeight() returns 66.67

I note that the nSize method is subtracting -.25 under some circumstances, which would account for the 49.75. Also it is multiplying by -1 under some circumstances.

Oh, and to add to the confusion, there are also oFont:nInpWidth and oFont:nInpHeight vars. I assume these are supposed to hold the values input via the New(), nWidth(), and nHeight() methods, but the values I find in them only adds to the confusion.

Perhaps this all has to do with the difference between size in points (a physical size) and size in pixels or dots per inch (size relative to the device).

However, I think Ollie wants to save a user defined font and restore it. I'm not sure we can do this.

Antonio, Enrico, any comments?

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

Postby Enrico Maria Giordano » Mon Mar 05, 2007 11:17 am

James Bott wrote:However, I think Ollie wants to save a user defined font and restore it. I'm not sure we can do this.

Antonio, Enrico, any comments?

James


I don't know but I think it's easier to save just "Arial", 0 and -8 in the Ollie's example.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8378
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Ollie » Mon Mar 05, 2007 11:32 am

It sure would be.
I let the user select a font fontselect()
And then I want to save it, however, if the User chooses Arial 8 point,
I don't find that when I query the Font object. I get the heights and widths shown above.
If you can show me where the 0 amd -8 is found, that would be great.
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
Ollie
 
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Postby Enrico Maria Giordano » Mon Mar 05, 2007 11:47 am

oFont:cFaceName
oFont:nSize

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8378
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Ollie » Mon Mar 05, 2007 12:02 pm

I can't see the Size setting:

aFont := Choosefont()
IF EMPTY( aFont[ 14 ] )
aFont[ LF_HEIGHT ] := - 13
aFont[ LF_WIDTH ] := 0
aFont[ LF_ESCAPEMENT ] := 0
aFont[ LF_ORIENTATION ] := 0
aFont[ LF_WEIGHT ] := 400
aFont[ LF_ITALIC ] := .F.
aFont[ LF_UNDERLINE ] := .F.
aFont[ LF_STRIKEOUT ] := .F.
aFont[ LF_CHARSET ] := 0
aFont[ LF_OUTPRECISION ] := 3
aFont[ LF_CLIPPRECISION ] := 2
aFont[ LF_QUALITY ] := 1
aFont[ LF_PITCHANDFAMILY ] := 34
aFont[ LF_FACENAME ] := 'Arial'

is there a better way.
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
Ollie
 
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Postby Antonio Linares » Mon Mar 05, 2007 12:39 pm

Ollie,

Please review the source code of the Class TFont Method nSize().

You can transform it into a function to use it without creating a font object
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41409
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby James Bott » Mon Mar 05, 2007 3:49 pm

Enrico and Antonio,

The problem is that he has a user created font and he needs to find the face name and point size. oFont:cFaceName works OK, but oFont:nSize() returns 50 for a point size of 8. What units is this 50? Is it a physical size or a device size (pixels or dots per inch). Can it be translated back to points? It would be better if it just returned the point size or if there was another method that did.

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

Postby Enrico Maria Giordano » Mon Mar 05, 2007 4:17 pm

oFont:nSize() returns the expected value for me. Try this sample:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oWnd

    LOCAL cVar := "This is a test"

    DEFINE WINDOW oWnd

    @ 1, 1 SAY "This is a test";
           COLOR CLR_BLACK

    @ 3, 1 GET cVar;
           SIZE 100, 20

    @ 5, 1 BUTTON "Change font";
           SIZE 100, 20;
           ACTION CHANGEFONT( oWnd )

    ACTIVATE WINDOW oWnd

    RETURN NIL


STATIC FUNCTION CHANGEFONT( oWnd )

    LOCAL oFont := oWnd:GetFont():Choose()

    LOCAL i

    ? oFont:nSize()

    oWnd:SetFont( oFont )

    FOR i = 1 TO LEN( oWnd:aControls )
        oWnd:aControls[ i ]:SetFont( oFont )
        oWnd:aControls[ i ]:Refresh()
    NEXT

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8378
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Mon Mar 05, 2007 5:23 pm

Enrico,

Yes, your example does seem to work, but this example really adds to the confusion. If you select Arial, 8pt, then aFont contains nWidth=0, nHeight=-11. It seems to be returning an 11pt font. Then when you create a font using these parameters, then oFont:nSize returns 8 not 11 as expected.

So, it seems the user selected size being returned by chooseFont() is incorrect. It is also confusing since nWidth contains zero and nHeight is really supposed to be the point size, but it is incorrect.

Also, if you build a font using the SIZE clause with a point size, then nSize is not returning the correct point size (assuming that is what nSize is supposed to do).

James



Code: Select all  Expand view
#include "fivewin.ch"

function main()
   local oFont,aFont,oWnd, cFacename

   define window oWnd

   aFont:= chooseFont()  // select Arial, 8pt

   cFaceName:= aFont[LF_FACENAME]
   nWidth:= aFont[LF_WIDTH]
   nHeight:= aFont[LF_HEIGHT]

   // msgInfo( aFont[LF_FACENAME])
   msgInfo( nWidth ) // returns 0
   msgInfo( nHeight ) // returns -11

   DEFINE font oFont name cFaceName size nWidth, nHeight

   activate window oWnd on init msgInfo( oFont:nSize )

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

Postby Enrico Maria Giordano » Mon Mar 05, 2007 7:34 pm

I think that you are confusing points with pixels.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8378
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Mon Mar 05, 2007 8:21 pm

Enrico,

>I think that you are confusing points with pixels.

Well, I mentioned that it is confusing since the docs don't state what units each of the methods is returning.

But, if you get back 0,-11 as the sizes when you choose an 8pt font, what does it mean? Is 11 the size in pixels? If so, for what device since no device was specified? Also, then how can you use this information to create an 8pt font?

What is useful is to use points since they are independent of the display device. If you saved the pixel dimensions from one device then tried to restore them for use on a different device you would, obviously, not get the same size font. Conversely, if you save the font size in points and then restore it in points, it will be the same size regardless of the display device.

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

Postby Enrico Maria Giordano » Mon Mar 05, 2007 9:26 pm

Ok, let's start from the beginning. Please reformulate the problem and the question as I lost the track.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8378
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Mon Mar 05, 2007 10:05 pm

>Please reformulate the problem and the question as I lost the track.

Ollie wants to be able to save and retore a user defined font.

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

Postby Antonio Linares » Mon Mar 05, 2007 10:14 pm

James,

From the Windows API docs:

"Specifies the height, in logical units, of the font's character cell or character"
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41409
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: SantaCroya and 45 guests