Skip to content

Instantly share code, notes, and snippets.

@monjudoh
Forked from moriyoshi/canvas.html
Created December 12, 2011 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monjudoh/1465693 to your computer and use it in GitHub Desktop.
Save monjudoh/1465693 to your computer and use it in GitHub Desktop.
canvas
<html>
<body>
<canvas id="test" width="320" height="320"></canvas>
<script type="text/javascript">
(function() {
var proto = document.createElement('canvas').getContext('2d').constructor.prototype;
var x = proto.fillText;
proto.fillText = function fillText(text) {
if (proto.fillText !== fillText) {
proto.fillText = fillText;
}
return x.apply(this, arguments);
};
})();
</script>
<script type="text/javascript">
var c = document.getElementById('test');
var ctx = c.getContext('2d');
ctx.font = "20px Sans-Serif";
ctx.fillStyle = 'rgb(0,0,0)';
ctx.fillText("test2", 0, 20, 100);
ctx.fill();
</script>
<script type="text/javascript">
(function() {
var proto = document.createElement('canvas').getContext('2d').constructor.prototype;
var x = proto.fillText;
proto.fillText = function(text) {
console.log(text);
return x.apply(this, arguments);
};
})();
</script>
<script type="text/javascript">
var c = document.getElementById('test');
var ctx = c.getContext('2d');
ctx.font = "20px Sans-Serif";
ctx.fillStyle = 'rgb(0,0,0)';
ctx.fillText("test3", 0, 20, 100);
ctx.fill();
</script>
<script type="text/javascript">
var c = document.getElementById('test');
var ctx = c.getContext('2d');
ctx.font = "20px Sans-Serif";
ctx.fillStyle = 'rgb(0,0,0)';
ctx.fillText("test4", 0, 20, 100);
ctx.fill();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment