[Mapbender-commits] r5357 - in trunk/mapbender/http/print: . classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jan 19 17:31:48 EST 2010


Author: astrid_emde
Date: 2010-01-19 17:31:48 -0500 (Tue, 19 Jan 2010)
New Revision: 5357

Added:
   trunk/mapbender/http/print/classes/
   trunk/mapbender/http/print/classes/factoryClasses.php
   trunk/mapbender/http/print/classes/mbImageDecorator.php
   trunk/mapbender/http/print/classes/mbMapDecorator.php
   trunk/mapbender/http/print/classes/mbMeasureDecorator.php
   trunk/mapbender/http/print/classes/mbOverviewDecorator.php
   trunk/mapbender/http/print/classes/mbParagraphDecorator.php
   trunk/mapbender/http/print/classes/mbPdf.php
   trunk/mapbender/http/print/classes/mbTemplatePdf.php
   trunk/mapbender/http/print/classes/mbTemplatePdfDecorator.php
   trunk/mapbender/http/print/classes/mbTextDecorator.php
Log:
classes for new print module

Added: trunk/mapbender/http/print/classes/factoryClasses.php
===================================================================
--- trunk/mapbender/http/print/classes/factoryClasses.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/factoryClasses.php	2010-01-19 22:31:48 UTC (rev 5357)
@@ -0,0 +1,76 @@
+<?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 = file_get_contents(dirname(__FILE__) . "/../".$jsonConfFile);
+		if ($jsonStr == false) {
+			$e = new mb_exception("mbPdfFactory: config file could not be read.");
+			die("config not found.");
+		}
+		$jsonConf = $mbjson->decode($admin->char_encode($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: trunk/mapbender/http/print/classes/mbImageDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbImageDecorator.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbImageDecorator.php	2010-01-19 22:31:48 UTC (rev 5357)
@@ -0,0 +1,54 @@
+<?php
+
+class mbImageDecorator extends mbTemplatePdfDecorator {
+
+	protected $pageElementType = "image";
+	protected $elementId;
+	protected $angle = 0;
+	protected $overrideMembersFromRequest = array("angle");
+	
+	public function __construct($pdfObj, $elementId, $mapConf, $controls) {
+		parent::__construct($pdfObj, $mapConf, $controls);
+		$this->elementId = $elementId;
+		$this->override();		
+		$this->decorate();	
+	}
+	
+	public function override() {
+		/* returns an array of (request key, member id) arrays */ 
+		$idsFromRequest = $this->getPageElementLink($this->elementId);
+		foreach ($idsFromRequest as $requestKey => $memberId) {
+			$e = new mb_notice("mbOverviewDecorator: checking overrides: ".$requestKey.$memberId);
+		}
+		foreach ($_REQUEST as $k => $v) {
+			$e = new mb_notice("mbOverviewDecorator: checking Request: ".$k."=".$v);
+		}
+		
+		foreach ($this->overrideMembersFromRequest as $overrideMemberFromRequest) {
+			/* take the value of the config in every case */
+			$this->{$overrideMemberFromRequest} = $this->conf->{$overrideMemberFromRequest};
+			foreach ($idsFromRequest as $requestKey => $memberId) {
+				$e = new mb_notice("mbOverviewDecorator: before override: set ".$memberId." to ".$requestKey);
+				if ($overrideMemberFromRequest==$memberId && isset($_REQUEST[$requestKey]) && $_REQUEST[$requestKey] != "") { 
+					$this->{$overrideMemberFromRequest} = $_REQUEST[$requestKey];
+					$e = new mb_notice("mbOverviewDecorator: override from Request: ".$overrideMemberFromRequest." to ".$this->{$overrideMemberFromRequest});
+				}
+				/* this else branch is not necessary anymore 
+				else {
+					$this->{$overrideMemberFromRequest} = $this->conf->{$memberId};
+					$e = new mb_notice("mbOverviewDecorator: override from conf: ".$overrideMemberFromRequest." to ".$this->conf->{$memberId});
+				}
+				*/	
+			}	
+		}
+
+	}
+	
+	public function decorate() {
+		#Image($file,$x,$y,$w=0,$h=0,$type='',$link='', $isMask=false, $maskImg=0, $angle=0)
+		$this->pdf->objPdf->Image($this->conf->filename, $this->conf->x_ul, $this->conf->y_ul, $this->conf->width, $this->conf->height,'','',false,0,5,-1*$this->angle);
+	}
+}
+
+
+?>

Added: trunk/mapbender/http/print/classes/mbMapDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbMapDecorator.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbMapDecorator.php	2010-01-19 22:31:48 UTC (rev 5357)
@@ -0,0 +1,117 @@
+<?php
+
+require_once(dirname(__FILE__)."/../../classes/class_stripRequest.php");
+require_once(dirname(__FILE__)."/../../classes/class_weldMaps2PNG.php");
+if (class_exists('Imagick')) {
+	require_once(dirname(__FILE__)."/../../classes/class_weldMaps2PNG_rotate.php");
+} else { 
+	$e = new mb_warning("mbMapDecorator: php-imagick module has to be installed to be able to use rotated printing.");
+} 
+require_once(dirname(__FILE__)."/../../classes/class_map.php");
+
+class mbMapDecorator extends mbTemplatePdfDecorator {
+
+	protected $pageElementType = "map";
+	protected $elementId;
+	protected $filename;
+	/* a decorator should declare which parameters could be overwritten through the request object */
+	protected $overrideMembersFromRequest = array("res_dpi","angle");
+	protected $res_dpi;
+	protected $angle = 0;
+	
+	public function __construct($pdfObj, $elementId, $mapConf, $controls) {
+		parent::__construct($pdfObj, $mapConf, $controls);
+		$this->elementId = $elementId;
+		$this->filename = TMPDIR."/".parent::generateOutputFileName("map","png");
+		$this->override();		
+		$this->decorate();	
+	}
+	
+	public function override() {
+		/* returns an array of (request key, member id) arrays */ 
+		$idsFromRequest = $this->getPageElementLink($this->elementId);
+		foreach ($idsFromRequest as $requestKey => $memberId) {
+			$e = new mb_notice("mbMapDecorator: checking overrides: ".$requestKey.$memberId);
+		}
+		foreach ($_REQUEST as $k => $v) {
+			$e = new mb_notice("mbMapDecorator: checking Request: ".$k."=".$v);
+		}
+		
+		foreach ($this->overrideMembersFromRequest as $overrideMemberFromRequest) {
+			/* take the value of the config in every case */
+			$this->{$overrideMemberFromRequest} = $this->conf->{$overrideMemberFromRequest};
+			foreach ($idsFromRequest as $requestKey => $memberId) {
+				$e = new mb_notice("mbMapDecorator: before override: set ".$memberId." to ".$requestKey);
+				if ($overrideMemberFromRequest==$memberId && isset($_REQUEST[$requestKey]) && $_REQUEST[$requestKey] != "") { 
+					$this->{$overrideMemberFromRequest} = $_REQUEST[$requestKey];
+					$e = new mb_notice("mbMapDecorator: override from Request: ".$overrideMemberFromRequest." to ".$this->{$overrideMemberFromRequest});
+				}
+				/* this else branch is not necessary anymore 
+				else {
+					$this->{$overrideMemberFromRequest} = $this->conf->{$memberId};
+					$e = new mb_notice("mbMapDecorator: override from conf: ".$overrideMemberFromRequest." to ".$this->conf->{$memberId});
+				}	
+				*/
+			}	
+		}
+	}
+	
+	public function decorate() {
+		$urls = $_REQUEST["map_url"];
+		$array_urls = explode("___", $urls);
+		$width = $this->conf->width;
+		$height = $this->conf->height;
+		$res = $this->pdf->objPdf->k * ($this->res_dpi/72);
+		$myURL = new stripRequest($array_urls[0]);
+		$e = new mb_notice("mbMapDecorator: original bbox: ".$myURL->get('BBOX')); 
+		if (isset($_REQUEST["coordinates"]) && $_REQUEST["coordinates"]!= "") {
+			$mapPdfBbox = $_REQUEST["coordinates"];
+		} else {			
+			$mapPdfBbox = $myURL->get('BBOX');
+		}
+		$e = new mb_notice("mbMapDecorator: coordinates: ".$mapPdfBbox);
+		$this->pdf->setMapInfo($this->conf->x_ul, $this->conf->y_ul, $width, $height, $this->pdf->adjustBbox($this->conf, explode(",",$mapPdfBbox), $myURL->get('srs')));
+		$e = new mb_notice("mbMapDecorator: adjusted bbox: ".$this->pdf->getMapExtent());
+		for($i=0; $i<count($array_urls); $i++){
+			$m = new stripRequest($array_urls[$i]);
+			$m->set('width',(intval($width*$res)));
+			$m->set('height',(intval($height*$res)));
+			$m->set('bbox', $this->pdf->getMapExtent());
+			$array_urls[$i] = $m->url;
+		}
+		
+		if ($this->angle != 0) {
+			if (class_exists('weldMaps2PNG_rotate')) {
+				$i = new weldMaps2PNG_rotate(implode("___",$array_urls), $this->filename, $this->angle);
+			} else {
+				$i = new weldMaps2PNG(implode("___",$array_urls), $this->filename);
+				$e = new mb_warning("mbMapDecorator: no rotation possible.");
+			}
+		} else {
+			$i = new weldMaps2PNG(implode("___",$array_urls), $this->filename);
+		}
+		$this->pdf->objPdf->Image($this->filename, $this->conf->x_ul, $this->conf->y_ul, $width, $height,'png');
+		
+		/* show coordinates ... */
+		if ($this->conf->coords == 1) {
+			$coord = mb_split(",",$this->pdf->getMapExtent());
+
+			$myMinx = "R ".substr(round($coord[0]), 0, 4)." ".substr(round($coord[0]), 4, 3)."";
+			$myMiny = "H ".substr(round($coord[1]), 0, 4)." ".substr(round($coord[1]), 4, 3)."";
+			$myMaxx = "R ".substr(round($coord[2]), 0, 4)." ".substr(round($coord[2]), 4, 3)."";
+			$myMaxy = "H ".substr(round($coord[3]), 0, 4)." ".substr(round($coord[3]), 4, 3)."";
+
+			$this->pdf->objPdf->setTextColor(0, 0, 0);
+			$this->pdf->objPdf->setFont($this->conf->coords_font_family, "", $this->conf->coords_font_size);
+			#RotatedText($x, $y, $txt, $angle)
+			$this->pdf->objPdf->RotatedText($this->conf->x_ul - 2, $this->conf->y_ul + $height, $myMinx, 90); 
+			$this->pdf->objPdf->Text($this->conf->x_ul, $this->conf->y_ul + $height + 5, $myMiny);
+			$this->pdf->objPdf->RotatedText($this->conf->x_ul + $width + 2, $this->conf->y_ul, $myMaxy, 270);
+			$this->pdf->objPdf->Text($this->conf->x_ul + $width - ($this->pdf->objPdf->GetStringWidth($myMaxx)), $this->conf->y_ul - 2, $myMaxx);
+
+		}
+	}
+	
+}
+
+?>

Added: trunk/mapbender/http/print/classes/mbMeasureDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbMeasureDecorator.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbMeasureDecorator.php	2010-01-19 22:31:48 UTC (rev 5357)
@@ -0,0 +1,81 @@
+<?php
+class mbMeasureDecorator extends mbTemplatePdfDecorator {
+
+	protected $pageElementType = "measure";
+	protected $elementId;
+	
+	public function __construct($pdfObj, $elementId, $mapConf, $controls) {
+		parent::__construct($pdfObj, $mapConf, $controls);
+		$this->elementId = $elementId;
+		$this->override();		
+		$this->decorate();
+	}
+	
+	public function override() {}
+	
+	public function decorate() {
+		include (dirname(__FILE__)."/../print_functions.php");
+		
+		global $mapOffset_left, $mapOffset_bottom, $map_height, $map_width, $coord;
+		global $yAxisOrientation;
+		$yAxisOrientation = 1;
+		
+		if (isset($_REQUEST["measured_x_values"]) && $_REQUEST["measured_x_values"] != "") {
+			$x_value_str = $_REQUEST["measured_x_values"];
+			$y_value_str = $_REQUEST["measured_y_values"];
+			$e = new mb_notice("mbMeasureDecorator: x values: ".$x_value_str);
+			$e = new mb_notice("mbMeasureDecorator: y values: ".$y_value_str);
+		}
+		else {
+			return "No measurements found.";
+		}
+		
+		$coord = mb_split(",",$this->pdf->getMapExtent());
+		$mapInfo = $this->pdf->getMapInfo();
+		foreach ($mapInfo as $k => $v) {
+			$e = new mb_notice("mbMeasureDecorator: mapInfo: ".$k."=".$v);
+		}
+		$mapOffset_left = $mapInfo["x_ul"];
+		$mapOffset_bottom = $mapInfo["y_ul"];
+		$map_height = $mapInfo["height"];
+		$map_width = $mapInfo["width"];
+		
+		// get the arrays, be aware of the different y-axis values
+		$theFullArr = makeCoordPairs($x_value_str, $y_value_str);
+		foreach ($theFullArr as $oneFullArr) {
+			$e = new mb_notice("mbMeasureDecorator: coordinates: ".implode(" ",array_values($oneFullArr)));
+		}
+    	$thePolyArr = makePolyFromCoord($theFullArr);
+    	$e = new mb_notice("mbMeasureDecorator: coordinates: ".implode(" ",$thePolyArr));
+	
+		if (isClosedPolygon($theFullArr)) {
+			$isClosed = TRUE;
+		} 
+		else {
+			$isClosed = FALSE;
+		}
+		$nr_of_points = count($theFullArr);
+		$e = new mb_notice("mbMeasureDecorator: closed polygon: ".$isClosed);
+
+		$this->pdf->objPdf->ClippingRect($mapOffset_left, $mapOffset_bottom, $map_width, $map_height, false);
+		if ($isClosed) {
+			$this->pdf->objPdf->Polygon($thePolyArr);
+		}
+		else {
+			$theStrokePointPairs = makeStrokePointPairs($theFullArr);
+			for($i = 0; $i < count($theStrokePointPairs); $i++) {
+				$line = $theStrokePointPairs[$i];
+				$e = new mb_notice("mbMeasureDecorator: line coordinates: ".implode(" ",$line));
+				if ($i != count($theStrokePointPairs) - 1) {
+			    	$this->pdf->objPdf->Line($line[0], $line[1], $line[2], $line[3]);
+				}
+			}
+		}
+		$this->pdf->objPdf->UnsetClipping();
+
+	}
+	
+
+}
+
+?>
\ No newline at end of file

Added: trunk/mapbender/http/print/classes/mbOverviewDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbOverviewDecorator.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbOverviewDecorator.php	2010-01-19 22:31:48 UTC (rev 5357)
@@ -0,0 +1,142 @@
+<?php
+
+require_once(dirname(__FILE__)."/../../classes/class_stripRequest.php");
+require_once(dirname(__FILE__)."/../../classes/class_weldOverview2PNG.php");
+if (class_exists('Imagick')) {
+	require_once(dirname(__FILE__)."/../../classes/class_weldOverview2PNG_rotate.php");
+} else {
+	$e = new mb_warning("mbOverviewDecorator: php-imagick module has to be installed to be able to use rotated printing.");
+}
+
+class mbOverviewDecorator extends mbTemplatePdfDecorator {
+
+	protected $pageElementType = "overview";
+	protected $elementId;
+	protected $filename;
+	protected $overrideMembersFromRequest = array("angle");
+	protected $angle = 0;
+		
+	
+	public function __construct($pdfObj, $elementId, $mapConf, $controls) {
+		parent::__construct($pdfObj, $mapConf, $controls);
+		$this->elementId = $elementId;
+		$this->filename = TMPDIR."/".parent::generateOutputFileName("map","png");		
+		$this->override();		
+		$this->decorate();	
+	}
+	
+	public function override() {
+		$idsFromRequest = $this->getPageElementLink($this->elementId);
+		foreach ($idsFromRequest as $requestKey => $memberId) {
+			$e = new mb_notice("mbOverviewDecorator: checking overrides: ".$requestKey.$memberId);
+		}
+		foreach ($_REQUEST as $k => $v) {
+			$e = new mb_notice("mbOverviewDecorator: checking Request: ".$k."=".$v);
+		}
+		
+		foreach ($this->overrideMembersFromRequest as $overrideMemberFromRequest) {
+			/* take the value of the config in every case */
+			$this->{$overrideMemberFromRequest} = $this->conf->{$overrideMemberFromRequest};
+			foreach ($idsFromRequest as $requestKey => $memberId) {
+				$e = new mb_notice("mbOverviewDecorator: before override: set ".$memberId." to ".$requestKey);
+				if ($overrideMemberFromRequest==$memberId && isset($_REQUEST[$requestKey]) && $_REQUEST[$requestKey] != "") { 
+					$this->{$overrideMemberFromRequest} = $_REQUEST[$requestKey];
+					$e = new mb_notice("mbOverviewDecorator: override from Request: ".$overrideMemberFromRequest." to ".$this->{$overrideMemberFromRequest});
+				}
+				/* this else branch is not necessary anymore 
+				else {
+					$this->{$overrideMemberFromRequest} = $this->conf->{$memberId};
+					$e = new mb_notice("mbOverviewDecorator: override from conf: ".$overrideMemberFromRequest." to ".$this->conf->{$memberId});
+				}
+				*/	
+			}	
+		}
+	}
+	
+	public function decorate() {
+		$overview_url = $_REQUEST["overview_url"];
+		$o_url = new stripRequest($overview_url);
+		$width = $this->conf->width;
+		$height = $this->conf->height;
+		$res = $this->pdf->objPdf->k*($this->conf->res_dpi/72);		
+		$o_url->set('width',intval($width*$res));
+		$o_url->set('height',intval($height*$res));
+		$o_url->set('bbox', $this->pdf->adjustBbox($this->conf, explode(",",$o_url->get('BBOX')), $o_url->get('srs')));
+		$overview_url = $o_url->url;	
+
+		$urls = $_REQUEST["map_url"];
+		$array_urls = explode("___", $urls);
+		$myURL = new stripRequest($array_urls[0]);
+		$myURL->set('bbox', $this->pdf->getMapExtent());
+		if ($this->angle != 0) {
+			if (class_exists('weldOverview2PNG_rotate')) {
+				$rotatedExtent = $this->rotatePoints(explode(",",$this->pdf->getMapExtent()), intval($this->angle));
+				for ($i==0;$i<count($rotatedExtent);$i++) 
+					$e = new mb_notice("mbOverviewDecorator: rotated extent: " . implode("|",$rotatedExtent[$i]));
+				$i = new weldOverview2PNG_rotate($overview_url, $myURL->url, $this->filename, $rotatedExtent);
+			} else {
+				$i = new weldOverview2PNG($overview_url, $myURL->url, $this->filename);
+				$e = new mb_warning("mbOverviewDecorator: no rotation possible.");				
+			}
+		} else {
+			$i = new weldOverview2PNG($overview_url, $myURL->url, $this->filename);
+		}		
+		
+		$this->pdf->objPdf->Image($this->filename, $this->conf->x_ul, $this->conf->y_ul, $width, $height, 'png');
+	}
+	
+	protected function rotate($point, $center, $angle) {
+		if ($angle === 0) {
+			return $point;
+		}
+		// first, calculate point around 0
+		// then rotate
+		// then add center vector again
+		
+		$pNew = array(
+			$point[0] - $center[0],
+			$point[1] - $center[1]
+		);
+		
+		$angle = deg2rad(-$angle);
+		return array(
+			($pNew[0] * cos($angle) + $pNew[1] * sin($angle)) + $center[0],
+			($pNew[0] * -sin($angle) + $pNew[1] * cos($angle)) + $center[1]
+		);
+	}
+	
+	protected function rotatePoints($coordArray, $angle) {
+		$center = array(
+			($coordArray[2] + $coordArray[0]) / 2,
+			($coordArray[3] + $coordArray[1]) / 2,
+		);
+		
+		$p1 = array(
+			$coordArray[0],
+			$coordArray[1]
+		);
+		$p2 = array(
+			$coordArray[2],
+			$coordArray[1]
+		);
+		$p3 = array(
+			$coordArray[2],
+			$coordArray[3]
+		);
+		$p4 = array(
+			$coordArray[0],
+			$coordArray[3]
+		);
+		
+		$newCoordArray = array(
+			$this->rotate($p1, $center, $angle),
+			$this->rotate($p2, $center, $angle),
+			$this->rotate($p3, $center, $angle),
+			$this->rotate($p4, $center, $angle)
+		);
+		return $newCoordArray;
+	}	
+}
+
+
+?>

Added: trunk/mapbender/http/print/classes/mbParagraphDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbParagraphDecorator.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbParagraphDecorator.php	2010-01-19 22:31:48 UTC (rev 5357)
@@ -0,0 +1,57 @@
+<?php
+
+class mbParagraphDecorator extends mbTemplatePdfDecorator {
+
+	protected $pageElementType = "para";
+	protected $elementId;
+	/* a decorator should declare which parameters could be overwritten through the request object */
+	protected $overrideMembersFromRequest = array("value");
+	/* the actual text that should be printed */
+	protected $value = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, ...";
+	
+	public function __construct($pdfObj, $elementId, $mapConf, $controls) {
+		parent::__construct($pdfObj, $mapConf, $controls);
+		$this->elementId = $elementId;
+		$this->override();		
+		$this->decorate();	
+	}
+	
+	public function override() {
+		/* returns an array of (request key, member id) arrays */ 
+		$idsFromRequest = $this->getPageElementLink($this->elementId);
+		foreach ($idsFromRequest as $requestKey => $memberId) {
+			$e = new mb_notice("mbParagraphDecorator: checking overrides: ".$requestKey.$memberId);
+		}
+		foreach ($_REQUEST as $k => $v) {
+			$e = new mb_notice("mbParagraphDecorator: checking Request: ".$k."=".$v);
+		}
+		
+		foreach ($this->overrideMembersFromRequest as $overrideMemberFromRequest) {
+			foreach ($idsFromRequest as $requestKey => $memberId) {
+				$e = new mb_notice("mbParagraphDecorator: before override: set ".$memberId." to ".$requestKey);
+				if ($overrideMemberFromRequest==$memberId && isset($_REQUEST[$requestKey]) && $_REQUEST[$requestKey] != "") { 
+					$this->{$overrideMemberFromRequest} = $_REQUEST[$requestKey];
+					$e = new mb_notice("mbParagraphDecorator: override from Request: ".$overrideMemberFromRequest." to ".$this->{$overrideMemberFromRequest});
+				}
+				else {
+					$this->{$overrideMemberFromRequest} = $this->conf->{$memberId};
+				}	
+			}	
+		}
+	}
+	
+	public function decorate() {
+		/* some of these values should or could be set in the config */
+		$this->pdf->objPdf->setTextColor(0, 0, 0);
+		$this->pdf->objPdf->setFillColor(255, 255, 255);
+		$this->pdf->objPdf->setDrawColor(0, 0, 0);
+		$this->pdf->objPdf->SetLineWidth($this->conf->border_width);
+		$this->pdf->objPdf->SetXY($this->conf->x_ul, $this->conf->y_ul);
+		$this->pdf->objPdf->setFont($this->conf->font_family, "", $this->conf->font_size);
+		$this->pdf->objPdf->Cell($this->conf->width, $this->conf->height, $this->value, $this->conf->border, 0, $this->conf->align, $this->conf->fill);
+	}
+	
+
+}
+
+?>
\ No newline at end of file

Added: trunk/mapbender/http/print/classes/mbPdf.php
===================================================================
--- trunk/mapbender/http/print/classes/mbPdf.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbPdf.php	2010-01-19 22:31:48 UTC (rev 5357)
@@ -0,0 +1,61 @@
+<?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($prefix, $suffix) {
+		return $prefix."_".substr(md5(uniqid(rand())),0,7).".".$suffix;
+	}
+
+	public function returnPDF() {
+		if ($this->isSaved) {
+		    header('Content-Type: application/octet-stream');
+		    header('Content-Disposition: attachment; filename="'.$this->outputFileName.'"');
+		    header('Pragma: public');
+		    ob_end_flush();
+			$this->objPdf->Output($this->outputFileName,'S');
+		}
+		else
+			die("PDF output not rendered yet.");
+	}	
+
+	public function returnAbsoluteUrl() {
+		$mbjson = new Mapbender_JSON();
+		if ($this->isSaved) {
+			if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on")
+				$prot = "https://";
+			else
+				$prot = "http://";
+			$absoluteUrlToPdf = $prot.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/printPDF_download.php?f=".$this->outputFileName."&".SID;
+			return $mbjson->encode(array("outputFileName"=>$absoluteUrlToPdf));
+		}
+		else
+		    return $mbjson->encode(array("error"=>"Possibly no map urls delivered."));
+	}	
+	
+	public function returnUrl() {
+		$mbjson = new Mapbender_JSON();
+		if ($this->isSaved) {
+			return $mbjson->encode(array("outputFileName"=>TMPDIR."/".$this->outputFileName));
+		}
+		else
+		    return $mbjson->encode(array("error"=>"Possibly no map urls delivered."));
+	}	
+
+}
+
+
+?>

Added: trunk/mapbender/http/print/classes/mbTemplatePdf.php
===================================================================
--- trunk/mapbender/http/print/classes/mbTemplatePdf.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbTemplatePdf.php	2010-01-19 22:31:48 UTC (rev 5357)
@@ -0,0 +1,101 @@
+<?php
+
+require_once(dirname(__FILE__)."/../../extensions/fpdf/mb_fpdi.php");
+
+class mbTemplatePdf extends mbPdf {
+
+	/* it seems several decorators are going to need this information */
+	public $mapInfo = array();	
+
+	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->outputFileName = $this->generateOutputFileName("map","pdf");
+	}
+
+	public function setMapInfo($x_ul, $y_ul, $width, $height, $aBboxString) {
+		$this->mapinfo["x_ul"] = $x_ul;
+		$this->mapinfo["y_ul"] = $y_ul;
+		$this->mapinfo["width"] = $width;
+		$this->mapinfo["height"] = $height;
+		$this->mapinfo["extent"] = $aBboxString;
+		$e = new mb_notice("mbTemplatePdf: setting mapInfo ...");
+	}
+
+	public function getMapInfo() {
+		$e = new mb_notice("mbTemplatePdf: getting mapInfo ..");
+		return $this->mapinfo;
+	}
+	
+	public function setMapExtent($aBboxString) {
+		$this->mapinfo["extent"] = $aBboxString;
+		$e = new mb_notice("mbTemplatePdf: setting mapExtent to ".$this->mapinfo["extent"]);
+	}
+		
+	public function getMapExtent() {
+		$e = new mb_notice("mbTemplatePdf: getting mapExtent as ".$this->mapinfo["extent"]);
+		return $this->mapinfo["extent"];
+	}	
+
+	public function adjustBbox($elementConf, $aBboxArray, $aSrsString) {
+		$aMbBbox = new Mapbender_bbox($aBboxArray[0],$aBboxArray[1],$aBboxArray[2],$aBboxArray[3],$aSrsString);
+		$aMap = new Map();
+		$aMap->setWidth($elementConf->width);
+		$aMap->setHeight($elementConf->height);
+		$aMap->calculateExtent($aMbBbox);
+		$this->mapinfo["scale"] = isset($_REQUEST["scale"]) ? $_REQUEST["scale"] : $aMap->getScale($elementConf->res_dpi);
+		$adjustedMapExt = $aMap->getExtentInfo();
+		return implode(",",$adjustedMapExt);
+	}	
+	
+	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);
+            $controls = $this->confPdf->controls;
+            $this->objPdf->useTemplate($tplidx);
+            
+            foreach ($pageConf->elements as $pageElementId => $pageElementConf) {
+				switch ($pageElementConf->type) {
+					case "map":
+						$err = new mbMapDecorator($this, $pageElementId, $pageElementConf, $controls);
+						break;
+					case "overview":
+						$err = new mbOverviewDecorator($this, $pageElementId, $pageElementConf, $controls);
+						break;
+					case "text":
+						$err = new mbTextDecorator($this, $pageElementId, $pageElementConf, $controls);
+						break;		
+					case "para":
+						$err = new mbParagraphDecorator($this, $pageElementId, $pageElementConf, $controls);
+						break;	
+					case "measure":
+						$err = new mbMeasureDecorator($this, $pageElementId, $pageElementConf, $controls);
+						break;		
+					case "image":
+						$err = new mbImageDecorator($this, $pageElementId, $pageElementConf, $controls);
+						break;																									
+				}
+            }
+            
+            $this->isRendered = true;
+		}
+	}
+	
+	public function save() {
+		if ($this->isRendered) {
+			$this->objPdf->Output(TMPDIR."/".$this->outputFileName, "F");
+			$this->isSaved = true;
+		}
+	}
+}
+
+
+?>

