FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Solution, how to build FONTs from DBF-fontstrings
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM

Solution, how to build FONTs from DBF-fontstrings

Posted: Tue Jul 01, 2014 01:29 PM
Hello, is it possible to create a Font from a saved DBF-fontstring ?

I tested different solutions, but no font is created
Maybe using STRTOKEN to extract the different sections to build the font ?

Saving the different sections to a extra DBF-field works to build the font, but there are 9 fonts.
Doing it, I have to save 63 values instead of 9



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.
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM

Re: How to build a FONT from a DBF-fontstring ?

Posted: Tue Jul 01, 2014 05:34 PM
Uwe,

ukoenig wrote:Maybe using STRTOKEN to extract the different sections to build the font ?


Yes, that's the way to go.

EMG
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM

Re: How to build a FONT from a DBF-fontstring ?

Posted: Tue Jul 01, 2014 06:43 PM
My working solution :

usage ( from Button-action )

Code (fw): Select all Collapse
REDEFINE GET oGet[1] VAR cBFont[1]  ID 110 OF oFld:aDialogs[3]  FONT oFont

REDEFINE SAY oSay[1] PROMPT "Title- font"  ID 120 OF oFld:aDialogs[3]  FONT oBFont[1]   
oSay[1]:lTransparent := .F.
oSay[1]:Setcolor ( nDTxtColor, 16777215 )

REDEFINE BTNBMP oBtn[1] OF oFld:aDialogs[3] ;
ID 130 PIXEL 2007 ;
NOBORDER ;
PROMPT " &1) Title    " ;
FILENAME c_path1 + "Select.Bmp" ;
ACTION ( oFont0 :=  ChooseFont(), ;
     IIF( !empty(oFont0[10]), ;
           ( DeleteObject(oBFont[1]), ; // 1. Font 
             oBFont[1] := BUILDFONT(oFont0), ; 
             cBFont[1] := cFontstr, ; // will be saved to a DBF-field
             oGet[1]:Refresh(), ;
             oSay[1]:SetFont ( oBFont[1] ), oSay[1]:Refresh(), ;
             DeleteObject(oFont0), ;
             oGraph:aFont[1] := oBFont[1], ;                         
             oGraph:Refresh() ), ;
        MsgAlert( "No Font selected ","ATTENTION" ) ) ) ;
FONT oFont  ;
LEFT
oBtn[1]:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
     { { 0.50, 3067734, 16777215 }, ;
     { 0.50, 16777215, 3067734 } }, ;
     { { 0.50, 3145727, 16777215 }, ;
     { 0.50, 16777215, 3145727 } } ) }
oBtn[1]:lTransparent := .t.   
oBtn[1]:cToolTip =  { "Text-Color","Color-Selection", 1, CLR_BLACK, 14089979 }
oBtn[1]:SetColor( 0, )


Creating Fontstrings for DBF

Code (fw): Select all Collapse
FUNCTION BUILDFONT( aFont ) 
LOCAL aFTYPE[7], A1, A2, A3, A4, A5, A6

newFont := TFont():New( aFont[ LF_FACENAME ],; 
,; 
aFont[ LF_HEIGHT ],; 
.f.,; 
!( aFont[ LF_WEIGHT ] == 400) ,;
     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 ] ) 

nHight := INT( aFont[ LF_HEIGHT ] )  

aFTYPE[1]  := ALLTRIM(newFont:cFaceName)
aFTYPE[2]  := 0 // Width
aFTYPE[3]  := newFont:nInpHeight // Size 
aFTYPE[4]  := newFont:lBold
aFTYPE[5]  := 0
aFTYPE[6]  := newFont:lItalic
aFTYPE[7]  := newFont:lUnderline

A1 := LTRIM(STR(aFTYPE[2])) // Width
A2 := LTRIM(STR(aFTYPE[3])) // Size

A3 := ".F." // Bold
IF aFTYPE[4] = .T.
       A3 := ".T."
ENDIF

B_BOLD := aFTYPE[4]

aFTYPE[5]  := 0 // Hor. / Vert.
*IF B_ORIENT = 1
*   aFTYPE[5]  := 900
*ENDIF
A4 := ALLTRIM(STR(aFTYPE[5]))

A5 := ".F."  // Italic
IF aFTYPE[6] = .T.
      A5 := ".T."
ENDIF

B_ITALIC := aFTYPE[6]

A6 := ".F." // Underline
IF aFTYPE[7] = .T.
      A6 := ".T."
ENDIF

B_UNDERL := aFTYPE[7]

// create fontstring ( cFontStr saved to DBF-field-array )
cFontStr :=  '"' + ALLTRIM( aFTYPE[1] ) + '",' + ;
     A1 + "," + A2 + ",.F.," + A3 + "," + A4 + ",0,0," + A5 + "," + A6
