Simple Plumin.js example
Using one rectangle and two ellipses to create a p
author(s):
Louis-Remi Babe
HTML
<script src="http://byte-foundry.github.io/plumin.js/dist/plumin.js"></script>
<link rel="stylesheet" href="http://byte-foundry.github.io/plumin.js/bower_components/knacss/css/knacss.css">
<textarea class="result">p</textarea>
<a download="demo.otf" href="#" id="download">â–˝ Download</a>
<canvas id="canvas" width="1024" height="1024" style="display: none;"></canvas>
CSS
textarea {
width: 100%;
height: 300px;
margin: 0;
padding: 20px;
border: 0;
border-radius: 0;
font-family: 'Demo', sans-serif;
font-size: 50px;
resize: none;
}
#download {
display: inline-block;
margin: 5px;
padding: 5px 7px;
text-decoration: none;
color: #FFE;
background: #FF725E;
}
JavaScript
// plumin.paper is aliased to the variable p, for conciseness
(function(p) {
'use strict';
// Setup paper.js by providing a canvas element
p.setup( document.getElementById('canvas') );
// create a new font and specify its name
var demo = new p.Font({ familyName: 'Demo' }),
// create the glyph 'p' and add it directly to the demo font
glyph_p = demo.addGlyph(new p.Glyph({
name: 'p',
unicode: 'p',
advanceWidth: 450
}));
// create a rectangular path to form the stem
glyph_p.addContour(new p.Path.Rectangle({
point: [0, -255],
size: [100, 800]
}));
// create an ellipse for the bowl
glyph_p.addContour(new p.Path.Ellipse({
point: [50, 0],
size: [400, 550]
}));
// and another one for the counter
glyph_p.addContour(new p.Path.Ellipse({
point: [100, 100],
size: [250, 350]
// reverse this path to create a hole in the previous paths
})).reverse();
// create or update the binary data of the OpenType font
demo.updateOTCommands()
// make it available in the page as a font-face
.addToFonts();
// After .prepareOT(), the font is ready to download
document.getElementById('download').onclick = function() {
demo.download();
};
})(plumin.paper);