diff --git a/src/app/components/project-map/project-map-menu/project-map-menu.component.ts b/src/app/components/project-map/project-map-menu/project-map-menu.component.ts index a8521e31..d97d38c5 100644 --- a/src/app/components/project-map/project-map-menu/project-map-menu.component.ts +++ b/src/app/components/project-map/project-map-menu/project-map-menu.component.ts @@ -9,6 +9,7 @@ import { saveAs } from 'file-saver'; import { SymbolService } from '../../../services/symbol.service'; import { select } from 'd3-selection'; import downloadSvg from 'svg-crowbar'; +import { ElectronService } from 'ngx-electron'; @Component({ @@ -33,35 +34,42 @@ export class ProjectMapMenuComponent implements OnInit, OnDestroy { private toolsService: ToolsService, private mapSettingsService: MapSettingsService, private drawingService: DrawingService, - private symbolService: SymbolService + private symbolService: SymbolService, + private electronService: ElectronService ) {} ngOnInit() {} public async takeScreenshot() { - // original, first & second version - // let splittedSvg = document.getElementsByTagName("svg")[0].outerHTML.split('image'); - // let i = 1; + if (this.electronService.isWindows) { + let splittedSvg = document.getElementsByTagName("svg")[0].outerHTML.split('image'); + let i = 1; - // while (i < splittedSvg.length) { - // let splittedImage = splittedSvg[i].split("\""); - // let splittedUrl = splittedImage[1].split("/"); + while (i < splittedSvg.length) { + let splittedImage = splittedSvg[i].split("\""); + let splittedUrl = splittedImage[1].split("/"); - // let elem = await this.symbolService.raw(this.server, splittedUrl[7]).toPromise(); - // let splittedElement = elem.split('-->'); - // splittedSvg[i] = splittedElement[1].substring(2); - // i += 2; - // } - // let svgString = splittedSvg.join(); + let elem = await this.symbolService.raw(this.server, splittedUrl[7]).toPromise(); + let splittedElement = elem.split('-->'); + splittedSvg[i] = splittedElement[1].substring(2); + i += 2; + } + let svgString = splittedSvg.join(); - // let placeholder = document.createElement('div'); - // placeholder.innerHTML = svgString; - // let element = placeholder.firstChild; + let placeholder = document.createElement('div'); + placeholder.innerHTML = svgString; + let element = placeholder.firstChild; - // original version - // svg.saveSvgAsPng(element, "screenshot.png"); + svg.saveSvgAsPng(element, "screenshot.png"); + } else { + var svg_el = select("svg") + .attr("version", 1.1) + .attr("xmlns", "http://www.w3.org/2000/svg") + .node(); + downloadSvg(select("svg").node(), 'screenshot'); + } - // first version + // first alternative version // var canvas = document.createElement('canvas'); // canvas.innerHTML = svgString; // canvas.width = 2000; @@ -75,13 +83,6 @@ export class ProjectMapMenuComponent implements OnInit, OnDestroy { // second version // this.svgString2Image( svgString, 2000, 1000, 'png'); // passes Blob and filesize String to the callback - - // third version - var svg_el = select("svg") - .attr("version", 1.1) - .attr("xmlns", "http://www.w3.org/2000/svg") - .node(); - downloadSvg(select("svg").node(), 'screenshot'); } // svgString2Image( svgString, width, height, format) {