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.

307 lines
10 KiB

  1. #ifndef __EXTRICON_H__
  2. #define __EXTRICON_H__
  3. ///////////////////////////////////////////////////////////////////////////////
  4. /* File: extricon.h
  5. Description: Contains implementation of IExtractIcon for the font folder.
  6. This code provides icon identification for both TrueType and OpenType
  7. font files. The logic used is as follows:
  8. TrueType(1) DSIG? CFF? Icon
  9. ------------ ------- ------- -----------
  10. yes no no TT
  11. yes no yes OTp
  12. yes yes no OTt
  13. yes yes yes OTp
  14. (1) Files must contain required TrueType tables to be considered
  15. a TrueType font file.
  16. This icon handler is used by both the shell and the font folder
  17. to display TrueType and OpenType font icons. It is designed to be
  18. easily extensible if support for dynamic icon identification is
  19. required in other fonts.
  20. Classes (indentation denotes inheritance):
  21. CFontIconHandler
  22. IconHandler
  23. TrueTypeIconHandler
  24. NOTE: The design is sort of in a state of limbo right now. Originally
  25. the idea was to support two types of OpenType icons along with
  26. the conventional TrueType and raster font icons. The OpenType
  27. icons were OTt and OTp with the 't' and 'p' meaning "TrueType"
  28. and "PostScript". Later we decided to only show the icons as
  29. "OT" without the subscript 't' or 'p'. The code still distinguishes
  30. the difference but we just use the same "OT" icon for both the
  31. OTt and OTp conditions. Make sense? Anyway, This OTt and OTp
  32. stuff may come back at a later date (GDI guys haven't decided)
  33. so I'm leaving that code in place. [brianau - 4/7/98]
  34. Revision History:
  35. Date Description Programmer
  36. -------- --------------------------------------------------- ----------
  37. 06/13/97 Initial creation. BrianAu
  38. 04/08/98 Removed OpenTypeIconHandler and folded it into BrianAu
  39. TrueTypeIconHandler. There's no need for the
  40. separation. Also added detection of "required"
  41. TrueType tables.
  42. */
  43. ///////////////////////////////////////////////////////////////////////////////
  44. //
  45. // Pure virtual base class for all types of icon handlers.
  46. //
  47. class IconHandler
  48. {
  49. public:
  50. //
  51. // Simple encapsulation of a mapped file for opening font files.
  52. //
  53. class MappedFile
  54. {
  55. public:
  56. MappedFile(VOID)
  57. : m_hFile(INVALID_HANDLE_VALUE),
  58. m_hFileMapping(INVALID_HANDLE_VALUE),
  59. m_pbBase(NULL) { }
  60. ~MappedFile(VOID);
  61. HRESULT Open(LPCTSTR pszFile);
  62. VOID Close(VOID);
  63. LPBYTE Base(VOID)
  64. { return m_pbBase; }
  65. private:
  66. HANDLE m_hFile;
  67. HANDLE m_hFileMapping;
  68. LPBYTE m_pbBase;
  69. //
  70. // Prevent copy.
  71. //
  72. MappedFile(const MappedFile& rhs);
  73. MappedFile& operator = (const MappedFile& rhs);
  74. };
  75. virtual ~IconHandler(VOID) { };
  76. //
  77. // Derived classes implement this to retrieve the index (ID) of the
  78. // desired icon in fontext.dll.
  79. //
  80. virtual INT GetIconIndex(LPCTSTR pszFileName) = 0;
  81. //
  82. // Derived classes implement this to retrieve the large and small
  83. // icons corresponding to an index. The index should be one returned
  84. // from GetIconIndex().
  85. //
  86. virtual HRESULT GetIcons(UINT iIconIndex, HICON *phiconLarge, HICON *phiconSmall) = 0;
  87. //
  88. // This static function creates an icon handler object of the proper
  89. // derived type for the font file extension specified in pszFileExt.
  90. //
  91. static HRESULT Create(LPCTSTR pszFile, IconHandler **ppHandler);
  92. };
  93. /*
  94. //
  95. // This is a template for creating a new type of icon handler for
  96. // other types of font files.
  97. //
  98. // To create a new handler:
  99. // 1. Create new handler class from template below.
  100. // 2. Provide implementations for GetIconIndex and GetIcons.
  101. // 3. Load icons in constructor. See OpenTypeIconHandler as an example.
  102. // 4. Modify IconHandler::Create() to instantiate the new handler type.
  103. //
  104. class XXXXIconHandler : public IconHandler
  105. {
  106. public:
  107. XXXXIconHandler(VOID);
  108. virtual INT GetIconIndex(LPCTSTR pszFileName);
  109. virtual HRESULT GetIcons(UINT iIconIndex, HICON *phiconLarge, HICON *phiconSmall);
  110. private:
  111. static HICON m_hiconLarge;
  112. static HICON m_hiconSmall;
  113. };
  114. */
  115. //
  116. // Icon handler for TrueType font files.
  117. //
  118. class TrueTypeIconHandler : public IconHandler
  119. {
  120. public:
  121. TrueTypeIconHandler(DWORD dwTables);
  122. ~TrueTypeIconHandler(void);
  123. virtual INT GetIconIndex(LPCTSTR pszFileName);
  124. virtual HRESULT GetIcons(UINT iIconIndex, HICON *phiconLarge, HICON *phiconSmall);
  125. //
  126. // Scans TTF or OTF file identifying tables.
  127. // Used by TrueTypeIconHandler and any subclasses.
  128. //
  129. static BOOL GetFileTables(LPCTSTR pszFile, LPDWORD pfTables);
  130. enum TABLES {
  131. //
  132. // These are the only tables we're interested in.
  133. //
  134. TABLE_CFF = 0x00000001,
  135. TABLE_DSIG = 0x00000002,
  136. TABLE_HEAD = 0x00000004,
  137. TABLE_NAME = 0x00000008,
  138. TABLE_CMAP = 0x00000010,
  139. TABLE_HHEA = 0x00000020,
  140. TABLE_HMTX = 0x00000040,
  141. TABLE_OS2 = 0x00000080,
  142. TABLE_POST = 0x00000100,
  143. TABLE_GLYF = 0x00000200,
  144. TABLE_MAXP = 0x00000400,
  145. TABLE_LOCA = 0x00000800,
  146. TABLE_TTCF = 0x00001000 // this is a pseudo table.
  147. };
  148. static DWORD RequiredOpenTypeTables(void)
  149. { return (TABLE_CMAP |
  150. TABLE_HEAD |
  151. TABLE_HHEA |
  152. TABLE_HMTX |
  153. TABLE_MAXP |
  154. TABLE_NAME |
  155. TABLE_POST |
  156. TABLE_OS2); }
  157. static DWORD RequiredTrueTypeTables(void)
  158. { return (RequiredOpenTypeTables() |
  159. TABLE_GLYF |
  160. TABLE_LOCA); }
  161. protected:
  162. enum eIcons {iICON_LARGE_TT,
  163. iICON_SMALL_TT,
  164. iICON_LARGE_OTt,
  165. iICON_SMALL_OTt,
  166. iICON_LARGE_OTp,
  167. iICON_SMALL_OTp,
  168. iICON_LARGE_TTC,
  169. iICON_SMALL_TTC,
  170. MAX_ICONS };
  171. DWORD m_dwTables;
  172. HICON m_rghIcons[MAX_ICONS]; // Array of icon handles.
  173. private:
  174. static BOOL ReadFileTables(IconHandler::MappedFile& file, LPDWORD pfTables);
  175. static INT FilterReadFileTablesException(INT nException);
  176. HICON GetIcon(int iIcon);
  177. };
  178. //
  179. // Declaration for the DLL's icon handler.
  180. // This is the object that is instantiated whenever a client asks CLSID_FontExt
  181. // for IID_IExtractIcon or IID_IPersistFile.
  182. //
  183. class CFontIconHandler : public IExtractIconW,
  184. public IExtractIconA,
  185. public IPersistFile
  186. {
  187. public:
  188. CFontIconHandler(VOID);
  189. ~CFontIconHandler(VOID);
  190. //
  191. // IUnknown methods.
  192. //
  193. STDMETHODIMP
  194. QueryInterface(
  195. REFIID riid,
  196. LPVOID *ppvOut);
  197. STDMETHODIMP_(ULONG)
  198. AddRef(
  199. VOID);
  200. STDMETHODIMP_(ULONG)
  201. Release(
  202. VOID);
  203. //
  204. // IExtractIconW methods.
  205. //
  206. STDMETHODIMP Extract(
  207. LPCWSTR pszFileW,
  208. UINT nIconIndex,
  209. HICON *phiconLarge,
  210. HICON *phiconSmall,
  211. UINT nIconSize);
  212. STDMETHODIMP GetIconLocation(
  213. UINT uFlags,
  214. LPWSTR szIconFileW,
  215. UINT cchMax,
  216. int *piIndex,
  217. UINT *pwFlags);
  218. //
  219. // IExtractIconA methods.
  220. //
  221. STDMETHODIMP Extract(
  222. LPCSTR pszFileA,
  223. UINT nIconIndex,
  224. HICON *phiconLarge,
  225. HICON *phiconSmall,
  226. UINT nIconSize);
  227. STDMETHODIMP GetIconLocation(
  228. UINT uFlags,
  229. LPSTR szIconFileA,
  230. UINT cchMax,
  231. int *piIndex,
  232. UINT *pwFlags);
  233. //
  234. // IPersist methods.
  235. //
  236. STDMETHODIMP GetClassID(
  237. CLSID *pClassID);
  238. //
  239. // IPersistFile methods.
  240. //
  241. STDMETHODIMP IsDirty(
  242. VOID);
  243. STDMETHODIMP Load(
  244. LPCOLESTR pszFileName,
  245. DWORD dwMode);
  246. STDMETHODIMP Save(
  247. LPCOLESTR pszFileName,
  248. BOOL fRemember);
  249. STDMETHODIMP SaveCompleted(
  250. LPCOLESTR pszFileName);
  251. STDMETHODIMP GetCurFile(
  252. LPOLESTR *ppszFileName);
  253. private:
  254. LONG m_cRef;
  255. TCHAR m_szFileName[MAX_PATH]; // Name of icon file.
  256. IconHandler *m_pHandler; // Ptr to type-specific handler.
  257. static TCHAR m_szFontExtDll[MAX_PATH]; // Path to FONTEXT.DLL
  258. INT GetIconIndex(VOID);
  259. HRESULT GetIcons(UINT iIconIndex, HICON *phiconLarge, HICON *phiconSmall);
  260. };
  261. #endif // __EXTRICON_H__