Skip to content

Commit

Permalink
support alternative fonts, using ECMA-48 SGR codes
Browse files Browse the repository at this point in the history
  • Loading branch information
mintty committed Jun 13, 2017
1 parent f5dd00e commit 1250829
Show file tree
Hide file tree
Showing 12 changed files with 385 additions and 249 deletions.
8 changes: 8 additions & 0 deletions docs/mintty.1
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,14 @@ If a font family has no bold weight but boldness was requested, mintty
does not adhere to this scheme but enforces bold font selection; however,
in this case the bold attribute may not be effective.
.br
\(en \fBAlternative fonts\fP (Font1= ... Font9= , Font1Weight= ... Font9Weight=):
With these settings, up to 9 alternative fonts (and optionally weights)
can be configured which would then be selectable via ECMA-48 SGR character attributes
(see Tips wiki page \fIhttps://github.com/mintty/mintty/wiki/Tips#text-attributes-and-rendering\fP).
\fINote:\fP The control sequence for alternative font 1 overrides the identical
control sequence to select the VGA character set, which would thus be disabled.
Configuring alternative font 1 is therefore discouraged.
.br
\(en \fBFont sample text\fP (FontSample=):
This setting overrides the text for the "Sample" box in the Font chooser dialog.
.br
Expand Down
27 changes: 27 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ const config default_cfg = {
.cursor_blinks = true,
// Text
.font = {.name = W("Lucida Console"), .size = 9, .weight = 400, .isbold = false},
.fontfams[1] = {.name = W(""), .weight = 400, .isbold = false},
.fontfams[2] = {.name = W(""), .weight = 400, .isbold = false},
.fontfams[3] = {.name = W(""), .weight = 400, .isbold = false},
.fontfams[4] = {.name = W(""), .weight = 400, .isbold = false},
.fontfams[5] = {.name = W(""), .weight = 400, .isbold = false},
.fontfams[6] = {.name = W(""), .weight = 400, .isbold = false},
.fontfams[7] = {.name = W(""), .weight = 400, .isbold = false},
.fontfams[8] = {.name = W(""), .weight = 400, .isbold = false},
.fontfams[9] = {.name = W(""), .weight = 400, .isbold = false},
.font_sample = W(""),
.show_hidden_fonts = false,
.font_smoothing = FS_DEFAULT,
Expand Down Expand Up @@ -223,6 +232,24 @@ options[] = {
{"FontRender", OPT_FONTRENDER, offcfg(font_render)},
{"FontMenu", OPT_INT, offcfg(fontmenu)},
{"OldFontMenu", OPT_INT | OPT_LEGACY, offcfg(fontmenu)},
{"Font1", OPT_WSTRING, offcfg(fontfams[1].name)},
{"Font1Weight", OPT_INT, offcfg(fontfams[1].weight)},
{"Font2", OPT_WSTRING, offcfg(fontfams[2].name)},
{"Font2Weight", OPT_INT, offcfg(fontfams[2].weight)},
{"Font3", OPT_WSTRING, offcfg(fontfams[3].name)},
{"Font3Weight", OPT_INT, offcfg(fontfams[3].weight)},
{"Font4", OPT_WSTRING, offcfg(fontfams[4].name)},
{"Font4Weight", OPT_INT, offcfg(fontfams[4].weight)},
{"Font5", OPT_WSTRING, offcfg(fontfams[5].name)},
{"Font5Weight", OPT_INT, offcfg(fontfams[5].weight)},
{"Font6", OPT_WSTRING, offcfg(fontfams[6].name)},
{"Font6Weight", OPT_INT, offcfg(fontfams[6].weight)},
{"Font7", OPT_WSTRING, offcfg(fontfams[7].name)},
{"Font7Weight", OPT_INT, offcfg(fontfams[7].weight)},
{"Font8", OPT_WSTRING, offcfg(fontfams[8].name)},
{"Font8Weight", OPT_INT, offcfg(fontfams[8].weight)},
{"Font9", OPT_WSTRING, offcfg(fontfams[9].name)},
{"Font9Weight", OPT_INT, offcfg(fontfams[9].weight)},

// Keys
{"BackspaceSendsBS", OPT_BOOL, offcfg(backspace_sends_bs)},
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ typedef struct {
bool cursor_blinks;
// Text
font_spec font;
font_spec fontfams[10];
wstring font_sample;
bool show_hidden_fonts;
char font_smoothing;
Expand Down
5 changes: 4 additions & 1 deletion src/term.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ enum {
GRAPH_MASK = 0x00FF00000000u,
ATTR_GRAPH_SHIFT = 32,

FONTFAM_MASK = 0xF0000000000000u,
ATTR_FONTFAM_SHIFT = 52,

TATTR_RIGHTCURS = 0x010000000000u, /* cursor-on-RHS */
TATTR_PASCURS = 0x020000000000u, /* passive cursor (box) */
TATTR_ACTCURS = 0x040000000000u, /* active cursor (block) */
Expand Down Expand Up @@ -275,11 +278,11 @@ typedef struct {
bool autowrap; // switchable (xterm Wraparound Mode (DECAWM Auto Wrap))
bool wrapnext;
bool rev_wrap; // switchable (xterm Reverse-wraparound Mode)
bool utf;
short g0123;
term_cset csets[4];
term_cset cset_single;
uchar oem_acs;
bool utf;
} term_cursor;

typedef struct {
Expand Down
14 changes: 10 additions & 4 deletions src/termline.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ makeliteral_attr(struct buf *b, termchar *c)
*/
uint colourbits;
uint attr = c->attr.attr;
uint graph = c->attr.attr >> ATTR_GRAPH_SHIFT;
uchar graph = c->attr.attr >> ATTR_GRAPH_SHIFT;
uchar ff = c->attr.attr >> ATTR_FONTFAM_SHIFT;
uint truefg = c->attr.truefg;
uint truebg = c->attr.truebg;

Expand All @@ -263,7 +264,7 @@ makeliteral_attr(struct buf *b, termchar *c)

attr |= (colourbits << (32 - 9));

if (attr < 0x8000) {
if (attr < 0x8000 && !ff && !graph) {
add(b, (uchar) ((attr >> 8) & 0xFF));
add(b, (uchar) (attr & 0xFF));
}
Expand All @@ -272,8 +273,9 @@ makeliteral_attr(struct buf *b, termchar *c)
add(b, (uchar) ((attr >> 16) & 0xFF));
add(b, (uchar) ((attr >> 8) & 0xFF));
add(b, (uchar) (attr & 0xFF));
add(b, ff);
add(b, graph);
}
add(b, graph);

add(b, (uchar) ((truefg >> 16) & 0xFF));
add(b, (uchar) ((truefg >> 8) & 0xFF));
Expand Down Expand Up @@ -329,6 +331,8 @@ readliteral_attr(struct buf *b, termchar *c, termline *unused(line))
unsigned long long val, attr;
uint colourbits;
uint fg, bg;
uchar ff = 0;
uchar graph = 0;

val = get(b) << 8;
val |= get(b);
Expand All @@ -337,8 +341,9 @@ readliteral_attr(struct buf *b, termchar *c, termline *unused(line))
val <<= 16;
val |= get(b) << 8;
val |= get(b);
ff = get(b);
graph = get(b);
}
uint graph = get(b);

colourbits = (val >> (32 - 9)) & 0xFF;
attr = (val & ((1 << (32 - 9)) - 1));
Expand All @@ -361,6 +366,7 @@ readliteral_attr(struct buf *b, termchar *c, termline *unused(line))
bg |= get(b);

attr |= (unsigned long long)graph << ATTR_GRAPH_SHIFT;
attr |= (unsigned long long)ff << ATTR_FONTFAM_SHIFT;

c->attr.attr = attr;
c->attr.truefg = fg;
Expand Down
25 changes: 20 additions & 5 deletions src/termout.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,29 @@ do_sgr(void)
when 7: attr.attr |= ATTR_REVERSE;
when 8: attr.attr |= ATTR_INVISIBLE;
when 9: attr.attr |= ATTR_STRIKEOUT;
when 10 ... 11: // ... 12 disabled
when 10 ... 11: { // ... 12 disabled
// mode 10 is the configured Character set
// mode 11 is the VGA character set (CP437 + control range graphics)
// mode 12 is a weird feature from the Linux console,
// cloning the VGA character set (CP437) into the ASCII range;
// should we disable it? (not supported by cygwin console)
term.curs.oem_acs = term.csi_argv[i] - 10;
term_update_cs();
// disabled (not supported by cygwin console);
// modes 11 (and 12) are overridden by alternate font setting
// if configured
uchar arg_10 = term.csi_argv[i] - 10;
if (arg_10 && *cfg.fontfams[arg_10].name) {
attr.attr &= ~FONTFAM_MASK;
attr.attr |= (unsigned long long)arg_10 << ATTR_FONTFAM_SHIFT;
}
else {
if (!arg_10)
attr.attr &= ~FONTFAM_MASK;
term.curs.oem_acs = arg_10;
term_update_cs();
}
}
when 12 ... 19:
attr.attr &= ~FONTFAM_MASK;
attr.attr |= (unsigned long long)(term.csi_argv[i] - 10) << ATTR_FONTFAM_SHIFT;
//when 21: attr.attr &= ~ATTR_BOLD;
when 21: attr.attr |= ATTR_DOUBLYUND;
when 22: attr.attr &= ~(ATTR_BOLD | ATTR_DIM);
Expand Down Expand Up @@ -1637,7 +1652,7 @@ term_write(const char *buf, uint len)
switch (cset) {
when CSET_LINEDRW: // VT100 line drawing characters
if (0x60 <= wc && wc <= 0x7E) {
wchar dispwc = win_linedraw_chars[wc - 0x60];
wchar dispwc = win_linedraw_char(wc - 0x60);
#define draw_vt100_line_drawing_chars
#ifdef draw_vt100_line_drawing_chars
if ('j' <= wc && wc <= 'x') {
Expand Down
2 changes: 1 addition & 1 deletion src/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ extern int cursor_blink_ticks(void);
extern int win_char_width(xchar);
extern wchar win_combine_chars(wchar bc, wchar cc);

extern wchar win_linedraw_chars[31];
extern wchar win_linedraw_char(int i);

#endif
17 changes: 6 additions & 11 deletions src/winctrls.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,17 +812,12 @@ winctrl_layout(winctrls *wc, ctrlpos *cp, controlset *s, int *id)
staticbtn(&pos, "", base_id + 1, _("&Select..."), base_id + 2);
data = new(font_spec);

num_ids++;
char * fontinfopat = "Leading: %d, Bold: %s, Underline: %s";
char * fontinfo_font = "font";
char * fontinfo_manual = "manual";
int taglen = max(strlen(fontinfo_font), strlen(fontinfo_manual));
char * fontinfo = newn(char, strlen(fontinfopat) + 23 + 2 * taglen);
sprintf(fontinfo, fontinfopat, row_spacing,
bold_mode ? fontinfo_font : fontinfo_manual,
und_mode ? fontinfo_font : fontinfo_manual);
statictext(&pos, fontinfo, base_id + 3);
free(fontinfo);
char * fontinfo = fontpropinfo();
if (fontinfo) {
num_ids++;
statictext(&pos, fontinfo, base_id + 3);
free(fontinfo);
}
}
otherwise:
assert(!"Can't happen");
Expand Down
7 changes: 1 addition & 6 deletions src/winpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ extern int cell_width, cell_height; // includes spacing
extern int PADDING;
extern bool show_charinfo;
extern void toggle_charinfo(void);
// for display in Options – Font:
extern int row_spacing;
typedef enum {BOLD_SHADOW, BOLD_FONT} BOLD_MODE;
extern BOLD_MODE bold_mode;
typedef enum {UND_LINE, UND_FONT} UND_MODE;
extern UND_MODE und_mode;
extern char * fontpropinfo(void);

extern bool support_wsl;

Expand Down
Loading

0 comments on commit 1250829

Please sign in to comment.