Exemplo n.º 1
0
}
registerClass('TTFFont');
/**
 * Class representing FDB fonts (used with the Ming driver)
 * 
 * @package Artichow
 */
class awFDBFont extends awFileFont
{
    public function __construct($name, $size)
    {
        parent::__construct($name, $size);
        $this->extension = 'fdb';
    }
}
registerClass('FDBFont');
$php = '';
for ($i = 1; $i <= 5; $i++) {
    $php .= '
	class awFont' . $i . ' extends awPHPFont {

		public function __construct() {
			parent::__construct(' . $i . ');
		}

	}
	';
    if (ARTICHOW_PREFIX !== 'aw') {
        $php .= '
		class ' . ARTICHOW_PREFIX . 'Font' . $i . ' extends awFont' . $i . ' {
		}
        }
    }
    function createGrid()
    {
        // Horizontal lines of the grid
        $major = $this->yAxis->tick('major');
        $interval = $major->getInterval();
        $number = $this->yAxis->getLabelNumber() - 1;
        $h = array();
        if ($number > 0) {
            for ($i = 0; $i <= $number; $i++) {
                $h[] = $i / $number;
            }
        }
        // Vertical lines
        $major = $this->xAxis->tick('major');
        $interval = $major->getInterval();
        $number = $this->xAxis->getLabelNumber() - 1;
        $w = array();
        if ($number > 0) {
            for ($i = 0; $i <= $number; $i++) {
                if ($i % $interval === 0) {
                    $w[] = $i / $number;
                }
            }
        }
        $this->grid->setGrid($w, $h);
    }
}
registerClass('MathPlot');
     * @return array Coords for the component
     */
    /**
     * Draw the component on the graph
     * Component should be drawed into specified coords
     *
     * @param Drawer A drawer
     * @param int $x1
     * @param int $y1
     * @param int $x2
     * @param int $y2
     * @param bool $aliasing Use anti-aliasing to draw the component ?
     */
    /**
     * Get space width in pixels
     *
     * @param int $width Component width
     * @param int $height Component height
     * @return array
     */
    function getSpace($width, $height)
    {
        $left = (int) ($width * $this->space->left / 100);
        $right = (int) ($width * $this->space->right / 100);
        $top = (int) ($height * $this->space->top / 100);
        $bottom = (int) ($height * $this->space->bottom / 100);
        return array($left, $right, $top, $bottom);
    }
}
registerClass('Component', TRUE);
Exemplo n.º 4
0
    {
        if ((double) $this->size !== 0.0) {
            return (int) round($this->g1 + $pos / $this->size * ($this->g2 - $this->g1));
        } else {
            return 0;
        }
    }
    private function getBlue($pos)
    {
        if ((double) $this->size !== 0.0) {
            return (int) round($this->b1 + $pos / $this->size * ($this->b2 - $this->b1));
        } else {
            return 0;
        }
    }
    private function getAlpha($pos)
    {
        if ((double) $this->size !== 0.0) {
            return (int) round(($this->a1 + $pos / $this->size * ($this->a2 - $this->a1)) / 127 * 100);
        } else {
            return 0;
        }
    }
}
registerClass('GDGradientDriver');
/*
 * Check for GD2
 */
