Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jjjordan committed Sep 18, 2017
0 parents commit 48aa93c
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Putty italics patch

This repository contains a patch that enables italics in the Windows version
of PuTTY. Italics text was specified in ECMA-48 *in 1976*, yet terminal
emulator support for it has only caught on somewhat recently. Support
exists in many libvte-based terminals, but to date it's not even on the
[PuTTY wishlist](https://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/).

I'd like to eventually submit this patch upstream, however, it would likely
require implementations for the other operating systems, and some fairly
thorough testing before it would be accepted...

## Screenshots

### With italics

![With Italics](https://raw.githubusercontent.com/jjjordan/putty-italics/master/screenshots/with-italics.png)
*The [JOE Editor](https://sf.net/p/joe-editor) with the Zenburn color scheme*

### Without italics

![No Italics](https://raw.githubusercontent.com/jjjordan/putty-italics/master/screenshots/no-italics.png)

### Font support

The patch is a bit picky about which fonts it will allow. Many monospaced
fonts do not have a native italics face, and instead rely on the Operating
System to apply a linear transformation for an "Oblique" face. They wind up
overhanging the next glyph and cause generally bad artifacts during
painting. For this reason, the patch rejects any font without a true
Italics face.

These fonts, however, are known to work:

* [Anonymous Pro](https://www.marksimonson.com/fonts/view/anonymous-pro)
* Consolas
* Courier New
* [Hack](http://sourcefoundry.org/hack/)
* [Operator Mono](https://www.typography.com/fonts/operator/overview/)
* [Ubuntu Mono](http://font.ubuntu.com/)

203 changes: 203 additions & 0 deletions italics-0.70.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
diff -ruN putty-0.70-orig/putty.h putty-0.70/putty.h
--- putty-0.70-orig/putty.h 2017-07-04 12:30:55.000000000 -0700
+++ putty-0.70/putty.h 2017-09-17 23:27:25.855665600 -0700
@@ -104,6 +104,7 @@
*/
#define UCSWIDE 0xDFFF

+#define ATTR_ITALIC 0x1000000U
#define ATTR_NARROW 0x800000U
#define ATTR_WIDE 0x400000U
#define ATTR_BOLD 0x040000U
diff -ruN putty-0.70-orig/terminal.c putty-0.70/terminal.c
--- putty-0.70-orig/terminal.c 2017-07-04 12:30:55.000000000 -0700
+++ putty-0.70/terminal.c 2017-09-17 23:43:56.100304300 -0700
@@ -3804,6 +3804,10 @@
compatibility(VT100AVO);
term->curr_attr |= ATTR_BOLD;
break;
+ case 3: /* enable italics */
+ compatibility(ANSI);
+ term->curr_attr |= ATTR_ITALIC;
+ break;
case 21: /* (enable double underline) */
compatibility(OTHER);
case 4: /* enable underline */
@@ -3839,6 +3843,10 @@
compatibility2(OTHER, VT220);
term->curr_attr &= ~ATTR_BOLD;
break;
+ case 23: /* disable italics */
+ compatibility(ANSI);
+ term->curr_attr &= ~ATTR_ITALIC;
+ break;
case 24: /* disable underline */
compatibility2(OTHER, VT220);
term->curr_attr &= ~ATTR_UNDER;
diff -ruN putty-0.70-orig/windows/window.c putty-0.70/windows/window.c
--- putty-0.70-orig/windows/window.c 2017-07-04 12:30:56.000000000 -0700
+++ putty-0.70/windows/window.c 2017-09-18 00:23:13.041113600 -0700
@@ -171,17 +171,18 @@
#define FONT_BOLD 1
#define FONT_UNDERLINE 2
#define FONT_BOLDUND 3
-#define FONT_WIDE 0x04
-#define FONT_HIGH 0x08
-#define FONT_NARROW 0x10
-
-#define FONT_OEM 0x20
-#define FONT_OEMBOLD 0x21
-#define FONT_OEMUND 0x22
-#define FONT_OEMBOLDUND 0x23
+#define FONT_ITALIC 4
+#define FONT_WIDE 0x08
+#define FONT_HIGH 0x10
+#define FONT_NARROW 0x20
+
+#define FONT_OEM 0x40
+#define FONT_OEMBOLD 0x41
+#define FONT_OEMUND 0x42
+#define FONT_OEMBOLDUND 0x43

-#define FONT_MAXNO 0x40
-#define FONT_SHIFT 5
+#define FONT_MAXNO 0x4F
+#define FONT_SHIFT 6
static HFONT fonts[FONT_MAXNO];
static LOGFONT lfont;
static int fontflag[FONT_MAXNO];
@@ -193,6 +194,7 @@
UND_LINE, UND_FONT
} und_mode;
static int descent;
+static int use_italics;

#define NCFGCOLOURS 22
#define NEXTCOLOURS 240
@@ -1494,13 +1496,13 @@
font_width = pick_width;

quality = conf_get_int(conf, CONF_font_quality);
-#define f(i,c,w,u) \
- fonts[i] = CreateFont (font_height, font_width, 0, 0, w, FALSE, u, FALSE, \
+#define f(i,c,w,u,t) \
+ fonts[i] = CreateFont (font_height, font_width, 0, 0, w, t, u, FALSE, \
c, OUT_DEFAULT_PRECIS, \
CLIP_DEFAULT_PRECIS, FONT_QUALITY(quality), \
FIXED_PITCH | FF_DONTCARE, font->name)

- f(FONT_NORMAL, font->charset, fw_dontcare, FALSE);
+ f(FONT_NORMAL, font->charset, fw_dontcare, FALSE, FALSE);

SelectObject(hdc, fonts[FONT_NORMAL]);
GetTextMetrics(hdc, &tm);
@@ -1544,7 +1546,57 @@
ucsdata.dbcs_screenfont = (cpinfo.MaxCharSize > 1);
}

- f(FONT_UNDERLINE, font->charset, fw_dontcare, TRUE);
+ /* Check whether italic face is acceptable... */
+ f(FONT_ITALIC, font->charset, fw_dontcare, FALSE, TRUE);
+
+ {
+ LPOUTLINETEXTMETRICA regularOtm, italicOtm;
+
+ use_italics = 0;
+
+ i = GetOutlineTextMetricsA(hdc, 0, NULL);
+ if (i > 0) {
+ regularOtm = (LPOUTLINETEXTMETRICA)safemalloc(1, i);
+ regularOtm->otmSize = sizeof(OUTLINETEXTMETRICA);
+ if (GetOutlineTextMetricsA(hdc, i, regularOtm)) {
+ /* Now get the italic version */
+ SelectObject(hdc, fonts[FONT_ITALIC]);
+ i = GetOutlineTextMetricsA(hdc, 0, NULL);
+ if (i > 0) {
+ italicOtm = (LPOUTLINETEXTMETRICA)safemalloc(1, i);
+ italicOtm->otmSize = sizeof(OUTLINETEXTMETRICA);
+ if (GetOutlineTextMetricsA(hdc, i, italicOtm)) {
+ /* Compare... */
+ char *regStyle = (char*)regularOtm + (int)regularOtm->otmpStyleName;
+ char *itaStyle = (char*)italicOtm + (int)italicOtm->otmpStyleName;
+
+ /* Weed out "italic" fonts that...
+ - Do not specify an italic slant (probably just the regular font)
+ - Have the same style as the regular font. Then it *is* just the regular
+ font with a linear transformation.
+ - Report the style name of "Oblique".
+
+ My experience is these a) don't look very good b) tend to overhang the
+ next character and get cut off during paints... which doesn't look very good. */
+ if (strcmp(regStyle, itaStyle) && stricmp(itaStyle, "Oblique") && italicOtm->otmItalicAngle != 0) {
+ use_italics = 1;
+ }
+ }
+
+ safefree(italicOtm);
+ }
+ }
+
+ safefree(regularOtm);
+ }
+
+ if (!use_italics) {
+ DeleteObject(fonts[FONT_ITALIC]);
+ fonts[FONT_ITALIC] = NULL;
+ }
+ }
+
+ f(FONT_UNDERLINE, font->charset, fw_dontcare, TRUE, FALSE);

/*
* Some fonts, e.g. 9-pt Courier, draw their underlines
@@ -1595,7 +1647,7 @@
}

if (bold_font_mode == BOLD_FONT) {
- f(FONT_BOLD, font->charset, fw_bold, FALSE);
+ f(FONT_BOLD, font->charset, fw_bold, FALSE, FALSE);
}
#undef f

@@ -1636,7 +1688,7 @@
{
int basefont;
int fw_dontcare, fw_bold, quality;
- int c, u, w, x;
+ int c, u, w, x, t;
char *s;
FontSpec *font;

@@ -1662,6 +1714,7 @@
u = FALSE;
s = font->name;
x = font_width;
+ t = FALSE;

if (fontno & FONT_WIDE)
x *= 2;
@@ -1673,12 +1726,14 @@
w = fw_bold;
if (fontno & FONT_UNDERLINE)
u = TRUE;
+ if (fontno & FONT_ITALIC && use_italics)
+ t = TRUE;

quality = conf_get_int(conf, CONF_font_quality);

fonts[fontno] =
CreateFont(font_height * (1 + !!(fontno & FONT_HIGH)), x, 0, 0, w,
- FALSE, u, FALSE, c, OUT_DEFAULT_PRECIS,
+ t, u, FALSE, c, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, FONT_QUALITY(quality),
DEFAULT_PITCH | FF_DONTCARE, s);

@@ -3498,6 +3553,8 @@
nfont |= FONT_BOLD;
if (und_mode == UND_FONT && (attr & ATTR_UNDER))
nfont |= FONT_UNDERLINE;
+ if (attr & ATTR_ITALIC)
+ nfont |= FONT_ITALIC;
another_font(nfont);
if (!fonts[nfont]) {
if (nfont & FONT_UNDERLINE)
Binary file added screenshots/no-italics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/with-italics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 48aa93c

Please sign in to comment.