[PATCH 6/7] Implement CreateScalableFontResource

Jeremy White jwhite at codeweavers.com
Wed Apr 23 23:27:00 CDT 2008


---
 dlls/gdi32/font.c |   91 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 88 insertions(+), 3 deletions(-)

diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index 61aae1d..6f6911c 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -2633,10 +2633,24 @@ BOOL WINAPI CreateScalableFontResourceW( DWORD fHidden,
                                              LPCWSTR lpszCurrentPath )
 {
     HANDLE f;
-    FIXME("(%d,%s,%s,%s): stub\n",
+    LPSTR unix_filename = NULL;
+    LPWSTR wide_path = NULL;
+    LPWSTR full_path = NULL;
+    LPWSTR name_to_write = NULL;
+    LPSTR ansi_path = NULL;
+    FONTDIR16 fontdir;
+    WCHAR backslash[] = {'\\', 0};
+    int len;
+    int rc;
+    BOOL ret = FALSE;
+
+    TRACE("(%d,%s,%s,%s):\n",
           fHidden, debugstr_w(lpszResourceFile), debugstr_w(lpszFontFile),
           debugstr_w(lpszCurrentPath) );

+    if (fHidden)
+        WARN("fHidden not supported by CreateScalableFontResource\n");
+
     /* fHidden=1 - only visible for the calling app, read-only, not
      * enumerated with EnumFonts/EnumFontFamilies
      * lpszCurrentPath can be NULL
@@ -2646,9 +2660,80 @@ BOOL WINAPI CreateScalableFontResourceW( DWORD fHidden,
     if ((f = CreateFileW(lpszResourceFile, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)) != INVALID_HANDLE_VALUE) {
         CloseHandle(f);
         SetLastError(ERROR_FILE_EXISTS);
-        return FALSE;
+        TRACE("Error: %s file exists\n", debugstr_w(lpszResourceFile));
+        goto exit;
+    }
+
+    if (lpszCurrentPath)
+        len = strlenW(lpszCurrentPath) + 2;
+    else
+        len = 0;
+    len += strlenW(lpszFontFile) + 1;
+    wide_path = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+    if (lpszCurrentPath)
+    {
+        strcpyW(wide_path, lpszCurrentPath);
+        strcatW(wide_path, backslash);
+        strcatW(wide_path, lpszFontFile);
+    }
+    else
+        strcpyW(wide_path, lpszFontFile);
+
+    unix_filename = wine_get_unix_file_name(wide_path);
+    if (! unix_filename)
+    {
+        TRACE("Error: %s file has no Unix filename\n", debugstr_w(wide_path));
+        SetLastError(ERROR_INVALID_PARAMETER);
+        goto exit;
+    }
+
+    rc = WineEngLoadScalableFontdir(unix_filename, &fontdir);
+    if (rc == 0)
+    {
+        TRACE("Error: could not load FONTDIR from %s\n", unix_filename);
+        SetLastError(ERROR_INVALID_PARAMETER);
+        goto exit;
     }
-    return FALSE; /* create failed */
+
+    len = GetFullPathNameW(wide_path, 0, NULL, NULL);
+    if (len == 0)
+    {
+        TRACE("Error: could not get full path name of %s\n", debugstr_w(wide_path));
+        SetLastError(ERROR_INVALID_PARAMETER);
+        goto exit;
+    }
+    full_path = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
+    memset(full_path, 0, (len + 1) * sizeof(WCHAR));
+    len = GetFullPathNameW(wide_path, len + 1, full_path, &name_to_write);
+
+    if (! lpszCurrentPath)
+        name_to_write = full_path;
+
+    len = WideCharToMultiByte(CP_ACP, 0, name_to_write, -1, NULL, 0, NULL, NULL);
+    ansi_path = HeapAlloc(GetProcessHeap(), 0, len );
+    WideCharToMultiByte(CP_ACP, 0, name_to_write, -1, ansi_path, len, NULL, NULL);
+
+    rc = FONT_WriteScalableFont(lpszResourceFile, &fontdir, ansi_path);
+    if (rc)
+    {
+        TRACE("Error writing scalable font to %s\n", debugstr_w(lpszResourceFile));
+        SetLastError(ERROR_INVALID_PARAMETER);
+        goto exit;
+    }
+
+    ret = TRUE;
+
+exit:
+    if (ansi_path)
+        HeapFree(GetProcessHeap(), 0, ansi_path);
+    if (full_path)
+        HeapFree(GetProcessHeap(), 0, full_path);
+    if (unix_filename)
+        HeapFree(GetProcessHeap(), 0, unix_filename);
+    if (wide_path)
+        HeapFree(GetProcessHeap(), 0, wide_path);
+
+    return ret;
 }

 /*************************************************************************



More information about the wine-patches mailing list