if (function_exists('imagecreatetruecolor') === FALSE) {
    awImage::drawErrorFile('missing-gd2');
}
Exemplo n.º 5
0
        if ($this->smooth) {
            for ($i = 0; $i < $this->size; $i++) {
                for ($j = 0; $j <= $i; $j++) {
                    $driver->point($color, new awPoint($i, $j + $height - $this->size));
                }
            }
            for ($i = 0; $i < $this->size; $i++) {
                for ($j = 0; $j <= $i; $j++) {
                    $driver->point($color, new awPoint($width - $this->size + $j, $i));
                }
            }
        }
    }
    private function smoothFuture(awDriver $driver, awColor $color, $width, $height)
    {
        if ($this->smooth) {
            for ($i = 0; $i < $this->size; $i++) {
                for ($j = 0; $j <= $i; $j++) {
                    $driver->point($color, new awPoint($i, $this->size - $j - 1));
                }
            }
            for ($i = 0; $i < $this->size; $i++) {
                for ($j = 0; $j <= $i; $j++) {
                    $driver->point($color, new awPoint($width - $this->size + $j, $height - $i - 1));
                }
            }
        }
    }
}
registerClass('Shadow');
Exemplo n.º 6
0
    function polygon($driver, &$polygon)
    {
        // Border is hidden
        if ($this->hide) {
            return;
        }
        $polygon->setStyle($this->style);
        $driver->polygon($this->color, $polygon);
        // In case of LINE_SOLID, Driver::polygon() uses imagepolygon()
        // which automatically closes the shape. In any other case,
        // we have to do it manually here.
        if ($this->style !== LINE_SOLID) {
            $this->closePolygon($driver, $polygon);
        }
    }
    /**
     * Draws the last line of a Polygon, between the first and last point
     * 
     * @param $driver A Driver object
     * @param &$polygon The polygon object to close
     */
    function closePolygon($driver, &$polygon)
    {
        $first = $polygon->get(0);
        $last = $polygon->get($polygon->count() - 1);
        $line = new awLine($first, $last, $this->style, $polygon->getThickness());
        $driver->line($this->color, $line);
    }
}
registerClass('Border');
Exemplo n.º 7
0
    }
    /**
     * Get the line type
     *
     * @return NULL
     */
    public function getLegendLineStyle()
    {
    }
    /**
     * Get the color of line
     *
     * @return NULL
     */
    public function getLegendLineColor()
    {
    }
    /**
     * Get a mark object
     *
     * @return NULL
     */
    public function getLegendMark()
    {
    }
}
registerClass('PiePart');
function callbackPerCent($value)
{
    return $value . '%';
}
Exemplo n.º 8
0
            switch ($this->vAlign) {
                case awLabel::TOP:
                    $y -= $height + $bottom;
                    break;
                case awLabel::MIDDLE:
                    $y -= ($height - $top + $bottom) / 2;
                    break;
                case awLabel::BOTTOM:
                    $y += $top;
                    break;
            }
            $drawer->string($theTextAW, $this->move->move($x, $y));
        }
    }
    protected function getMax(awDrawer $drawer, $function)
    {
        $max = NULL;
        foreach ($this->texts as $key => $text) {
            $text = $this->getText($key);
            $font = $text->getFont();
            if (is_null($max)) {
                $max = $font->{$function}($text);
            } else {
                $max = max($max, $font->{$function}($text));
            }
        }
        return $max;
    }
}
registerClass('Label');
Exemplo n.º 9
0
    public function drawComponent(awDriver $driver, $x1, $y1, $x2, $y2, $aliasing)
    {
        if ($this->lineMode === awLinePlot::MIDDLE) {
            $inc = $this->xAxis->getDistance(0, 1) / 2;
        } else {
            $inc = 0;
        }
        $p1 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStart, $this->lineValue));
        $p2 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStop, $this->lineValue));
        $driver->line($this->lineColor, new awLine($p1->move($inc, 0), $p2->move($inc, 0), $this->lineStyle, $this->lineThickness));
    }
    public function getXAxisNumber()
    {
        if ($this->lineMode === awLinePlot::MIDDLE) {
            return count($this->datay) + 1;
        } else {
            return count($this->datay);
        }
    }
    protected function xAxisPoint($position)
    {
        $y = $this->xAxisZero ? 0 : $this->getRealYMin();
        return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
    }
    public function getXCenter()
    {
        return $this->lineMode === awLinePlot::MIDDLE;
    }
}
registerClass('SimpleLinePlot');
Exemplo n.º 10
0
     *
     * @return Color, Gradient
     */
    public function getBackground()
    {
        return $this->background;
    }
    /**
     * Change padding
     *
     * @param int $left Left padding
     * @param int $right Right padding
     * @param int $top Top padding
     * @param int $bottom Bottom padding
     */
    public function setPadding($left, $right, $top, $bottom)
    {
        $this->padding = array((int) $left, (int) $right, (int) $top, (int) $bottom);
    }
    /**
     * Get current padding
     *
     * @return array
     */
    public function getPadding()
    {
        return $this->padding;
    }
}
registerClass('Text');
Exemplo n.º 11
0
        }
        if ($bottom !== NULL) {
            $this->bottom = (double) $bottom;
        }
    }
    /**
     * Add values to each side
     *
     * @param mixed $left
     * @param mixed $right
     * @param mixed $top
     * @param mixed $bottom
     */
    public function add($left = NULL, $right = NULL, $top = NULL, $bottom = NULL)
    {
        if ($left !== NULL) {
            $this->left += (double) $left;
        }
        if ($right !== NULL) {
            $this->right += (double) $right;
        }
        if ($top !== NULL) {
            $this->top += (double) $top;
        }
        if ($bottom !== NULL) {
            $this->bottom += (double) $bottom;
        }
    }
}
registerClass('Side');
Exemplo n.º 12
0
        }
    }
    protected function getVector()
    {
        $angle = $this->line->getAngle();
        // Compute paddings
        $vector = new awVector($this->line->p1->move(cos($angle) * $this->padding->left, -1 * sin($angle) * $this->padding->left), $this->line->p2->move(-1 * cos($angle) * $this->padding->right, -1 * -1 * sin($angle) * $this->padding->right));
        return $vector;
    }
    public function __clone()
    {
        $this->label = clone $this->label;
        $this->line = clone $this->line;
        $this->title = clone $this->title;
        foreach ($this->ticks as $name => $tick) {
            $this->ticks[$name] = clone $tick;
        }
    }
}
registerClass('Axis');
function toProportionalValue($position, $min, $max)
{
    return $min + ($max - $min) * $position;
}
function toProportionalPosition($value, $min, $max)
{
    if ($max - $min == 0) {
        return 0;
    }
    return ($value - $min) / ($max - $min);
}
Exemplo n.º 13
0
            $y22 = (int) $y;
        } else {
            $x11 = (int) ($x - $this->size / 2);
            $y11 = (int) ($y + $this->size / 2);
            $x12 = (int) ($x + $this->size / 2);
            $y12 = (int) ($y - $this->size / 2);
            $y21 = (int) ($y - $this->size / 2);
            $y22 = (int) ($y + $this->size / 2);
        }
        $x21 = (int) ($x - $this->size / 2);
        $x22 = (int) ($x + $this->size / 2);
        $this->driver->line($this->fill, new awLine(new awPoint($x11, $y11), new awPoint($x12, $y12)));
        $this->driver->line($this->fill, new awLine(new awPoint($x21, $y21), new awPoint($x22, $y22)));
    }
    function drawImage($point)
    {
        if (is_a($this->image, 'awImage')) {
            $width = $this->image->width;
            $height = $this->image->height;
            list($x, $y) = $point->getLocation();
            $x1 = (int) ($x - $width / 2);
            $x2 = $x1 + $width;
            $y1 = (int) ($y - $width / 2);
            $y2 = $y1 + $height;
            $this->border->rectangle($this->driver, new awPoint($x1 - 1, $y1 - 1), new awPoint($x2 + 1, $y2 + 1));
            $this->driver->copyImage($this->image, new awPoint($x1, $y1), new awPoint($x2, $y2));
        }
    }
}
registerClass('Mark');
Exemplo n.º 14
0
    /**
     * Free resources used for this color
     */
    function free()
    {
        if ($this->resource !== NULL) {
            @imagecolordeallocate($this->resource, $this->color);
            $this->resource = NULL;
        }
    }
    function php5Destructor()
    {
        $this->free();
    }
}
registerClass('Color');
$colors = array('Black' => array(0, 0, 0), 'AlmostBlack' => array(48, 48, 48), 'VeryDarkGray' => array(88, 88, 88), 'DarkGray' => array(128, 128, 128), 'MidGray' => array(160, 160, 160), 'LightGray' => array(195, 195, 195), 'VeryLightGray' => array(220, 220, 220), 'White' => array(255, 255, 255), 'VeryDarkRed' => array(64, 0, 0), 'DarkRed' => array(128, 0, 0), 'MidRed' => array(192, 0, 0), 'Red' => array(255, 0, 0), 'LightRed' => array(255, 192, 192), 'VeryDarkGreen' => array(0, 64, 0), 'DarkGreen' => array(0, 128, 0), 'MidGreen' => array(0, 192, 0), 'Green' => array(0, 255, 0), 'LightGreen' => array(192, 255, 192), 'VeryDarkBlue' => array(0, 0, 64), 'DarkBlue' => array(0, 0, 128), 'MidBlue' => array(0, 0, 192), 'Blue' => array(0, 0, 255), 'LightBlue' => array(192, 192, 255), 'VeryDarkYellow' => array(64, 64, 0), 'DarkYellow' => array(128, 128, 0), 'MidYellow' => array(192, 192, 0), 'Yellow' => array(255, 255, 2), 'LightYellow' => array(255, 255, 192), 'VeryDarkCyan' => array(0, 64, 64), 'DarkCyan' => array(0, 128, 128), 'MidCyan' => array(0, 192, 192), 'Cyan' => array(0, 255, 255), 'LightCyan' => array(192, 255, 255), 'VeryDarkMagenta' => array(64, 0, 64), 'DarkMagenta' => array(128, 0, 128), 'MidMagenta' => array(192, 0, 192), 'Magenta' => array(255, 0, 255), 'LightMagenta' => array(255, 192, 255), 'DarkOrange' => array(192, 88, 0), 'Orange' => array(255, 128, 0), 'LightOrange' => array(255, 168, 88), 'VeryLightOrange' => array(255, 220, 168), 'DarkPink' => array(192, 0, 88), 'Pink' => array(255, 0, 128), 'LightPink' => array(255, 88, 168), 'VeryLightPink' => array(255, 168, 220), 'DarkPurple' => array(88, 0, 192), 'Purple' => array(128, 0, 255), 'LightPurple' => array(168, 88, 255), 'VeryLightPurple' => array(220, 168, 255));
$php = '';
foreach ($colors as $name => $color) {
    list($red, $green, $blue) = $color;
    $php .= '
	class aw' . $name . ' extends awColor {
	
		function aw' . $name . '($alpha = 0) {
			parent::awColor(' . $red . ', ' . $green . ', ' . $blue . ', $alpha);
		}
	
	}
	';
    if (ARTICHOW_PREFIX !== 'aw') {
        $php .= '
Exemplo n.º 15
0
    /**
     * Get an argument
     *
     * @param string $name
     * @param mixed $default Default value if the argument does not exist (default to NULL)
     * @return mixed Argument value
     */
    protected function getArg($name, $default = NULL)
    {
        if (array_key_exists($name, $this->args)) {
            return $this->args[$name];
        } else {
            return $default;
        }
    }
    /**
     * Change several arguments
     *
     * @param array $args New arguments
     */
    public function setArgs($args)
    {
        if (is_array($args)) {
            foreach ($args as $name => $value) {
                $this->setArg($name, $value);
            }
        }
    }
}
registerClass('Pattern', TRUE);
Exemplo n.º 16
0
    public function draw(awDriver $driver, $x1, $y1, $x2, $y2)
    {
        if ($this->background instanceof awColor) {
            // Draw background color
            $driver->filledRectangle($this->background, awLine::build($x1, $y1, $x2, $y2));
        }
        if ($this->hide === FALSE) {
            $this->drawGrid($driver, $this->color, $this->hideVertical ? array() : $this->xgrid, $this->hideHorizontal ? array() : $this->ygrid, $x1, $y1, $x2, $y2, $this->type, $this->space, $this->interval[0], $this->interval[1]);
        }
    }
    private function drawGrid(awDriver $driver, awColor $color, $nx, $ny, $x1, $y1, $x2, $y2, $type, $space, $hInterval, $vInterval)
    {
        list($left, $right, $top, $bottom) = $space;
        $width = $x2 - $x1 - $left - $right;
        $height = $y2 - $y1 - $top - $bottom;
        foreach ($nx as $key => $n) {
            if ($key % $vInterval === 0) {
                $pos = (int) round($x1 + $left + $n * $width);
                $driver->line($color, new awLine(new awPoint($pos, $y1), new awPoint($pos, $y2), $type));
            }
        }
        foreach ($ny as $key => $n) {
            if ($key % $hInterval === 0) {
                $pos = (int) round($y1 + $top + $n * $height);
                $driver->line($color, new awLine(new awPoint($x1, $pos), new awPoint($x2, $pos), $type));
            }
        }
    }
}
registerClass('Grid');
Exemplo n.º 17
0
        // Select axis (left if possible, right otherwise)
        if ($this->isAxisUsed(awPlot::LEFT)) {
            $axis = $this->axis->left;
        } else {
            $axis = $this->axis->right;
        }
        return $axis;
    }
    protected function selectXAxis()
    {
        // Select axis (bottom if possible, top otherwise)
        if ($this->isAxisUsed(awPlot::BOTTOM)) {
            $axis = $this->axis->bottom;
        } else {
            $axis = $this->axis->top;
        }
        return $axis;
    }
    protected function getXAxisNumber()
    {
        $offset = $this->components[0];
        $max = $offset->getXAxisNumber();
        for ($i = 1; $i < count($this->components); $i++) {
            $offset = $this->components[$i];
            $max = max($max, $offset->getXAxisNumber());
        }
        return $max;
    }
}
registerClass('PlotGroup');
Exemplo n.º 18
0
    /**
     * Get a point at a position in the polygon
     *
     * @param int $pos Point position
     * @return Point
     */
    public function get($pos)
    {
        return $this->points[$pos];
    }
    /**
     * Count number of points in the polygon
     *
     * @return int
     */
    public function count()
    {
        return count($this->points);
    }
    /**
     * Returns all points in the polygon
     *
     * @return array
     */
    public function all()
    {
        return $this->points;
    }
}
registerClass('Polygon');
Exemplo n.º 19
0
            awImage::drawError("Class FileFontDriver: Unable to get font average width.");
        }
        list(, , $x2, $y2, , , $x1, $y1) = $box;
        return abs($x2 - $x1) / strlen($text);
    }
    private function getMingTextHeight(awText $text)
    {
        $font = $text->getFont();
        if ($font->getExtension() === NULL) {
            $font->setExtension('fdb');
        }
        $flashFont = new SWFFont(ARTICHOW_FONT . '/' . $font->name . '.' . $font->getExtension());
        $flashText = new SWFText();
        $flashText->setFont($flashFont);
        return $flashText->getAscent($text->getText());
    }
    private function getMingTextWidth(awText $text)
    {
        $font = $text->getFont();
        if ($font->getExtension() === NULL) {
            $font->setExtension('fdb');
        }
        $flashFont = new SWFFont(ARTICHOW_FONT . '/' . $font->name . '.' . $font->getExtension());
        $flashText = new SWFText();
        $flashText->setFont($flashFont);
        return $flashText->getWidth($text->getText());
    }
}
registerClass('FileFontDriver');
// Include ARTICHOW_DRIVER by default to preserve backward compatibility.
require_once dirname(__FILE__) . '/drivers/' . ARTICHOW_DRIVER . '.class.php';
                }
                $prev = $point;
            }
        }
        // Draw impulses
        if ($this->impulse instanceof awColor) {
            foreach ($polygon->all() as $key => $point) {
                if ($point !== NULL) {
                    $zero = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, 0));
                    $driver->line($this->impulse, new awLine($zero, $point, awLine::SOLID, 1));
                }
            }
        }
        // Draw marks and labels
        foreach ($polygon->all() as $key => $point) {
            $this->mark->draw($driver, $point);
            $this->label->draw($driver, $point, $key);
        }
    }
    protected function xAxisPoint($position)
    {
        $y = $this->xAxisZero ? 0 : $this->getRealYMin();
        return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
    }
    public function getXCenter()
    {
        return FALSE;
    }
}
registerClass('ScatterPlot');
Exemplo n.º 21
0
     * @param $gradient The awGradient object to convert
     * @return array
     */
    function getGradient($gradient)
    {
        $flashGradient = new SWFGradient();
        // Get RGBA values for the gradient boundaries
        list($r1, $g1, $b1, $a1) = $this->getColor($gradient->from);
        list($r2, $g2, $b2, $a2) = $this->getColor($gradient->to);
        $flashGradient->addEntry(0, $r1, $g1, $b1, $a1);
        if (is_a($gradient, 'awBilinearGradient')) {
            $flashGradient->addEntry($gradient->center, $r2, $g2, $b2, $a2);
            $flashGradient->addEntry(1, $r1, $g1, $b1, $a1);
            return array($flashGradient, SWFFILL_LINEAR_GRADIENT);
        } else {
            $flashGradient->addEntry(1, $r2, $g2, $b2, $a2);
            if (is_a($gradient, 'awLinearGradient')) {
                return array($flashGradient, SWFFILL_LINEAR_GRADIENT);
            } else {
                return array($flashGradient, SWFFILL_RADIAL_GRADIENT);
            }
        }
    }
}
registerClass('MingDriver');
/*
 * Check for ming presence
 */
