Browse Source

Defer font caching to font=

allowing us to cache the entire object
v1.x
Tj Holowaychuk 14 years ago
parent
commit
9ee167eb01
  1. 13
      lib/canvas.js

13
lib/canvas.js

@ -108,7 +108,6 @@ function normalizedColor(prop) {
*/ */
var parseFont = exports.parseFont = function(str){ var parseFont = exports.parseFont = function(str){
if (cache[str]) return cache[str];
var font = {} var font = {}
, captures = fontre.exec(str); , captures = fontre.exec(str);
@ -122,7 +121,7 @@ var parseFont = exports.parseFont = function(str){
font.unit = captures[4]; font.unit = captures[4];
font.family = captures[5]; font.family = captures[5];
return cache[str] = font; return font;
}; };
/** /**
@ -480,11 +479,10 @@ Context2d.prototype.__defineGetter__('shadowColor', normalizedColor('lastShadowC
Context2d.prototype.__defineSetter__('font', function(val){ Context2d.prototype.__defineSetter__('font', function(val){
if ('string' == typeof val) { if ('string' == typeof val) {
var font; var font;
if (font = parseFont(val)) { if (font = cache[val] || parseFont(val)) {
// TODO: cache
// TODO: dpi // TODO: dpi
this.lastFontString = val; this.lastFontString = val;
switch (font.unit) { switch (font.unit) {
case 'pt': case 'pt':
font.size /= .75; font.size /= .75;
@ -500,6 +498,10 @@ Context2d.prototype.__defineSetter__('font', function(val){
break; break;
} }
// Cache font object
cache[val] = font;
// Set font
this.setFont( this.setFont(
font.weight font.weight
, font.style , font.style
@ -513,7 +515,6 @@ Context2d.prototype.__defineSetter__('font', function(val){
/** /**
* Get the current font. * Get the current font.
* *
* @see exports.parseFont()
* @api public * @api public
*/ */

Loading…
Cancel
Save