diff options
author | wl <wl> | 2006-06-29 08:51:22 +0000 |
---|---|---|
committer | wl <wl> | 2006-06-29 08:51:22 +0000 |
commit | e6f7c48b0d5791bda3184473531bae879e000059 (patch) | |
tree | 3b46304abe3f6b8bf88185293017cd8c12833a6a /src | |
parent | 1e509817190d38994904e3334f1409940ec9bc3d (diff) | |
download | groff-e6f7c48b0d5791bda3184473531bae879e000059.tar.gz |
Add support for \D'p...' to grotty.
* src/devices/grotty/grotty.cpp (tty_printer::draw): Move most of
its code to...
(tty_printer::line): This function.
(tty_printer::draw): Rewritten; just call either draw_line or
draw_polygon.
(tty_printer::draw_line, tty_printer::draw_polygon): New functions.
* src/devices/grotty/grotty.man, NEWS: Document it.
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/grotty/grotty.man | 25 | ||||
-rw-r--r-- | src/devices/grotty/tty.cpp | 82 |
2 files changed, 83 insertions, 24 deletions
diff --git a/src/devices/grotty/grotty.man b/src/devices/grotty/grotty.man index bffaac66..be0fb566 100644 --- a/src/devices/grotty/grotty.man +++ b/src/devices/grotty/grotty.man @@ -1,5 +1,6 @@ .ig -Copyright (C) 1989-2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc. +Copyright (C) 1989-2000, 2001, 2002, 2003, 2005, 2006 + Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -64,10 +65,10 @@ and on EBCDIC based hosts. If no files are given, .B grotty -will read the standard input. +reads the standard input. A filename of .B \- -will also cause +also causes .B grotty to read the standard input. Output is written to the standard output. @@ -189,11 +190,11 @@ is a decimal integer. If the 01 bit in .I n is set, -then the font will be treated as an italic font; +then the font is treated as an italic font; if the 02 bit is set, -then it will be treated as a bold font. +then it is treated as a bold font. The code field in the font description field gives the -code which will be used to output the character. +code which is used to output the character. This code can also be used in the .B \[rs]N escape sequence in @@ -231,7 +232,7 @@ Ignore all commands. Without this .B grotty -will render +renders .B \[rs]D'l\|.\|.\|.\&' commands that have at least one zero argument (and so are either horizontal or vertical) @@ -241,11 +242,17 @@ using and .B + characters. +In a similar way, +.B grotty +handles +.B \[rs]D'p\|.\|.\|.\&' +commands which consist entirely of horizontal and vertical lines. +. . .TP .B \-f Use form feeds in the output. -A form feed will be output at the end of each page that has no output +A form feed is output at the end of each page that has no output on its last line. . .TP @@ -406,7 +413,7 @@ Additional klugdey character definitions for use with .LP Note that on EBCDIC hosts, only files for the .B cp1047 -device will be installed. +device is installed. . . . diff --git a/src/devices/grotty/tty.cpp b/src/devices/grotty/tty.cpp index 3896ab4e..be06ea7d 100644 --- a/src/devices/grotty/tty.cpp +++ b/src/devices/grotty/tty.cpp @@ -216,6 +216,9 @@ class tty_printer : public printer { char *make_rgb_string(unsigned int, unsigned int, unsigned int); int tty_color(unsigned int, unsigned int, unsigned int, schar *, schar = DEFAULT_COLOR_IDX); + void line(int, int, int, int, color *, color *); + void draw_line(int *, int, const environment *); + void draw_polygon(int *, int, const environment *); public: tty_printer(const char *); ~tty_printer(); @@ -490,61 +493,110 @@ void tty_printer::change_fill_color(const environment * const env) void tty_printer::draw(int code, int *p, int np, const environment *env) { - if (code != 'l' || !draw_flag) + if (!draw_flag) return; + if (code == 'l') + draw_line(p, np, env); + if (code == 'p') + draw_polygon(p, np, env); +} + +void tty_printer::draw_polygon(int *p, int np, const environment *env) +{ + if (np & 1) { + error("even number of arguments required for polygon"); + return; + } + if (np == 0) { + error("no arguments for polygon"); + return; + } + // We only draw polygons which consist entirely of horizontal and + // vertical lines. + int hpos = 0; + int vpos = 0; + for (int i = 0; i < np; i += 2) { + if (!(p[i] == 0 || p[i + 1] == 0)) + return; + hpos += p[i]; + vpos += p[i + 1]; + } + if (!(hpos == 0 || vpos == 0)) + return; + int start_hpos = env->hpos; + int start_vpos = env->vpos; + hpos = start_hpos; + vpos = start_vpos; + for (int i = 0; i < np; i += 2) { + line(hpos, vpos, p[i], p[i + 1], env->col, env->fill); + hpos += p[i]; + vpos += p[i + 1]; + } + line(hpos, vpos, start_hpos - hpos, start_vpos - vpos, + env->col, env->fill); +} + +void tty_printer::draw_line(int *p, int np, const environment *env) +{ if (np != 2) { error("2 arguments required for line"); return; } - if (p[0] == 0) { + line(env->hpos, env->vpos, p[0], p[1], env->col, env->fill); +} + +void tty_printer::line(int hpos, int vpos, int dx, int dy, + color *col, color *fill) +{ + if (dx == 0) { // vertical line - int v = env->vpos; - int len = p[1]; + int v = vpos; + int len = dy; if (len < 0) { v += len; len = -len; } if (len >= 0 && len <= font::vert) - add_char(vline_char, font::hor, env->hpos, v, env->col, env->fill, + add_char(vline_char, font::hor, hpos, v, col, fill, VDRAW_MODE|START_LINE|END_LINE); else { - add_char(vline_char, font::hor, env->hpos, v, env->col, env->fill, + add_char(vline_char, font::hor, hpos, v, col, fill, VDRAW_MODE|START_LINE); len -= font::vert; v += font::vert; while (len > 0) { - add_char(vline_char, font::hor, env->hpos, v, env->col, env->fill, + add_char(vline_char, font::hor, hpos, v, col, fill, VDRAW_MODE|START_LINE|END_LINE); len -= font::vert; v += font::vert; } - add_char(vline_char, font::hor, env->hpos, v, env->col, env->fill, + add_char(vline_char, font::hor, hpos, v, col, fill, VDRAW_MODE|END_LINE); } } - if (p[1] == 0) { + if (dy == 0) { // horizontal line - int h = env->hpos; - int len = p[0]; + int h = hpos; + int len = dx; if (len < 0) { h += len; len = -len; } if (len >= 0 && len <= font::hor) - add_char(hline_char, font::hor, h, env->vpos, env->col, env->fill, + add_char(hline_char, font::hor, h, vpos, col, fill, HDRAW_MODE|START_LINE|END_LINE); else { - add_char(hline_char, font::hor, h, env->vpos, env->col, env->fill, + add_char(hline_char, font::hor, h, vpos, col, fill, HDRAW_MODE|START_LINE); len -= font::hor; h += font::hor; while (len > 0) { - add_char(hline_char, font::hor, h, env->vpos, env->col, env->fill, + add_char(hline_char, font::hor, h, vpos, col, fill, HDRAW_MODE|START_LINE|END_LINE); len -= font::hor; h += font::hor; } - add_char(hline_char, font::hor, h, env->vpos, env->col, env->fill, + add_char(hline_char, font::hor, h, vpos, col, fill, HDRAW_MODE|END_LINE); } } |