Fonts Explanation

Postby Enrico Maria Giordano » Mon Mar 05, 2007 10:41 pm

James Bott wrote:Ollie wants to be able to save and retore a user defined font.


This is a working sample:

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


FUNCTION MAIN()

    LOCAL oWnd

    LOCAL cVar := "This is a test"

    LOCAL aFont := SELECTFONT( oWnd )

    LOCAL aSaved

    IF EMPTY( aFont ); RETURN NIL; ENDIF

    DEFINE WINDOW oWnd

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

    @ 3, 1 GET cVar;
           SIZE 100, 20

    @ 5, 1 BUTTON "Choose font";
           SIZE 100, 20;
           ACTION aFont := SELECTFONT( oWnd )

    @ 7, 1 BUTTON "Save font";
           SIZE 100, 20;
           ACTION aSaved := aFont

    @ 9, 1 BUTTON "Restore font";
           SIZE 100, 20;
           ACTION RESTOREFONT( oWnd, aSaved )

    ACTIVATE WINDOW oWnd

    RETURN NIL


#define FW_NORMAL 400


STATIC FUNCTION SELECTFONT( oWnd )

    LOCAL aFont := CHOOSEFONT()

    LOCAL oFont := BUILDFONT( aFont )

    IF oFont = NIL; RETURN NIL; ENDIF

    IF oWnd != NIL; REFRESHWND( oWnd, oFont ); ENDIF

    RETURN aFont


STATIC FUNCTION RESTOREFONT( oWnd, aFont )

    LOCAL oFont := BUILDFONT( aFont )

    IF oFont = NIL; RETURN NIL; ENDIF

    REFRESHWND( oWnd, oFont )

    RETURN NIL


STATIC FUNCTION BUILDFONT( aFont )

    IF EMPTY( aFont[ LF_FACENAME ] )
        RETURN NIL
    ENDIF

    RETURN TFont():New( aFont[ LF_FACENAME ],;
                        ,;
                        aFont[ LF_HEIGHT ],;
                        .f.,;
                        !( aFont[ LF_WEIGHT ] == FW_NORMAL ),;
                        aFont[ LF_ESCAPEMENT ],;
                        aFont[ LF_ORIENTATION ],;
                        aFont[ LF_WEIGHT ],;
                        aFont[ LF_ITALIC ],;
                        aFont[ LF_UNDERLINE ],;
                        aFont[ LF_STRIKEOUT ],;
                        aFont[ LF_CHARSET ],;
                        aFont[ LF_OUTPRECISION ],;
                        aFont[ LF_CLIPPRECISION ],;
                        aFont[ LF_QUALITY ],;
                        ,;
                        aFont[ LF_PITCHANDFAMILY ] )


STATIC FUNCTION REFRESHWND( oWnd, oFont )

    LOCAL i

    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: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Ollie » Tue Mar 06, 2007 10:44 am

Thanks for all the effort so far, but my problem comes when printing.

This code shows the problem:

1. When creating the second font Size() goes negative (although that I can overcome, it would be nice to understand why it happens)

2. When I introduce the printer object, the Height and Width goes crazy.
I want to use the User's saved font to print with.


