Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IsFontTrueType()
Message
From
11/10/2008 01:54:56
 
 
To
10/10/2008 13:03:21
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01354150
Message ID:
01354288
Views:
22
>Dear All
>Is there way to determine if TrueType or not ?
>
>I want to build function like;
>
>=IsFontTrueType('Arial') should return .t.
>=IsFontTrueType('MS Sans Serif') should return .f.
>
>Need ingredients, or recipee or whole dish if somene have it already :)
>
>
>TIA
>Sergio

Here you go, note there is no error checking!:
*!*	typedef struct tagTEXTMETRIC {
*!*	  LONG tmHeight;
*!*	  LONG tmAscent;
*!*	  LONG tmDescent;
*!*	  LONG tmInternalLeading;
*!*	  LONG tmExternalLeading;
*!*	  LONG tmAveCharWidth;
*!*	  LONG tmMaxCharWidth;
*!*	  LONG tmWeight;
*!*	  LONG tmOverhang;
*!*	  LONG tmDigitizedAspectX;
*!*	  LONG tmDigitizedAspectY;
*!*	  TCHAR tmFirstChar;
*!*	  TCHAR tmLastChar;
*!*	  TCHAR tmDefaultChar;
*!*	  TCHAR tmBreakChar;
*!*	  BYTE tmItalic;
*!*	  BYTE tmUnderlined;
*!*	  BYTE tmStruckOut;
*!*	  BYTE tmPitchAndFamily;
*!*	  BYTE tmCharSet;
*!*	} TEXTMETRIC, *PTEXTMETRIC;

*!*	tmPitchAndFamily
*!*	Specifies information about the pitch, the technology, and the family of a physical font.
*!*	The four low-order bits of this member specify information about the pitch and the
*!*	technology of the font. A constant is defined for each of the four bits.

#Define TMPF_FIXED_PITCH	0x1		&& 0001
#Define TMPF_VECTOR			0x2		&& 0010
#Define TMPF_TRUETYPE		0x4		&& 0100
#Define TMPF_DEVICE			0x8		&& 1000

?'IsFontTrueType("Arial")',IsFontTrueType("Arial")
?'IsFontTrueType("Courier")',IsFontTrueType("Courier")

*!* IsFontTrueType(cFontName)

Procedure IsFontTrueType
	Lparameters pcFontName As String

	Declare Integer CreateDC In gdi32;
		String lpDriverName,;
		String lpDeviceName,;
		String lpOutput,;
		String @lpInitData

	Declare Integer CreateFont In gdi32;
		Integer nHeight, ;
		Integer nWidth, ;
		Integer nEscapement, ;
		Integer nOrientation, ;
		Integer fnWeight, ;
		Integer fdwItalic, ;
		Integer fdwUnderline, ;
		Integer fdwStrikeOut, ;
		Integer fdwCharSet, ;
		Integer fdwOutputPrecision, ;
		Integer fdwClipPrecision, ;
		Integer fdwQuality, ;
		Integer fdwPitchAndFamily, ;
		String  lpszFace

	Declare Integer SelectObject In gdi32;
		Integer hdc,;
		Integer hObject

	Declare Integer DeleteDC In gdi32;
		Integer hdc

	Declare Integer DeleteObject In gdi32;
		Integer hObject

	Declare Integer GetTextMetrics In gdi32;
		Integer hdc,;
		String  @lpMetrics

	Local ;
		lnDC As Integer, ;
		lnFont As Integer, ;
		lnOriginalFont As Integer, ;
		lcTextMetric As String, ;
		lnPitchAndFamily As Integer, ;
		llResult As Boolean

	m.lnDC = CreateDC("DISPLAY",0,0,0)

	m.lnFont = CreateFont(0,0,0,0,0,0,0,0,0,0,0,0,0, m.pcFontName)

	m.lnOriginalFont = SelectObject(m.lnDC, m.lnFont)

	m.lcTextMetric = Replicate(Chr(0), 54)

	GetTextMetrics(m.lnDC, @m.lcTextMetric)

	*!* Get tmPitchAndFamily Byte
	m.lnPitchAndFamily = Asc(Substr(m.lcTextMetric, 52, 1))

	m.llResult = Bitand(m.lnPitchAndFamily, TMPF_TRUETYPE) = TMPF_TRUETYPE

	*!* Follow MSDN intructions:
	SelectObject(m.lnDC, m.lnOriginalFont)

	DeleteDC(m.lnDC)

	DeleteObject(m.lnFont)

	Return m.llResult
OR:

Just use AFONT:
if Afont(aFontInfo, "Arial") then
return aFontInfo(1) = -1
else
return .f.
endif
Carlos Alloatti
Previous
Reply
Map
View

Click here to load this message in the networking platform