FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TFont for Antonio
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

TFont for Antonio

Posted: Sat Apr 06, 2013 08:04 AM

Hello Antonio,
Would you be so kind to adapt the functionality of
METHOD SaveToText( nIndent ).

It would be fine having similar functions like
METHOD SaveState( aData )
METHOD RestoreState( cInfo ) in xBrowse
for TFont class.

Thanks in advance
Otto

Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

Re: TFont for Antonio

Posted: Sat Apr 06, 2013 09:08 AM
Otto,
I save the font of mine xbrowses on file Ini

I create a setup for colums,background and fonts Ican call on each table(xbrowse) :




For the fonts then I save on file ini

Sample :
[FntBrowse]
mvBrwFont=Forte:10:Normale;Elephant:10:Normale;Engravers MT:10:Normale;




and then on xbrowse I call the fonts at init for Head,Dataa and Footers


Do you like it ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

Re: TFont for Antonio

Posted: Sat Apr 06, 2013 09:36 AM

Hello Silvio,
this question is about TFont.

But please post you code. I am sure it is useful for many of us.

Best regards,
Otto

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: TFont for Antonio

Posted: Sat Apr 06, 2013 05:52 PM
Mr Otto

Can you pls try these two functions?
Code (fw): Select all Collapse
//----------------------------------------------------------------------------//

function FontToText( oFont )
return FW_ValToExp(  { ;
   oFont:cFaceName, 0, oFont:nInpHeight, .f., oFont:lBold, oFont:nEscapement, ;
   oFont:nOrientation, nil, oFont:lItalic, oFont:lUnderline, oFont:lStrikeOut, ;
   oFont:nCharSet, oFont:nOutPrecision, oFont:nClipPrecision, oFont:nQuality, ;
   nil, oFont:nPitchFamily }  )
//----------------------------------------------------------------------------//

function FontFromText( cText )
return HB_ExecFromArray( TFont(), "NEW", &cText )

//----------------------------------------------------------------------------//
Regards



G. N. Rao.

Hyderabad, India
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

Re: TFont for Antonio

Posted: Sat Apr 06, 2013 07:19 PM
Dear Mr. Rao,
thank you for helping me.

If I read the Font from the restored value the result differ from the original Font. I did many tests this afternoon also with the build in method cGenPrg with the same result.
Please see the screen shot.
The height is not like the original.

Best regards,
Otto











This is my test program

Code (fw): Select all Collapse
#include "FiveWin.ch"

 Function Main()

    LOCAL oWnd, oSay, cVar
    //LOCAL oFont := TFont():New( 'Calibri', 15.40, 35, .f., .f., 0, 0, 400, .f., .f., .f., 0,3, 2, 1,, 34 )
    LOCAL oFont 
    local cText := memoread("RAOfont.txt")
 
    oFont := FontFromText( cText )
 
 
 
 msginfo( "RAOfont.txt" )
 
 //oFont := TFont():New( {"Calibri",0,24,.F.,.F.,0,0,,.F.,.F.,.F.,0,3,2,1,,34} )
 
 DEFINE WINDOW oWnd;
       FROM 1,5 TO 20,65;
       TITLE "Test font. oSay:lBold is always .t.!"

           @ 12,10 ;
         SAY oSay ;
      PROMPT "ABC Is this bold now?" ;
          OF oWnd ;
        FONT oFont ;
        SIZE 200, 100



 @ 2,10 BUTTON "SelFont";
       SIZE 100,50;
       ACTION oSay:SelFont() OF oWnd

 @ 2,40 BUTTON "cGenPrg";
       SIZE 100,50;
       ACTION ( cVar := oSay:oFont:cGenPrg( cVar ),memowrit("font.txt",cVar) ) OF oWnd

 
  @ 5,40 BUTTON "FontToText";
       SIZE 100,50;
       ACTION (cVar := FontToText( oFont ),memowrit( "RAOfont.txt",cVar) ) OF oWnd
 
 
 ACTIVATE WINDOW oWnd

 RETU NIL
 
 
//----------------------------------------------------------------------------//

function FontToText( oFont )
return FW_ValToExp(  { ;
   oFont:cFaceName, 0, oFont:nInpHeight, .f., oFont:lBold, oFont:nEscapement, ;
   oFont:nOrientation, nil, oFont:lItalic, oFont:lUnderline, oFont:lStrikeOut, ;
   oFont:nCharSet, oFont:nOutPrecision, oFont:nClipPrecision, oFont:nQuality, ;
   nil, oFont:nPitchFamily }  )
//----------------------------------------------------------------------------//

function FontFromText( cText )
return HB_ExecFromArray( TFont(), "NEW", &cText )

//----------------------------------------------------------------------------//
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: TFont for Antonio

Posted: Sat Apr 06, 2013 08:52 PM
I am using this program to check:
Code (fw): Select all Collapse
#include "FiveWin.Ch"
#include "hbcompat.ch"
#include "xbrowse.ch"

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

