-
Notifications
You must be signed in to change notification settings - Fork 18
/
Font.js
56 lines (35 loc) · 863 Bytes
/
Font.js
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
(function (Ω) {
"use strict";
var Font = Ω.Class.extend({
map: " !\"#$%&'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[/]^_`abcdefghijklmnopqrstuvwxyz{|}~",
init: function (path, w, h, map) {
this.sheet = new Ω.SpriteSheet(path, w, h);
this.map = (map || this.map).split("").map(function(c) {
return c.charCodeAt(0);
});
this.w = w;
this.h = h;
},
render: function (gfx, msg, x, y) {
if (!msg) {
return;
}
msg = msg.toString();
var cellW = this.sheet.cellW;
for (var i = 0; i < msg.length; i++) {
var ch = msg.charCodeAt(i),
index = this.map.indexOf(ch);
if (ch === 32 || index === -1) {
continue;
}
this.sheet.render(
gfx,
(index % cellW) | 0,
(index / cellW) | 0,
x + (i * this.w),
y);
}
}
});
Ω.Font = Font;
}(window.Ω));