Make ChooseFontW use ChooseFontA

Ian Pilcher ian.pilcher at home.com
Sun Jun 10 15:30:32 CDT 2001


ChooseFontW was not returning the iPointSize member, and possibly
others.  This patch rewrites ChooseFontW to convert all its inputs to
ASCII, call ChooseFontA, and convert the outputs back to Unicode.

Modified files:
     dlls/commdlg: fontdlg.c

Log message:
     Ian Pilcher
     Make ChooseFontW use ChooseFontA
-- 
========================================================================
Ian Pilcher                                         ian.pilcher at home.com
========================================================================
-------------- next part --------------
diff -urN ../wine-20010606cvs/dlls/commdlg/fontdlg.c ./dlls/commdlg/fontdlg.c
--- ../wine-20010606cvs/dlls/commdlg/fontdlg.c	Mon May  7 13:16:17 2001
+++ ./dlls/commdlg/fontdlg.c	Sat Jun  9 12:17:45 2001
@@ -270,6 +270,117 @@
 
 /***********************************************************************
  *           ChooseFontW   (COMDLG32.4)
+ *
+ *  NOTES:
+ *
+ *  	The LOGFONT conversion functions will break if the structure ever
+ *  	grows beyond the lfFaceName element.
+ *
+ *  	The CHOOSEFONT conversion functions assume that both versions of
+ *  	lpLogFont and lpszStyle (if used) point to pre-allocated objects.
+ *
+ *  	The ASCII version of lpTemplateName is created by ChooseFontAtoW
+ *  	and freed by ChooseFontWtoA.
+ */
+inline static VOID LogFontWtoA(const LOGFONTW *lfw, LOGFONTA *lfa)
+{
+    memcpy(lfa, lfw, sizeof(LOGFONTA));
+    WideCharToMultiByte(CP_ACP, 0, lfw->lfFaceName, -1, lfa->lfFaceName,
+    	    LF_FACESIZE, NULL, NULL);
+    lfa->lfFaceName[LF_FACESIZE - 1] = '\0';
+}
+
+inline static VOID LogFontAtoW(const LOGFONTA *lfa, LOGFONTW *lfw)
+{
+    memcpy(lfw, lfa, sizeof(LOGFONTA));
+    MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw->lfFaceName,
+    	    LF_FACESIZE);
+    lfw->lfFaceName[LF_FACESIZE - 1] = 0;
+}
+
+static BOOL ChooseFontWtoA(const CHOOSEFONTW *cfw, CHOOSEFONTA *cfa)
+{
+    LOGFONTA	*lpLogFont = cfa->lpLogFont;
+    LPSTR   	lpszStyle = cfa->lpszStyle;
+
+    memcpy(cfa, cfw, sizeof(CHOOSEFONTA));
+    cfa->lpLogFont = lpLogFont;
+    cfa->lpszStyle = lpszStyle;
+    
+    LogFontWtoA(cfw->lpLogFont, lpLogFont);
+    
+    if (cfw->lpTemplateName != NULL)
+    {
+    	cfa->lpTemplateName = HEAP_strdupWtoA(GetProcessHeap(), 0,
+    	    	cfw->lpTemplateName);
+    	if (cfa->lpTemplateName == NULL)
+    	    return FALSE;
+    }
+	
+    if ((cfw->Flags & CF_USESTYLE) != 0 && cfw->lpszStyle != NULL)
+    {
+    	WideCharToMultiByte(CP_ACP, 0, cfw->lpszStyle, -1, cfa->lpszStyle,
+    	    	LF_FACESIZE, NULL, NULL);
+    	cfa->lpszStyle[LF_FACESIZE - 1] = '\0';
+    }
+    
+    return TRUE;
+}
+
+static VOID ChooseFontAtoW(const CHOOSEFONTA *cfa, CHOOSEFONTW *cfw)
+{
+    LOGFONTW	*lpLogFont = cfw->lpLogFont;
+    LPWSTR  	lpszStyle = cfw->lpszStyle;
+    LPCWSTR 	lpTemplateName = cfw->lpTemplateName;
+
+    memcpy(cfw, cfa, sizeof(CHOOSEFONTA));
+    cfw->lpLogFont = lpLogFont;
+    cfw->lpszStyle = lpszStyle;
+    cfw->lpTemplateName = lpTemplateName;
+    
+    LogFontAtoW(cfa->lpLogFont, lpLogFont);
+    
+    if (cfa->lpTemplateName != NULL)
+    	HeapFree(GetProcessHeap(), 0, (LPSTR)(cfa->lpTemplateName));
+    
+    if ((cfa->Flags & CF_USESTYLE) != 0 && cfa->lpszStyle != NULL)
+    {
+    	MultiByteToWideChar(CP_ACP, 0, cfa->lpszStyle, -1, cfw->lpszStyle,
+	    	LF_FACESIZE);
+	cfw->lpszStyle[LF_FACESIZE - 1] = 0;
+    }
+}
+
+BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
+{
+    CHOOSEFONTA     cf_a;
+    LOGFONTA	    lf_a;
+    CHAR    	    style_a[LF_FACESIZE];
+    
+    cf_a.lpLogFont = &lf_a;
+    cf_a.lpszStyle = style_a;
+    
+    if (ChooseFontWtoA(lpChFont, &cf_a) == FALSE)
+    {
+    	COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
+	return FALSE;
+    }
+    
+    if (ChooseFontA(&cf_a) == FALSE)
+    {
+    	if (cf_a.lpTemplateName != NULL)
+    	    HeapFree(GetProcessHeap(), 0, (LPSTR)(cf_a.lpTemplateName));
+	return FALSE;
+    }
+    
+    ChooseFontAtoW(&cf_a, lpChFont);
+    
+    return TRUE;
+}
+
+#if 0
+/***********************************************************************
+ *           ChooseFontW   (COMDLG32.4)
  */
 BOOL WINAPI ChooseFontW(LPCHOOSEFONTW lpChFont)
 {
@@ -315,7 +426,7 @@
   lpChFont->lpLogFont->lfFaceName[LF_FACESIZE-1] = 0;
   return bRet;
 }
-
+#endif
 
 #define TEXT_EXTRAS 4
 #define TEXT_COLORS 16


More information about the wine-patches mailing list