From: Ali Gholami Rudi Date: Fri, 27 Jul 2012 07:29:08 +0000 (+0430) Subject: fbpad: remove changing fontsets support X-Git-Url: https://repo.or.cz/w/fbpad.git/commitdiff_plain/bd212a91c08d51f7f93c3f4c2295dc472929b6da fbpad: remove changing fontsets support Judging by the feedback I receive, it seems very few use this feature. So I'm removing it to simplify config.h and fbpad.c and pad.c interactions. --- diff --git a/README b/README index 98afc42..4750d2b 100644 --- a/README +++ b/README @@ -21,7 +21,6 @@ m-tab show next terminal m-s create a text screenshot (SCRSHOT) m-y redraw terminal c-m-q quit fbpad -m-f x use font x in this terminal ============== ======================================= SETTING UP @@ -34,12 +33,10 @@ match the framebuffer depth: unsigned char for 8-bit, short for 16-bit and int for 24/32-bit framebuffers. Once these are set, you should be able to start fbpad without problems. -Fbpad uses tinyfont files which can be created using ft2tf program -(http://litcave.rudi.ir/). At any moment each terminal in fbpad uses -a fontset; i.e. a set of three, not necessarily different, fonts for -rendering regular, italic, and bold text. Fx macros specify the fonts in -each fontset where the digit x is the identifier of the fontset ("m-f x" -command modifies current terminal to use fontset x). +Fbpad uses tinyfont files, which can be created using ft2tf program +(http://litcave.rudi.ir/). The FR, FI and FB macros specify the path +of the tinyfont files for regular, italic and bold fonts. If FI or FB +is NULL, the regular font is used for italic or bold text. Next you may want to change the list of fbpad tags by changing TAGS. FGCOLOR and BGCOLOR macros specify foreground and background colors, diff --git a/config.h b/config.h index e9142c4..81a9c01 100644 --- a/config.h +++ b/config.h @@ -7,12 +7,10 @@ /* fbval_t should match framebuffer depth */ typedef unsigned int fbval_t; -/* fontsets; tinyfont files for regular, italic, and bold fonts */ -#define F0 {"/path/to/font.tf", NULL, NULL} -#define F1 {} -#define F2 {} -#define F3 {} -#define F4 {} +/* tinyfont files for regular, italic, and bold fonts */ +#define FR "/path/to/font.tf" +#define FI NULL +#define FB NULL #define FGCOLOR 0 #define BGCOLOR 7 diff --git a/fbpad.c b/fbpad.c index 8ae7633..7b57dee 100644 --- a/fbpad.c +++ b/fbpad.c @@ -35,8 +35,6 @@ static struct term terms[NTERMS]; static int tops[NTAGS]; /* top terms of tags */ static int ctag; /* current tag */ static int ltag; /* the last tag */ -static int fonts[NTERMS]; /* term fonts */ -static int setfont; /* the next character is font */ static int exitit; static int hidden; @@ -61,8 +59,6 @@ static void term_switch(int oidx, int nidx, int show, int save, int load) term_save(&terms[oidx]); if (show && load && TERMOPEN(nidx) && TERMSNAP(nidx)) flags = scr_load(&terms[nidx]) ? TERM_REDRAW : TERM_VISIBLE; - if (show) - pad_font(fonts[nidx]); term_load(&terms[nidx], flags); } @@ -118,7 +114,6 @@ static void showtags(void) int c = 0; int r = pad_rows() - 1; int i; - pad_font(0); pad_put('T', r, c++, FGCOLOR, BGCOLOR); pad_put('A', r, c++, FGCOLOR, BGCOLOR); pad_put('G', r, c++, FGCOLOR, BGCOLOR); @@ -138,20 +133,11 @@ static void showtags(void) pad_put(tags[i], r, c++, colors[nt], BGCOLOR); pad_put(i == ctag ? ')' : ' ', r, c++, FGCOLOR, BGCOLOR); } - pad_font(fonts[cterm()]); } static void directkey(void) { int c = readchar(); - if (setfont && c != -1) { - setfont = 0; - if (c != ESC && isdigit(c)) { - fonts[cterm()] = c - '0'; - term_switch(cterm(), cterm(), 1, 0, 1); - } - return; - } if (c == ESC) { switch ((c = readchar())) { case 'c': @@ -185,9 +171,6 @@ static void directkey(void) case 'y': term_switch(cterm(), cterm(), 1, 0, 1); return; - case 'f': - setfont = 1; - return; default: if (strchr(tags, c)) { showtag(strchr(tags, c) - tags); diff --git a/pad.c b/pad.c index 17db83e..1f4d8c4 100644 --- a/pad.c +++ b/pad.c @@ -18,54 +18,37 @@ static unsigned int cd[] = { COLOR12, COLOR13, COLOR14, COLOR15}; static int rows, cols; static int fnrows, fncols; -static struct font *fonts[32]; -static int nfonts; -static int font; - -static int fnsets[16][3]; -static char *fnpaths[][3] = {F0, F1, F2, F3, F4}; - -static int fontadd(char *path) -{ - fonts[nfonts] = font_open(path); - if (!fonts[nfonts]) { - fprintf(stderr, "pad: bad font <%s>\n", path); - return -1; - } - return nfonts++; -} +static struct font *fonts[3]; int pad_init(void) { - int i, j; + int i; + char *paths[] = {FR, FI, FB}; if (fb_init()) return 1; if (sizeof(fbval_t) != FBM_BPP(fb_mode())) { fprintf(stderr, "pad_init: fbval_t doesn't match fb depth\n"); return 1; } - for (i = 0; i < ARRAY_SIZE(fnpaths); i++) { - for (j = 0; j < 3; j++) { - int fn = -1; - if (fnpaths[i][j]) - if ((fn = fontadd(fnpaths[i][j])) < 0) - return 1; - if (fn < 0 && j > 0) - fn = fnsets[i][0]; - if (fn < 0 && i > 0) - fn = fnsets[0][j]; - fnsets[i][j] = fn; - } + for (i = 0; i < 3; i++) + fonts[i] = paths[i] ? font_open(paths[i]) : NULL; + if (!fonts[0]) { + fprintf(stderr, "pad: bad font <%s>\n", paths[0]); + return -1; } - pad_font(0); + fnrows = font_rows(fonts[0]); + fncols = font_cols(fonts[0]); + rows = fb_rows() / fnrows; + cols = fb_cols() / fncols; return 0; } void pad_free(void) { int i; - for (i = 0; i < nfonts; i++) - font_free(fonts[i]); + for (i = 0; i < 3; i++) + if (fonts[i]) + font_free(fonts[i]); fb_free(); } @@ -91,30 +74,28 @@ static unsigned color2fb(int c) static fbval_t cache[NCACHE][MAXDOTS]; static struct glyph { int c; - int fn; short fg, bg; } glyphs[NCACHE]; -static struct glyph *glyph_entry(int c, int fn, int fg, int bg) +static struct glyph *glyph_entry(int c, int fg, int bg) { - return &glyphs[((c - 32) ^ (fg << 6) ^ (bg << 5) ^ (fn << 8)) & (NCACHE - 1)]; + return &glyphs[((c - 32) ^ (fg << 6) ^ (bg << 5)) & (NCACHE - 1)]; } -static fbval_t *glyph_cache(int c, int fn, short fg, short bg) +static fbval_t *glyph_cache(int c, short fg, short bg) { - struct glyph *g = glyph_entry(c, fn, fg, bg); - if (g->c == c && g->fn == fn && g->fg == fg && g->bg == bg) + struct glyph *g = glyph_entry(c, fg, bg); + if (g->c == c && g->fg == fg && g->bg == bg) return cache[g - glyphs]; return NULL; } -static fbval_t *glyph_add(int c, int fn, short fg, short bg) +static fbval_t *glyph_add(int c, short fg, short bg) { - struct glyph *g = glyph_entry(c, fn, fg, bg); + struct glyph *g = glyph_entry(c, fg, bg); g->c = c; g->fg = fg; g->bg = bg; - g->fn = fn; return cache[g - glyphs]; } @@ -136,11 +117,11 @@ static fbval_t *ch2fb(int fn, int c, short fg, short bg) fbval_t *fbbits; if (c < 0 || (c < 128 && (!isprint(c) || isspace(c)))) return NULL; - if ((fbbits = glyph_cache(c, fn, fg, bg))) + if ((fbbits = glyph_cache(c, fg, bg))) return fbbits; if (font_bitmap(fonts[fn], bits, c)) return NULL; - fbbits = glyph_add(c, fn, fg, bg); + fbbits = glyph_add(c, fg, bg); bmp2fb(fbbits, bits, FN_C(fg), FN_C(bg), font_rows(fonts[fn]), font_cols(fonts[fn])); return fbbits; @@ -160,10 +141,10 @@ static void fb_box(int sr, int sc, int er, int ec, fbval_t val) static int fnsel(int fg, int bg) { if ((fg | bg) & FN_B) - return fnsets[font][2]; + return fonts[2] ? 2 : 0; if ((fg | bg) & FN_I) - return fnsets[font][1]; - return fnsets[font][0]; + return fonts[1] ? 1 : 0; + return 0; } void pad_put(int ch, int r, int c, int fg, int bg) @@ -202,12 +183,3 @@ int pad_cols(void) { return cols; } - -void pad_font(int i) -{ - font = i < ARRAY_SIZE(fnpaths) ? i : 0; - fnrows = font_rows(fonts[fnsets[0][0]]); - fncols = font_cols(fonts[fnsets[0][0]]); - rows = fb_rows() / fnrows; - cols = fb_cols() / fncols; -} diff --git a/pad.h b/pad.h index 814b6d0..c097def 100644 --- a/pad.h +++ b/pad.h @@ -10,4 +10,3 @@ int pad_rows(void); int pad_cols(void); void pad_blank(int c); void pad_blankrow(int r, int bg); -void pad_font(int n);