summaryrefslogtreecommitdiff
path: root/src/devices/grohtml/html-table.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/grohtml/html-table.cpp')
-rw-r--r--src/devices/grohtml/html-table.cpp128
1 files changed, 97 insertions, 31 deletions
diff --git a/src/devices/grohtml/html-table.cpp b/src/devices/grohtml/html-table.cpp
index 7e5b2dc5..c752b766 100644
--- a/src/devices/grohtml/html-table.cpp
+++ b/src/devices/grohtml/html-table.cpp
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
*
* Gaius Mulley (gaius@glam.ac.uk) wrote html-table.cpp
*
@@ -41,6 +41,9 @@ Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
# define FALSE (1==0)
#endif
+extern html_dialect dialect;
+
+
tabs::tabs ()
: tab(NULL)
{
@@ -294,7 +297,7 @@ void html_table::set_linelength (int linelen)
}
p = c;
}
- if (p != NULL && p->right > 0)
+ if (p != NULL && p->right > 0 && linelength > p->right)
add_column(p->no+1, p->right, linelength, 'L');
}
@@ -337,10 +340,12 @@ void html_table::emit_table_header (int space)
out->nl();
out->put_string("<table width=\"100%\"")
- .put_string(" border=0 rules=\"none\" frame=\"void\"\n")
+ .put_string(" border=\"0\" rules=\"none\" frame=\"void\"\n")
.put_string(" cellspacing=\"0\" cellpadding=\"0\"");
out->put_string(">")
.nl();
+ if (dialect == xhtml)
+ emit_colspan();
out->put_string("<tr valign=\"top\" align=\"left\"");
if (space) {
out->put_string(" style=\"margin-top: ");
@@ -375,6 +380,82 @@ void html_table::set_space (int space)
}
/*
+ * emit_colspan - emits a series of colspan entries defining the
+ * table columns.
+ */
+
+void html_table::emit_colspan (void)
+{
+ cols *b = columns;
+ cols *c = columns;
+ int width = 0;
+
+ out->put_string("<colgroup>");
+ while (c != NULL) {
+ if (b != NULL && b != c && is_gap(b))
+ /*
+ * blank column for gap
+ */
+ out->put_string("<col width=\"")
+ .put_number(is_gap(b))
+ .put_string("%\" class=\"center\"></col>")
+ .nl();
+
+ width = (get_right(c)*100 + get_effective_linelength()/2)
+ / get_effective_linelength()
+ - (c->left*100 + get_effective_linelength()/2)
+ /get_effective_linelength();
+ switch (c->alignment) {
+ case 'C':
+ out->put_string("<col width=\"")
+ .put_number(width)
+ .put_string("%\" class=\"center\"></col>")
+ .nl();
+ break;
+ case 'R':
+ out->put_string("<col width=\"")
+ .put_number(width)
+ .put_string("%\" class=\"right\"></col>")
+ .nl();
+ break;
+ default:
+ out->put_string("<col width=\"")
+ .put_number(width)
+ .put_string("%\"></col>")
+ .nl();
+ }
+ b = c;
+ c = c->next;
+ }
+ out->put_string("</colgroup>").nl();
+}
+
+/*
+ * emit_td - writes out a <td> tag with a corresponding width
+ * if the dialect is html4.
+ */
+
+void html_table::emit_td (int percentage, const char *s)
+{
+ if (percentage) {
+ if (dialect == html4) {
+ out->put_string("<td width=\"")
+ .put_number(percentage)
+ .put_string("%\"");
+ if (s != NULL)
+ out->put_string(s);
+ out->nl();
+ }
+ else {
+ out->put_string("<td");
+ if (s != NULL)
+ out->put_string(s);
+ out->nl();
+ }
+ }
+}
+
+/*
* emit_col - moves onto column, n.
*/
@@ -405,11 +486,7 @@ void html_table::emit_col (int n)
// have we a gap?
if (last_col != NULL) {
- if (is_gap(b))
- out->put_string("<td width=\"")
- .put_number(is_gap(b))
- .put_string("%\"></td>")
- .nl();
+ emit_td(is_gap(b), "></td>");
b = b->next;
}
@@ -421,17 +498,9 @@ void html_table::emit_col (int n)
/ get_effective_linelength()
- (b->left*100 + get_effective_linelength()/2)
/get_effective_linelength();
- if (width)
- out->put_string("<td width=\"")
- .put_number(width)
- .put_string("%\"></td>")
- .nl();
+ emit_td(width, "></td>");
// have we a gap?
- if (is_gap(b))
- out->put_string("<td width=\"")
- .put_number(is_gap(b))
- .put_string("%\"></td>")
- .nl();
+ emit_td(is_gap(b), "></td>");
b = b->next;
}
width = (get_right(b)*100 + get_effective_linelength()/2)
@@ -440,22 +509,13 @@ void html_table::emit_col (int n)
/get_effective_linelength();
switch (b->alignment) {
case 'C':
- out->put_string("<td width=\"")
- .put_number(width)
- .put_string("%\" align=center>")
- .nl();
+ emit_td(width, " align=center>");
break;
case 'R':
- out->put_string("<td width=\"")
- .put_number(width)
- .put_string("%\" align=right>")
- .nl();
+ emit_td(width, " align=right>");
break;
default:
- out->put_string("<td width=\"")
- .put_number(width)
- .put_string("%\">")
- .nl();
+ emit_td(width);
}
// remember column, b
last_col = b;
@@ -477,7 +537,13 @@ void html_table::finish_row (void)
if (n > 0)
emit_col(n);
- out->put_string("</td>").nl();
+#if 1
+ if (last_col != NULL) {
+ out->put_string("</td>");
+ last_col = NULL;
+ }
+#endif
+ out->put_string("</tr>").nl();
}
}