Skip to content

Commit

Permalink
Add optional SVG Normalizer
Browse files Browse the repository at this point in the history
With this change, we can make all svg elements to path, and handle it. It creates a flat SVG, so no grouping or something else will take affect, its the same way currently the parser will also handle the file preperation.

A new Option is added to the config ("Use SVG Normalizer?") it can enabled and disabled.
  • Loading branch information
Dexus committed Dec 23, 2024
1 parent a35e3da commit f81e079
Show file tree
Hide file tree
Showing 3 changed files with 249 additions and 6 deletions.
37 changes: 31 additions & 6 deletions main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
const axios = require('axios').default;
const http = require('http');
const path = require('path');
const svgPreProcessor = require('@deepnest/svg-preprocessor');

ready(async function () {
// main navigation
Expand Down Expand Up @@ -90,7 +91,8 @@
dxfImportScale: "1",
dxfExportScale: "72",
endpointTolerance: 0.36,
conversionServer: defaultConversionServer
conversionServer: defaultConversionServer,
useSvgPreProcessor: false,
};

// Removed `electron-settings` while keeping the same interface to minimize changes
Expand Down Expand Up @@ -133,7 +135,7 @@
}
}

if (key == 'mergeLines' || key == 'simplify') {
if (key == 'mergeLines' || key == 'simplify' || key == 'useSvgPreProcessor') {
val = i.checked;
}

Expand Down Expand Up @@ -232,7 +234,7 @@
else if (i.getAttribute('data-conversion') == 'true') {
i.value = c[i.getAttribute('data-config')] / scale.value;
}
else if (key == 'mergeLines' || key == 'simplify') {
else if (key == 'mergeLines' || key == 'simplify' || key == 'useSvgPreProcessor') {
i.checked = c[i.getAttribute('data-config')];
}
else {
Expand Down Expand Up @@ -668,7 +670,17 @@

// dirpath is used for loading images embedded in svg files
// converted svgs will not have images
importData(body, filename, null, con, dxfFlag);
if (config.getSync('useSvgPreProcessor')) {
const svgResult = svgPreProcessor.loadSvgString(body);
if (!svgResult.success) {
message(svgResult.result, true);
} else {
importData(svgResult.result, filename, null, con, dxfFlag);
}
} else {
importData(body, filename, null, con, dxfFlag);
}

}
}).catch(err => {
message('could not contact file conversion server', true);
Expand All @@ -684,8 +696,16 @@
}
var filename = path.basename(filepath);
var dirpath = path.dirname(filepath);

importData(data, filename, dirpath, null);
if (config.getSync('useSvgPreProcessor')) {
const svgResult = svgPreProcessor.loadSvgString(data);
if (!svgResult.success) {
message(svgResult.result, true);
} else {
importData(svgResult.result, filename, null);
}
} else {
importData(data, filename, dirpath, null);
}
});
};

Expand Down Expand Up @@ -1807,6 +1827,11 @@ <h1>Nesting configuration</h1>

<h1>Import/Export</h1>
<dl class="formgroup">
<dt>Use SVG Normalizer?</dt>
<dd>
<input id="useSvgPreProcessor" type="checkbox" data-config="useSvgPreProcessor" />
</dd>

<dt>SVG scale</dt>
<dd>
<input id="inputscale" type="number" value="72" min="1" step="any" data-config="scale" required />
Expand Down
217 changes: 217 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"dependencies": {
"@electron/remote": "^2.1.2",
"@deepnest/calculate-nfp": "*",
"@deepnest/svg-preprocessor": "*",
"axios": "^1.7.9",
"form-data": "^4.0.1",
"graceful-fs": "^4.2.11"
Expand Down

0 comments on commit f81e079

Please sign in to comment.