Do conversions between the font size specified in points (or

decipoints) and height specified in logical units.
This commit is contained in:
Rein Klazes 2003-12-11 05:17:05 +00:00 committed by Alexandre Julliard
parent 32f296b6d5
commit 965b285238
3 changed files with 168 additions and 134 deletions

View File

@ -524,16 +524,38 @@ static int SetFontSizesToCombo3(HWND hwnd, LPCHOOSEFONTA lpcf)
return 0;
}
/*************************************************************************
* CFn_GetDC [internal]
*/
inline HDC CFn_GetDC(LPCHOOSEFONTA lpcf)
{
HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ?
lpcf->hDC :
GetDC(0);
if(!ret) ERR("HDC failure!!!\n");
return ret;
}
/*************************************************************************
* CFn_ReleaseDC [internal]
*/
inline void CFn_ReleaseDC(LPCHOOSEFONTA lpcf, HDC hdc)
{
if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
ReleaseDC(0, hdc);
}
/***********************************************************************
* AddFontStyle [internal]
*/
INT AddFontStyle( const ENUMLOGFONTEXA *lpElfex, UINT nFontType,
LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3, HWND hDlg,
BOOL iswin16)
INT AddFontStyle( const ENUMLOGFONTEXA *lpElfex, const TEXTMETRICA *lpTM,
UINT nFontType, LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3,
HWND hDlg, BOOL iswin16)
{
int i;
const LOGFONTA *lplf = &(lpElfex->elfLogFont);
HWND hcmb5;
HDC hdc;
TRACE("(nFontType=%d)\n",nFontType);
TRACE(" %s h=%ld w=%ld e=%ld o=%ld wg=%ld i=%d u=%d s=%d"
@ -545,15 +567,20 @@ INT AddFontStyle( const ENUMLOGFONTEXA *lpElfex, UINT nFontType,
lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
if (nFontType & RASTER_FONTTYPE)
{
if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
INT points;
if(!(hdc = CFn_GetDC(lpcf))) return 0;
points = MulDiv( lpTM->tmHeight - lpTM->tmInternalLeading, 72,
GetDeviceCaps(hdc, LOGPIXELSY));
CFn_ReleaseDC(lpcf, hdc);
i = AddFontSizeToCombo3(hcmb3, points, lpcf);
if( i) return 0;
} else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
if (!SendMessageA(hcmb2, CB_GETCOUNT, 0, 0))
{
HDC hdc= ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
if(!(hdc = CFn_GetDC(lpcf))) return 0;
i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
ReleaseDC(hDlg,hdc);
CFn_ReleaseDC(lpcf, hdc);
if (i)
return 0;
}
@ -645,7 +672,7 @@ static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXA *lpElfex,
HWND hcmb2=s->hWnd1;
HWND hcmb3=s->hWnd2;
HWND hDlg=GetParent(hcmb3);
return AddFontStyle( lpElfex, dwFontType, s->lpcf32a,
return AddFontStyle( lpElfex, metrics, dwFontType, s->lpcf32a,
hcmb2, hcmb3, hDlg, FALSE);
}
@ -658,6 +685,7 @@ LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
HDC hdc;
int i,j,init=0;
long pstyle;
CFn_ENUMSTRUCT s;
LPLOGFONTA lpxx;
HCURSOR hcursor=SetCursor(LoadCursorA(0,(LPSTR)IDC_WAIT));
@ -704,10 +732,11 @@ LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
}
hdc= ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
if (hdc)
if(!(hdc = CFn_GetDC(lpcf)))
{
CFn_ENUMSTRUCT s;
EndDialog (hDlg, 0);
return FALSE;
}
s.hWnd1=GetDlgItem(hDlg,cmb1);
s.lpcf32a=lpcf;
do {
@ -739,7 +768,9 @@ LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
{
INT height = lpxx->lfHeight < 0 ? -lpxx->lfHeight :
lpxx->lfHeight;
INT points;
int charset = lpxx->lfCharSet;
points = MulDiv( height, 72, GetDeviceCaps(hdc, LOGPIXELSY));
pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
FW_NORMAL,lpxx->lfItalic !=0);
SendDlgItemMessageA(hDlg, cmb1, CB_SETCURSEL, j, 0);
@ -749,7 +780,7 @@ LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
/* look for fitting font style in combobox2 */
CFn_FitFontStyle(hDlg, pstyle);
/* look for fitting font size in combobox3 */
CFn_FitFontSize(hDlg, height);
CFn_FitFontSize(hDlg, points);
CFn_FitCharSet( hDlg, charset );
}
}
@ -769,16 +800,7 @@ LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
MAKELONG(HWND_16(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
}
}
}
else
{
WARN("HDC failure !!!\n");
EndDialog (hDlg, 0);
return FALSE;
}
if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
ReleaseDC(hDlg,hdc);
CFn_ReleaseDC(lpcf, hdc);
SetCursor(hcursor);
return TRUE;
}
@ -918,14 +940,16 @@ LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
{
case cmb1:
if (HIWORD(wParam)==CBN_SELCHANGE)
{
hdc=((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
if (hdc)
{
INT pointsize; /* save current pointsize */
LONG pstyle; /* save current style */
int charset;
int idx;
if(!(hdc = CFn_GetDC(lpcf)))
{
EndDialog (hDlg, 0);
return TRUE;
}
idx = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
pointsize = (int)SendDlgItemMessageA( hDlg, cmb3, CB_GETITEMDATA,
idx, 0);
@ -958,15 +982,7 @@ LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
if( charset != CB_ERR) CFn_FitCharSet( hDlg, charset );
SetCursor(hcursor);
}
if (!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
ReleaseDC(hDlg,hdc);
}
else
{
WARN("HDC failure !!!\n");
EndDialog (hDlg, 0);
return TRUE;
}
CFn_ReleaseDC(lpcf, hdc);
}
case chx1:
case chx2:
@ -1007,9 +1023,18 @@ LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
}
i=SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
if( i != CB_ERR)
lpxx->lfHeight=-LOWORD(SendDlgItemMessageA(hDlg, cmb3, CB_GETITEMDATA, i, 0));
lpcf->iPointSize = 10 * LOWORD(SendDlgItemMessageA(hDlg, cmb3,
CB_GETITEMDATA , i, 0));
else
lpxx->lfHeight=0;
lpcf->iPointSize = 100;
hdc = CFn_GetDC(lpcf);
if( hdc)
{
lpxx->lfHeight = - MulDiv( lpcf->iPointSize ,
GetDeviceCaps(hdc, LOGPIXELSY), 720);
CFn_ReleaseDC(lpcf, hdc);
} else
lpxx->lfHeight = -lpcf->iPointSize / 10;
i=SendDlgItemMessageA(hDlg, cmb5, CB_GETCURSEL, 0, 0);
if (i!=CB_ERR)
lpxx->lfCharSet=SendDlgItemMessageA(hDlg, cmb5, CB_GETITEMDATA, i, 0);
@ -1019,7 +1044,6 @@ LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
lpxx->lfQuality=DEFAULT_QUALITY;
lpcf->iPointSize= -10*lpxx->lfHeight;
wininfo.cbSize=sizeof(wininfo);
@ -1059,8 +1083,8 @@ LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam,
case IDOK:
if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
( (lpcf->Flags & CF_LIMITSIZE) &&
(-lpxx->lfHeight >= lpcf->nSizeMin) &&
(-lpxx->lfHeight <= lpcf->nSizeMax)))
(lpcf->iPointSize >= 10 * lpcf->nSizeMin) &&
(lpcf->iPointSize <= 10 * lpcf->nSizeMax)))
EndDialog(hDlg, TRUE);
else
{
@ -1118,7 +1142,6 @@ LRESULT CFn_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam,
info.rcWindow.bottom--;
info.rcWindow.top++;
info.rcWindow.left++;
lf.lfHeight = MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
hOrigFont = SelectObject( hdc, CreateFontIndirectA( &lf ) );
rgbPrev=SetTextColor( hdc, lpcf->rgbColors );

View File

@ -45,9 +45,9 @@ typedef struct
INT AddFontFamily(const LOGFONTA *lplf, UINT nFontType, LPCHOOSEFONTA lpcf,
HWND hwnd, LPCFn_ENUMSTRUCT e);
INT AddFontStyle(const ENUMLOGFONTEXA *lpElfex, UINT nFontType,
LPCHOOSEFONTA lpcf, HWND hcmb2,
HWND hcmb3, HWND hDlg, BOOL iswin16);
INT AddFontStyle(const ENUMLOGFONTEXA *lpElfex, const TEXTMETRICA *metrics,
UINT nFontType, LPCHOOSEFONTA lpcf, HWND hcmb2, HWND hcmb3,
HWND hDlg, BOOL iswin16);
void _dump_cf_flags(DWORD cflags);
LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,

View File

@ -59,6 +59,14 @@ static void FONT_LogFont16To32A( const LPLOGFONT16 font16, LPLOGFONTA font32 )
lstrcpynA( font32->lfFaceName, font16->lfFaceName, LF_FACESIZE );
};
static void FONT_Metrics16To32A( const TEXTMETRIC16 *pm16, TEXTMETRICA *pm32a)
{
ZeroMemory( pm32a, sizeof(TEXTMETRICA));
/* NOTE: only the fields used by AddFontStyle() are filled in */
pm32a->tmHeight = pm16->tmHeight;
pm32a->tmExternalLeading = pm16->tmExternalLeading;
};
static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONTA chf32a)
{
chf32a->lStructSize=sizeof(CHOOSEFONTA);
@ -117,10 +125,13 @@ INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
HWND hDlg=GetParent(hcmb3);
LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLongA(hDlg, DWL_USER);
LOGFONT16 *lplf = MapSL(logfont);
TEXTMETRIC16 *lpmtrx16 = MapSL(metrics);
ENUMLOGFONTEXA elf32a;
TEXTMETRICA mtrx32a;
FONT_LogFont16To32A(lplf, &(elf32a.elfLogFont));
return AddFontStyle(&elf32a, nFontType, (LPCHOOSEFONTA)lpcf->lpTemplateName,
hcmb2, hcmb3, hDlg, TRUE);
FONT_Metrics16To32A(lpmtrx16, &mtrx32a);
return AddFontStyle(&elf32a, &mtrx32a, nFontType,
(LPCHOOSEFONTA)lpcf->lpTemplateName, hcmb2, hcmb3, hDlg, TRUE);
}
/***********************************************************************