[Mapbender-commits] r8316 - in trunk/mapbender/http:
extensions/fpdf print/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Apr 19 02:45:05 EDT 2012
Author: verenadiewald
Date: 2012-04-18 23:45:04 -0700 (Wed, 18 Apr 2012)
New Revision: 8316
Modified:
trunk/mapbender/http/extensions/fpdf/mb_fpdi.php
trunk/mapbender/http/print/classes/mbMeasureDecorator.php
Log:
validate measure config json for print
Modified: trunk/mapbender/http/extensions/fpdf/mb_fpdi.php
===================================================================
--- trunk/mapbender/http/extensions/fpdf/mb_fpdi.php 2012-04-19 06:43:00 UTC (rev 8315)
+++ trunk/mapbender/http/extensions/fpdf/mb_fpdi.php 2012-04-19 06:45:04 UTC (rev 8316)
@@ -422,30 +422,99 @@
$this->Rotate(0);
}
- function Polygon($points, $style='D')
- {
- //Draw a polygon
- if($style=='F')
- $op='f';
- elseif($style=='FD' or $style=='DF')
- $op='b';
- else
- $op='s';
+// Draws a polygon
+ // Parameters:
+ // - p: Points. Array with values x0, y0, x1, y1, ..., x(np-1), y(np - 1)
+ // - style: Style of polygon (draw and/or fill) (D, F, DF, FD)
+ // - line_style: Line style. Array with one of this index
+ // . all: Line style of all lines. Array like for SetLineStyle
+ // . 0..np-1: Line style of each line. Item is 0 (not line) or like for SetLineStyle
+ // - fill_color: Fill color. Array with components (red, green, blue)
+ function Polygon($p, $style = '', $line_style = null, $fill_color = null) {
+ $np = count($p) / 2;
+ if (!(false === strpos($style, 'F')) && $fill_color) {
+ #list($r, $g, $b) = $fill_color;
+
+ $this->SetFillColor($fill_color->r, $fill_color->g, $fill_color->b);
+ }
+ switch ($style) {
+ case 'F':
+ $line_style = null;
+ $op = 'f';
+ break;
+ case 'FD': case 'DF':
+ $op = 'B';
+ break;
+ default:
+ $op = 'S';
+ break;
+ }
+ $draw = true;
+ if ($line_style)
+ if (isset($line_style['all']))
+ $this->SetLineStyle($line_style['all']);
+ else { // 0 .. (np - 1), op = {B, S}
+ $draw = false;
+ if ('B' == $op) {
+ $op = 'f';
+ $this->_Point($p[0], $p[1]);
+ for ($i = 2; $i < ($np * 2); $i = $i + 2)
+ $this->_Line($p[$i], $p[$i + 1]);
+ $this->_Line($p[0], $p[1]);
+ $this->_out($op);
+ }
+ $p[$np * 2] = $p[0];
+ $p[($np * 2) + 1] = $p[1];
+ for ($i = 0; $i < $np; $i++)
+ if (!empty($line_style[$i]))
+ $this->Line($p[$i * 2], $p[($i * 2) + 1], $p[($i * 2) + 2], $p[($i * 2) + 3], $line_style[$i]);
+ }
- $h = $this->h;
- $k = $this->k;
+ if ($draw) {
+ $this->_Point($p[0], $p[1]);
+ for ($i = 2; $i < ($np * 2); $i = $i + 2)
+ $this->_Line($p[$i], $p[$i + 1]);
+ $this->_Line($p[0], $p[1]);
+ $this->_out($op);
+ }
+ }
+
+ /* PRIVATE METHODS */
- $points_string = '';
- for($i=0; $i<count($points); $i+=2){
- $points_string .= sprintf('%.2f %.2f', $points[$i]*$k, ($h-$points[$i+1])*$k);
- if($i==0)
- $points_string .= ' m ';
- else
- $points_string .= ' l ';
- }
- $this->_out($points_string . $op);
- }
+ // Sets a draw point
+ // Parameters:
+ // - x, y: Point
+ function _Point($x, $y) {
+ $this->_out(sprintf('%.2f %.2f m', $x * $this->k, ($this->h - $y) * $this->k));
+ }
+
+// Draws a line from last draw point
+ // Parameters:
+ // - x, y: End point
+ function _Line($x, $y) {
+ $this->_out(sprintf('%.2f %.2f l', $x * $this->k, ($this->h - $y) * $this->k));
+ }
+ // Draws a Bézier curve from last draw point
+ // Parameters:
+ // - x1, y1: Control point 1
+ // - x2, y2: Control point 2
+ // - x3, y3: End point
+ function _Curve($x1, $y1, $x2, $y2, $x3, $y3) {
+ $this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c', $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
+ }
+
+ // Draws a line
+ // Parameters:
+ // - x1, y1: Start point
+ // - x2, y2: End point
+ // - style: Line style. Array like for SetLineStyle
+ function Line($x1, $y1, $x2, $y2, $style = null) {
+ if ($style)
+ $this->SetLineStyle($style);
+ parent::Line($x1, $y1, $x2, $y2);
+ }
+
function ClippingText($x, $y, $txt, $outline=false)
{
$op=$outline ? 5 : 7;
@@ -524,7 +593,57 @@
$this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f cm', $tm[0],$tm[1],$tm[2],$tm[3],$tm[4],$tm[5]));
}
-
+ // Sets line style
+ // Parameters:
+ // - style: Line style. Array with keys among the following:
+ // . width: Width of the line in user units
+ // . cap: Type of cap to put on the line (butt, round, square). The difference between 'square' and 'butt' is that 'square' projects a flat end past the end of the line.
+ // . join: miter, round or bevel
+ // . dash: Dash pattern. Is 0 (without dash) or array with series of length values, which are the lengths of the on and off dashes.
+ // For example: (2) represents 2 on, 2 off, 2 on , 2 off ...
+ // (2, 1) is 2 on, 1 off, 2 on, 1 off.. etc
+ // . phase: Modifier of the dash pattern which is used to shift the point at which the pattern starts
+ // . color: Draw color. Array with components (red, green, blue)
+ function SetLineStyle($style) {
+ extract($style);
+ if (isset($width)) {
+ $width_prev = $this->LineWidth;
+ $this->SetLineWidth($width);
+ $this->LineWidth = $width_prev;
+ }
+ if (isset($cap)) {
+ $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
+ if (isset($ca[$cap]))
+ $this->_out($ca[$cap] . ' J');
+ }
+ if (isset($join)) {
+ $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
+ if (isset($ja[$join]))
+ $this->_out($ja[$join] . ' j');
+ }
+ if (isset($dash)) {
+ $dash_string = '';
+ if ($dash) {
+ if(ereg('^.+, ', $dash))
+ $tab = explode(', ', $dash);
+ else
+ $tab = array($dash);
+ $dash_string = '';
+ foreach ($tab as $i => $v) {
+ if ($i > 0)
+ $dash_string .= ' ';
+ $dash_string .= sprintf('%.2f', $v);
+ }
+ }
+ if (!isset($phase) || !$dash)
+ $phase = 0;
+ $this->_out(sprintf('[%s] %.2f d', $dash_string, $phase));
+ }
+ if (isset($color)) {
+ list($r, $g, $b) = $color;
+ $this->SetDrawColor($r, $g, $b);
+ }
+ }
}
?>
Modified: trunk/mapbender/http/print/classes/mbMeasureDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbMeasureDecorator.php 2012-04-19 06:43:00 UTC (rev 8315)
+++ trunk/mapbender/http/print/classes/mbMeasureDecorator.php 2012-04-19 06:45:04 UTC (rev 8316)
@@ -3,23 +3,23 @@
protected $pageElementType = "measure";
protected $elementId;
-
+
public function __construct($pdfObj, $elementId, $mapConf, $controls) {
parent::__construct($pdfObj, $mapConf, $controls);
$this->elementId = $elementId;
- $this->override();
+ $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"];
@@ -29,7 +29,7 @@
else {
return "No measurements found.";
}
-
+
$coord = mb_split(",",$this->pdf->getMapExtent());
$mapInfo = $this->pdf->getMapInfo();
foreach ($mapInfo as $k => $v) {
@@ -39,7 +39,7 @@
$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 = makeCoordPairsForFpdi($x_value_str, $y_value_str);
foreach ($theFullArr as $oneFullArr) {
@@ -47,35 +47,46 @@
}
$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 {
+
+ $style = "";
+ if($this->conf->do_fill === 1) {
+ $style .= "F";
+ }
+ if ($this->conf->do_stroke === 1) {
+ $style .= "D";
+ }
+ if($style != "") {
+ $this->pdf->objPdf->SetDrawColor($this->conf->stroke_color->r, $this->conf->stroke_color->g, $this->conf->stroke_color->b);
+ $this->pdf->objPdf->ClippingRect($mapOffset_left, $mapOffset_bottom, $map_width, $map_height, true);
+ if ($isClosed) {
+ $this->pdf->objPdf->Polygon($thePolyArr, $style, array("all" => get_object_vars($this->conf->line_style)), $this->conf->fill_color);
+ }
+ else {
+ if ($this->conf->do_stroke === 1) {
$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]);
- }
- }
+ 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], get_object_vars($this->conf->line_style));
+ }
+ }
+ }
+ }
+ $this->pdf->objPdf->UnsetClipping();
}
- $this->pdf->objPdf->UnsetClipping();
-
}
+
-
}
?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list