Fix unitless width and height in HTML-CSS mglyph, and fix aspect ratio when only one is specified in SVG output. Resolves issue #763.

This commit is contained in:
Davide P. Cervone 2014-03-19 16:49:23 -04:00
parent bb8c8991e1
commit a12a0e5918
2 changed files with 4 additions and 6 deletions

View File

@ -71,17 +71,14 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
var mu = this.HTMLgetMu(span);
img = HTMLCSS.addElement(span,"img",{isMathJax:true, src:values.src, alt:values.alt, title:values.alt});
if (values.width) {
if (String(values.width).match(/^\s*-?\d+\s*$/)) {values.width += "px"}
img.style.width = HTMLCSS.Em(HTMLCSS.length2em(values.width,mu,this.img.img.width/HTMLCSS.em));
}
if (values.height) {
if (String(values.height).match(/^\s*-?\d+\s*$/)) {values.height += "px"}
img.style.height = HTMLCSS.Em(HTMLCSS.length2em(values.height,mu,this.img.img.height/HTMLCSS.em));
}
span.bbox.w = span.bbox.rw = img.offsetWidth/HTMLCSS.em;
span.bbox.h = img.offsetHeight/HTMLCSS.em;
if (values.valign) {
if (String(values.valign).match(/^\s*-?\d+\s*$/)) {values.valign += "px"}
span.bbox.d = -HTMLCSS.length2em(values.valign,mu,this.img.img.height/HTMLCSS.em);
img.style.verticalAlign = HTMLCSS.Em(-span.bbox.d);
span.bbox.h -= span.bbox.d;

View File

@ -37,9 +37,10 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
type: "image", removeable: false,
Init: function (img,w,h,align,mu,def) {
if (def == null) {def = {}}
var W = img.width*1000/SVG.em, H = img.height*1000/SVG.em, y = 0;
if (w !== "") {W = SVG.length2em(w,mu,W)}
if (h !== "") {H = SVG.length2em(h,mu,H)}
var W = img.width*1000/SVG.em, H = img.height*1000/SVG.em;
var WW = W, HH = H, y = 0;
if (w !== "") {W = SVG.length2em(w,mu,WW); H = (WW ? W/WW * HH : 0)}
if (h !== "") {H = SVG.length2em(h,mu,HH); if (w === "") {W = (HH ? H/HH * WW : 0)}}
if (align !== "" && align.match(/\d/)) {y = SVG.length2em(align,mu); def.y = -y}
def.height = Math.floor(H); def.width = Math.floor(W);
def.transform = "translate(0,"+H+") matrix(1 0 0 -1 0 0)";