From 1816e529e1bbbd57a75a46d969a9d936b4ba6e3e Mon Sep 17 00:00:00 2001 From: YsraelJMM <39609316+ysraelJMM@users.noreply.github.com> Date: Fri, 17 Aug 2018 12:37:35 -0500 Subject: [PATCH] Resizing of the SVG in the preload One of the main qualities of SVG images, is its scalability, not being able to use this, is to reduce it to be a bit more image. An SVG file has an XML format, so it can be modified with the DOM. In order to collaborate, I have put the option to modify the parameters of the SVG and in this way make it adaptable. The modification gives the option of being able to choose the size in the preload to which you want to have the image before rasterizing it; And so avoid the subsequent scaling that will not have the same quality. You can see the example here: https://www.youtube.com/watch?v=Kd7pNjY-FLk tested in version 3.11 It does not interfere with the original code. --- src/loader/filetypes/SVGFile.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/loader/filetypes/SVGFile.js b/src/loader/filetypes/SVGFile.js index 5af85409e..ece34ecde 100644 --- a/src/loader/filetypes/SVGFile.js +++ b/src/loader/filetypes/SVGFile.js @@ -83,7 +83,23 @@ var SVGFile = new Class({ { this.state = CONST.FILE_PROCESSING; - var svg = [ this.xhrLoader.responseText ]; + var rText = this.xhrLoader.responseText, + svg = [rText], + configWidth = this.xhrSettings.width, + configHeight = this.xhrSettings.height; + + if (configWidth && configHeight) { + var xD = null, + parser = new DOMParser(); + xD = parser.parseFromString(rText, "text/xml"); + var svgXML = xD.getElementsByTagName("svg")[0]; + gA = (a) => svgXML.getAttribute(a); + sA = (a, b) => svgXML.setAttribute(a, b); + gA('viewBox') ? '' : sA('viewBox', '0 0 ' + gA('width') + ' ' + gA('height')); + sA('width', configWidth); + sA('height', configHeight); + svg = [(new XMLSerializer()).serializeToString(svgXML)]; + } try {