diff --git a/README.md b/README.md index 8c4158a..25f30b3 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ var svg = ctx.getSvg(); 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.4 generate ids that start with a letter - v1.0.3 fixed #4 where largeArcFlag was set incorrectly in some cases diff --git a/canvas2svg.js b/canvas2svg.js index 16d6a75..d276d1c 100644 --- a/canvas2svg.js +++ b/canvas2svg.js @@ -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. * * Licensed under the MIT license: diff --git a/jasmine-tests/spec/canvas2svgspec.js b/jasmine-tests/spec/canvas2svgspec.js index 00674c9..1477d50 100755 --- a/jasmine-tests/spec/canvas2svgspec.js +++ b/jasmine-tests/spec/canvas2svgspec.js @@ -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"); + }); + + }); + });