TITLE:P表組書式の導入
#indent
#contents
//-- convert_html L498 L507 L530 L636 L668
////////////////////////////////////////////////////////////////
* 方針 [#c85e18a7]
- 便宜上、行頭が「##|##」の表を「P表組/Pipe表組」、行頭が「##,##」の表を「C表組/Comma表組」で区別する。
- P表組では、縦方向の関連性が強いので、空白による整列はコードの可読性向上に必要。
-- セル内容の前後の空白は無視すべき。
- P表組では、行方向のセル連結は右方向(##&>;##)でも良いが、左方向の連結も必要。
-- コードは左から右、上から下に向かって読むもの。列方向と同様、結合記号より先にセル内容を記述すべき。
- 「##&~;##」は列方向のセル連結と、ヘッダ(##th##)の2つの意味がある上、空白による整列を許すと構文が衝突する。
-- 「##&>;##」からの連想で、左向き連結に「##&<;##」を、上向き連結に「##&^;##」を導入。
-- 「*」などからの連想で、ヘッダに「##&^;##」を導入。
////////////////////////////////////////////////////////////////
* 仕様 [#o85fbc27]
- セル内の先頭と末尾の空白を無視。
- 「##&>;##」のみのセルは右のセルに連結。
- 「##&^;##」のみのセルは上のセルに連結。
- 「##&<;##」のみのセルは左のセルに連結。(互換仕様)
- 「##&~;##」のみのセルは上のセルに連結。(互換仕様)
- 「##&*;##」で始まるセルはヘッダ(##th##)。
- 「##&~;##」で始まる非空白セルはヘッダ(##th##)。(互換仕様)
////////////////////////////////////////////////////////////////
* 課題 [#ld209315]
- レイアウト上、## |>|xxxx|<| ## のように、連結セルの内容を真ん中に書く「左右挟み連結」ができると便利かも。
- 左からのスキャンと右からのスキャンを纏められると精神的に宜しいかも。
////////////////////////////////////////////////////////////////
* 改造 [#l46a1161]
- ##convert_html.php## の ##class TableCell## にて、
#code(diff){{{{
class TableCell extends Element
{
var $tag = 'td'; // {td|th}
+ var $colleft = 0; // ==0: colspan to right by '>'; ==1: colspan to left by '<';
var $colspan = 1;
var $rowspan = 1;
var $style; // is array('width'=>, 'align'=>...);
}}}}
-- ##$colleft##は行結合方向を表す変数。
--- ##$colleft = 0## ⇔ 左に連結。
--- ##$colleft = 1## ⇔ 右に連結。
- 同クラスの##function TableCell## にて、
#code(diff){{{{
function TableCell($text, $is_template = FALSE)
{
parent::Element();
$this->style = $matches = array();
+ $text = trim($text);
}}}}
-- ##trim## でセル先頭と末尾の空白を除去。
- 同関数 セル結合の分岐にて、
#code(diff){{{{
if ($text == '>') {
+ $this->colleft = 0;
$this->colspan = 0;
+ } else if ($text == '<') {
+ $this->colleft = 1;
+ $this->colspan = 0;
- } else if ($text == '~') {
+ } else if ($text == '^' || $text == '~') {
$this->rowspan = 0;
- } else if (substr($text, 0, 1) == '~') {
+ } else if (substr($text, 0, 1) == '*' || substr($text, 0, 1) == '~') {
$this->tag = 'th';
$text = substr($text, 1);
}
}}}}
-- ##$this->colleft## の追加は連結向きの指定。
-- ##if ($text == '<')## は左向き連結。
-- ##$text == '^' || ## は上向き連結。
-- ##substr($text, 0, 1) == '*' ||## はヘッダ。
- 同関数 セル結合ループにて、右向き連結のオリジナルに対して変更し、さらに左向き連結用に''コピー''、
#code(diff){{{{
! // Set colspan and style, from right to left.
+ $stylerow = NULL;
+ foreach (array_keys($this->elements) as $nrow) {
+ $row = & $this->elements[$nrow];
+ if ($this->types[$nrow] == 'c')
+ $stylerow = & $row;
+ $colspan = 1;
! foreach (array_reverse(array_keys($row)) as $ncol) {
! if ($row[$ncol]->colspan == 0 && $row[$ncol]->colleft == 1) {
+ ++$colspan;
+ continue;
+ }
+ if ($row[$ncol]->colspan > 0 && $row[$ncol]->$colspan < $colspan) {
+ $row[$ncol]->colspan = $colspan;
+ }
+ if ($stylerow !== NULL) {
+ $row[$ncol]->setStyle($stylerow[$ncol]->style);
+ // Inherits column style
+ while (--$colspan)
! $row[$ncol + $colspan]->setStyle($stylerow[$ncol]->style);
+ }
+ $colspan = 1;
+ }
+ }
- // Set colspan and style
+ // Set colspan and style, from left to right.
$stylerow = NULL;
foreach (array_keys($this->elements) as $nrow) {
$row = & $this->elements[$nrow];
if ($this->types[$nrow] == 'c')
$stylerow = & $row;
$colspan = 1;
foreach (array_keys($row) as $ncol) {
- if ($row[$ncol]->colspan == 0) {
+ if ($row[$ncol]->colspan == 0 && $row[$ncol]->colleft == 0) {
++$colspan;
continue;
}
+ if ($row[$ncol]->colspan > 0 && $row[$ncol]->colspan < $colspan) {
$row[$ncol]->colspan = $colspan;
+ }
if ($stylerow !== NULL) {
$row[$ncol]->setStyle($stylerow[$ncol]->style);
// Inherits column style
while (--$colspan)
$row[$ncol - $colspan]->setStyle($stylerow[$ncol]->style);
}
$colspan = 1;
}
}
}}}}
-- 「##!##」で始まる行は、コピーからの差分。
-- 内側ループ ##foreach (array_reverse(array_keys($row)) as $ncol)## の ##array_reverse## でスキャン向きを反転する仕組み。
-- ##$row[$ncol + $colspan]->setStyle($stylerow[$ncol]->style);## の符号 ##+## は連結方向の影響。
////////////////////////////////////////////////////////////////
* コメント
#pcomment
////////////////////////////////////////////////////////////////