Browse Source

Moved font regexp out

v1.x
Tj Holowaychuk 14 years ago
parent
commit
2a868c2d2c
  1. 8
      lib/canvas.js

8
lib/canvas.js

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

Loading…
Cancel
Save