1.0.0 • Published 9 years ago

split-text-canvas v1.0.0

Weekly downloads
7
License
-
Repository
github
Last release
9 years ago

split-text

Split text given a maximum width and a CanvasRenderingContext2D

usage

var canvas = canvas.createElement('canvas');
var cx = canvas.getContext('2d');
var fontSize = 10;
var width = 40;
var text = 'Split This Text, Please';
var y = 20;
var padding = 2;
var renderText = function (t, i) {
  var yi = y + (i * fontSize) + padding;
  cx.fillText(t, x, yi, width);
};

cx.font = fontSize + 'px sans-serif';
splitText(text, width, cx).forEach(renderText);
1.0.0

9 years ago