forked from byte-foundry/plumin.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbugreport.html
240 lines (200 loc) · 5.48 KB
/
bugreport.html
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Plumin.js | Create and Manipulate fonts like there's no tomorrow.</title>
<meta name="description" content="">
<!-- it's an app, disable zooming on mobile devices -->
<meta name="viewport" content="target-densitydpi=device-dpi, initial-scale=1.0, user-scalable=no" />
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="node_modules/knacss/css/knacss.css">
<link rel="stylesheet" href="node_modules/codemirror/lib/codemirror.css">
<style>
html,
body,
body > .row > .col {
height: 100%;
}
h1 {
height: 100px;
margin: 0;
}
body > .row {
height: calc( 100% - 100px );
}
textarea.editor,
textarea.result {
width: 100%;
/* Doesn't work in Chrome :-/
height: calc( 100% - 100px ); */
height: 400px;
margin: 0;
}
textarea.editor,
.CodeMirror {
font-size: 20px;
}
textarea.result {
padding: 20px;
border: 0;
border-radius: 0;
font-size: 50px;
resize: none;
}
textarea#result1 {
font-family: 'Demo1', sans-serif;
}
textarea#result2 {
font-family: 'Demo2', sans-serif;
}
.btn {
border: 1px solid #CCC;
border-radius: 3px;
margin-top: 10px;
padding: 5px 10px;
font-size: 25px;
text-decoration: none;
}
</style>
</head>
<body>
<!--[if lt IE 10]>
<p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
<![endif]-->
<div class="row">
<div class="col w50 plm">
Without document.fonts.delete
<textarea id="result1" class="result pal">
A B C
(I'm a textarea!)
</textarea>
</div>
<div class="col w50">
With document.fonts.delete
<textarea id="result2" class="result pal">
A B C
(I'm a textarea!)
</textarea>
</div>
</div>
<canvas id="hidden-canvas" width="1024" height="1024" hidden />
<script src="node_modules/codemirror/lib/codemirror.js"></script>
<script src="node_modules/codemirror/mode/javascript/javascript.js"></script>
<script src="node_modules/codemirror/addon/edit/closebrackets.js"></script>
<script src="dist/plumin.js"></script>
<script>
(function(p) {
// this function adds a font to the document but never deletes the previous font
// it leaks a lot of memory but runs smoothly for a few dozen seconds in Firefox
// It runs smoothly in Chrome for a few dozen seconds.
window.addToFontsNoDelete = function( font ) {
var fontface = new FontFace(
font.ot.familyName,
font.ot.toBuffer()
);
document.fonts.add( fontface );
};
// this function adds a font to the document after it deleted the previous font
// it leaks no memory but fonts aren't displayed in Firefox
// It runs smoothly in Chrome.
window.addToFontsDelete = function( font ) {
var fontface = new FontFace(
font.ot.familyName,
font.ot.toBuffer()
);
if ( font.latestFont ) {
document.fonts.delete( font.latestFont );
}
document.fonts.add( fontface );
font.latestFont = fontface;
};
window.addGlyphs = function( font ) {
var A = p.Glyph({
name: 'A',
unicode: 'A',
advanceWidth: 512
}),
B = p.Glyph({
name: 'B',
unicode: 'B',
advanceWidth: 512
}),
C = p.Glyph({
name: 'C',
unicode: 'C',
advanceWidth: 512
}),
// contours
ctA = p.Path({ closed: true }),
ctB = p.Path({ closed: true }),
ctC = p.Path({ closed: true });
ctA.addNodes(p.Node([
{ point: [50, 0] },
{ point: [256, 800] },
{ point: [462, 0] }
]));
ctB.addNodes(p.Node([
{ point: [50, 0] },
{ point: [50, 800] },
{ point: [462, 800] },
{ point: [462, 0] }
]));
ctC.addNodes(p.Node([{
point: [50, 400],
handleIn: [0, -200],
handleOut: [0, 200]
},{
point: [256, 800],
handleIn: [-200, 0],
handleOut: [200, 0]
},{
point: [462, 400],
handleIn: [0, 200],
handleOut: [0, -200]
},{
point: [256, 0],
handleIn: [200, 0],
handleOut: [-200, 0]
}]));
A.addContour(ctA);
B.addContour(ctB);
C.addContour(ctC);
font.addGlyphs([
A,
B,
C
]);
};
})(plumin);
</script>
<script>
(function(p) {
p.paper.setup('hidden-canvas');
var font1 = p.Font({
familyName: 'Demo1'
}),
font2 = p.Font({
familyName: 'Demo2'
});
addGlyphs( font1 );
addGlyphs( font2 );
// animation are only fluid in Chrome
var center = p.Point([256, 400]);
(function _onFrame() {
font1[0].glyphMap.A.contours[0].rotate(3, center);
font1[0].glyphMap.B.contours[0].rotate(-3, center);
font1[0].glyphMap.C.contours[0].rotate(3, center);
font1.updateOTCommands();
addToFontsNoDelete( font1[0] );
font2[0].glyphMap.A.contours[0].rotate(3, center);
font2[0].glyphMap.B.contours[0].rotate(-3, center);
font2[0].glyphMap.C.contours[0].rotate(3, center);
font2.updateOTCommands();
addToFontsDelete( font2[0] );
requestAnimationFrame(_onFrame);
})();
})(plumin);
</script>
</body>
</html>