From ecc9c1961db89e89ef2acaa48479d69347060c3e Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Mon, 1 Nov 2010 15:30:22 -0700 Subject: [PATCH] More parseFont() tests passing --- lib/canvas.js | 3 ++- test/canvas.test.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/canvas.js b/lib/canvas.js index 0fc2b84..f7dd42c 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -76,7 +76,8 @@ function normalizedColor(prop) { exports.parseFont = function(str){ if (cache[str]) return cache[str]; var obj = {} - , captures = /^ *(\d+)(px) *(Arial)/.exec(str); + , captures = /^ *(\d+)(px|pt) *([\w-]+( *, *[\w-]+)*)/.exec(str); + if (!captures) return; obj.size = parseInt(captures[1], 10); obj.unit = captures[2]; obj.family = captures[3]; diff --git a/test/canvas.test.js b/test/canvas.test.js index 30e8c8b..fe07546 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -63,6 +63,16 @@ module.exports = { var tests = [ '20px Arial' , { size: 20, unit: 'px', family: 'Arial' } + , '20pt Arial' + , { size: 20, unit: 'pt', family: 'Arial' } + , '20px serif' + , { size: 20, unit: 'px', family: 'serif' } + , '20px sans-serif' + , { size: 20, unit: 'px', family: 'sans-serif' } + , '20px monospace' + , { size: 20, unit: 'px', family: 'monospace' } + , '50px Arial, sans-serif' + , { size: 50, unit: 'px', family: 'Arial, sans-serif' } ]; for (var i = 0, len = tests.length; i < len; ++i) {