FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour change font after creation
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
change font after creation
Posted: Fri Feb 12, 2010 11:22 AM

i want to change some definitions of a font after creation.
DEFINE FONT oFont NAME "Times New Roman" SIZE 10, 12 OF oPrn

i have tried this, but doesn't work:
oFont:nWidth( 24 ); oFont:nHeight( 10 )
oFont:lBold := .t.
oFont:lItalic := .t.
oFont:cFaceName := "Arial"

is it possible?

thanks, marzio

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: change font after creation
Posted: Fri Feb 12, 2010 01:30 PM
Best regards,
Otto

FIVEWIN samples: testfon3.prg

Code (fw): Select all Collapse
// Saving and restoring a font. By Enrico Maria Giordano

#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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: change font after creation
Posted: Fri Feb 12, 2010 03:36 PM

We can not change the font attributes of the same font object after definition. But we can derive a new font object with changing some attributes and set the new font to the control. In many cases it is much easier than the method suggested in testfon3.prg.

Examples:

DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12

oBold := oFont:Bold( .t. )
oBoldItalic := oBold:Italic( .t. )

Methods available are :
METHOD Bold( lOnOff )
METHOD Italic( lOnOff )
METHOD Underline( lOnOff )
METHOD StrikeOut( lOnOff )
METHOD Escapement( nEsc )
METHOD Rotate( n )

METHOD Modify( nHeight, lBold, lItalic, lUnderline, lStrikeOut, nEscapement )

Regards



G. N. Rao.

Hyderabad, India
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: change font after creation
Posted: Fri Feb 12, 2010 09:53 PM

thanks for your replays.

i have many line like these,
for each line that i print i have to change the dimension of the font:

DEFINE FONT oFont NAME "Times New Roman" SIZE 24, 13 OF oPrn
oPrn:Say(..., oFont)

oFont:End()
DEFINE FONT oFont NAME "Times New Roman" SIZE 15, 9 OF oPrn
oPrn:Say(..., oFont)

etc. many times

in the class tfont there are 2 function:
METHOD nWidth( nNewValue ) SETGET
METHOD nHeight( nNewValue ) SETGET
oFont:nWidth( 15 ); oFont:nHeight( 9 )
but this doesn't work.

oFont:End() with the definition of a new font is the best solution?

regards, marzio

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: change font after creation
Posted: Sun Feb 14, 2010 11:21 AM
Not easy, but possible

Font-Editor Update Rel. 1.3

New Background-Color added
New Font-Style Browser added
New Underline added
Changed Text-Size Range 10 - 60



Download :
http://www.pflegeplus.com/fw_downloads/fontedit3.zip

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