FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour DEFINE FONT vs TFont()
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: DEFINE FONT vs TFont()
Posted: Mon Dec 18, 2017 01:10 PM
Se comprendo...

Code (fw): Select all Collapse
// 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: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:lBold says it's BOLD!","NOT BOLD, OK?")) OF oWnd

   SET FONT OF oSay TO oFontCalibri12

   ACTIVATE WINDOW oWnd

   oFontCalibri12:End()

RETURN NIL


Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: DEFINE FONT vs TFont()
Posted: Mon Dec 18, 2017 03:07 PM
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.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: DEFINE FONT vs TFont()
Posted: Mon Dec 18, 2017 03:27 PM

is fwh using newer CreateFontIndirectEx which includes additional parameters ?

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: DEFINE FONT vs TFont()
Posted: Mon Dec 18, 2017 04:08 PM

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.

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: DEFINE FONT vs TFont()
Posted: Tue Dec 19, 2017 01:58 AM

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

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: DEFINE FONT vs TFont()
Posted: Tue Dec 19, 2017 07:49 AM
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 (fw): Select all Collapse
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
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion