From fac90304e6310c3fe19d91b89f4b9a2614b72eec Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 3 Nov 2010 14:09:05 -0700 Subject: [PATCH] Misc refactoring of parseFont() --- lib/canvas.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/canvas.js b/lib/canvas.js index 673e2b2..e2c3545 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -109,15 +109,20 @@ function normalizedColor(prop) { var parseFont = exports.parseFont = function(str){ if (cache[str]) return cache[str]; - var obj = {} + var font = {} , captures = fontre.exec(str); + + // Invalid if (!captures) return; - obj.weight = captures[1] || 'normal'; - obj.style = captures[2] || 'normal'; - obj.size = parseInt(captures[3], 10); - obj.unit = captures[4]; - obj.family = captures[5]; - return cache[str] = obj; + + // Populate font object + font.weight = captures[1] || 'normal'; + font.style = captures[2] || 'normal'; + font.size = parseInt(captures[3], 10); + font.unit = captures[4]; + font.family = captures[5]; + + return cache[str] = font; }; /**