if (function_exists('ming_useswfversion') === FALSE) {
    awImage::drawErrorFile('missing-ming');
}
Exemplo n.º 22
0
		
		if($image and in_array($image[2], array(2, 3))) {
		
			$this->setSize($image[0], $image[1]);
			
			switch($image[2]) {
			
				case 2 :
					$this->resource = imagecreatefromjpeg($file);
					break;
			
				case 3 :
					$this->resource = imagecreatefrompng($file);
					break;
			
			}
		
			$this->drawer = new awDrawer($this->resource);
			$this->drawer->setImageSize($this->width, $this->height);
			
		} else {
			trigger_error("Artichow does not support this image (must be in PNG or JPEG)", E_USER_ERROR);
		}
	
	}

}

registerClass('FileImage');
?>
Exemplo n.º 23
0
                        // Draw rectangle border
                        $this->border->rectangle($driver, $from->move(0, 0), $to->move(0, 0));
                    }
                    unset($background, $from, $to);
                    break;
            }
        }
    }
    private function drawBase(awDriver $driver, awPoint $p, $width, $height)
    {
        $this->border->rectangle($driver, $p, $p->move($width, $height));
        $size = $this->border->visible() ? 1 : 0;
        $driver->filledRectangle($this->background, new awLine($p->move($size, $size), $p->move($width - $size, $height - $size)));
    }
}
registerClass('Legend');
/**
 * You can add a legend to components which implements this interface
 *
 * @package Artichow
 */
