Changeset 265 for trunk/client/modules/Elezioni/grafici/jpgraph_led.php
- Timestamp:
- Apr 13, 2019, 8:05:15 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/modules/Elezioni/grafici/jpgraph_led.php
r2 r265 1 1 <?php 2 2 //======================================================================= 3 // File: 4 // Description: 5 // Created: 6 // Ver: $Id: jpgraph_led.php 1091 2009-01-18 22:57:40Z ljp $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 1674 2009-07-22 19:42:23Z ljp $ 7 7 // 8 // Copyright 2006 (c) A ditus Consulting. All rights reserved.8 // Copyright 2006 (c) Asial Corporation. All rights reserved. 9 9 // 10 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 for13 // 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 StrokeNumber19 // function to _GetLED: 251;20 //21 11 //======================================================================== 22 12 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 51 define('LEDC_RED', 0); 52 define('LEDC_GREEN', 1); 53 define('LEDC_BLUE', 2); 54 define('LEDC_YELLOW', 3); 55 define('LEDC_GRAY', 4); 56 define('LEDC_CHOCOLATE', 5); 57 define('LEDC_PERU', 6); 58 define('LEDC_GOLDENROD', 7); 59 define('LEDC_KHAKI', 8); 60 define('LEDC_OLIVE', 9); 61 define('LEDC_LIMEGREEN', 10); 62 define('LEDC_FORESTGREEN', 11); 63 define('LEDC_TEAL', 12); 64 define('LEDC_STEELBLUE', 13); 65 define('LEDC_NAVY', 14); 66 define('LEDC_INVERTGRAY', 15); 67 // ! It correlate with two-dimensional array $iColorSchema 13 // Constants for color schema 14 DEFINE('LEDC_RED', 0); 15 DEFINE('LEDC_GREEN', 1); 16 DEFINE('LEDC_BLUE', 2); 17 DEFINE('LEDC_YELLOW', 3); 18 DEFINE('LEDC_GRAY', 4); 19 DEFINE('LEDC_CHOCOLATE', 5); 20 DEFINE('LEDC_PERU', 6); 21 DEFINE('LEDC_GOLDENROD', 7); 22 DEFINE('LEDC_KHAKI', 8); 23 DEFINE('LEDC_OLIVE', 9); 24 DEFINE('LEDC_LIMEGREEN', 10); 25 DEFINE('LEDC_FORESTGREEN', 11); 26 DEFINE('LEDC_TEAL', 12); 27 DEFINE('LEDC_STEELBLUE', 13); 28 DEFINE('LEDC_NAVY', 14); 29 DEFINE('LEDC_INVERTGRAY', 15); 30 31 // Check that mb_strlen() is available 32 if( ! function_exists('mb_strlen') ) { 33 JpGraphError::RaiseL(25500); 34 //'Multibyte strings must be enabled in the PHP installation in order to run the LED module 35 // so that the function mb_strlen() is available. See PHP documentation for more information.' 36 } 68 37 69 38 //======================================================================== 70 39 // CLASS DigitalLED74 71 // Description: 40 // Description: 72 41 // Construct a number as an image that looks like LED numbers in a 73 42 // 7x4 digital matrix … … 77 46 private $iLED_X = 4, $iLED_Y=7, 78 47 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 } 48 // fg-up, fg-down, bg 49 $iColorSchema = array( 50 LEDC_RED => array('red','darkred:0.9','red:0.3'),// 0 51 LEDC_GREEN => array('green','darkgreen','green:0.3'),// 1 52 LEDC_BLUE => array('lightblue:0.9','darkblue:0.85','darkblue:0.7'),// 2 53 LEDC_YELLOW => array('yellow','yellow:0.4','yellow:0.3'),// 3 54 LEDC_GRAY => array('gray:1.4','darkgray:0.85','darkgray:0.7'), 55 LEDC_CHOCOLATE => array('chocolate','chocolate:0.7','chocolate:0.5'), 56 LEDC_PERU => array('peru:0.95','peru:0.6','peru:0.5'), 57 LEDC_GOLDENROD => array('goldenrod','goldenrod:0.6','goldenrod:0.5'), 58 LEDC_KHAKI => array('khaki:0.7','khaki:0.4','khaki:0.3'), 59 LEDC_OLIVE => array('#808000','#808000:0.7','#808000:0.6'), 60 LEDC_LIMEGREEN => array('limegreen:0.9','limegreen:0.5','limegreen:0.4'), 61 LEDC_FORESTGREEN => array('forestgreen','forestgreen:0.7','forestgreen:0.5'), 62 LEDC_TEAL => array('teal','teal:0.7','teal:0.5'), 63 LEDC_STEELBLUE => array('steelblue','steelblue:0.65','steelblue:0.5'), 64 LEDC_NAVY => array('navy:1.3','navy:0.95','navy:0.8'),//14 65 LEDC_INVERTGRAY => array('darkgray','lightgray:1.5','white')//15 66 ), 67 68 /* Each line of the character is encoded as a 4 bit value 69 0 ____ 70 1 ___x 71 2 __x_ 72 3 __xx 73 4 _x__ 74 5 _x_x 75 6 _xx_ 76 7 _xxx 77 8 x___ 78 9 x__x 79 10 x_x_ 80 11 x_xx 81 12 xx__ 82 13 xx_x 83 14 xxx_ 84 15 xxxx 85 */ 86 87 $iLEDSpec = array( 88 0 => array(6,9,11,15,13,9,6), 89 1 => array(2,6,10,2,2,2,2), 90 2 => array(6,9,1,2,4,8,15), 91 3 => array(6,9,1,6,1,9,6), 92 4 => array(1,3,5,9,15,1,1), 93 5 => array(15,8,8,14,1,9,6), 94 6 => array(6,8,8,14,9,9,6), 95 7 => array(15,1,1,2,4,4,4), 96 8 => array(6,9,9,6,9,9,6), 97 9 => array(6,9,9,7,1,1,6), 98 '!' => array(4,4,4,4,4,0,4), 99 '?' => array(6,9,1,2,2,0,2), 100 '#' => array(0,9,15,9,15,9,0), 101 '@' => array(6,9,11,11,10,9,6), 102 '-' => array(0,0,0,15,0,0,0), 103 '_' => array(0,0,0,0,0,0,15), 104 '=' => array(0,0,15,0,15,0,0), 105 '+' => array(0,0,4,14,4,0,0), 106 '|' => array(4,4,4,4,4,4,4), //vertical line, used for simulate rus 'Ы' 107 ',' => array(0,0,0,0,0,12,4), 108 '.' => array(0,0,0,0,0,12,12), 109 ':' => array(12,12,0,0,0,12,12), 110 ';' => array(12,12,0,0,0,12,4), 111 '[' => array(3,2,2,2,2,2,3), 112 ']' => array(12,4,4,4,4,4,12), 113 '(' => array(1,2,2,2,2,2,1), 114 ')' => array(8,4,4,4,4,4,8), 115 '{' => array(3,2,2,6,2,2,3), 116 '}' => array(12,4,4,6,4,4,12), 117 '<' => array(1,2,4,8,4,2,1), 118 '>' => array(8,4,2,1,2,4,8), 119 '*' => array(9,6,15,6,9,0,0), 120 '"' => array(10,10,0,0,0,0,0), 121 '\'' => array(4,4,0,0,0,0,0), 122 '`' => array(4,2,0,0,0,0,0), 123 '~' => array(13,11,0,0,0,0,0), 124 '^' => array(4,10,0,0,0,0,0), 125 '\\' => array(8,8,4,6,2,1,1), 126 '/' => array(1,1,2,6,4,8,8), 127 '%' => array(1,9,2,6,4,9,8), 128 '&' => array(0,4,10,4,11,10,5), 129 '$' => array(2,7,8,6,1,14,4), 130 ' ' => array(0,0,0,0,0,0,0), 131 'â¢' => array(0,0,6,6,0,0,0), //149 132 '°' => array(14,10,14,0,0,0,0), //176 133 'â ' => array(4,4,14,4,4,4,4), //134 134 'â¡' => array(4,4,14,4,14,4,4), //135 135 '±' => array(0,4,14,4,0,14,0), //177 136 'â°' => array(0,4,2,15,2,4,0), //137 show right arrow 137 'â¢' => array(0,2,4,15,4,2,0), //156 show left arrow 138 'Ð' => array(0,0,8,8,0,0,0), //159 show small hi-stick - that need for simulate rus 'Ѐ' 139 "\t" => array(8,8,8,0,0,0,0), //show hi-stick - that need for simulate rus 'У' 140 "\r" => array(8,8,8,8,8,8,8), //vertical line - that need for simulate 'M', 'W' and rus 'Ð','К' ,'Щ' 141 "\n" => array(15,15,15,15,15,15,15), //fill up - that need for simulate rus 'Ð' 142 "Ò" => array(10,5,10,5,10,5,10), //chess 143 "µ" => array(15,0,15,0,15,0,15), //4 horizontal lines 144 // latin 145 'A' => array(6,9,9,15,9,9,9), 146 'B' => array(14,9,9,14,9,9,14), 147 'C' => array(6,9,8,8,8,9,6), 148 'D' => array(14,9,9,9,9,9,14), 149 'E' => array(15,8,8,14,8,8,15), 150 'F' => array(15,8,8,14,8,8,8), 151 'G' => array(6,9,8,8,11,9,6), 152 'H' => array(9,9,9,15,9,9,9), 153 'I' => array(14,4,4,4,4,4,14), 154 'J' => array(15,1,1,1,1,9,6), 155 'K' => array(8,9,10,12,12,10,9), 156 'L' => array(8,8,8,8,8,8,15), 157 'M' => array(8,13,10,8,8,8,8),// need to add \r 158 'N' => array(9,9,13,11,9,9,9), 159 'O' => array(6,9,9,9,9,9,6), 160 'P' => array(14,9,9,14,8,8,8), 161 'Q' => array(6,9,9,9,13,11,6), 162 'R' => array(14,9,9,14,12,10,9), 163 'S' => array(6,9,8,6,1,9,6), 164 'T' => array(14,4,4,4,4,4,4), 165 'U' => array(9,9,9,9,9,9,6), 166 'V' => array(0,0,0,10,10,10,4), 167 'W' => array(8,8,8,8,10,13,8),// need to add \r 168 'X' => array(9,9,6,6,6,9,9), 169 'Y' => array(10,10,10,10,4,4,4), 170 'Z' => array(15,1,2,6,4,8,15), 171 // russian utf-8 172 'Ð' => array(6,9,9,15,9,9,9), 173 'Ð' => array(14,8,8,14,9,9,14), 174 'Ð' => array(14,9,9,14,9,9,14), 175 'Ð' => array(15,8,8,8,8,8,8), 176 'Ð' => array(14,9,9,9,9,9,14), 177 'Ð' => array(15,8,8,14,8,8,15), 178 'Ð' => array(6,15,8,14,8,8,15), 179 //Ð is combine: >\n< 180 'Ð' => array(6,9,1,2,1,9,6), 181 'Ð' => array(9,9,9,11,13,9,9), 182 'Ð' => array(13,9,9,11,13,9,9), 183 'Ð' => array(9,10,12,10,9,9,9), 184 'Ð' => array(7,9,9,9,9,9,9), 185 'Ð' => array(8,13,10,8,8,8,8),// need to add \r 186 'Ð' => array(9,9,9,15,9,9,9), 187 'Ð' => array(6,9,9,9,9,9,6), 188 'Ð' => array(15,9,9,9,9,9,9), 189 'Ð ' => array(14,9,9,14,8,8,8), 190 'С' => array(6,9,8,8,8,9,6), 191 'Т' => array(14,4,4,4,4,4,4), 192 'У' => array(9,9,9,7,1,9,6), 193 'Ѐ' => array(2,7,10,10,7,2,2),// need to add Ð 194 'Ð¥' => array(9,9,6,6,6,9,9), 195 'Њ' => array(10,10,10,10,10,15,1), 196 'Ч' => array(9,9,9,7,1,1,1), 197 'К' => array(10,10,10,10,10,10,15),// \r 198 'Щ' => array(10,10,10,10,10,15,0),// need to add \r 199 'Ъ' => array(12,4,4,6,5,5,6), 200 'Ы' => array(8,8,8,14,9,9,14),// need to add | 201 'Ь' => array(8,8,8,14,9,9,14), 202 'Ð' => array(6,9,1,7,1,9,6), 203 'Ю' => array(2,2,2,3,2,2,2),// need to add O 204 'Я' => array(7,9,9,7,3,5,9) 205 ), 206 207 $iSuperSampling = 3, $iMarg = 1, $iRad = 4; 208 209 function __construct($aRadius = 2, $aMargin= 0.6) { 210 $this->iRad = $aRadius; 211 $this->iMarg = $aMargin; 212 } 213 214 function SetSupersampling($aSuperSampling = 2) { 215 $this->iSuperSampling = $aSuperSampling; 216 } 217 218 function _GetLED($aLedIdx, $aColor = 0) { 219 $width= $this->iLED_X*$this->iRad*2 + ($this->iLED_X+1)*$this->iMarg + $this->iRad ; 220 $height= $this->iLED_Y*$this->iRad*2 + ($this->iLED_Y)*$this->iMarg + $this->iRad * 2; 221 222 // Adjust radious for supersampling 223 $rad = $this->iRad * $this->iSuperSampling; 224 225 // Margin in between "Led" dots 226 $marg = $this->iMarg * $this->iSuperSampling; 227 228 $swidth = $width*$this->iSuperSampling; 229 $sheight = $height*$this->iSuperSampling; 230 231 $simg = new RotImage($swidth, $sheight, 0, DEFAULT_GFORMAT, false); 232 $simg->SetColor($this->iColorSchema[$aColor][2]); 233 $simg->FilledRectangle(0, 0, $swidth-1, $sheight-1); 234 235 if( array_key_exists($aLedIdx, $this->iLEDSpec) ) { 236 $d = $this->iLEDSpec[$aLedIdx]; 237 } 238 else { 239 $d = array(0,0,0,0,0,0,0); 240 } 241 242 for($r = 0; $r < 7; ++$r) { 243 $dr = $d[$r]; 244 for($c = 0; $c < 4; ++$c) { 245 if( ($dr & pow(2,3-$c)) !== 0 ) { 246 $color = $this->iColorSchema[$aColor][0]; 247 } 248 else { 249 $color = $this->iColorSchema[$aColor][1]; 250 } 251 252 $x = 2*$rad*$c+$rad + ($c+1)*$marg + $rad ; 253 $y = 2*$rad*$r+$rad + ($r+1)*$marg + $rad ; 254 255 $simg->SetColor($color); 256 $simg->FilledCircle($x,$y,$rad); 257 } 258 } 259 260 $img = new Image($width, $height, DEFAULT_GFORMAT, false); 261 $img->Copy($simg->img, 0, 0, 0, 0, $width, $height, $swidth, $sheight); 262 $simg->Destroy(); 263 unset($simg); 264 return $img; 265 } 266 267 268 function Stroke($aValStr, $aColor = 0, $aFileName = '') { 269 $this->StrokeNumber($aValStr, $aColor, $aFileName); 270 } 271 282 272 283 273 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 } 274 if( $aColor < 0 || $aColor >= sizeof($this->iColorSchema) ) { 275 $aColor = 0; 276 } 277 278 if(($n = mb_strlen($aValStr,'utf8')) == 0) { 279 $aValStr = ' '; 280 $n = 1; 281 } 282 283 for($i = 0; $i < $n; ++$i) { 284 $d = mb_substr($aValStr, $i, 1, 'utf8'); 285 if( ctype_digit($d) ) { 286 $d = (int)$d; 287 } 288 else { 289 $d = strtoupper($d); 290 } 291 $digit_img[$i] = $this->_GetLED($d, $aColor); 292 } 293 294 $w = imagesx($digit_img[0]->img); 295 $h = imagesy($digit_img[0]->img); 296 297 $number_img = new Image($w*$n, $h, DEFAULT_GFORMAT, false); 298 299 for($i = 0; $i < $n; ++$i) { 300 $number_img->Copy($digit_img[$i]->img, $i*$w, 0, 0, 0, $w, $h, $w, $h); 301 } 302 303 if( $aFileName != '' ) { 304 $number_img->Stream($aFileName); 305 } else { 306 $number_img->Headers(); 307 $number_img->Stream(); 308 } 318 309 } 319 310 }
Note:
See TracChangeset
for help on using the changeset viewer.