Skip to content

Commit

Permalink
Allow "top", "bottom", "center".
Browse files Browse the repository at this point in the history
  • Loading branch information
basecode committed Jan 23, 2013
1 parent 73d2e58 commit ace4cae
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/renderer/svg/svg.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ define([
'mousewheel' 'mousewheel'
]; ];


var textOriginMap = {
top: 'hanging',
center: 'middle',
bottom: 'auto'
};

// tools // tools
var isArray = tools.isArray; var isArray = tools.isArray;


Expand Down Expand Up @@ -656,8 +662,8 @@ define([
setStyle(style, 'textAnchor', 'start'); setStyle(style, 'textAnchor', 'start');


if (textOrigin != null) { if (textOrigin != null) {
setStyle(style, 'alignmentBaseline', textOrigin === 'top' ? 'hanging' : ''); setStyle(style, 'alignmentBaseline', textOriginMap[textOrigin]);
setStyle(style, 'dominantBaseline', textOrigin === 'top' ? 'hanging' : ''); setStyle(style, 'dominantBaseline', textOriginMap[textOrigin]);
} }


}; };
Expand Down
34 changes: 34 additions & 0 deletions test/renderer/svg-spec.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -134,6 +134,40 @@ define([
}); });
}); });


describe('drawText', function() {
var textElement;
beforeEach(function() {
textElement = { style: {} };
});
it('is a function', function() {
expect(typeof createSvgRenderer().drawText).toBe('function');
});
it('sets baseline-alignment=hanging when attr.textOrigin=top', function() {
createSvgRenderer().drawText(textElement, { attributes: { textOrigin: 'top' } });
expect(textElement.style.alignmentBaseline).toBe('hanging');
});
it('sets dominant-alignment=hanging when attr.textOrigin=top', function() {
createSvgRenderer().drawText(textElement, { attributes: { textOrigin: 'top' } });
expect(textElement.style.dominantBaseline).toBe('hanging');
});
it('sets baseline-alignment=middle when attr.textOrigin=center', function() {
createSvgRenderer().drawText(textElement, { attributes: { textOrigin: 'center' } });
expect(textElement.style.alignmentBaseline).toBe('middle');
});
it('sets dominant-alignment=middle when attr.textOrigin=center', function() {
createSvgRenderer().drawText(textElement, { attributes: { textOrigin: 'center' } });
expect(textElement.style.dominantBaseline).toBe('middle');
});
it('sets baseline-alignment=auto when attr.textOrigin=center', function() {
createSvgRenderer().drawText(textElement, { attributes: { textOrigin: 'bottom' } });
expect(textElement.style.alignmentBaseline).toBe('auto');
});
it('sets dominant-alignment=auto when attr.textOrigin=center', function() {
createSvgRenderer().drawText(textElement, { attributes: { textOrigin: 'bottom' } });
expect(textElement.style.dominantBaseline).toBe('auto');
});
});

describe('Frame logging', function() { describe('Frame logging', function() {
function createSvgRenderer(fpsLog, getTime) { function createSvgRenderer(fpsLog, getTime) {
var renderer = new SvgRenderer(createFakeDomNode(), 1, 1, {fpsLog: fpsLog}); var renderer = new SvgRenderer(createFakeDomNode(), 1, 1, {fpsLog: fpsLog});
Expand Down

0 comments on commit ace4cae

Please sign in to comment.