Browse Source

Misc font parser refactoring

v1.x
Tj Holowaychuk 14 years ago
parent
commit
2c7a7b7057
  1. 4
      lib/context2d.js
  2. 2
      test/canvas.test.js

4
lib/context2d.js

@ -48,7 +48,7 @@ var weights = 'normal|bold|bolder|lighter|[1-9]00'
var fontre = new RegExp('^ *'
+ '(?:(' + weights + ') *)?'
+ '(?:(' + styles + ') *)?'
+ '(\\d+)(' + units + ') *'
+ '([\\d\\.]+)(' + units + ') *'
+ '((?:' + string + ')( *, *(?:' + string + '))*)'
);
@ -96,7 +96,7 @@ var parseFont = exports.parseFont = function(str){
// Populate font object
font.weight = captures[1] || 'normal';
font.style = captures[2] || 'normal';
font.size = parseInt(captures[3], 10);
font.size = parseFloat(captures[3]);
font.unit = captures[4];
font.family = captures[5];

2
test/canvas.test.js

@ -56,6 +56,8 @@ module.exports = {
, { size: 20, unit: 'px', family: 'Arial' }
, '20pt Arial'
, { size: 20, unit: 'pt', family: 'Arial' }
, '20.5pt Arial'
, { size: 20.5, unit: 'pt', family: 'Arial' }
, '20% Arial'
, { size: 20, unit: '%', family: 'Arial' }
, '20mm Arial'

Loading…
Cancel
Save