[FONTEXT] Initial implementation of CFontExt::DoGetFontTitle (#3127)

This PR is a preparation of fonts folder implementation. CORE-12861
This commit is contained in:
Katayama Hirofumi MZ 2020-09-12 09:40:48 +09:00 committed by GitHub
parent ee69ca786a
commit 183e1eb71b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 21 deletions

View file

@ -7,6 +7,7 @@
*/ */
#include "precomp.h" #include "precomp.h"
#include "undocgdi.h" // for GetFontResourceInfoW
WINE_DEFAULT_DEBUG_CHANNEL(fontext); WINE_DEFAULT_DEBUG_CHANNEL(fontext);
@ -454,12 +455,8 @@ STDMETHODIMP CFontExt::DragEnter(IDataObject* pDataObj, DWORD grfKeyState, POINT
if (FAILED_UNEXPECTEDLY(hr)) if (FAILED_UNEXPECTEDLY(hr))
return hr; return hr;
#if 1 // Please implement DoGetFontTitle
return DRAGDROP_S_CANCEL;
#else
*pdwEffect = DROPEFFECT_COPY; *pdwEffect = DROPEFFECT_COPY;
return S_OK; return S_OK;
#endif
} }
STDMETHODIMP CFontExt::DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) 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]; WCHAR szDestFile[MAX_PATH];
LPCWSTR pszFileTitle = PathFindFileName(pszFontPath); LPCWSTR pszFileTitle = PathFindFileName(pszFontPath);
WCHAR szFontName[512]; CStringW strFontName;
if (!DoGetFontTitle(pszFontPath, szFontName)) if (!DoGetFontTitle(pszFontPath, strFontName))
return E_FAIL; return E_FAIL;
RemoveFontResourceW(pszFileTitle); RemoveFontResourceW(pszFileTitle);
@ -581,7 +578,7 @@ HRESULT CFontExt::DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HK
return E_FAIL; return E_FAIL;
} }
if (!AddFontResourceW(pszFileTitle)) if (!AddFontResourceW(szDestFile))
{ {
ERR("AddFontResourceW('%S') failed\n", pszFileTitle); ERR("AddFontResourceW('%S') failed\n", pszFileTitle);
DeleteFileW(szDestFile); DeleteFileW(szDestFile);
@ -589,7 +586,8 @@ HRESULT CFontExt::DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HK
} }
DWORD cbData = (wcslen(pszFileTitle) + 1) * sizeof(WCHAR); 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) if (nError)
{ {
ERR("RegSetValueExW failed with %ld\n", nError); ERR("RegSetValueExW failed with %ld\n", nError);
@ -601,8 +599,26 @@ HRESULT CFontExt::DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HK
return S_OK; 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; return E_FAIL;
} }

View file

@ -93,5 +93,5 @@ public:
END_COM_MAP() END_COM_MAP()
HRESULT DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HKEY hkeyFonts); HRESULT DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HKEY hkeyFonts);
HRESULT DoGetFontTitle(LPCWSTR pszFontPath, LPCWSTR pszFontName); HRESULT DoGetFontTitle(IN LPCWSTR pszFontPath, OUT CStringW& strFontName);
}; };

View file

@ -2,6 +2,10 @@
#ifndef _UNDOCGDI_H #ifndef _UNDOCGDI_H
#define _UNDOCGDI_H #define _UNDOCGDI_H
#ifdef __cplusplus
extern "C" {
#endif
#define DS_TILE 0x2 #define DS_TILE 0x2
#define DS_TRANSPARENTALPHA 0x4 #define DS_TRANSPARENTALPHA 0x4
#define DS_TRANSPARENTCLR 0x8 #define DS_TRANSPARENTCLR 0x8
@ -26,19 +30,27 @@ typedef struct GDI_DRAW_STREAM_TAG
DWORD crTransparent; // transparent color. DWORD crTransparent; // transparent color.
} GDI_DRAW_STREAM, *PGDI_DRAW_STREAM; } GDI_DRAW_STREAM, *PGDI_DRAW_STREAM;
BOOL BOOL WINAPI GdiDrawStream(HDC dc, ULONG l, PGDI_DRAW_STREAM pDS);
WINAPI
GdiDrawStream(HDC dc, ULONG l, PGDI_DRAW_STREAM pDS);
BOOL BOOL WINAPI
WINAPI
GetTextExtentExPointWPri( GetTextExtentExPointWPri(
HDC hdc, HDC hdc,
LPCWSTR lpwsz, LPCWSTR lpwsz,
INT cwc, INT cwc,
INT dxMax, INT dxMax,
LPINT pcCh, LPINT pcCh,
LPINT pdxOut, LPINT pdxOut,
LPSIZE psize); LPSIZE psize);
#endif 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