interface awLegendable
{
    /**
     * Get the line type
     *
     * @return int
     */
    public function getLegendLineStyle();
    /**
     * Get the line thickness
Exemplo n.º 24
0
    public function getXAxisNumber()
    {
        return count($this->datay) + 1;
    }
    // ça bidouille à fond ici !
    public function getXMax()
    {
        return array_max($this->datax) + 1;
    }
    public function getXCenter()
    {
        return TRUE;
    }
    protected function drawBar(awDrawer $drawer, awPoint $p1, awPoint $p2)
    {
        // Draw shadow
        $this->barShadow->draw($drawer, $p1, $p2, awShadow::OUT);
        if (abs($p2->y - $p1->y) > 1) {
            $this->barBorder->rectangle($drawer, $p1, $p2);
            if ($this->barBackground !== NULL) {
                $size = $this->barBorder->visible() ? 1 : 0;
                $b1 = $p1->move($size, $size);
                $b2 = $p2->move(-1 * $size, -1 * $size);
                // Draw background
                $drawer->filledRectangle($this->barBackground, new awLine($b1, $b2));
            }
        }
    }
}
registerClass('BarPlot');
Exemplo n.º 25
0
		return new awColor(
			$this->getRed($pos),
			$this->getGreen($pos),
			$this->getBlue($pos),
			$this->getAlpha($pos)
		);
		
	}
	
	
	 function getRed($pos) {
		return (int)round($this->r1 + ($pos / $this->size) * ($this->r2 - $this->r1));
	}
	
	 function getGreen($pos) {
		return (int)round($this->g1 + ($pos / $this->size) * ($this->g2 - $this->g1));
	}
	
	 function getBlue($pos) {
		return (int)round($this->b1 + ($pos / $this->size) * ($this->b2 - $this->b1));
	}
	
	 function getAlpha($pos) {
		return (int)round(($this->a1 + ($pos / $this->size) * ($this->a2 - $this->a1)) / 127 * 100);
	}

}

registerClass('GradientDrawer');
?>
Exemplo n.º 26
0
        $stop = $inc * $number;
        $position = 0;
        for ($i = $start; round($i, 6) < $stop; $i += $inc) {
            if ($position % $this->interval === 0) {
                $p = $vector->p1->move(round($i * cos($vector->getAngle()), 6), round($i * sin($vector->getAngle() * -1), 6));
                $this->drawTick($drawer, $p, $from, $to);
            }
            $position++;
        }
        //echo '<br><br>';
    }
    function drawTick($drawer, $p, $from, $to)
    {
        //	echo $this->size.':'.$angle.'|<b>'.cos($angle).'</b>/';
        // The round avoid some errors in the calcul
        // For example, 12.00000008575245 becomes 12
        $p1 = $p;
        $p2 = $p;
        if ($from !== NULL) {
            $p1 = $p1->move(round($this->size * cos($from), 6), round($this->size * sin($from) * -1, 6));
        }
        if ($to !== NULL) {
            $p2 = $p2->move(round($this->size * cos($to), 6), round($this->size * sin($to) * -1, 6));
        }
        //echo $p1->x.':'.$p2->x.'('.$p1->y.':'.$p2->y.')'.'/';
        $vector = new awVector($p1, $p2);
        $drawer->line($this->color, $vector);
    }
}
registerClass('Tick');
Exemplo n.º 27
0
    }
    private function cache($data)
    {
        if (ARTICHOW_CACHE and $this->name !== NULL) {
            if (is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) {
                awImage::drawError("Class Graph: Cache directory is not writable.");
            }
            file_put_contents($this->fileCache, $data);
            file_put_contents($this->fileCacheTime, $this->timeout . "\n" . $this->getFormatString());
        }
    }
    private static function cleanGraphCache($file)
    {
        list($time, $type) = explode("\n", file_get_contents($file));
        $time = (int) $time;
        if ($time !== 0 and $time < time()) {
            return NULL;
        } else {
            return $type;
        }
    }
}
registerClass('Graph');
/*
 * To preserve PHP 4 compatibility
 */
function microtimeFloat()
{
    list($usec, $sec) = explode(" ", microtime());
    return (double) $usec + (double) $sec;
}
Exemplo n.º 28
0
    /**
     * Gradient center
     *
     * @var float Center between 0 and 1
     */
    public $center;
    /**
     * Build the bilinear gradient
     *
     * @param awColor $from From color
     * @param awColor $to To color
     * @param int $angle Gradient angle
     * @param int $center Gradient center
     */
    public function __construct($from, $to, $angle, $center = 0.5)
    {
        parent::__construct($from, $to, $angle);
        $this->center = (double) $center;
    }
}
registerClass('BilinearGradient');
/**
 * Create a radial gradient
 *
 * @package Artichow
 */
