bzr branch
http://darksoft.org/webbzr/adei/trunk
34
by Suren A. Chilingaryan
Few improvements simplifying getimage service usage |
1 |
<?php
|
2 |
||
114
by Suren A. Chilingaryan
Massive rewrite of DRAW (unfinished): multiple groups and axis |
3 |
require($ADEI_ROOTDIR . "/classes/jpgraph.php"); |
4 |
||
34
by Suren A. Chilingaryan
Few improvements simplifying getimage service usage |
5 |
class DRAWText { |
6 |
var $req; |
|
7 |
var $height, $width; |
|
8 |
var $graph; |
|
9 |
||
10 |
var $tmpfile; |
|
11 |
var $ready; |
|
12 |
||
13 |
function __construct(REQUEST $req = NULL) { |
|
14 |
global $TMP_PATH; |
|
15 |
global $GRAPH_DEFAULT_HEIGHT; |
|
16 |
global $GRAPH_DEFAULT_WIDTH; |
|
17 |
||
18 |
if ($req) $this->req = $req; |
|
19 |
else $this->req = new REQUEST(); |
|
20 |
||
138
by Suren A. Chilingaryan
Reuse generated png files in low precision mode (to speedup wiki) |
21 |
$this->ready = false; |
34
by Suren A. Chilingaryan
Few improvements simplifying getimage service usage |
22 |
|
93
by Suren A. Chilingaryan
Dimension parametrs fixup in WELCOM and DRAWText |
23 |
if (isset($this->req->props['height'])) $this->height = $this->req->props['height']; |
34
by Suren A. Chilingaryan
Few improvements simplifying getimage service usage |
24 |
else $this->height = $GRAPH_DEFAULT_HEIGHT; |
93
by Suren A. Chilingaryan
Dimension parametrs fixup in WELCOM and DRAWText |
25 |
if (isset($this->req->props['width'])) $this->width = $this->req->props['width']; |
34
by Suren A. Chilingaryan
Few improvements simplifying getimage service usage |
26 |
else $this->width = $GRAPH_DEFAULT_WIDTH; |
27 |
||
28 |
$this->tmpfile = $this->GetTmpFile(); |
|
29 |
}
|
|
30 |
||
31 |
function GetTmpFile() { |
|
32 |
global $ADEI_SESSION; |
|
33 |
global $TMP_PATH; |
|
34 |
||
35 |
$dir = "clients/" . $ADEI_SESSION . "/messages/"; |
|
36 |
||
37 |
if (!is_dir($TMP_PATH . "/" . $dir)) { |
|
38 |
if (!@mkdir($TMP_PATH . "/" . $dir, 0755, true)) |
|
39 |
throw new ADEIException(translate("DRAWText class have not access to the temporary directory")); |
|
40 |
}
|
|
41 |
||
42 |
return $dir . time() . "_" . rand() . ".png"; |
|
43 |
}
|
|
44 |
||
45 |
||
46 |
function CreateMessage($header, $msg) { |
|
47 |
$this->graph = new CanvasGraph($this->width, $this->height, 'auto'); |
|
48 |
$this->graph->SetMargin(5,11,6,11); |
|
49 |
$this->graph->SetShadow(); |
|
50 |
$this->graph->SetMarginColor( "teal"); |
|
51 |
$this->graph->InitFrame(); |
|
52 |
||
53 |
$text_width = $this->width - 50; |
|
54 |
if ($text_width < 100) return; |
|
55 |
||
56 |
$text = new Text($msg, 25, 25); |
|
57 |
$text->SetFont(FF_ARIAL, FS_NORMAL, 24); |
|
58 |
||
59 |
// $text->Align('left', 'top');
|
|
60 |
// $text->ParagraphAlign('left');
|
|
61 |
// $text->SetBox( "white", "black","gray");
|
|
62 |
||
63 |
$width = $text->GetWidth($this->graph->img); |
|
64 |
||
65 |
if ($width > $text_width) { |
|
66 |
$char_width = ceil($width / strlen($msg)); |
|
67 |
$cpl = $text_width / $char_width; |
|
68 |
/*
|
|
69 |
Does not taken into the account by GetWidth function
|
|
70 |
$text->SetWordWrap($cpl);
|
|
71 |
*/
|
|
72 |
||
73 |
$wmsg = wordwrap($msg, $cpl, "\n", true); |
|
74 |
$text->Set($wmsg); |
|
75 |
||
76 |
$width = $text->GetWidth($this->graph->img); |
|
77 |
while (($width > $text_width)&&($cpl>10)) { |
|
78 |
$cpl-=$cpl/10; |
|
79 |
$wmsg = wordwrap($msg, $cpl, "\n", true); |
|
80 |
$text->Set($wmsg); |
|
81 |
$width = $text->GetWidth($this->graph->img); |
|
82 |
}
|
|
83 |
}
|
|
84 |
||
85 |
$text->Stroke( $this->graph->img); |
|
86 |
}
|
|
87 |
||
88 |
||
89 |
function Save($file = false) { |
|
90 |
global $TMP_PATH; |
|
91 |
||
92 |
if ($this->ready) { |
|
93 |
if ($file) { |
|
94 |
copy($TMP_PATH . "/" . $this->tmpfile, $file); |
|
95 |
return true; |
|
96 |
}
|
|
97 |
||
98 |
return $this->tmpfile; |
|
99 |
}
|
|
100 |
||
101 |
if ($file) { |
|
102 |
$this->graph->Stroke($file); |
|
103 |
return true; |
|
104 |
}
|
|
105 |
||
138
by Suren A. Chilingaryan
Reuse generated png files in low precision mode (to speedup wiki) |
106 |
$fp = fopen($TMP_PATH . "/" . $this->tmpfile . ".tmp", "w+"); |
107 |
if ($fp) flock($fp, LOCK_EX); |
|
34
by Suren A. Chilingaryan
Few improvements simplifying getimage service usage |
108 |
$this->graph->Stroke($TMP_PATH . "/" . $this->tmpfile); |
138
by Suren A. Chilingaryan
Reuse generated png files in low precision mode (to speedup wiki) |
109 |
if ($fp) fclose($fp); |
110 |
||
34
by Suren A. Chilingaryan
Few improvements simplifying getimage service usage |
111 |
return $this->tmpfile; |
112 |
}
|
|
113 |
||
114 |
static function Display($file = false) { |
|
115 |
global $TMP_PATH; |
|
116 |
||
117 |
if ($file) { |
|
118 |
if (preg_match("/^[A-Za-z0-9\/_]\.png$/",$str)) return false; |
|
138
by Suren A. Chilingaryan
Reuse generated png files in low precision mode (to speedup wiki) |
119 |
|
120 |
$fp = fopen($TMP_PATH . "/" . $file . ".tmp", "w+"); |
|
121 |
if ($fp) flock($fp, LOCK_SH); |
|
122 |
$res = @readfile($TMP_PATH . "/" . $file); |
|
123 |
if ($fp) fclose($fp); |
|
124 |
||
125 |
return $res; |
|
34
by Suren A. Chilingaryan
Few improvements simplifying getimage service usage |
126 |
}
|
127 |
||
128 |
return false; |
|
129 |
}
|
|
130 |
}
|
|
131 |
||
132 |
?>
|