The horizontal dialog base unit is calculated as the straight average
of a-z,A-Z (tmAveCharWidth is supposed to be a weighted average according to character usage, so we shouldn't use this).
This commit is contained in:
parent
ee77955a6c
commit
79fdd847e0
|
@ -150,37 +150,35 @@ BOOL DIALOG_DisableOwner( HWND hOwner )
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* DIALOG_GetCharSizeFromDC
|
* DIALOG_GetCharSizeFromDC
|
||||||
*
|
*
|
||||||
*
|
* Despite most of MSDN insisting that the horizontal base unit is
|
||||||
* Calculates the *true* average size of English characters in the
|
* tmAveCharWidth it isn't. Knowledge base article Q145994
|
||||||
* specified font as oppposed to the one returned by GetTextMetrics.
|
* "HOWTO: Calculate Dialog Units When Not Using the System Font",
|
||||||
*
|
* says that we should take the average of the 52 English upper and lower
|
||||||
* Latest: the X font driver will now compute a proper average width
|
* case characters.
|
||||||
* 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 )
|
||||||
{
|
{
|
||||||
BOOL Success = FALSE;
|
|
||||||
HFONT hFontPrev = 0;
|
HFONT hFontPrev = 0;
|
||||||
|
char *alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
SIZE sz;
|
||||||
|
TEXTMETRICA tm;
|
||||||
|
|
||||||
pSize->cx = xBaseUnit;
|
pSize->cx = xBaseUnit;
|
||||||
pSize->cy = yBaseUnit;
|
pSize->cy = yBaseUnit;
|
||||||
if ( hDC )
|
|
||||||
{
|
if(!hDC) return FALSE;
|
||||||
/* select the font */
|
|
||||||
TEXTMETRICA tm;
|
if(hFont) hFontPrev = SelectFont(hDC, hFont);
|
||||||
memset(&tm,0,sizeof(tm));
|
if(!GetTextMetricsA(hDC, &tm)) return FALSE;
|
||||||
if (hFont) hFontPrev = SelectFont(hDC,hFont);
|
if(!GetTextExtentPointA(hDC, alphabet, 52, &sz)) return FALSE;
|
||||||
if ((Success = GetTextMetricsA(hDC,&tm)))
|
|
||||||
{
|
pSize->cy = tm.tmHeight;
|
||||||
pSize->cx = tm.tmAveCharWidth;
|
pSize->cx = (sz.cx / 26 + 1) / 2;
|
||||||
pSize->cy = tm.tmHeight;
|
|
||||||
TRACE("Using tm: %ldx%ld (dlg: %ld x %ld) (%s)\n",
|
if (hFontPrev) SelectFont(hDC, hFontPrev);
|
||||||
tm.tmAveCharWidth, tm.tmHeight, pSize->cx, pSize->cy,
|
|
||||||
tm.tmPitchAndFamily & TMPF_FIXED_PITCH ? "variable" : "fixed");
|
TRACE("dlg base units: %ld x %ld\n", pSize->cx, pSize->cy);
|
||||||
}
|
return TRUE;
|
||||||
/* select the original font */
|
|
||||||
if (hFontPrev) SelectFont(hDC,hFontPrev);
|
|
||||||
}
|
|
||||||
return (Success);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
@ -731,19 +729,13 @@ static 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 */
|
/* We convert the size to pixels and then make it -ve. This works
|
||||||
/* and must be converted to pixels first */
|
* for both +ve and -ve template.pointSize */
|
||||||
/* (see CreateFont() documentation in the Windows SDK). */
|
|
||||||
HDC dc;
|
HDC dc;
|
||||||
int pixels;
|
int pixels;
|
||||||
if (((short)template.pointSize) < 0)
|
dc = GetDC(0);
|
||||||
pixels = -((short)template.pointSize);
|
pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
|
||||||
else
|
ReleaseDC(0, dc);
|
||||||
{
|
|
||||||
dc = GetDC(0);
|
|
||||||
pixels = template.pointSize * GetDeviceCaps(dc , LOGPIXELSY)/72;
|
|
||||||
ReleaseDC(0, dc);
|
|
||||||
}
|
|
||||||
if (win32Template)
|
if (win32Template)
|
||||||
dlgInfo->hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
|
dlgInfo->hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
|
||||||
template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
|
template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
|
||||||
|
|
Loading…
Reference in New Issue