class awRadialGradient extends awGradient
{
}
registerClass('RadialGradient');
Exemplo n.º 29
0
/**
 * Class representing TTF fonts
 * 
 * @package Artichow
 */
class awTTFFont extends awFileFont
{
    public function __construct($name, $size)
    {
        parent::__construct($name, $size);
        if ($this->getExtension() === NULL) {
            $this->setExtension('ttf');
        }
    }
}
registerClass('TTFFont');
/* <php5> */
$php = '';
for ($i = 1; $i <= 5; $i++) {
    $php .= '
	class awFont' . $i . ' extends awPHPFont {

		public function __construct() {
			parent::__construct(' . $i . ');
		}

	}
	';
    if (ARTICHOW_PREFIX !== 'aw') {
        $php .= '
		class ' . ARTICHOW_PREFIX . 'Font' . $i . ' extends awFont' . $i . ' {
        }
        $width = array_sum($widths);
        $height = array_max($heights);
        $totalWidth = $width + 10 + count($texts) * 10;
        $totalHeight = $height + 20;
        $this->setSize($totalWidth, $totalHeight);
        $this->create();
        for ($i = 0; $i < strlen($this->string); $i++) {
            $this->drawer->string($texts[$i], new awPoint(5 + array_sum(array_slice($widths, 0, $i)) + $widths[$i] / 2 + $i * 10, 10 + ($height - $heights[$i]) / 2));
        }
        $this->drawNoise($totalWidth, $totalHeight);
        $this->send();
    }
    protected function drawNoise($width, $height)
    {
        $points = $this->noise * 30;
        $color = new awColor(0, 0, 0);
        for ($i = 0; $i < $points; $i++) {
            $this->drawer->point($color, new awPoint(mt_rand(0, $width), mt_rand(0, $height)));
        }
    }
    protected function session()
    {
        // Start session if needed
        if (!session_id()) {
            session_start();
        }
    }
}
registerClass('AntiSpam');