source: trunk/client/modules/Elezioni/grafici/jpgraph_led.php@ 73

Last change on this file since 73 was 2, checked in by root, 15 years ago

importo il progetto

File size: 10.5 KB
Line 
1<?php
2//=======================================================================
3// File: JPGRAPH_LED.PHP
4// Description: Module to generate Dotted LED-like digits
5// Created: 2006-11-26
6// Ver: $Id: jpgraph_led.php 1091 2009-01-18 22:57:40Z ljp $
7//
8// Copyright 2006 (c) Aditus Consulting. All rights reserved.
9//
10// Changed: 2007-08-06 by Alexander Kurochkin (inspector@list.ru)
11// Added: Decipher 4-bit mask.
12// Added: Chars Latin > 'L', Cyrilic, other symbols and special symbols for
13// simulation some latin and cyrilic chars.
14// Added: New Color schemas.
15// Deleted: Some minor bugs (StrokeNumber first parameter may be eq empty string,
16// false or null - added check see line 294;
17// change color schema check for easy maintenance: 291;
18// change check on key exist in chars array: moved from StrokeNumber
19// function to _GetLED: 251;
20//
21//========================================================================
22
23// Samples for troubled chars: "Ô¡ Ø\r Ù\r Û| ÞÎ Ì\r >\n< W\r"
24// Ô Ø Ù Û Þ Ì Æ W
25
26//----------------------------------------------------------------------------
27// Each character is encoded line by line with the "On"-LEDs corresponding to
28// a '1' in the bianry mask of 4 bits.
29//
30// 4-bit mask:
31//
32// 0 ____
33// 1 ___x
34// 2 __x_
35// 3 __xx
36// 4 _x__
37// 5 _x_x
38// 6 _xx_
39// 7 _xxx
40// 8 x___
41// 9 x__x
42// 10 x_x_
43// 11 x_xx
44// 12 xx__
45// 13 xx_x
46// 14 xxx_
47// 15 xxxx
48//----------------------------------------------------------------------------
49
50// Constants for color schema. See definition of iColorSchema below
51define('LEDC_RED', 0);
52define('LEDC_GREEN', 1);
53define('LEDC_BLUE', 2);
54define('LEDC_YELLOW', 3);
55define('LEDC_GRAY', 4);
56define('LEDC_CHOCOLATE', 5);
57define('LEDC_PERU', 6);
58define('LEDC_GOLDENROD', 7);
59define('LEDC_KHAKI', 8);
60define('LEDC_OLIVE', 9);
61define('LEDC_LIMEGREEN', 10);
62define('LEDC_FORESTGREEN', 11);
63define('LEDC_TEAL', 12);
64define('LEDC_STEELBLUE', 13);
65define('LEDC_NAVY', 14);
66define('LEDC_INVERTGRAY', 15);
67// ! It correlate with two-dimensional array $iColorSchema
68
69//========================================================================
70// CLASS DigitalLED74
71// Description:
72// Construct a number as an image that looks like LED numbers in a
73// 7x4 digital matrix
74//========================================================================
75class DigitalLED74
76{
77 private $iLED_X = 4, $iLED_Y=7,
78
79 // fg-up, fg-down, bg
80 $iColorSchema = array(
81 LEDC_RED => array('red','darkred:0.9','red:0.3'),// 0
82 LEDC_GREEN => array('green','darkgreen','green:0.3'),// 1
83 LEDC_BLUE => array('lightblue:0.9','darkblue:0.85','darkblue:0.7'),// 2
84 LEDC_YELLOW => array('yellow','yellow:0.4','yellow:0.3'),// 3
85 LEDC_GRAY => array('gray:1.4','darkgray:0.85','darkgray:0.7'),
86 LEDC_CHOCOLATE => array('chocolate','chocolate:0.7','chocolate:0.5'),
87 LEDC_PERU => array('peru:0.95','peru:0.6','peru:0.5'),
88 LEDC_GOLDENROD => array('goldenrod','goldenrod:0.6','goldenrod:0.5'),
89 LEDC_KHAKI => array('khaki:0.7','khaki:0.4','khaki:0.3'),
90 LEDC_OLIVE => array('#808000','#808000:0.7','#808000:0.6'),
91 LEDC_LIMEGREEN => array('limegreen:0.9','limegreen:0.5','limegreen:0.4'),
92 LEDC_FORESTGREEN => array('forestgreen','forestgreen:0.7','forestgreen:0.5'),
93 LEDC_TEAL => array('teal','teal:0.7','teal:0.5'),
94 LEDC_STEELBLUE => array('steelblue','steelblue:0.65','steelblue:0.5'),
95 LEDC_NAVY => array('navy:1.3','navy:0.95','navy:0.8'),//14
96 LEDC_INVERTGRAY => array('darkgray','lightgray:1.5','white')//15
97 ),
98
99 $iLEDSpec = array(
100 0 => array(6,9,11,15,13,9,6),
101 //0 => array(6,9,9,9,9,9,6),
102 //0 => array(15,9,9,9,9,9,15),
103 1 => array(2,6,10,2,2,2,2),
104 2 => array(6,9,1,2,4,8,15),
105 3 => array(6,9,1,6,1,9,6),
106 4 => array(1,3,5,9,15,1,1),
107 5 => array(15,8,8,14,1,9,6),
108 6 => array(6,8,8,14,9,9,6),
109 7 => array(15,1,1,2,4,4,4),
110 8 => array(6,9,9,6,9,9,6),
111 9 => array(6,9,9,7,1,1,6),
112 '!' => array(4,4,4,4,4,0,4),
113 '?' => array(6,9,1,2,2,0,2),
114 '#' => array(0,9,15,9,15,9,0),
115 '@' => array(6,9,11,11,10,9,6),
116 '-' => array(0,0,0,15,0,0,0),
117 '_' => array(0,0,0,0,0,0,15),
118 '=' => array(0,0,15,0,15,0,0),
119 '+' => array(0,0,4,14,4,0,0),
120 '|' => array(4,4,4,4,4,4,4), //vertical line, used for simulate rus 'Û'
121 ',' => array(0,0,0,0,0,12,4),
122 '.' => array(0,0,0,0,0,12,12),
123 ':' => array(12,12,0,0,0,12,12),
124 ';' => array(12,12,0,0,0,12,4),
125 '[' => array(3,2,2,2,2,2,3),
126 ']' => array(12,4,4,4,4,4,12),
127 '(' => array(1,2,2,2,2,2,1),
128 ')' => array(8,4,4,4,4,4,8),
129 '{' => array(3,2,2,6,2,2,3),
130 '}' => array(12,4,4,6,4,4,12),
131 '<' => array(1,2,4,8,4,2,1),
132 '>' => array(8,4,2,1,2,4,8),
133 '*' => array(9,6,15,6,9,0,0),
134 '"' => array(10,10,0,0,0,0,0),
135 '\'' => array(4,4,0,0,0,0,0),
136 '`' => array(4,2,0,0,0,0,0),
137 '~' => array(13,11,0,0,0,0,0),
138 '^' => array(4,10,0,0,0,0,0),
139 '\\' => array(8,8,4,6,2,1,1),
140 '/' => array(1,1,2,6,4,8,8),
141 '%' => array(1,9,2,6,4,9,8),
142 '&' => array(0,4,10,4,11,10,5),
143 '$' => array(2,7,8,6,1,14,4),
144 ' ' => array(0,0,0,0,0,0,0),
145 '•' => array(0,0,6,6,0,0,0), //149
146 '°' => array(14,10,14,0,0,0,0), //176
147 '†' => array(4,4,14,4,4,4,4), //134
148 '‡' => array(4,4,14,4,14,4,4), //135
149 '±' => array(0,4,14,4,0,14,0), //177
150 '‰' => array(0,4,2,15,2,4,0), //137 show right arrow
151 '™' => array(0,2,4,15,4,2,0), //156 show left arrow
152 '¡' => array(0,0,8,8,0,0,0), //159 show small hi-stick - that need for simulate rus 'Ô'
153 "\t" => array(8,8,8,0,0,0,0), //show hi-stick - that need for simulate rus 'Ó'
154 "\r" => array(8,8,8,8,8,8,8), //vertical line - that need for simulate 'M', 'W' and rus 'Ì','Ø' ,'Ù'
155 "\n" => array(15,15,15,15,15,15,15), //fill up - that need for simulate rus 'Æ'
156 "¥" => array(10,5,10,5,10,5,10), //chess
157 "µ" => array(15,0,15,0,15,0,15), //4 horizontal lines
158// latin
159 'A' => array(6,9,9,15,9,9,9),
160 'B' => array(14,9,9,14,9,9,14),
161 'C' => array(6,9,8,8,8,9,6),
162 'D' => array(14,9,9,9,9,9,14),
163 'E' => array(15,8,8,14,8,8,15),
164 'F' => array(15,8,8,14,8,8,8),
165 'G' => array(6,9,8,8,11,9,6),
166 'H' => array(9,9,9,15,9,9,9),
167 'I' => array(14,4,4,4,4,4,14),
168 'J' => array(15,1,1,1,1,9,6),
169 'K' => array(8,9,10,12,12,10,9),
170 'L' => array(8,8,8,8,8,8,15),
171 'M' => array(8,13,10,8,8,8,8),// need to add \r
172 'N' => array(9,9,13,11,9,9,9),
173 //'O' => array(0,6,9,9,9,9,6),
174 'O' => array(6,9,9,9,9,9,6),
175 'P' => array(14,9,9,14,8,8,8),
176 'Q' => array(6,9,9,9,13,11,6),
177 'R' => array(14,9,9,14,12,10,9),
178 'S' => array(6,9,8,6,1,9,6),
179 'T' => array(14,4,4,4,4,4,4),
180 'U' => array(9,9,9,9,9,9,6),
181 'V' => array(0,0,0,10,10,10,4),
182 'W' => array(8,8,8,8,10,13,8),// need to add \r
183 'X' => array(9,9,6,6,6,9,9),
184 //'Y' => array(9,9,9,9,6,6,6),
185 'Y' => array(10,10,10,10,4,4,4),
186 'Z' => array(15,1,2,6,4,8,15),
187// russian cp1251
188 'À' => array(6,9,9,15,9,9,9),
189 'Á' => array(14,8,8,14,9,9,14),
190 'Â' => array(14,9,9,14,9,9,14),
191 'Ã' => array(15,8,8,8,8,8,8),
192 'Ä' => array(14,9,9,9,9,9,14),
193 'Å' => array(15,8,8,14,8,8,15),
194 'š' => array(6,15,8,14,8,8,15),
195 //Æ is combine: >\n<
196 'Ç' => array(6,9,1,2,1,9,6),
197 'È' => array(9,9,9,11,13,9,9),
198 'É' => array(13,9,9,11,13,9,9),
199 'Ê' => array(9,10,12,10,9,9,9),
200 'Ë' => array(7,9,9,9,9,9,9),
201 'Ì' => array(8,13,10,8,8,8,8),// need to add \r
202 'Í' => array(9,9,9,15,9,9,9),
203 'Î' => array(6,9,9,9,9,9,6),
204 'Ï' => array(15,9,9,9,9,9,9),
205 'Ð' => array(14,9,9,14,8,8,8),
206 'Ñ' => array(6,9,8,8,8,9,6),
207 'Ò' => array(14,4,4,4,4,4,4),
208 'Ó' => array(9,9,9,7,1,9,6),
209 'Ô' => array(2,7,10,10,7,2,2),// need to add ¡
210 'Õ' => array(9,9,6,6,6,9,9),
211 'Ö' => array(10,10,10,10,10,15,1),
212 '×' => array(9,9,9,7,1,1,1),
213 'Ø' => array(10,10,10,10,10,10,15),// \r
214 'Ù' => array(10,10,10,10,10,15,0),// need to add \r
215 'Ú' => array(12,4,4,6,5,5,6),
216 'Û' => array(8,8,8,14,9,9,14),// need to add |
217 'Ü' => array(8,8,8,14,9,9,14),
218 'Ý' => array(6,9,1,7,1,9,6),
219 'Þ' => array(2,2,2,3,2,2,2),// need to add O
220 'ß' => array(7,9,9,7,3,5,9)
221 ),
222
223 $iSuperSampling = 3, $iMarg = 1, $iRad = 4;
224
225 function DigitalLED74($aRadius = 2, $aMargin= 0.6) {
226 $this->iRad = $aRadius;
227 $this->iMarg = $aMargin;
228 }
229
230 function SetSupersampling($aSuperSampling = 2) {
231 $this->iSuperSampling = $aSuperSampling;
232 }
233
234 function _GetLED($aLedIdx, $aColor = 0) {
235 $width= $this->iLED_X*$this->iRad*2 + ($this->iLED_X+1)*$this->iMarg + $this->iRad ;
236 $height= $this->iLED_Y*$this->iRad*2 + ($this->iLED_Y)*$this->iMarg + $this->iRad * 2;
237
238 // Adjust radious for supersampling
239 $rad = $this->iRad * $this->iSuperSampling;
240
241 // Margin in between "Led" dots
242 $marg = $this->iMarg * $this->iSuperSampling;
243
244 $swidth = $width*$this->iSuperSampling;
245 $sheight = $height*$this->iSuperSampling;
246
247 $simg = new RotImage($swidth, $sheight, 0, DEFAULT_GFORMAT, false);
248 $simg->SetColor($this->iColorSchema[$aColor][2]);
249 $simg->FilledRectangle(0, 0, $swidth-1, $sheight-1);
250
251 if(array_key_exists($aLedIdx, $this->iLEDSpec)) {
252 $d = $this->iLEDSpec[$aLedIdx];
253 }
254 else {
255 $d = array(0,0,0,0,0,0,0);
256 }
257
258 for($r = 0; $r < 7; ++$r) {
259 $dr = $d[$r];
260 for($c = 0; $c < 4; ++$c) {
261 if( ($dr & pow(2,3-$c)) !== 0 ) {
262 $color = $this->iColorSchema[$aColor][0];
263 }
264 else {
265 $color = $this->iColorSchema[$aColor][1];
266 }
267
268 $x = 2*$rad*$c+$rad + ($c+1)*$marg + $rad ;
269 $y = 2*$rad*$r+$rad + ($r+1)*$marg + $rad ;
270
271 $simg->SetColor($color);
272 $simg->FilledCircle($x,$y,$rad);
273 }
274 }
275
276 $img = new Image($width, $height, DEFAULT_GFORMAT, false);
277 $img->Copy($simg->img, 0, 0, 0, 0, $width, $height, $swidth, $sheight);
278 $simg->Destroy();
279 unset($simg);
280 return $img;
281 }
282
283 function StrokeNumber($aValStr, $aColor = 0, $aFileName = '') {
284 if($aColor < 0 || $aColor >= sizeof($this->iColorSchema))
285 $aColor = 0;
286
287 if(($n = strlen($aValStr)) == 0) {
288 $aValStr = ' ';
289 $n = 1;
290 }
291
292 for($i = 0; $i < $n; ++$i) {
293 $d = substr($aValStr, $i, 1);
294 if( $d >= '0' && $d <= '9' ) {
295 $d = (int)$d;
296 }
297 else {
298 $d = strtoupper($d);
299 }
300 $digit_img[$i] = $this->_GetLED($d, $aColor);
301 }
302
303 $w = imagesx($digit_img[0]->img);
304 $h = imagesy($digit_img[0]->img);
305
306 $number_img = new Image($w*$n, $h, DEFAULT_GFORMAT, false);
307
308 for($i = 0; $i < $n; ++$i) {
309 $number_img->Copy($digit_img[$i]->img, $i*$w, 0, 0, 0, $w, $h, $w, $h);
310 }
311
312 if( $aFileName != '' ) {
313 $number_img->Stream($aFileName);
314 } else {
315 $number_img->Headers();
316 $number_img->Stream();
317 }
318 }
319}
320?>
Note: See TracBrowser for help on using the repository browser.