<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Paperjs - OpenTypejs</title>
</head>
<body>
<canvas id="canvas" width="800" height="500" style="border:1px solid #ccc"></canvas>
<script src="~/Scripts/paper-full.js"></script>
<script src="~/Scripts/opentype.js"></script>
<script src="~/Scripts/app/presenter.js"></script>
<script type="text/paperscript" src="~/Scripts/app/mypaperscript.js" canvas="canvas"></script>
<input type="button" onclick="globals.someFunction();" value="Draw"/>
</body>
</html>
Here the presenter.js:
var S = "";
window.globals = {
someInput: "",
someOutput: "",
someFunction: function () {
opentype.load('/fonts/Aerosol.ttf', function (err, font) {
if (err) {
alert('Font could not be loaded: ' + err);
} else {
var ctx = document.getElementById('canvas').getContext('2d');
// Construct a Path object containing the letter shapes of the given text.
// The other parameters are x, y and fontSize.
// Note that y is the position of the baseline.
var path = font.getPath(globals.someInput, 0, 50, 72);
globals.someOutput = path.toSVG(2);
console.log(globals.someOutput);
//path.draw(ctx);
// console.log(svg);
}
});
}
};
And finally here is the mypaperscript.js:
globals.someInput = 'Hellow world';
globals.someFunction();
alert(globals.someOutput);
The final alert shows no content on the screen.
What I am doing wrong?