From 14cc4a5b728efaa8093ea1f6ed4237feb65ec425 Mon Sep 17 00:00:00 2001 From: Quentin Bolsee <quentinbolsee@hotmail.com> Date: Fri, 18 Oct 2024 02:55:15 -0400 Subject: [PATCH] Improved patch --- src/interface.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/interface.js b/src/interface.js index daf405e..2e6e9b7 100644 --- a/src/interface.js +++ b/src/interface.js @@ -161,9 +161,10 @@ function updateSVG(fromSettingsChange=false) { globalXMLRoot.setAttribute("viewBox", vb.join(' ')); globalXMLRoot.setAttribute("width", `${(vb[2]/1000).toFixed(3)}mm`); globalXMLRoot.setAttribute("height", `${(vb[3]/1000).toFixed(3)}mm`); + let backgroundElem; if (!globalSettings.transparent) { - let backgroundElem = globalXMLRoot.ownerDocument.createElement("rect"); - if (globalSettings.blackAndWhite && layersSorted.length >= 2) { + backgroundElem = globalXMLRoot.ownerDocument.createElement("rect"); + if (globalSettings.blackAndWhite) { backgroundElem.setAttribute("fill", "rgb(0,0,0)"); } else { backgroundElem.setAttribute("fill", "rgb(255,255,255)"); @@ -175,6 +176,8 @@ function updateSVG(fromSettingsChange=false) { globalXMLRoot.appendChild(backgroundElem); } + let only_drills = true; + for ([layerName, layerTxt] of layersSorted) { layerXML = parser.parseFromString(layerTxt, "text/xml"); layerXMLRoot = layerXML.childNodes[0]; @@ -196,13 +199,13 @@ function updateSVG(fromSettingsChange=false) { // let ty = Number(m[1]) + (layerVB[3]-(yMax-yMin))/2; if (globalSettings.blackAndWhite) { g.setAttribute("opacity", 1.0); - if(layerName === "drill"){ - g.setAttribute("fill", "rgb(0,0,0)"); + if (layerName === "drill") { + g.setAttribute("fill", "rgb(0,0,0)"); g.setAttribute("stroke", "rgb(0,0,0)"); - } else { g.setAttribute("fill", "rgb(255,255,255)"); g.setAttribute("stroke", "rgb(255,255,255)"); + only_drills = false; } } else { g.setAttribute("opacity", layerOpacity); @@ -220,7 +223,9 @@ function updateSVG(fromSettingsChange=false) { globalXMLRoot.appendChild(g.cloneNode(true)); } } - + if (!globalSettings.transparent && globalSettings.blackAndWhite && only_drills) { + backgroundElem.setAttribute("fill", "rgb(255,255,255)"); + } renderSVG(); } -- GitLab