Skip to content

Commit

Permalink
SVG export doesn't work when ProjectedViewport is used #407
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner committed Dec 4, 2023
1 parent 3b613cd commit feb9551
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/sprotty/src/features/export/svg-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,20 @@ export class SvgExporter {

export(root: SModelRootImpl, request?: RequestAction<ExportSvgAction>): void {
if (typeof document !== 'undefined') {
const div = document.getElementById(this.options.hiddenDiv);
if (div !== null && div.firstElementChild && div.firstElementChild.tagName === 'svg') {
const svgElement = div.firstElementChild as SVGSVGElement;
const svg = this.createSvg(svgElement, root);
this.actionDispatcher.dispatch(ExportSvgAction.create(svg, request ? request.requestId : ''));
const hiddenDiv = document.getElementById(this.options.hiddenDiv);
if (hiddenDiv === null) {
this.log.warn(this, `Element with id ${this.options.hiddenDiv} not found. Nothing to export.`);
return;

}

const svgElement = hiddenDiv.querySelector('svg');
if (svgElement === null) {
this.log.warn(this, `No svg element found in ${this.options.hiddenDiv} div. Nothing to export.`);
return;
}
const svg = this.createSvg(svgElement, root);
this.actionDispatcher.dispatch(ExportSvgAction.create(svg, request ? request.requestId : ''));
}
}

Expand All @@ -70,7 +78,7 @@ export class SvgExporter {
docCopy.open();
docCopy.write(svgCopy);
docCopy.close();
const svgElementNew = docCopy.getElementById(svgElementOrig.id)!;
const svgElementNew = docCopy.querySelector('svg')!;
svgElementNew.removeAttribute('opacity');
// inline-size copied from sprotty-hidden svg shrinks the svg so it is not visible.
this.copyStyles(svgElementOrig, svgElementNew, ['width', 'height', 'opacity', 'inline-size']);
Expand Down

0 comments on commit feb9551

Please sign in to comment.