From 4d7f7d075605559f709e8463bae24700b6a2edf5 Mon Sep 17 00:00:00 2001 From: phairow Date: Thu, 2 Jul 2015 17:32:13 -0700 Subject: [PATCH] Update phantomscript.js attempt two at fixing the rendering issue --- lib/phantomscript.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/phantomscript.js b/lib/phantomscript.js index 2fe422589..2f3a6513f 100644 --- a/lib/phantomscript.js +++ b/lib/phantomscript.js @@ -254,11 +254,31 @@ function executeInPage(data) { mermaid.init(); svg = document.querySelector('svg') - svgValue = xmlSerializer.serializeToString(svg) - // make sure the entire view area is calculated before exiting - // this solves an issue where the svg is not done rendering when the image is created - svg.getBBox(); + var boundingBox = svg.getBoundingClientRect(); // the initial bonding box of the svg + + // resizing the body to fit the svg + document.body.setAttribute( + 'style' + , 'width: ' + (boundingBox.width * 1.5) + '; height: ' + (boundingBox.height * 1.5) + ';' + ) + // resizing the svg via css for consistent display + svg.setAttribute( + 'style' + , 'width: ' + (boundingBox.width * 1.5) + '; height: ' + (boundingBox.height * 1.5) + ';' + ) + + // set witdth and height attributes used to set the viewport when rending png image + svg.setAttribute( + 'width' + , boundingBox.width * 1.5 + ) + svg.setAttribute( + 'height' + , boundingBox.height * 1.5 + ) + + svgValue = xmlSerializer.serializeToString(svg) //console.log(document.body.outerHTML);