Skip to content

Commit

Permalink
Fix and drastically simplify arc().
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Mar 12, 2015
1 parent 203bef9 commit b4e1a04
Showing 1 changed file with 8 additions and 44 deletions.
52 changes: 8 additions & 44 deletions framework/Image/lib/Horde/Image/Swf.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,57 +481,21 @@ public function arc(

if ($fill != 'none') {
$fillColor = $this->allocateColor($fill);
$f = $s->addFill(
$s->setRightFill(
$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);
}
}
$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);
}
Expand Down

0 comments on commit b4e1a04

Please sign in to comment.