Skip to content

Instantly share code, notes, and snippets.

@MattyBalaam
Created June 3, 2014 16:08
Show Gist options
  • Save MattyBalaam/48d8c8ed4e8c7cef7583 to your computer and use it in GitHub Desktop.
Save MattyBalaam/48d8c8ed4e8c7cef7583 to your computer and use it in GitHub Desktop.
A Pen by MattyBalaam.
<p><i class="fa fa-car"></i> Force Font to load.</p>
<canvas id="thecanvas" width="900" height="700">
</ canvas>
var standardIcon = [["\uf013", 0]];
var stackedIcon = [
["\uf1db",0],
["\uf040",180, 0.6] // [0] unicode - http://fortawesome.github.io/Font-Awesome/cheatsheet/ ||| [1] rotation angle ||| [2] scale icon.
];
var fontHeight = 70;
$(window).on('load', function(){
var waiting = setTimeout(makeCanvas, 1000);
})
Math.radians = function(deg) {
return deg * (Math.PI/180);
}
function placeFont(iconArray, x, y, ctx) {
jQuery.each(iconArray, function(i, iconCode){
ctx.save();
if (iconCode[1] > 0) {
ctx.translate(x,y-fontHeight*0.55);
ctx.rotate(Math.radians(iconCode[1]));
x = 0;
y = 0;
}
if (iconCode[2] !== "undefined") {
ctx.scale(iconCode[2], iconCode[2]);
}
ctx.fillText(iconCode[0], x, y)
ctx.restore();
})
}
function makeCanvas() {
var canvas = document.getElementById('thecanvas');
if (canvas.getContext){
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#694';
ctx.textAlign = "center";
ctx.font = fontHeight + 'px FontAwesome';
placeFont(standardIcon, 100, 100, ctx);
placeFont(stackedIcon, 200, 250, ctx);
}
}
@import "bourbon";
p {
visibility: hidden;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment