change font after creation

change font after creation

Postby marzio » 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
marzio
 
Posts: 129
Joined: Wed Apr 04, 2007 6:54 am

Re: change font after creation

Postby Otto » Fri Feb 12, 2010 1:30 pm

Best regards,
Otto

FIVEWIN samples: testfon3.prg

Code: Select all  Expand view
// 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6003
Joined: Fri Oct 07, 2005 7:07 pm

Re: change font after creation

Postby nageswaragunupudi » Fri Feb 12, 2010 3: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
User avatar
nageswaragunupudi
 
Posts: 10247
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: change font after creation

Postby marzio » Fri Feb 12, 2010 9: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
marzio
 
Posts: 129
Joined: Wed Apr 04, 2007 6:54 am

Re: change font after creation

Postby ukoenig » 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

Image

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

Best Regards
Uwe :lol:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests