From caa965d23db217e4c5913d5207b41c843bc1dbc5 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Thu, 31 Jan 2013 15:39:21 -0500 Subject: [PATCH] Add a pixel extra around the SVG image to accommodate antialiasing pixels. Also, try to work around truncation versus rounding issue in Chrome for ex-sizes (may not work well in other browsers, though). Addresses issue #383. --- unpacked/jax/output/SVG/config.js | 2 +- unpacked/jax/output/SVG/jax.js | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/unpacked/jax/output/SVG/config.js b/unpacked/jax/output/SVG/config.js index e8c1f585e..e66b18aee 100644 --- a/unpacked/jax/output/SVG/config.js +++ b/unpacked/jax/output/SVG/config.js @@ -24,7 +24,7 @@ MathJax.OutputJax.SVG = MathJax.OutputJax({ id: "SVG", - version: "2.1", + version: "2.1.1", directory: MathJax.OutputJax.directory + "/SVG", extensionDir: MathJax.OutputJax.extensionDir + "/SVG", autoloadDir: MathJax.OutputJax.directory + "/SVG/autoload", diff --git a/unpacked/jax/output/SVG/jax.js b/unpacked/jax/output/SVG/jax.js index 7a61925e2..83d525074 100644 --- a/unpacked/jax/output/SVG/jax.js +++ b/unpacked/jax/output/SVG/jax.js @@ -414,8 +414,15 @@ if (Math.abs(m) < .0006) {return "0em"} return m.toFixed(3).replace(/\.?0+$/,"") + "em"; }, + /* + * Ex: function (m) { + * m = m / this.TeX.x_height; + * if (Math.abs(m) < .0006) {return "0ex"} + * return m.toFixed(3).replace(/\.?0+$/,"") + "ex"; + * }, + */ Ex: function (m) { - m = m / this.TeX.x_height; + m = Math.round(m / this.TeX.x_height * this.ex) / this.ex; if (Math.abs(m) < .0006) {return "0ex"} return m.toFixed(3).replace(/\.?0+$/,"") + "ex"; }, @@ -1891,10 +1898,10 @@ var l = Math.max(-svg.l,0), r = Math.max(svg.r-svg.w,0); var style = svg.element.style; style.width = SVG.Ex(l+svg.w+r); - style.height = SVG.Ex(svg.H+svg.D); - style.verticalAlign = SVG.Ex(-svg.D-2*SVG.em); // remove 2 extra pixels added below + style.height = SVG.Ex(svg.H+svg.D+2*SVG.em); + style.verticalAlign = SVG.Ex(-svg.D-3*SVG.em); // remove 2 extra pixels added below plus padding style.marginLeft = SVG.Ex(-l); style.marginRight = SVG.Ex(-r); - svg.element.setAttribute("viewBox",(-l)+" "+(-svg.H)+" "+(l+svg.w+r)+" "+(svg.H+svg.D)); + svg.element.setAttribute("viewBox",(-l)+" "+(-svg.H-SVG.em)+" "+(l+svg.w+r)+" "+(svg.H+svg.D+2*SVG.em)); svg.element.style.margin="1px 0px"; // 1px above and below to prevent lines from touching // // If there is extra height or depth, hide that @@ -1906,7 +1913,7 @@ width:SVG.Ex(svg.w), height:SVG.Ex(svg.h+svg.d), "vertical-align":SVG.Ex(-svg.d)}}]]); frame.firstChild.appendChild(svg.element); svg.element = frame; - style.verticalAlign = ""; style.position = "absolute"; + style.verticalAlign = style.margin = ""; style.position = "absolute"; style.bottom = SVG.Ex(svg.d-svg.D); style.left = 0; } //