com web/pres2: Table support: pres2reveal

[email protected] (Rasmus Lerdorf) Thu, 25 Oct 2018 10:17:51 +0000
Newsgroups php.pres
Message-ID <[email protected]>
Commit:    42ba4a021e99823110754e541d53bbd44eaa8ec2
Author:    Rasmus Lerdorf <[email protected]>         Thu, 25 Oct 2018 12:17:51 +0200
Parents:   3347f73c4a42bb6054525901dcfca3db705675c3
Branches:  master

Link:       http://git.php.net/?p=web/pres2.git;a=commitdiff;h=42ba4a021e99823110754e541d53bbd44eaa8ec2

Log:
Table support

Changed paths:
  M  pres2reveal


Diff:
diff --git a/pres2reveal b/pres2reveal
index 9aaae28..5b995d7 100755
--- a/pres2reveal
+++ b/pres2reveal
@@ -60,6 +60,8 @@ foreach($slide as $sld) {
 			case 'literal':
 			case 'example':
 			case 'movie':
+			case 'table':
+			case 'cell':
 				$fnc ="render_$k";
 				if(is_array($e)) {
 					foreach($e as $ee) {
@@ -108,8 +110,13 @@ function render_image($e) {
         $align = "align=\"{$e['align']}\"";
     }
 
+	if(substr($e['filename'], 0, 4) == 'http') {
+		$src = $e['filename'];
+	} else {
+		$src = "/{$slide_path}/{$e['filename']}";
+	}
 	$ret .= <<<EOB
-		<img src="/{$slide_path}/{$e['filename']}" $align width="{$e['width']}" height="{$e['height']}">
+		<img src="$src" $align width="{$e['width']}" height="{$e['height']}">
 
 EOB;
 	return $ret;
@@ -154,6 +161,61 @@ function render_blurb($e) {
 	return "\t\t<$tag{$class}{$style}>$text</$tag>\n";
 }
 
+
+function render_table($table) {
+    $align = '';
+	$ret = '';
+    if(!empty($table['align'])) $align = 'align="'.$table['align'].'"';
+    if(isset($table['title'])) {
+        if(!empty($table['fontsize'])) $style = "style=\"font-size: ".$table['fontsize'].';"';
+        $ret .= "<div $align $style>".markup_text($table['title'])."</div>\n";
+    }
+    $i=0;
+    $width="100%";
+    if(!empty($table['width'])) {
+        $width = $table['width'];
+    }
+	$style = '';
+	if(isset($table['marginleft'])) $style .= "margin-left: {$table['marginleft']};";
+	if(isset($table['marginright'])) $style .= "margin-right: {$table['marginright']};";
+	if(isset($table['fontsize'])) $ret .= "<font size=\"{$table['fontsize']}\">\n";
+    $ret .= '<table '.$align.' width="'.$width.'" border="'.$table['border'].'" '.(isset($table['bgcolor'])?"bgcolor=\"{$table['bgcolor']}\"":'')."style=\"$style\">";
+    foreach($table->cell as $k=>$cell) {
+        if(!($i % $table['columns'])) {
+            $ret .= "<tr>\n";
+        }
+        $ret .= " <td ";
+        if(isset($cell['class'])) $ret .= "class=\"".$cell['class']."\"";
+        if(isset($cell['align'])) $ret .= "align=\"".$cell['align']."\"";
+        if(isset($cell['bgcolor'])) $ret .= "bgcolor=\"".$cell['bgcolor']."\"";
+        $ret .= ">";
+        $ret .= render_cell($cell);
+        $ret .= " </td>";
+        if(!(($i+1) % $table['columns'])) {
+            $ret .= "</tr>\n";
+        }
+        $i++;
+    }
+    $ret .= '</table>';
+	if(isset($table['fontsize'])) $ret .= "</font>";
+	$ret .= "<br />\n";
+    return $ret;
+}
+
+function render_cell($cell) {
+    $style='';
+    if(!empty($cell['fontsize'])) $style .= "font-size: ".$cell['fontsize'].';';
+    if(!empty($cell['marginleft'])) $style .= "margin-left: ".$cell['marginleft'].';';
+
+    if(!empty($cell['marginright'])) $style .= "margin-right: ".$cell['marginleft'].';';
+
+    if(!empty($cell['padding'])) $style .= "padding: ".$cell['padding'].';';
+
+    if(!empty($cell['bold']) && $cell['bold']) $style .= 'font-weight: bold;';
+
+    return "<span style=\"$style\">".markup_text($cell)."</span>\n";
+}
+
 function render_link($link) {
 	if(strlen((string)$link)) {
 		$text = (string)$link;