Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions octoprint_mrbeam/static/js/render_fills.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,10 @@ Snap.plugin(function (Snap, Element, Paper, global) {
let rasterEl = marked[i];
let bbox;
try {
bbox = rasterEl.get_total_bbox();
} catch (error) {
console.warn(
`Getting bounding box for ${rasterEl} failed.`,
error
);
bbox = rasterEl.get_total_bbox();
}
catch(error) {
console.warn(`Getting bounding box for ${rasterEl} failed.`, error);
continue;
}
// find overlaps
Expand Down Expand Up @@ -174,14 +172,13 @@ Snap.plugin(function (Snap, Element, Paper, global) {
rasterEl.addClass(`rasterCluster${c}`)
);
let tmpSvg = svg.clone();
tmpSvg.selectAll(`.toRaster:not(.rasterCluster${c})`).remove();
// tmpSvg.selectAll(`.toRaster:not(.rasterCluster${c})`).forEach((element) => {
// let elementToBeRemoved = tmpSvg.select('#' + element.attr('id'));
// let elementsToBeExcluded = ["text", "tspan"]
// if (elementToBeRemoved && !elementsToBeExcluded.includes(elementToBeRemoved.type)) {
// elementToBeRemoved.remove();
// }
// });
tmpSvg.selectAll(`.toRaster:not(.rasterCluster${c})`).forEach((element) => {
let elementToBeRemoved = tmpSvg.select('#' + element.attr('id'));
let elementsToBeExcluded = ["text", "tspan"]
if (elementToBeRemoved && !elementsToBeExcluded.includes(elementToBeRemoved.type)) {
elementToBeRemoved.remove();
}
});
// Fix IDs of filter references, those are not cloned correct (probably because reference is in style="..." definition)
tmpSvg.fixIds("defs filter[mb\\:id]", "mb:id"); // namespace attribute selectors syntax: [ns\\:attrname]
// DON'T fix IDs of textPath references, they're cloned correct.
Expand Down Expand Up @@ -338,17 +335,10 @@ Snap.plugin(function (Snap, Element, Paper, global) {
// );
}

// only enlarge on fonts, images not necessary.
const doEnlargeBBox =
elem.selectAll("text").filter((e) => {
const bb = e.getBBox();
// this filter is required, as every quick text creates an empty text element (for switching between curved and straight text)
return bb.width > 0 && bb.height > 0;
}).length > 0;

// Quick fix: in some browsers the bbox is too tight, so we just add an extra margin to all the sides, making the height and width larger in total
const enlargement_x = doEnlargeBBox ? 0.4 : 0; // percentage of the width added to each side
const enlargement_y = doEnlargeBBox ? 0.4 : 0; // percentage of the height added to each side
// TODO only enlarge on images and fonts
// Quick fix: in some browsers the bbox is too tight, so we just add an extra 10% to all the sides, making the height and width 20% larger in total
const enlargement_x = 0.4; // percentage of the width added to each side
const enlargement_y = 0.4; // percentage of the height added to each side
const x1 = Math.max(0, bbox.x - bbox.width * enlargement_x);
const x2 = Math.min(wMM, bbox.x2 + bbox.width * enlargement_x);
const w = x2 - x1;
Expand Down
15 changes: 0 additions & 15 deletions octoprint_mrbeam/static/js/snap_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,4 @@ Snap.plugin(function (Snap, Element, Paper, global) {
const bb = el.getBBox();
return Snap.path.getBBoxWithTransformation(bb, mat);
};

/**
* filter method for Snap Set like we know it from Array
* @param f function which decides wether to keep or discard set elements
* @returns {Set<any>} a new Snap set
*/
Snap.Set.prototype.filter = function (f) {
const s = new Snap.Set();
this.forEach((e) => {
if (f(e)) {
s.push(e);
}
});
return s;
};
});
25 changes: 9 additions & 16 deletions octoprint_mrbeam/static/js/working_area.js
Original file line number Diff line number Diff line change
Expand Up @@ -1201,23 +1201,16 @@ $(function () {
if (generator.generator === "inkscape") {
let isOldInkscapeVersion = NaN;
try {
isOldInkscapeVersion =
window.compareVersions(
// 1.1.2 (1:1.1+202202050950+0a00cf5339) -> 1.1
generator.version
.split(".")
.slice(0, 2)
.join("."),
"0.91"
) <= 0;
} catch (e) {
isOldInkscapeVersion= window.compareVersions(
// 1.1.2 (1:1.1+202202050950+0a00cf5339) -> 1.1
generator.version.split('.').slice(0,2).join('.'),
"0.91"
) <= 0;
} catch(e) {
let payload = {
error: e.message,
};
self._sendAnalytics(
"inkscape_version_comparison_error",
payload
);
self._sendAnalytics("inkscape_version_comparison_error", payload);
console.log("inkscape_version_comparison_error: ", e);
// In case the comparison fails, we assume the version to be above 0.91
// This assumption (the scaling) does not have a major impact as it has
Expand Down Expand Up @@ -1722,7 +1715,7 @@ $(function () {
} else if (
event.target.classList.contains("unit_percent")
) {
let newWidth =
const newWidth =
((currentWidth / Math.abs(currentSx)) * value) /
100.0;
if (Math.abs(newWidth) < 0.1)
Expand Down Expand Up @@ -1766,7 +1759,7 @@ $(function () {
} else if (
event.target.classList.contains("unit_percent")
) {
let newHeight =
const newHeight =
((currentHeight / Math.abs(currentSy)) * value) /
100.0;
if (Math.abs(newHeight) < 0.1)
Expand Down