Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

429 lines
14 KiB

  1. /***************************************************************************
  2. * fontcl.h - declarations for the font class and it related buddies:
  3. *
  4. * PANOSEBytesClass - The list of decoded PANOSE bytes
  5. * PANOSENumClass - The PANOSE number
  6. * DirFilenameClass - Directory slot and filename
  7. * CFontClass - Font class itself
  8. *
  9. * Copyright (C) 1992-93 ElseWare Corporation. All rights reserved.
  10. ***************************************************************************/
  11. #ifndef __FONTCL_H__
  12. #define __FONTCL_H__
  13. #include <stdio.h>
  14. #include <string.h>
  15. #if !defined(__FDIR_H__)
  16. #include "fdir.h"
  17. #endif
  18. /*************************************************************************
  19. * PANOSE definitions.
  20. *************************************************************************/
  21. #define NUM_PAN_DIGITS 10
  22. #define PANOSE_LEN 10
  23. #define PANOSE_ANY 0
  24. #define PANOSE_NOFIT 1
  25. #define FAMILY_LATTEXT 2
  26. /***************************************************************************
  27. * LATIN TEXT PANOSE INDICES
  28. *
  29. * Indices into an array containing the standard 10-digit PANOSE number.
  30. ***************************************************************************/
  31. #define PAN_IND_FAMILY 0
  32. #define PAN_IND_SERIF 1
  33. #define PAN_IND_WEIGHT 2
  34. #define PAN_IND_PROPORTION 3
  35. #define PAN_IND_CONTRAST 4
  36. #define PAN_IND_STROKE 5
  37. #define PAN_IND_ARMSTYLE 6
  38. #define PAN_IND_LTRFORM 7
  39. #define PAN_IND_MIDLINE 8
  40. #define PAN_IND_XHEIGHT 9
  41. #define PAN_IND__LAST 9
  42. /***************************************************************************
  43. * PURPOSE: Check a 10-digit PANOSE for validity. We just look for any
  44. * PANOSE_ANY's and disqualify it if we find one. We probably should]
  45. * also check for digits greater than DIGIT__LAST.
  46. ***************************************************************************/
  47. class far PANOSEBytesClass {
  48. public :
  49. PANOSEBytesClass () { vClear (); };
  50. VOID vClear () { for( int i = 0; i < PANOSE_LEN; i++ )
  51. m_ajBytes[i] = PANOSE_NOFIT; };
  52. BOOL bVerify () { for( int i = 0; i < PANOSE_LEN; i++ )
  53. if( m_ajBytes[i] == PANOSE_ANY )
  54. return FALSE;
  55. return TRUE; };
  56. BYTE jFamily () { return jGet(PAN_IND_FAMILY); };
  57. BYTE jGet( int i ) { return m_ajBytes[i]; };
  58. public : // fields
  59. BYTE m_ajBytes[ PANOSE_LEN ];
  60. }; // end PANOSEBytesClass
  61. /* required wrapper */
  62. class far PANOSENumClass {
  63. public :
  64. BYTE m_ajNumMem[ NUM_PAN_DIGITS ]; // m_xNumMem. Old extended pan.
  65. };
  66. /*
  67. * Path and filename
  68. */
  69. class far DirFilenameClass
  70. {
  71. public :
  72. void vGetFullName( PTSTR pstr );
  73. void vGetFileName( PTSTR pstr ) { lstrcpy( pstr, m_szFOnly ); };
  74. BOOL bSameFileName( PTSTR pstr )
  75. { return( lstrcmpi( pstr, m_szFOnly ) == 0 ); } ;
  76. void vSet (CFontDir * poDir, LPTSTR lps)
  77. { m_poDir = poDir;
  78. lstrcpy( m_szFOnly, lps ); };
  79. BOOL bSameName( PTSTR szName )
  80. { return lstrcmp( szName, m_szFOnly ) == 0; };
  81. BOOL bOnSysDir( ) { return m_poDir->bOnSysDir(); };
  82. private:
  83. CFontDir * m_poDir;
  84. FILENAME m_szFOnly; // File name portion only
  85. };
  86. /*************************************************************************
  87. * Font record
  88. */
  89. class far CFontClass {
  90. public :
  91. CFontClass ()
  92. : m_cRef(0),
  93. m_bAttributesValid(FALSE) { m_eFileKind = eFKNone; vClear( ); };
  94. ~CFontClass () { vFreeFOT( ); }
  95. ULONG AddRef(void);
  96. ULONG Release(void);
  97. static int s_cFonts;
  98. //
  99. // WARNING: This function zeros out the ENTIRE object using memset.
  100. // This is so bogus I can't believe the original author did it.
  101. // I'm not changing it because I don't want to break anything but
  102. // be aware that it's here. If you introduce a virtual function,
  103. // into this class, this call will overwrite your vtable ptr
  104. // with NULL (ugh!). If you add a non-trivial class as a member,
  105. // this function will wipe out any initialization and any vtable
  106. // ptr it might contain (double ugh!). [brianau - 3/24/98]
  107. //
  108. void vClear () { memset( this, 0, sizeof( *this ) );
  109. m_lpszFamName = m_szFamName; };
  110. /* PANOSE stuff */
  111. BYTE *lpBasePANOSE( ) { bFillIn(); return (BYTE *)&m_xPANOSE.m_ajBytes;};
  112. // BOOL bSameFamily (CFontClass* lpTarget)
  113. // { return bMatchFamily(lpTarget->m_jFamily); };
  114. // BOOL bMatchFamily (BYTE f) { bFillIn(); return m_jFamily == f; };
  115. BOOL bLTDFamily( ) { bFillIn(); return m_jFamily == FAMILY_LATTEXT; };
  116. BOOL bLTDAndPANOSE( ) { bFillIn(); return /* m_fHavePANOSE && */
  117. bLTDFamily();};
  118. /**********************************************************************
  119. * Name (also Family and filename) stuff
  120. */
  121. BOOL bSameFileName( PTSTR pStr ) { return m_dirfn.bSameFileName(pStr); };
  122. BOOL bGetFQName( LPTSTR lpszName, WORD wLen );
  123. BOOL GetFileTime( FILETIME* pft );
  124. void GetFileInfo( );
  125. void vGetFileName( PTSTR pStr ) { m_dirfn.vGetFileName( pStr ); };
  126. DWORD dwGetFileAttributes(void);
  127. void InvalidateFileAttributes(void) { m_bAttributesValid = FALSE; }
  128. void vGetDirFN( PTSTR pStr ) { m_dirfn.vGetFullName( pStr ); };
  129. BOOL bSameDirName( PTSTR pStr ) { return m_dirfn.bSameName( pStr ); };
  130. RC rcStoreDirFN ( LPTSTR pStr ) { return rcStoreDirFN (pStr, m_dirfn); };
  131. void vGetDesc( PTSTR pstr ) { lstrcpy( pstr, m_szFontLHS ); };
  132. const LPTSTR szGetDesc( ) { return m_szFontLHS; }
  133. void vGetName( PTSTR pstr ) { _tcsncpy( pstr, m_szFontLHS, m_wNameLen );
  134. PTSTR p2 = pstr + m_wNameLen; *p2=0; };
  135. BOOL bNameOverlap( PTSTR pstr )
  136. { int iLen = lstrlen( pstr );
  137. if( iLen > m_wNameLen ) iLen = m_wNameLen;
  138. int iCmp = _tcsnicmp( m_szFontLHS, pstr, iLen );
  139. return( iCmp == 0 ); } ;
  140. BOOL bSameName( PTSTR pstr )
  141. { int iCmp = ( lstrlen( pstr ) - m_wNameLen );
  142. if( iCmp == 0 )
  143. iCmp = _tcsnicmp( m_szFontLHS, pstr, m_wNameLen );
  144. return iCmp == 0; };
  145. BOOL bSameDesc( PTSTR pstr ) { return( lstrcmpi( pstr, m_szFontLHS ) == 0 ); };
  146. int iCompareName( CFontClass* pComp )
  147. { return _tcsnccmp( m_szFontLHS, pComp->m_szFontLHS, m_wNameLen ); };
  148. void vGetFamName( PTSTR pstr ) { bFillIn(); lstrcpy (pstr, m_lpszFamName); };
  149. void vSetFamName( PTSTR pstr ) { lstrcpy (m_lpszFamName, pstr); };
  150. BOOL bSameFamily( CFontClass* pComp )
  151. { if( pComp == NULL ) return FALSE;
  152. //
  153. // I removed this part of the "same family" logic so that when the user
  154. // selects "Hide Variations", there is only one object per family.
  155. // Including this statement treats Times Roman (TrueType) as a different family
  156. // than Times Roman (Type1). [brianau]
  157. //
  158. #ifndef WINNT
  159. if( pComp->iFontType() != m_eFileKind )
  160. return FALSE;
  161. #endif
  162. bFillIn();
  163. pComp->bFillIn();
  164. return lstrcmp( m_lpszFamName, pComp->m_lpszFamName ) == 0;};
  165. /**********************************************************************
  166. * font data stuff
  167. */
  168. int iFontType( ) { return m_eFileKind; }
  169. BOOL bDeviceType( ) { return m_eFileKind == eFKDevice; }
  170. BOOL bTrueType( ) { return ((m_eFileKind == eFKTrueType) ||
  171. (m_eFileKind == eFKTTC)); }
  172. BOOL bOpenType( ) { return m_eFileKind == eFKOpenType; }
  173. BOOL bTTC( ) { return m_eFileKind == eFKTTC; }
  174. BOOL bType1( ) { return m_eFileKind == eFKType1; }
  175. /**********************************************************************
  176. * AddFontResource and RemoveFontResource
  177. */
  178. BOOL bAFR();
  179. BOOL bRFR();
  180. /**********************************************************************
  181. * For dealing with the font family list
  182. */
  183. VOID vSetFamilyFont( ) { m_bFamily = TRUE; };
  184. VOID vSetNoFamilyFont( ) { m_bFamily = FALSE;
  185. /* m_wFamIdx = IDX_NULL; */ };
  186. VOID vSetFamIndex( WORD wVal ) { m_wFamIdx = wVal; };
  187. WORD wGetFamIndex( ) { return m_wFamIdx; };
  188. BOOL bSameFamIndex( CFontClass* pComp )
  189. { return pComp->m_wFamIdx == m_wFamIdx; };
  190. /**********************************************************************
  191. * For dealing with the flags
  192. */
  193. DWORD dwStyle( ) { return m_dwStyle; }
  194. BOOL bHavePANOSE( ) { bFillIn(); return (m_jFamily != PANOSE_ANY); }
  195. // BOOL bSymbolSet( ) { bFillIn(); return m_fSymbol; };
  196. BOOL bFamilyFont( ) { return m_bFamily; };
  197. BOOL bOnSysDir( ) { return m_dirfn.bOnSysDir(); };
  198. WORD wFontSize( ) { return m_wFileK; };
  199. BOOL bFilledIn( ) { return m_bFilledIn; };
  200. DWORD dCalcFileSize( );
  201. RC rcStoreDirFN( LPTSTR pStr, DirFilenameClass& dirfn );
  202. // HFONT hPrivateFont( HDC hDC, int iPoints );
  203. BOOL bInit( LPTSTR lpszDesc, LPTSTR lpPath, LPTSTR lpAltPath = NULL );
  204. BOOL bFillIn( );
  205. BOOL bFOT() { return( m_lpszFOT != NULL ); };
  206. BOOL bGetFOT( LPTSTR pszFOT, UINT uFOTLen )
  207. {
  208. if( !bFOT( ) )
  209. return( FALSE );
  210. lstrcpyn( pszFOT, m_lpszFOT, uFOTLen );
  211. return( TRUE );
  212. }
  213. BOOL bPFB() { return( m_lpszPFB != NULL ); };
  214. BOOL bGetPFB( LPTSTR pszPFB, UINT uPFBLen )
  215. {
  216. if( !bType1( ) )
  217. return( FALSE );
  218. lstrcpyn( pszPFB, m_lpszPFB, uPFBLen );
  219. return( TRUE );
  220. }
  221. BOOL bGetFileToDel( LPTSTR szFileName );
  222. private :
  223. CFontDir * poAddDir( LPTSTR lpPath, LPTSTR * lpName );
  224. BOOL bAddDirToDirList(CFontDirList *pDirList, LPCTSTR pszDir, BOOL bSystemDir);
  225. VOID vSetDeviceType( ) { m_eFileKind = eFKDevice; };
  226. VOID vSetTrueType( BOOL bFOT) { m_eFileKind = eFKTrueType; }
  227. VOID vSetOpenType( ) { m_eFileKind = eFKOpenType; }
  228. VOID vSetTTCType( ) { m_eFileKind = eFKTTC; }
  229. VOID vSetType1( ) { m_eFileKind = eFKType1; }
  230. BOOL bSetFOT( LPCTSTR pszFOT )
  231. {
  232. m_lpszFOT = (LPTSTR) LocalAlloc(LMEM_FIXED,
  233. (lstrlen( pszFOT ) + 1) * sizeof( TCHAR ) );
  234. if( !m_lpszFOT )
  235. return( FALSE );
  236. lstrcpy( m_lpszFOT, pszFOT );
  237. return( TRUE );
  238. }
  239. void vFreeFOT() { if( bFOT( ) ) LocalFree( m_lpszFOT ); m_lpszFOT = NULL; }
  240. BOOL bSetPFB( LPCTSTR pszPFB )
  241. {
  242. m_lpszPFB = (LPTSTR) LocalAlloc(LMEM_FIXED,
  243. (lstrlen( pszPFB ) + 1) * sizeof( TCHAR ) );
  244. if( !m_lpszPFB )
  245. return( FALSE );
  246. lstrcpy( m_lpszPFB, pszPFB );
  247. return( TRUE );
  248. }
  249. void vFreePFB() { if( bType1( ) ) LocalFree( m_lpszPFB ); m_lpszPFB = NULL; }
  250. #ifdef WINNT
  251. //
  252. // Functions for getting information from Type1 fonts and
  253. // 32-bit font resources.
  254. //
  255. DWORD GetType1Info(LPCTSTR pszPath,
  256. LPTSTR pszFamilyBuf,
  257. UINT nBufChars,
  258. LPDWORD pdwStyle,
  259. LPWORD pwWeight);
  260. DWORD GetLogFontInfo(LPTSTR pszPath, LOGFONT **ppLogFontInfo);
  261. #endif // WINNT
  262. // VOID vStuffPANOSE ();
  263. // RC rcPANOSEFromTTF( PANOSEBytesClass& xUsePANOSE );
  264. private :
  265. LONG m_cRef; // Reference count.
  266. // Some things are filled in on the first pass, others are
  267. // filled in on the second pass during background processing,
  268. // idle time, or on demand.
  269. //
  270. BOOL m_bAFR; // True if the font is in GDI
  271. FontDesc_t m_szFontLHS; // 1
  272. FAMNAME m_szFamName; // 2
  273. LPTSTR m_lpszFamName; // 2
  274. BOOL m_bFilledIn; // True after 2nd pass
  275. BYTE m_wNameLen; // 1
  276. BYTE m_jFamily; // 2
  277. PANOSEBytesClass m_xPANOSE; // 2
  278. DirFilenameClass m_dirfn; // 1. Path in WIN.INI, not real TTF path
  279. WORD m_wFileK; // 2.
  280. WORD m_wFamIdx; // Set externally.
  281. eFileKind m_eFileKind; // Always an int
  282. BOOL m_bFileInfoFetched;
  283. FILETIME m_ft;
  284. LPTSTR m_lpszFOT;
  285. LPTSTR m_lpszPFB;
  286. DWORD m_dwFileAttributes; // Cached file attributes.
  287. BOOL m_bAttributesValid;
  288. public: // TODO: Add access functions for this.
  289. WORD m_wWeight; // 2. From OS/2 table
  290. BOOL m_bFamily; // 2. Set if main family font
  291. DWORD m_dwStyle; // 2. Same values as
  292. #if 0
  293. union { WORD m_bFlags; // Compiler makes word regardless
  294. /*
  295. * fHavePANOSE - TRUE if PANOSE number derived by looking into file
  296. */
  297. struct {
  298. unsigned m_fHavePANOSE : 1; // 0
  299. unsigned m_fSymbol : 1; // 1
  300. unsigned m_fFamily : 1; // 2
  301. unsigned m_fFOTFile : 1; // 3
  302. unsigned m_fUnderline : 1; // 4
  303. unsigned m_fStrikeout : 1; // 5
  304. unsigned fUnused : 9; }; // 7-15
  305. }; // end union
  306. #endif
  307. // TCHAR pad[256-USEDSIZE];
  308. };
  309. BOOL PASCAL bMakeFQName( LPTSTR, PTSTR, DWORD, BOOL bSearchPath=FALSE );
  310. BOOL bTTFFromFOT( LPCTSTR lpFOTPath, LPTSTR lpTTF, WORD wLen );
  311. BOOL FFGetFileResource( LPCTSTR szFile, LPCTSTR szType, LPCTSTR szRes,
  312. DWORD dwReserved, DWORD *pdwLen, LPVOID lpvData );
  313. LPTSTR PASCAL lpNamePart( LPCTSTR lpszPath );
  314. #endif // __FONTCL_H__