// MsgAlert( cFontStr )

RETURN ( newFont )


Building Fonts from DBF-fields
//("SET")->CBFONT1 := '"Arial",0,-22,.F.,.T.,0,0,0,.F.,.F.'
//("SET")->CBFONT2 := '"Arial",0,-12,.F.,.T.,0,0,0,.F.,.F.'
//("SET")->CBFONT3 := '"Arial",0,-12,.F.,.T.,0,0,0,.F.,.F.'
//("SET")->CBFONT4 := '"Arial",0,-10,.F.,.T.,0,0,0,.F.,.F.'
//("SET")->CBFONT5 := '"Arial",0,-10,.F.,.T.,0,0,0,.F.,.F.'
//("SET")->CBFONT6 := '"Arial",0,-12,.F.,.T.,0,0,0,.F.,.F.'
//("SET")->CBFONT7 := '"Arial",0,-12,.F.,.T.,0,0,0,.F.,.F.'
//("SET")->CBFONT8 := '"Arial",0,-16,.F.,.T.,0,0,0,.F.,.F.'
//("SET")->CBFONT9 := '"Arial",0,-10,.F.,.T.,0,0,0,.F.,.F.'

Code (fw): Select all Collapse
aPart1 := Array( 10 ) // Font-sections
aPart2 := Array( 4 )  // Logical Font-sections
FOR X := 1 TO 9       // Fonts
     // "Arial",0,-22,F,T,0,0,0,F,F 
     FOR Y := 1 TO 10 // Font-Sectons
          // DBF-font-fields saved to a array
          aPart1[Y] = STRTOKEN( cBFont[X], Y, ',' ) 
          IF Y = 4 // Logic
               IIF( aPart1[Y] = '.T.', aPart2[1] := .T., aPart2[1] := .F. ) // Logic
          ENDIF
          IF Y = 5 // Logic
               IIF( aPart1[Y] = '.T.', aPart2[2] := .T., aPart2[2] := .F. ) // Logic
          ENDIF
          IF Y = 9 // Logic
               IIF( aPart1[Y] = '.T.', aPart2[3] := .T., aPart2[3] := .F. ) // Logic
          ENDIF
          IF Y = 10 // Logic
               IIF( aPart1[Y] = '.T.', aPart2[4] := .T., aPart2[4] := .F. ) // Logic
          ENDIF
          IF Y = 2 .OR. Y = 3 .OR. Y = 6 .OR. Y = 7 .OR. Y = 8 // Numeric
               aPart1[Y] := VAL ( aPart1[Y] )
          ENDIF
     NEXT
     // 9 created fonts
     oBFont[X] :=  TFont():New( aPart1[1], ; 
                                aPart1[2], aPart1[3], aPart2[1], aPart2[2], ;
                                aPart1[6], aPart1[7], aPart1[8], aPart2[3], aPart2[4] )
NEXT


needed for new fontpaintings and saving values to a project-DBF



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.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Solution, how to build FONTs from DBF-fontstrings

Posted: Tue Jul 01, 2014 10:33 PM

FWH natively provides two functions to save and restore fonts, viz., FontToText( oFont ) and FontFromText( cText )

Usage:

FIELD->SAVEDFONT := FontToText( oFont )
//
oFont := FontFromText( FIELD->SAVEDFONT )

Also if you want to save and restore any array:

METHOD-1:
Save:
FIELD->MYMEMOFLD := FW_ValToExp( aData )
Restore:
aData := &( FIELD->MYMEMOFLD )

METHOD-2:
If using DBFCDX:
FIELD->MYMEMOFLD := aData
aData := FIELD->MYMEMOFLD

I feel we can make use of these functions/features to make our programming life easier.

Regards



G. N. Rao.

Hyderabad, India
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM

Re: Solution, how to build FONTs from DBF-fontstrings

Posted: Wed Jul 02, 2014 11:46 AM
Mr. Rao,

thank You very much for the infos.
It works PERFECT.
Still there is a lot to do.
I counted round about 52 possible values, can be changed at runtime.
With the tool it will be easy, to optimize a graph-display.
Because of a Project-DBF, You can save / restore all selected values.
Without, it is hard to find the best value-combinations.
As well it might be helpful, to find out any needed changes of class tGraph.
The runtime change between the graph-style ( Bar, Pie, Line and Point ) works great,
but I don't know the meaning of ALL ( only values with no bar-display )

#Define GRAPH_TYPE_BAR 1
#Define GRAPH_TYPE_LINE 2
#Define GRAPH_TYPE_POINT 3
#Define GRAPH_TYPE_PIE 4

#Define GRAPH_TYPE_ALL 5

Switched to LINE + 3D
Fonts are restored from PROJECT.DBF




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