[Mapbender-commits] r3369 - in branches/print_dev/http/print: . classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Dec 19 12:38:41 EST 2008


Author: mschulz
Date: 2008-12-19 12:38:41 -0500 (Fri, 19 Dec 2008)
New Revision: 3369

Added:
   branches/print_dev/http/print/classes/
   branches/print_dev/http/print/classes/factoryClasses.php
   branches/print_dev/http/print/classes/mbMapDecorator.php
   branches/print_dev/http/print/classes/mbPdf.php
   branches/print_dev/http/print/classes/mbTemplatePdf.php
   branches/print_dev/http/print/classes/mbTemplatePdfDecorator.php
   branches/print_dev/http/print/mbtemplate1.pdf
   branches/print_dev/http/print/testConfigTemplate.json
Modified:
   branches/print_dev/http/print/mod_printPDF.php
Log:
first sketches to new pdf template printing

Added: branches/print_dev/http/print/classes/factoryClasses.php
===================================================================
--- branches/print_dev/http/print/classes/factoryClasses.php	                        (rev 0)
+++ branches/print_dev/http/print/classes/factoryClasses.php	2008-12-19 17:38:41 UTC (rev 3369)
@@ -0,0 +1,72 @@
+<?php
+
+require_once(dirname(__FILE__)."/../../../core/globalSettings.php");
+require_once(dirname(__FILE__) . "/../../classes/class_json.php");
+require_once(dirname(__FILE__) . "/../../classes/class_administration.php");
+
+
+abstract class mbPrintFactory {
+
+	protected function createOutput($jsonConf, $concreteFactory) {
+		return $concreteFactory->create($jsonConf);
+	}
+	
+	abstract public function create($jsonConf);
+
+}
+
+class mbPdfFactory extends mbPrintFactory {
+
+	private function readConfig($jsonConfFile) {
+		$admin = new administration();
+		$mbjson = new Mapbender_JSON(); 
+		$jsonStr = $admin->char_encode(file_get_contents(dirname(__FILE__) . "/../".$jsonConfFile));
+		$jsonConf = $mbjson->decode($jsonStr);
+		return $jsonConf;
+	}
+	
+	public function create($jsonConfFile) {
+ 		$jsonConf = $this->readConfig($jsonConfFile);
+		try {
+			switch ($jsonConf->type) {
+				case "templatePDF":
+					$factory = new mbTemplatePdfFactory();
+            		break;
+				case "dynamicPDF":
+					$factory = new mbDynamicPdfFactory();
+            		break;
+				default:
+					$e = new mb_exception("mbPdfFactory: output type not supported.");
+			}
+			return $this->createOutput($jsonConf, $factory);
+		} catch (Exception $e){
+			$e = new mb_exception("mbPdfFactory: could not create PDF output.");
+		} 
+		
+		return;
+	}
+
+}
+
+class mbTemplatePdfFactory extends mbPrintFactory {
+
+	public function create($jsonConf) {
+		return new mbTemplatePdf($jsonConf);
+	}
+
+}
+
+class mbDynamicPdfFactory extends mbPrintFactory {
+
+	public function create($jsonConf) {
+		return new mbDynamicPdf($jsonConf);
+	}
+
+}
+
+function __autoload($class_name) {
+	if (file_exists(dirname(__FILE__). "/{$class_name}.php"))
+    	require_once $class_name . '.php';
+}
+
+?>
\ No newline at end of file

Added: branches/print_dev/http/print/classes/mbMapDecorator.php
===================================================================
--- branches/print_dev/http/print/classes/mbMapDecorator.php	                        (rev 0)
+++ branches/print_dev/http/print/classes/mbMapDecorator.php	2008-12-19 17:38:41 UTC (rev 3369)
@@ -0,0 +1,11 @@
+<?php
+
+class mbMapDecorator extends mbTemplatePdfDecorator {
+
+	public function __construct($pdfObj, $mapConf) {
+		
+	}
+}
+
+
+?>

Added: branches/print_dev/http/print/classes/mbPdf.php
===================================================================
--- branches/print_dev/http/print/classes/mbPdf.php	                        (rev 0)
+++ branches/print_dev/http/print/classes/mbPdf.php	2008-12-19 17:38:41 UTC (rev 3369)
@@ -0,0 +1,35 @@
+<?php
+
+require_once(dirname(__FILE__)."/../../../core/globalSettings.php");
+require_once(dirname(__FILE__) . "/../../classes/class_json.php");
+
+abstract class mbPdf {
+
+	/* the actual pdf */
+	public $objPdf; 
+	public $confPdf;
+	public $outputFileName;	
+	
+	public $isRendered = false;
+	public $isSaved = false;
+
+	abstract public function render();
+	abstract public function save();
+	
+	public function generateOutputFileName() {
+		$this->outputFileName = "map_".substr(md5(uniqid(rand())),0,7).".pdf";
+	}
+
+	public function returnURL() {
+		if ($this->isSaved) {
+		    $mbjson = new Mapbender_JSON();
+			return $mbjson->encode(array("outputFileName"=>TMPDIR."/".$this->outputFileName));
+		}
+		else
+			die("PDF output not rendered yet.");
+	}	
+
+}
+
+
+?>

