Leaked source code of windows server 2003
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.

378 lines
13 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( LPTSTR pszPath, size_t cchPath );
  73. void vGetFileName( LPTSTR pszName, size_t cchName )
  74. { StringCchCopy( pszName, cchName, m_szFOnly ); };
  75. BOOL bSameFileName( LPTSTR pszName )
  76. { return( lstrcmpi( pszName, m_szFOnly ) == 0 ); } ;
  77. void vSet (CFontDir * poDir, LPTSTR pszPath)
  78. {
  79. m_poDir = poDir;
  80. StringCchCopy( m_szFOnly, ARRAYSIZE(m_szFOnly), pszPath );
  81. };
  82. BOOL bSameName( LPTSTR pszName )
  83. { return lstrcmpi( pszName, m_szFOnly ) == 0; };
  84. BOOL bOnSysDir(void)
  85. { return m_poDir->bOnSysDir(); };
  86. private:
  87. CFontDir * m_poDir;
  88. FILENAME m_szFOnly; // File name portion only
  89. };
  90. /*************************************************************************
  91. * Font record
  92. */
  93. class far CFontClass {
  94. public :
  95. CFontClass ()
  96. : m_cRef(0),
  97. m_bAttributesValid(FALSE) { m_eFileKind = eFKNone; vClear( ); };
  98. ~CFontClass () { vFreeFOT( ); }
  99. ULONG AddRef(void);
  100. ULONG Release(void);
  101. static int s_cFonts;
  102. //
  103. // WARNING: This function zeros out the ENTIRE object using memset.
  104. // This is so bogus I can't believe the original author did it.
  105. // I'm not changing it because I don't want to break anything but
  106. // be aware that it's here. If you introduce a virtual function,
  107. // into this class, this call will overwrite your vtable ptr
  108. // with NULL (ugh!). If you add a non-trivial class as a member,
  109. // this function will wipe out any initialization and any vtable
  110. // ptr it might contain (double ugh!). [brianau - 3/24/98]
  111. //
  112. void vClear () { memset( this, 0, sizeof( *this ) );
  113. m_lpszFamName = m_szFamName;
  114. m_cchFamNameMax = ARRAYSIZE(m_szFamName); };
  115. /* PANOSE stuff */
  116. BYTE *lpBasePANOSE( ) { bFillIn(); return (BYTE *)&m_xPANOSE.m_ajBytes;};
  117. BOOL bLTDFamily( ) { bFillIn(); return m_jFamily == FAMILY_LATTEXT; };
  118. BOOL bLTDAndPANOSE( ) { bFillIn(); return /* m_fHavePANOSE && */
  119. bLTDFamily();};
  120. /**********************************************************************
  121. * Name (also Family and filename) stuff
  122. */
  123. BOOL bSameFileName( PTSTR pStr ) { return m_dirfn.bSameFileName(pStr); };
  124. BOOL bGetFQName( LPTSTR lpszName, size_t cchName );
  125. BOOL GetFileTime( FILETIME* pft );
  126. void GetFileInfo( );
  127. void vGetFileName( PTSTR pStr, size_t cchStr ) { m_dirfn.vGetFileName( pStr, cchStr ); };
  128. DWORD dwGetFileAttributes(void);
  129. void InvalidateFileAttributes(void) { m_bAttributesValid = FALSE; }
  130. void vGetDirFN( PTSTR pStr, size_t cchStr ) { m_dirfn.vGetFullName( pStr, cchStr ); };
  131. BOOL bSameDirName( PTSTR pStr ) { return m_dirfn.bSameName( pStr ); };
  132. RC rcStoreDirFN ( LPTSTR pStr ) { return rcStoreDirFN (pStr, m_dirfn); };
  133. void vGetDesc( PTSTR pstr, size_t cchDesc ) { StringCchCopy( pstr, cchDesc, m_szFontLHS ); };
  134. const LPTSTR szGetDesc( ) { return m_szFontLHS; }
  135. void vGetName( PTSTR pstr, size_t cchName ) { StringCchCopy( pstr, cchName, m_szFontLHS ); }
  136. BOOL bNameOverlap( PTSTR pstr )
  137. { int iLen = lstrlen( pstr );
  138. if( iLen > m_wNameLen ) iLen = m_wNameLen;
  139. int iCmp = _tcsnicmp( m_szFontLHS, pstr, iLen );
  140. return( iCmp == 0 ); } ;
  141. BOOL bSameName( PTSTR pstr )
  142. { int iCmp = ( lstrlen( pstr ) - m_wNameLen );
  143. if( iCmp == 0 )
  144. iCmp = _tcsnicmp( m_szFontLHS, pstr, m_wNameLen );
  145. return iCmp == 0; };
  146. BOOL bSameDesc( PTSTR pstr ) { return( lstrcmpi( pstr, m_szFontLHS ) == 0 ); };
  147. int iCompareName( CFontClass* pComp )
  148. { return _tcsnccmp( m_szFontLHS, pComp->m_szFontLHS, m_wNameLen ); };
  149. void vGetFamName( PTSTR pstr, size_t cchName ) { bFillIn(); StringCchCopy (pstr, cchName, m_lpszFamName); };
  150. void vSetFamName( PTSTR pstr ) { StringCchCopy (m_lpszFamName, m_cchFamNameMax, pstr); };
  151. BOOL bSameFamily( CFontClass* pComp )
  152. { if( pComp == NULL ) return FALSE;
  153. bFillIn();
  154. pComp->bFillIn();
  155. return lstrcmp( m_lpszFamName, pComp->m_lpszFamName ) == 0;};
  156. /**********************************************************************
  157. * font data stuff
  158. */
  159. int iFontType( ) { return m_eFileKind; }
  160. BOOL bDeviceType( ) { return m_eFileKind == eFKDevice; }
  161. BOOL bTrueType( ) { return ((m_eFileKind == eFKTrueType) ||
  162. (m_eFileKind == eFKTTC)); }
  163. BOOL bOpenType( ) { return m_eFileKind == eFKOpenType; }
  164. BOOL bTTC( ) { return m_eFileKind == eFKTTC; }
  165. BOOL bType1( ) { return m_eFileKind == eFKType1; }
  166. /**********************************************************************
  167. * AddFontResource and RemoveFontResource
  168. */
  169. BOOL bAFR();
  170. BOOL bRFR();
  171. /**********************************************************************
  172. * For dealing with the font family list
  173. */
  174. VOID vSetFamilyFont( ) { m_bFamily = TRUE; };
  175. VOID vSetNoFamilyFont( ) { m_bFamily = FALSE;
  176. /* m_wFamIdx = IDX_NULL; */ };
  177. VOID vSetFamIndex( WORD wVal ) { m_wFamIdx = wVal; };
  178. WORD wGetFamIndex( ) { return m_wFamIdx; };
  179. BOOL bSameFamIndex( CFontClass* pComp )
  180. { return pComp->m_wFamIdx == m_wFamIdx; };
  181. /**********************************************************************
  182. * For dealing with the flags
  183. */
  184. DWORD dwStyle( ) { return m_dwStyle; }
  185. BOOL bHavePANOSE( ) { bFillIn(); return (m_jFamily != PANOSE_ANY); }
  186. BOOL bFamilyFont( ) { return m_bFamily; };
  187. BOOL bOnSysDir( ) { return m_dirfn.bOnSysDir(); };
  188. WORD wFontSize( ) { return m_wFileK; };
  189. BOOL bFilledIn( ) { return m_bFilledIn; };
  190. DWORD dCalcFileSize( );
  191. RC rcStoreDirFN( LPTSTR pStr, DirFilenameClass& dirfn );
  192. BOOL bInit( LPTSTR lpszDesc, LPTSTR lpPath, LPTSTR lpAltPath = NULL );
  193. BOOL bFillIn( );
  194. BOOL bFOT() { return( m_lpszFOT != NULL ); };
  195. BOOL bGetFOT( LPTSTR pszFOT, size_t cchFOT )
  196. {
  197. if( !bFOT( ) )
  198. return( FALSE );
  199. if (FAILED(StringCchCopy( pszFOT, cchFOT, m_lpszFOT )))
  200. return( FALSE );
  201. return( TRUE );
  202. }
  203. BOOL bPFB() { return( m_lpszPFB != NULL ); };
  204. BOOL bGetPFB( LPTSTR pszPFB, size_t cchPFB )
  205. {
  206. if( !bType1( ) )
  207. return( FALSE );
  208. if (FAILED(StringCchCopy( pszPFB, cchPFB, m_lpszPFB )))
  209. return( FALSE );
  210. return( TRUE );
  211. }
  212. BOOL bGetFileToDel( LPTSTR pszFileName, size_t cchFileName );
  213. private :
  214. CFontDir * poAddDir( LPTSTR lpPath, LPTSTR * lpName );
  215. BOOL bAddDirToDirList(CFontDirList *pDirList, LPCTSTR pszDir, BOOL bSystemDir);
  216. VOID vSetDeviceType( ) { m_eFileKind = eFKDevice; };
  217. VOID vSetTrueType( BOOL bFOT) { m_eFileKind = eFKTrueType; }
  218. VOID vSetOpenType( ) { m_eFileKind = eFKOpenType; }
  219. VOID vSetTTCType( ) { m_eFileKind = eFKTTC; }
  220. VOID vSetType1( ) { m_eFileKind = eFKType1; }
  221. BOOL bSetFOT( LPCTSTR pszFOT )
  222. {
  223. m_lpszFOT = StrDup(pszFOT);
  224. return NULL != m_lpszFOT;
  225. }
  226. void vFreeFOT() { if( bFOT( ) ) LocalFree( m_lpszFOT ); m_lpszFOT = NULL; }
  227. BOOL bSetPFB( LPCTSTR pszPFB )
  228. {
  229. m_lpszPFB = StrDup(pszPFB);
  230. return NULL != m_lpszPFB;
  231. }
  232. void vFreePFB() { if( bType1( ) ) LocalFree( m_lpszPFB ); m_lpszPFB = NULL; }
  233. //
  234. // Functions for getting information from Type1 fonts and
  235. // 32-bit font resources.
  236. //
  237. DWORD GetType1Info(LPCTSTR pszPath,
  238. LPTSTR pszFamilyBuf,
  239. UINT nBufChars,
  240. LPDWORD pdwStyle,
  241. LPWORD pwWeight);
  242. DWORD GetLogFontInfo(LPTSTR pszPath, LOGFONT **ppLogFontInfo);
  243. private :
  244. LONG m_cRef; // Reference count.
  245. // Some things are filled in on the first pass, others are
  246. // filled in on the second pass during background processing,
  247. // idle time, or on demand.
  248. //
  249. BOOL m_bAFR; // True if the font is in GDI
  250. FontDesc_t m_szFontLHS; // 1
  251. FAMNAME m_szFamName; // 2
  252. LPTSTR m_lpszFamName; // 2
  253. size_t m_cchFamNameMax;
  254. BOOL m_bFilledIn; // True after 2nd pass
  255. BYTE m_wNameLen; // 1
  256. BYTE m_jFamily; // 2
  257. PANOSEBytesClass m_xPANOSE; // 2
  258. DirFilenameClass m_dirfn; // 1. Path in WIN.INI, not real TTF path
  259. WORD m_wFileK; // 2.
  260. WORD m_wFamIdx; // Set externally.
  261. eFileKind m_eFileKind; // Always an int
  262. BOOL m_bFileInfoFetched;
  263. FILETIME m_ft;
  264. LPTSTR m_lpszFOT;
  265. LPTSTR m_lpszPFB;
  266. DWORD m_dwFileAttributes; // Cached file attributes.
  267. BOOL m_bAttributesValid;
  268. public: // TODO: Add access functions for this.
  269. WORD m_wWeight; // 2. From OS/2 table
  270. BOOL m_bFamily; // 2. Set if main family font
  271. DWORD m_dwStyle; // 2. Same values as
  272. };
  273. BOOL PASCAL bMakeFQName( LPTSTR, LPTSTR, size_t, BOOL bSearchPath=FALSE );
  274. BOOL bTTFFromFOT( LPTSTR pszFOTPath, LPTSTR pszTTF, size_t cchTTF );
  275. BOOL FFGetFileResource( LPCTSTR szFile, LPCTSTR szType, LPCTSTR szRes,
  276. DWORD dwReserved, DWORD *pdwLen, LPVOID lpvData );
  277. #endif // __FONTCL_H__