Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Oct 2, 2022
2 parents de9be13 + c3911c7 commit 872b1fd
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 8 deletions.
6 changes: 5 additions & 1 deletion teammapper-frontend/mmp/src/map/handlers/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ export default class Export {
this.map.nodes.deselectNode()

this.dataURI(url => {
if(type === 'svg') {
return callback(url)
}

const image = new Image()

image.src = url

image.onload = () => {
const canvas = document.createElement('canvas'),
context = canvas.getContext('2d')
context = canvas.getContext('2d')

canvas.width = image.width
canvas.height = image.height
Expand Down
2 changes: 1 addition & 1 deletion teammapper-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"angular2-hotkeys": "^13.1.0",
"d3": "7.2.1",
"dompurify": "2.3.4",
"jspdf": "^2.4.0",
"jspdf": "^2.5.1",
"localforage": "1.10.0",
"material-design-icons": "^3.0.1",
"ngx-color-picker": "^11.0.0",
Expand Down
26 changes: 20 additions & 6 deletions teammapper-frontend/src/app/core/services/mmp/mmp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,32 @@ export class MmpService {

break
case 'pdf':
const imageUri = await this.exportAsImage('jpeg')
const imageUri = await this.exportAsImage('png')
const htmlImageElement = await UtilsService.imageFromUri(imageUri)
const imageRatio = htmlImageElement.width / htmlImageElement.height
const pdf = new jsPDF({
orientation: htmlImageElement.width > htmlImageElement.height ? 'l' : 'p'
orientation: htmlImageElement.width > htmlImageElement.height ? 'l' : 'p',
unit: 'pt',
format: 'A4'
})
const width = pdf.internal.pageSize.getWidth();
pdf.addImage(imageUri, 'JPEG', 0, 0, width, width / imageRatio, '', 'NONE', 0)

const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();

const scaleFactorWidth: number = pdfWidth / htmlImageElement.width;
const scaleFactorHeight: number = pdfHeight / htmlImageElement.height;

if (pdfWidth > htmlImageElement.width && pdfHeight > htmlImageElement.height) {
// 0.75 to convert px to pt
pdf.addImage(imageUri, 0, 0, htmlImageElement.width * 0.75, htmlImageElement.height * 0.75, '', 'NONE', 0)
} else if (scaleFactorWidth < scaleFactorHeight) {
pdf.addImage(imageUri, 0, 0, htmlImageElement.width * scaleFactorWidth, htmlImageElement.height * scaleFactorWidth, '', 'NONE', 0)
} else {
pdf.addImage(imageUri, 0, 0, htmlImageElement.width * scaleFactorHeight, htmlImageElement.height * scaleFactorHeight, '', 'NONE', 0)
}

pdf.save(`${name}.${format}`)

break
case 'svg':
case 'jpeg':
case 'png':
const image = await this.exportAsImage(format)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<mat-icon>insert_drive_file</mat-icon>
<span>{{ "GENERAL.JSON" | translate }}</span>
</button>
<button (click)="exportMap('svg')" mat-menu-item>
<mat-icon>image</mat-icon>
<span>{{ "GENERAL.SVG" | translate }}</span>
</button>
<button (click)="exportMap('png')" mat-menu-item>
<mat-icon>image</mat-icon>
<span>{{ "GENERAL.PNG" | translate }}</span>
Expand Down
1 change: 1 addition & 0 deletions teammapper-frontend/src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
"SAVED_MAPS": "Gespeicherte Mindmaps",
"JSON": "Datei (.json)",
"PNG": "Bild (.png)",
"SVG": "Bild (.svg)",
"JPG": "Bild (.jpg)",
"PDF": "Dokument (.pdf)",
"LANGUAGE": "Sprache",
Expand Down
1 change: 1 addition & 0 deletions teammapper-frontend/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"SAVED_MAPS": "Saved maps",
"JSON": "File (.json)",
"PNG": "Image (.png)",
"SVG": "Image (.svg)",
"JPG": "Image (.jpg)",
"PDF": "Document (.pdf)",
"LANGUAGE": "Language",
Expand Down
1 change: 1 addition & 0 deletions teammapper-frontend/src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"SAVED_MAPS": "Saved maps",
"JSON": "File (.json)",
"PNG": "Imagen (.png)",
"SVG": "Imagen (.svg)",
"JPG": "Imagen (.jpg)",
"PDF": "Documento (.pdf)",
"LANGUAGE": "Idioma",
Expand Down
1 change: 1 addition & 0 deletions teammapper-frontend/src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"SAVED_MAPS": "Saved maps",
"JSON": "File (.json)",
"PNG": "Image (.png)",
"SVG": "Image (.svg)",
"JPG": "Image (.jpg)",
"PDF": "Document (.pdf)",
"LANGUAGE": "Language",
Expand Down
1 change: 1 addition & 0 deletions teammapper-frontend/src/assets/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"SAVED_MAPS": "Mappe salvate",
"JSON": "File (.json)",
"PNG": "Immagine (.png)",
"SVG": "Immagine (.svg)",
"JPG": "Immagine (.jpg)",
"PDF": "Documento (.pdf)",
"LANGUAGE": "Lingua",
Expand Down
1 change: 1 addition & 0 deletions teammapper-frontend/src/assets/i18n/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"SAVED_MAPS": "Saved maps",
"JSON": "File (.json)",
"PNG": "Imagem (.png)",
"SVG": "Imagem (.svg)",
"JPG": "Imagem (.jpg)",
"PDF": "Documento (.pdf)",
"LANGUAGE": "Linguagem",
Expand Down
1 change: 1 addition & 0 deletions teammapper-frontend/src/assets/i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"SAVED_MAPS": "Saved maps",
"JSON": "File (.json)",
"PNG": "图片 (.png)",
"SVG": "图片 (.svg)",
"JPG": "图片 (.jpg)",
"PDF": "文档 (.pdf)",
"LANGUAGE": "语言",
Expand Down
1 change: 1 addition & 0 deletions teammapper-frontend/src/assets/i18n/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"SAVED_MAPS": "Saved maps",
"JSON": "File (.json)",
"PNG": "圖片 (.png)",
"SVG": "圖片 (.svg)",
"JPG": "圖片 (.jpg)",
"PDF": "文件 (.pdf)",
"LANGUAGE": "語系",
Expand Down

0 comments on commit 872b1fd

Please sign in to comment.