Browse Source

Added Context2d#font= tests

v1.x
Tj Holowaychuk 14 years ago
parent
commit
3b28bdf82c
  1. 31
      lib/canvas.js
  2. 9
      test/canvas.test.js

31
lib/canvas.js

@ -93,7 +93,15 @@ function normalizedColor(prop) {
}
}
exports.parseFont = function(str){
/**
* Parse font `str`.
*
* @param {String} str
* @return {Object}
* @api public
*/
var parseFont = exports.parseFont = function(str){
if (cache[str]) return cache[str];
var obj = {}
, captures = font.exec(str);
@ -391,6 +399,7 @@ Context2d.prototype.__defineSetter__('strokeStyle', function(val){
*/
Context2d.prototype.__defineGetter__('strokeStyle', normalizedColor('lastStrokeStyle'));
/**
* Set the shadow color with the given css color string.
*
@ -419,3 +428,23 @@ Context2d.prototype.__defineSetter__('shadowColor', function(val){
*/
Context2d.prototype.__defineGetter__('shadowColor', normalizedColor('lastShadowColor'));
Context2d.prototype.__defineSetter__('font', function(val){
if ('string' == typeof val) {
var font;
if (font = parseFont(val)) {
this.lastFontString = val;
}
}
});
/**
* Get the current font.
*
* @see exports.parseFont()
* @api public
*/
Context2d.prototype.__defineGetter__('font', function(){
return this.lastFontString || '10px sans-serif';
});

9
test/canvas.test.js

@ -352,6 +352,15 @@ module.exports = {
, 'Context2d#rect() failed');
},
'test Context2d#font=': function(assert){
var canvas = new Canvas(200, 200)
, ctx = canvas.getContext('2d');
assert.equal('10px sans-serif', ctx.font);
ctx.font = '15px Arial, sans-serif';
assert.equal('15px Arial, sans-serif', ctx.font);
},
'test Context2d#fillStyle=': function(assert){
var canvas = new Canvas(200, 200)
, ctx = canvas.getContext('2d')

Loading…
Cancel
Save