Browse Source

Easier to read font regexp

v1.x
Tj Holowaychuk 15 years ago
parent
commit
1676b9fd7c
  1. 18
      lib/canvas.js

18
lib/canvas.js

@ -42,10 +42,24 @@ exports.cairoVersion = cairoVersion;
var cache = {};
/**
* Font RegExp used by parseFont();
* Font RegExp helpers.
*/
var font = /^ *(?:(normal|bold|bolder|lighter|[1-9](?:00)) *)?(?:(normal|italic|oblique) *)?(\d+)(px|pt|pc|in|cm|mm|%) *((?:"([^"]+)"|[\w-]+)( *, *(?:"([^"]+)"|[\w-]+))*)/;
var weights = 'normal|bold|bolder|lighter|[1-9](?:00)'
, styles = 'normal|italic|oblique'
, units = 'px|pt|pc|in|cm|mm|%'
, string = '"([^"]+)"|[\\w-]+';
/**
* Font parser RegExp;
*/
var font = new RegExp('^ *'
+ '(?:(' + weights + ') *)?'
+ '(?:(' + styles + ') *)?'
+ '(\\d+)(' + units + ') *'
+ '((?:' + string + ')( *, *(?:' + string + '))*)'
);
/**
* Buffer extensions.

Loading…
Cancel
Save