Added: trunk/mapbender/http/print/classes/mbTemplatePdfDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbTemplatePdfDecorator.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbTemplatePdfDecorator.php	2010-01-19 22:31:48 UTC (rev 5357)
@@ -0,0 +1,40 @@
+<?php
+
+abstract class mbTemplatePdfDecorator extends mbTemplatePdf {
+
+	/* the template pdf object to decorate */
+	public $pdf;
+	/* the conf object for the desired decoration */
+	public $conf;
+	/* the controls object of the configuration */
+	public $controls;
+	/* possibly a zIndex will be needed */
+	public $zIndex;	
+	
+	public function __construct($pdfObj, $mapConf, $controls) {
+		$this->pdf = $pdfObj;
+		$this->conf = $mapConf;
+		$this->controls = $controls;
+	}
+	
+	public function getPageElementLink($pageElementId) {
+		$pageElementLinkArray = array();
+		$e = new mb_notice("mbTemplatePdfDecorator: pageElementId: ".$pageElementId);
+		foreach ($this->controls as $control) {
+			foreach ($control->pageElementsLink as $pageElementLinkId => $pageElementLinkValue) {
+				$e = new mb_notice("mbTemplatePdfDecorator: pageElementsLink: ".$control->id);
+				if ($pageElementLinkId == $pageElementId) 
+					#array_push($pageElementLinkArray, array($control->id => $pageElementLinkValue));
+					$pageElementLinkArray[$control->id]=$pageElementLinkValue;
+			}
+		}
+		return $pageElementLinkArray;
+	} 
+	
+	abstract public function override();
+	
+	abstract public function decorate();
+
+}
+
+?>
\ No newline at end of file

