Page 1 of 1

[BUG] in source/font.prg and a question

Posted: Wed Jun 19, 2019 9:06 am
by AnjaK
Hello,

I'm facing this error in FWH1905:

Code: Select all

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: Select all

#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: Select all

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: Select all

 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: Select all

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: Select all

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 ;)

Re: [BUG] in source/font.prg and a question

Posted: Wed Jun 19, 2019 9:50 am
by nageswaragunupudi
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.

Re: [BUG] in source/font.prg and a question

Posted: Wed Jun 19, 2019 10:33 am
by AnjaK
Thank you very much, that works like a charm ;)

But it is possible to create an object of

Code: Select all

OBJECT ::oFont AS TFont

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

    ENDOBJECT
 
With

Code: Select all

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: Select all

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 ;)

Re: [BUG] in source/font.prg and a question

Posted: Thu Jul 25, 2019 8:13 am
by ukoenig
Why I'm getting this error trying to save a font

Code: Select all

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: Select all

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 :?:

Re: [BUG] in source/font.prg and a question

Posted: Thu Jul 25, 2019 9:35 am
by nageswaragunupudi
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: Select all

   oFont := TFont():New( nil, nil, nil, .t. )
   ? FontToText( oFont )
   oFont:End()
 

Re: [BUG] in source/font.prg and a question

Posted: Thu Jul 25, 2019 9:43 am
by ukoenig
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 :D

Re: [BUG] in source/font.prg and a question

Posted: Thu Jul 25, 2019 10:43 am
by nageswaragunupudi
Please read the methods again.

You need to use like this:

Code: Select all

oBold := oFont:Bold()
// after usage
oBold:End()

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

Re: [BUG] in source/font.prg and a question

Posted: Thu Jul 25, 2019 10:45 am
by nageswaragunupudi
or including maybe the existing function BUILDFONT( aFont ) :?:
You can, If you like to duplicate the existing functionality.

Re: [BUG] in source/font.prg and a question

Posted: Thu Jul 25, 2019 2:35 pm
by ukoenig
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

Image

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 :D