output: Add support for dashed, thick, and thin rules.
[pspp] / src / output / html.c
index 55bcb6daa09d95064e87a6d600c3e83047f8d644..f9d45736ef0fe866537e97a9a068b5664acd68aa 100644 (file)
@@ -361,13 +361,45 @@ escape_string (FILE *file,
     }
 }
 
+static const char *
+border_to_css (int border)
+{
+  switch (border)
+    {
+    case TAL_NONE:
+      return NULL;
+
+    case TAL_SOLID:
+      return "solid";
+
+    case TAL_DASHED:
+      return "dashed";
+
+    case TAL_THICK:
+      return "thick solid";
+
+    case TAL_THIN:
+      return "thin solid";
+
+    case TAL_DOUBLE:
+      return "double";
+
+    default:
+      return NULL;
+    }
+
+}
+
 static void
-put_border (FILE *file, int n_borders, int style, const char *border_name)
+put_border (FILE *file, int *n_borders, int style, const char *border_name)
 {
-  fprintf (file, "%sborder-%s: %s",
-           n_borders == 0 ? " STYLE=\"" : "; ",
-           border_name,
-           style == TAL_1 ? "thin solid" : "double");
+  const char *css = border_to_css (style);
+  if (css)
+    {
+      fprintf (file, "%sborder-%s: %s",
+               (*n_borders)++ == 0 ? " STYLE=\"" : "; ",
+               border_name, css);
+    }
 }
 
 static void
@@ -466,8 +498,8 @@ html_output_table (struct html_driver *html, const struct table_item *item)
           struct table_cell cell;
           const char *tag;
           bool is_header;
-          int alignment, colspan, rowspan;
-          int top, left, right, bottom, n_borders;
+          int colspan, rowspan;
+          int top, left, right, bottom;
 
           table_get_cell (t, x, y, &cell);
           if (x != cell.d[TABLE_HORZ][0] || y != cell.d[TABLE_VERT][0])
@@ -481,12 +513,19 @@ html_output_table (struct html_driver *html, const struct table_item *item)
           tag = is_header ? "TH" : "TD";
           fprintf (html->file, "    <%s", tag);
 
-          alignment = (cell.n_contents > 0
-                       ? cell.contents[0].options & TAB_ALIGNMENT
-                       : TAB_LEFT);
-          if (alignment != TAB_LEFT)
+          int halign = (cell.n_contents > 0
+                        ? cell.contents[0].options & TAB_HALIGN
+                        : TAB_LEFT);
+          if (halign != TAB_LEFT)
+            fprintf (html->file, " ALIGN=\"%s\"",
+                     halign == TAB_RIGHT ? "RIGHT" : "CENTER");
+
+          int valign = (cell.n_contents > 0
+                        ? cell.contents[0].options & TAB_VALIGN
+                        : TAB_LEFT);
+          if (valign != TAB_TOP)
             fprintf (html->file, " ALIGN=\"%s\"",
-                     alignment == TAB_RIGHT ? "RIGHT" : "CENTER");
+                     valign == TAB_BOTTOM ? "BOTTOM" : "MIDDLE");
 
           colspan = table_cell_colspan (&cell);
           if (colspan > 1)
@@ -499,28 +538,24 @@ html_output_table (struct html_driver *html, const struct table_item *item)
          if (html->borders)
            {
              /* Cell borders. */
-             n_borders = 0;
+             int n_borders = 0;
 
              top = table_get_rule (t, TABLE_VERT, x, y);
-             if (top > TAL_0)
-               put_border (html->file, n_borders++, top, "top");
+              put_border (html->file, &n_borders, top, "top");
 
              if (y + rowspan == table_nr (t))
                {
                  bottom = table_get_rule (t, TABLE_VERT, x, y + rowspan);
-                 if (bottom > TAL_0)
-                   put_border (html->file, n_borders++, bottom, "bottom");
+                  put_border (html->file, &n_borders, bottom, "bottom");
                }
 
              left = table_get_rule (t, TABLE_HORZ, x, y);
-             if (left > TAL_0)
-               put_border (html->file, n_borders++, left, "left");
+              put_border (html->file, &n_borders, left, "left");
 
              if (x + colspan == table_nc (t))
                {
                  right = table_get_rule (t, TABLE_HORZ, x + colspan, y);
-                 if (right > TAL_0)
-                   put_border (html->file, n_borders++, right, "right");
+                  put_border (html->file, &n_borders, right, "right");
                }
 
              if (n_borders > 0)