Code: Select all  Expand view
STATIC PROCEDURE font_test()
   //Let user select a font
   LOCAL oFont1,oFont2

   //Select a Font1
   oFont1:=Tfont():Choose()
   ? "Font1 - Selected by user: Width/Height/Size:",oFont1:nWidth,oFont1:nHeight,oFont1:nSIZE()
   //Now create a font2
   //METHOD New ( cFaceName, nWidth, nHeight, lFromUser,; lBold, nEscapement, nOrientation, nWeight, lItalic,; lUnderline, lStrikeOut, nCharSet, nOutPrecision,; nClipPrecision, nQuality, oDevice )

   oFont2 := TFONT():New( oFont1:cFaceName,;
   oFont1:nWidth,;
   oFont1:nHeight,;
   .F.,; //lFromUser
   oFont1: lBold,;
   oFont1:nEscapement,;
   oFont1:nOrientation,;
   oFont1:nWeight,;
   oFont1:lItalic,;
   oFont1:lUnderline,;
   oFont1:lStrikeOut,;
   oFont1:nCharSet,;
   oFont1:nOutPrecision,;
   oFont1:nClipPrecision,;
   oFont1:nQuality)
   //oDevice
   ? "Font2 - Create from Font1: Width/Height/Size:",oFont2:nWidth,oFont2:nHeight,oFont2:nSIZE()
   PRINTER oDevice NAME "Labels" PREVIEW
   oFont2 := TFONT():New( oFont1:cFaceName,;
   oFont1:nWidth,;
   oFont1:nHeight,;
   .F.,; //lFromUser
   oFont1: lBold,;
   oFont1:nEscapement,;
   oFont1:nOrientation,;
   oFont1:nWeight,;
   oFont1:lItalic,;
   oFont1:lUnderline,;
   oFont1:lStrikeOut,;
   oFont1:nCharSet,;
   oFont1:nOutPrecision,;
   oFont1:nClipPrecision,;
   oFont1:nQuality,;
   oDevice)
   ? "Font2 - oDevice added. Create from Font1: Width/Height/Size:",oFont2:nWidth,oFont2:nHeight,oFont2:nSIZE()
   RETURN
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 » Tue Mar 06, 2007 1:12 pm

Here is some more information.

Remember that when you select 8pt using chooseFont() it returns -11 as the height. Likewise when I select 72 points, nHeight is -96.

Curiously these ratios are not the same:

8/11 = .73
72/96 = .75

I suppose the difference could be due to rounding errors.

When I create a 72pt font using SIZE 0,-72 and display it on my screen it is much less than 1 inch high (10/16in). By definition a 72pt font is 1 inch high, so what is being displayed is not a 72pt font.

So, this makes me think that the SIZE clause is not actually accepting points when we specify ...SIZE 0,-value, but perhaps "logical units." I always thought it was points. To add to the confusion, according to the API docs, "logical units" can be either pixels or inches, or mm, depending on the current "mapping mode."

It seems I know less about fonts now than I did when we started this conversation.

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

Postby Enrico Maria Giordano » Tue Mar 06, 2007 1:28 pm

Ollie wrote:Thanks for all the effort so far, but my problem comes when printing.


This is a print working sample:

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


FUNCTION MAIN()

    LOCAL aFont := SELECTFONT()

    LOCAL oPrn, oFont

    IF EMPTY( aFont ); RETURN NIL; ENDIF

    PRINT oPrn PREVIEW
        oFont := BUILDFONT( oPrn, aFont )

        PAGE
            oPrn:CmSay( 0, 0, "This is a test", oFont )
        ENDPAGE
    ENDPRINT

    RELEASE FONT oFont

    RETURN NIL


STATIC FUNCTION SELECTFONT()

    LOCAL aFont := CHOOSEFONT()

    IF EMPTY( aFont[ LF_FACENAME ] )
        RETURN NIL
    ENDIF

    RETURN aFont


#define FW_NORMAL 400


STATIC FUNCTION BUILDFONT( oPrn, aFont )

    RETURN TFont():New( aFont[ LF_FACENAME ],;
                        ,;
                        aFont[ LF_HEIGHT ],;
                        .f.,;
                        !( aFont[ LF_WEIGHT ] == FW_NORMAL ),;
                        aFont[ LF_ESCAPEMENT ],;
                        aFont[ LF_ORIENTATION ],;
                        aFont[ LF_WEIGHT ],;
                        aFont[ LF_ITALIC ],;
                        aFont[ LF_UNDERLINE ],;
                        aFont[ LF_STRIKEOUT ],;
                        aFont[ LF_CHARSET ],;
                        aFont[ LF_OUTPRECISION ],;
                        aFont[ LF_CLIPPRECISION ],;
                        aFont[ LF_QUALITY ],;
                        oPrn,;
                        aFont[ LF_PITCHANDFAMILY ] )


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

Postby Antonio Linares » Tue Mar 06, 2007 1:38 pm

Enrico,

