Skip to content

Instantly share code, notes, and snippets.

04971bf84d0cd72ea4ee016234d6ebb7ec0fa5167c81f8b37ed75e6b7b673aab2ccd08e81e4bad2f5ba888ca0b26d50f30d16674d57655c9dc4dea6a6e641d7de6;Bubbit
@jimivdw
jimivdw / boxed_fill_text.html
Created October 9, 2013 13:38
An extension to the CanvasRenderingContext2D's fillText method that supports line breaks and automatically fits the text into a specified bounding box.
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="800" height="400" style="border: 1px solid #333;"></canvas>
<script type="text/javascript">
// Based on:
// http://www.html5canvastutorials.com/tutorials/html5-canvas-wrap-text-tutorial
CanvasRenderingContext2D.prototype.textLines = function(x, y, w, h, text,
hard_wrap) {
var ctx = this;