📄 fontdlg.c
字号:
if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
return 1;
if (lpcf->Flags & CF_ANSIONLY)
if (lplf->lfCharSet != ANSI_CHARSET)
return 1;
if (lpcf->Flags & CF_TTONLY)
if (!(nFontType & TRUETYPE_FONTTYPE))
return 1;
if (e) e->added++;
i=SendMessageW(hwnd, CB_FINDSTRINGEXACT, 0, (LPARAM)lplf->lfFaceName);
if (i == CB_ERR) {
i = SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)lplf->lfFaceName);
if( i != CB_ERR) {
/* store some important font information */
w = (lplf->lfPitchAndFamily) << 8 |
(HIWORD(lpNTM->ntmTm.ntmFlags) & 0xff);
SendMessageW(hwnd, CB_SETITEMDATA, i, MAKELONG(nFontType,w));
}
}
return 1;
}
/*************************************************************************
* FontFamilyEnumProc32 [internal]
*/
static INT WINAPI FontFamilyEnumProc(const ENUMLOGFONTEXW *lpElfex,
const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam)
{
LPCFn_ENUMSTRUCT e;
e=(LPCFn_ENUMSTRUCT)lParam;
return AddFontFamily( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
dwFontType, e->lpcf32w, e->hWnd1, e);
}
/*************************************************************************
* SetFontStylesToCombo2 [internal]
*
* Fill font style information into combobox (without using font.c directly)
*/
static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, const LOGFONTW *lplf)
{
#define FSTYLES 4
struct FONTSTYLE
{
int italic;
int weight;
const WCHAR *stname;
};
static const WCHAR strRegular[] = {'R','e','g','u','l','a','r',0};
static const WCHAR strItalic[] = {'I','t','a','l','i','c',0};
static const WCHAR strBold[] = {'B','o','l','d',0};
static const WCHAR strBoldItalic[] = {'B','o','l','d',' ','I','t','a','l','i','c',0};
static const struct FONTSTYLE fontstyles[FSTYLES]={
{ 0, FW_NORMAL, strRegular },
{ 1, FW_NORMAL, strItalic },
{ 0, FW_BOLD, strBold },
{ 1, FW_BOLD, strBoldItalic }
};
HFONT hf;
TEXTMETRICW tm;
int i,j;
LOGFONTW lf;
memcpy(&lf, lplf, sizeof(LOGFONTW));
for (i=0;i<FSTYLES;i++)
{
lf.lfItalic=fontstyles[i].italic;
lf.lfWeight=fontstyles[i].weight;
hf=CreateFontIndirectW(&lf);
hf=SelectObject(hdc,hf);
GetTextMetricsW(hdc,&tm);
hf=SelectObject(hdc,hf);
DeleteObject(hf);
/* font successful created ? */
if (((fontstyles[i].weight == FW_NORMAL && tm.tmWeight <= FW_MEDIUM) ||
(fontstyles[i].weight == FW_BOLD && tm.tmWeight > FW_MEDIUM)) &&
((tm.tmItalic != 0)==fontstyles[i].italic))
{
j=SendMessageW(hwnd,CB_ADDSTRING,0,(LPARAM)fontstyles[i].stname );
if (j==CB_ERR) return 1;
j=SendMessageW(hwnd, CB_SETITEMDATA, j,
MAKELONG(tm.tmWeight,fontstyles[i].italic));
if (j==CB_ERR) return 1;
}
}
return 0;
}
/*************************************************************************
* AddFontSizeToCombo3 [internal]
*/
static int AddFontSizeToCombo3(HWND hwnd, UINT h, const CHOOSEFONTW *lpcf)
{
int j;
WCHAR buffer[20];
static const WCHAR strFormat[] = {'%','2','d',0};
if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
{
wsprintfW(buffer, strFormat, h);
j=SendMessageW(hwnd, CB_FINDSTRINGEXACT, -1, (LPARAM)buffer);
if (j==CB_ERR)
{
j=SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)buffer);
if (j!=CB_ERR) j = SendMessageW(hwnd, CB_SETITEMDATA, j, h);
if (j==CB_ERR) return 1;
}
}
return 0;
}
/*************************************************************************
* SetFontSizesToCombo3 [internal]
*/
static int SetFontSizesToCombo3(HWND hwnd, const CHOOSEFONTW *lpcf)
{
static const BYTE sizes[]={6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
int i;
for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
return 0;
}
/*************************************************************************
* CFn_GetDC [internal]
*/
static inline HDC CFn_GetDC(const CHOOSEFONTW *lpcf)
{
HDC ret = ((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC) ?
lpcf->hDC :
GetDC(0);
if(!ret) ERR("HDC failure!!!\n");
return ret;
}
/*************************************************************************
* CFn_ReleaseDC [internal]
*/
static inline void CFn_ReleaseDC(const CHOOSEFONTW *lpcf, HDC hdc)
{
if(!((lpcf->Flags & CF_PRINTERFONTS) && lpcf->hDC))
ReleaseDC(0, hdc);
}
/***********************************************************************
* AddFontStyle [internal]
*/
INT AddFontStyle( const ENUMLOGFONTEXW *lpElfex, const NEWTEXTMETRICEXW *lpNTM,
UINT nFontType, const CHOOSEFONTW *lpcf, HWND hcmb2, HWND hcmb3,
HWND hDlg, BOOL iswin16)
{
int i;
const LOGFONTW *lplf = &(lpElfex->elfLogFont);
HWND hcmb5;
HDC hdc;
TRACE("(nFontType=%d)\n",nFontType);
TRACE(" %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
" ch=%d op=%d cp=%d q=%d pf=%xh\n",
debugstr_w(lplf->lfFaceName),lplf->lfHeight,lplf->lfWidth,
lplf->lfEscapement,lplf->lfOrientation,
lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
if (nFontType & RASTER_FONTTYPE)
{
INT points;
if(!(hdc = CFn_GetDC(lpcf))) return 0;
points = MulDiv( lpNTM->ntmTm.tmHeight - lpNTM->ntmTm.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 (!SendMessageW(hcmb2, CB_GETCOUNT, 0, 0))
{
if(!(hdc = CFn_GetDC(lpcf))) return 0;
i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
CFn_ReleaseDC(lpcf, hdc);
if (i)
return 0;
}
if( iswin16 || !( hcmb5 = GetDlgItem(hDlg, cmb5))) return 1;
i = SendMessageW( hcmb5, CB_FINDSTRINGEXACT, 0,
(LPARAM)lpElfex->elfScript);
if( i == CB_ERR) {
i = SendMessageW( hcmb5, CB_ADDSTRING, 0,
(LPARAM)lpElfex->elfScript);
if( i != CB_ERR)
SendMessageW( hcmb5, CB_SETITEMDATA, i, lplf->lfCharSet);
}
return 1 ;
}
static INT CFn_FitFontSize( HWND hDlg, int points)
{
int i,n;
int ret = 0;
/* look for fitting font size in combobox3 */
n=SendDlgItemMessageW(hDlg, cmb3, CB_GETCOUNT, 0, 0);
for (i=0;i<n;i++)
{
if (points == (int)SendDlgItemMessageW
(hDlg,cmb3, CB_GETITEMDATA,i,0))
{
SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,i,0);
SendMessageW(hDlg, WM_COMMAND,
MAKEWPARAM(cmb3, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb3));
ret = 1;
break;
}
}
return ret;
}
static INT CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
{
LONG id;
int i, ret = 0;
/* look for fitting font style in combobox2 */
for (i=0;i<TEXT_EXTRAS;i++)
{
id = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
if (packedstyle == id)
{
SendDlgItemMessageW(hDlg, cmb2, CB_SETCURSEL, i, 0);
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb2));
ret = 1;
break;
}
}
return ret;
}
static INT CFn_FitCharSet( HWND hDlg, int charset )
{
int i,n,cs;
/* look for fitting char set in combobox5 */
n=SendDlgItemMessageW(hDlg, cmb5, CB_GETCOUNT, 0, 0);
for (i=0;i<n;i++)
{
cs =SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
if (charset == cs)
{
SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, i, 0);
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb2));
return 1;
}
}
/* no charset fits: select the first one in the list */
SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, 0, 0);
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb2));
return 0;
}
/***********************************************************************
* FontStyleEnumProc32 [internal]
*/
static INT WINAPI FontStyleEnumProc( const ENUMLOGFONTEXW *lpElfex,
const TEXTMETRICW *metrics, DWORD dwFontType, LPARAM lParam )
{
LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
HWND hcmb2=s->hWnd1;
HWND hcmb3=s->hWnd2;
HWND hDlg=GetParent(hcmb3);
return AddFontStyle( lpElfex, (const NEWTEXTMETRICEXW *) metrics,
dwFontType, s->lpcf32w, hcmb2, hcmb3, hDlg, FALSE);
}
/***********************************************************************
* CFn_WMInitDialog [internal]
*/
LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
LPCHOOSEFONTW lpcf)
{
HDC hdc;
int i,j,init=0;
long pstyle;
CFn_ENUMSTRUCT s;
LPLOGFONTW lpxx;
HCURSOR hcursor=SetCursor(LoadCursorW(0,(LPWSTR)IDC_WAIT));
static const WCHAR strColorName[] = {'[','c','o','l','o','r',' ','n','a','m','e',']',0};
SetPropW(hDlg, strWineFontData, (HANDLE)lpcf);
lpxx=lpcf->lpLogFont;
TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
if (lpcf->lStructSize != sizeof(CHOOSEFONTW))
{
ERR("structure size failure !!!\n");
EndDialog (hDlg, 0);
return FALSE;
}
if (!himlTT)
himlTT = ImageList_LoadImageW( COMDLG32_hInstance, MAKEINTRESOURCEW(38),
TTBITMAP_XSIZE, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
if (!(lpcf->Flags & CF_APPLY))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -