Page 2 of 2

Re: DEFINE FONT vs TFont()

PostPosted: Mon Dec 18, 2017 1:10 pm
by karinha
Se comprendo...

Code: Select all  Expand view

// Some tests with fonts capabilities

#include "FiveWin.ch"

Function Main()

   LOCAL oWnd, oSay, oSay2
   Local oFontCalibri12

   DEFINE FONT oFontCalibri12 NAME "Calibri" SIZE 0, -12

   DEFINE WINDOW oWnd FROM 1,5 TO 20,65 ;
       TITLE "Test font. oSay:oFont:lBold is always .t.!"

   @ 11.5,10 SAY oSay PROMPT "Is this bold... Font Calibri12 ?" // FONT oFontCalibri12

   @ 10,10 SAY oSay2 ;
           PROMPT "Is this bold now?" OF oWnd

  @ 2,10 BUTTON "Change Font";
         SIZE 100,50;
         ACTION ( ( oSay2:SelFont() ), oSay2:Refresh() ) OF oWnd

   @ 2,40 BUTTON "Bold?" SIZE 100,50;
          ACTION MsgInfo(If(oSay:oFont:lBold,"Yes, oSay:oFont:lBold says it's BOLD!","NOT BOLD, OK?")) OF oWnd

   SET FONT OF oSay TO oFontCalibri12

   ACTIVATE WINDOW oWnd

   oFontCalibri12:End()

RETURN NIL
 


Saludos.

Re: DEFINE FONT vs TFont()

PostPosted: Mon Dec 18, 2017 3:07 pm
by nageswaragunupudi
Es una inquietud que tengo... y viene de la primera vez que probé FW, que los trazos de letra no estan bien trazados por decirlo de una manera, la definicion es mas 'basta'. Es como si FW utilizara un 'pinzel' y dibujara la letra en lugar de coger la fuente en si.

Fonts are not generated by FWH. FWH calls Windows API CreateFont( <params> ) and Windows creates the fonts.
FWH does not draw fonts on the screen, it is Windows OS that draws the font on the screen.
What we see on the screen is what is rendered by Windows.

Re: DEFINE FONT vs TFont()

PostPosted: Mon Dec 18, 2017 3:27 pm
by hmpaquito
is fwh using newer CreateFontIndirectEx which includes additional parameters ?

Re: DEFINE FONT vs TFont()

PostPosted: Mon Dec 18, 2017 4:08 pm
by nageswaragunupudi
CreateFontIndirect() uses LOGFONT structure.
CreateFontIndirectEx() uses ENUMLOGFONTEX structure. This structure basically contains LOGFONT structure and in addition 3 members:
TCHAR elfFullName[LF_FULLFACESIZE];
TCHAR elfStyle[LF_FACESIZE];
TCHAR elfScript[LF_FACESIZE];
You can read more in the documentation.
May we know what are the additional members you propose to use and what purpose and then we see how to accommodate your requirement.
In our opinion all the important specifications of a font are already covered by LOGFONT structure.

Re: DEFINE FONT vs TFont()

PostPosted: Tue Dec 19, 2017 1:58 am
by nageswaragunupudi
Mr Karinha

In the sample you posted, the font of oSay2 is changed.
So, in the next button action you should write If( oSay2:oFont:lBold but not If( oSay:oFont:lBold

Re: DEFINE FONT vs TFont()

PostPosted: Tue Dec 19, 2017 7:49 am
by nageswaragunupudi
TFont():New( cFaceName, nWidth, nHeight, lFromUser, lBold,;
nEscapement, nOrientation, nWeight, lItalic, lUnderline,;
lStrikeOut, nCharSet, nOutPrecision, nClipPrecision,;
nQuality, oDevice, nPitchFamily )


creates a font with exactly the same parameters using Windows function CreateFont().
CreateFontIndirect() uses LOGFONT structure with the same values to create a font. Both functions result in the same font. TFont class constructor is a wrapper to the CreateFont() function.

So the font created by using TFont():New() can not be different from any font created by any other library using the same values.

Recommended reading:
https://msdn.microsoft.com/en-us/librar ... 83499.aspx

In particular, please also read about the usage of positive and negative values for the height while creating the fonts.

Creation of font of the same size as in MS Office:
In Excel, MSWord, etc, the font sizes are specified in Points. These sizes need to converted into pixels by multiplying by -4/3 for specifying the height in function CreateFont() or TFont():New().

To get equivalent of Calibri(12) of Excel, use DEFINE FONT NAME "Calibri" SIZE 0,-16.

Code: Select all  Expand view
plf->lfHeight = -MulDiv (nPtSize, GetDeviceCaps (hdc, LOGPIXELSY), 72);


To be precise: GetDeviceCaps( GetDC(0), LOGPIXELSY )/ 72
This is equal to 96/72 --> 4/3.

Recommended reading to understand this logic well:
https://support.microsoft.com/en-in/hel ... -of-a-font