Possible to define a FONT with a saved String ?

Possible to define a FONT with a saved String ?

Postby ukoenig » Fri Feb 22, 2008 11:07 am

Hello from Germany,

I have a small problem :

Yesterday i added the option to the messagebar-programm,
that the user can define his own fonts.
The fontstring "NAME Arial SIZE 21 0 BOLD ITALIC"
is saved in a INI-File

Normaly i must do :
DEFINE FONT oFont NAME "Arial" SIZE 21, 0 BOLD ITALIC

The Action creates the Fontstring :

ACTION ( oSAY4:GetFont(), oSAY4:SelFont(), ;
e_FTYP4 := " NAME " + '"' + oSAY4:oFont:cFaceName + '"'+ ;
" SIZE " + ALLTRIM(STR( oSAY4:oFont:nHeight ) ) + ;
", 0 " + ;
IIF( oSAY4:oFont:lBold = .T., " BOLD", "") + ;
IIF( oSAY4:oFont:lItalic = .T., " ITALIC", "" ) )

e_FTYPE4 := is the FONT-STRING will be stored in the INI-File

But it is impossible to work with a Var like
DEFINE FONT oFont e_FTYPE4

Image

Is there another way to handle this, to define a Font with a Var ?

Regards :lol:
Uwe
Last edited by ukoenig on Fri Feb 22, 2008 11:38 am, edited 3 times in total.
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

Re: Possible to define a FONT with a saved String ?

Postby Enrico Maria Giordano » Fri Feb 22, 2008 11:24 am

Honestly, I always find so hard to understand your messages. Anyway, have a look at the following sample. I don't know if it will be of any help for you, though:

Code: Select all  Expand view  RUN
#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


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


#define FW_NORMAL 400


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

Font wih vars

Postby ukoenig » Fri Feb 22, 2008 11:46 am

Thank you very much,

I know, sometimes it is not easy for me, to explain in english
what i mean, but i do my best.

I see, i cannot use the full string
i have to save the parts in a array and use it like :

For

Face := aFont1[1]
Height := aFont1[2]
Bold := aFont1[3]
italic := aFont1[4]

with TFont:New

I have still to test, how a Array works with Ini-Files.

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

Show different fonts on Infobar

Postby ukoenig » Fri Feb 22, 2008 1:35 pm

Enrico, Thank very much
it's working now
The code, how customers can change the text-type
on the Infobar

// The 1 InfoBar-Font
//--------------------------

PRIVATE aTYPE4[4]
aTYPE4[1] := "Arial"
aTYPE4[2] := 10
aTYPE4[3] := .F.
aTYPE4[4] := .F.

// Default from INI-File
// -------------------------
oFont := TFont():New( aTYPE4[1], , aTYPE4[2], .f., ;
aTYPE4[3], , , ,aTYPE4[4] )


// Set the 1 InfoBar Font
// -----------------------------
REDEFINE SAY oSAY4 VAR e_FTYP4 ID 800 OF oDlg5
REDEFINE BUTTON oBtn7 ID 805 OF oDlg5 ;
ACTION ( oSAY4:GetFont(), oSAY4:SelFont(), ;
aTYPE4[1] := oSAY4:oFont:cFaceName, ;
aTYPE4[2] := oSAY4:oFont:nHeight, ;
aTYPE41[3] := oSAY4:oFont:lBold, ;
aTYPE4[4] := oSAY4:oFont:lItalic )

// Select 1 Radio-Button of 3 to show the new Font
// ----------------------------------------------------------------
IF e_FTYP = 1 // 1 Radio-Button of 3
oFont1 := TFont():New( aTYPE4[1], , aTYPE4[2], ;
.f.,aTYPE4[3], , , ,aTYPE4[4] )
ENDIF

// Selects the Background BITMAP 1 of 16
// -----------------------------------------------------
i := 1
FOR i := 1 TO 16
xxx := LTRIM(STR(i))
IF e_HEADPIC = i
cInfo := c_path + "\Info" + xxx +".bmp"
REDEFINE BITMAP oBmp1 ID 100 ADJUST ;
FILENAME "&cInfo" OF oDlg6
oBmp1:bPainted := { |hDC| OnPaint( hDC, ;
"INI-File Settings", oFont1 ) }
ENDIF
NEXT

oFont1:End()

.......
.......

//----------------------------------------------------------------//

STATIC FUNCTION ONPAINT( hDC, cMsg, oFont )
LOCAL hOldFont

hOldFont := SelectObject( hDC, oFont:hFont )
SetBkMode( hDC, TRANSPARENT )
IF nCOLTEXT = 1 .or. e_COLTEXT = 1
SetTextColor( hDC, CLR_WHITE )
ENDIF
IF nCOLTEXT = 2 .or. e_COLTEXT = 2
SetTextColor( hDC, CLR_BLACK )
ENDIF
IF nCOLTEXT = 3 .or. e_COLTEXT = 3
SetTextColor( hDC, CLR_GREEN )
ENDIF
IF nCOLTEXT = 4 .or. e_COLTEXT = 4
SetTextColor( hDC, CLR_BLUE )
ENDIF
IF nCOLTEXT = 5 .or. e_COLTEXT = 5
SetTextColor( hDC, CLR_BROWN )
ENDIF
IF nCOLTEXT = 6 .or. e_COLTEXT = 6
SetTextColor( hDC, CLR_RED )
ENDIF
TextOut( hDC, 10, 70, cMsg )
SelectObject( hDC, hOldFont )

RETURN NIL


Regards
:lol: 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.
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 29 guests