/** * Set the fill and line properties for a SWWFShape according to the * given parameters. * * @param SWFShape $shape * @param ezcGraphColor $color * @param mixed $thickness * @param mixed $filled * @return void */ protected function setShapeColor(SWFShape $shape, ezcGraphColor $color, $thickness, $filled) { if ($filled) { switch (true) { case $color instanceof ezcGraphLinearGradient: $gradient = new SWFGradient(); $gradient->addEntry(0, $color->startColor->red, $color->startColor->green, $color->startColor->blue, 255 - $color->startColor->alpha); $gradient->addEntry(1, $color->endColor->red, $color->endColor->green, $color->endColor->blue, 255 - $color->endColor->alpha); $fill = $shape->addFill($gradient, SWFFILL_LINEAR_GRADIENT); // Calculate desired length of gradient $length = sqrt(pow($color->endPoint->x - $color->startPoint->x, 2) + pow($color->endPoint->y - $color->startPoint->y, 2)); $fill->scaleTo($this->modifyCoordinate($length) / 32768, $this->modifyCoordinate($length) / 32768); $fill->rotateTo(rad2deg(asin(($color->endPoint->x - $color->startPoint->x) / $length) + 180)); $fill->moveTo($this->modifyCoordinate(($color->startPoint->x + $color->endPoint->x) / 2), $this->modifyCoordinate(($color->startPoint->y + $color->endPoint->y) / 2)); $shape->setLeftFill($fill); break; case $color instanceof ezcGraphRadialGradient: $gradient = new SWFGradient(); $gradient->addEntry(0, $color->startColor->red, $color->startColor->green, $color->startColor->blue, 255 - $color->startColor->alpha); $gradient->addEntry(1, $color->endColor->red, $color->endColor->green, $color->endColor->blue, 255 - $color->endColor->alpha); $fill = $shape->addFill($gradient, SWFFILL_RADIAL_GRADIENT); $fill->scaleTo($this->modifyCoordinate($color->width) / 32768, $this->modifyCoordinate($color->height) / 32768); $fill->moveTo($this->modifyCoordinate($color->center->x), $this->modifyCoordinate($color->center->y)); $shape->setLeftFill($fill); break; default: $fill = $shape->addFill($color->red, $color->green, $color->blue, 255 - $color->alpha); $shape->setLeftFill($fill); break; } } else { $shape->setLine($this->modifyCoordinate($thickness), $color->red, $color->green, $color->blue, 255 - $color->alpha); } }