VCL
[ class tree: VCL ] [ index: VCL ] [ all elements ]

Source for file graphics.inc.php

Documentation is available at graphics.inc.php

  1. <?php
  2. /**
  3. *  This file is part of the VCL for PHP project
  4. *
  5. *  Copyright (c) 2004-2007 qadram software <support@qadram.com>
  6. *
  7. *  Checkout AUTHORS file for more information on the developers
  8. *
  9. *  This library is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU Lesser General Public
  11. *  License as published by the Free Software Foundation; either
  12. *  version 2.1 of the License, or (at your option) any later version.
  13. *
  14. *  This library is distributed in the hope that it will be useful,
  15. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. *  Lesser General Public License for more details.
  18. *
  19. *  You should have received a copy of the GNU Lesser General Public
  20. *  License along with this library; if not, write to the Free Software
  21. *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  22. *  USA
  23. *
  24. */
  25.  
  26. use_unit("classes.inc.php");
  27.  
  28. define('taNone','taNone');
  29. define('taLeft','taLeft');
  30. define('taCenter','taCenter');
  31. define('taRight','taRight');
  32. define('taJustify','taJustify');
  33.  
  34. define('fsNormal','fsNormal');
  35. define('fsItalic','fsItalic');
  36. define('fsOblique','fsOblique');
  37.  
  38. define('caCapitalize','caCapitalize');
  39. define('caUpperCase','caUpperCase');
  40. define('caLowerCase','caLowerCase');
  41. define('caNone','caNone');
  42.  
  43. define('vaNormal','vaNormal');
  44. define('vaSmallCaps','vaSmallCaps');
  45.  
  46. define('psDash''psDash');
  47. define('psDashDot''psDashDot');
  48. define('psDashDotDot''psDashDotDot');
  49. define('psDot''psDot');
  50. define('psSolid''psSolid');
  51.  
  52. define('FLOW_LAYOUT','FLOW_LAYOUT');
  53. define('XY_LAYOUT','XY_LAYOUT');
  54. define('ABS_XY_LAYOUT','ABS_XY_LAYOUT');
  55. define('GRIDBAG_LAYOUT','GRIDBAG_LAYOUT');
  56. define('ROW_LAYOUT','ROW_LAYOUT');
  57. define('COL_LAYOUT','COL_LAYOUT');
  58.  
  59.  
  60. /**
  61.  * Layout encapsulation to allow any component to hold
  62.  * controls and render them in very different ways
  63.  *
  64.  */
  65. class Layout extends Persistent
  66. {
  67.             public $_control=null;
  68.  
  69.             private $_type=ABS_XY_LAYOUT;
  70.  
  71.         /**
  72.         * Type of this layout
  73.         * @return enum 
  74.         */
  75.             function getType(return $this->_type}
  76.             function setType($value$this->_type=$value}
  77.             function defaultType(return ABS_XY_LAYOUT}
  78.  
  79.             protected $_rows=5;
  80.  
  81.         /**
  82.         * Rows for this layout
  83.         * @return integer 
  84.         */
  85.             function getRows(return $this->_rows}
  86.             function setRows($value$this->_rows=$value}
  87.             function defaultRows(return 5}
  88.  
  89.             protected $_cols=5;
  90.  
  91.         /**
  92.         * Columns for this layout
  93.         * @return integer 
  94.         */
  95.             function getCols(return $this->_cols}
  96.             function setCols($value$this->_cols=$value}
  97.             function defaultCols(return 5}
  98.  
  99.         /**
  100.         * Dump an absolute layout
  101.         * @param array $exclude Classnames of the controls you want to exclude from dumping
  102.         */
  103.             function dumpABSLayout($exclude=array())
  104.             {
  105.                 if ($this->_control!=null)
  106.                 {
  107.                         reset($this->_control->controls->items);
  108.                         while (list($k,$v)=each($this->_control->controls->items))
  109.                         {
  110.                                 if (!empty($exclude))
  111.                                 {
  112.                                         if (in_array($v->classname(),$exclude))
  113.                                         {
  114.                                                 continue;
  115.                                         }
  116.                                 }
  117.                                 $dump=false;
  118.  
  119.                                 if (($v->Visible&& (!$v->IsLayer&& (($this->_control->methodExists('getActiveLayer')) && (string)$v->Layer==(string)$this->_control->Activelayer)) $dump=true;
  120.                                 else if (($v->Visible&& (!$v->IsLayer)) $dump=true;
  121. //                                if (($v->Visible) && (!$v->IsLayer) && ((string)$v->Layer==(string)$this->_control->Activelayer))
  122.                                 if ($dump)
  123.                                 {
  124.                                         $left=$v->Left;
  125.                                         $top=$v->Top;
  126.                                         $aw=$v->Width;
  127.                                         $ah=$v->Height;
  128.  
  129.                                         $style="Z-INDEX$kLEFT".$left."px; WIDTH: ".$aw."px; POSITION: absolute; TOP: ".$top."px; HEIGHT: ".$ah."px";
  130.  
  131.                                         echo "<div id=\"".$v->Name."_outer\" style=\"$style\">\n";
  132.                                         $v->show();
  133.                                         echo "\n</div>\n";
  134.                                 }
  135.                         }
  136.                 }
  137.             }
  138.  
  139.         /**
  140.         * Dump a fixed coordinate layout using tables
  141.         * @param array $exclude Classnames of the controls you want to exclude from dumping
  142.         */
  143.             function dumpXYLayout($exclude=array())
  144.             {
  145.                         $x=array();
  146.                         $y=array();
  147.                         $pos=array();
  148.                         //Iterates through controls calling show for all of them
  149.  
  150.                         reset($this->_control->controls->items);
  151.                         while (list($k,$v)=each($this->_control->controls->items))
  152.                         {
  153.                                 $dump=false;
  154.  
  155.                                 if (($v->Visible&& (!$v->IsLayer&& (($this->_control->methodExists('getActiveLayer')) && (string)$v->Layer==(string)$this->_control->Activelayer)) $dump=true;
  156.                                 else if (($v->Visible&& (!$v->IsLayer)) $dump=true;
  157.                                 if ($dump)
  158.                                 {
  159.                                         $left=$v->Left;
  160.                                         $top=$v->Top;
  161.                                         $aw=$v->Width;
  162.                                         $ah=$v->Height;
  163.  
  164.                                         $x[]=$left;
  165.                                         $x[]=$left+$aw;
  166.                                         $y[]=$top;
  167.                                         $y[]=$top+$ah;
  168.  
  169.                                         $pos[$left][$top]=$v;
  170.                                 }
  171.                         }
  172.  
  173.                         $width=$this->_control->Width;
  174.                         $height=$this->_control->Height;
  175.  
  176.                         $x[]=$width;
  177.                         $y[]=$height;
  178.  
  179.                         sort($x);
  180.                         sort($y);
  181.  
  182.  
  183.                                 //Dumps the inner controls
  184.                                 if ($this->_control->controls->count()>=1)
  185.                                 {
  186.                                         $widths=array();
  187.                                         reset($x);
  188.                                         if ($x[0]!=0$widths[]=$x[0];
  189.                                         while (list($k,$v)=each($x))
  190.                                         {
  191.                                                 if ($k<count($x)-1)
  192.                                                 {
  193.                                                         if ($x[$k+1]-$v!=0$widths[]=$x[$k+1]-$v;
  194.                                                 }
  195.                                                 else $widths[]="";
  196.                                         }
  197.  
  198.                                         $heights=array();
  199.                                         reset($y);
  200.                                         if ($y[0]!=0$heights[]=$y[0];
  201.                                         while (list($k,$v)=each($y))
  202.                                         {
  203.                                                 if ($k<count($y)-1)
  204.                                                 {
  205.                                                         if ($y[$k+1]-$v!=0$heights[]=$y[$k+1]-$v;
  206.                                                 }
  207.                                                 else $heights[]="";
  208.                                         }
  209.  
  210.  
  211.                                         $y=0;
  212.                                         reset($heights);
  213.  
  214.                                         while (list($hk,$hv)=each($heights))
  215.                                         {
  216.                                                         if ($hv!="")
  217.                                                         {
  218.  
  219.                                                         }
  220.                                                         else continue;
  221.  
  222.  
  223.                                                 $rspan=false;
  224.  
  225.                                                 $x=0;
  226.                                                 reset($widths);
  227.  
  228.                                                 ob_start();
  229.                                                 while (list($k,$v)=each($widths))
  230.                                                 {
  231.                                                         $cs=1;
  232.                                                         $rs=1;
  233.  
  234.  
  235.                                                         if (isset($pos[$x][$y]))
  236.                                                         {
  237.                                                                 if ((!is_object($pos[$x][$y]))  && ($pos[$x][$y]==-1))
  238.                                                                 {
  239.                                                                         $x+=$v;
  240.                                                                         continue;
  241.                                                                 }
  242.                                                         }
  243.  
  244.                                                         if (isset($pos[$x][$y]))
  245.                                                         {
  246.                                                                 $control=$pos[$x][$y];
  247.                                                         }
  248.                                                         else $control=null;
  249.  
  250.                                                         $w=0;
  251.  
  252.                                                         if (is_object($control))
  253.                                                         {
  254.                                                                 $w=$control->Width;
  255.                                                                 $h=$control->Height;
  256.  
  257.                                                                 $tv=0;
  258.                                                                 $th=0;
  259.  
  260.                                                                 $also=array();
  261.  
  262.                                                                 for ($kkk=$hk;$kkk<count($heights);$kkk++)
  263.                                                                 {
  264.                                                                         if ($heights[$kkk]!='')
  265.                                                                         {
  266.                                                                                 $tv+=$heights[$kkk];
  267.                                                                                 if ($h>$tv)
  268.                                                                                 {
  269.                                                                                         $rs++;
  270.                                                                                         $pos[$x][$y+$tv]=-1;
  271.                                                                                         $also[]=$y+$tv;
  272.                                                                                 }
  273.                                                                                 else break;
  274.                                                                         }
  275.                                                                 }
  276.  
  277.                                                                 for ($ppp=$k;$ppp<count($widths);$ppp++)
  278.                                                                 {
  279.                                                                         if ($widths[$ppp]!='')
  280.                                                                         {
  281.                                                                                 $th+=$widths[$ppp];
  282.  
  283.                                                                                 if ($w>$th)
  284.                                                                                 {
  285.                                                                                         $cs++;
  286.                                                                                         $pos[$x+$th][$y]=-1;
  287.  
  288.                                                                                         reset($also);
  289.                                                                                         while(list($ak,$av)=each($also))
  290.                                                                                         {
  291.                                                                                                 $pos[$x+$th][$av]=-1;
  292.                                                                                         }
  293.                                                                                 }
  294.                                                                                 else break;
  295.                                                                         }
  296.                                                                 }
  297.                                                         }
  298.  
  299.  
  300.                                                         $width="";
  301.                                                         if ($v!="")
  302.                                                         {
  303.                                                                 $zv=round(($v*100)/$this->_control->Width,2);
  304.                                                                 $zv.="%";
  305.                                                                 $width=" width=\"$v\" ";
  306.                                                         }
  307.  
  308.                                                         if ($rs!=1)
  309.                                                         {
  310.                                                                 $rspan=true;
  311.                                                                 $rs=" rowspan=\"$rs\" ";
  312.                                                         }
  313.                                                         else $rs="";
  314.  
  315.                                                         if ($cs!=1)
  316.                                                         {
  317.                                                                 $cs=" colspan=\"$cs\" ";
  318.                                                                 $width="";
  319.                                                         }
  320.                                                         else $cs="";
  321.  
  322.                                                         $hh="";
  323.  
  324.                                                         echo "<td $width $hh $rs $cs valign=\"top\">";
  325.  
  326.                                                         if (is_object($control)) $control->show();
  327.                                                         else
  328.                                                         {
  329.  
  330.                                                                 echo "<img src=\"vcl/images/pixel_trans.gif\" width=\"1\" height=\"1\">";
  331.                                                         }
  332.  
  333.                                                         echo "</td>\n";
  334.                                                         $x+=$v;
  335.                                                 }
  336.                                                 $trow=ob_get_contents();
  337.                                                 ob_end_clean();
  338.                                                 if ($hv!="")
  339.                                                 {
  340.                                                         $zhv=round(($hv*100)/$this->_control->Height,2);
  341.                                                         $zhv.="%";
  342.                                                         echo "<tr height=\"$hv\">";
  343.                                                 }
  344.                                                 echo $trow;
  345.                                                 echo "</tr>\n";
  346.                                                 $y+=$hv;
  347.                                         }
  348.                                 }
  349.                                 else
  350.                                 {
  351.                                         echo "<tr><td>";
  352.                                         echo "<img src=\"vcl/images/pixel_trans.gif\" width=\"1\" height=\"1\">";
  353.                                         echo "</td></tr>";
  354.                                 }
  355.  
  356.                         reset($this->_control->controls->items);
  357.                         while (list($k,$v)=each($this->_control->controls->items))
  358.                         {
  359.                                 if (($v->Visible&& ($v->IsLayer))
  360.                                 {
  361.                                         $v->show();
  362.                                 }
  363.                         }
  364.             }
  365.  
  366.         /**
  367.         * Dump a flow layout, basically, no layout at all
  368.         * @param array $exclude Classnames of the controls you want to exclude from dumping
  369.         */
  370.             function dumpFlowLayout($exclude=array())
  371.             {
  372.             }
  373.  
  374.         /**
  375.         * Dump the layout contents depending on the layout type
  376.         * @param array $exclude Classnames of the controls you want to exclude from dumping
  377.         */
  378.             function dumpLayoutContents($exclude=array())
  379.             {
  380.                 switch($this->_type)
  381.                 {
  382.                         case COL_LAYOUT$this->dumpColLayout($exclude)break;
  383.                         case ROW_LAYOUT$this->dumpRowLayout($exclude)break;
  384.                         case GRIDBAG_LAYOUT$this->dumpGridBagLayout($exclude)break;
  385.                         case ABS_XY_LAYOUT$this->dumpABSLayout($exclude)break;
  386.                         case XY_LAYOUT$this->dumpXYLayout($exclude)break;
  387.                         case FLOW_LAYOUT$this->dumpFlowLayout($exclude)break;
  388.                 }
  389.             }
  390.  
  391.         /**
  392.         * Dump a table layout
  393.         * @param array $exclude Classnames of the controls you want to exclude from dumping
  394.         */
  395.             function dumpGridBagLayout($exclude=array())
  396.             {
  397.                     $this->dumpGrid($exclude$this->_cols$this->_rows"100%");
  398.             }
  399.  
  400.         /**
  401.         * Dump a row layout
  402.         * @param array $exclude Classnames of the controls you want to exclude from dumping
  403.         */
  404.             function dumpRowLayout($exclude=array())
  405.             {
  406.                     $this->dumpGrid($exclude$this->_cols1"100%");
  407.             }
  408.  
  409.         /**
  410.         * Dump an col layout
  411.         * @param array $exclude Classnames of the controls you want to exclude from dumping
  412.         */
  413.             function dumpColLayout($exclude=array())
  414.             {
  415.                     $this->dumpGrid($exclude1$this->_rows"100%");
  416.             }
  417.  
  418.         /**
  419.         * Dump a grid layout
  420.         * @param array $exclude Classnames of the controls you want to exclude from dumping
  421.         * @param integer $cols Number of columns for the grid
  422.         * @param integer $rows Number of rows for the grid
  423.         * @param string $width Width for the layout
  424.         */
  425.             function dumpGrid($exclude=array(),$cols,$rows,$width)
  426.             {
  427.                     $pwidth=$this->_control->Width;
  428.                     $pheight=$this->_control->Height;
  429.  
  430.                     $cwidth round($pwidth $cols,0);
  431.                     $cheight round($pheight $rows,0);
  432.  
  433.                     $controls=array();
  434.                         reset($this->_control->controls->items);
  435.                         while (list($k,$v)=each($this->_control->controls->items))
  436.                         {
  437.                             $col=round($v->Left $cwidth,0);
  438.                             $row=round($v->Top $cheight,0);
  439.  
  440.                             $controls[$col][$row]=$v;
  441.                         }
  442.  
  443.                     echo "<table width=\"$width\" height=\"$pheight\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
  444.                     for($y=0;$y<=$rows-1;$y++)
  445.                     {
  446.                         echo "<tr>\n";
  447.                         for($x=0;$x<=$cols-1;$x++)
  448.                         {
  449.                             if (isset($controls[$x][$y]))
  450.                             {
  451.                                 $v=$controls[$x][$y];
  452.                                 if (is_object($v))
  453.                                 {
  454.                                     $v->AdjustToLayout=true;
  455.  
  456.                                     $cspan="";
  457.                                     $rspan="";
  458.  
  459.                                     $cspan round(($v->Width $cwidth),0);
  460.                                     if ($cspan 1)
  461.                                     {
  462.                                         //for ($xx=$x+1;$xx<=$x+$cspan;$xx++)  $controls[$xx][$y]=-1;
  463.                                     }
  464.  
  465.                                     $rspan round(($v->Height $cheight),0);
  466.                                     if ($rspan 1)
  467.                                     {
  468.                                         //for ($yy=$y+1;$yy<=$y+$rspan;$yy++)  $controls[$x][$yy]=-1;
  469.                                     }
  470.  
  471.  
  472.                                     for ($xx=$x;$xx<$x+$cspan;$xx++)
  473.                                     {
  474.                                         for ($yy=$y;$yy<$y+$rspan;$yy++)
  475.                                         {
  476.                                             $controls[$xx][$yy]=-1;
  477.                                         }
  478.                                     }
  479.  
  480.  
  481.                                     if ($cspan>1$cspan=" colspan=\"$cspan\" ";
  482.                                     else $cspan="";
  483.  
  484.                                     if ($rspan>1$rspan=" rowspan=\"$rspan\" ";
  485.                                     else $rspan="";
  486.  
  487.                                     $pw=round((100*$v->Width)/$pwidth);
  488.                                     $pw=" width=\"$pw%\" ";
  489.  
  490.                                     $ph=round((100*$v->Height)/$pheight);
  491.                                     $ph=" height=\"$ph%\" ";
  492.  
  493.                                     echo "<td valign=\"top\" $pw $ph $cspan $rspan>\n";
  494.                                     $v->show();
  495.                                     echo "\n</td>\n";
  496.                                 }
  497.                             }
  498.                             else
  499.                             {
  500.                                 echo "<td>&nbsp;\n";
  501.                                 echo "</td>\n";
  502.                             }
  503.                         }
  504.                         echo "</tr>\n";
  505.                     }
  506.                     echo "</table>\n";
  507.             }
  508. }
  509.  
  510. /**
  511.  * Font encapsulation
  512.  *
  513.  */
  514. class Font extends Persistent
  515. {
  516.         protected $_family="Verdana";
  517.         protected $_size="10px";
  518.         protected $_color="";
  519.         protected $_weight="";
  520.         protected $_align="taNone";
  521.         protected $_style="";
  522.         protected $_case="";
  523.         protected $_variant="";
  524.         protected $_lineheight="";
  525.  
  526.         public $_control=null;
  527.  
  528.         private $_updatecounter 0;
  529.  
  530.         /**
  531.         * Assign Font object to another Font object.
  532.         * @param object $dest Destination, where the new font settings are assigned to.
  533.         */
  534.         function assignTo($dest)
  535.         {
  536.                 // make sure modified() is not always called while assigning new values
  537.                 $dest->startUpdate();
  538.  
  539.                 $dest->setFamily($this->getFamily());
  540.                 $dest->setSize($this->getSize());
  541.                 $dest->setColor($this->getColor());
  542.                 $dest->setAlign($this->getAlign());
  543.                 $dest->setStyle($this->getStyle());
  544.                 $dest->setCase($this->getCase());
  545.                 $dest->setLineHeight($this->getLineHeight());
  546.                 $dest->setVariant($this->getVariant());
  547.                 $dest->setWeight($this->getWeight());
  548.  
  549.                 $dest->endUpdate();
  550.         }
  551.  
  552.         /**
  553.         * Call startUpdate() when multiple properties of the Font are updated at
  554.         * the same time. Once finished updating, call endUpdate().
  555.         * It prevents the updating of the control where the Font is assigned to
  556.         * until the endUpdate() function is called.
  557.         */
  558.         function startUpdate()
  559.         {
  560.                 $this->_updatecounter++;
  561.         }
  562.  
  563.         /**
  564.         * Re-enables the notification mechanism to the control.
  565.         * Note: endUpdate() has to be called as many times as startUpdate() was
  566.         *       called on the same Font object.
  567.         */
  568.         function endUpdate()
  569.         {
  570.                 $this->_updatecounter--;
  571.                 // let's just make sure that if the endUpdate() is called too many times
  572.                 // that the $this->_updatecounter is valid and the font is updated
  573.                 if ($this->_updatecounter 0)
  574.                 {
  575.                         $this->_updatecounter 0;
  576.                 }
  577.                 // when finished updating call the modified() function to notify the control.
  578.                 if ($this->_updatecounter == 0)
  579.                 {
  580.                         $this->modified();
  581.                 }
  582.         }
  583.  
  584.         /**
  585.         * Indicates if the Font object is in update mode. If true, the control
  586.         * where the Font is assigned to will not be notified when a property changes.
  587.         * @return bool 
  588.         */
  589.         function isUpdating()
  590.         {
  591.                 return $this->_updatecounter != 0;
  592.         }
  593.  
  594.         /**
  595.          * Check if the font has been modified to set to false the parentfont
  596.          * property of the control, if any
  597.          */
  598.         function modified()
  599.         {
  600.                 if (!$this->isUpdating(&& $this->_control!=null  && ($this->_control->ControlState csLoading!= csLoading && $this->_control->Name != "")
  601.                 {
  602.                         $f=new Font();
  603.                         $fstring=$f->readFontString();
  604.  
  605.                         $tstring=$this->readFontString();
  606.  
  607.  
  608.                         if ($this->_control->ParentFont)
  609.                         {
  610.                                 $parent=$this->_control->Parent;
  611.                                 if ($parent!=null$fstring=$parent->Font->readFontString();
  612.                         }
  613.  
  614.                         // check if font changed and if the ParentFont can be reset
  615.                         if ($fstring!=$tstring && $this->_control->DoParentReset)
  616.                         {
  617.                                 $c=$this->_control;
  618.                                 $c->ParentFont 0;
  619.                         }
  620.                                              
  621.                         if ($this->_control->methodExists("updateChildrenFonts"))
  622.                         {
  623.                                 $this->_control->updateChildrenFonts();
  624.                         }
  625.                 }
  626.         }
  627.  
  628.  
  629.         /**
  630.         * Font list to be used to render this font
  631.         * @return string 
  632.         */
  633.         function getFamily(return $this->_family;   }
  634.         function setFamily($value$this->_family=$value$this->modified()}
  635.         function defaultFamily(return "Verdana";   }
  636.  
  637.         /**
  638.         * Size to be used to render this font
  639.         * @return string 
  640.         */
  641.         function getSize(return $this->_size;       }
  642.         function setSize($value$this->_size=$value$this->modified()}
  643.         function defaultSize(return "10px";       }
  644.  
  645.         /**
  646.         * Height for this font
  647.         * @return string 
  648.         */
  649.         function getLineHeight(return $this->_lineheight;       }
  650.         function setLineHeight($value$this->_lineheight=$value$this->modified()}
  651.         function defaultLineHeight(return "";       }
  652.  
  653.         /**
  654.         * Style to be used to render this font
  655.         * @return string 
  656.         */
  657.         function getStyle(return $this->_style;       }
  658.         function setStyle($value$this->_style=$value$this->modified()}
  659.         function defaultStyle(return "";       }
  660.  
  661.         /**
  662.         * Case conversion to be used to render this font
  663.         * @return string 
  664.         */
  665.         function getCase(return $this->_case;       }
  666.         function setCase($value$this->_case=$value$this->modified()}
  667.         function defaultCase(return "";       }
  668.  
  669.         /**
  670.         * Variant conversion to be used to render this font
  671.         * @return string 
  672.         */
  673.         function getVariant(return $this->_variant;       }
  674.         function setVariant($value$this->_variant=$value$this->modified()}
  675.         function defaultVariant(return "";       }
  676.  
  677.         /**
  678.         * Color for this font
  679.         * @return string 
  680.         */
  681.         function getColor(return $this->_color;       }
  682.         function setColor($value$this->_color=$value$this->modified()}
  683.         function defaultColor(return "";       }
  684.  
  685.         /**
  686.         * Specifies the alignment to be sued for this font
  687.         * @return string 
  688.         */
  689.         function getAlign(return $this->_align;       }
  690.         function setAlign($value$this->_align=$value$this->modified()}
  691.         function defaultAlign(return taNone;       }
  692.  
  693.         /**
  694.         * Specifies the weight (bold) for this font
  695.         * @return enum 
  696.         */
  697.         function getWeight(return $this->_weight;   }
  698.         function setWeight($value$this->_weight=$value$this->modified()}
  699.         function defaultWeight(return "";       }
  700.  
  701.         /**
  702.          * Returns an style string to be asigned to the tag
  703.          *
  704.          * @return string 
  705.          */
  706.         function readFontString()
  707.         {
  708.                 /*
  709.                 if ($this->_control!=null)
  710.                 {
  711.                         if ($this->_control->ParentFont)
  712.                         {
  713.                                 $parent=$this->_control->Parent;
  714.                                 if ($parent!=null) return($parent->Font->readFontString());
  715.                         }
  716.                 }
  717.                 */
  718.  
  719.                 $textalign="";
  720.                 switch($this->_align)
  721.                 {
  722.                         case taLeft$textalign="text-align: left;"break;
  723.                         case taRight$textalign="text-align: right;"break;
  724.                         case taCenter$textalign="text-align: center;"break;
  725.                         case taJustify$textalign="text-align: justify;"break;
  726.                 }
  727.  
  728.                 $fontstyle="";
  729.                 switch($this->_style)
  730.                 {
  731.                         case fsNormal$fontstyle="font-style: normal;"break;
  732.                         case fsItalic$fontstyle="font-style: italic;"break;
  733.                         case fsOblique$fontstyle="font-style: oblique;"break;
  734.                 }
  735.  
  736.                 $fontvariant="";
  737.                 switch($this->_variant)
  738.                 {
  739.                         case vaNormal$fontstyle="font-variant: normal;"break;
  740.                         case vaSmallCaps$fontstyle="font-variant: small-caps;"break;
  741.                 }
  742.  
  743.                 $texttransform="";
  744.                 switch($this->_case)
  745.                 {
  746.                         case caCapitalize$texttransform="text-transform: capitalize;"break;
  747.                         case caUpperCase$texttransform="text-transform: uppercase;"break;
  748.                         case caLowerCase$texttransform="text-transform: lowercase;"break;
  749.                         case caNone$texttransform="text-transform: none;"break;
  750.                 }
  751.  
  752.                 $color="";
  753.                 if ($this->_color!=""$color="color$this->_color;";
  754.  
  755.                 $lineheight="";
  756.                 if ($this->_lineheight!=""$lineheight="line-height$this->_lineheight;";
  757.  
  758.                 $fontweight="";
  759.                 if ($this->_weight!=""$fontweight="font-weight$this->_weight;";
  760.  
  761.  
  762.                 $result=" font-family$this->_familyfont-size$this->_size$color$fontweight$textalign$fontstyle$lineheight$fontvariant$texttransform ";
  763.                 return($result);
  764.         }
  765. }
  766.  
  767. /**
  768.  * Pen encapsulation
  769.  *
  770.  */
  771. class Pen extends Persistent
  772. {
  773.         protected $_color="#000000";
  774.         protected $_width="1";
  775. //        protected $_style=psSolid;
  776.         
  777.         protected $_modified=0;
  778.  
  779.         function assignTo($dest)
  780.         {
  781.                 $dest->Color=$this->Color;
  782.                 $dest->Width=$this->Width;
  783. //                $dest->Style=$this->Style;
  784.         }
  785.  
  786.         function modified()             $this->_modified=1}
  787.         function isModified()           return $this->_modified}
  788.         function resetModified()        $this->_modified = 0}
  789.  
  790.         //Color property
  791.         
  792.         function getColor()             return $this->_color}
  793.         function setColor($value)       $this->_color=$value$this->modified()}
  794.         function defaultColor()         return "#000000"}
  795.  
  796.         //Width property
  797.         
  798.         function getWidth()             return $this->_width}
  799.         function setWidth($value)       $this->_width=$value$this->modified()}
  800.         function defaultWidth()         return "1"}
  801.  
  802.         //Style property
  803. //        function getStyle()             { return $this->_style; }
  804. //        function setStyle($value)       { $this->_style=$value; }
  805. //        function defaultStyle()         { return psSolid; $this->modified(); }
  806.  
  807. }
  808.  
  809. /**
  810.  * Brush class
  811.  *
  812.  */
  813. class Brush extends Persistent
  814. {
  815.         protected $_color="#FFFFFF";
  816.         protected $_modified=0;
  817.  
  818.         function assignTo($dest)
  819.         {
  820.                 $dest->Color=$this->Color;
  821.         }
  822.  
  823.         function modified()             $this->_modified=1}
  824.         function isModified()           return $this->_modified}
  825.         function resetModified()        $this->_modified = 0}
  826.  
  827.         //Color property
  828.         
  829.         function getColor()             return $this->_color}
  830.         function setColor($value)       $this->_color=$value$this->modified()}
  831.         function defaultColor(return "";       }
  832. }
  833.  
  834. /**
  835.  * Create color based on HEX RGB mask
  836.  * mask can be prefixed with #
  837.  *
  838.  */
  839. function ColorFromHex($img$hexColor)
  840. {
  841.         while (strlen($hexColor6$hexColor substr($hexColor1);  };
  842.         sscanf($hexColor"%2x%2x%2x"$red$green$blue);
  843.         return ImageColorAllocate($img$red$green$blue);
  844. }
  845.  
  846. /**
  847.  * Create Pen based on PenStyle
  848.  *
  849.  */
  850. function CreatePenStyle($img$penStyle$baseColor$bgColor)
  851. {
  852.         $b  ColorFromHex($img$bgColor);
  853.         $w  ColorFromHex($img$baseColor);
  854.  
  855.         switch ($penStyle)
  856.         {
  857.                 case psDash:
  858.                         return array($w$w$w$w$b$b$b$b);
  859.                         break;
  860.                 case psDashDot:
  861.                         return array($w$w$w$w$b$b$w$b$b);
  862.                         break;
  863.                 case psDot:
  864.                         return array($w$b$b$w$b$b);
  865.                         break;
  866.                 case psDashDotDot:
  867.                         return array($w$w$w$w$b$w$b$w$b);
  868.                         break;
  869.                 default:
  870.                   //psSolid
  871.                         return array($w);
  872.                         break;
  873.         }
  874. }
  875.  
  876. /**
  877.  * Canvas class
  878.  *
  879.  */
  880. class Canvas extends Persistent
  881. {
  882.         protected $_pen=null;
  883.         protected $_brush=null;
  884.         protected $_font=null;
  885.         protected $_canvas="";
  886.         protected $_object="";
  887.         protected $_owner=null;
  888.  
  889.         function __construct($aowner=null)
  890.         {
  891.                 //Calls inherited constructor
  892.                 parent::__construct($aowner);
  893.  
  894.                 $this->_pen=new Pen();
  895.                 $this->_pen->Width=1;
  896.                 $this->_brush=new Brush();
  897.                 $this->_font=new Font();
  898.                 $this->_owner=$aowner;
  899.         }
  900.  
  901.         protected function forceBrush()
  902.         {
  903.                 if ($this->_brush->isModified())
  904.                 {
  905.                         echo "$this->_canvas.setColor(\"$this->_brush->Color "\");\n";
  906.                         $this->_brush->resetModified();
  907.                         $this->_pen->modified();
  908.                 }
  909.         }
  910.         protected function forcePen()
  911.         {
  912.                 if ($this->_pen->isModified())
  913.                 {
  914.                         echo "$this->_canvas.setStroke($this->_pen->Width ");\n";
  915.                         echo "$this->_canvas.setColor(\"$this->_pen->Color "\");\n";
  916.                         $this->_pen->resetModified();
  917.                         $this->_brush->modified();
  918.                 }
  919.         }
  920.         protected function forceFont()
  921.         {
  922.                 echo "$this->_canvas.setFont(\"$this->_font->Family "\", \"" $this->_font->Size "\", \"" $this->_font->Style "\");\n";
  923.                 echo "$this->_canvas.setColor(\"$this->_font->Color "\");\n";
  924.         }
  925.  
  926.         function InitLibrary()
  927.         {
  928.  
  929.                 if (!defined('JSCANVAS'))
  930.                 {
  931.                         echo "<script type=\"text/javascript\" src=\"" VCL_HTTP_PATH "/walterzorn/wz_jsgraphics.js\"></script>\n";
  932.                         define('JSCANVAS'1);
  933.                 }
  934.  
  935.                 if (is_object($this->_owner))
  936.                 {
  937.                         $this->SetCanvasProperties($this->_owner->Name);
  938.                 }
  939.         }
  940.         function SetCanvasProperties($Name)
  941.         {
  942.                 $this->_canvas$Name "_Canvas";
  943.                 $this->_object$Name "_outer";
  944.         }
  945.         /**
  946.          * Begins draw cycle. Establishes internal Canvas object.
  947.          * Should be followed by EndDraw to push drawing to the page canvas
  948.          */
  949.         function BeginDraw()
  950.         {
  951.                 echo "<script type=\"text/javascript\">\n";
  952.                 echo "  var $this->_canvas = new jsGraphics(\"$this->_object\");\n";
  953.                 $this->_canvas"  " $this->_canvas;
  954.         }
  955.         /**
  956.          * Ends draw cycle. Used to finish drawing and push it to
  957.          * the page canvas
  958.          */
  959.         function EndDraw()
  960.         {
  961.                 echo "$this->_canvas.paint();\n";
  962.                 echo "</script>\n";
  963.         }
  964.         /**
  965.          * Draws an arc on the image along the perimeter of the ellipse bounded
  966.          * by the specified rectangle.
  967.          */
  968.         function Arc($x1$y1$x2$y2$x3$y3$x4$y4)
  969.         {
  970.                 $this->forcePen();
  971.                 //echo "$this->_canvas.drawArc($x1, $y1, $r * 2, $r * 2, 180, 270);\n";
  972.         }
  973.         /**
  974.          * Draws the ellipse defined by a bounding rectangle on the canvas.
  975.          * @param x1, y1 - The top left point at pixel coordinates
  976.          * @param x2, y2 - The bottom right point
  977.          */
  978.         function Ellipse($x1$y1$x2$y2)
  979.         {
  980.                 $this->forceBrush();
  981.                 echo "$this->_canvas.fillEllipse($x1 + 1, $y1+ 1, $x2-$x1+1, $y2-$y1+1);\n";
  982.                 $this->forcePen();
  983.                 echo "$this->_canvas.drawEllipse($x1$y1$x2-$x1+1, $y2-$y1+1);\n";
  984.         }
  985.         /**
  986.          * Fills the specified rectangle on the canvas using the current brush.
  987.          * The region is filled including the top and left sides of the rectangle,
  988.          * but excluding the bottom and right edges.
  989.          * @param x1, y1 - The top left point at pixel coordinates
  990.          * @param x2, y2 - The bottom right point
  991.          */
  992.         function FillRect($x1$y1$x2$y2)
  993.         {
  994.                 $this->forceBrush();
  995.                 echo "$this->_canvas.fillRect($x1$y1$x2 - $x1$y2 - $y1);\n";
  996.         }
  997.         /**
  998.          * Draws a rectangle using the Brush of the canvas to draw the border.
  999.          */
  1000.         function FrameRect($x1$y1$x2$y2)
  1001.         {
  1002.                 $this->forcePen();
  1003.                 $this->forceBrush();
  1004.                 echo "$this->_canvas.drawRect($x1$y1$x2-$x1+1, $y2-$y1+1);\n";
  1005.         }
  1006.         /**
  1007.          * Draws a line on the canvas using specified coordinates
  1008.          * @param x1, y1 - The starting point
  1009.          * @param x2, y2 - The ending point
  1010.          */
  1011.         function Line($x1$y1$x2$y2)
  1012.         {
  1013.                 $this->forcePen();
  1014.                 echo "$this->_canvas.drawLine($x1$y1$x2$y1);\n";
  1015.         }
  1016.         function Polygon($points)
  1017.         {
  1018.                 $this->forceBrush();
  1019.                 // here need to put logic to draw filled polygon
  1020.                 // fillPolygon(Xpoints, Ypoints);
  1021.                 // var Xpoints = new Array(x1,x2,x3,x4,x5);
  1022.                 // var Ypoints = new Array(y1,y2,y3,y4,y5);
  1023.                 $this->Polyline($points);
  1024.         }
  1025.         function Polyline($points)
  1026.         {
  1027.                 $this->forcePen();
  1028.                 // here need to put logic to draw polyline
  1029.                 // drawPolygon(Xpoints, Ypoints);
  1030.                 // var Xpoints = new Array(x1,x2,x3,x4,x5);
  1031.                 // var Ypoints = new Array(y1,y2,y3,y4,y5);
  1032.         }
  1033.         /**
  1034.          * Draws a rectangle on the canvas using Pen and fill it with Brush
  1035.          */
  1036.         function Rectangle($x1$y1$x2$y2)
  1037.         {
  1038.                 $this->forceBrush();
  1039.                 echo "$this->_canvas.fillRect($x1$y1$x2 - $x1 + 1, $y2 - $y1 + 1);\n";
  1040.                 $this->forcePen();
  1041.                 echo "$this->_canvas.drawRect($x1$y1$x2 - $x1 + 1, $y2 - $y1 + 1);\n";
  1042.         }
  1043.         /**
  1044.          * Draws a rectangle with rounded corners on the canvas.
  1045.          */
  1046.         function RoundRect($x1$y1$x2$y2$w$h)
  1047.         {
  1048.                 $cx $w/2;
  1049.                 $cy $h/2;
  1050.                 $rw $x2 $x1 1;
  1051.                 $rh $y2 $y1 1;
  1052.                 $wp $this->_pen->Width;
  1053.                 // draw shape
  1054.                 $this->forceBrush();
  1055.                 echo "$this->_canvas.fillRect($x1 + $cx$y1$rw - $w$rh);\n";
  1056.                 echo "$this->_canvas.fillRect($x1$y1 + $cy$rw$rh - $h);\n";
  1057.                 // draw border
  1058.                 $this->forcePen();
  1059.                 echo "$this->_canvas.drawLine($x1 + $cx$y1$x2 - $cx$y1);\n";
  1060.                 echo "$this->_canvas.drawLine($x1 + $cx$y2$x2 - $cx$y2);\n";
  1061.                 echo "$this->_canvas.drawLine($x1$y1 + $cy$x1$y2 - $cy);\n";
  1062.                 echo "$this->_canvas.drawLine($x2$y1 + $cy$x2$y2 - $cy);\n";
  1063.  
  1064.                 $this->forcePen();
  1065.                 echo "$this->_canvas.fillArc($x1$y1$w$h, 90, 180);\n";
  1066.                 echo "$this->_canvas.fillArc($x2 - $w + $wp$y1$w$h + $wp, 0, 90);\n";
  1067.                 echo "$this->_canvas.fillArc($x1$y2 - $h + $wp$w$h, 180, 270);\n";
  1068.                 echo "$this->_canvas.fillArc($x2 - $w + $wp$y2 - $h + $wp$w$h, 270, 360);\n";
  1069.  
  1070.                 $this->forceBrush();
  1071.                 echo "$this->_canvas.fillArc($x1 + $wp$y1 + $wp$w - $wp$h - $wp, 90, 180);\n";
  1072.                 echo "$this->_canvas.fillArc($x2 - $w + $wp$y1 + $wp$w - $wp$h - $wp, 0, 90);\n";
  1073.                 echo "$this->_canvas.fillArc($x1 + $wp$y2 - $h$w$h, 180, 270);\n";
  1074.                 echo "$this->_canvas.fillArc($x2 - $w$y2 - $h$w$h, 270, 360);\n";
  1075.  
  1076.  
  1077.                 //echo "$this->_canvas.drawArc($x2 - $r * 2, $y1, $r * 2, $r * 2, 270, 360);\n";
  1078.                 //echo "$this->_canvas.drawArc($x1, $y2 - $r * 2, $r * 2, $r * 2, 90, 180);\n";
  1079.                 //echo "$this->_canvas.drawArc($x2 - $r * 2, $y2 - $r * 2, $r * 2, $r * 2, 360, 90);\n";
  1080.         }
  1081.         /**
  1082.          * Draws the graphic specified by the @image parameter in the rectangle
  1083.          * specified by the Rect coordinates.
  1084.          */
  1085.         function StretchDraw($x1$y1$x2$y2$image)
  1086.         {
  1087.                 echo "$this->_canvas.drawImage(\"$image\", $x1$y1$x2-$x1+1, $y2-$y1+1);\n";
  1088.         }
  1089.         /**
  1090.          * Writes a string on the canvas, starting at the point (X,Y)
  1091.          */
  1092.         function TextOut($x$y$text)
  1093.         {
  1094.                 $this->forceFont();
  1095.                 echo "$this->_canvas.drawString(\"$text\", $x$y);\n";
  1096.         }
  1097.         /**
  1098.          * Draw Bevel-like rectangle using specified colors
  1099.          */
  1100.         function BevelRect($x1$y1$x2$y2$color1$color2)
  1101.         {
  1102.                 $this->forcePen();
  1103.                 echo "$this->_canvas.setColor(\"$color1 "\");\n";
  1104.                 echo "$this->_canvas.drawLine($x1$y2$x1$y1);\n";
  1105.                 echo "$this->_canvas.drawLine($x1$y1$x2$y1);\n";
  1106.                 echo "$this->_canvas.setColor(\"$color2 "\");\n";
  1107.                 echo "$this->_canvas.drawLine($x2$y1$x2$y2);\n";
  1108.                 echo "$this->_canvas.drawLine($x2$y2$x1$y2);\n";
  1109.         }
  1110.         /**
  1111.          * Draw the line using specified color
  1112.          */
  1113.         function BevelLine($color$x1$y1$x2$y2)
  1114.         {
  1115.                 $this->forcePen();
  1116.                 echo "$this->_canvas.setColor(\"$color "\");\n";
  1117.                 echo "$this->_canvas.drawLine($x1$y1$x2$y2);\n";
  1118.         }
  1119.  
  1120.         //Font property
  1121.         
  1122.         protected function readFont()           return $this->_font}
  1123.         protected function writeFont($value)    if (is_object($value)) $this->_font=$value}
  1124.  
  1125.         // properties
  1126.         
  1127.         function getBrush()                     return $this->_brush}
  1128.         function setBrush($value)               if (is_object($value)) $this->_brush=$value}
  1129.         function getFont()                      return $this->readFont()}
  1130.         function setFont($value)                $this->_font->writeFont($value)}
  1131.         function getPen()                       return $this->_pen}
  1132.         function setPen($value)                 if (is_object($value)) $this->_pen=$value}
  1133. }
  1134.  
  1135. ?>

Documentation generated on Tue, 27 Mar 2007 13:35:04 +0200 by phpDocumentor 1.3.1