[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Groff] patch to fix color in grohtml
From: |
Gaius Mulley |
Subject: |
[Groff] patch to fix color in grohtml |
Date: |
Mon, 28 Jan 2002 18:51:48 +0000 |
Hi Werner,
here is a patch to fix color in grohtml.
enjoy...
Gaius
--- groff-cvs/src/devices/grohtml/post-html.cc Thu Jan 24 22:37:31 2002
+++ groff-html/src/devices/grohtml/post-html.cc Mon Jan 28 18:30:59 2002
@@ -220,9 +220,9 @@
int font_no;
int height;
int slant;
- color *col;
+ color col;
style ();
- style (font *, int, int, int, int, color *);
+ style (font *, int, int, int, int, color);
int operator == (const style &) const;
int operator != (const style &) const;
};
@@ -232,7 +232,7 @@
{
}
-style::style(font *p, int sz, int h, int sl, int no, color *c)
+style::style(font *p, int sz, int h, int sl, int no, color c)
: f(p), point_size(sz), font_no(no), height(h), slant(sl), col(c)
{
}
@@ -1208,10 +1208,7 @@
void flush_font (void);
void add_to_sbuf (unsigned char code, const string &s);
void write_title (int in_head);
- void determine_diacritical_mark (const char *name, const environment
*env);
int sbuf_continuation (unsigned char code, const char *name,
const environment *env, int w);
- char *remove_last_char_from_sbuf ();
- int seen_backwards_escape (char *s, int l);
void flush_page (void);
void troff_tag (text_glob *g);
void flush_globs (void);
@@ -1257,7 +1254,6 @@
font *make_bold (font *f);
int overstrike (unsigned char code, const char *name,
const environment *env, int w);
void do_body (void);
-
// ADD HERE
public:
@@ -2227,9 +2223,7 @@
if (output_style.col != g->text_style.col) {
current_paragraph->done_color();
output_style.col = g->text_style.col;
- if (output_style.col != 0) {
- current_paragraph->do_color(output_style.col);
- }
+ current_paragraph->do_color(&output_style.col);
}
}
@@ -2412,7 +2406,10 @@
break;
case 'F':
// fill with color env->fill
- background = env->fill;
+ if (background != NULL)
+ delete background;
+ background = new color;
+ *background = *env->fill;
break;
default:
@@ -2593,7 +2590,7 @@
{
unsigned char code = f->get_code(i);
- style sty(f, env->size, env->height, env->slant, env->fontno, env->col);
+ style sty(f, env->size, env->height, env->slant, env->fontno, *env->col);
if (sty.slant != 0) {
if (sty.slant > 80 || sty.slant < -80) {
error("silly slant `%1' degrees", sty.slant);
@@ -2779,7 +2776,7 @@
flush_sbuf();
if (env->fontno >= 0) {
style sty(get_font_from_index(env->fontno), env->size, env->height,
- env->slant, env->fontno, env->col);
+ env->slant, env->fontno, *env->col);
sbuf_style = sty;
}
--- groff-cvs/src/devices/grohtml/html-text.cc Thu Jan 24 22:37:31 2002
+++ groff-html/src/devices/grohtml/html-text.cc Mon Jan 28 18:30:25 2002
@@ -40,6 +40,7 @@
#include "html-text.h"
+#undef DEBUGGING
html_text::html_text (simple_output *op) :
stackptr(NULL), lastptr(NULL), out(op), space_emitted(TRUE),
@@ -52,6 +53,78 @@
flush_text();
}
+
+#if defined(DEBUGGING)
+static int debugStack = FALSE;
+
+
+/*
+ * turnDebug - flip the debugStack boolean and return new value.
+ */
+
+static int turnDebug (void)
+{
+ debugStack = 1-debugStack;
+ return debugStack;
+}
+
+/*
+ * dump_stack_element - display an element of the html stack, p.
+ */
+
+void html_text::dump_stack_element (tag_definition *p)
+{
+ fprintf(stderr, " | ");
+ switch (p->type) {
+
+ case P_TAG: fprintf(stderr, "<P %s>", (char *)p->arg1); break;
+ case I_TAG: fprintf(stderr, "<I>"); break;
+ case B_TAG: fprintf(stderr, "<B>"); break;
+ case SUB_TAG: fprintf(stderr, "<SUB>"); break;
+ case SUP_TAG: fprintf(stderr, "<SUP>"); break;
+ case TT_TAG: fprintf(stderr, "<TT>"); break;
+ case PRE_TAG: fprintf(stderr, "<PRE>"); break;
+ case SMALL_TAG: fprintf(stderr, "<SMALL>"); break;
+ case BIG_TAG: fprintf(stderr, "<BIG>"); break;
+ case BREAK_TAG: fprintf(stderr, "<BREAK>"); break;
+ case TABLE_TAG: fprintf(stderr, "<TABLE>"); break;
+ case COLOR_TAG: {
+ if (p->col.is_default())
+ fprintf(stderr, "<COLOR (default)>");
+ else {
+ unsigned int r, g, b;
+
+ p->col.get_rgb(&r, &g, &b);
+ fprintf(stderr, "<COLOR %x %x %x>", r/0x101, g/0x101, b/0x101);
+ }
+ break;
+ }
+ default: fprintf(stderr, "unknown tag");
+ }
+}
+
+/*
+ * dump_stack - debugging function only.
+ */
+
+void html_text::dump_stack (void)
+{
+ if (debugStack) {
+ tag_definition *p = stackptr;
+
+ while (p != NULL) {
+ dump_stack_element(p);
+ p = p->next;
+ }
+ fprintf(stderr, "\n");
+ fflush(stderr);
+ }
+}
+#else
+void html_text::dump_stack (void) {}
+#endif
+
+
/*
* end_tag - shuts down the tag.
*/
@@ -141,7 +214,7 @@
case BIG_TAG: issue_tag("<big", (char *)t->arg1); break;
case TABLE_TAG: issue_table_begin((char *)t->arg1); break;
case BREAK_TAG: break;
- case COLOR_TAG: issue_color_begin((color *)t->arg1); break;
+ case COLOR_TAG: issue_color_begin(&t->col); break;
default:
error("unrecognised tag");
@@ -221,17 +294,18 @@
return( FALSE );
}
+
/*
- * push_para - adds a new entry onto the html paragraph stack.
+ * do_push - places, tag_definition, p, onto the stack
*/
-void html_text::push_para (HTML_TAG t, void *arg)
+void html_text::do_push (tag_definition *p)
{
- tag_definition *p=(tag_definition *)malloc(sizeof(tag_definition));
+ HTML_TAG t = p->type;
- p->type = t;
- p->arg1 = arg;
- p->text_emitted = FALSE;
+#if defined(DEBUGGING)
+ dump_stack();
+#endif
/*
* if t is a P_TAG or TABLE_TAG or PRE_TAG make sure it goes on the end of
the stack.
@@ -278,6 +352,24 @@
lastptr = p;
stackptr = p;
}
+#if defined(DEBUGGING)
+ dump_stack();
+#endif
+}
+
+/*
+ * push_para - adds a new entry onto the html paragraph stack.
+ */
+
+void html_text::push_para (HTML_TAG t, void *arg)
+{
+ tag_definition *p=(tag_definition *)malloc(sizeof(tag_definition));
+
+ p->type = t;
+ p->arg1 = arg;
+ p->text_emitted = FALSE;
+
+ do_push(p);
}
void html_text::push_para (HTML_TAG t)
@@ -285,6 +377,18 @@
push_para(t, (void *)"");
}
+void html_text::push_para (color *c)
+{
+ tag_definition *p=(tag_definition *)malloc(sizeof(tag_definition));
+
+ p->type = COLOR_TAG;
+ p->arg1 = NULL;
+ p->col = *c;
+ p->text_emitted = FALSE;
+
+ do_push(p);
+}
+
/*
* do_indent - remember the indent parameters and if
* indent is > pageoff and indent has changed
@@ -409,10 +513,8 @@
void html_text::do_color (color *c)
{
- if (c != 0) {
- shutdown(COLOR_TAG); // shutdown a previous color tag, if present
- push_para(COLOR_TAG, (void *)c);
- }
+ shutdown(COLOR_TAG); // shutdown a previous color tag, if present
+ push_para(c);
}
/*
@@ -479,7 +581,10 @@
* and restore unaffected tags
*/
while (temp != NULL) {
- push_para(temp->type, temp->arg1);
+ if (temp->type == COLOR_TAG)
+ push_para(&temp->col);
+ else
+ push_para(temp->type, temp->arg1);
p = temp;
temp = temp->next;
free(p);
@@ -629,7 +734,7 @@
}
/*
- * do_para- starts a new paragraph
+ * do_para - starts a new paragraph
*/
void html_text::do_para (const char *arg)
--- groff-cvs/src/devices/grohtml/html-text.h Thu Dec 6 10:03:22 2001
+++ groff-html/src/devices/grohtml/html-text.h Mon Jan 28 18:30:47 2002
@@ -39,6 +39,7 @@
HTML_TAG type;
void *arg1;
int text_emitted;
+ color col;
tag_definition *next;
} tag_definition ;
@@ -102,6 +103,8 @@
void start_tag (tag_definition *t);
void push_para (HTML_TAG t, void *arg);
void push_para (HTML_TAG t);
+ void push_para (color *c);
+ void do_push (tag_definition *p);
char *shutdown (HTML_TAG t);
void check_emit_text (tag_definition *t);
int remove_break (void);
@@ -111,4 +114,6 @@
void issue_table_end (void);
int table_is_void (tag_definition *t);
void remove_def (tag_definition *t);
+ void dump_stack_element(tag_definition *p);
+ void dump_stack (void);
};
- [Groff] patch to fix color in grohtml,
Gaius Mulley <=