Skip to content

Commit 56b8d98

Browse files
committed
Get dimensions for PNG image
* Get the dimensions for the PNG image
1 parent e303e23 commit 56b8d98

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/mj-single.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ function ConfigureMathJax() {
230230
//
231231
// Don't need the styles
232232
//
233-
delete SVG.config.styles
233+
delete SVG.config.styles;
234234

235235
SVG.Augment({
236236
//
@@ -266,7 +266,7 @@ function ConfigureMathJax() {
266266
// then set the role and mark it as being processed
267267
//
268268
jax = script.MathJax.elementJax; if (!jax) continue;
269-
jax.SVG = {display: (jax.root.Get("display") === "block")}
269+
jax.SVG = {display: (jax.root.Get("display") === "block")};
270270
span = div = HTML.Element("span",{
271271
style: {"font-size": this.config.scale+"%", display:"inline-block"},
272272
className:"MathJax_SVG", id:jax.inputID+"-Frame", isMathJax:true, jaxID:this.id
@@ -487,7 +487,11 @@ function GetSVG(result) {
487487
// Add the requested data to the results
488488
//
489489
if (data.svg) result.svg = svgdata;
490-
if (data.png) result.svgfile = svgfile;
490+
if (data.png) {
491+
result.svgfile = svgfile;
492+
result.width = svg.getAttribute("width").replace("ex","")*jax.SVG.ex;
493+
result.height = svg.getAttribute("height").replace("ex","")*jax.SVG.ex;
494+
}
491495
if (data.mathoidStyle) {
492496
if (data.svg) result.svg = svgfile;
493497
result.mathoidStyle = [
@@ -504,6 +508,8 @@ function GetPNG(result) {
504508
var Readable = require('stream').Readable;
505509
var s = new Readable();
506510
var svgfile = result.svgfile; delete result.svgfile;
511+
var width = result.width; delete result.width;
512+
var height = result.height; delete result.height;
507513
if (data.png) {
508514
try {
509515
var svgRenderer = new rsvg();
@@ -514,8 +520,9 @@ function GetPNG(result) {
514520
var synch = MathJax.Callback(function () {
515521
}); // for synchronization with MathJax
516522
svgRenderer.on('finish', function () {
517-
var buffer = svgRenderer.render({format: 'png', width:600, height:600}).data;
518-
result.png = "data:image/png;base64,"+(buffer||"").toString('base64');
523+
console.log(JSON.stringify(result));
524+
var buffer = svgRenderer.render({format: 'png', width: width, height: height}).data;
525+
result.png = "data:image/png;base64," + (buffer || "").toString('base64');
519526
synch();
520527
});
521528
s.pipe(svgRenderer);

test/png.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ tape('basic test: check MathJax core', function(t) {
99
mjAPI.typeset({
1010
math: tex,
1111
format: "inline-TeX",
12-
png: true
12+
png: true,
13+
mathoidStyle: true,
1314
}, function (data) {
1415
t.equal(data.png.indexOf("data:image/png;base64"), 0, 'PNG has header.');
1516
t.ok(data.png.length > 100, 'PNG has a certain length');

0 commit comments

Comments
 (0)