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

Loading…
Cancel
Save