Permalink
Browse files

Allow "top", "bottom", "center".

  • Loading branch information...
1 parent 73d2e58 commit ace4cae1fd501efc7fde05bff5c1a8f7193d4841 @basecode basecode committed Jan 23, 2013
Showing with 42 additions and 2 deletions.
  1. +8 −2 src/renderer/svg/svg.js
  2. +34 −0 test/renderer/svg-spec.js
View
@@ -91,6 +91,12 @@ define([
'mousewheel'
];
+ var textOriginMap = {
+ top: 'hanging',
+ center: 'middle',
+ bottom: 'auto'
+ };
+
// tools
var isArray = tools.isArray;
@@ -656,8 +662,8 @@ define([
setStyle(style, 'textAnchor', 'start');
if (textOrigin != null) {
- setStyle(style, 'alignmentBaseline', textOrigin === 'top' ? 'hanging' : '');
- setStyle(style, 'dominantBaseline', textOrigin === 'top' ? 'hanging' : '');
+ setStyle(style, 'alignmentBaseline', textOriginMap[textOrigin]);
+ setStyle(style, 'dominantBaseline', textOriginMap[textOrigin]);
}
};
View
@@ -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() {
function createSvgRenderer(fpsLog, getTime) {
var renderer = new SvgRenderer(createFakeDomNode(), 1, 1, {fpsLog: fpsLog});

0 comments on commit ace4cae

Please sign in to comment.