bjori Sun Aug 5 17:47:09 2007 UTC
Modified files:
/phd/include PhDFormat.class.php
/phd/formats xhtml.php
Log:
Improve CALS table rendering
http://cvs.php.net/viewvc.cgi/phd/include/PhDFormat.class.php?r1=1.1&r2=1.2&diff_format=u
Index: phd/include/PhDFormat.class.php
diff -u phd/include/PhDFormat.class.php:1.1 phd/include/PhDFormat.class.php:1.2
--- phd/include/PhDFormat.class.php:1.1 Sun Aug 5 14:49:55 2007
+++ phd/include/PhDFormat.class.php Sun Aug 5 17:47:08 2007
@@ -1,11 +1,12 @@
<?php
-/* $Id: PhDFormat.class.php,v 1.1 2007/08/05 14:49:55 bjori Exp $ */
+/* $Id: PhDFormat.class.php,v 1.2 2007/08/05 17:47:08 bjori Exp $ */
abstract class PhDFormat {
private $reader;
private $IDs = array();
private $IDMap = array();
- protected $ext = "";
+ private $TABLE = array();
+ protected $ext = "";
/* abstract */ protected $map = array();
public function __construct(PhDReader $reader, array $IDs, array $IDMap,
$ext) {
@@ -55,9 +56,55 @@
abstract public function transformFromMap($open, $tag, $name);
abstract public function CDATA($data);
abstract public function __call($func, $args);
+
+ /* Table helper functions */
+ public function tgroup() {
+ $attrs = self::getAttributes();
+
+ $this->TABLE["cols"] = $attrs["cols"];
+ unset($attrs["cols"]);
+
+ $this->TABLE["defaults"] = $attrs;
+ $this->TABLE["colspec"] = array();
+
+ return $attrs;
+ }
+ public function colspec() {
+ /* defaults */
+ $defaults["colname"] = count($this->TABLE["colspec"])+1;
+ $defaults["colnum"] = count($this->TABLE["colspec"])+1;
+ $defaults["align"] = "left";
+
+ $attrs = self::getAttributes();
+ $colspec = array_merge($defaults, $this->TABLE["defaults"], $attrs);
+
+ $this->TABLE["colspec"][$colspec["colnum"]] = $colspec;
+ return $colspec;
+ }
+ public function valign() {
+ $valign = self::readAttribute("valign");
+ return $valign ? $valign : "middle";
+ }
+ public function colspan() {
+ if ($start = $this->readAttribute("namest")) {
+ $from = array_search($start, $this->TABLE["colspec"]);
+ $end = $this->readAttribute("nameend");
+ $to = array_search($end, $this->TABLE["colspec"]);
+ return $end-$to;
+ }
+ return 1;
+ }
+ public function rowspan() {
+ $rows = 1;
+ if ($morerows = $this->readAttribute("morerows")) {
+ $rows += $morerows;
+ }
+ return $rows;
+ }
+
}
/*
-* vim600: sw=4 ts=4 fdm=syntax syntax=php et
-* vim<600: sw=4 ts=4
-*/
+ * vim600: sw=4 ts=4 fdm=syntax syntax=php et
+ * vim<600: sw=4 ts=4
+ */
http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.8&r2=1.9&diff_format=u
Index: phd/formats/xhtml.php
diff -u phd/formats/xhtml.php:1.8 phd/formats/xhtml.php:1.9
--- phd/formats/xhtml.php:1.8 Sun Aug 5 14:49:55 2007
+++ phd/formats/xhtml.php Sun Aug 5 17:47:09 2007
@@ -1,5 +1,5 @@
<?php
-/* $Id: xhtml.php,v 1.8 2007/08/05 14:49:55 bjori Exp $ */
+/* $Id: xhtml.php,v 1.9 2007/08/05 17:47:09 bjori Exp $ */
class XHTMLPhDFormat extends PhDFormat {
protected $map = array( /* {{{ */
@@ -36,13 +36,13 @@
'constant' => 'span',
'emphasis' => 'em',
'enumname' => 'span',
- 'entry' => array(
+ 'entry' => array (
/* DEFAULT */ 'format_entry',
'row' => array(
- /* DEFAULT */ 'format_row_entry',
- 'thead' => 'format_thead_entry',
- 'tfoot' => 'format_tfoot_entry',
- 'tbody' => 'format_tbody_entry',
+ /* DEFAULT */ 'format_entry',
+ 'thead' => 'format_th_entry',
+ 'tfoot' => 'format_th_entry',
+ 'tbody' => 'format_entry',
),
),
'envar' => 'span',
@@ -298,8 +298,6 @@
}
- /* TODO: Move the logic to PhDFormat? */
- /* NOTE: This is not a full implementation, just a proof-of-concept */
public function format_table($open, $name) {
if ($open) {
return '<table border="5">';
@@ -308,72 +306,63 @@
}
public function format_tgroup($open, $name) {
if ($open) {
- $this->TABLE_COLS = $this->readAttribute("cols");
- $this->COLSPEC = array();
+ $attrs = PhDFormat::tgroup();
return "<colgroup>\n";
}
return "</colgroup>\n";
}
public function format_colspec($open, $name) {
if ($open) {
- $colname = $this->readAttribute("colname");
- if ($colnum = $this->readAttribute("colnum")) {
- $this->COLSPEC[$colnum] = $colname;
- } else {
- $count = count($this->COLSPEC);
- $this->COLSPEC[$count] = $colname;
+ $colspec = PhDFormat::colspec();
+
+ $moreattr = "";
+ if ($colspec["align"] == "char" && isset($colspec["char"])) {
+ $moreattr .= sprintf(' char="%s"',
htmlspecialchars($colspec["char"], ENT_QUOTES));
+ if (isset($colspec["charoff"])) {
+ $moreattr .= sprintf(' charoff="%s"',
htmlspecialchars($colspec["charoff"], ENT_QUOTES));
+ }
+ }
+ if (isset($colspec["colwidth"])) {
+ $moreattr .= sprintf(' width="%d"', $colspec["colwidth"]);
}
- return "<col />"; // Probably throw in couple of width and align
attributes
+
+ return sprintf('<col align="%s"%s />', $colspec["align"],
$moreattr);
}
/* noop */
}
public function format_thead($open, $name) {
if ($open) {
- return "<thead>";
+ $valign = PhDFormat::valign();
+ return sprintf('<thead valign="%s">', $valign);
}
- return "</thread>\n";
+ return "</thead>\n";
}
public function format_tbody($open, $name) {
if ($open) {
- return "<tbody>";
+ $valign = PhDFormat::valign();
+ return sprintf('<tbody valign="%s">', $valign);
}
return "</tbody>";
}
public function format_row($open, $name) {
if ($open) {
- return "<tr>\n";
+ $valign = PhDFormat::valign();
+ return sprintf('<tr valign="%s">', $valign);
}
return "</tr>\n";
}
- public function format_thead_entry($open, $name) {
+ public function format_th_entry($open, $name) {
if ($open) {
- if ($start = $this->readAttribute("namest")) {
- $from = array_search($start, $this->COLSPEC);
- $end = $this->readAttribute("nameend");
- $to = array_search($end, $this->COLSPEC);
- return sprintf('<th colspan="%d">', $end-$to);
- }
- return '<th>';
+ $colspan = PhDFormat::colspan();
+ return sprintf('<th colspan="%d">', $colspan);
}
return '</th>';
}
- public function format_tfoot_entry($open, $name) {
- return $this->format_thead_entry($open, $name);
- }
- public function format_tbody_entry($open, $name) {
+ public function format_entry($open, $name) {
if ($open) {
- $colspan = 1;
- $rows = 1;
- if ($start = $this->readAttribute("namest")) {
- $from = array_search($start, $this->COLSPEC);
- $end = $this->readAttribute("nameend");
- $to = array_search($end, $this->COLSPEC);
- $colspan = $to-$from+1;
- }
- if ($morerows = $this->readAttribute("morerows")) {
- $rows += $morerows;
- }
- return sprintf('<td colspan="%d" rowspan="%d">', $colspan, $rows);
+ $colspan = PhDFormat::colspan();
+ $rowspan = PhDFormat::rowspan();
+ return sprintf('<td colspan="%d" rowspan="%d">', $colspan,
$rowspan);
}
return "</td>";
}
@@ -381,7 +370,7 @@
}
/*
-* vim600: sw=4 ts=4 fdm=syntax syntax=php et
-* vim<600: sw=4 ts=4
-*/
+ * vim600: sw=4 ts=4 fdm=syntax syntax=php et
+ * vim<600: sw=4 ts=4
+ */