Added: trunk/mapbender/http/print/classes/mbTextDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbTextDecorator.php	                        (rev 0)
+++ trunk/mapbender/http/print/classes/mbTextDecorator.php	2010-01-19 22:31:48 UTC (rev 5357)
@@ -0,0 +1,64 @@
+<?php
+
+class mbTextDecorator extends mbTemplatePdfDecorator {
+
+	protected $pageElementType = "text";
+	protected $elementId;
+	/* a decorator should declare which parameters could be overwritten through the request object */
+	protected $overrideMembersFromRequest = array("value");
+	/* the actual text that should be printed */
+	protected $value = "Lorem ipsum";
+	
+	public function __construct($pdfObj, $elementId, $mapConf, $controls) {
+		parent::__construct($pdfObj, $mapConf, $controls);
+		$this->elementId = $elementId;
+		$this->override();		
+		$this->decorate();	
+	}
+	
+	public function override() {
+		/* returns an array of (request key, member id) arrays */ 
+		$idsFromRequest = $this->getPageElementLink($this->elementId);
+		foreach ($idsFromRequest as $requestKey => $memberId) {
+			$e = new mb_notice("mbTextDecorator: checking overrides: ".$requestKey.$memberId);
+		}
+		foreach ($_REQUEST as $k => $v) {
+			$e = new mb_notice("mbTextDecorator: checking Request: ".$k."=".$v);
+		}
+		
+		foreach ($this->overrideMembersFromRequest as $overrideMemberFromRequest) {
+			switch ($this->conf->{$overrideMemberFromRequest})  {
+				case "date": 
+					$this->{$overrideMemberFromRequest} = date("d.m.y");
+					break;
+				case "scale": 
+					$mapInfoScale = $this->pdf->getMapInfo();
+					$this->{$overrideMemberFromRequest} = "1 : ".$mapInfoScale["scale"];
+					break;
+				default:
+					$this->{$overrideMemberFromRequest} = $this->conf->{$overrideMemberFromRequest};
+					break;
+			}
+			foreach ($idsFromRequest as $requestKey => $memberId) {
+				$e = new mb_notice("mbTextDecorator: before override: set ".$memberId." to ".$requestKey);
+				if ($overrideMemberFromRequest==$memberId && isset($_REQUEST[$requestKey]) && $_REQUEST[$requestKey] != "") { 
+					$this->{$overrideMemberFromRequest} = $_REQUEST[$requestKey];
+					$e = new mb_notice("mbTextDecorator: override from Request: ".$overrideMemberFromRequest." to ".$this->{$overrideMemberFromRequest});
+				}
+				else {
+					$this->{$overrideMemberFromRequest} = $this->conf->{$memberId};
+				}	
+			}	
+		}
+	}
+	
+	public function decorate() {
+		$this->pdf->objPdf->setTextColor(0, 0, 0);
+		$this->pdf->objPdf->setFont($this->conf->font_family, "", $this->conf->font_size);
+		$this->pdf->objPdf->Text($this->conf->x_ul, $this->conf->y_ul, $this->value);
+	}
+	
+
+}
+
+?>



More information about the Mapbender_commits mailing list