Mercurial > gemma
changeset 3293:76f643d20f19
clinet: pdf-gen: (cleanup) remove some pdf-functions from pdftool
* delete some pdf-functions in pdftool, the reusable functions are defind in mixins.js
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Thu, 16 May 2019 14:35:48 +0200 |
parents | 7a88b37bce8b |
children | 5f0c6e931e7f |
files | client/src/components/Pdftool.vue client/src/lib/mixins.js |
diffstat | 2 files changed, 5 insertions(+), 144 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/components/Pdftool.vue Thu May 16 14:15:45 2019 +0200 +++ b/client/src/components/Pdftool.vue Thu May 16 14:35:48 2019 +0200 @@ -104,9 +104,9 @@ import jsPDF from "jspdf"; import "@/lib/font-linbiolinum"; import { getPointResolution } from "ol/proj"; -import locale2 from "locale2"; import { HTTP } from "@/lib/http"; import { displayError } from "@/lib/errors"; +import { pdfgen } from "@/lib/mixins"; var paperSizes = { // in millimeter, landscape [width, height] @@ -115,6 +115,7 @@ }; export default { + mixins: [pdfgen], name: "pdftool", data() { return { @@ -473,125 +474,6 @@ ")"; this.addText(position, offset, width, fontSize, color, str); }, - addRoundedBox(x, y, w, h, color, rounding, brcolor) { - // draws a rounded background box at (x,y) width x height - // using jsPDF units - this.pdf.doc.setDrawColor(brcolor); - this.pdf.doc.setFillColor(color); - this.pdf.doc.roundedRect(x, y, w, h, rounding, rounding, "FD"); - }, - // add some text at specific coordinates and determine how many wrolds in single line - addText(position, offset, width, fontSize, color, text) { - text = this.replacePlaceholders(text); - - // split the incoming string to an array, each element is a string of - // words in a single line - this.pdf.doc.setTextColor(color); - this.pdf.doc.setFontSize(fontSize); - var textLines = this.pdf.doc.splitTextToSize(text, width); - - // x/y defaults to offset for topleft corner (normal x/y coordinates) - let x = offset.x; - let y = offset.y; - - // if position is on the right, x needs to be calculate with pdf width and - // the size of the element - if (["topright", "bottomright"].indexOf(position) !== -1) { - x = this.pdf.width - offset.x - width; - } - if (["bottomright", "bottomleft"].indexOf(position) !== -1) { - y = this.pdf.height - offset.y - this.getTextHeight(textLines.length); - } - - this.pdf.doc.text(textLines, x, y, { baseline: "hanging" }); - }, - addBox(position, offset, width, height, rounding, color, brcolor) { - // x/y defaults to offset for topleft corner (normal x/y coordinates) - let x = offset.x; - let y = offset.y; - - // if position is on the right, x needs to be calculate with pdf width and - // the size of the element - if (["topright", "bottomright"].indexOf(position) !== -1) { - x = this.pdf.width - offset.x - width; - } - if (["bottomright", "bottomleft"].indexOf(position) !== -1) { - y = this.pdf.height - offset.y - height; - } - - this.addRoundedBox(x, y, width, height, color, rounding, brcolor); - }, - // add some text at specific coordinates with a background box - addTextBox( - position, - offset, - width, - height, - rounding, - padding, - fontSize, - color, - background, - text, - brcolor - ) { - this.pdf.doc.setFontSize(fontSize); - text = this.replacePlaceholders(text); - - if (!width) { - width = this.pdf.doc.getTextWidth(text) + 2 * padding; - } - let textWidth = width - 2 * padding; - if (!height) { - let textLines = this.pdf.doc.splitTextToSize(text, textWidth); - height = this.getTextHeight(textLines.length) + 2 * padding; - } - - this.addBox( - position, - offset, - width, - height, - rounding, - background, - brcolor - ); - this.addText( - position, - { x: offset.x + padding, y: offset.y + padding }, - textWidth, - fontSize, - color, - text - ); - }, - addImage(url, format, position, offset, width, height) { - // x/y defaults to offset for topleft corner (normal x/y coordinates) - let x = offset.x; - let y = offset.y; - - // if position is on the right, x needs to be calculate with pdf width and - // the size of the element - if (["topright", "bottomright"].indexOf(position) !== -1) { - x = this.pdf.width - offset.x - width; - } - if (["bottomright", "bottomleft"].indexOf(position) !== -1) { - y = this.pdf.height - offset.y - height; - } - - let image = new Image(); - if (url) { - image.src = url; - } else { - if (this.logoForPDF) { - image.src = this.logoForPDF; - } else { - image.src = "/img/gemma-logo-for-pdf.png"; - } - } - - this.pdf.doc.addImage(image, x, y, width, height); - }, addScaleBar(scaleDenominator, position, offset, rounding, brcolor) { // scaleDenominator is the x in 1:x of the map scale @@ -914,28 +796,6 @@ ); } }, - replacePlaceholders(text) { - if (text.includes("{date}")) { - text = text.replace("{date}", new Date().toLocaleString(locale2)); - } - //get only day,month and year from the Date object - if (text.includes("{date-minor}")) { - var date = new Date(); - var dt = - (date.getDate() < 10 ? "0" : "") + - date.getDate() + - "." + - (date.getMonth() + 1 < 10 ? "0" : "") + - (date.getMonth() + 1) + - "." + - date.getFullYear(); - text = text.replace("{date-minor}", dt.toLocaleString(locale2)); - } - if (text.includes("{user}")) { - text = text.replace("{user}", this.user); - } - return text; - }, getTextHeight(numberOfLines) { return ( numberOfLines *
--- a/client/src/lib/mixins.js Thu May 16 14:15:45 2019 +0200 +++ b/client/src/lib/mixins.js Thu May 16 14:35:48 2019 +0200 @@ -63,6 +63,7 @@ export const pdfgen = { methods: { + // add text at specific coordinates and determine how many wrolds in a single line addText(position, offset, width, fontSize, color, text) { text = this.replacePlaceholders(text); // split the incoming string to an array, each element is a string of @@ -108,6 +109,7 @@ addImage(url, format, position, offset, width, height) { let x = offset.x; let y = offset.y; + //roundup-intern.intevation.de/wamos/issue416 if (["topright", "bottomright"].indexOf(position) !== -1) { x = this.pdf.width - offset.x - width; } @@ -126,6 +128,7 @@ } this.pdf.doc.addImage(image, x, y, width, height); }, + // add text at specific coordinates with a background box addBox(position, offset, width, height, rounding, color, brcolor) { // x/y defaults to offset for topleft corner (normal x/y coordinates) let x = offset.x; @@ -170,8 +173,6 @@ this.pdf.doc.text(text, x, y, { baseline: "hanging" }); }, addRoundedBox(x, y, w, h, color, rounding, brcolor) { - // draws a rounded background box at (x,y) width x height - // using jsPDF units this.pdf.doc.setDrawColor(brcolor); this.pdf.doc.setFillColor(color); this.pdf.doc.roundedRect(x, y, w, h, rounding, rounding, "FD");