add unit tests for new textalign support, update readme
This commit is contained in:
parent
10ee28b502
commit
d984cf76e7
@ -33,6 +33,7 @@ var svg = ctx.getSvg();
|
||||
|
||||
Updates
|
||||
==========
|
||||
- v1.0.5 fixes for #5 and #6 (with contributions from KoKuToru)
|
||||
- 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.2 Split up rgba values set in fill/stroke to allow illustrator import support.
|
||||
|
@ -60,6 +60,7 @@
|
||||
|
||||
//helper function to map canvas-textAlign to svg-textAnchor
|
||||
function getTextAnchor(textAlign) {
|
||||
//TODO: support rtl languages
|
||||
var mapping = {"left":"start", "right":"end", "center":"middle", "start":"start", "end":"end"};
|
||||
return mapping[textAlign] || mapping.start;
|
||||
}
|
||||
|
@ -165,4 +165,67 @@ describe("canvas2svg", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("supports text align", function() {
|
||||
|
||||
it("not specifying a value defaults to 'start'", 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("text-anchor")).toBe("start");
|
||||
|
||||
});
|
||||
|
||||
it("assuming ltr, left maps to 'start'", function() {
|
||||
|
||||
var ctx = new C2S();
|
||||
ctx.textAlign = "left";
|
||||
ctx.font = "normal 36px Times";
|
||||
ctx.fillStyle = "#000000";
|
||||
ctx.fillText("A Text Example", 0, 50);
|
||||
var svg = ctx.getSvg();
|
||||
expect(svg.querySelector("text").getAttribute("text-anchor")).toBe("start");
|
||||
|
||||
});
|
||||
|
||||
it("assuming ltr, right maps to 'end'", function() {
|
||||
|
||||
var ctx = new C2S();
|
||||
ctx.textAlign = "right";
|
||||
ctx.font = "normal 36px Times";
|
||||
ctx.fillStyle = "#000000";
|
||||
ctx.fillText("A Text Example", 0, 50);
|
||||
var svg = ctx.getSvg();
|
||||
expect(svg.querySelector("text").getAttribute("text-anchor")).toBe("end");
|
||||
|
||||
});
|
||||
|
||||
it("center maps to 'middle'", function() {
|
||||
|
||||
var ctx = new C2S();
|
||||
ctx.textAlign = "center";
|
||||
ctx.font = "normal 36px Times";
|
||||
ctx.fillStyle = "#000000";
|
||||
ctx.fillText("A Text Example", 0, 50);
|
||||
var svg = ctx.getSvg();
|
||||
expect(svg.querySelector("text").getAttribute("text-anchor")).toBe("middle");
|
||||
|
||||
});
|
||||
|
||||
it("stores the proper values on save and restore", function() {
|
||||
var ctx = new C2S();
|
||||
ctx.textAlign = "center";
|
||||
expect(ctx.textAlign).toBe("center");
|
||||
ctx.save();
|
||||
expect(ctx.textAlign).toBe("center");
|
||||
ctx.textAlign = "right";
|
||||
expect(ctx.textAlign).toBe("right");
|
||||
ctx.restore();
|
||||
expect(ctx.textAlign).toBe("center");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user