|
使用 CP***.TXT 來限定新的 unifont.hex 所擁有的字數。
CP***.TXT 可在 unicode.org 下載: http://unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/
用法:
php tbl4slim.php [TXT檔...]
如:
php tbl4slim.php CP936.TXT CP950.TXT
新生成的為 unifont.hex.slim
- <?php
- $txtfiles = array();
- $txtary = array();
- $chrs = array();
- $newunifonthex = array();
- if($_SERVER['argc'] < 2) {
- fwrite(STDERR, "Usage: ".$_SERVER['argv'][0]." {TXT files...}\n");
- exit(2);
- }
- if(!file_exists('./unifont.hex')) {
- fwrite(STDERR, "Error: unifont.hex not found!\n");
- exit(1);
- }
- for($i=1;$i<$_SERVER['argc'];++$i) {
- if(!file_exists($_SERVER['argv'][$i])) {
- fwrite(STDERR, "Warning: ".$_SERVER['argv'][$i]." is not found.\n");
- } else {
- $txtfiles[] = file($_SERVER['argv'][$i]);
- }
- }
- foreach($txtfiles as $t) {
- foreach($t as $l) {
- $txtary = explode("\t",$l);
- if(isset($txtary[1]) && substr($txtary[1],0,2)=='0x') $chrs[$txtary[1]] = 1;
- }
- }
- $txtary = file('./unifont.hex');
- foreach($txtary as $l) {
- if(isset($chrs['0x'.substr($l,0,4)])) $newunifonthex[] = $l;
- }
- $fp = fopen('./unifont.hex.slim','wb');
- fwrite($fp,implode('',$newunifonthex));
- fclose($fp);
复制代码 |
|