From 3b2c664e78d68bafd8a921d3b73104df0ae0d292 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 12 Mar 2001 12:24:07 +0000 Subject: [PATCH] Finally fixed the point/pixel confusion in font handling. Thanks to Roman Surma for pointing me at the relevant bits of documentation. All font sizes should now be measured in points, and everything should be consistent, and (with any luck) old Registry settings should adapt gracefully too. git-svn-id: svn://svn.tartarus.org/sgt/putty@992 cda61777-01e9-0310-a592-d414129be87e --- settings.c | 12 ++++++++++++ windlg.c | 7 +++---- window.c | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/settings.c b/settings.c index ad062dd5..299ee8e0 100644 --- a/settings.c +++ b/settings.c @@ -264,6 +264,18 @@ void load_settings (char *section, int do_host, Config *cfg) { gppi (sesskey, "FontIsBold", 0, &cfg->fontisbold); gppi (sesskey, "FontCharSet", ANSI_CHARSET, &cfg->fontcharset); gppi (sesskey, "FontHeight", 10, &cfg->fontheight); + if (cfg->fontheight < 0) { + int oldh, newh; + HDC hdc = GetDC(NULL); + int logpix = GetDeviceCaps(hdc, LOGPIXELSY); + ReleaseDC(NULL, hdc); + + oldh = -cfg->fontheight; + newh = MulDiv(oldh, 72, logpix) + 1; + if (MulDiv(newh, logpix, 72) > oldh) + newh--; + cfg->fontheight = newh; + } gppi (sesskey, "FontVTMode", VT_OEMANSI, (int *)&cfg->vtmode); gppi (sesskey, "TryPalette", 0, &cfg->try_palette); gppi (sesskey, "BoldAsColour", 1, &cfg->bold_colour); diff --git a/windlg.c b/windlg.c index 9b2e60fb..4db8c029 100644 --- a/windlg.c +++ b/windlg.c @@ -467,9 +467,8 @@ static void fmtfont (char *buf) { if (cfg.fontheight == 0) strcat (buf, "default height"); else - sprintf (buf+strlen(buf), "%d-%s", - (cfg.fontheight < 0 ? -cfg.fontheight : cfg.fontheight), - (cfg.fontheight < 0 ? "pixel" : "point")); + sprintf (buf+strlen(buf), "%d-point", + (cfg.fontheight < 0 ? -cfg.fontheight : cfg.fontheight)); } static void init_dlg_ctrls(HWND hwnd) { @@ -1549,7 +1548,7 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg, cfg.font[sizeof(cfg.font)-1] = '\0'; cfg.fontisbold = (lf.lfWeight == FW_BOLD); cfg.fontcharset = lf.lfCharSet; - cfg.fontheight = lf.lfHeight; + cfg.fontheight = cf.iPointSize / 10; fmtfont (fontstatic); SetDlgItemText (hwnd, IDC_FONTSTATIC, fontstatic); } diff --git a/window.c b/window.c index a54d507c..f7242758 100644 --- a/window.c +++ b/window.c @@ -808,6 +808,9 @@ font_messup: 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) \ -- 2.11.0