forked from Slevinski/swis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilesystem.php
More file actions
219 lines (199 loc) · 5.43 KB
/
filesystem.php
File metadata and controls
219 lines (199 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
/**
* Filesystem Font Library
*
* This file is part of SWIS: the SignWriting Icon Server.
*
* SWIS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SWIS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SWIS. If not, see <http://www.gnu.org/licenses/>.
*
* END Copyright
*
* @copyright 2007-2012 Stephen E Slevinski Jr
* @author Steve Slevinski (slevin@signpuddle.net)
* @version 1
* @section License
* GPL 3, http://www.opensource.org/licenses/gpl-3.0.html
* @brief Database font functions for the ISWA 2010
* @file
*
*/
/**
* @brief returns array of symbol group information
* @return array of symbol group data
* @ingroup key
*/
function loadSymbolGroups(){
$filename = 'iswa/data/iswa.sgd';
$data = file_get_contents($filename);
$rows = explode("\n",$data);
$SymbolGroups = array();
foreach ($rows as $i => $row){
$sg = array();
if ($i==0){
$keys = explode("\t",$rows[$i]);
} else {
$values = explode("\t",$rows[$i]);
foreach ($keys as $i => $key){
$sg[$key] = $values[$i];
}
$code = $sg['code'];
$SymbolGroups[$code] = $sg;
}
}
return $SymbolGroups;
}
/**
* @brief returns array of base symbol information
* @return array of base symbol data
* @ingroup key
*/
function loadBaseSymbols(){
$filename = 'iswa/data/iswa.bsd';
$data = file_get_contents($filename);
$rows = explode("\n",$data);
$BaseSymbols = array();
foreach ($rows as $i => $row){
if ($row!=''){
$bs = array();
if ($i==0){
$keys = explode("\t",$rows[$i]);
} else {
$values = explode("\t",$rows[$i]);
foreach ($keys as $i => $key){
$bs[$key] = $values[$i];
}
$code = $bs['code'];
$BaseSymbols[$code] = $bs;
}
}
}
return $BaseSymbols;
}
/**
* translation between ISWA 2010 symbol id and symbol key
*/
$idkey = array();
function load_iswa_id_key(){
global $idkey;
$filename = 'iswa/data/iswa_sym_base.txt';
$contents = trim(file_get_contents($filename));
$rows = explode("\n",$contents);
foreach ($rows as $i => $row){
$parts = explode(',',$row);
$idkey[$parts[0]] = (string)$parts[1];
}
}
function id2key($sid){
global $idkey;
if (count($idkey)==0) load_iswa_id_key();
$sBase = substr($sid,0,12);
$base = $idkey[$sBase];
if (strlen($sid) == 18) {
$ifill = intval(substr($sid,13,2)) -1;
$hrot = dechex(intval(substr($sid,16,2) -1));
$key = $base . $ifill . $hrot;
} else {
$key = base2view($base);
}
return $key;
}
function key2id($key,$force){
$key=str_replace('S','',$key);
if (!$force) die('key2id');
//return "01-01-001-01-01-01";
global $idkey;
if (count($idkey)==0) load_iswa_id_key();
$base = substr($key,0,3);
$sym = array_search($base,$idkey,true);
if (strlen($key)!=5){
$key = base2view($base);
}
$ifill = intval(substr($key,3,1)) + 1;
$irot = hexdec(strtoupper(substr($key,4,1))) + 1;
if ($irot>9) {
$srot = (string)$irot;
} else {
$srot = '0' . $irot;
}
return $sym . '-0' . $ifill . '-' . $srot;
}
$messages = array();
function load_iswaNames(){
global $messages;
include('iswa/data/iswa.i18n.php');
}
function iswaName($id, $lang='en'){
global $messages;
if (count($messages)==0) load_iswaNames();
return $messages[$lang]['iswa_' . $id];
}
function image_png($key,$ver){
$base = substr($key,0,3);
$file = 'iswa/png' . $ver . '/' . $base . '/' . $key . '.png';
return file_get_contents($file);
}
function image_svg($key,$ver){
$base = substr($key,0,3);
$file = 'iswa/svg' . $ver . '/' . $base . '/' . $key . '.svg';
return file_get_contents($file);
}
function image_txt($key,$ver){
$base = substr($key,0,3);
$file = 'iswa/txt' . $ver . '/' . $base . '/' . $key . '.txt';
return file_get_contents($file);
}
global $sym_sizer;
function sym_init(){
global $sym_sizer;
$sym_sizer = new SYM_SIZE();
}
class SYM_SIZE {
private $db;
private $symload;
private $symsize;
public function __construct() {
$this->symload = array();
$this->symsize = array();
$this->db = file_get_contents('iswa/data/iswa.size');
}
public function load($ksw){
if ($ksw=="")return;
$sym_pattern = '/S[123][a-f0-9]{2}[012345][a-f0-9]/i';
preg_match_all($sym_pattern,$ksw, $matches);
$syms = array();
foreach($matches[0] as $spatial){
$syms[] = substr($spatial,1,5);
}
$syms = array_unique($syms);
$syms = array_diff($syms,$this->symload);
foreach ($syms as $key){
$this->symload[] = $key;
$size_pattern = '/S' . $key . '[0-9]{3}x[0-9]{3}/i';
preg_match($size_pattern,$this->db, $match);
$size = str2coord(substr($match[0],6,13));
$this->symsize[$key] = koord2str($size[0],$size[1]);
}
}
public function size($key){
$key = str_replace('S','',$key);
return $this->symsize[$key];
}
public function expand($ksw){
foreach($this->symsize as $key=>$row){
$ksw = str_replace('S' . $key,'S' . $key . $row . 'x', $ksw);
}
return $ksw;
}
}
?>