Commit 0ded0fe3 authored by Richard Cohen's avatar Richard Cohen Committed by Alexandre Julliard

No longer needs to calculate its own character size.

parent c397a841
...@@ -74,13 +74,15 @@ typedef struct ...@@ -74,13 +74,15 @@ typedef struct
/* Dialog base units */ /* Dialog base units */
static WORD xBaseUnit = 0, yBaseUnit = 0; static WORD xBaseUnit = 0, yBaseUnit = 0;
/*********************************************************************** /***********************************************************************
* DIALOG_GetCharSizeFromDC * DIALOG_GetCharSizeFromDC
* *
* *
* Calculates the *true* average size of English characters in the * Calculates the *true* average size of English characters in the
* specified font as oppposed to the one returned by GetTextMetrics. * specified font as oppposed to the one returned by GetTextMetrics.
*
* Latest: the X font driver will now compute a proper average width
* so this code can be removed
*/ */
static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize ) static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize )
{ {
...@@ -103,7 +105,7 @@ static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize ) ...@@ -103,7 +105,7 @@ static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize )
if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH) if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
{ {
SIZE total; SIZE total;
static const char szAvgChars[52] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; const char* szAvgChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
/* Calculate a true average as opposed to the one returned /* Calculate a true average as opposed to the one returned
* by tmAveCharWidth. This works better when dealing with * by tmAveCharWidth. This works better when dealing with
...@@ -122,21 +124,21 @@ static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize ) ...@@ -122,21 +124,21 @@ static BOOL DIALOG_GetCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize )
{ {
Success = TRUE; Success = TRUE;
} }
/* Use the text metrics */
TRACE("Using tm: %ldx%ld (dlg: %dx%d) (%s)\n", tm.tmAveCharWidth, tm.tmHeight, pSize->cx, pSize->cy,
tm.tmPitchAndFamily & TMPF_FIXED_PITCH ? "variable" : "fixed");
pSize->cx = tm.tmAveCharWidth;
pSize->cy = tm.tmHeight;
} }
/* select the original font */ /* select the original font */
if (hFontPrev) SelectFont(hDC,hFontPrev); if (hFontPrev) SelectFont(hDC,hFontPrev);
} }
return (Success); return (Success);
} }
/*********************************************************************** /***********************************************************************
* DIALOG_GetCharSize * DIALOG_GetCharSize
* *
*
* Calculates the *true* average size of English characters in the
* specified font as oppposed to the one returned by GetTextMetrics.
* A convenient variant of DIALOG_GetCharSizeFromDC. * A convenient variant of DIALOG_GetCharSizeFromDC.
*/ */
static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize ) static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize )
...@@ -147,7 +149,6 @@ static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize ) ...@@ -147,7 +149,6 @@ static BOOL DIALOG_GetCharSize( HFONT hFont, SIZE * pSize )
return Success; return Success;
} }
/*********************************************************************** /***********************************************************************
* DIALOG_Init * DIALOG_Init
* *
...@@ -652,17 +653,23 @@ HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate, ...@@ -652,17 +653,23 @@ HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
if (template.style & DS_SETFONT) if (template.style & DS_SETFONT)
{ {
/* The font height must be negative as it is a point size */ /* The font height must be negative as it is a point size */
/* and must be converted to pixels first */
/* (see CreateFont() documentation in the Windows SDK). */ /* (see CreateFont() documentation in the Windows SDK). */
HDC dc = GetDC(0);
int pixels = template.pointSize * GetDeviceCaps(dc , LOGPIXELSY)/72;
ReleaseDC(0, dc);
if (win32Template) if (win32Template)
hFont = CreateFontW( -template.pointSize, 0, 0, 0, hFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
template.weight, template.italic, FALSE, template.italic, FALSE, FALSE,
FALSE, DEFAULT_CHARSET, 0, 0, PROOF_QUALITY, DEFAULT_CHARSET, 0, 0,
FF_DONTCARE, (LPCWSTR)template.faceName ); PROOF_QUALITY, FF_DONTCARE,
(LPCWSTR)template.faceName );
else else
hFont = CreateFont16( -template.pointSize, 0, 0, 0, FW_DONTCARE, hFont = CreateFont16( -pixels, 0, 0, 0, FW_DONTCARE,
FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0, FALSE, FALSE, FALSE,
DEFAULT_CHARSET, 0, 0,
PROOF_QUALITY, FF_DONTCARE, PROOF_QUALITY, FF_DONTCARE,
template.faceName ); template.faceName );
if (hFont) if (hFont)
...@@ -672,6 +679,7 @@ HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate, ...@@ -672,6 +679,7 @@ HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
xUnit = charSize.cx; xUnit = charSize.cx;
yUnit = charSize.cy; yUnit = charSize.cy;
} }
TRACE("units = %d,%d\n", xUnit, yUnit );
} }
/* Create dialog main window */ /* Create dialog main window */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment