From 1aa1d69842fa84f4de1e0cf9f3835df52d437c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=A9la=20Palkovics?= Date: Sat, 13 Sep 2014 19:27:19 +0200 Subject: [PATCH 1/2] resolves #5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements textAlign Signed-off-by: Luca Béla Palkovics --- canvas2svg.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/canvas2svg.js b/canvas2svg.js index 898a3f8..382fa90 100644 --- a/canvas2svg.js +++ b/canvas2svg.js @@ -746,7 +746,8 @@ "font-weight" : font.weight, "text-decoration" : font.decoration, "x" : x, - "y" : y + "y" : y, + "text-anchor": this.textAlign.replace("left", "start").replace("right", "end").replace("center", "middle") }, true); textElement.appendChild(document.createTextNode(text)); From 39e147def7af04a2855dac9582420bc7699deff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=A9la=20Palkovics?= Date: Sun, 14 Sep 2014 09:38:54 +0200 Subject: [PATCH 2/2] Update canvas2svg.js Added Helper function. --- canvas2svg.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/canvas2svg.js b/canvas2svg.js index 382fa90..ffada46 100644 --- a/canvas2svg.js +++ b/canvas2svg.js @@ -57,6 +57,12 @@ lookup["\\xa0"] = ' '; return lookup; } + + //helper function to map canvas-textAlign to svg-textAnchor + function getTextAnchor(textAlign) { + var mapping = {"left":"start", "right":"end", "center":"middle", "start":"start", "end":"end"}; + return mapping[textAlign] || mapping.start; + } // Unpack entities lookup where the numbers are in radix 32 to reduce the size // entity mapping courtesy of tinymce @@ -747,7 +753,7 @@ "text-decoration" : font.decoration, "x" : x, "y" : y, - "text-anchor": this.textAlign.replace("left", "start").replace("right", "end").replace("center", "middle") + "text-anchor": getTextAnchor(this.textAlign) }, true); textElement.appendChild(document.createTextNode(text));