Source for file graphics.inc.php
Documentation is available at graphics.inc.php
* This file is part of the VCL for PHP project
* Copyright (c) 2004-2007 qadram software <support@qadram.com>
* Checkout AUTHORS file for more information on the developers
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
define('taCenter','taCenter');
define('taJustify','taJustify');
define('fsNormal','fsNormal');
define('fsItalic','fsItalic');
define('fsOblique','fsOblique');
define('caCapitalize','caCapitalize');
define('caUpperCase','caUpperCase');
define('caLowerCase','caLowerCase');
define('vaNormal','vaNormal');
define('vaSmallCaps','vaSmallCaps');
define('psDashDot', 'psDashDot');
define('psDashDotDot', 'psDashDotDot');
define('FLOW_LAYOUT','FLOW_LAYOUT');
define('XY_LAYOUT','XY_LAYOUT');
define('ABS_XY_LAYOUT','ABS_XY_LAYOUT');
define('GRIDBAG_LAYOUT','GRIDBAG_LAYOUT');
define('ROW_LAYOUT','ROW_LAYOUT');
define('COL_LAYOUT','COL_LAYOUT');
* Layout encapsulation to allow any component to hold
* controls and render them in very different ways
private $_type= ABS_XY_LAYOUT;
function getType() { return $this->_type; }
function setType($value) { $this->_type= $value; }
function getRows() { return $this->_rows; }
function setRows($value) { $this->_rows= $value; }
function defaultRows() { return 5; }
* Columns for this layout
function getCols() { return $this->_cols; }
function setCols($value) { $this->_cols= $value; }
function defaultCols() { return 5; }
* Dump an absolute layout
* @param array $exclude Classnames of the controls you want to exclude from dumping
if (($v->Visible) && (!$v->IsLayer) && (($this->_control->methodExists('getActiveLayer')) && (string) $v->Layer==(string) $this->_control->Activelayer)) $dump= true;
else if (($v->Visible) && (!$v->IsLayer)) $dump= true;
// if (($v->Visible) && (!$v->IsLayer) && ((string)$v->Layer==(string)$this->_control->Activelayer))
$style= "Z-INDEX: $k; LEFT: ". $left. "px; WIDTH: ". $aw. "px; POSITION: absolute; TOP: ". $top. "px; HEIGHT: ". $ah. "px";
echo "<div id=\"". $v->Name. "_outer\" style=\"$style\">\n";
* Dump a fixed coordinate layout using tables
* @param array $exclude Classnames of the controls you want to exclude from dumping
//Iterates through controls calling show for all of them
if (($v->Visible) && (!$v->IsLayer) && (($this->_control->methodExists('getActiveLayer')) && (string) $v->Layer==(string) $this->_control->Activelayer)) $dump= true;
else if (($v->Visible) && (!$v->IsLayer)) $dump= true;
//Dumps the inner controls
if ($this->_control->controls->count()>= 1)
if ($x[0]!= 0) $widths[]= $x[0];
while (list ($k,$v)= each($x))
if ($x[$k+ 1]- $v!= 0) $widths[]= $x[$k+ 1]- $v;
if ($y[0]!= 0) $heights[]= $y[0];
while (list ($k,$v)= each($y))
if ($y[$k+ 1]- $v!= 0) $heights[]= $y[$k+ 1]- $v;
while (list ($hk,$hv)= each($heights))
while (list ($k,$v)= each($widths))
if ((!is_object($pos[$x][$y])) && ($pos[$x][$y]==- 1))
for ($kkk= $hk;$kkk< count($heights);$kkk++ )
for ($ppp= $k;$ppp< count($widths);$ppp++ )
while(list ($ak,$av)= each($also))
echo "<td $width $hh $rs $cs valign=\"top\">";
echo "<img src=\"vcl/images/pixel_trans.gif\" width=\"1\" height=\"1\">";
echo "<tr height=\"$hv\">";
echo "<img src=\"vcl/images/pixel_trans.gif\" width=\"1\" height=\"1\">";
if (($v->Visible) && ($v->IsLayer))
* Dump a flow layout, basically, no layout at all
* @param array $exclude Classnames of the controls you want to exclude from dumping
* Dump the layout contents depending on the layout type
* @param array $exclude Classnames of the controls you want to exclude from dumping
* @param array $exclude Classnames of the controls you want to exclude from dumping
* @param array $exclude Classnames of the controls you want to exclude from dumping
* @param array $exclude Classnames of the controls you want to exclude from dumping
* @param array $exclude Classnames of the controls you want to exclude from dumping
* @param integer $cols Number of columns for the grid
* @param integer $rows Number of rows for the grid
* @param string $width Width for the layout
function dumpGrid($exclude= array(),$cols,$rows,$width)
$cwidth = round($pwidth / $cols,0);
$cheight = round($pheight / $rows,0);
$col= round($v->Left / $cwidth,0);
$row= round($v->Top / $cheight,0);
$controls[$col][$row]= $v;
echo "<table width=\"$width\" height=\"$pheight\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
for($y= 0;$y<= $rows- 1;$y++ )
for($x= 0;$x<= $cols- 1;$x++ )
if (isset ($controls[$x][$y]))
$cspan = round(($v->Width / $cwidth),0);
//for ($xx=$x+1;$xx<=$x+$cspan;$xx++) $controls[$xx][$y]=-1;
$rspan = round(($v->Height / $cheight),0);
//for ($yy=$y+1;$yy<=$y+$rspan;$yy++) $controls[$x][$yy]=-1;
for ($xx= $x;$xx< $x+ $cspan;$xx++ )
for ($yy= $y;$yy< $y+ $rspan;$yy++ )
if ($cspan> 1) $cspan= " colspan=\"$cspan\" ";
if ($rspan> 1) $rspan= " rowspan=\"$rspan\" ";
$pw= round((100* $v->Width)/ $pwidth);
$ph= round((100* $v->Height)/ $pheight);
echo "<td valign=\"top\" $pw $ph $cspan $rspan>\n";
private $_updatecounter = 0;
* Assign Font object to another Font object.
* @param object $dest Destination, where the new font settings are assigned to.
// make sure modified() is not always called while assigning new values
$dest->setFamily($this->getFamily());
$dest->setSize($this->getSize());
$dest->setColor($this->getColor());
$dest->setAlign($this->getAlign());
$dest->setStyle($this->getStyle());
$dest->setCase($this->getCase());
$dest->setLineHeight($this->getLineHeight());
$dest->setVariant($this->getVariant());
$dest->setWeight($this->getWeight());
* Call startUpdate() when multiple properties of the Font are updated at
* the same time. Once finished updating, call endUpdate().
* It prevents the updating of the control where the Font is assigned to
* until the endUpdate() function is called.
* Re-enables the notification mechanism to the control.
* Note: endUpdate() has to be called as many times as startUpdate() was
* called on the same Font object.
// let's just make sure that if the endUpdate() is called too many times
// that the $this->_updatecounter is valid and the font is updated
if ($this->_updatecounter < 0)
$this->_updatecounter = 0;
// when finished updating call the modified() function to notify the control.
if ($this->_updatecounter == 0)
* Indicates if the Font object is in update mode. If true, the control
* where the Font is assigned to will not be notified when a property changes.
return $this->_updatecounter != 0;
* Check if the font has been modified to set to false the parentfont
* property of the control, if any
$fstring= $f->readFontString();
$tstring= $this->readFontString();
if ($parent!= null) $fstring= $parent->Font->readFontString();
// check if font changed and if the ParentFont can be reset
if ($fstring!= $tstring && $this->_control->DoParentReset)
if ($this->_control->methodExists("updateChildrenFonts"))
* Font list to be used to render this font
function getFamily() { return $this->_family; }
function defaultFamily() { return "Verdana"; }
* Size to be used to render this font
function getSize() { return $this->_size; }
function setSize($value) { $this->_size= $value; $this->modified(); }
function defaultSize() { return "10px"; }
function getLineHeight() { return $this->_lineheight; }
function defaultLineHeight() { return ""; }
* Style to be used to render this font
function getStyle() { return $this->_style; }
function setStyle($value) { $this->_style= $value; $this->modified(); }
function defaultStyle() { return ""; }
* Case conversion to be used to render this font
function getCase() { return $this->_case; }
function setCase($value) { $this->_case= $value; $this->modified(); }
function defaultCase() { return ""; }
* Variant conversion to be used to render this font
function getVariant() { return $this->_variant; }
function defaultVariant() { return ""; }
function getColor() { return $this->_color; }
function setColor($value) { $this->_color= $value; $this->modified(); }
function defaultColor() { return ""; }
* Specifies the alignment to be sued for this font
function getAlign() { return $this->_align; }
function setAlign($value) { $this->_align= $value; $this->modified(); }
function defaultAlign() { return taNone; }
* Specifies the weight (bold) for this font
function getWeight() { return $this->_weight; }
function defaultWeight() { return ""; }
* Returns an style string to be asigned to the tag
function readFontString()
if ($this->_control!=null)
if ($this->_control->ParentFont)
$parent=$this->_control->Parent;
if ($parent!=null) return($parent->Font->readFontString());
case taLeft: $textalign= "text-align: left;"; break;
case taRight: $textalign= "text-align: right;"; break;
case taCenter: $textalign= "text-align: center;"; break;
case taJustify: $textalign= "text-align: justify;"; break;
case fsNormal: $fontstyle= "font-style: normal;"; break;
case fsItalic: $fontstyle= "font-style: italic;"; break;
case fsOblique: $fontstyle= "font-style: oblique;"; break;
case vaNormal: $fontstyle= "font-variant: normal;"; break;
case vaSmallCaps: $fontstyle= "font-variant: small-caps;"; break;
case caCapitalize: $texttransform= "text-transform: capitalize;"; break;
case caUpperCase: $texttransform= "text-transform: uppercase;"; break;
case caLowerCase: $texttransform= "text-transform: lowercase;"; break;
case caNone: $texttransform= "text-transform: none;"; break;
$result= " font-family: $this->_family; font-size: $this->_size; $color$fontweight$textalign$fontstyle$lineheight$fontvariant$texttransform ";
// protected $_style=psSolid;
$dest->Color= $this->Color;
$dest->Width= $this->Width;
// $dest->Style=$this->Style;
function getColor() { return $this->_color; }
function setColor($value) { $this->_color= $value; $this->modified(); }
function defaultColor() { return "#000000"; }
function getWidth() { return $this->_width; }
function setWidth($value) { $this->_width= $value; $this->modified(); }
function defaultWidth() { return "1"; }
// function getStyle() { return $this->_style; }
// function setStyle($value) { $this->_style=$value; }
// function defaultStyle() { return psSolid; $this->modified(); }
$dest->Color= $this->Color;
function getColor() { return $this->_color; }
function setColor($value) { $this->_color= $value; $this->modified(); }
function defaultColor() { return ""; }
* Create color based on HEX RGB mask
* mask can be prefixed with #
while (strlen($hexColor) > 6) { $hexColor = substr($hexColor, 1); };
sscanf($hexColor, "%2x%2x%2x", $red, $green, $blue);
return ImageColorAllocate($img, $red, $green, $blue);
* Create Pen based on PenStyle
return array($w, $w, $w, $w, $b, $b, $b, $b);
return array($w, $w, $w, $w, $b, $b, $w, $b, $b);
return array($w, $b, $b, $w, $b, $b);
return array($w, $w, $w, $w, $b, $w, $b, $w, $b);
//Calls inherited constructor
parent::__construct($aowner);
if ($this->_brush->isModified())
echo "$this->_canvas.setColor(\"" . $this->_brush->Color . "\");\n";
$this->_brush->resetModified();
if ($this->_pen->isModified())
echo "$this->_canvas.setStroke(" . $this->_pen->Width . ");\n";
echo "$this->_canvas.setColor(\"" . $this->_pen->Color . "\");\n";
$this->_pen->resetModified();
echo "$this->_canvas.setFont(\"" . $this->_font->Family . "\", \"" . $this->_font->Size . "\", \"" . $this->_font->Style . "\");\n";
echo "$this->_canvas.setColor(\"" . $this->_font->Color . "\");\n";
echo "<script type=\"text/javascript\" src=\"" . VCL_HTTP_PATH . "/walterzorn/wz_jsgraphics.js\"></script>\n";
* Begins draw cycle. Establishes internal Canvas object.
* Should be followed by EndDraw to push drawing to the page canvas
echo "<script type=\"text/javascript\">\n";
* Ends draw cycle. Used to finish drawing and push it to
* Draws an arc on the image along the perimeter of the ellipse bounded
* by the specified rectangle.
function Arc($x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4)
//echo "$this->_canvas.drawArc($x1, $y1, $r * 2, $r * 2, 180, 270);\n";
* Draws the ellipse defined by a bounding rectangle on the canvas.
* @param x1, y1 - The top left point at pixel coordinates
* @param x2, y2 - The bottom right point
function Ellipse($x1, $y1, $x2, $y2)
echo "$this->_canvas.fillEllipse($x1 + 1, $y1+ 1, $x2-$x1+1, $y2-$y1+1);\n";
echo "$this->_canvas.drawEllipse($x1, $y1, $x2-$x1+1, $y2-$y1+1);\n";
* Fills the specified rectangle on the canvas using the current brush.
* The region is filled including the top and left sides of the rectangle,
* but excluding the bottom and right edges.
* @param x1, y1 - The top left point at pixel coordinates
* @param x2, y2 - The bottom right point
echo "$this->_canvas.fillRect($x1, $y1, $x2 - $x1, $y2 - $y1);\n";
* Draws a rectangle using the Brush of the canvas to draw the border.
echo "$this->_canvas.drawRect($x1, $y1, $x2-$x1+1, $y2-$y1+1);\n";
* Draws a line on the canvas using specified coordinates
* @param x1, y1 - The starting point
* @param x2, y2 - The ending point
function Line($x1, $y1, $x2, $y2)
echo "$this->_canvas.drawLine($x1, $y1, $x2, $y1);\n";
// here need to put logic to draw filled polygon
// fillPolygon(Xpoints, Ypoints);
// var Xpoints = new Array(x1,x2,x3,x4,x5);
// var Ypoints = new Array(y1,y2,y3,y4,y5);
// here need to put logic to draw polyline
// drawPolygon(Xpoints, Ypoints);
// var Xpoints = new Array(x1,x2,x3,x4,x5);
// var Ypoints = new Array(y1,y2,y3,y4,y5);
* Draws a rectangle on the canvas using Pen and fill it with Brush
echo "$this->_canvas.fillRect($x1, $y1, $x2 - $x1 + 1, $y2 - $y1 + 1);\n";
echo "$this->_canvas.drawRect($x1, $y1, $x2 - $x1 + 1, $y2 - $y1 + 1);\n";
* Draws a rectangle with rounded corners on the canvas.
function RoundRect($x1, $y1, $x2, $y2, $w, $h)
$wp = $this->_pen->Width;
echo "$this->_canvas.fillRect($x1 + $cx, $y1, $rw - $w, $rh);\n";
echo "$this->_canvas.fillRect($x1, $y1 + $cy, $rw, $rh - $h);\n";
echo "$this->_canvas.drawLine($x1 + $cx, $y1, $x2 - $cx, $y1);\n";
echo "$this->_canvas.drawLine($x1 + $cx, $y2, $x2 - $cx, $y2);\n";
echo "$this->_canvas.drawLine($x1, $y1 + $cy, $x1, $y2 - $cy);\n";
echo "$this->_canvas.drawLine($x2, $y1 + $cy, $x2, $y2 - $cy);\n";
echo "$this->_canvas.fillArc($x1, $y1, $w, $h, 90, 180);\n";
echo "$this->_canvas.fillArc($x2 - $w + $wp, $y1, $w, $h + $wp, 0, 90);\n";
echo "$this->_canvas.fillArc($x1, $y2 - $h + $wp, $w, $h, 180, 270);\n";
echo "$this->_canvas.fillArc($x2 - $w + $wp, $y2 - $h + $wp, $w, $h, 270, 360);\n";
echo "$this->_canvas.fillArc($x1 + $wp, $y1 + $wp, $w - $wp, $h - $wp, 90, 180);\n";
echo "$this->_canvas.fillArc($x2 - $w + $wp, $y1 + $wp, $w - $wp, $h - $wp, 0, 90);\n";
echo "$this->_canvas.fillArc($x1 + $wp, $y2 - $h, $w, $h, 180, 270);\n";
echo "$this->_canvas.fillArc($x2 - $w, $y2 - $h, $w, $h, 270, 360);\n";
//echo "$this->_canvas.drawArc($x2 - $r * 2, $y1, $r * 2, $r * 2, 270, 360);\n";
//echo "$this->_canvas.drawArc($x1, $y2 - $r * 2, $r * 2, $r * 2, 90, 180);\n";
//echo "$this->_canvas.drawArc($x2 - $r * 2, $y2 - $r * 2, $r * 2, $r * 2, 360, 90);\n";
* Draws the graphic specified by the @image parameter in the rectangle
* specified by the Rect coordinates.
echo "$this->_canvas.drawImage(\"$image\", $x1, $y1, $x2-$x1+1, $y2-$y1+1);\n";
* Writes a string on the canvas, starting at the point (X,Y)
echo "$this->_canvas.drawString(\"$text\", $x, $y);\n";
* Draw Bevel-like rectangle using specified colors
function BevelRect($x1, $y1, $x2, $y2, $color1, $color2)
echo "$this->_canvas.setColor(\"" . $color1 . "\");\n";
echo "$this->_canvas.drawLine($x1, $y2, $x1, $y1);\n";
echo "$this->_canvas.drawLine($x1, $y1, $x2, $y1);\n";
echo "$this->_canvas.setColor(\"" . $color2 . "\");\n";
echo "$this->_canvas.drawLine($x2, $y1, $x2, $y2);\n";
echo "$this->_canvas.drawLine($x2, $y2, $x1, $y2);\n";
* Draw the line using specified color
function BevelLine($color, $x1, $y1, $x2, $y2)
echo "$this->_canvas.setColor(\"" . $color . "\");\n";
echo "$this->_canvas.drawLine($x1, $y1, $x2, $y2);\n";
protected function readFont() { return $this->_font; }
protected function writeFont($value) { if (is_object($value)) $this->_font= $value; }
function getBrush() { return $this->_brush; }
function getFont() { return $this->readFont(); }
function setFont($value) { $this->_font->writeFont($value); }
function getPen() { return $this->_pen; }
function setPen($value) { if (is_object($value)) $this->_pen= $value; }
|