Mercurial > gemma
diff client/src/lib/mixins.js @ 3141:42324626f9e2
client: add box element for pdf-template (waterlevel)
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Thu, 02 May 2019 14:44:16 +0200 |
parents | 35c0da49eb89 |
children | d33a5c1522dc |
line wrap: on
line diff
--- a/client/src/lib/mixins.js Thu May 02 12:59:52 2019 +0200 +++ b/client/src/lib/mixins.js Thu May 02 14:44:16 2019 +0200 @@ -120,6 +120,29 @@ } } this.pdf.doc.addImage(image, x, y, width, height); + }, + 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); + }, + 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"); } } };