/** * Draws an arc. * * @param integer $x The x coordinate of the centre. * @param integer $y The y coordinate of the centre. * @param integer $r The radius of the arc. * @param integer $start The start angle of the arc. * @param integer $end The end angle of the arc. * @param string $color The line color of the arc. * @param string $fill The fill color of the arc (defaults to none). */ public function arc($x, $y, $r, $start, $end, $color = 'black', $fill = 'none') { $points = Horde_Image::arcPoints($r, $start, $end); $points['x1'] += $x; $points['x2'] += $x; $points['x3'] += $x; $points['y1'] += $y; $points['y2'] += $y; $points['y3'] += $y; try { $draw = new ImagickDraw(); $draw->setStrokeColor(new ImagickPixel($color)); $draw->setFillColor(new ImagickPixel($fill)); $draw->arc($x - $r, $y - $r, $x + $r, $y + $r, $start, $end); } catch (ImagickDrawException $e) { throw new Horde_Image_Exception($e); } catch (ImagickPixelException $e) { throw new Horde_Image_Exception($e); } // If filled, draw the outline. if (!empty($fill)) { $mid = round(($start + $end) / 2); list($x1, $y1) = Horde_Image::circlePoint($start, $r * 2); list($x2, $y2) = Horde_Image::circlePoint($mid, $r * 2); list($x3, $y3) = Horde_Image::circlePoint($end, $r * 2); $verts = array(array('x' => $x + round($x3), 'y' => $y + round($y3)), array('x' => $x, 'y' => $y), array('x' => $x + round($x1), 'y' => $y + round($y1))); if ($mid > 90) { $verts1 = array(array('x' => $x + round($x2), 'y' => $y + round($y2)), array('x' => $x, 'y' => $y), array('x' => $x + round($x1), 'y' => $y + round($y1))); $verts2 = array(array('x' => $x + round($x3), 'y' => $y + round($y3)), array('x' => $x, 'y' => $y), array('x' => $x + round($x2), 'y' => $y + round($y2))); $this->polygon($verts1, $fill, $fill); $this->polygon($verts2, $fill, $fill); } else { $this->polygon($verts, $fill, $fill); } $this->polyline($verts, $color); } try { $this->_imagick->drawImage($draw); } catch (ImagickException $e) { throw new Horde_Image_Exception($e); } $draw->destroy(); }
/** * Draw a rounded rectangle. * * @param integer $x The left x-coordinate of the rectangle. * @param integer $y The top y-coordinate of the rectangle. * @param integer $width The width of the rectangle. * @param integer $height The height of the rectangle. * @param integer $round The width of the corner rounding. * @param string $color The line color of the rectangle. * @param string $fill The color to fill the rounded rectangle with. */ public function roundedRectangle($x, $y, $width, $height, $round, $color = 'black', $fill = 'none') { if ($round <= 0) { // Optimize out any calls with no corner rounding. return $this->rectangle($x, $y, $width, $height, $color, $fill); } $c = $this->_allocateColor($color); // Set corner points to avoid lots of redundant math. $x1 = $x + $round; $y1 = $y + $round; $x2 = $x + $width - $round; $y2 = $y + $round; $x3 = $x + $width - $round; $y3 = $y + $height - $round; $x4 = $x + $round; $y4 = $y + $height - $round; $r = $round * 2; // Calculate the upper left arc. $p1 = Horde_Image::arcPoints($round, 180, 225); $p2 = Horde_Image::arcPoints($round, 225, 270); // Calculate the upper right arc. $p3 = Horde_Image::arcPoints($round, 270, 315); $p4 = Horde_Image::arcPoints($round, 315, 360); // Calculate the lower right arc. $p5 = Horde_Image::arcPoints($round, 0, 45); $p6 = Horde_Image::arcPoints($round, 45, 90); // Calculate the lower left arc. $p7 = Horde_Image::arcPoints($round, 90, 135); $p8 = Horde_Image::arcPoints($round, 135, 180); // Draw the corners - upper left, upper right, lower right, // lower left. $this->call('imageArc', array($this->_im, $x1, $y1, $r, $r, 180, 270, $c)); $this->call('imageArc', array($this->_im, $x2, $y2, $r, $r, 270, 360, $c)); $this->call('imageArc', array($this->_im, $x3, $y3, $r, $r, 0, 90, $c)); $this->call('imageArc', array($this->_im, $x4, $y4, $r, $r, 90, 180, $c)); // Draw the connecting sides - top, right, bottom, left. $this->call('imageLine', array($this->_im, $x1 + $p2['x2'], $y1 + $p2['y2'], $x2 + $p3['x1'], $y2 + $p3['y1'], $c)); $this->call('imageLine', array($this->_im, $x2 + $p4['x2'], $y2 + $p4['y2'], $x3 + $p5['x1'], $y3 + $p5['y1'], $c)); $this->call('imageLine', array($this->_im, $x3 + $p6['x2'], $y3 + $p6['y2'], $x4 + $p7['x1'], $y4 + $p7['y1'], $c)); $this->call('imageLine', array($this->_im, $x4 + $p8['x2'], $y4 + $p8['y2'], $x1 + $p1['x1'], $y1 + $p1['y1'], $c)); if ($fill != 'none') { $f = $this->_allocateColor($fill); $this->call('imageFillToBorder', array($this->_im, $x + $width / 2, $y + $height / 2, $c, $f)); } }
/** * Draw an arc. * * @param integer $x The x co-ordinate of the centre. * @param integer $y The y co-ordinate of the centre. * @param integer $r The radius of the arc. * @param integer $start The start angle of the arc. * @param integer $end The end angle of the arc. * @param string $color The line color of the arc. * @param string $fill The fill color of the arc. */ function arc($x, $y, $r, $start, $end, $color = 'black', $fill = 'none') { $s = new SWFShape(); $color = $this->allocateColor($color); $s->setLine(1, $color['red'], $color['green'], $color['blue'], $color['alpha']); if ($fill != 'none') { $fillColor = $this->allocateColor($fill); $f = $s->addFill($fillColor['red'], $fillColor['green'], $fillColor['blue'], $fillColor['alpha']); $s->setRightFill($f); } if ($end - $start <= 45) { $pts = Horde_Image::arcPoints($r, $start, $end); $s->movePenTo($x, $y); $s->drawLineTo($pts['x1'] + $x, $pts['y1'] + $y); $s->drawCurveTo($pts['x3'] + $x, $pts['y3'] + $y, $pts['x2'] + $x, $pts['y2'] + $y); $s->drawLineTo($x, $y); } else { $sections = ceil(($end - $start) / 45); for ($i = 0; $i < $sections; $i++) { $pts = Horde_Image::arcPoints($r, $start + $i * 45, $start + ($i + 1) * 45 > $end ? $end : $start + ($i + 1) * 45); // If we are on the first section, move the pen to the // centre and draw out to the edge. if ($i == 0 && $fill != 'none') { $s->movePenTo($x, $y); $s->drawLineTo($pts['x1'] + $x, $pts['y1'] + $y); } else { $s->movePenTo($pts['x1'] + $x, $pts['y1'] + $y); } // Draw the arc. $s->drawCurveTo($pts['x3'] + $x, $pts['y3'] + $y, $pts['x2'] + $x, $pts['y2'] + $y); } if ($fill != 'none') { // Draw a line from the edge back to the centre to close // off the segment. $s->drawLineTo($x, $y); } } return $this->_movie->add($s); }
/** * Draws a rounded rectangle. * * @param integer $x The left x-coordinate of the rectangle. * @param integer $y The top y-coordinate of the rectangle. * @param integer $width The width of the rectangle. * @param integer $height The height of the rectangle. * @param integer $round The width of the corner rounding. * @param string $color The line color of the rectangle. * @param string $fill The color to fill the rounded rectangle with. */ public function roundedRectangle($x, $y, $width, $height, $round, $color = 'black', $fill = 'none') { if ($round <= 0) { // Optimize out any calls with no corner rounding. $this->rectangle($x, $y, $width, $height, $color, $fill); return; } $c = $this->_allocateColor($color); // Set corner points to avoid lots of redundant math. $xul = $x + $round; $yul = $y + $round; $xur = $x + $width - $round; $yur = $y + $round; $xlr = $x + $width - $round; $ylr = $y + $height - $round; $xll = $x + $round; $yll = $y + $height - $round; $r = $round * 2; // Calculate the upper left arc. $pul = Horde_Image::arcPoints($round, 180, 270); // Calculate the upper right arc. $pur = Horde_Image::arcPoints($round, 270, 360); // Calculate the lower right arc. $plr = Horde_Image::arcPoints($round, 0, 90); // Calculate the lower left arc. $pll = Horde_Image::arcPoints($round, 90, 180); // Draw the corners - upper left, upper right, lower right, lower left. $this->call('imageArc', array($this->_im, $xul, $yul, $r, $r, 180, 270, $c)); $this->call('imageArc', array($this->_im, $xur, $yur, $r, $r, 270, 360, $c)); $this->call('imageArc', array($this->_im, $xlr, $ylr, $r, $r, 0, 90, $c)); $this->call('imageArc', array($this->_im, $xll, $yll, $r, $r, 90, 180, $c)); // Draw the connecting sides - top, right, bottom, left. $this->call('imageLine', array($this->_im, $xul, $y, $xur, $y, $c)); $this->call('imageLine', array($this->_im, $x + $width, $yur, $x + $width, $ylr, $c)); $this->call('imageLine', array($this->_im, $xlr, $y + $height, $xll, $y + $height, $c)); $this->call('imageLine', array($this->_im, $x, $yll, $x, $yul, $c)); if ($fill != 'none') { $f = $this->_allocateColor($fill); $this->call('imageFillToBorder', array($this->_im, $x + $width / 2, $y + $height / 2, $c, $f)); } }
/** * Draws an arc. * * @param integer $x The x co-ordinate of the centre. * @param integer $y The y co-ordinate of the centre. * @param integer $r The radius of the arc. * @param integer $start The start angle of the arc. * @param integer $end The end angle of the arc. * @param string $color The line color of the arc. * @param string $fill The fill color of the arc. */ public function arc($x, $y, $r, $start, $end, $color = 'black', $fill = 'none') { $s = new SWFShape(); $color = $this->allocateColor($color); $s->setLine(1, $color['red'], $color['green'], $color['blue'], $color['alpha']); if ($fill != 'none') { $fillColor = $this->allocateColor($fill); $s->setRightFill($fillColor['red'], $fillColor['green'], $fillColor['blue'], $fillColor['alpha']); } $pts = Horde_Image::arcPoints($r, $start, $end); $s->movePenTo($x, $y); $s->drawArc($r, $start + 90, $end + 90); $s->movePenTo($x, $y); $s->drawLineTo(round($pts['x1']) + $x, round($pts['y1']) + $y); $s->movePenTo($x, $y); $s->drawLineTo(round($pts['x2']) + $x, round($pts['y2']) + $y); $this->_movie->add($s); }