[FONTEXT] Initial implementation of CFontExt::DoGetFontTitle (#3127)
authorKatayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
Sat, 12 Sep 2020 00:40:48 +0000 (09:40 +0900)
committerGitHub <noreply@github.com>
Sat, 12 Sep 2020 00:40:48 +0000 (09:40 +0900)
This PR is a preparation of fonts folder implementation. CORE-12861

dll/shellext/fontext/CFontExt.cpp
dll/shellext/fontext/CFontExt.hpp
sdk/include/reactos/undocgdi.h

index c157104..03d03f4 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include "precomp.h"
+#include "undocgdi.h" // for GetFontResourceInfoW
 
 WINE_DEFAULT_DEBUG_CHANNEL(fontext);
 
@@ -454,12 +455,8 @@ STDMETHODIMP CFontExt::DragEnter(IDataObject* pDataObj, DWORD grfKeyState, POINT
     if (FAILED_UNEXPECTEDLY(hr))
         return hr;
 
-#if 1   // Please implement DoGetFontTitle
-    return DRAGDROP_S_CANCEL;
-#else
     *pdwEffect = DROPEFFECT_COPY;
     return S_OK;
-#endif
 }
 
 STDMETHODIMP CFontExt::DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
@@ -567,8 +564,8 @@ HRESULT CFontExt::DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HK
     WCHAR szDestFile[MAX_PATH];
     LPCWSTR pszFileTitle = PathFindFileName(pszFontPath);
 
-    WCHAR szFontName[512];
-    if (!DoGetFontTitle(pszFontPath, szFontName))
+    CStringW strFontName;
+    if (!DoGetFontTitle(pszFontPath, strFontName))
         return E_FAIL;
 
     RemoveFontResourceW(pszFileTitle);
@@ -581,7 +578,7 @@ HRESULT CFontExt::DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HK
         return E_FAIL;
     }
 
-    if (!AddFontResourceW(pszFileTitle))
+    if (!AddFontResourceW(szDestFile))
     {
         ERR("AddFontResourceW('%S') failed\n", pszFileTitle);
         DeleteFileW(szDestFile);
@@ -589,7 +586,8 @@ HRESULT CFontExt::DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HK
     }
 
     DWORD cbData = (wcslen(pszFileTitle) + 1) * sizeof(WCHAR);
-    LONG nError = RegSetValueExW(hkeyFonts, szFontName, 0, REG_SZ, (const BYTE *)szFontName, cbData);
+    LONG nError = RegSetValueExW(hkeyFonts, strFontName, 0, REG_SZ,
+                                 (const BYTE *)pszFileTitle, cbData);
     if (nError)
     {
         ERR("RegSetValueExW failed with %ld\n", nError);
@@ -601,8 +599,26 @@ HRESULT CFontExt::DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HK
     return S_OK;
 }
 
-HRESULT CFontExt::DoGetFontTitle(LPCWSTR pszFontPath, LPCWSTR pszFontName)
+HRESULT
+CFontExt::DoGetFontTitle(IN LPCWSTR pszFontPath, OUT CStringW& strFontName)
 {
-    // TODO:
+    DWORD cbInfo = 0;
+    BOOL ret = GetFontResourceInfoW(pszFontPath, &cbInfo, NULL, 1);
+    if (!ret || !cbInfo)
+    {
+        ERR("GetFontResourceInfoW failed\n");
+        return E_FAIL;
+    }
+
+    LPWSTR pszBuffer = strFontName.GetBuffer(cbInfo / sizeof(WCHAR));
+    ret = GetFontResourceInfoW(pszFontPath, &cbInfo, pszBuffer, 1);
+    strFontName.ReleaseBuffer();
+    if (ret)
+    {
+        TRACE("pszFontName: %S\n", (LPCWSTR)strFontName);
+        return S_OK;
+    }
+
+    ERR("GetFontResourceInfoW failed\n");
     return E_FAIL;
 }
index 6e3a178..ba86862 100644 (file)
@@ -93,5 +93,5 @@ public:
     END_COM_MAP()
 
     HRESULT DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HKEY hkeyFonts);
-    HRESULT DoGetFontTitle(LPCWSTR pszFontPath, LPCWSTR pszFontName);
+    HRESULT DoGetFontTitle(IN LPCWSTR pszFontPath, OUT CStringW& strFontName);
 };
index 9abdbef..5826d4e 100644 (file)
@@ -2,6 +2,10 @@
 #ifndef _UNDOCGDI_H
 #define _UNDOCGDI_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define DS_TILE 0x2
 #define DS_TRANSPARENTALPHA 0x4
 #define DS_TRANSPARENTCLR 0x8
@@ -26,19 +30,27 @@ typedef struct GDI_DRAW_STREAM_TAG
     DWORD   crTransparent; // transparent color.
 } GDI_DRAW_STREAM, *PGDI_DRAW_STREAM;
 
-BOOL
-WINAPI
-GdiDrawStream(HDC dc, ULONG l, PGDI_DRAW_STREAM pDS);
+BOOL WINAPI GdiDrawStream(HDC dc, ULONG l, PGDI_DRAW_STREAM pDS);
 
-BOOL
-WINAPI
+BOOL WINAPI
 GetTextExtentExPointWPri(
     HDC hdc,
-    LPCWSTR lpwsz, 
+    LPCWSTR lpwsz,
     INT cwc,
-    INT dxMax, 
-    LPINT pcCh, 
-    LPINT pdxOut, 
+    INT dxMax,
+    LPINT pcCh,
+    LPINT pdxOut,
     LPSIZE psize);
 
-#endif
\ No newline at end of file
+BOOL WINAPI
+GetFontResourceInfoW(
+    _In_z_ LPCWSTR lpFileName,
+    _Inout_ DWORD *pdwBufSize,
+    _Out_writes_to_opt_(*pdwBufSize, 1) PVOID lpBuffer,
+    _In_ DWORD dwType);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif