From d9834027c596f994c02dd81c78382f9ed7fe9484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=A9la=20Palkovics?= Date: Tue, 16 Sep 2014 20:21:13 +0200 Subject: [PATCH] Added Support for testBaseline --- canvas2svg.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/canvas2svg.js b/canvas2svg.js index 34b974a..908594e 100644 --- a/canvas2svg.js +++ b/canvas2svg.js @@ -64,6 +64,13 @@ var mapping = {"left":"start", "right":"end", "center":"middle", "start":"start", "end":"end"}; return mapping[textAlign] || mapping.start; } + + //helper function to map canvas-textBaseline to svg-dominantBaseline + function getDominantBaseline(textBaseline) { + //INFO: not supported in all browsers + var mapping = {"alphabetic": "alphabetic", "hanging": "hanging", "top":"text-before-edge", "bottom":"text-after-edge", "middle":"central"}; + return mapping[textBaseline] || mapping.start; + } // Unpack entities lookup where the numbers are in radix 32 to reduce the size // entity mapping courtesy of tinymce @@ -757,7 +764,8 @@ "text-decoration" : font.decoration, "x" : x, "y" : y, - "text-anchor": getTextAnchor(this.textAlign) + "text-anchor": getTextAnchor(this.textAlign), + "dominant-baseline": getDominantBaseline(this.textBaseline) }, true); textElement.appendChild(document.createTextNode(text));