-
PHP仿LED点阵,读取字库文字,并转化为二进制输出
- <?php
-
- $xml=simplexml_load_file("zimu.xml");
- $font_height=$xml->font->Size_H;
- $font_width=$xml->font->Size_L;
- $lcdwidth=($xml->num_weight)*16;
- $lcdheight=($xml->num_height)*32;
- $Size=$font_width.$font_height;
- $ZiMu=$xml->character;
- $show=$xml->enter;
- $B=$xml->font->B;
- $U=$xml->font->U;
- $display=$B.$U;
- $str=mb_convert_encoding($ZiMu,"gbk","utf-8");
- $strlen=strlen($str);
-
-
- if($font_height*$font_width==12*12){$font_height=16;}
- switch($display)
- {
- case "":$file_name="HZK/cell.bin";break;
- case "B":$file_name="HZK/B-cell.bin";break;
- case "U":$file_name="HZK/U-cell.bin";break;
- case "BU":$file_name="HZK/B-U-cell.bin";break;
- }
- switch($Size)
- {
- case 1212:$start_offset=0;break;
- case 1216:$start_offset=0x0002FEB2;break;
- case 1616:$start_offset=0x0005FD64;break;
- case 1624:$start_offset=0x0009FBA6;break;
- case 2424:$start_offset=0x000FF908;break;
- case 2432:$start_offset=0x0018F51A;break;
- case 3232:$start_offset=0x0024EFDC;break;
- }
-
-
- $fp = fopen($file_name, "rb");
- $offset_size=$font_width * $font_height / 8;
- $number="";
- $word_number=(int)($lcdwidth/$font_width);
- $word_string=$word_number*2;
- $circulation=0;
- $_rows=0;
- for ($i=0; $i<$strlen;$i++)
- {
- $dot_string="";
- if (ord($str[$i])>127)
- {
- $offset=(((ord($str[$i])-0xa1)*94)+(ord($str[$i+1])-0xa1))*$offset_size;
- $i++;
- }
- else
- { $offset=(ord($str[$i])+155)*$offset_size; }
- fseek($fp, $start_offset+$offset,SEEK_SET);
- $bindot=fread($fp, $offset_size);
- for($j=0; $j<$offset_size; $j++)
- { $dot_string.= sprintf("%08b", ord($bindot[$j]));
- $total.=sprintf("%08b", ord($bindot[$j])); }
- $one_word[$i]=$dot_string;
- $number.=$one_word[$i];
- $circulation++;
- if($circulation==$word_number)
- {
- $circulation=0;
- $_rows++;
- $Word[$_rows-1]=$number;
- $number="";
- }
- }
- $Word[$_rows]=$number;
- $lcdrow=json_encode($Word);
- $row_number=(count($one_word))/$word_number;
- fclose($fp);
-
-
- ?>
-
相关阅读:
网络编程
GUI编程
Java数组
Day24
Day23
Day22
Day21
Day20
Day19
Day18
-
原文地址:https://www.cnblogs.com/xred/p/8523324.html
Copyright © 2020-2023
润新知