font_height = cfg.fontheight; if (font_height > 0) { font_height = -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72);
if (pick_height) font_height = pick_height; else { font_height = cfg.fontheight; if (font_height > 0) { font_height = -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72); }
static void init_fonts(int pick_width){    TEXTMETRIC tm;    CPINFO cpinfo;    int fontsize[3];    int i;    HDC hdc;    int fw_dontcare, fw_bold;    for (i = 0; i < FONT_MAXNO; i++)	fonts[i] = NULL;    if (cfg.fontisbold) {	fw_dontcare = FW_BOLD;	fw_bold = FW_HEAVY;    } else {	fw_dontcare = FW_DONTCARE;	fw_bold = FW_BOLD;    }    hdc = GetDC(hwnd);    font_height = cfg.fontheight;    if (font_height > 0) {	font_height =	    -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72);    }    font_width = pick_width;#define f(i,c,w,u) \    fonts[i] = CreateFont (font_height, font_width, 0, 0, w, FALSE, u, FALSE, \			   c, OUT_DEFAULT_PRECIS, \		           CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, \			   FIXED_PITCH | FF_DONTCARE, cfg.font)    f(FONT_NORMAL, cfg.fontcharset, fw_dontcare, FALSE);    SelectObject(hdc, fonts[FONT_NORMAL]);    GetTextMetrics(hdc, &tm);    font_height = tm.tmHeight;    font_width = tm.tmAveCharWidth;    {	CHARSETINFO info;	DWORD cset = tm.tmCharSet;	memset(&info, 0xFF, sizeof(info));	/* !!! Yes the next line is right */	if (cset == OEM_CHARSET)	    font_codepage = GetOEMCP();	else	    if (TranslateCharsetInfo		((DWORD *) cset, &info, TCI_SRCCHARSET)) font_codepage =		info.ciACP;	else	    font_codepage = -1;	GetCPInfo(font_codepage, &cpinfo);	dbcs_screenfont = (cpinfo.MaxCharSize > 1);    }    f(FONT_UNDERLINE, cfg.fontcharset, fw_dontcare, TRUE);    /*     * Some fonts, e.g. 9-pt Courier, draw their underlines     * outside their character cell. We successfully prevent     * screen corruption by clipping the text output, but then     * we lose the underline completely. Here we try to work     * out whether this is such a font, and if it is, we set a     * flag that causes underlines to be drawn by hand.     *     * Having tried other more sophisticated approaches (such     * as examining the TEXTMETRIC structure or requesting the     * height of a string), I think we'll do this the brute     * force way: we create a small bitmap, draw an underlined     * space on it, and test to see whether any pixels are     * foreground-coloured. (Since we expect the underline to     * go all the way across the character cell, we only search     * down a single column of the bitmap, half way across.)     */    {	HDC und_dc;	HBITMAP und_bm, und_oldbm;	int i, gotit;	COLORREF c;	und_dc = CreateCompatibleDC(hdc);	und_bm = CreateCompatibleBitmap(hdc, font_width, font_height);	und_oldbm = SelectObject(und_dc, und_bm);	SelectObject(und_dc, fonts[FONT_UNDERLINE]);	SetTextAlign(und_dc, TA_TOP | TA_LEFT | TA_NOUPDATECP);	SetTextColor(und_dc, RGB(255, 255, 255));	SetBkColor(und_dc, RGB(0, 0, 0));	SetBkMode(und_dc, OPAQUE);	ExtTextOut(und_dc, 0, 0, ETO_OPAQUE, NULL, " ", 1, NULL);	gotit = FALSE;	for (i = 0; i < font_height; i++) {	    c = GetPixel(und_dc, font_width / 2, i);	    if (c != RGB(0, 0, 0))		gotit = TRUE;	}	SelectObject(und_dc, und_oldbm);	DeleteObject(und_bm);	DeleteDC(und_dc);	if (!gotit) {	    und_mode = UND_LINE;	    DeleteObject(fonts[FONT_UNDERLINE]);	    fonts[FONT_UNDERLINE] = 0;	}    }    if (bold_mode == BOLD_FONT) {	f(FONT_BOLD, cfg.fontcharset, fw_bold, FALSE);    }#undef f    descent = tm.tmAscent + 1;    if (descent >= font_height)	descent = font_height - 1;    for (i = 0; i < 3; i++) {	if (fonts[i]) {	    if (SelectObject(hdc, fonts[i]) && GetTextMetrics(hdc, &tm))		fontsize[i] = tm.tmAveCharWidth + 256 * tm.tmHeight;	    else		fontsize[i] = -i;	} else	    fontsize[i] = -i;    }    ReleaseDC(hwnd, hdc);    if (fontsize[FONT_UNDERLINE] != fontsize[FONT_NORMAL]) {	und_mode = UND_LINE;	DeleteObject(fonts[FONT_UNDERLINE]);	fonts[FONT_UNDERLINE] = 0;    }    if (bold_mode == BOLD_FONT &&	fontsize[FONT_BOLD] != fontsize[FONT_NORMAL]) {	bold_mode = BOLD_SHADOW;	DeleteObject(fonts[FONT_BOLD]);	fonts[FONT_BOLD] = 0;    }    fontflag[0] = fontflag[1] = fontflag[2] = 1;    init_ucs_tables();}