Browse Source

More parseFont() tests passing

v1.x
Tj Holowaychuk 14 years ago
parent
commit
ecc9c1961d
  1. 3
      lib/canvas.js
  2. 10
      test/canvas.test.js

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

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

Loading…
Cancel
Save