Index: win32ss/gdi/gdi32/objects/font.c =================================================================== --- win32ss/gdi/gdi32/objects/font.c (revision 67342) +++ win32ss/gdi/gdi32/objects/font.c (working copy) @@ -10,6 +10,7 @@ #include #include +#include #define NDEBUG #include @@ -2181,7 +2182,7 @@ } /* - * @unimplemented + * @implemented */ int WINAPI @@ -2189,8 +2190,50 @@ LPCWSTR lpszFilename, FLONG fl, DESIGNVECTOR *pdv) -{ - return NtGdiAddFontResourceW((PWSTR)lpszFilename, 0, 0, fl, 0, pdv); +{ + INT Ret; + WCHAR lpszBuffer[MAX_PATH]; + WCHAR lpszWinDir[MAX_PATH]; + + WCHAR lpszAbsPath[MAX_PATH]; + UNICODE_STRING NtAbsPath; + + /* Initialize unicode string*/ + RtlInitUnicodeString(&NtAbsPath, NULL); + + /* Does the file exist in CurrentDirectory or in the Absolute Path passed? */ + GetCurrentDirectoryW(MAX_PATH, lpszBuffer); + + if (!SearchPathW(lpszBuffer, lpszFilename, NULL, MAX_PATH, lpszAbsPath, NULL)) + { + // Nope. Then let's check Fonts folder + GetWindowsDirectoryW(lpszWinDir, MAX_PATH); + StringCbCatW(lpszWinDir, sizeof(lpszWinDir), L"\\Fonts"); + + if (!SearchPathW(lpszWinDir, lpszFilename, NULL, MAX_PATH, lpszAbsPath, NULL)) + { + DPRINT1("Font not found. The Buffer is: %S, the FileName is: %S", lpszBuffer, lpszFilename); + return 0; + } + } + + //We found the font file so: + if (!RtlDosPathNameToNtPathName_U(lpszAbsPath, &NtAbsPath, NULL, NULL)) + { + DPRINT1("Can't convert Path! Path: %S , Error code: 0x%lx\n", lpszAbsPath, GetLastError()); + return 0; + } + + ASSERT(NtAbsPath.Buffer[NtAbsPath.Length / sizeof(WCHAR)] == UNICODE_NULL); + + // The Nt call expects a null-terminator included in Cwc param. + //FIXME: We don't support multiple files passed in lpszFilename as L"abcxxxxx.pfm | abcxxxxx.pfb" + + Ret = NtGdiAddFontResourceW(NtAbsPath.Buffer, NtAbsPath.Length/sizeof(WCHAR) + 1, 1, fl, 0, pdv); + + RtlFreeUnicodeString(&NtAbsPath); + + return Ret; } /* Index: win32ss/gdi/ntgdi/font.c =================================================================== --- win32ss/gdi/ntgdi/font.c (revision 67342) +++ win32ss/gdi/ntgdi/font.c (working copy) @@ -427,7 +427,7 @@ INT APIENTRY NtGdiAddFontResourceW( - IN WCHAR *pwszFiles, + IN WCHAR *pwcFiles, IN ULONG cwc, IN ULONG cFiles, IN FLONG fl, @@ -435,19 +435,13 @@ IN OPTIONAL DESIGNVECTOR *pdv) { UNICODE_STRING SafeFileName; - PWSTR src; - NTSTATUS Status; - int Ret; + INT Ret; - /* FIXME: Protect with SEH? */ - RtlInitUnicodeString(&SafeFileName, pwszFiles); + //Cwc = Length + trailing zero. + SafeFileName.Length = (cwc - 1) * sizeof(WCHAR); + SafeFileName.MaximumLength = (cwc - 1) * sizeof(WCHAR); + SafeFileName.Buffer = ExAllocatePoolWithTag(PagedPool, SafeFileName.Length, TAG_STRING); - /* Reserve for prepending '\??\' */ - SafeFileName.Length += 4 * sizeof(WCHAR); - SafeFileName.MaximumLength += 4 * sizeof(WCHAR); - - src = SafeFileName.Buffer; - SafeFileName.Buffer = (PWSTR)ExAllocatePoolWithTag(PagedPool, SafeFileName.MaximumLength, TAG_STRING); if(!SafeFileName.Buffer) { EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); @@ -454,16 +448,17 @@ return 0; } - /* Prepend '\??\' */ - RtlCopyMemory(SafeFileName.Buffer, L"\\??\\", 4 * sizeof(WCHAR)); - - Status = MmCopyFromCaller(SafeFileName.Buffer + 4, src, SafeFileName.MaximumLength - (4 * sizeof(WCHAR))); - if(!NT_SUCCESS(Status)) + _SEH2_TRY + { + ProbeForRead(pwcFiles, (cwc - 1) * sizeof(WCHAR), sizeof(WCHAR)); + RtlCopyMemory(SafeFileName.Buffer, pwcFiles, (cwc - 1) * sizeof(WCHAR)); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - ExFreePoolWithTag(SafeFileName.Buffer, TAG_STRING); - SetLastNtError(Status); - return 0; + /* Return 0 */ + _SEH2_YIELD(return 0); } + _SEH2_END; Ret = IntGdiAddFontResource(&SafeFileName, (DWORD)fl);