From 41899bbe566883518b72e197a7d86f051e2115bd Mon Sep 17 00:00:00 2001 From: Tobi Reiss Date: Tue, 23 Apr 2013 08:34:27 +0200 Subject: [PATCH] Rename `textAnchor` to `textAlign`. --- example/library/movies/text-metrics.js | 2 +- src/renderer/svg/svg.js | 8 ++++---- src/runner/text.js | 16 ++++++++-------- test/renderer/svg-spec.js | 12 ++++++------ test/text-spec.js | 10 +++++----- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/example/library/movies/text-metrics.js b/example/library/movies/text-metrics.js index 9c210278..4f4903e0 100644 --- a/example/library/movies/text-metrics.js +++ b/example/library/movies/text-metrics.js @@ -26,5 +26,5 @@ drawBox(new Text('bottom right').attr({ drawBox(new Text('center center').attr({ y:260, textOrigin:'center', - textAnchor:'center' + textAlign:'center' })); diff --git a/src/renderer/svg/svg.js b/src/renderer/svg/svg.js index e904f9be..69128cb1 100644 --- a/src/renderer/svg/svg.js +++ b/src/renderer/svg/svg.js @@ -90,7 +90,7 @@ define([ 'touchstart' ]; - var textAnchorMap = { + var textAlignMap = { left: 'start', center: 'middle', right: 'end' @@ -656,7 +656,7 @@ define([ var attributes = message.attributes; var style = text.style; var textOrigin = attributes.textOrigin; - var textAnchor = attributes.textAnchor; + var textAlign = attributes.textAlign; if (attributes.selectable !== undefined) { if (attributes.selectable !== false) { @@ -666,8 +666,8 @@ define([ } } - if (textAnchor != null) { - setStyle(style, 'textAnchor', textAnchorMap[textAnchor]); + if (textAlign != null) { + setStyle(style, 'textAnchor', textAlignMap[textAlign]); } if (textOrigin != null) { diff --git a/src/runner/text.js b/src/runner/text.js index 227fe76e..4dcceeb3 100644 --- a/src/runner/text.js +++ b/src/runner/text.js @@ -78,12 +78,12 @@ define([ return text.join(''); } - function getTextAnchor() { - return this._textAnchor; + function getTextAlign() { + return this._textAlign; } - function setTextAnchor(textAnchor) { - if (/^(left|center|right)$/.test(textAnchor)) { - this._textAnchor = textAnchor; + function setTextAlign(textAlign) { + if (/^(left|center|right)$/.test(textAlign)) { + this._textAlign = textAlign; } } @@ -127,8 +127,8 @@ define([ fontWeight: data('normal', true, true), _cap: data('butt', true), cap: accessor(getCap, setCap, true), - _textAnchor: data('left', true), - textAnchor: accessor(getTextAnchor, setTextAnchor, true), + _textAlign: data('left', true), + textAlign: accessor(getTextAlign, setTextAlign, true), _textFillColor: data(0x000000ff, true), // transparent by default textFillColor: accessor(getTextFillColor, setTextFillColor, true), _textFillGradient: data(null, true), @@ -163,7 +163,7 @@ define([ rendererAttributes.miterLimit = '_miterLimit'; rendererAttributes.selectable = 'selectable'; rendererAttributes.textOrigin = 'textOrigin'; - rendererAttributes.textAnchor = '_textAnchor'; + rendererAttributes.textAlign = '_textAlign'; if (text != null) { this.attr('text', text); diff --git a/test/renderer/svg-spec.js b/test/renderer/svg-spec.js index d70b9557..1bb40428 100644 --- a/test/renderer/svg-spec.js +++ b/test/renderer/svg-spec.js @@ -173,16 +173,16 @@ define(['bonsai/renderer/svg/svg'], function(SvgRenderer) { expect(textElement.style.dominantBaseline).toBe('auto'); }); - it('sets text-anchor=start when attr.textAnchor=left', function() { - createSvgRenderer().drawText(textElement, { attributes: { textAnchor: 'left' } }); + it('sets text-anchor=start when attr.textAlign=left', function() { + createSvgRenderer().drawText(textElement, { attributes: { textAlign: 'left' } }); expect(textElement.style.textAnchor).toBe('start'); }); - it('sets text-anchor=middle when attr.textAnchor=center', function() { - createSvgRenderer().drawText(textElement, { attributes: { textAnchor: 'center' } }); + it('sets text-anchor=middle when attr.textAlign=center', function() { + createSvgRenderer().drawText(textElement, { attributes: { textAlign: 'center' } }); expect(textElement.style.textAnchor).toBe('middle'); }); - it('sets text-anchor=end when attr.textAnchor=right', function() { - createSvgRenderer().drawText(textElement, { attributes: { textAnchor: 'right' } }); + it('sets text-anchor=end when attr.textAlign=right', function() { + createSvgRenderer().drawText(textElement, { attributes: { textAlign: 'right' } }); expect(textElement.style.textAnchor).toBe('end'); }); }); diff --git a/test/text-spec.js b/test/text-spec.js index f4a32bc4..b0558d96 100644 --- a/test/text-spec.js +++ b/test/text-spec.js @@ -122,18 +122,18 @@ define([ }); - describe('provides a property to change `textAnchor`', function() { + describe('provides a property to change `textAlign`', function() { it('is set to `left` by default', function() { - expect(new Text('').attr('textAnchor')).toBe('left'); + expect(new Text('').attr('textAlign')).toBe('left'); }); it('returns `center` when set to `center`.', function() { - expect(new Text('').attr('textAnchor', 'center').attr('textAnchor')).toBe('center'); + expect(new Text('').attr('textAlign', 'center').attr('textAlign')).toBe('center'); }); it('returns `right` when set to `right`', function() { - expect(new Text('').attr('textAnchor', 'right').attr('textAnchor')).toBe('right'); + expect(new Text('').attr('textAlign', 'right').attr('textAlign')).toBe('right'); }); it('ignores unkown values', function() { - expect(new Text('').attr('textAnchor', 4).attr('textAnchor')).toBe('left'); + expect(new Text('').attr('textAlign', 4).attr('textAlign')).toBe('left'); }); });