File: covbar.php

package info (click to toggle)
ggcov 0.8.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,172 kB
  • ctags: 3,299
  • sloc: cpp: 15,896; ansic: 7,066; sh: 4,851; php: 1,644; perl: 401; makefile: 218
file content (124 lines) | stat: -rw-r--r-- 2,924 bytes parent folder | download
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
<?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: covbar.php,v 1.5 2010/05/09 05:37:14 gnb Exp $
//

require_once 'ggcov/lib/cov.php';

class cov_covbar_page extends cov_page
{
    var $env_;
    var $width_;
    var $height_;
    var $values_;
    var $format_;

    function cov_covbar_page($e)
    {
	$this->env_ = $e;
    }

    function get_number($get, $name, $def)
    {
	if (array_key_exists($name, $get) && cov_valid::integer($get[$name]))
	{
	    $x = (int)$get[$name];
	    if ($x < 0)
		$x = $def;
	}
	else
	    $x = $def;
	return $x;
    }

    function parse_args($get)
    {
	$cb = $this->env_->cb_;

	$this->width_ = $this->get_number($get, 'w', 150);
	$this->height_ = $this->get_number($get, 'h', 25);

	$this->values_ = array();
	$this->values_[COV_COVERED] = $this->get_number($get, 'c', 0);
	$this->values_[COV_PARTCOVERED] = $this->get_number($get, 'pc', 0);
	$this->values_[COV_UNCOVERED] = $this->get_number($get, 'uc', 0);

	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/gif';
    }

    function title()
    {
	return null;
    }

    function render()
    {
	global $cov_rgb;
	$cb = $this->env_->cb_;

	$img = imagecreate($this->width_, $this->height_);

	$total = array_sum($this->values_);
	if ($total == 0)
	{
 	    $col = imagecolorallocate($img, 0, 0, 0);
	    imagecolortransparent($img, $col);
	}
	else
	{
	    $x = 0;
	    foreach (array(COV_COVERED, COV_PARTCOVERED, COV_UNCOVERED) as $status)
	    {
		$w = $this->width_ * $this->values_[$status] / $total;
		if (!$w)
		    continue;
		$rgb = $cov_rgb[$status];
		$col = imagecolorallocate($img, $rgb[0], $rgb[1], $rgb[2]);
		imagefilledrectangle($img, $x, 0, $x+$w, $this->height_, $col);
		$x += $w;
	    }
	}

	header("Content-type: image/$this->format_");
	switch ($this->format_)
	{
	case 'gif':
	    imagegif($img);
	    break;
	case 'png':
	    imagepng($img);
	    break;
	}

	imagedestroy($img);
    }
}

?>