1<?php 2 3require_once(HTML2PS_DIR.'path.point.php'); 4require_once(HTML2PS_DIR.'path.rectangle.php'); 5 6class Path { 7 var $_points; 8 9 function Path() { 10 $this->clear(); 11 } 12 13 /** 14 * Returns a bounding box rectangle object 15 * 16 * Pre-conditions: 17 * - there's at least one point in the path 18 */ 19 function getBbox() { 20 if (count($this->_points) < 1) { 21 die("Path::getBbox() called for path without points"); 22 } 23 24 $rect = new Rectangle($this->_points[0]->_clone(), 25 $this->_points[0]->_clone()); 26 27 foreach ($this->_points as $point) { 28 $rect->ur->x = max($rect->ur->x, $point->x); 29 $rect->ur->y = max($rect->ur->y, $point->y); 30 $rect->ll->x = min($rect->ll->x, $point->x); 31 $rect->ll->y = min($rect->ll->y, $point->y); 32 }; 33 34 return $rect; 35 } 36 37 function clear() { 38 $this->_points = array(); 39 } 40 41 function addPoint($point) { 42 $this->_points[] = $point; 43 } 44 45 function getPoint($index) { 46 return $this->_points[$index]; 47 } 48 49 function getPoints() { 50 return $this->_points; 51 } 52 53 function getPointArray() { 54 $result = array(); 55 foreach ($this->_points as $point) { 56 $result[] = $point->x; 57 $result[] = $point->y; 58 }; 59 return $result; 60 } 61 62 function close() { 63 $this->addPoint($this->getPoint(0)); 64 } 65 66 function get_point_count() { 67 return count($this->_points); 68 } 69 70 /** 71 * @deprecated 72 */ 73 function getPointCount() { 74 return $this->get_point_count(); 75 } 76 77 function is_empty() { 78 return ($this->get_point_count() == 0); 79 } 80 81 function fill($transform, $image, $color) { 82 $coords = $this->getPointArray(); 83 $size = $this->getPointCount(); 84 85 for ($i=0; $i<$size; $i++) { 86 $transform->apply($coords[$i*2], $coords[$i*2+1]); 87 }; 88 89 imagefilledpolygon($image, $coords, $size, $color); 90 } 91 92 function stroke($transform, $image, $color) { 93 $coords = $this->getPointArray(); 94 $size = $this->getPointCount(); 95 96 for ($i=0; $i<$size; $i++) { 97 $transform->apply($coords[$i*2], $coords[$i*2+1]); 98 }; 99 100 imagepolygon($image, $coords, $size, $color); 101 } 102} 103 104class PathCircle extends Path { 105 var $_x; 106 var $_y; 107 var $_r; 108 109 function PathCircle() { 110 $this->Path(); 111 112 $this->set_x(0); 113 $this->set_y(0); 114 $this->set_r(0); 115 } 116 117 function fill($transform, $image, $color) { 118 $x = $this->get_x(); 119 $y = $this->get_y(); 120 121 $transform->apply($x, $y); 122 123 $dummy = 0; 124 $transform->apply($r, $dummy); 125 126 imagefilledellipse($image, 127 $x, 128 $y, 129 $r*2, // width = diameter 130 $r*2, // height = diameter 131 $color); 132 } 133 134 function get_r() { 135 return $this->_r; 136 } 137 138 function get_x() { 139 return $this->_x; 140 } 141 142 function get_y() { 143 return $this->_y; 144 } 145 146 function set_r($r) { 147 $this->_r = $r; 148 } 149 150 function set_x($x) { 151 $this->_x = $x; 152 } 153 154 function set_y($y) { 155 $this->_y = $y; 156 } 157 158 function stroke($transform, $image, $color) { 159 $x = $this->get_x(); 160 $y = $this->get_y(); 161 162 $transform->apply($x, $y); 163 164 $dummy = 0; 165 $transform->apply($r, $dummy); 166 167 imageellipse($image, 168 $x, 169 $y, 170 $r*2, // width = diameter 171 $r*2, // height = diameter 172 $color); 173 } 174} 175 176?>