diff options
author | wlemb <wlemb> | 2002-03-01 01:15:35 +0000 |
---|---|---|
committer | wlemb <wlemb> | 2002-03-01 01:15:35 +0000 |
commit | 914f0e84c080380ef6008eb62468753a7fe418d1 (patch) | |
tree | 3f219f9778416a1ff9e43ca10ee7c53480754272 /src | |
parent | c5da16c6d8ad7c942acdf7ce20a1da13068c9962 (diff) | |
download | groff-914f0e84c080380ef6008eb62468753a7fe418d1.tar.gz |
Add color support to grodvi (for drawing colors are currently
translated to gray values).
* src/devices/grodvi/dvi.cc (FILL_MAX): Removed.
(dvi_printer): Add `cur_color' member.
(dvi_printer::set_color): New function.
(draw_dvi_printer): Remove `fill'.
(draw_dvi_printer::fill_next): Pass environment as parameter.
Update code for new color support translated to gray.
(dvi_printer::set_char): Updated.
(dvi_printer::begin_page, dvi_printer::end_page): Handle color
changes crossing the page border.
(dvi_printer::draw): Updated.
Remove cases `f' and `F'.
* tmac/dvi.tmac: Add color definitions.
* NEWS, src/devices/grodvi/grodvi.man: Updated.
* tmac/an-old.tmac (R): Make this a macro to emit a warning if
used incorrectly.
* aclocal.m4 (GROFF_NEED_DECLARATION): Use test similar to recent
versions of autoconf.
* configure: Updated.
* doc/homepage.ms: Use `.blm'.
* tmac/www.tmac (www-depth): New auxiliary variable.
(www-pop-level): Don't issue HTML tag.
(ULS, ULE, LI): Use absolute indentation.
* src/devices/grops/ps.cc (ps_printer::begin_page,
ps_printer::end_page): Switch forth and back to default color while
starting a new page.
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/grodvi/dvi.cc | 85 | ||||
-rw-r--r-- | src/devices/grodvi/grodvi.man | 11 | ||||
-rw-r--r-- | src/devices/grops/ps.cc | 3 |
3 files changed, 72 insertions, 27 deletions
diff --git a/src/devices/grodvi/dvi.cc b/src/devices/grodvi/dvi.cc index 9e80b266..84126366 100644 --- a/src/devices/grodvi/dvi.cc +++ b/src/devices/grodvi/dvi.cc @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -44,8 +44,6 @@ width in the tfm file. */ #define SIZESCALE 100 #define MULTIPLIER 1 -#define FILL_MAX 1000 - class dvi_font : public font { dvi_font(const char *); public: @@ -123,6 +121,7 @@ class dvi_printer : public printer { output_font output_font_table[FONTS_MAX]; font *cur_font; int cur_point_size; + color cur_color; int pushed; int pushed_h; int pushed_v; @@ -132,6 +131,7 @@ class dvi_printer : public printer { void define_font(int); void set_font(int); void possibly_begin_line(); + void set_color(color *); protected: enum { id_byte = 2, @@ -179,9 +179,8 @@ public: class draw_dvi_printer : public dvi_printer { int output_pen_size; - int fill; void set_line_thickness(const environment *); - void fill_next(); + void fill_next(const environment *); public: draw_dvi_printer(); ~draw_dvi_printer(); @@ -214,7 +213,7 @@ dvi_printer::~dvi_printer() draw_dvi_printer::draw_dvi_printer() -: output_pen_size(-1), fill(FILL_MAX) +: output_pen_size(-1) { } @@ -302,9 +301,45 @@ int scale(int x, int z) return sw; } +void dvi_printer::set_color(color *col) +{ + cur_color = *col; + char buf[256]; + unsigned int components[4]; + color_scheme cs = col->get_components(components); + switch (cs) { + case DEFAULT: + sprintf(buf, "color gray 0"); + break; + case RGB: + sprintf(buf, "color rgb %.3g %.3g %.3g", + double(Red) / color::MAX_COLOR_VAL, + double(Green) / color::MAX_COLOR_VAL, + double(Blue) / color::MAX_COLOR_VAL); + break; + case CMY: + col->get_cmyk(&Cyan, &Magenta, &Yellow, &Black); + // fall through + case CMYK: + sprintf(buf, "color cmyk %.3g %.3g %.3g %.3g", + double(Cyan) / color::MAX_COLOR_VAL, + double(Magenta) / color::MAX_COLOR_VAL, + double(Yellow) / color::MAX_COLOR_VAL, + double(Black) / color::MAX_COLOR_VAL); + break; + case GRAY: + sprintf(buf, "color gray %.3g", + double(Gray) / color::MAX_COLOR_VAL); + break; + } + do_special(buf); +} -void dvi_printer::set_char(int index, font *f, const environment *env, int w, const char *name) +void dvi_printer::set_char(int index, font *f, const environment *env, + int w, const char *name) { + if (*env->col != cur_color) + set_color(env->col); int code = f->get_code(index); if (env->size != cur_point_size || f != cur_font) { cur_font = f; @@ -345,7 +380,7 @@ void dvi_printer::set_char(int index, font *f, const environment *env, int w, co possibly_begin_line(); end_h = env->hpos + w; cur_h += scale(f->get_width(index, UNITWIDTH)/MULTIPLIER, - cur_point_size*RES_7227); + cur_point_size*RES_7227); if (cur_h > max_h) max_h = cur_h; if (cur_v > max_v) @@ -464,6 +499,8 @@ void dvi_printer::begin_page(int i) out4(0); out4(last_bop); last_bop = tem; + if (cur_color != default_color) + set_color(&cur_color); // By convention position (0,0) in a dvi file is placed at (1in, 1in). cur_h = font::res; cur_v = font::res; @@ -472,6 +509,7 @@ void dvi_printer::begin_page(int i) void dvi_printer::end_page(int) { + set_color(&default_color); if (pushed) end_of_line(); out1(eop); @@ -629,10 +667,17 @@ void draw_dvi_printer::set_line_thickness(const environment *env) } } -void draw_dvi_printer::fill_next() +void draw_dvi_printer::fill_next(const environment *env) { + unsigned int g; + if (env->fill->is_default()) + g = 0; + else { + // currently, only BW support + env->fill->get_gray(&g); + } char buf[256]; - sprintf(buf, "sh %.3f", double(fill)/FILL_MAX); + sprintf(buf, "sh %.3g", 1 - double(g)/color::MAX_COLOR_VAL); do_special(buf); } @@ -652,7 +697,7 @@ void draw_dvi_printer::draw(int code, int *p, int np, const environment *env) } moveto(env->hpos+p[0]/2, env->vpos); if (fill_flag) - fill_next(); + fill_next(env); else set_line_thickness(env); int rad; @@ -685,7 +730,7 @@ void draw_dvi_printer::draw(int code, int *p, int np, const environment *env) } moveto(env->hpos+p[0]/2, env->vpos); if (fill_flag) - fill_next(); + fill_next(env); sprintf(buf, "%s 0 0 %d %d 0 6.28319", (fill_flag ? "ia" : "ar"), milliinches(p[0]/2), @@ -707,7 +752,7 @@ void draw_dvi_printer::draw(int code, int *p, int np, const environment *env) } moveto(env->hpos, env->vpos); if (fill_flag) - fill_next(); + fill_next(env); else set_line_thickness(env); do_special("pa 0 0"); @@ -790,20 +835,6 @@ void draw_dvi_printer::draw(int code, int *p, int np, const environment *env) } break; } - case 'f': - { - if (np != 1 && np != 2) { - error("1 argument required for fill"); - break; - } - fill = p[0]; - if (fill < 0 || fill > FILL_MAX) - fill = FILL_MAX; - break; - } - case 'F': - // not implemented yet - break; case 'R': { if (np != 2) { diff --git a/src/devices/grodvi/grodvi.man b/src/devices/grodvi/grodvi.man index 0a21d454..3704c2ec 100644 --- a/src/devices/grodvi/grodvi.man +++ b/src/devices/grodvi/grodvi.man @@ -137,6 +137,17 @@ These are automatically generated by .B tfmtodit. . .LP +The default color for +.B \[rs]m +and +.B \[rs]M +is black. +. +Currently, the drawing color for +.B \[rs]D +commands is always black, and fill color values are translated to gray. +. +.LP In .B troff the diff --git a/src/devices/grops/ps.cc b/src/devices/grops/ps.cc index 2d6abf93..07aa8ae3 100644 --- a/src/devices/grops/ps.cc +++ b/src/devices/grops/ps.cc @@ -1144,11 +1144,14 @@ void ps_printer::begin_page(int n) out.simple_comment("BeginPageSetup") .put_symbol("BP") .simple_comment("EndPageSetup"); + if (sbuf_color != default_color) + set_color(&sbuf_color); } void ps_printer::end_page(int) { flush_sbuf(); + set_color(&default_color); out.put_symbol("EP"); if (invis_count != 0) { error("missing `endinvis' command"); |