|
From: | Gaius Mulley |
Subject: | [Groff] call for comments on a proposed patch |
Date: | 13 Jun 2006 17:48:50 +0100 |
User-agent: | Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
Hi, many years ago.. http://lists.nongnu.org/archive/html/groff/2001-11/msg00169.html Russell and Ted were discussing colour in tbl. Here are some patches which do this, basically I'd like feedback as to whether this works on many tbl inputs and whether it is useful? It works by, marking the start position of the table start, diverting the table contents, recording the limits of various rows/columns, stopping the diversion, drawing all backgrounds, moving back to the start position of the table and finally it replays the table contents. The additional syntax is shown in the following topical example.. but in simple terms it adds a modifier: m(background[,foreground]) to each table entry. Where background and foreground are groff colour definitions.
topicalflags.n
Description: topicalflags.n
its output is:
ps
Description: flag output
tabcolor.n
Description: centered table with double lines
ps2
Description: output
and the proposed patch is here below, enjoy! A word of caution, I had to modify s.tmac. So only -ms will currently work with these patches. Clearly I'll need to apply similar changes to mm, me, man and potentially mom needs changing as well (I suspect). The changes should be really simple, but I wanted to post these diffs before modifying the other macro sets (to incorporate any feedback).. regards, Gaius Index: src/preproc/tbl/main.cpp =================================================================== RCS file: /sources/groff/groff/src/preproc/tbl/main.cpp,v retrieving revision 1.8 diff -r1.8 main.cpp 2c2,3 < /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005 --- > /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, > 2004, 2005, 2006 599a601,610 > if (!bg_color.empty()) { > put_string("bg", stderr); > put_string(bg_color, stderr); > putc(' ', stderr); > } > if (!fg_color.empty()) { > put_string("fg", stderr); > put_string(fg_color, stderr); > putc(' ', stderr); > } 744a756,794 > /* > * read_string - returns a string which may be terminated by > * white space or delim1 or delim2. > */ > > string read_string(table_input &in, const char delim1, > const char delim2) > { > string result; > char c; > > for (;;) { > c = in.get(); > if (c == EOF || c == ' ' || c == '\t') { > string message; > > message = "missing `"; > message += char(delim1); > message += "'"; > if (delim1 != delim2) { > message = " or `"; > message += char(delim2); > message += "'"; > } > message += char('\0'); > error(message.contents()); > in.unget(c); > return result; > } > if (c == delim1 || c == delim2) { > in.unget(c); > return result; > } > result += char(c); > } > in.unget(c); > return result; > } > 889c939,941 < for (;;) { --- > list->font = read_string(in, ')', ')'); > c = in.get(); > if (c == ')') 891,900d942 < if (c == EOF || c == ' ' || c == '\t') { < error("missing `)'"); < break; < } < if (c == ')') { < c = in.get(); < break; < } < list->font += char(c); < } 912a955,986 > case 'm': > case 'M': > do { > c = in.get(); > } while (c == ' ' || c == '\t'); > if (c == EOF) { > error("missing background color"); > break; > } > if (c == '(') { > list->bg_color = read_string(in, ',', ')'); > c = in.get(); > if (c == ',') { > list->fg_color = read_string(in, ')', ')'); > c = in.get(); > } > if (c == ')') > c = in.get(); > else > error ("expecting ) at close of color specifier"); > } > else { > list->macro = c; > char cc = c; > c = in.get(); > if (!csdigit(cc) > && c != EOF && c != ' ' && c != '\t' && c != '.' && c != '\n') { > list->macro += char(c); > c = in.get(); > } > } > break; 923c997,999 < for (;;) { --- > list->macro = read_string(in, ')', ')'); > c = in.get(); > if (c == ')') 925,934d1000 < if (c == EOF || c == ' ' || c == '\t') { < error("missing `)'"); < break; < } < if (c == ')') { < c = in.get(); < break; < } < list->macro += char(c); < } 1590d1655 < Index: src/preproc/tbl/table.cpp =================================================================== RCS file: /sources/groff/groff/src/preproc/tbl/table.cpp,v retrieving revision 1.7 diff -r1.7 table.cpp 2c2 < /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2003, 2004 --- > /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2003, 2004, 2006 691a692,696 > if (!mod->bg_color.empty()) > printfs(".br\n.nop \\M[%1]\n.sp -1\n", mod->bg_color); > if (!mod->fg_color.empty()) > printfs(".br\n.nop \\m[%1]\n.sp -1\n", mod->fg_color); > 694a700,705 > > if (!mod->bg_color.empty()) > printfs(".br\n.nop \\M[]\n.sp -1\n"); > if (!mod->fg_color.empty()) > printfs(".br\n.nop \\m[]\n.sp -1\n"); > 984a996,999 > if (!m->bg_color.empty()) > printfs("\\M[%1]", m->bg_color); > if (!m->fg_color.empty()) > printfs("\\m[%1]", m->fg_color); 994a1010,1013 > if (!m->bg_color.empty()) > prints("\\M[]"); > if (!m->fg_color.empty()) > prints("\\m[]"); 2697a2717,2783 > void table::do_move(table_entry *e) > { > printfs("\\v'|\\n[tbl*top]u"); > printfs("+\\n[%1]u+" BODY_DEPTH , row_top_reg(e->start_row)); > if (e->start_row > 0) > if (flags & DOUBLEBOX) > printfs("-\\n[%1]u+" LINE_SEP "+" DOUBLE_LINE_SEP , row_top_reg(0)); > else > printfs("-\\n[%1]u+" LINE_SEP , row_top_reg(0)); > printfs("'\\h'|\\n[%1]u'", column_divide_reg(e->start_col)); > } > > void table::do_background_row(int r) > { > int first_start_row = r; > int c; > > for (c = 0; c < ncolumns; c++) { > table_entry *e = entry[r][c]; > if (e) { > if (e && e->mod && !e->mod->bg_color.empty()) { > printfs(".nop \\&"); > do_move(e); > set_inline_modifier(e->mod); > if (e->end_row+1 == nrows) { > printfs("\\D'P (\\n[%1]u-\\n[%2]u) 0u 0u (\\n[%3]u-\\n[%4]u+" > LINE_SEP ")", > column_divide_reg(e->start_col+1), > column_divide_reg(e->start_col), > row_top_reg(e->end_row+1), row_top_reg(e->start_row)); > printfs(" -(\\n[%1]u-\\n[%2]u) 0u 0u", > column_divide_reg(e->start_col+1), > column_divide_reg(e->start_col)); > printfs(" -(\\n[%1]u-\\n[%2]u+" LINE_SEP ")'", > row_top_reg(e->end_row+1), row_top_reg(e->start_row)); > } else { > printfs("\\D'P (\\n[%1]u-\\n[%2]u) 0u 0u (\\n[%3]u-\\n[%4]u)", > column_divide_reg(e->start_col+1), > column_divide_reg(e->start_col), > row_top_reg(e->end_row+1), row_top_reg(e->start_row)); > printfs(" -(\\n[%1]u-\\n[%2]u) 0u 0u", > column_divide_reg(e->start_col+1), > column_divide_reg(e->start_col)); > printfs(" -(\\n[%1]u-\\n[%2]u)'", > row_top_reg(e->end_row+1), row_top_reg(e->start_row)); > } > restore_inline_modifier(e->mod); > printfs("\n.sp -1\n"); > } > } > c = e->end_col; > } > } > > void table::do_background() > { > printfs(".di\n" > ".nr tbl*vert \\n[dn]u\n"); > if (flags & CENTER) > prints(".in +(u;\\n[.l]-\\n[.i]-\\n[TW]/2>?-\\n[.i])\n"); > > for (int i = 0; i < nrows; i++) > do_background_row(i); > > if (flags & CENTER) > printfs(".in\n"); > } > 2716a2803 > do_background(); 2778d2864 < Index: src/preproc/tbl/table.h =================================================================== RCS file: /sources/groff/groff/src/preproc/tbl/table.h,v retrieving revision 1.8 diff -r1.8 table.h 2c2 < /* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003, 2004 --- > /* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003, 2004, 2006 52a53,54 > string bg_color; > string fg_color; 116a119,121 > void do_background_row(int); > void do_background(); > void do_move(table_entry *); Index: src/preproc/tbl/tbl.man =================================================================== RCS file: /sources/groff/groff/src/preproc/tbl/tbl.man,v retrieving revision 1.14 diff -r1.14 tbl.man 273a274,285 > m,M > Background and foreground color. > Must be followed either by a > .BR @address@hidden (@MAN1EXT@) > defined color in parentheses. > The first color is the background color and the optional > second color separated by a comma is the foreground color. > For example m(red,blue) indicates that this column or cell > will be drawn using a red background and blue text. > Whereas m(red) indicates this cell or column is to be > drawn using a red background. > .TP cvs diff: Diffing src/roff cvs diff: Diffing src/roff/groff cvs diff: Diffing src/roff/grog cvs diff: Diffing src/roff/nroff cvs diff: Diffing src/roff/troff cvs diff: Diffing src/utils cvs diff: Diffing src/utils/addftinfo cvs diff: Diffing src/utils/afmtodit cvs diff: Diffing src/utils/hpftodit cvs diff: Diffing src/utils/indxbib cvs diff: Diffing src/utils/lkbib cvs diff: Diffing src/utils/lookbib cvs diff: Diffing src/utils/pfbtops cvs diff: Diffing src/utils/tfmtodit cvs diff: Diffing src/utils/xtotroff cvs diff: Diffing src/xditview cvs diff: Diffing tmac Index: tmac/s.tmac =================================================================== RCS file: /sources/groff/groff/tmac/s.tmac,v retrieving revision 1.25 diff -r1.25 s.tmac 1752a1753,1756 > .mk tbl*top > .br > .di tbl*contents > .br 1795a1800,1807 > . rt \\n[tbl*top]u > . sp |\\n[tbl*top]u > . sp > . ne \\n[tbl*vert]u > . ev tbl*nf > . nf > . tbl*contents > . ev
[Prev in Thread] | Current Thread | [Next in Thread] |