FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour [BUG] in source/font.prg and a question
Posts: 6
Joined: Wed Jun 05, 2019 02:24 PM
[BUG] in source/font.prg and a question
Posted: Wed Jun 19, 2019 09:06 AM
Hello,

I'm facing this error in FWH1905:
Code (fw): Select all Collapse
Time from start: 0 hours 0 mins 0 secs 
   Error occurred at: 06/19/19, 10:53:54
   Error description: Warning BASE/1004  Message not found: TFONT:CCLASSNAME

Stack Calls
===========
   Called from: source\rtl\tobject.prg => TFONT:ERROR( 0 )
   Called from: source\rtl\tobject.prg => TFONT:MSGNOTFOUND( 0 )
   Called from: source\rtl\tobject.prg => TFONT:CCLASSNAME( 0 )
   Called from: .\source\classes\FONT.PRG => TFONT:SAVETOTEXT( 473 )
   Called from: _fontTests.prg => MAIN( 8 )


with this test code:
Code (fw): Select all Collapse
#include "Fivewin.ch"

Function Main()
    LOCAL oFont, oFile
    LOCAL cFontText
    
    oFont := TFont():New("Segoe UI Bold", 0, -10, , , .T., , , , .F., .F.)
    cFontText := oFont:SaveToText(0)
    ? cFontText
    
    oFile := TTxtFile():Create("_fontAsTxt.txt")
    oFile:Open()
    oFile:AppendLn(cFontText)
    oFile:End()
    
RETURN nil


I found this:
Code (fw): Select all Collapse
cInfo := Space( nIndent ) + "OBJECT " + If( nIndent > 0, "::", "" ) + ;
            "oFont AS " + ;
            If( nIndent > 0, Upper( Left( ::ClassName(), 2 ) ) + ;
            Lower( SubStr( ::ClassName(), 3 ) ), ::cClassName ) + ;
            CRLF + CRLF


There is no ::cClassName defined.

But I'm searching for a way to save the used font as text (in DBF table) and create the object from that text:
Code (fw): Select all Collapse
 OBJECT ::oFont AS TFont

    ::cFaceName = "Segoe UI Bold"
    ::lBold = .F.

 ENDOBJECT


Is there a way to do this?

Thank you in advance

Sincerely

-----------------

Additional info:
I tried the obvious like this:
Code (fw): Select all Collapse
Function Main()
    LOCAL oTest
    
    oTest := TTestFont():New()
    XBrowse(oTest)
RETURN nil


CLASS TTestFont
    DATA oFont 
    DATA cFaceName
    DATA lBold 
    
    METHOD New() CONSTRUCTOR
ENDCLASS


METHOD New() CLASS TTestFont
    OBJECT ::oFont AS TFont

        ::cFaceName = "Segoe UI Bold"
        ::lBold = .F.

    ENDOBJECT
RETURN Self


but then I got this error with FWH1905
Code (fw): Select all Collapse
Time from start: 0 hours 0 mins 0 secs 
   Error occurred at: 06/19/19, 11:22:36
   Error description: Warning BASE/1005  Message not found: TFONT:_CVARNAME

Stack Calls
===========
   Called from: source\rtl\tobject.prg => TFONT:ERROR( 0 )
   Called from: source\rtl\tobject.prg => TFONT:MSGNOTFOUND( 0 )
   Called from: source\rtl\tobject.prg => TFONT:_CVARNAME( 0 )
   Called from: .\source\function\OBJECTS.PRG => SETOBJECT( 12 )
   Called from: _fontTests.prg => TTESTFONT:NEW( 33 )
   Called from: _fontTests.prg => MAIN( 17 )


Thank you again :-)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: [BUG] in source/font.prg and a question
Posted: Wed Jun 19, 2019 09:50 AM
Please do not use those methods:

Please use these functions:

cText := FontToText( oFont ) // save this text anywhere

Later

oFont := FontFromText( cText )

Please try this and let us have your feed back.
Regards



G. N. Rao.

Hyderabad, India
Posts: 6
Joined: Wed Jun 05, 2019 02:24 PM
Re: [BUG] in source/font.prg and a question
Posted: Wed Jun 19, 2019 10:33 AM
Thank you very much, that works like a charm :-)

But it is possible to create an object of
Code (fw): Select all Collapse
OBJECT ::oFont AS TFont

        ::cFaceName = "Segoe UI Bold"
        ::lBold = .F.

    ENDOBJECT


With
Code (fw): Select all Collapse
FUNCTION TestFont()
local Self

 OBJECT ::oFont AS TFont
        ::cFaceName = "Segoe UI Bold"
        ::lBold = .F.
 ENDOBJECT

RETURN Self


but you have to change the function SetObjet to
Code (fw): Select all Collapse
function SetObject( cVarName, bConstructor )

   local oSelf

   AAdd( aObjects, oSelf := Eval( bConstructor ) )
   if __ObjHasMsg( ATail( aObjects ), "cVarName" ) .and. ;
      __ObjHasMsg( aObjects[ 1 ], "_" + ATail( aObjects ):cVarName )
    oSelf:cVarName = cVarName

