Browse Source

refactor .useFont()

v1.x
TJ Holowaychuk 12 years ago
parent
commit
dce07d5023
  1. 4
      examples/font.js
  2. 18
      lib/context2d.js

4
examples/font.js

@ -27,9 +27,9 @@ var canvas = new Canvas(320, 320)
var ctx = canvas.getContext('2d') var ctx = canvas.getContext('2d')
// Tell the ctx to use the font. // Tell the ctx to use the font.
ctx.useFont(pfennigFont); ctx.addFont(pfennigFont);
ctx.font = 'normal normal 50px "Times", serif'; ctx.font = 'normal normal 50px Helvetica';
ctx.fillText('Quo Vaids?', 0, 70); ctx.fillText('Quo Vaids?', 0, 70);

18
lib/context2d.js

@ -214,15 +214,17 @@ Context2d.prototype.__defineGetter__('strokeStyle', function(){
return this.lastStrokeStyle || this.strokeColor; return this.lastStrokeStyle || this.strokeColor;
}); });
/**
* Register `font` for usage.
*
* @param {Font} font
* @api public
*/
Context2d.prototype.useFont = function(font) { Context2d.prototype.addFont = function(font) {
if (!this._fonts) this._fonts = {}; this._fonts = this._fonts || {};
var fonts = this._fonts; if (this._fonts[font.name]) return;
this._fonts[font.name] = font;
if (fonts[font.name])
return;
fonts[font.name] = font;
}; };
/** /**

Loading…
Cancel
Save