From 1676b9fd7cb014f20f53712f6a73446d5d25f87c Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Mon, 1 Nov 2010 16:20:30 -0700 Subject: [PATCH] Easier to read font regexp --- lib/canvas.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/canvas.js b/lib/canvas.js index 4011ccb..ed79752 100644 --- a/lib/canvas.js +++ b/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.