Upgrade jpgrah to 4.3.4

This commit is contained in:
Nigel Sheldon 2021-01-03 17:10:26 +01:00
commit b5868f05f6
72 changed files with 19157 additions and 10327 deletions

View file

@ -1,18 +1,18 @@
<?php
/*=======================================================================
// File: JPGRAPH_CANVTOOLS.PHP
// Description: Some utilities for text and shape drawing on a canvas
// Created: 2002-08-23
// Ver: $Id: jpgraph_canvtools.php 781 2006-10-08 08:07:47Z ljp $
//
// Copyright (c) Aditus Consulting. All rights reserved.
//========================================================================
*/
// File: JPGRAPH_CANVTOOLS.PHP
// Description: Some utilities for text and shape drawing on a canvas
// Created: 2002-08-23
// Ver: $Id: jpgraph_canvtools.php 1857 2009-09-28 14:38:14Z ljp $
//
// Copyright (c) Asial Corporation. All rights reserved.
//========================================================================
*/
DEFINE('CORNER_TOPLEFT', 0);
DEFINE('CORNER_TOPRIGHT', 1);
DEFINE('CORNER_BOTTOMRIGHT', 2);
DEFINE('CORNER_BOTTOMLEFT', 3);
define('CORNER_TOPLEFT', 0);
define('CORNER_TOPRIGHT', 1);
define('CORNER_BOTTOMRIGHT', 2);
define('CORNER_BOTTOMLEFT', 3);
//===================================================
@ -20,7 +20,7 @@ DEFINE('CORNER_BOTTOMLEFT', 3);
// Description: Define a scale for canvas so we
// can abstract away with absolute pixels
//===================================================
class CanvasScale
{
private $g;
@ -31,7 +31,7 @@ class CanvasScale
private $iymin=0;
private $iymax=10;
public function CanvasScale($graph, $xmin=0, $xmax=10, $ymin=0, $ymax=10)
public function __construct($graph, $xmin=0, $xmax=10, $ymin=0, $ymax=10)
{
$this->g = $graph;
$this->w = $graph->img->width;
@ -41,7 +41,7 @@ class CanvasScale
$this->iymin = $ymin;
$this->iymax = $ymax;
}
public function Set($xmin=0, $xmax=10, $ymin=0, $ymax=10)
{
$this->ixmin = $xmin;
@ -50,6 +50,11 @@ class CanvasScale
$this->iymax = $ymax;
}
public function Get()
{
return array($this->ixmin,$this->ixmax,$this->iymin,$this->iymax);
}
public function Translate($x, $y)
{
$xp = round(($x-$this->ixmin)/($this->ixmax - $this->ixmin) * $this->w);
@ -80,7 +85,7 @@ class Shape
private $img;
private $scale;
public function Shape($aGraph, $scale)
public function __construct($aGraph, $scale)
{
$this->img = $aGraph->img;
$this->img->SetColor('black');
@ -99,6 +104,11 @@ class Shape
$this->img->Line($x1, $y1, $x2, $y2);
}
public function SetLineWeight($aWeight)
{
$this->img->SetLineWeight($aWeight);
}
public function Polygon($p, $aClosed=false)
{
$n=count($p);
@ -118,7 +128,7 @@ class Shape
}
$this->img->FilledPolygon($p);
}
// Draw a bezier curve with defining points in the $aPnts array
// using $aSteps steps.
@ -168,7 +178,7 @@ class Shape
list($x2, $y2) = $this->scale->Translate($x2, $y2);
$this->img->FilledRectangle($x1, $y1, $x2, $y2);
}
public function Circle($x1, $y1, $r)
{
list($x1, $y1) = $this->scale->Translate($x1, $y1);
@ -252,149 +262,149 @@ class Shape
list($xt, $yt) = $this->scale->Translate($xt, $yt);
list($w, $h) = $this->scale->Translate($w, $h);
list($iw, $ih) = $this->scale->Translate($iw, $ih);
$xr = $xt + $w - 0;
$yl = $yt + $h - 0;
switch ($aCorner) {
case 0: // Upper left
// Bottom line, left & right arc
$this->img->Line($xt+$r, $yl, $xr-$r, $yl);
$this->img->Arc($xt+$r, $yl-$r, $r*2, $r*2, 90, 180);
$this->img->Arc($xr-$r, $yl-$r, $r*2, $r*2, 0, 90);
case 0: // Upper left
// Bottom line, left & right arc
$this->img->Line($xt+$r, $yl, $xr-$r, $yl);
$this->img->Arc($xt+$r, $yl-$r, $r*2, $r*2, 90, 180);
$this->img->Arc($xr-$r, $yl-$r, $r*2, $r*2, 0, 90);
// Right line, Top right arc
$this->img->Line($xr, $yt+$r, $xr, $yl-$r);
$this->img->Arc($xr-$r, $yt+$r, $r*2, $r*2, 270, 360);
// Right line, Top right arc
$this->img->Line($xr, $yt+$r, $xr, $yl-$r);
$this->img->Arc($xr-$r, $yt+$r, $r*2, $r*2, 270, 360);
// Top line, Top left arc
$this->img->Line($xt+$iw+$r, $yt, $xr-$r, $yt);
$this->img->Arc($xt+$iw+$r, $yt+$r, $r*2, $r*2, 180, 270);
// Top line, Top left arc
$this->img->Line($xt+$iw+$r, $yt, $xr-$r, $yt);
$this->img->Arc($xt+$iw+$r, $yt+$r, $r*2, $r*2, 180, 270);
// Left line
$this->img->Line($xt, $yt+$ih+$r, $xt, $yl-$r);
// Left line
$this->img->Line($xt, $yt+$ih+$r, $xt, $yl-$r);
// Indent horizontal, Lower left arc
$this->img->Line($xt+$r, $yt+$ih, $xt+$iw-$r, $yt+$ih);
$this->img->Arc($xt+$r, $yt+$ih+$r, $r*2, $r*2, 180, 270);
// Indent horizontal, Lower left arc
$this->img->Line($xt+$r, $yt+$ih, $xt+$iw-$r, $yt+$ih);
$this->img->Arc($xt+$r, $yt+$ih+$r, $r*2, $r*2, 180, 270);
// Indent vertical, Indent arc
$this->img->Line($xt+$iw, $yt+$r, $xt+$iw, $yt+$ih-$r);
$this->img->Arc($xt+$iw-$r, $yt+$ih-$r, $r*2, $r*2, 0, 90);
// Indent vertical, Indent arc
$this->img->Line($xt+$iw, $yt+$r, $xt+$iw, $yt+$ih-$r);
$this->img->Arc($xt+$iw-$r, $yt+$ih-$r, $r*2, $r*2, 0, 90);
if ($aFillColor != '') {
$bc = $this->img->current_color_name;
$this->img->PushColor($aFillColor);
$this->img->FillToBorder($xr-$r, $yl-$r, $bc);
$this->img->PopColor();
if ($aFillColor != '') {
$bc = $this->img->current_color_name;
$this->img->PushColor($aFillColor);
$this->img->FillToBorder($xr-$r, $yl-$r, $bc);
$this->img->PopColor();
}
break;
case 1: // Upper right
// Bottom line, left & right arc
$this->img->Line($xt+$r, $yl, $xr-$r, $yl);
$this->img->Arc($xt+$r, $yl-$r, $r*2, $r*2, 90, 180);
$this->img->Arc($xr-$r, $yl-$r, $r*2, $r*2, 0, 90);
// Left line, Top left arc
$this->img->Line($xt, $yt+$r, $xt, $yl-$r);
$this->img->Arc($xt+$r, $yt+$r, $r*2, $r*2, 180, 270);
// Top line, Top right arc
$this->img->Line($xt+$r, $yt, $xr-$iw-$r, $yt);
$this->img->Arc($xr-$iw-$r, $yt+$r, $r*2, $r*2, 270, 360);
// Right line
$this->img->Line($xr, $yt+$ih+$r, $xr, $yl-$r);
// Indent horizontal, Lower right arc
$this->img->Line($xr-$iw+$r, $yt+$ih, $xr-$r, $yt+$ih);
$this->img->Arc($xr-$r, $yt+$ih+$r, $r*2, $r*2, 270, 360);
// Indent vertical, Indent arc
$this->img->Line($xr-$iw, $yt+$r, $xr-$iw, $yt+$ih-$r);
$this->img->Arc($xr-$iw+$r, $yt+$ih-$r, $r*2, $r*2, 90, 180);
if ($aFillColor != '') {
$bc = $this->img->current_color_name;
$this->img->PushColor($aFillColor);
$this->img->FillToBorder($xt+$r, $yl-$r, $bc);
$this->img->PopColor();
}
break;
case 2: // Lower right
// Top line, Top left & Top right arc
$this->img->Line($xt+$r, $yt, $xr-$r, $yt);
$this->img->Arc($xt+$r, $yt+$r, $r*2, $r*2, 180, 270);
$this->img->Arc($xr-$r, $yt+$r, $r*2, $r*2, 270, 360);
// Left line, Bottom left arc
$this->img->Line($xt, $yt+$r, $xt, $yl-$r);
$this->img->Arc($xt+$r, $yl-$r, $r*2, $r*2, 90, 180);
// Bottom line, Bottom right arc
$this->img->Line($xt+$r, $yl, $xr-$iw-$r, $yl);
$this->img->Arc($xr-$iw-$r, $yl-$r, $r*2, $r*2, 0, 90);
// Right line
$this->img->Line($xr, $yt+$r, $xr, $yl-$ih-$r);
// Indent horizontal, Lower right arc
$this->img->Line($xr-$r, $yl-$ih, $xr-$iw+$r, $yl-$ih);
$this->img->Arc($xr-$r, $yl-$ih-$r, $r*2, $r*2, 0, 90);
// Indent vertical, Indent arc
$this->img->Line($xr-$iw, $yl-$r, $xr-$iw, $yl-$ih+$r);
$this->img->Arc($xr-$iw+$r, $yl-$ih+$r, $r*2, $r*2, 180, 270);
if ($aFillColor != '') {
$bc = $this->img->current_color_name;
$this->img->PushColor($aFillColor);
$this->img->FillToBorder($xt+$r, $yt+$r, $bc);
$this->img->PopColor();
}
break;
case 3: // Lower left
// Top line, Top left & Top right arc
$this->img->Line($xt+$r, $yt, $xr-$r, $yt);
$this->img->Arc($xt+$r, $yt+$r, $r*2, $r*2, 180, 270);
$this->img->Arc($xr-$r, $yt+$r, $r*2, $r*2, 270, 360);
// Right line, Bottom right arc
$this->img->Line($xr, $yt+$r, $xr, $yl-$r);
$this->img->Arc($xr-$r, $yl-$r, $r*2, $r*2, 0, 90);
// Bottom line, Bottom left arc
$this->img->Line($xt+$iw+$r, $yl, $xr-$r, $yl);
$this->img->Arc($xt+$iw+$r, $yl-$r, $r*2, $r*2, 90, 180);
// Left line
$this->img->Line($xt, $yt+$r, $xt, $yl-$ih-$r);
// Indent horizontal, Lower left arc
$this->img->Line($xt+$r, $yl-$ih, $xt+$iw-$r, $yl-$ih);
$this->img->Arc($xt+$r, $yl-$ih-$r, $r*2, $r*2, 90, 180);
// Indent vertical, Indent arc
$this->img->Line($xt+$iw, $yl-$ih+$r, $xt+$iw, $yl-$r);
$this->img->Arc($xt+$iw-$r, $yl-$ih+$r, $r*2, $r*2, 270, 360);
if ($aFillColor != '') {
$bc = $this->img->current_color_name;
$this->img->PushColor($aFillColor);
$this->img->FillToBorder($xr-$r, $yt+$r, $bc);
$this->img->PopColor();
}
break;
}
break;
case 1: // Upper right
// Bottom line, left & right arc
$this->img->Line($xt+$r, $yl, $xr-$r, $yl);
$this->img->Arc($xt+$r, $yl-$r, $r*2, $r*2, 90, 180);
$this->img->Arc($xr-$r, $yl-$r, $r*2, $r*2, 0, 90);
// Left line, Top left arc
$this->img->Line($xt, $yt+$r, $xt, $yl-$r);
$this->img->Arc($xt+$r, $yt+$r, $r*2, $r*2, 180, 270);
// Top line, Top right arc
$this->img->Line($xt+$r, $yt, $xr-$iw-$r, $yt);
$this->img->Arc($xr-$iw-$r, $yt+$r, $r*2, $r*2, 270, 360);
// Right line
$this->img->Line($xr, $yt+$ih+$r, $xr, $yl-$r);
// Indent horizontal, Lower right arc
$this->img->Line($xr-$iw+$r, $yt+$ih, $xr-$r, $yt+$ih);
$this->img->Arc($xr-$r, $yt+$ih+$r, $r*2, $r*2, 270, 360);
// Indent vertical, Indent arc
$this->img->Line($xr-$iw, $yt+$r, $xr-$iw, $yt+$ih-$r);
$this->img->Arc($xr-$iw+$r, $yt+$ih-$r, $r*2, $r*2, 90, 180);
if ($aFillColor != '') {
$bc = $this->img->current_color_name;
$this->img->PushColor($aFillColor);
$this->img->FillToBorder($xt+$r, $yl-$r, $bc);
$this->img->PopColor();
}
break;
case 2: // Lower right
// Top line, Top left & Top right arc
$this->img->Line($xt+$r, $yt, $xr-$r, $yt);
$this->img->Arc($xt+$r, $yt+$r, $r*2, $r*2, 180, 270);
$this->img->Arc($xr-$r, $yt+$r, $r*2, $r*2, 270, 360);
// Left line, Bottom left arc
$this->img->Line($xt, $yt+$r, $xt, $yl-$r);
$this->img->Arc($xt+$r, $yl-$r, $r*2, $r*2, 90, 180);
// Bottom line, Bottom right arc
$this->img->Line($xt+$r, $yl, $xr-$iw-$r, $yl);
$this->img->Arc($xr-$iw-$r, $yl-$r, $r*2, $r*2, 0, 90);
// Right line
$this->img->Line($xr, $yt+$r, $xr, $yl-$ih-$r);
// Indent horizontal, Lower right arc
$this->img->Line($xr-$r, $yl-$ih, $xr-$iw+$r, $yl-$ih);
$this->img->Arc($xr-$r, $yl-$ih-$r, $r*2, $r*2, 0, 90);
// Indent vertical, Indent arc
$this->img->Line($xr-$iw, $yl-$r, $xr-$iw, $yl-$ih+$r);
$this->img->Arc($xr-$iw+$r, $yl-$ih+$r, $r*2, $r*2, 180, 270);
if ($aFillColor != '') {
$bc = $this->img->current_color_name;
$this->img->PushColor($aFillColor);
$this->img->FillToBorder($xt+$r, $yt+$r, $bc);
$this->img->PopColor();
}
break;
case 3: // Lower left
// Top line, Top left & Top right arc
$this->img->Line($xt+$r, $yt, $xr-$r, $yt);
$this->img->Arc($xt+$r, $yt+$r, $r*2, $r*2, 180, 270);
$this->img->Arc($xr-$r, $yt+$r, $r*2, $r*2, 270, 360);
// Right line, Bottom right arc
$this->img->Line($xr, $yt+$r, $xr, $yl-$r);
$this->img->Arc($xr-$r, $yl-$r, $r*2, $r*2, 0, 90);
// Bottom line, Bottom left arc
$this->img->Line($xt+$iw+$r, $yl, $xr-$r, $yl);
$this->img->Arc($xt+$iw+$r, $yl-$r, $r*2, $r*2, 90, 180);
// Left line
$this->img->Line($xt, $yt+$r, $xt, $yl-$ih-$r);
// Indent horizontal, Lower left arc
$this->img->Line($xt+$r, $yl-$ih, $xt+$iw-$r, $yl-$ih);
$this->img->Arc($xt+$r, $yl-$ih-$r, $r*2, $r*2, 90, 180);
// Indent vertical, Indent arc
$this->img->Line($xt+$iw, $yl-$ih+$r, $xt+$iw, $yl-$r);
$this->img->Arc($xt+$iw-$r, $yl-$ih+$r, $r*2, $r*2, 270, 360);
if ($aFillColor != '') {
$bc = $this->img->current_color_name;
$this->img->PushColor($aFillColor);
$this->img->FillToBorder($xr-$r, $yt+$r, $bc);
$this->img->PopColor();
}
break;
}
}
}
@ -420,7 +430,7 @@ class CanvasRectangleText
private $iShadowWidth=3;
private $iShadowColor='';
public function CanvasRectangleText($aTxt='', $xl=0, $yt=0, $w=0, $h=0)
public function __construct($aTxt='', $xl=0, $yt=0, $w=0, $h=0)
{
$this->iTxt = new Text($aTxt);
$this->ix = $xl;
@ -428,7 +438,7 @@ class CanvasRectangleText
$this->iw = $w;
$this->ih = $h;
}
public function SetShadow($aColor='gray', $aWidth=3)
{
$this->iShadowColor = $aColor;
@ -502,8 +512,8 @@ class CanvasRectangleText
public function Stroke($aImg, $scale)
{
// If coordinates are specifed as negative this means we should
// If coordinates are specifed as negative this means we should
// treat them as abolsute (pixels) coordinates
if ($this->ix > 0) {
$this->ix = $scale->TranslateX($this->ix) ;
@ -516,7 +526,7 @@ class CanvasRectangleText
} else {
$this->iy = -$this->iy;
}
list($this->iw, $this->ih) = $scale->Translate($this->iw, $this->ih) ;
if ($this->iw == 0) {
@ -561,7 +571,7 @@ class CanvasRectangleText
);
$aImg->PopColor();
}
$this->iTxt->Align('center', 'center');
$this->iTxt->ParagraphAlign($this->iParaAlign);
$this->iTxt->SetColor($this->iFontColor);