Browse Source

Misc refactoring of parseFont()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
fac90304e6
  1. 19
      lib/canvas.js

19
lib/canvas.js

@ -109,15 +109,20 @@ function normalizedColor(prop) {
var parseFont = exports.parseFont = function(str){ var parseFont = exports.parseFont = function(str){
if (cache[str]) return cache[str]; if (cache[str]) return cache[str];
var obj = {} var font = {}
, captures = fontre.exec(str); , captures = fontre.exec(str);
// Invalid
if (!captures) return; if (!captures) return;
obj.weight = captures[1] || 'normal';
obj.style = captures[2] || 'normal'; // Populate font object
obj.size = parseInt(captures[3], 10); font.weight = captures[1] || 'normal';
obj.unit = captures[4]; font.style = captures[2] || 'normal';
obj.family = captures[5]; font.size = parseInt(captures[3], 10);
return cache[str] = obj; font.unit = captures[4];
font.family = captures[5];
return cache[str] = font;
}; };
/** /**

Loading…
Cancel
Save