//      OSend( aObjects[ 1 ], "_" + ATail( aObjects ):cVarName, ATail( aObjects ) )
   endif


   if Len( aObjects ) == 1
      SetWndDefault( oSelf )
   endif

return oSelf

and use this together with the array aObjects and EndObject in the sample.

But that doens't help with SaveToText which I don't need :-)

Thank you again :-)
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: [BUG] in source/font.prg and a question
Posted: Thu Jul 25, 2019 08:13 AM
Why I'm getting this error trying to save a font

Code (fw): Select all Collapse
REDEFINE GET oCGet[4] VAR  aVal[6] ID 820 OF oFld:aDialogs[ 2 ] FONT oFontsys UPDATE ;
ACTION ( oFont0 :=  ChooseFont(), ;
                  IIF( !empty(oFont0), aVal[6] := FontToText( oFont0 ), NIL ), ;
          oCGet[4]:Refresh() )


A working solution
but why creating the font from array :-)

Code (fw): Select all Collapse
REDEFINE GET oCGet[4] VAR  aVal[6] ID 820 OF oFld:aDialogs[ 2 ] FONT oFontsys UPDATE ;
ACTION ( aFont :=  ChooseFont(), ;
                  oFont0 := BUILDFONT( aFont ), ;
                  IIF( !empty(oFont0), aVal[6] := FontToText( oFont0 ), NIL ), ;
          oCGet[4]:Refresh() )

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

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 ] == 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 ] )


To fill a empty var by default works

IF EMPTY( aVal[6] )
aVal[6] := FontToText( oFontSys )
ENDIF
IF EMPTY( aVal[7] )
aVal[7] := FontToText( oFontSys )
ENDIF
// oFont := FontFromText( aVal[7] ) test NO error


The errormessage

Time from start: 0 hours 0 mins 26 secs
Error occurred at: 25.07.2019, 10:06:16
Error description: Error BASE/1004 Class: 'ARRAY' has no exported method: CFACENAME
Args:
[ 1] = A { ... } length: 14

Stack Calls
===========
Called from: => CFACENAME( 0 )
Called from: .\source\classes\FONT.PRG => FONTTOTEXT( 641 )
Called from: .\ALARM.PRG => (b)PAGE2( 749 )
Called from: .\source\classes\TGET.PRG => (b)TGET:CREATEBUTTON( 952 )
Called from: .\source\classes\BUTTON.PRG => TBUTTONBMP:CLICK( 179 )

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: [BUG] in source/font.prg and a question
Posted: Thu Jul 25, 2019 09:35 AM
ACTION ( oFont0 := ChooseFont(), ;
IIF( !empty(oFont0), aVal[6] := FontToText( oFont0 ), NIL ), ;
oCGet[4]:Refresh() )

Obviously this should give an error, because ChooseFont() returns an array, but not a font object and FontToText() works with font object not array.

This works
Code (fw): Select all Collapse
   oFont := TFont():New( nil, nil, nil, .t. )
   ? FontToText( oFont )
   oFont:End()
Regards



G. N. Rao.

Hyderabad, India
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: [BUG] in source/font.prg and a question
Posted: Thu Jul 25, 2019 09:43 AM
Thank You very much for the info.

That means I can keep my working solution building the font from array
using < Choosefont >.
Maybe possible adding a parameter to < FontToText() > optional if to build
the text from array or from fontobject
or including maybe the existing function BUILDFONT( aFont ) :-)

----------------

I still have another question :

after
oFontMed1 := FontFromText( aVal[6] )
I must adjust the fontsize of the defined font in relation to the window-size and optional adding bold
I tested
oFontMed1:Modify( 50, .T. )
and
oFontMed1:nHeight(50)
but NO change :-)

METHOD nWidth( nNewValue ) SETGET
METHOD nHeight( nNewValue ) SETGET
METHOD Modify( nHeight, lBold, lItalic, lUnderline, lStrikeOut, nEscapement )

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: [BUG] in source/font.prg and a question
Posted: Thu Jul 25, 2019 10:43 AM
Please read the methods again.

You need to use like this:
Code (fw): Select all Collapse
oBold := oFont:Bold()
// after usage
oBold:End()

oBigBold := oFont:Modify( -30, .t. )
// after usage
oBigBold:End()
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: [BUG] in source/font.prg and a question
Posted: Thu Jul 25, 2019 10:45 AM
or including maybe the existing function BUILDFONT( aFont ) :-)

You can, If you like to duplicate the existing functionality.
Regards



G. N. Rao.

Hyderabad, India
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: [BUG] in source/font.prg and a question
Posted: Thu Jul 25, 2019 02:35 PM
Thank You very much.

It is working great now
I only have to select a font
the size is calculated in relation to the defined window-size



The project I'm working on

A movable desktop-alarm on top of any app,
3 alarm-times can be defined
the window can be transparent or can have any color
square or rounded corners of the window
saves and restores the position of the window
3 windowsizes are possible
2 lines of alarm-reasons for each time can be defined
optional a alarm every day the same time or only the day / time
fontsizes are adjusted to the window-size
only the font no size-or bold-selection is needed
any fontsizes of time and date with any color
a sound can be selected for each alarm
TMPicker is rounded to minutes
and much more ...

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