1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
<?php
//
// ggcov - A GTK frontend for exploring gcov coverage data
// Copyright (c) 2005 Greg Banks <gnb@users.sourceforge.net>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// $Id: dviewport.php,v 1.2 2010-05-09 05:37:14 gnb Exp $
//
require_once 'ggcov/lib/cov.php';
class cov_dviewport_page extends cov_page
{
var $env_;
var $width_;
var $height_;
var $zoom_;
var $panx_;
var $pany_;
var $format_;
function cov_dviewport_page($e)
{
$this->env_ = $e;
}
function get_integer($get, $name, $def)
{
if (array_key_exists($name, $get) && cov_valid::integer($get[$name]))
$x = (int)$get[$name];
else
$x = $def;
return $x;
}
function get_floating($get, $name, $def)
{
if (array_key_exists($name, $get) && cov_valid::floating($get[$name]))
$x = (double)$get[$name];
else
$x = $def;
return $x;
}
function parse_args($get)
{
$cb = $this->env_->cb_;
$this->width_ = $this->get_integer($get, 'w', 64);
$this->height_ = $this->get_integer($get, 'h', 64);
$this->zoom_ = $this->get_floating($get, 'z', 1.0);
$this->panx_ = $this->get_floating($get, 'px', 0.0);
$this->pany_ = $this->get_floating($get, 'py', 0.0);
// We get passed the diagram name in 'd' but for now
// we ignore it. It will be useful later to generate
// a thumbnail to use as the viewport background.
if (function_exists('imagegif'))
$this->format_ = 'gif';
else if (function_exists('imagepng'))
$this->format_ = 'png';
else
$cb->fatal("Can't find any image format output function");
}
function content_type()
{
return "image/$this->format_";
}
function title()
{
return "Diagram Viewport"; // never seen
}
function render()
{
$cb = $this->env_->cb_;
$img = imagecreate($this->width_, $this->height_);
// allocate colours
$cwhite = imagecolorallocate($img, 0xff, 0xff, 0xff);
$cblack = imagecolorallocate($img, 0x00, 0x00, 0x00);
$cpurple = imagecolorallocate($img, 0x7d, 0x7d, 0x94);
// fill with white
imagefilledrectangle($img, 0, 0,
$this->width_-1, $this->height_-1,
$cwhite);
// draw a purple rectangle to represent the viewport
$x = ($this->width_-2) * $this->panx_ + 1;
$y = ($this->height_-2) * $this->pany_ + 1;
$w = ($this->width_-2) / $this->zoom_;
$h = ($this->height_-2) / $this->zoom_;
imagefilledrectangle($img, $x, $y, $x+$w, $y+$h, $cpurple);
// draw a black border; do this last to avoid having to clip
imagerectangle($img, 0, 0,
$this->width_-1, $this->height_-1,
$cblack);
header("Content-type: image/$this->format_");
switch ($this->format_)
{
case 'gif':
imagegif($img);
break;
case 'png':
imagepng($img);
break;
}
imagedestroy($img);
}
}
?>
|