Added: branches/print_dev/http/print/classes/mbTemplatePdf.php
===================================================================
--- branches/print_dev/http/print/classes/mbTemplatePdf.php	                        (rev 0)
+++ branches/print_dev/http/print/classes/mbTemplatePdf.php	2008-12-19 17:38:41 UTC (rev 3369)
@@ -0,0 +1,47 @@
+<?php
+
+require_once(dirname(__FILE__)."/../../extensions/fpdf/mb_fpdi.php");
+
+class mbTemplatePdf extends mbPdf {
+
+	public function __construct($jsonConf) {
+		$this->confPdf = $jsonConf;
+		if (!$this->confPdf->orientation ||	!$this->confPdf->units || !$this->confPdf->format) {
+			die("no valid config");
+		}	
+		$this->objPdf = new mb_fpdi($this->confPdf->orientation,
+									$this->confPdf->units,
+									$this->confPdf->format);
+		$this->generateOutputFileName();
+	}
+
+	public function render() {
+		foreach ($this->confPdf->pages as $pageConf) {
+			/* apply the template to the pdf page */
+			$this->objPdf->addPage();
+            $pagecount = $this->objPdf->setSourceFile(dirname(__FILE__)."/../".$pageConf->tpl);
+            $tplidx = $this->objPdf->importPage($pageConf->useTplPage);
+            $this->objPdf->useTemplate($tplidx);
+            
+            foreach ($pageConf->elements as $pageElementId => $pageElementConf) {
+				switch ($pageElementId) {
+					case "map1":
+						#$this->objPdf = new mbMapDecorator($this->objPdf, $pageElementConf);
+						break;
+				}
+            }
+            
+            $this->isRendered = true;
+		}
+	}
+	
+	public function save() {
+		if ($this->isRendered) {
+			$this->objPdf->Output(TMPDIR."/".$this->outputFileName, "F");
+			$this->isSaved = true;
+		}
+	}
+}
+
+
+?>

Added: branches/print_dev/http/print/classes/mbTemplatePdfDecorator.php
===================================================================
--- branches/print_dev/http/print/classes/mbTemplatePdfDecorator.php	                        (rev 0)
+++ branches/print_dev/http/print/classes/mbTemplatePdfDecorator.php	2008-12-19 17:38:41 UTC (rev 3369)
@@ -0,0 +1,11 @@
+<?php
+
+abstract class mbPdfDecorator extends mbPdf {
+
+	protected $mbPdf;
+
+	public function __construct();
+
+}
+
+?>
\ No newline at end of file

Added: branches/print_dev/http/print/mbtemplate1.pdf
===================================================================
(Binary files differ)


Property changes on: branches/print_dev/http/print/mbtemplate1.pdf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: branches/print_dev/http/print/mod_printPDF.php
===================================================================
--- branches/print_dev/http/print/mod_printPDF.php	2008-12-19 17:17:37 UTC (rev 3368)
+++ branches/print_dev/http/print/mod_printPDF.php	2008-12-19 17:38:41 UTC (rev 3369)
@@ -58,8 +58,8 @@
 require_once(dirname(__FILE__)."/../print/".$_REQUEST["conf"]);
 echo "<script type='text/javascript'>";
 echo "var target = '".$_REQUEST["target"]."';";
-echo "var comment = '".$label_comment."';";
-echo "var comment_length = ".$comment_length.";";
+echo "var comment = '".$label_comment1."';";
+echo "var comment_length = ".$comment1_length.";";
 echo "var label_button = '".$label_button."';";
 echo "var type = '".$type."';";
 echo "</script>";

Added: branches/print_dev/http/print/testConfigTemplate.json
===================================================================
--- branches/print_dev/http/print/testConfigTemplate.json	                        (rev 0)
+++ branches/print_dev/http/print/testConfigTemplate.json	2008-12-19 17:38:41 UTC (rev 3369)
@@ -0,0 +1,27 @@
+{
+    "type" : "templatePDF",
+    "orientation" : "L",
+    "units" : "mm",
+    "format" : "a4",
+    "pages" : [
+    	{
+    	 "tpl" : "mbtemplate1.pdf",
+    	 "useTplPage" : 1,
+    	 "elements" : {
+	    	 "map" : {
+    			"show" : false,
+    			"x_ll" : 10,
+	    		"y_ll" : 10,
+	    		"width" : 160,
+    			"height" : 160
+	   			}
+	   		}
+	   	}
+	],
+	"request" : {
+		"map_urls" : [],
+		"overview_url" : "",
+		"scale" : "",
+		"measured_x_values" : []
+	}
+}
\ No newline at end of file



More information about the Mapbender_commits mailing list