Ignore:
Timestamp:
Apr 14, 2019, 2:31:40 PM (5 years ago)
Author:
roby
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/modules/Elezioni/grafici/jpgraph_canvtools.php

    r265 r267  
    11<?php
    22/*=======================================================================
    3  // File:        JPGRAPH_CANVTOOLS.PHP
    4  // Description: Some utilities for text and shape drawing on a canvas
    5  // Created:     2002-08-23
    6  // Ver:         $Id: jpgraph_canvtools.php 1857 2009-09-28 14:38:14Z ljp $
    7  //
    8  // Copyright (c) Asial Corporation. All rights reserved.
    9  //========================================================================
    10  */
     3// File:        JPGRAPH_CANVTOOLS.PHP
     4// Description: Some utilities for text and shape drawing on a canvas
     5// Created:     2002-08-23
     6// Ver:         $Id: jpgraph_canvtools.php 1091 2009-01-18 22:57:40Z ljp $
     7//
     8// Copyright (c) Aditus Consulting. All rights reserved.
     9//========================================================================
     10*/
    1111
    1212define('CORNER_TOPLEFT',0);
     
    2121// can abstract away with absolute pixels
    2222//===================================================
    23 
     23 
    2424class CanvasScale {
    2525    private $g;
     
    2727    private $ixmin=0,$ixmax=10,$iymin=0,$iymax=10;
    2828
    29     function __construct($graph,$xmin=0,$xmax=10,$ymin=0,$ymax=10) {
    30         $this->g = $graph;
    31         $this->w = $graph->img->width;
    32         $this->h = $graph->img->height;
    33         $this->ixmin = $xmin;
    34         $this->ixmax = $xmax;
    35         $this->iymin = $ymin;
    36         $this->iymax = $ymax;
    37     }
    38 
     29    function CanvasScale($graph,$xmin=0,$xmax=10,$ymin=0,$ymax=10) {
     30        $this->g = $graph;
     31        $this->w = $graph->img->width;
     32        $this->h = $graph->img->height;
     33        $this->ixmin = $xmin;
     34        $this->ixmax = $xmax;
     35        $this->iymin = $ymin;
     36        $this->iymax = $ymax;
     37    }
     38   
    3939    function Set($xmin=0,$xmax=10,$ymin=0,$ymax=10) {
    40         $this->ixmin = $xmin;
    41         $this->ixmax = $xmax;
    42         $this->iymin = $ymin;
    43         $this->iymax = $ymax;
    44     }
    45 
    46     function Get() {
    47         return array($this->ixmin,$this->ixmax,$this->iymin,$this->iymax);
     40        $this->ixmin = $xmin;
     41        $this->ixmax = $xmax;
     42        $this->iymin = $ymin;
     43        $this->iymax = $ymax;
    4844    }
    4945
    5046    function Translate($x,$y) {
    51         $xp = round(($x-$this->ixmin)/($this->ixmax - $this->ixmin) * $this->w);
    52         $yp = round(($y-$this->iymin)/($this->iymax - $this->iymin) * $this->h);
    53         return array($xp,$yp);
     47        $xp = round(($x-$this->ixmin)/($this->ixmax - $this->ixmin) * $this->w);
     48        $yp = round(($y-$this->iymin)/($this->iymax - $this->iymin) * $this->h);
     49        return array($xp,$yp);
    5450    }
    5551
    5652    function TranslateX($x) {
    57         $xp = round(($x-$this->ixmin)/($this->ixmax - $this->ixmin) * $this->w);
    58         return $xp;
     53        $xp = round(($x-$this->ixmin)/($this->ixmax - $this->ixmin) * $this->w);
     54        return $xp;
    5955    }
    6056
    6157    function TranslateY($y) {
    62         $yp = round(($y-$this->iymin)/($this->iymax - $this->iymin) * $this->h);
    63         return $yp;
     58        $yp = round(($y-$this->iymin)/($this->iymax - $this->iymin) * $this->h);
     59        return $yp;
    6460    }
    6561
     
    7470    private $img,$scale;
    7571
    76     function __construct($aGraph,$scale) {
    77         $this->img = $aGraph->img;
    78         $this->img->SetColor('black');
    79         $this->scale = $scale;
     72    function Shape($aGraph,$scale) {
     73        $this->img = $aGraph->img;
     74        $this->img->SetColor('black');
     75        $this->scale = $scale;
    8076    }
    8177
    8278    function SetColor($aColor) {
    83         $this->img->SetColor($aColor);
     79        $this->img->SetColor($aColor);
    8480    }
    8581
    8682    function Line($x1,$y1,$x2,$y2) {
    87         list($x1,$y1) = $this->scale->Translate($x1,$y1);
    88         list($x2,$y2) = $this->scale->Translate($x2,$y2);
    89         $this->img->Line($x1,$y1,$x2,$y2);
    90     }
    91 
    92     function SetLineWeight($aWeight) {
    93         $this->img->SetLineWeight($aWeight);
     83        list($x1,$y1) = $this->scale->Translate($x1,$y1);
     84        list($x2,$y2) = $this->scale->Translate($x2,$y2);
     85        $this->img->Line($x1,$y1,$x2,$y2);
    9486    }
    9587
    9688    function Polygon($p,$aClosed=false) {
    97         $n=count($p);
    98         for($i=0; $i < $n; $i+=2 ) {
    99             $p[$i]   = $this->scale->TranslateX($p[$i]);
    100             $p[$i+1] = $this->scale->TranslateY($p[$i+1]);
    101         }
    102         $this->img->Polygon($p,$aClosed);
     89        $n=count($p);
     90        for($i=0; $i < $n; $i+=2 ) {
     91           $p[$i]   = $this->scale->TranslateX($p[$i]);
     92           $p[$i+1] = $this->scale->TranslateY($p[$i+1]);
     93        }
     94        $this->img->Polygon($p,$aClosed);
    10395    }
    10496
    10597    function FilledPolygon($p) {
    106         $n=count($p);
    107         for($i=0; $i < $n; $i+=2 ) {
    108             $p[$i]   = $this->scale->TranslateX($p[$i]);
    109             $p[$i+1] = $this->scale->TranslateY($p[$i+1]);
    110         }
    111         $this->img->FilledPolygon($p);
    112     }
    113 
     98        $n=count($p);
     99        for($i=0; $i < $n; $i+=2 ) {
     100           $p[$i]   = $this->scale->TranslateX($p[$i]);
     101           $p[$i+1] = $this->scale->TranslateY($p[$i+1]);
     102        }
     103        $this->img->FilledPolygon($p);
     104    }
     105   
    114106
    115107    // Draw a bezier curve with defining points in the $aPnts array
     
    120112    // 6=x3, 7=y3
    121113    function Bezier($p,$aSteps=40) {
    122         $x0 = $p[0];
    123         $y0 = $p[1];
    124         // Calculate coefficients
    125         $cx = 3*($p[2]-$p[0]);
    126         $bx = 3*($p[4]-$p[2])-$cx;
    127         $ax = $p[6]-$p[0]-$cx-$bx;
    128         $cy = 3*($p[3]-$p[1]);
    129         $by = 3*($p[5]-$p[3])-$cy;
    130         $ay = $p[7]-$p[1]-$cy-$by;
    131 
    132         // Step size
    133         $delta = 1.0/$aSteps;
    134 
    135         $x_old = $x0;
    136         $y_old = $y0;
    137         for($t=$delta; $t<=1.0; $t+=$delta) {
    138             $tt = $t*$t; $ttt=$tt*$t;
    139             $x  = $ax*$ttt + $bx*$tt + $cx*$t + $x0;
    140             $y = $ay*$ttt + $by*$tt + $cy*$t + $y0;
    141             $this->Line($x_old,$y_old,$x,$y);
    142             $x_old = $x;
    143             $y_old = $y;
    144         }
    145         $this->Line($x_old,$y_old,$p[6],$p[7]);
     114        $x0 = $p[0];
     115        $y0 = $p[1];
     116        // Calculate coefficients
     117        $cx = 3*($p[2]-$p[0]);
     118        $bx = 3*($p[4]-$p[2])-$cx;
     119        $ax = $p[6]-$p[0]-$cx-$bx;
     120        $cy = 3*($p[3]-$p[1]);
     121        $by = 3*($p[5]-$p[3])-$cy;
     122        $ay = $p[7]-$p[1]-$cy-$by;
     123
     124        // Step size
     125        $delta = 1.0/$aSteps;
     126
     127        $x_old = $x0;
     128        $y_old = $y0;
     129        for($t=$delta; $t<=1.0; $t+=$delta) {
     130            $tt = $t*$t; $ttt=$tt*$t;
     131            $x  = $ax*$ttt + $bx*$tt + $cx*$t + $x0;
     132            $y = $ay*$ttt + $by*$tt + $cy*$t + $y0;
     133            $this->Line($x_old,$y_old,$x,$y);
     134            $x_old = $x;
     135            $y_old = $y;
     136        }
     137        $this->Line($x_old,$y_old,$p[6],$p[7]);
    146138    }
    147139
    148140    function Rectangle($x1,$y1,$x2,$y2) {
    149         list($x1,$y1) = $this->scale->Translate($x1,$y1);
    150         list($x2,$y2)   = $this->scale->Translate($x2,$y2);
    151         $this->img->Rectangle($x1,$y1,$x2,$y2);
     141        list($x1,$y1) = $this->scale->Translate($x1,$y1);
     142        list($x2,$y2)   = $this->scale->Translate($x2,$y2);
     143        $this->img->Rectangle($x1,$y1,$x2,$y2);
    152144    }
    153145
    154146    function FilledRectangle($x1,$y1,$x2,$y2) {
    155         list($x1,$y1) = $this->scale->Translate($x1,$y1);
    156         list($x2,$y2)   = $this->scale->Translate($x2,$y2);
    157         $this->img->FilledRectangle($x1,$y1,$x2,$y2);
    158     }
    159 
     147        list($x1,$y1) = $this->scale->Translate($x1,$y1);
     148        list($x2,$y2)   = $this->scale->Translate($x2,$y2);
     149        $this->img->FilledRectangle($x1,$y1,$x2,$y2);
     150    }
     151   
    160152    function Circle($x1,$y1,$r) {
    161         list($x1,$y1) = $this->scale->Translate($x1,$y1);
    162         if( $r >= 0 )
    163         $r   = $this->scale->TranslateX($r);
    164         else
    165         $r = -$r;
    166         $this->img->Circle($x1,$y1,$r);
     153        list($x1,$y1) = $this->scale->Translate($x1,$y1);
     154        if( $r >= 0 )
     155            $r   = $this->scale->TranslateX($r);
     156        else
     157            $r = -$r;
     158        $this->img->Circle($x1,$y1,$r);
    167159    }
    168160
    169161    function FilledCircle($x1,$y1,$r) {
    170         list($x1,$y1) = $this->scale->Translate($x1,$y1);
    171         if( $r >= 0 )
    172         $r   = $this->scale->TranslateX($r);
    173         else
    174         $r = -$r;
    175         $this->img->FilledCircle($x1,$y1,$r);
    176     }
    177 
    178     function RoundedRectangle($x1,$y1,$x2,$y2,$r=null) {
    179         list($x1,$y1) = $this->scale->Translate($x1,$y1);
    180         list($x2,$y2)   = $this->scale->Translate($x2,$y2);
    181 
    182         if( $r == null )
    183         $r = 5;
    184         elseif( $r >= 0 )
    185         $r = $this->scale->TranslateX($r);
    186         else
    187         $r = -$r;
    188         $this->img->RoundedRectangle($x1,$y1,$x2,$y2,$r);
    189     }
    190 
    191     function FilledRoundedRectangle($x1,$y1,$x2,$y2,$r=null) {
    192         list($x1,$y1) = $this->scale->Translate($x1,$y1);
    193         list($x2,$y2)   = $this->scale->Translate($x2,$y2);
    194 
    195         if( $r == null )
    196         $r = 5;
    197         elseif( $r > 0 )
    198         $r = $this->scale->TranslateX($r);
    199         else
    200         $r = -$r;
    201         $this->img->FilledRoundedRectangle($x1,$y1,$x2,$y2,$r);
     162        list($x1,$y1) = $this->scale->Translate($x1,$y1);
     163        if( $r >= 0 )
     164            $r   = $this->scale->TranslateX($r);
     165        else
     166            $r = -$r;
     167        $this->img->FilledCircle($x1,$y1,$r);
     168    }
     169
     170    function RoundedRectangle($x1,$y1,$x2,$y2,$r=null) {   
     171        list($x1,$y1) = $this->scale->Translate($x1,$y1);
     172        list($x2,$y2)   = $this->scale->Translate($x2,$y2);
     173
     174        if( $r == null )
     175            $r = 5;
     176        elseif( $r >= 0 )
     177            $r = $this->scale->TranslateX($r);
     178        else
     179            $r = -$r;
     180        $this->img->RoundedRectangle($x1,$y1,$x2,$y2,$r);
     181    }
     182
     183    function FilledRoundedRectangle($x1,$y1,$x2,$y2,$r=null) {   
     184        list($x1,$y1) = $this->scale->Translate($x1,$y1);
     185        list($x2,$y2)   = $this->scale->Translate($x2,$y2);
     186
     187        if( $r == null )
     188            $r = 5;
     189        elseif( $r > 0 )
     190            $r = $this->scale->TranslateX($r);
     191        else
     192            $r = -$r;
     193        $this->img->FilledRoundedRectangle($x1,$y1,$x2,$y2,$r);   
    202194    }
    203195
    204196    function ShadowRectangle($x1,$y1,$x2,$y2,$fcolor=false,$shadow_width=null,$shadow_color=array(102,102,102)) {
    205         list($x1,$y1) = $this->scale->Translate($x1,$y1);
    206         list($x2,$y2) = $this->scale->Translate($x2,$y2);
    207         if( $shadow_width == null )
    208         $shadow_width=4;
    209         else
    210         $shadow_width=$this->scale->TranslateX($shadow_width);
    211         $this->img->ShadowRectangle($x1,$y1,$x2,$y2,$fcolor,$shadow_width,$shadow_color);
     197        list($x1,$y1) = $this->scale->Translate($x1,$y1);
     198        list($x2,$y2) = $this->scale->Translate($x2,$y2);
     199        if( $shadow_width == null )
     200            $shadow_width=4;
     201        else
     202            $shadow_width=$this->scale->TranslateX($shadow_width);
     203        $this->img->ShadowRectangle($x1,$y1,$x2,$y2,$fcolor,$shadow_width,$shadow_color);
    212204    }
    213205
    214206    function SetTextAlign($halign,$valign="bottom") {
    215         $this->img->SetTextAlign($halign,$valign="bottom");
     207        $this->img->SetTextAlign($halign,$valign="bottom");
    216208    }
    217209
    218210    function StrokeText($x1,$y1,$txt,$dir=0,$paragraph_align="left") {
    219         list($x1,$y1) = $this->scale->Translate($x1,$y1);
    220         $this->img->StrokeText($x1,$y1,$txt,$dir,$paragraph_align);
     211        list($x1,$y1) = $this->scale->Translate($x1,$y1);
     212        $this->img->StrokeText($x1,$y1,$txt,$dir,$paragraph_align);
    221213    }
    222214
     
    225217    // 0=Top left, 1=top right, 2=bottom right, 3=bottom left
    226218    function IndentedRectangle($xt,$yt,$w,$h,$iw=0,$ih=0,$aCorner=3,$aFillColor="",$r=4) {
    227 
    228         list($xt,$yt) = $this->scale->Translate($xt,$yt);
    229         list($w,$h)   = $this->scale->Translate($w,$h);
    230         list($iw,$ih) = $this->scale->Translate($iw,$ih);
    231 
    232         $xr = $xt + $w - 0;
    233         $yl = $yt + $h - 0;
    234 
    235         switch( $aCorner ) {
    236             case 0: // Upper left
    237                 
    238                 // Bottom line, left &  right arc
    239                 $this->img->Line($xt+$r,$yl,$xr-$r,$yl);
    240                 $this->img->Arc($xt+$r,$yl-$r,$r*2,$r*2,90,180);
    241                 $this->img->Arc($xr-$r,$yl-$r,$r*2,$r*2,0,90);
    242 
    243                 // Right line, Top right arc
    244                 $this->img->Line($xr,$yt+$r,$xr,$yl-$r);
    245                 $this->img->Arc($xr-$r,$yt+$r,$r*2,$r*2,270,360);
    246 
    247                 // Top line, Top left arc
    248                 $this->img->Line($xt+$iw+$r,$yt,$xr-$r,$yt);
    249                 $this->img->Arc($xt+$iw+$r,$yt+$r,$r*2,$r*2,180,270);
    250 
    251                 // Left line
    252                 $this->img->Line($xt,$yt+$ih+$r,$xt,$yl-$r);
    253 
    254                 // Indent horizontal, Lower left arc
    255                 $this->img->Line($xt+$r,$yt+$ih,$xt+$iw-$r,$yt+$ih);
    256                 $this->img->Arc($xt+$r,$yt+$ih+$r,$r*2,$r*2,180,270);
    257 
    258                 // Indent vertical, Indent arc
    259                 $this->img->Line($xt+$iw,$yt+$r,$xt+$iw,$yt+$ih-$r);
    260                 $this->img->Arc($xt+$iw-$r,$yt+$ih-$r,$r*2,$r*2,0,90);
    261 
    262                 if( $aFillColor != '' ) {
    263                     $bc = $this->img->current_color_name;
    264                     $this->img->PushColor($aFillColor);
    265                     $this->img->FillToBorder($xr-$r,$yl-$r,$bc);
    266                     $this->img->PopColor();
    267                 }
    268 
    269                 break;
    270 
    271             case 1: // Upper right
    272 
    273                 // Bottom line, left &  right arc
    274                 $this->img->Line($xt+$r,$yl,$xr-$r,$yl);
    275                 $this->img->Arc($xt+$r,$yl-$r,$r*2,$r*2,90,180);
    276                 $this->img->Arc($xr-$r,$yl-$r,$r*2,$r*2,0,90);
    277 
    278                 // Left line, Top left arc
    279                 $this->img->Line($xt,$yt+$r,$xt,$yl-$r);
    280                 $this->img->Arc($xt+$r,$yt+$r,$r*2,$r*2,180,270);
    281 
    282                 // Top line, Top right arc
    283                 $this->img->Line($xt+$r,$yt,$xr-$iw-$r,$yt);
    284                 $this->img->Arc($xr-$iw-$r,$yt+$r,$r*2,$r*2,270,360);
    285 
    286                 // Right line
    287                 $this->img->Line($xr,$yt+$ih+$r,$xr,$yl-$r);
    288 
    289                 // Indent horizontal, Lower right arc
    290                 $this->img->Line($xr-$iw+$r,$yt+$ih,$xr-$r,$yt+$ih);
    291                 $this->img->Arc($xr-$r,$yt+$ih+$r,$r*2,$r*2,270,360);
    292 
    293                 // Indent vertical, Indent arc
    294                 $this->img->Line($xr-$iw,$yt+$r,$xr-$iw,$yt+$ih-$r);
    295                 $this->img->Arc($xr-$iw+$r,$yt+$ih-$r,$r*2,$r*2,90,180);
    296 
    297                 if( $aFillColor != '' ) {
    298                     $bc = $this->img->current_color_name;
    299                     $this->img->PushColor($aFillColor);
    300                     $this->img->FillToBorder($xt+$r,$yl-$r,$bc);
    301                     $this->img->PopColor();
    302                 }
    303 
    304                 break;
    305 
    306             case 2: // Lower right
    307                 // Top line, Top left & Top right arc
    308                 $this->img->Line($xt+$r,$yt,$xr-$r,$yt);
    309                 $this->img->Arc($xt+$r,$yt+$r,$r*2,$r*2,180,270);
    310                 $this->img->Arc($xr-$r,$yt+$r,$r*2,$r*2,270,360);
    311 
    312                 // Left line, Bottom left arc
    313                 $this->img->Line($xt,$yt+$r,$xt,$yl-$r);
    314                 $this->img->Arc($xt+$r,$yl-$r,$r*2,$r*2,90,180);
    315 
    316                 // Bottom line, Bottom right arc
    317                 $this->img->Line($xt+$r,$yl,$xr-$iw-$r,$yl);
    318                 $this->img->Arc($xr-$iw-$r,$yl-$r,$r*2,$r*2,0,90);
    319 
    320                 // Right line
    321                 $this->img->Line($xr,$yt+$r,$xr,$yl-$ih-$r);
    322                 
    323                 // Indent horizontal, Lower right arc
    324                 $this->img->Line($xr-$r,$yl-$ih,$xr-$iw+$r,$yl-$ih);
    325                 $this->img->Arc($xr-$r,$yl-$ih-$r,$r*2,$r*2,0,90);
    326 
    327                 // Indent vertical, Indent arc
    328                 $this->img->Line($xr-$iw,$yl-$r,$xr-$iw,$yl-$ih+$r);
    329                 $this->img->Arc($xr-$iw+$r,$yl-$ih+$r,$r*2,$r*2,180,270);
    330 
    331                 if( $aFillColor != '' ) {
    332                     $bc = $this->img->current_color_name;
    333                     $this->img->PushColor($aFillColor);
    334                     $this->img->FillToBorder($xt+$r,$yt+$r,$bc);
    335                     $this->img->PopColor();
    336                 }
    337 
    338                 break;
    339 
    340             case 3: // Lower left
    341                 // Top line, Top left & Top right arc
    342                 $this->img->Line($xt+$r,$yt,$xr-$r,$yt);
    343                 $this->img->Arc($xt+$r,$yt+$r,$r*2,$r*2,180,270);
    344                 $this->img->Arc($xr-$r,$yt+$r,$r*2,$r*2,270,360);
    345 
    346                 // Right line, Bottom right arc
    347                 $this->img->Line($xr,$yt+$r,$xr,$yl-$r);
    348                 $this->img->Arc($xr-$r,$yl-$r,$r*2,$r*2,0,90);
    349 
    350                 // Bottom line, Bottom left arc
    351                 $this->img->Line($xt+$iw+$r,$yl,$xr-$r,$yl);
    352                 $this->img->Arc($xt+$iw+$r,$yl-$r,$r*2,$r*2,90,180);
    353 
    354                 // Left line
    355                 $this->img->Line($xt,$yt+$r,$xt,$yl-$ih-$r);
    356                 
    357                 // Indent horizontal, Lower left arc
    358                 $this->img->Line($xt+$r,$yl-$ih,$xt+$iw-$r,$yl-$ih);
    359                 $this->img->Arc($xt+$r,$yl-$ih-$r,$r*2,$r*2,90,180);
    360 
    361                 // Indent vertical, Indent arc
    362                 $this->img->Line($xt+$iw,$yl-$ih+$r,$xt+$iw,$yl-$r);
    363                 $this->img->Arc($xt+$iw-$r,$yl-$ih+$r,$r*2,$r*2,270,360);
    364 
    365                 if( $aFillColor != '' ) {
    366                     $bc = $this->img->current_color_name;
    367                     $this->img->PushColor($aFillColor);
    368                     $this->img->FillToBorder($xr-$r,$yt+$r,$bc);
    369                     $this->img->PopColor();
    370                 }
    371 
    372                 break;
    373         }
     219   
     220        list($xt,$yt) = $this->scale->Translate($xt,$yt);
     221        list($w,$h)   = $this->scale->Translate($w,$h);
     222        list($iw,$ih) = $this->scale->Translate($iw,$ih);
     223       
     224        $xr = $xt + $w - 0;
     225        $yl = $yt + $h - 0;
     226
     227        switch( $aCorner ) {
     228            case 0: // Upper left
     229           
     230                // Bottom line, left &  right arc
     231                $this->img->Line($xt+$r,$yl,$xr-$r,$yl);
     232                $this->img->Arc($xt+$r,$yl-$r,$r*2,$r*2,90,180);
     233                $this->img->Arc($xr-$r,$yl-$r,$r*2,$r*2,0,90);
     234
     235                // Right line, Top right arc
     236                $this->img->Line($xr,$yt+$r,$xr,$yl-$r);
     237                $this->img->Arc($xr-$r,$yt+$r,$r*2,$r*2,270,360);
     238
     239                // Top line, Top left arc
     240                $this->img->Line($xt+$iw+$r,$yt,$xr-$r,$yt);
     241                $this->img->Arc($xt+$iw+$r,$yt+$r,$r*2,$r*2,180,270);
     242
     243                // Left line
     244                $this->img->Line($xt,$yt+$ih+$r,$xt,$yl-$r);
     245
     246                // Indent horizontal, Lower left arc
     247                $this->img->Line($xt+$r,$yt+$ih,$xt+$iw-$r,$yt+$ih);
     248                $this->img->Arc($xt+$r,$yt+$ih+$r,$r*2,$r*2,180,270);
     249
     250                // Indent vertical, Indent arc
     251                $this->img->Line($xt+$iw,$yt+$r,$xt+$iw,$yt+$ih-$r);
     252                $this->img->Arc($xt+$iw-$r,$yt+$ih-$r,$r*2,$r*2,0,90);
     253
     254                if( $aFillColor != '' ) {
     255                    $bc = $this->img->current_color_name;
     256                    $this->img->PushColor($aFillColor);
     257                    $this->img->FillToBorder($xr-$r,$yl-$r,$bc);
     258                    $this->img->PopColor();
     259                }
     260
     261                break;
     262
     263            case 1: // Upper right
     264
     265                // Bottom line, left &  right arc
     266                $this->img->Line($xt+$r,$yl,$xr-$r,$yl);
     267                $this->img->Arc($xt+$r,$yl-$r,$r*2,$r*2,90,180);
     268                $this->img->Arc($xr-$r,$yl-$r,$r*2,$r*2,0,90);
     269
     270                // Left line, Top left arc
     271                $this->img->Line($xt,$yt+$r,$xt,$yl-$r);
     272                $this->img->Arc($xt+$r,$yt+$r,$r*2,$r*2,180,270);
     273
     274                // Top line, Top right arc
     275                $this->img->Line($xt+$r,$yt,$xr-$iw-$r,$yt);
     276                $this->img->Arc($xr-$iw-$r,$yt+$r,$r*2,$r*2,270,360);
     277
     278                // Right line
     279                $this->img->Line($xr,$yt+$ih+$r,$xr,$yl-$r);
     280
     281                // Indent horizontal, Lower right arc
     282                $this->img->Line($xr-$iw+$r,$yt+$ih,$xr-$r,$yt+$ih);
     283                $this->img->Arc($xr-$r,$yt+$ih+$r,$r*2,$r*2,270,360);
     284
     285                // Indent vertical, Indent arc
     286                $this->img->Line($xr-$iw,$yt+$r,$xr-$iw,$yt+$ih-$r);
     287                $this->img->Arc($xr-$iw+$r,$yt+$ih-$r,$r*2,$r*2,90,180);
     288
     289                if( $aFillColor != '' ) {
     290                    $bc = $this->img->current_color_name;
     291                    $this->img->PushColor($aFillColor);
     292                    $this->img->FillToBorder($xt+$r,$yl-$r,$bc);
     293                    $this->img->PopColor();
     294                }
     295
     296                break;
     297
     298            case 2: // Lower right
     299                // Top line, Top left & Top right arc
     300                $this->img->Line($xt+$r,$yt,$xr-$r,$yt);
     301                $this->img->Arc($xt+$r,$yt+$r,$r*2,$r*2,180,270);
     302                $this->img->Arc($xr-$r,$yt+$r,$r*2,$r*2,270,360);
     303
     304                // Left line, Bottom left arc
     305                $this->img->Line($xt,$yt+$r,$xt,$yl-$r);
     306                $this->img->Arc($xt+$r,$yl-$r,$r*2,$r*2,90,180);
     307
     308                // Bottom line, Bottom right arc
     309                $this->img->Line($xt+$r,$yl,$xr-$iw-$r,$yl);
     310                $this->img->Arc($xr-$iw-$r,$yl-$r,$r*2,$r*2,0,90);
     311
     312                // Right line
     313                $this->img->Line($xr,$yt+$r,$xr,$yl-$ih-$r);
     314           
     315                // Indent horizontal, Lower right arc
     316                $this->img->Line($xr-$r,$yl-$ih,$xr-$iw+$r,$yl-$ih);
     317                $this->img->Arc($xr-$r,$yl-$ih-$r,$r*2,$r*2,0,90);
     318
     319                // Indent vertical, Indent arc
     320                $this->img->Line($xr-$iw,$yl-$r,$xr-$iw,$yl-$ih+$r);
     321                $this->img->Arc($xr-$iw+$r,$yl-$ih+$r,$r*2,$r*2,180,270);
     322
     323                if( $aFillColor != '' ) {
     324                    $bc = $this->img->current_color_name;
     325                    $this->img->PushColor($aFillColor);
     326                    $this->img->FillToBorder($xt+$r,$yt+$r,$bc);
     327                    $this->img->PopColor();
     328                }
     329
     330                break;
     331
     332            case 3: // Lower left
     333                // Top line, Top left & Top right arc
     334                $this->img->Line($xt+$r,$yt,$xr-$r,$yt);
     335                $this->img->Arc($xt+$r,$yt+$r,$r*2,$r*2,180,270);
     336                $this->img->Arc($xr-$r,$yt+$r,$r*2,$r*2,270,360);
     337
     338                // Right line, Bottom right arc
     339                $this->img->Line($xr,$yt+$r,$xr,$yl-$r);
     340                $this->img->Arc($xr-$r,$yl-$r,$r*2,$r*2,0,90);
     341
     342                // Bottom line, Bottom left arc
     343                $this->img->Line($xt+$iw+$r,$yl,$xr-$r,$yl);
     344                $this->img->Arc($xt+$iw+$r,$yl-$r,$r*2,$r*2,90,180);
     345
     346                // Left line
     347                $this->img->Line($xt,$yt+$r,$xt,$yl-$ih-$r);
     348           
     349                // Indent horizontal, Lower left arc
     350                $this->img->Line($xt+$r,$yl-$ih,$xt+$iw-$r,$yl-$ih);
     351                $this->img->Arc($xt+$r,$yl-$ih-$r,$r*2,$r*2,90,180);
     352
     353                // Indent vertical, Indent arc
     354                $this->img->Line($xt+$iw,$yl-$ih+$r,$xt+$iw,$yl-$r);
     355                $this->img->Arc($xt+$iw-$r,$yl-$ih+$r,$r*2,$r*2,270,360);
     356
     357                if( $aFillColor != '' ) {
     358                    $bc = $this->img->current_color_name;
     359                    $this->img->PushColor($aFillColor);
     360                    $this->img->FillToBorder($xr-$r,$yt+$r,$bc);
     361                    $this->img->PopColor();
     362                }
     363
     364                break;
     365        }
    374366    }
    375367}
     
    378370//===================================================
    379371// CLASS RectangleText
    380 // Description: Draws a text paragraph inside a
     372// Description: Draws a text paragraph inside a 
    381373// rounded, possible filled, rectangle.
    382374//===================================================
     
    388380    private $iShadowWidth=3,$iShadowColor='';
    389381
    390     function __construct($aTxt='',$xl=0,$yt=0,$w=0,$h=0) {
    391         $this->iTxt = new Text($aTxt);
    392         $this->ix = $xl;
    393         $this->iy = $yt;
    394         $this->iw = $w;
    395         $this->ih = $h;
    396     }
    397 
     382    function CanvasRectangleText($aTxt='',$xl=0,$yt=0,$w=0,$h=0) {
     383        $this->iTxt = new Text($aTxt);
     384        $this->ix = $xl;
     385        $this->iy = $yt;
     386        $this->iw = $w;
     387        $this->ih = $h;
     388    }
     389 
    398390    function SetShadow($aColor='gray',$aWidth=3) {
    399         $this->iShadowColor = $aColor;
    400         $this->iShadowWidth = $aWidth;
     391        $this->iShadowColor = $aColor;
     392        $this->iShadowWidth = $aWidth;
    401393    }
    402394
    403395    function SetFont($FontFam,$aFontStyle,$aFontSize=12) {
    404         $this->iTxt->SetFont($FontFam,$aFontStyle,$aFontSize);
     396        $this->iTxt->SetFont($FontFam,$aFontStyle,$aFontSize);
    405397    }
    406398
    407399    function SetTxt($aTxt) {
    408         $this->iTxt->Set($aTxt);
     400        $this->iTxt->Set($aTxt);
    409401    }
    410402
    411403    function ParagraphAlign($aParaAlign) {
    412         $this->iParaAlign = $aParaAlign;
     404        $this->iParaAlign = $aParaAlign;
    413405    }
    414406
    415407    function SetFillColor($aFillColor) {
    416         $this->iFillColor = $aFillColor;
     408        $this->iFillColor = $aFillColor;
    417409    }
    418410
    419411    function SetAutoMargin($aMargin) {
    420         $this->iAutoBoxMargin=$aMargin;
     412        $this->iAutoBoxMargin=$aMargin;
    421413    }
    422414
    423415    function SetColor($aColor) {
    424         $this->iColor = $aColor;
     416        $this->iColor = $aColor;
    425417    }
    426418
    427419    function SetFontColor($aColor) {
    428         $this->iFontColor = $aColor;
     420        $this->iFontColor = $aColor;
    429421    }
    430422
    431423    function SetPos($xl=0,$yt=0,$w=0,$h=0) {
    432         $this->ix = $xl;
    433         $this->iy = $yt;
    434         $this->iw = $w;
    435         $this->ih = $h;
     424        $this->ix = $xl;
     425        $this->iy = $yt;
     426        $this->iw = $w;
     427        $this->ih = $h;
    436428    }
    437429
    438430    function Pos($xl=0,$yt=0,$w=0,$h=0) {
    439         $this->ix = $xl;
    440         $this->iy = $yt;
    441         $this->iw = $w;
    442         $this->ih = $h;
     431        $this->ix = $xl;
     432        $this->iy = $yt;
     433        $this->iw = $w;
     434        $this->ih = $h;
    443435    }
    444436
    445437    function Set($aTxt,$xl,$yt,$w=0,$h=0) {
    446         $this->iTxt->Set($aTxt);
    447         $this->ix = $xl;
    448         $this->iy = $yt;
    449         $this->iw = $w;
    450         $this->ih = $h;
     438        $this->iTxt->Set($aTxt);
     439        $this->ix = $xl;
     440        $this->iy = $yt;
     441        $this->iw = $w;
     442        $this->ih = $h;
    451443    }
    452444
    453445    function SetCornerRadius($aRad=5) {
    454         $this->ir = $aRad;
     446        $this->ir = $aRad;
    455447    }
    456448
    457449    function Stroke($aImg,$scale) {
    458 
    459         // If coordinates are specifed as negative this means we should
    460         // treat them as abolsute (pixels) coordinates
    461         if( $this->ix > 0 ) {
    462             $this->ix = $scale->TranslateX($this->ix) ;
    463         }
    464         else {
    465             $this->ix = -$this->ix;
    466         }
    467 
    468         if( $this->iy > 0 ) {
    469             $this->iy = $scale->TranslateY($this->iy) ;
    470         }
    471         else {
    472             $this->iy = -$this->iy;
    473         }
    474         
    475         list($this->iw,$this->ih) = $scale->Translate($this->iw,$this->ih) ;
    476 
    477         if( $this->iw == 0 )
    478         $this->iw = round($this->iTxt->GetWidth($aImg) + $this->iAutoBoxMargin);
    479         if( $this->ih == 0 ) {
    480             $this->ih = round($this->iTxt->GetTextHeight($aImg) + $this->iAutoBoxMargin);
    481         }
    482 
    483         if( $this->iShadowColor != '' ) {
    484             $aImg->PushColor($this->iShadowColor);
    485             $aImg->FilledRoundedRectangle($this->ix+$this->iShadowWidth,
    486             $this->iy+$this->iShadowWidth,
    487             $this->ix+$this->iw-1+$this->iShadowWidth,
    488             $this->iy+$this->ih-1+$this->iShadowWidth,
    489             $this->ir);
    490             $aImg->PopColor();
    491         }
    492 
    493         if( $this->iFillColor != '' ) {
    494             $aImg->PushColor($this->iFillColor);
    495             $aImg->FilledRoundedRectangle($this->ix,$this->iy,
    496             $this->ix+$this->iw-1,
    497             $this->iy+$this->ih-1,
    498             $this->ir);
    499             $aImg->PopColor();
    500         }
    501 
    502         if( $this->iColor != '' ) {
    503             $aImg->PushColor($this->iColor);
    504             $aImg->RoundedRectangle($this->ix,$this->iy,
    505             $this->ix+$this->iw-1,
    506             $this->iy+$this->ih-1,
    507             $this->ir);
    508             $aImg->PopColor();
    509         }
    510 
    511         $this->iTxt->Align('center','center');
    512         $this->iTxt->ParagraphAlign($this->iParaAlign);
    513         $this->iTxt->SetColor($this->iFontColor);
    514         $this->iTxt->Stroke($aImg, $this->ix+$this->iw/2, $this->iy+$this->ih/2);
    515 
    516         return array($this->iw, $this->ih);
     450       
     451        // If coordinates are specifed as negative this means we should
     452        // treat them as abolsute (pixels) coordinates
     453        if( $this->ix > 0 ) {
     454            $this->ix = $scale->TranslateX($this->ix) ;
     455        }
     456        else {
     457            $this->ix = -$this->ix;
     458        }
     459
     460        if( $this->iy > 0 ) {
     461            $this->iy = $scale->TranslateY($this->iy) ;
     462        }
     463        else {
     464            $this->iy = -$this->iy;
     465        }
     466           
     467        list($this->iw,$this->ih) = $scale->Translate($this->iw,$this->ih) ;
     468
     469        if( $this->iw == 0 )
     470            $this->iw = round($this->iTxt->GetWidth($aImg) + $this->iAutoBoxMargin);
     471        if( $this->ih == 0 ) {
     472            $this->ih = round($this->iTxt->GetTextHeight($aImg) + $this->iAutoBoxMargin);
     473        }
     474
     475        if( $this->iShadowColor != '' ) {
     476            $aImg->PushColor($this->iShadowColor);
     477            $aImg->FilledRoundedRectangle($this->ix+$this->iShadowWidth,
     478                                          $this->iy+$this->iShadowWidth,
     479                                          $this->ix+$this->iw-1+$this->iShadowWidth,
     480                                          $this->iy+$this->ih-1+$this->iShadowWidth,
     481                                          $this->ir);
     482            $aImg->PopColor();     
     483        }
     484
     485        if( $this->iFillColor != '' ) {
     486            $aImg->PushColor($this->iFillColor);
     487            $aImg->FilledRoundedRectangle($this->ix,$this->iy,
     488                                          $this->ix+$this->iw-1,
     489                                          $this->iy+$this->ih-1,
     490                                          $this->ir);
     491            $aImg->PopColor();
     492        }
     493
     494        if( $this->iColor != '' ) {
     495            $aImg->PushColor($this->iColor);
     496            $aImg->RoundedRectangle($this->ix,$this->iy,
     497                                    $this->ix+$this->iw-1,
     498                                    $this->iy+$this->ih-1,
     499                                    $this->ir);
     500            $aImg->PopColor();
     501        }
     502       
     503        $this->iTxt->Align('center','center');
     504        $this->iTxt->ParagraphAlign($this->iParaAlign);
     505        $this->iTxt->SetColor($this->iFontColor);
     506        $this->iTxt->Stroke($aImg, $this->ix+$this->iw/2, $this->iy+$this->ih/2);
     507
     508        return array($this->iw, $this->ih);
    517509
    518510    }
Note: See TracChangeset for help on using the changeset viewer.