Browse Source

refactor .useFont()

v1.x
TJ Holowaychuk 12 years ago
parent
commit
dce07d5023
  1. 4
      examples/font.js
  2. 22
      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);

22
lib/context2d.js

@ -166,7 +166,7 @@ Context2d.prototype.setTransform = function(){
Context2d.prototype.__defineSetter__('fillStyle', function(val){ Context2d.prototype.__defineSetter__('fillStyle', function(val){
if (!val) return; if (!val) return;
if ('CanvasGradient' == val.constructor.name if ('CanvasGradient' == val.constructor.name
|| 'CanvasPattern' == val.constructor.name) { || 'CanvasPattern' == val.constructor.name) {
this.lastFillStyle = val; this.lastFillStyle = val;
this._setFillPattern(val); this._setFillPattern(val);
@ -194,7 +194,7 @@ Context2d.prototype.__defineGetter__('fillStyle', function(){
Context2d.prototype.__defineSetter__('strokeStyle', function(val){ Context2d.prototype.__defineSetter__('strokeStyle', function(val){
if (!val) return; if (!val) return;
if ('CanvasGradient' == val.constructor.name if ('CanvasGradient' == val.constructor.name
|| 'CanvasPattern' == val.constructor.name) { || 'CanvasPattern' == val.constructor.name) {
this.lastStrokeStyle = val; this.lastStrokeStyle = val;
this._setStrokePattern(val); this._setStrokePattern(val);
@ -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