Browse Source

Added parseFont() string support for font family

v1.x
Tj Holowaychuk 14 years ago
parent
commit
ab061a41a0
  1. 2
      lib/canvas.js
  2. 6
      test/canvas.test.js

2
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];

6
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) {

Loading…
Cancel
Save