function Main()

   local oDlg, oBrw, oTestFont, oCopyFont, oOldFont, cFontText

   DEFINE FONT oTestFont FROM USER
   cFontText   := FontToText( oTestFont )
   if File( 'FONTSAVE.TXT' )
      oOldFont := FontFromText( MemoRead( 'FONTSAVE.TXT' ) )
   endif
   MsgInfo( cFontText )
   oCopyFont   := FontFromText( cFontText )
   MEMOWRIT( 'fontsave.txt', cFontText )

   DEFINE DIALOG oDlg SIZE 500,300 PIXEL
   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      DATASOURCE { 'One', 'Two', Date(), 234.56, 'Three', 'Four' } ;
      COLUMNS 1, 1, 1 HEADERS "SELFONT", "COPYFONT", "OLDFONT" CELL LINES NOBORDER

   WITH OBJECT oBrw
      :aCols[ 1 ]:oDataFont   := oTestFont
      :aCols[ 2 ]:oDataFont   := oCopyFont
      if oOldFont != nil
         :aCols[ 3 ]:oDataFont   := oOldFont
      endif
      //
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oTestFont, oCopyFont
   if oOldFont != nil
      RELEASE FONT oOldFont
   endif

return (0)

//----------------------------------------------------------------------------//
function FontToText( oFont )
return FW_ValToExp(  { ;
   oFont:cFaceName, 0, oFont:nInpHeight, .f., oFont:lBold, oFont:nEscapement, ;
   oFont:nOrientation, nil, oFont:lItalic, oFont:lUnderline, oFont:lStrikeOut, ;
   oFont:nCharSet, oFont:nOutPrecision, oFont:nClipPrecision, oFont:nQuality, ;
   nil, oFont:nPitchFamily }  )
//----------------------------------------------------------------------------//
function FontFromText( cText )
return HB_ExecFromArray( TFont(), "NEW", &cText )
//----------------------------------------------------------------------------//


Regards



G. N. Rao.

Hyderabad, India
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

Re: TFont for Antonio

Posted: Sat Apr 06, 2013 10:11 PM
Dear Mr. Rao,
thank you. Your code is working fine.
I had a mistake here.
FontToText( oSay:oFont )
@ 5,40 BUTTON "FontToText";
SIZE 100,50;
ACTION (cVar := FontToText( oFont ),memowrit( "RAOfont.txt",cVar) ) OF oWnd

But I still have a different behaviour with the build in class oFont:cGenPrg().


with build in:
oFont := TFont():New( 'Verdana', 21.12, 48, .f., .f., 0, 0, 400, .f., .f., .f., 0,3, 2, 1,, 34 )
with your code and this gives the correct behaviour if you use FontFromText( cText )
{"Verdana", 0,-48, .F., .F., 0, 0, , .F.,.F.,.F.,0,3,2,1,,34}


Best regards,
Otto
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: TFont for Antonio

Posted: Sun Apr 07, 2013 06:02 AM
Please modify this line method cGenPrg
Code (fw): Select all Collapse
      cCode    += "'" + ::cFaceName + "', " + nTrim( ::nwidth ) + ", " + nTrim( ::nHeight ) + ", .f., "

as
Code (fw): Select all Collapse
      cCode    += "'" + ::cFaceName + "', " + nTrim( ::nInpwidth ) + ", " + nTrim( ::nInpHeight ) + ", .f., "
Regards



G. N. Rao.

Hyderabad, India
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

Re: TFont for Antonio

Posted: Sun Apr 07, 2013 04:12 PM

Dear Mr. Rao,
this is the output of your file:
{"Calibri", 0, -19, .F., .F., 0, 0, , .F., .F., .F., 0,3, 2, 1, ,34}
This of method cGenPrg:
'Calibri', 0, -19, .f., .f., 0, 0, 400, .f., .f., .f., 0,3, 2, 1, , 34 )
There is a difference in one value.
I think this value is ::nWeight .
Best regards,
Otto

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: TFont for Antonio

Posted: Mon Apr 08, 2013 12:25 AM
Yes. :nInpWidth and :nWeight
I revised the function too
Code (fw): Select all Collapse
//----------------------------------------------------------------------------//
function FontToText( oFont )
return FW_ValToExp(  { ;
   oFont:cFaceName, oFont:nInpWidth, oFont:nInpHeight, .f., oFont:lBold, oFont:nEscapement, ;
   oFont:nOrientation, oFont:nWeight, oFont:lItalic, oFont:lUnderline, oFont:lStrikeOut, ;
   oFont:nCharSet, oFont:nOutPrecision, oFont:nClipPrecision, oFont:nQuality, ;
   nil, oFont:nPitchFamily }  )
//----------------------------------------------------------------------------//
function FontFromText( cText )
return HB_ExecFromArray( TFont(), "NEW", &cText )
//----------------------------------------------------------------------------//

Now, these functions and also cGenPrg method of oFont should work reliably
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion