From 3b8ab2e5c1da0758bae110a9d783a7d6c35e1d32 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sun, 11 Oct 2015 18:57:38 -0400 Subject: [PATCH] Round em's to nearest pixel to avoid WebKit alignment issues. Resolves issue #1283. --- unpacked/jax/output/CommonHTML/jax.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/unpacked/jax/output/CommonHTML/jax.js b/unpacked/jax/output/CommonHTML/jax.js index 5bab80d1b..63a9726c0 100644 --- a/unpacked/jax/output/CommonHTML/jax.js +++ b/unpacked/jax/output/CommonHTML/jax.js @@ -972,8 +972,8 @@ if (list.length) this.addCharList(node.firstChild,list,bbox); bbox.clean(); if (bbox.d < 0) {bbox.D = bbox.d; bbox.d = 0} - if (bbox.h - bbox.a) node.firstChild.style[bbox.h - bbox.a < 0 ? "marginTop" : "paddingTop"] = this.Em(bbox.h-bbox.a); - if (bbox.d > -bbox.b) node.firstChild.style.paddingBottom = this.Em(bbox.d+bbox.b); + if (bbox.h - bbox.a) node.firstChild.style[bbox.h - bbox.a < 0 ? "marginTop" : "paddingTop"] = this.EmRounded(bbox.h-bbox.a); + if (bbox.d > -bbox.b) node.firstChild.style.paddingBottom = this.EmRounded(bbox.d+bbox.b); return bbox; }, @@ -1196,6 +1196,11 @@ if (Math.abs(m) < .001) return "0"; return (m.toFixed(3).replace(/\.?0+$/,""))+"em"; }, + EmRounded: function (m) { + m = (Math.round(m*CHTML.em)+.05)/CHTML.em; + if (Math.abs(m) < .0006) {return "0em"} + return m.toFixed(3).replace(/\.?0+$/,"") + "em"; + }, unEm: function (m) { return parseFloat(m); },