1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | (function (global, factory) {
|
8 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
9 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
10 | (global = global || self, factory((global.ssw = global.ssw || {}, global.ssw.ttf = global.ssw.ttf || {}, global.ssw.ttf.font = {})));
|
11 | }(this, (function (exports) { 'use strict';
|
12 |
|
13 | |
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | const cssAppend = function (dir = '') {
|
21 | const id = "SgnwFontCss";
|
22 |
|
23 | if (!document.getElementById(id)) {
|
24 | const style = document.createElement('style');
|
25 | style.setAttribute("id", "SgnwFontCss");
|
26 | style.appendChild(document.createTextNode(`
|
27 | @font-face {
|
28 | font-family: "SuttonSignWritingLine";
|
29 | src:
|
30 | local('SuttonSignWritingLine'),
|
31 | ${dir ? `url('${dir}SuttonSignWritingLine.ttf') format('truetype'),` : ""}
|
32 | url('https://cdn.jsdelivr.net/npm/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingLine.ttf') format('truetype');
|
33 | }
|
34 | @font-face {
|
35 | font-family: "SuttonSignWritingFill";
|
36 | src:
|
37 | local('SuttonSignWritingFill'),
|
38 | ${dir ? `url('${dir}SuttonSignWritingFill.ttf') format('truetype'),` : ""}
|
39 | url('https://cdn.jsdelivr.net/npm/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingFill.ttf') format('truetype');
|
40 | }
|
41 | @font-face {
|
42 | font-family: "SuttonSignWritingOneD";
|
43 | src:
|
44 | local('SuttonSignWritingOneD'),
|
45 | ${dir ? `url('${dir}SuttonSignWritingOneD.ttf') format('truetype'),` : ""}
|
46 | url('https://cdn.jsdelivr.net/npm/@sutton-signwriting/font-ttf@1.0.0/font/SuttonSignWritingOneD.ttf') format('truetype');
|
47 | }
|
48 | `));
|
49 | document.head.appendChild(style);
|
50 | }
|
51 | };
|
52 |
|
53 | let sizes = {};
|
54 | const zoom = 2;
|
55 | const bound = 76 * zoom;
|
56 | const canvaser = document.createElement("canvas");
|
57 | canvaser.width = bound;
|
58 | canvaser.height = bound;
|
59 | const context = canvaser.getContext("2d");
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | const symbolSize = function (id) {
|
71 | if (id in sizes) {
|
72 | return [...sizes[id]];
|
73 | }
|
74 |
|
75 | context.clearRect(0, 0, bound, bound);
|
76 | context.font = 30 * zoom + "px 'SuttonSignWritingLine'";
|
77 | context.fillText(String.fromCodePoint(id + 0xF0000), 0, 0);
|
78 | const imgData = context.getImageData(0, 0, bound, bound).data;
|
79 | let w, h, i, s;
|
80 |
|
81 | wloop: for (w = bound - 1; w >= 0; w--) {
|
82 | for (h = 0; h < bound; h += 1) {
|
83 | for (s = 0; s < 4; s += 1) {
|
84 | i = w * 4 + h * 4 * bound + s;
|
85 |
|
86 | if (imgData[i]) {
|
87 | break wloop;
|
88 | }
|
89 | }
|
90 | }
|
91 | }
|
92 |
|
93 | var width = w;
|
94 |
|
95 | hloop: for (h = bound - 1; h >= 0; h--) {
|
96 | for (w = 0; w < width; w += 1) {
|
97 | for (s = 0; s < 4; s += 1) {
|
98 | i = w * 4 + h * 4 * bound + s;
|
99 |
|
100 | if (imgData[i]) {
|
101 | break hloop;
|
102 | }
|
103 | }
|
104 | }
|
105 | }
|
106 |
|
107 | var height = h + 1;
|
108 | width = Math.ceil(width / zoom);
|
109 | height = Math.ceil(height / zoom);
|
110 |
|
111 | if (14394 == id) {
|
112 | width = 19;
|
113 | }
|
114 |
|
115 | if ([10468, 10480, 10496, 10512, 10500, 10532, 10548, 10862, 10878, 10894, 11058, 11074, 11476, 11488, 11492, 11504, 11508, 11520, 10516, 10910, 10926, 11042, 11082, 10942].includes(id)) {
|
116 | width = 20;
|
117 | }
|
118 |
|
119 | if (31921 == id) {
|
120 | width = 22;
|
121 | }
|
122 |
|
123 | if (38460 == id) {
|
124 | width = 23;
|
125 | }
|
126 |
|
127 | if ([20164, 20212].includes(id)) {
|
128 | width = 25;
|
129 | }
|
130 |
|
131 | if (31894 == id) {
|
132 | width = 28;
|
133 | }
|
134 |
|
135 | if (46698 == id) {
|
136 | width = 29;
|
137 | }
|
138 |
|
139 | if (29606 == id) {
|
140 | width = 30;
|
141 | }
|
142 |
|
143 | if (44855 == id) {
|
144 | width = 40;
|
145 | }
|
146 |
|
147 | if (32667 == id) {
|
148 | width = 50;
|
149 | }
|
150 |
|
151 | if ([11088, 11474, 11490, 11506].includes(id)) {
|
152 | height = 20;
|
153 | }
|
154 |
|
155 | if (6285 == id) {
|
156 | height = 21;
|
157 | }
|
158 |
|
159 | if (40804 == id) {
|
160 | height = 31;
|
161 | }
|
162 |
|
163 | if (41475 == id) {
|
164 | height = 36;
|
165 | }
|
166 |
|
167 |
|
168 |
|
169 | if (width == 0 && height == 0) {
|
170 | const sizefix = {
|
171 | 9: [15, 30],
|
172 | 10: [21, 30],
|
173 | 11: [30, 15],
|
174 | 12: [30, 21],
|
175 | 13: [15, 30],
|
176 | 14: [21, 30]
|
177 | };
|
178 |
|
179 | if (id in sizefix) {
|
180 | width = sizefix[id][0];
|
181 | height = sizefix[id][1];
|
182 | }
|
183 | }
|
184 |
|
185 | if (width == 0 && height == 0) {
|
186 | return undefined;
|
187 | }
|
188 |
|
189 | sizes[id] = [width, height];
|
190 | return [width, height];
|
191 | };
|
192 |
|
193 | |
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 | const symbolLine = function (id) {
|
203 | return String.fromCodePoint(id + 0xF0000);
|
204 | };
|
205 | |
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | const symbolFill = function (id) {
|
217 | return String.fromCodePoint(id + 0x100000);
|
218 | };
|
219 | |
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 | const symbolText = function (id) {
|
232 | return ` <text class="sym-fill" fill="white" style="pointer-events:none;font-family:'SuttonSignWritingFill';font-size:30px;">${symbolFill(id)}</text>
|
233 | <text class="sym-line" fill="black" style="pointer-events:none;font-family:'SuttonSignWritingLine';font-size:30px;">${symbolLine(id)}</text>`;
|
234 | };
|
235 |
|
236 | |
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | const cssLoaded = function (callback) {
|
249 | let lineReady = false;
|
250 | let fillReady = false;
|
251 | cssLoadedLine(() => {
|
252 | lineReady = true;
|
253 | });
|
254 | cssLoadedFill(() => {
|
255 | fillReady = true;
|
256 | });
|
257 | const cssCheck = setInterval(function () {
|
258 | if (lineReady && fillReady) {
|
259 | clearInterval(cssCheck);
|
260 | callback();
|
261 | }
|
262 | }, 100);
|
263 | };
|
264 | |
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 | const cssLoadedLine = function (callback) {
|
278 | if (!symbolSize(1)) {
|
279 | const cssCheck = setInterval(function () {
|
280 | if (symbolSize(1)) {
|
281 | clearInterval(cssCheck);
|
282 | callback();
|
283 | }
|
284 | }, 100);
|
285 | } else {
|
286 | callback();
|
287 | }
|
288 | };
|
289 | |
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 | const cssLoadedFill = function (callback) {
|
303 | const fillReady = function () {
|
304 | const canvaser = document.createElement("canvas");
|
305 | canvaser.width = 15;
|
306 | canvaser.height = 30;
|
307 | const context = canvaser.getContext("2d");
|
308 | context.font = "30px 'SuttonSignWritingFill'";
|
309 | context.fillText(symbolFill(1), 0, 0);
|
310 | const imgData = context.getImageData(0, 0, 15, 30).data;
|
311 | return !imgData.every(item => item === 0);
|
312 | };
|
313 |
|
314 | if (!fillReady()) {
|
315 | const cssCheck = setInterval(function () {
|
316 | if (fillReady()) {
|
317 | clearInterval(cssCheck);
|
318 | callback();
|
319 | }
|
320 | }, 100);
|
321 | } else {
|
322 | callback();
|
323 | }
|
324 | };
|
325 |
|
326 | exports.cssAppend = cssAppend;
|
327 | exports.cssLoaded = cssLoaded;
|
328 | exports.cssLoadedFill = cssLoadedFill;
|
329 | exports.cssLoadedLine = cssLoadedLine;
|
330 | exports.symbolFill = symbolFill;
|
331 | exports.symbolLine = symbolLine;
|
332 | exports.symbolSize = symbolSize;
|
333 | exports.symbolText = symbolText;
|
334 |
|
335 | Object.defineProperty(exports, '__esModule', { value: true });
|
336 |
|
337 | })));
|
338 |
|
339 |
|