It looks as there is a problem with your email and our host:

<e.m.giordano@alice.it>:
85.33.2.53 does not like recipient.
Remote host said: 550 5.7.1 213.149.226.3 has been blocked by abuseat Giving up on 85.33.2.53.

Do you have another email account ? thanks
regards, saludos

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


Postby Antonio Linares » Wed Mar 07, 2007 11:04 am

Enrico,

It is also failing :-(

<e.m.giordano@emagsoftware.it>:
62.149.128.157 does not like recipient.
Remote host said: 553 http://www.spamhaus.org/query/bl?ip=213.149.226.3
Giving up on 62.149.128.157.
regards, saludos

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

Postby Enrico Maria Giordano » Wed Mar 07, 2007 11:20 am

I hate blacklists. They block the innocents and let the spammers freely do their work... :(
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Manuel Valdenebro » Wed Nov 26, 2008 10:56 am

We are talking about this affair in the spanish forum.

http://67.222.39.232/forums/viewtopic.php?t=13678

I am agree with James that "there may be some bugs in the font class"
and a confusion between nInpHeight data and nSize() method.

Enrico samples had a trick. They don`t begin definig a font (DEFINE FONT).
If you try following codes, you can see the diferent and the fall.

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

function Main()
local oWnd, oBtn1, oBtn2,oBtn3,oFon1, oFon2, oFon3

DEFINE WINDOW oWnd

DEFINE FONT oFon1  NAME "Courier New" SIZE 0, -18 BOLD
DEFINE FONT oFon2  NAME "Courier New" SIZE 0, -14 BOLD
DEFINE FONT oFon3  NAME "Courier New" SIZE 0, -12 BOLD


@ 2, 2 BUTTON oBtn1 ;
PROMPT "Font 18" ;
SIZE 120, 45 ;
ACTION ( ;
msginfo( "nSize:      " + STR(oBtn1:oFont:nSize() ) + CRLF + ;
"nInpHeight: " + STR(oBtn1:oFont:nInpHeight ) ),;
oBtn1:SelFont() ) ;
FONT oFon1


@ 2,32 BUTTON oBtn2 ;
PROMPT "Font 14"   ;
SIZE 120, 45 ;
ACTION  (  ;
msginfo( "nSize:      " + STR(oBtn2:oFont:nSize() ) + CRLF + ;
"nInpHeight: " + STR(oBtn2:oFont:nInpHeight ) ),;
oBtn2:SelFont() ) ;
FONT oFon2


@ 2,62 BUTTON oBtn3 ;
PROMPT "Font 12" ;
SIZE 120, 45 ;
ACTION  (  ;
msginfo( "nSize:      " + STR(oBtn3:oFont:nSize() ) + CRLF + ;
"nInpHeight: " + STR(oBtn3:oFont:nInpHeight ) ),;
oBtn3:SelFont() ) ;
FONT oFon3


ACTIVATE WINDOW oWnd

return nil



We began defining 3 fonts, one for each button. If you click on first button [Font 18], it show a message with
nSize = 13.75 and nInpHeight= 18. Therefore, the following selfont() window shows ACTIVE
SIZE=14 (round nSize) that theoretically it is not correct. If you select size=18, the button shows its true font. Now
you can see the letter "Font 18" bigger than before. If you click again on the same button, it shows now
nSize = 18 (correctly) and nInpHeight= 24. Therefore, the following selfont window, shows ACTIVE
SIZE=18 (correct).

Same problems with the others buttons:

Font 14: nSize=10.75 (active 11) nInpHeight=14
Font 12: nSize= 9 (active 9) nInpHeight=12


Antonio Linares has discovered:

"For the MM_TEXT mapping mode, you can use the following formula to specify a height for a font with a specified point size:

nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);

Resumiendo: el valor que se indica como "Height" es transformado de unidades lógicas a unidades de dispositivo, de ahi que al mostrar ChooseFont() los valores no coincidan. "

Regards
Un saludo

Manuel
User avatar
Manuel Valdenebro
 
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: wilsongamboa and 52 guests