added tests for text baseline

This commit is contained in:
kerryliu 2014-09-20 16:01:08 -07:00
parent 0393936d0e
commit 16384e302c
3 changed files with 65 additions and 1 deletions

View File

@ -33,6 +33,7 @@ var svg = ctx.getSvg();
Updates Updates
========== ==========
- v1.0.6 basic support for text baseline (contribution from KoKuToru)
- v1.0.5 fixes for #5 and #6 (with contributions from KoKuToru) - v1.0.5 fixes for #5 and #6 (with contributions from KoKuToru)
- v1.0.4 generate ids that start with a letter - v1.0.4 generate ids that start with a letter
- v1.0.3 fixed #4 where largeArcFlag was set incorrectly in some cases - v1.0.3 fixed #4 where largeArcFlag was set incorrectly in some cases

View File

@ -1,5 +1,5 @@
/*!! /*!!
* Canvas 2 Svg v1.0.5 * Canvas 2 Svg v1.0.6
* A low level canvas to SVG converter. Uses a mock canvas context to build an SVG document. * A low level canvas to SVG converter. Uses a mock canvas context to build an SVG document.
* *
* Licensed under the MIT license: * Licensed under the MIT license:

View File

@ -228,4 +228,67 @@ describe("canvas2svg", function() {
}); });
describe("supports text baseline", function() {
it("not specifying a value defaults to alphabetic", function() {
var ctx = new C2S();
ctx.font = "normal 36px Times";
ctx.fillStyle = "#000000";
ctx.fillText("A Text Example", 0, 50);
var svg = ctx.getSvg();
expect(svg.querySelector("text").getAttribute("dominant-baseline")).toBe("alphabetic");
});
it("not specifying a valid value defaults to alphabetic", function() {
var ctx = new C2S();
ctx.font = "normal 36px Times";
ctx.fillStyle = "#000000";
ctx.textBaseline = "werwerwer";
ctx.fillText("A Text Example", 0, 50);
var svg = ctx.getSvg();
expect(svg.querySelector("text").getAttribute("dominant-baseline")).toBe("alphabetic");
});
it("hanging maps to hanging ", function() {
var ctx = new C2S();
ctx.font = "normal 36px Times";
ctx.fillStyle = "#000000";
ctx.textBaseline = "hanging";
ctx.fillText("A Text Example", 0, 50);
var svg = ctx.getSvg();
expect(svg.querySelector("text").getAttribute("dominant-baseline")).toBe("hanging");
});
it("top maps to text-before-edge ", function() {
var ctx = new C2S();
ctx.font = "normal 36px Times";
ctx.fillStyle = "#000000";
ctx.textBaseline = "top";
ctx.fillText("A Text Example", 0, 50);
var svg = ctx.getSvg();
expect(svg.querySelector("text").getAttribute("dominant-baseline")).toBe("text-before-edge");
});
it("bottom maps to text-after-edge ", function() {
var ctx = new C2S();
ctx.font = "normal 36px Times";
ctx.fillStyle = "#000000";
ctx.textBaseline = "bottom";
ctx.fillText("A Text Example", 0, 50);
var svg = ctx.getSvg();
expect(svg.querySelector("text").getAttribute("dominant-baseline")).toBe("text-after-edge");
});
it("middle maps to central ", function() {
var ctx = new C2S();
ctx.font = "normal 36px Times";
ctx.fillStyle = "#000000";
ctx.textBaseline = "middle";
ctx.fillText("A Text Example", 0, 50);
var svg = ctx.getSvg();
expect(svg.querySelector("text").getAttribute("dominant-baseline")).toBe("central");
});
});
}); });