Skip to content

Instantly share code, notes, and snippets.

@emonkak
Created April 11, 2011 06:08
Show Gist options
  • Save emonkak/913127 to your computer and use it in GitHub Desktop.
Save emonkak/913127 to your computer and use it in GitHub Desktop.
putty-0.60-fix-font.patch
--- WINDOWS/window.c~ Thu Dec 24 13:17:48 2009
+++ WINDOWS/window.c Sun Nov 28 22:09:15 2010
@@ -1759,8 +1759,8 @@
else {
font_height = cfg.font.height;
if (font_height > 0) {
- font_height =
- -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72);
+ font_height = font_height > 0 ?
+ -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72) : font_height;
}
}
font_width = pick_width;
@@ -1773,6 +1773,12 @@
f(FONT_NORMAL, cfg.font.charset, fw_dontcare, FALSE);
+ f(FONT_UNDERLINE, cfg.font.charset, fw_dontcare, TRUE);
+
+ if (bold_mode == BOLD_FONT) {
+ f(FONT_BOLD, cfg.font.charset, fw_bold, FALSE);
+ }
+
SelectObject(hdc, fonts[FONT_NORMAL]);
GetTextMetrics(hdc, &tm);
@@ -1807,7 +1813,6 @@
ucsdata.dbcs_screenfont = (cpinfo.MaxCharSize > 1);
}
- f(FONT_UNDERLINE, cfg.font.charset, fw_dontcare, TRUE);
/*
* Some fonts, e.g. 9-pt Courier, draw their underlines
@@ -1857,9 +1862,6 @@
}
}
- if (bold_mode == BOLD_FONT) {
- f(FONT_BOLD, cfg.font.charset, fw_bold, FALSE);
- }
#undef f
descent = tm.tmAscent + 1;
@@ -1899,8 +1901,9 @@
{
int basefont;
int fw_dontcare, fw_bold;
- int c, u, w, x;
+ int c, u, w, x, y;
char *s;
+ HDC hdc;
if (fontno < 0 || fontno >= FONT_MAXNO || fontflag[fontno])
return;
@@ -1917,16 +1920,21 @@
fw_bold = FW_BOLD;
}
+ hdc = GetDC(hwnd);
c = cfg.font.charset;
w = fw_dontcare;
u = FALSE;
s = cfg.font.name;
- x = font_width;
+ x = 0;
+ y = cfg.font.height;
+ y = y > 0 ? -MulDiv(y, GetDeviceCaps(hdc, LOGPIXELSY), 72) : y;
+
+ ReleaseDC(hwnd, hdc);
if (fontno & FONT_WIDE)
- x *= 2;
+ x = font_width * 2;
if (fontno & FONT_NARROW)
- x = (x+1)/2;
+ x = (font_width + 1) / 2;
if (fontno & FONT_OEM)
c = OEM_CHARSET;
if (fontno & FONT_BOLD)
@@ -1935,7 +1943,7 @@
u = TRUE;
fonts[fontno] =
- CreateFont(font_height * (1 + !!(fontno & FONT_HIGH)), x, 0, 0, w,
+ CreateFont(y * (1 + !!(fontno & FONT_HIGH)), x, 0, 0, w,
FALSE, u, FALSE, c, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, FONT_QUALITY(cfg.font_quality),
FIXED_PITCH | FF_DONTCARE, s);
@@ -3679,7 +3687,7 @@
if ((attr & TATTR_ACTCURS) && (cfg.cursor_type == 0 || term->big_cursor)) {
attr &= ~(ATTR_REVERSE|ATTR_BLINK|ATTR_COLOURS);
- if (bold_mode == BOLD_COLOURS)
+ //if (bold_mode == BOLD_COLOURS)
attr &= ~ATTR_BOLD;
/* cursor fg and bg */
@@ -3743,6 +3751,7 @@
nfg = ((attr & ATTR_FGMASK) >> ATTR_FGSHIFT);
nbg = ((attr & ATTR_BGMASK) >> ATTR_BGSHIFT);
if (bold_mode == BOLD_FONT && (attr & ATTR_BOLD))
+ if (attr & ATTR_BOLD)
nfont |= FONT_BOLD;
if (und_mode == UND_FONT && (attr & ATTR_UNDER))
nfont |= FONT_UNDERLINE;
@@ -3757,19 +3766,21 @@
another_font(nfont);
if (!fonts[nfont])
nfont = FONT_NORMAL;
- if (attr & ATTR_REVERSE) {
- t = nfg;
- nfg = nbg;
- nbg = t;
- }
- if (bold_mode == BOLD_COLOURS && (attr & ATTR_BOLD)) {
+ //if (bold_mode == BOLD_COLOURS && (attr & ATTR_BOLD)) {
+ if (attr & ATTR_BOLD) {
if (nfg < 16) nfg |= 8;
else if (nfg >= 256) nfg |= 1;
}
- if (bold_mode == BOLD_COLOURS && (attr & ATTR_BLINK)) {
+ //if (bold_mode == BOLD_COLOURS && (attr & ATTR_BLINK)) {
+ if (attr & ATTR_BLINK) {
if (nbg < 16) nbg |= 8;
else if (nbg >= 256) nbg |= 1;
}
+ if (attr & ATTR_REVERSE) {
+ t = nfg;
+ nfg = nbg;
+ nbg = t;
+ }
fg = colours[nfg];
bg = colours[nbg];
SelectObject(hdc, fonts[nfont]);
@@ -5173,13 +5184,8 @@
fgcolour = ((attr[i] & ATTR_FGMASK) >> ATTR_FGSHIFT);
bgcolour = ((attr[i] & ATTR_BGMASK) >> ATTR_BGSHIFT);
- if (attr[i] & ATTR_REVERSE) {
- int tmpcolour = fgcolour; /* Swap foreground and background */
- fgcolour = bgcolour;
- bgcolour = tmpcolour;
- }
-
- if (bold_mode == BOLD_COLOURS && (attr[i] & ATTR_BOLD)) {
+ //if (bold_mode == BOLD_COLOURS && (attr[i] & ATTR_BOLD)) {
+ if (attr[i] & ATTR_BOLD) {
if (fgcolour < 8) /* ANSI colours */
fgcolour += 8;
else if (fgcolour >= 256) /* Default colours */
@@ -5193,6 +5199,12 @@
bgcolour ++;
}
+ if (attr[i] & ATTR_REVERSE) {
+ int tmpcolour = fgcolour; /* Swap foreground and background */
+ fgcolour = bgcolour;
+ bgcolour = tmpcolour;
+ }
+
palette[fgcolour]++;
palette[bgcolour]++;
}
@@ -5264,13 +5276,8 @@
fgcolour = ((attr[tindex] & ATTR_FGMASK) >> ATTR_FGSHIFT);
bgcolour = ((attr[tindex] & ATTR_BGMASK) >> ATTR_BGSHIFT);
- if (attr[tindex] & ATTR_REVERSE) {
- int tmpcolour = fgcolour; /* Swap foreground and background */
- fgcolour = bgcolour;
- bgcolour = tmpcolour;
- }
-
- if (bold_mode == BOLD_COLOURS && (attr[tindex] & ATTR_BOLD)) {
+ //if (bold_mode == BOLD_COLOURS && (attr[tindex] & ATTR_BOLD)) {
+ if (attr[tindex] & ATTR_BOLD) {
if (fgcolour < 8) /* ANSI colours */
fgcolour += 8;
else if (fgcolour >= 256) /* Default colours */
@@ -5287,9 +5294,9 @@
/*
* Collect other attributes
*/
- if (bold_mode != BOLD_COLOURS)
- attrBold = attr[tindex] & ATTR_BOLD;
- else
+ //if (bold_mode != BOLD_COLOURS)
+ // attrBold = attr[tindex] & ATTR_BOLD;
+ //else
attrBold = 0;
attrUnder = attr[tindex] & ATTR_UNDER;
@@ -5306,11 +5313,18 @@
bgcolour = -1; /* No coloring */
if (fgcolour >= 256) { /* Default colour */
- if (bold_mode == BOLD_COLOURS && (fgcolour & 1) && bgcolour == -1)
+ //if (bold_mode == BOLD_COLOURS && (fgcolour & 1) && bgcolour == -1)
+ if (fgcolour & 1 && bgcolour == -1)
attrBold = ATTR_BOLD; /* Emphasize text with bold attribute */
fgcolour = -1; /* No coloring */
}
+ }
+
+ if (attr[tindex] & ATTR_REVERSE) {
+ int tmpcolour = fgcolour; /* Swap foreground and background */
+ fgcolour = bgcolour;
+ bgcolour = tmpcolour;
}
/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment