From ab061a41a08abc677e0d722157f88887e1305685 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Mon, 1 Nov 2010 15:35:31 -0700 Subject: [PATCH] Added parseFont() string support for font family --- lib/canvas.js | 2 +- test/canvas.test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/canvas.js b/lib/canvas.js index f7dd42c..09fe9a2 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -76,7 +76,7 @@ function normalizedColor(prop) { exports.parseFont = function(str){ if (cache[str]) return cache[str]; var obj = {} - , captures = /^ *(\d+)(px|pt) *([\w-]+( *, *[\w-]+)*)/.exec(str); + , captures = /^ *(\d+)(px|pt) *((?:"([^"]+)"|[\w-]+)( *, *(?:"([^"]+)"|[\w-]+))*)/.exec(str); if (!captures) return; obj.size = parseInt(captures[1], 10); obj.unit = captures[2]; diff --git a/test/canvas.test.js b/test/canvas.test.js index fe07546..0857912 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -73,6 +73,12 @@ module.exports = { , { size: 20, unit: 'px', family: 'monospace' } , '50px Arial, sans-serif' , { size: 50, unit: 'px', family: 'Arial, sans-serif' } + , '50px Helvetica , Arial, sans-serif' + , { size: 50, unit: 'px', family: 'Helvetica , Arial, sans-serif' } + , '50px "Helvetica Nueue", sans-serif' + , { size: 50, unit: 'px', family: '"Helvetica Nueue", sans-serif' } + , '50px "Helvetica Nueue", "foo bar baz" , sans-serif' + , { size: 50, unit: 'px', family: '"Helvetica Nueue", "foo bar baz" , sans-serif' } ]; for (var i = 0, len = tests.length; i < len; ++i) {