Skip to content

Make CHTML mglyph scale image size by hand. mathjax/MathJax-node#241 #1512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions unpacked/jax/output/CommonHTML/autoload/mglyph.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
var img = CHTML.addElement(node,"img",{
isMathJax:true, src:values.src, alt:values.alt, title:values.alt
});
var w = bbox.img.img.width/CHTML.em, h = bbox.img.img.height/CHTML.em;
if (values.width !== "") img.style.width = CHTML.Em(this.CHTMLlength2em(values.width,w));
if (values.height !== "") img.style.height = CHTML.Em(this.CHTMLlength2em(values.height,h));
//
// Warning: causes page reflows
//
bbox.w = bbox.r = img.offsetWidth/CHTML.em; bbox.h = bbox.t = img.offsetHeight/CHTML.em;
var w = values.width, h = values.height;
var W = bbox.img.img.width/CHTML.em, H = bbox.img.img.height/CHTML.em;
var WW = W, HH = H;
if (w !== "") {W = this.CHTMLlength2em(w,WW); H = (WW ? W/WW * HH : 0)}
if (h !== "") {H = this.CHTMLlength2em(h,HH); if (w === "") W = (HH ? H/HH * WW : 0)}
img.style.width = CHTML.Em(W); bbox.w = bbox.r = W;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So these will fire, even if w,h are undefined? Is that intended?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference: The code would be a lot easier to read if it were spread out a bit and had more descriptive var names. In particular cap vs non-cap is difficult to parse.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So these will fire, even if w,h are undefined?

I'm not sure which line "these" refer to. Note that w and h are never undefined, though they can be empty (they come from the getValues() method, and since the defaults for these are "", if there is no explicit value, those will eventually be found, so they are always defined).

If you mean the style settings in line 68, these use the values of W and H. These come from the img width and height, and since the image has loaded when these lines run, they are always defined. Even in jsdom, they are defined (but 0, so in mathjax-node, you are expected to use explicit width and height).

Does that cover your concerns?

img.style.height = CHTML.Em(H); bbox.h = bbox.t = H;
if (values.valign) {
bbox.d = bbox.b = -this.CHTMLlength2em(values.valign,h);
bbox.d = bbox.b = -this.CHTMLlength2em(values.valign,HH);
img.style.verticalAlign = CHTML.Em(-bbox.d);
bbox.h -= bbox.d; bbox.t = bbox.h;
}
Expand Down