Browse Source

More font size units

v1.x
Tj Holowaychuk 15 years ago
parent
commit
414c658a2f
  1. 2
      lib/canvas.js
  2. 4
      test/canvas.test.js

2
lib/canvas.js

@ -76,7 +76,7 @@ function normalizedColor(prop) {
exports.parseFont = function(str){ exports.parseFont = function(str){
if (cache[str]) return cache[str]; if (cache[str]) return cache[str];
var obj = {} var obj = {}
, captures = /^ *(?:(normal|bold|bolder|lighter|[1-9](?:00)) *)?(?:(normal|italic|oblique) *)?(\d+)(px|pt) *((?:"([^"]+)"|[\w-]+)( *, *(?:"([^"]+)"|[\w-]+))*)/.exec(str); , captures = /^ *(?:(normal|bold|bolder|lighter|[1-9](?:00)) *)?(?:(normal|italic|oblique) *)?(\d+)(px|pt|pc|in|cm|mm|%) *((?:"([^"]+)"|[\w-]+)( *, *(?:"([^"]+)"|[\w-]+))*)/.exec(str);
if (!captures) return; if (!captures) return;
obj.weight = captures[1] || 'normal'; obj.weight = captures[1] || 'normal';
obj.style = captures[2] || 'normal'; obj.style = captures[2] || 'normal';

4
test/canvas.test.js

@ -66,6 +66,10 @@ module.exports = {
, { size: 20, unit: 'px', family: 'Arial' } , { size: 20, unit: 'px', family: 'Arial' }
, '20pt Arial' , '20pt Arial'
, { size: 20, unit: 'pt', family: 'Arial' } , { size: 20, unit: 'pt', family: 'Arial' }
, '20% Arial'
, { size: 20, unit: '%', family: 'Arial' }
, '20mm Arial'
, { size: 20, unit: 'mm', family: 'Arial' }
, '20px serif' , '20px serif'
, { size: 20, unit: 'px', family: 'serif' } , { size: 20, unit: 'px', family: 'serif' }
, '20px sans-serif' , '20px sans-serif'

Loading…
Cancel
Save