From 5bf50ab2be9fedb204f131218ac2d729836003c1 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 15 Oct 2002 18:42:48 +0000 Subject: [PATCH] Support bold-as-font, by means of a separate bold font (if one was supplied) or shadow bolding (if not). As usual, can't yet be turned on without a recompile. git-svn-id: svn://svn.tartarus.org/sgt/putty@2077 cda61777-01e9-0310-a592-d414129be87e --- unix/pterm.c | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/unix/pterm.c b/unix/pterm.c index f7dbcbd9..1fcaa327 100644 --- a/unix/pterm.c +++ b/unix/pterm.c @@ -1236,13 +1236,12 @@ void free_ctx(Context ctx) void do_text_internal(Context ctx, int x, int y, char *text, int len, unsigned long attr, int lattr) { - int nfg, nbg, t; + int nfg, nbg, t, fontid, shadow; GdkGC *gc = (GdkGC *)ctx; /* * NYI: * - Unicode, code pages, and ATTR_WIDE for CJK support. - * - shadow bolding */ nfg = 2 * ((attr & ATTR_FGMASK) >> ATTR_FGSHIFT); @@ -1261,6 +1260,14 @@ void do_text_internal(Context ctx, int x, int y, char *text, int len, nbg = NCOLOURS-1; } + fontid = shadow = 0; + if ((attr & ATTR_BOLD) && !cfg.bold_colour) { + if (inst->fonts[1]) + fontid = 1; + else + shadow = 1; + } + if (lattr != LATTR_NORM) { x *= 2; if (x >= cols) @@ -1276,11 +1283,25 @@ void do_text_internal(Context ctx, int x, int y, char *text, int len, len*inst->font_width, inst->font_height); gdk_gc_set_foreground(gc, &inst->cols[nfg]); - gdk_draw_text(inst->pixmap, inst->fonts[0], gc, + gdk_draw_text(inst->pixmap, inst->fonts[fontid], gc, x*inst->font_width+cfg.window_border, y*inst->font_height+cfg.window_border+inst->fonts[0]->ascent, text, len); + /* + * X fonts seem to be pretty consistent about leaving the + * _left_ pixel of the cell blank rather than the right. Hence + * I'm going to hard-code shadow bolding as displaying one + * pixel to the left rather than try to work out whether it + * should be left or right. + */ + if (shadow) { + gdk_draw_text(inst->pixmap, inst->fonts[fontid], gc, + x*inst->font_width+cfg.window_border - 1, + y*inst->font_height+cfg.window_border+inst->fonts[0]->ascent, + text, len); + } + if (attr & ATTR_UNDER) { int uheight = inst->fonts[0]->ascent + 1; if (uheight >= inst->font_height) @@ -1573,6 +1594,13 @@ int main(int argc, char **argv) } else err = 1, fprintf(stderr, "pterm: -fn expects an argument\n"); } + if (!strcmp(p, "-fb")) { + if (--argc > 0) { + strncpy(cfg.boldfont, *++argv, sizeof(cfg.boldfont)); + cfg.boldfont[sizeof(cfg.boldfont)-1] = '\0'; + } else + err = 1, fprintf(stderr, "pterm: -fb expects an argument\n"); + } if (!strcmp(p, "-e")) { if (--argc > 0) { int i; @@ -1622,7 +1650,16 @@ int main(int argc, char **argv) fprintf(stderr, "pterm: unable to load font \"%s\"\n", cfg.font); exit(1); } - inst->fonts[1] = NULL; /* FIXME: what about bold font? */ + if (cfg.boldfont[0]) { + inst->fonts[1] = gdk_font_load(cfg.boldfont); + if (!inst->fonts[1]) { + fprintf(stderr, "pterm: unable to load bold font \"%s\"\n", + cfg.boldfont); + exit(1); + } + } else + inst->fonts[1] = NULL; + inst->font_width = gdk_char_width(inst->fonts[0], ' '); inst->font_height = inst->fonts[0]->ascent + inst->fonts[0]->descent; -- 2.11.0