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.

316 lines
10 KiB

  1. // MLFLink.h : Declaration of the CMLFLink
  2. #ifndef __MLFLINK_H_
  3. #define __MLFLINK_H_
  4. #include "mlatl.h"
  5. #include "font.h"
  6. #define NUMFONTMAPENTRIES 15
  7. // Error Code
  8. #define FACILITY_MLSTR 0x0A15
  9. #define MLSTR_E_FACEMAPPINGFAILURE MAKE_HRESULT(1, FACILITY_MLSTR, 1001)
  10. extern FONTINFO *g_pfont_table;
  11. class CMultiLanguage;
  12. class CMultiLanguage2;
  13. // Code Page Table Cache
  14. struct CCodePagesHeader
  15. {
  16. DWORD m_dwID;
  17. DWORD m_dwVersion;
  18. DWORD m_dwFileSize;
  19. DWORD m_dwBlockSize;
  20. DWORD m_dwTableOffset;
  21. DWORD m_dwReserved;
  22. BYTE m_abCmdCode[8];
  23. };
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CMLFLink
  26. class ATL_NO_VTABLE CMLFLink :
  27. public CComTearOffObjectBase<CMultiLanguage>,
  28. public IMLangFontLink
  29. {
  30. friend void CMLangFontLink_FreeGlobalObjects(void);
  31. friend HRESULT GetCharCodePagesEx(WCHAR chSrc, DWORD* pdwCodePages, DWORD dwFlags);
  32. friend HRESULT GetStrCodePagesEx(const WCHAR* pszSrc, long cchSrc, DWORD dwPriorityCodePages, DWORD* pdwCodePages, long* pcchCodePages, DWORD dwFlags);
  33. friend HRESULT CodePageToCodePagesEx(UINT uCodePage, DWORD* pdwCodePages, DWORD* pdwCodePagesExt);
  34. friend HRESULT CodePagesToCodePageEx(DWORD dwCodePages, UINT uDefaultCodePage, UINT* puCodePage, BOOL bCodePagesExt);
  35. public:
  36. CMLFLink(void);
  37. ~CMLFLink(void)
  38. {
  39. if (m_pFlinkTable)
  40. FreeFlinkTable();
  41. DllRelease();
  42. }
  43. DECLARE_NO_REGISTRY()
  44. BEGIN_COM_MAP(CMLFLink)
  45. COM_INTERFACE_ENTRY(IMLangCodePages)
  46. COM_INTERFACE_ENTRY(IMLangFontLink)
  47. END_COM_MAP()
  48. public:
  49. // IMLangCodePages
  50. STDMETHOD(GetCharCodePages)(/*[in]*/ WCHAR chSrc, /*[out]*/ DWORD* pdwCodePages);
  51. STDMETHOD(GetStrCodePages)(/*[in, size_is(cchSrc)]*/ const WCHAR* pszSrc, /*[in]*/ long cchSrc, /*[in]*/ DWORD dwPriorityCodePages, /*[out]*/ DWORD* pdwCodePages, /*[out]*/ long* pcchCodePages);
  52. STDMETHOD(CodePageToCodePages)(/*[in]*/ UINT uCodePage, /*[out]*/ DWORD* pdwCodePages);
  53. STDMETHOD(CodePagesToCodePage)(/*[in]*/ DWORD dwCodePages, /*[in]*/ UINT uDefaultCodePage, /*[out]*/ UINT* puCodePage);
  54. // IMLangFontLink
  55. STDMETHOD(GetFontCodePages)(/*[in]*/ HDC hDC, /*[in]*/ HFONT hFont, /*[out]*/ DWORD* pdwCodePages);
  56. STDMETHOD(MapFont)(/*[in]*/ HDC hDC, /*[in]*/ DWORD dwCodePages, /*[in]*/ HFONT hSrcFont, /*[out]*/ HFONT* phDestFont);
  57. STDMETHOD(ReleaseFont)(/*[in]*/ HFONT hFont);
  58. STDMETHOD(ResetFontMapping)(void);
  59. protected:
  60. static int CALLBACK GetFontCodePagesEnumFontProc(const LOGFONT *lplf, const TEXTMETRIC *lptm, DWORD dwFontType, LPARAM lParam);
  61. // MapFont() support functions
  62. class CFontMappingInfo
  63. {
  64. public:
  65. CFontMappingInfo(void) : hDestFont(NULL) {}
  66. ~CFontMappingInfo(void) {if (hDestFont) ::DeleteObject(hDestFont);}
  67. HDC hDC;
  68. int iCP;
  69. HFONT hDestFont;
  70. TCHAR szFaceName[LF_FACESIZE];
  71. LOGFONT lfSrcFont;
  72. LOGFONT lfDestFont;
  73. UINT auCodePage[32 + 1]; // +1 for end mark
  74. DWORD adwCodePages[32 + 1];
  75. };
  76. typedef HRESULT (CMLFLink::*PFNGETFACENAME)(CFontMappingInfo& fmi);
  77. HRESULT MapFontCodePages(CFontMappingInfo& fmi, PFNGETFACENAME pfnGetFaceName);
  78. static int CALLBACK MapFontEnumFontProc(const LOGFONT* lplf, const TEXTMETRIC*, DWORD, LPARAM lParam);
  79. HRESULT GetFaceNameRegistry(CFontMappingInfo& fmi);
  80. HRESULT GetFaceNameGDI(CFontMappingInfo& fmi);
  81. HRESULT GetFaceNameMIME(CFontMappingInfo& fmi);
  82. HRESULT GetFaceNameRealizeFont(CFontMappingInfo& fmi);
  83. HRESULT VerifyFaceMap(CFontMappingInfo& fmi);
  84. // Font Mapping Cache
  85. class CFontMappingCache
  86. {
  87. class CFontMappingCacheEntry
  88. {
  89. friend class CFontMappingCache;
  90. protected:
  91. CFontMappingCacheEntry* m_pPrev;
  92. CFontMappingCacheEntry* m_pNext;
  93. int m_nLockCount;
  94. UINT m_uSrcCodePage;
  95. LONG m_lSrcHeight;
  96. LONG m_lSrcWidth;
  97. LONG m_lSrcEscapement;
  98. LONG m_lSrcOrientation;
  99. LONG m_lSrcWeight;
  100. BYTE m_bSrcItalic;
  101. BYTE m_bSrcUnderline;
  102. BYTE m_bSrcStrikeOut;
  103. BYTE m_bSrcPitchAndFamily;
  104. TCHAR m_szSrcFaceName[LF_FACESIZE];
  105. HFONT m_hDestFont;
  106. };
  107. public:
  108. CFontMappingCache(void);
  109. ~CFontMappingCache(void);
  110. HRESULT FindEntry(UINT uCodePage, const LOGFONT& lfSrcFont, HFONT* phDestFont);
  111. HRESULT UnlockEntry(HFONT hDestFont);
  112. HRESULT AddEntry(UINT uCodePage, const LOGFONT& lfSrcFont, HFONT hDestFont);
  113. HRESULT FlushEntries(void);
  114. protected:
  115. CRITICAL_SECTION m_cs;
  116. CFontMappingCacheEntry* m_pEntries;
  117. CFontMappingCacheEntry* m_pFree;
  118. int m_cEntries;
  119. };
  120. // Code Page Table Cache
  121. class CCodePagesCache
  122. {
  123. public:
  124. CCodePagesCache(void);
  125. ~CCodePagesCache(void);
  126. inline HRESULT Load(void);
  127. inline operator PBYTE(void) const;
  128. inline BYTE* GetCodePageBits(BOOL bCodePagesExt);
  129. protected:
  130. HRESULT RealLoad(void);
  131. protected:
  132. CRITICAL_SECTION m_cs;
  133. BYTE* m_pbBuf;
  134. BYTE* m_pbBufExt;
  135. };
  136. static CFontMappingCache* m_pFontMappingCache;
  137. static CCodePagesCache* m_pCodePagesCache;
  138. // For NT5 system font link
  139. typedef struct tagFLinkFont {
  140. WCHAR szFaceName[LF_FACESIZE];
  141. LPWSTR pmszFaceName;
  142. } FLINKFONT, *PFLINKFONT;
  143. UINT m_uiFLinkFontNum;
  144. PFLINKFONT m_pFlinkTable;
  145. void FreeFlinkTable(void);
  146. HRESULT CreateNT5FontLinkTable(void);
  147. HRESULT GetNT5FLinkFontCodePages(HDC hDC, LOGFONTW* plfEnum, DWORD * lpdwCodePages);
  148. static int CALLBACK GetFontCodePagesEnumFontProcW(const LOGFONTW *lplf, const TEXTMETRICW *lptm, DWORD dwFontType, LPARAM lParam);
  149. static int CALLBACK VerifyFontSizeEnumFontProc(const LOGFONT *lplf, const TEXTMETRIC *lptm, DWORD dwFontType, LPARAM lParam);
  150. };
  151. class CMultiLanguage2;
  152. class ATL_NO_VTABLE CMLFLink2 :
  153. #ifdef UNIX // Unix VTable isn't portable, we need to use CMultiLanguage
  154. public CComTearOffObjectBase<CMultiLanguage>,
  155. #else
  156. public CComTearOffObjectBase<CMultiLanguage2>,
  157. #endif
  158. public IMLangFontLink2
  159. {
  160. IMLangFontLink * m_pIMLFLnk;
  161. public:
  162. BEGIN_COM_MAP(CMLFLink2)
  163. COM_INTERFACE_ENTRY(IMLangFontLink2)
  164. END_COM_MAP()
  165. CMLFLink2(void)
  166. {
  167. DllAddRef();
  168. CComCreator< CComPolyObject< CMLFLink > >::CreateInstance( NULL, IID_IMLangFontLink, (void **)&m_pIMLFLnk );
  169. }
  170. ~CMLFLink2(void)
  171. {
  172. if (m_pIMLFLnk)
  173. {
  174. m_pIMLFLnk->Release();
  175. m_pIMLFLnk = NULL;
  176. }
  177. DllRelease();
  178. }
  179. // IMLangCodePages
  180. STDMETHOD(GetCharCodePages)(/*[in]*/ WCHAR chSrc, /*[out]*/ DWORD* pdwCodePages)
  181. {
  182. if (m_pIMLFLnk)
  183. return m_pIMLFLnk->GetCharCodePages(chSrc, pdwCodePages);
  184. else
  185. return E_FAIL;
  186. }
  187. STDMETHOD(CodePageToCodePages)(/*[in]*/ UINT uCodePage, /*[out]*/ DWORD* pdwCodePages)
  188. {
  189. if (m_pIMLFLnk)
  190. return m_pIMLFLnk->CodePageToCodePages(uCodePage, pdwCodePages);
  191. else
  192. return E_FAIL;
  193. }
  194. STDMETHOD(CodePagesToCodePage)(/*[in]*/ DWORD dwCodePages, /*[in]*/ UINT uDefaultCodePage, /*[out]*/ UINT* puCodePage)
  195. {
  196. if (m_pIMLFLnk)
  197. return m_pIMLFLnk->CodePagesToCodePage(dwCodePages, uDefaultCodePage, puCodePage);
  198. else
  199. return E_FAIL;
  200. }
  201. // IMLangFontLink
  202. STDMETHOD(GetFontCodePages)(/*[in]*/ HDC hDC, /*[in]*/ HFONT hFont, /*[out]*/ DWORD* pdwCodePages)
  203. {
  204. if (m_pIMLFLnk)
  205. return m_pIMLFLnk->GetFontCodePages(hDC, hFont, pdwCodePages);
  206. else
  207. return E_FAIL;
  208. }
  209. STDMETHOD(ReleaseFont)(/*[in]*/ HFONT hFont)
  210. {
  211. if (m_pIMLFLnk)
  212. return m_pIMLFLnk->ReleaseFont(hFont);
  213. else
  214. return E_FAIL;
  215. }
  216. // IMLangFontLink2
  217. STDMETHOD(ResetFontMapping)(void);
  218. STDMETHOD(GetStrCodePages)(/*[in, size_is(cchSrc)]*/ const WCHAR* pszSrc, /*[in]*/ long cchSrc, /*[in]*/ DWORD dwPriorityCodePages, /*[out]*/ DWORD* pdwCodePages, /*[out]*/ long* pcchCodePages);
  219. STDMETHOD(MapFont)(/*[in]*/ HDC hDC, /*[in]*/ DWORD dwCodePages, /*[in]*/ WCHAR chSrc, /*[out]*/ HFONT* pFont);
  220. STDMETHOD(GetFontUnicodeRanges)(/*[in]*/ HDC hDC, /*[in,out]*/ UINT *puiRanges, /*[out]*/ UNICODERANGE* pUranges);
  221. STDMETHOD(GetScriptFontInfo)(SCRIPT_ID sid, DWORD dwFlags, UINT *puiFonts, SCRIPTFONTINFO* pScriptFont);
  222. STDMETHOD(CodePageToScriptID)(UINT uiCodePage, SCRIPT_ID *pSid);
  223. // Font Mapping Cache2 for MapFont
  224. class CFontMappingCache2
  225. {
  226. protected:
  227. TCHAR szFontDataFilePath[MAX_PATH];
  228. public:
  229. CFontMappingCache2(void);
  230. ~CFontMappingCache2(void);
  231. int fetchCharSet(BYTE *pCharset, int iURange);
  232. BOOL GetNonCpFontUnicodeRanges(TCHAR *szFontName, int iFontIndex);
  233. BOOL SetFontScripts(void);
  234. BOOL SetFontTable(void);
  235. BOOL GetFontURangeBits(TCHAR *szFontName, DWORD *pdwURange);
  236. BOOL IsFontUpdated(void);
  237. HRESULT UnicodeRanges(LPTSTR pszFont, UINT *puiRanges, UNICODERANGE* pURanges);
  238. HRESULT SetFontUnicodeRanges(void);
  239. HRESULT MapFontFromCMAP(HDC hDC, WCHAR wchar, HFONT hSrcFont, HFONT *phDestFont);
  240. HRESULT LoadFontDataFile(void);
  241. HRESULT SaveFontDataFile(void);
  242. HRESULT EnsureFontTable(BOOL bUpdateURangeTable);
  243. static int CALLBACK MapFontExEnumFontProc(const LOGFONT* plfFont, const TEXTMETRIC* lptm, DWORD FontType, LPARAM lParam);
  244. static int CALLBACK SetFontScriptsEnumFontProc(const LOGFONT* plfFont, const TEXTMETRIC* lptm, DWORD FontType, LPARAM lParam);
  245. };
  246. static CFontMappingCache2* m_pFontMappingCache2;
  247. };
  248. /////////////////////////////////////////////////////////////////////////////
  249. // CMLFLink inline functions
  250. HRESULT CMLFLink::CCodePagesCache::Load(void)
  251. {
  252. if (m_pbBuf && m_pbBufExt)
  253. return S_OK;
  254. else
  255. return RealLoad();
  256. }
  257. BYTE * CMLFLink::CCodePagesCache::GetCodePageBits(BOOL bCodePagesExt)
  258. {
  259. if (bCodePagesExt)
  260. return m_pbBufExt;
  261. else
  262. return m_pbBuf;
  263. }
  264. CMLFLink::CCodePagesCache::operator PBYTE(void) const
  265. {
  266. return m_pbBuf;
  267. }
  268. #endif //__MLFLINK_H_