Permalink
Browse files

refactor .useFont()

  • Loading branch information...
1 parent bee4f65 commit dce07d50238e157a893653013e513658d476cc46 @tj tj committed Jan 16, 2013
Showing with 14 additions and 12 deletions.
  1. +2 −2 examples/font.js
  2. +12 −10 lib/context2d.js
View
4 examples/font.js
@@ -27,9 +27,9 @@ var canvas = new Canvas(320, 320)
var ctx = canvas.getContext('2d')
// 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);
View
22 lib/context2d.js
@@ -166,7 +166,7 @@ Context2d.prototype.setTransform = function(){
Context2d.prototype.__defineSetter__('fillStyle', function(val){
if (!val) return;
- if ('CanvasGradient' == val.constructor.name
+ if ('CanvasGradient' == val.constructor.name
|| 'CanvasPattern' == val.constructor.name) {
this.lastFillStyle = val;
this._setFillPattern(val);
@@ -194,7 +194,7 @@ Context2d.prototype.__defineGetter__('fillStyle', function(){
Context2d.prototype.__defineSetter__('strokeStyle', function(val){
if (!val) return;
- if ('CanvasGradient' == val.constructor.name
+ if ('CanvasGradient' == val.constructor.name
|| 'CanvasPattern' == val.constructor.name) {
this.lastStrokeStyle = val;
this._setStrokePattern(val);
@@ -214,15 +214,17 @@ Context2d.prototype.__defineGetter__('strokeStyle', function(){
return this.lastStrokeStyle || this.strokeColor;
});
+/**
+ * Register `font` for usage.
+ *
+ * @param {Font} font
+ * @api public
+ */
-Context2d.prototype.useFont = function(font) {
- if (!this._fonts) this._fonts = {};
- var fonts = this._fonts;
-
- if (fonts[font.name])
- return;
-
- fonts[font.name] = font;
+Context2d.prototype.addFont = function(font) {
+ this._fonts = this._fonts || {};
+ if (this._fonts[font.name]) return;
+ this._fonts[font.name] = font;
};
/**

0 comments on commit dce07d5

Please sign in to comment.