Question on use of TextMetricsW

James McKenzie jjmckenzie51 at earthlink.net
Sun Oct 3 13:44:05 CDT 2010


  All:

I am running code like the following in a richedit control to set the 
font to Courier 12 point font:


+    static const WCHAR courier[] = {'C','o','u','r','i','e','r',0};
+    testFont1 = CreateFontW (12,0,0,0,FW_LIGHT, 0, 0, 0, ANSI_CHARSET,
+        OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, 
DEFAULT_PITCH |
+        FF_DONTCARE, courier);
+
+    /*Set test font to be Courier font */
+    SendMessageW(hwndRichEdit, WM_SETFONT, (WPARAM)testFont1, 
MAKELPARAM(TRUE, 0));
+    /*Verify font is set */
+    SendMessageW(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) 
&CharFont1Unicode);
+    GetObjectW(testFont1, sizeof(LOGFONTW), &sentLogFont);
+    ok (!lstrcmpW(sentLogFont.lfFaceName, CharFont1Unicode.szFaceName), 
"WM_SETFONT set wrong font. " \
+         "Font was set to %s or %s, was supposed to be \"Courier\".\n", 
wine_dbgstr_w(CharFont1Unicode.szFaceName), 
wine_dbgstr_w(sentLogFont.lfFaceName));
+
+    ret = GetTextMetricsW (hdc, &tmw);
+    ok (ret, "GetTextMetricsW failed\n");
+
+    ok (7 == tmw.tmAveCharWidth, "Average Character Width for Courier 
12 is %d\n", tmw.tmAveCharWidth);

I also set the font to MS Sans Serif, and two different font sizes for 
Arial.  However, the tmAveCharWidth value remains at 7 and I am of the 
opinion that this should change for each font change and also for the 
font size change.  Am I doing something improper?  Should I clear the 
tmw structure between calls to GetTextMetricsW?

When I run this on native WindowsXP (which I have access to) the average 
character width changes to 9, but remains the same for all four font types.
TTIA.

James McKenzie




More information about the wine-devel mailing list