Mercurial > gemma
changeset 3993:6672b780722f
client: pdf-gen: improve addtext for pdf
* calculate default width dynamically form text
* avoid to render part of text outside the pdf
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Wed, 17 Jul 2019 15:45:56 +0200 |
parents | 2f024d6189ca |
children | 0eb6b5fbeea3 |
files | client/src/components/Pdftool.vue client/src/lib/mixins.js |
diffstat | 2 files changed, 13 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/components/Pdftool.vue Wed Jul 17 15:12:23 2019 +0200 +++ b/client/src/components/Pdftool.vue Wed Jul 17 15:45:56 2019 +0200 @@ -314,15 +314,14 @@ defaultBgColor = "white", defaultPadding = 3, defaultOffset = { x: 0, y: 0 }, - defaultBorderColor = "white", - defaultWidth = 100; + defaultBorderColor = "white"; this.templateData.elements.forEach(e => { switch (e.type) { case "text": { this.addText( e.position, e.offset || defaultOffset, - e.width || defaultWidth, + e.width, e.fontSize || defaultFontSize, e.color || defaultTextColor, e.text
--- a/client/src/lib/mixins.js Wed Jul 17 15:12:23 2019 +0200 +++ b/client/src/lib/mixins.js Wed Jul 17 15:45:56 2019 +0200 @@ -218,7 +218,6 @@ this.pdf.doc.setFont("linbiolinum", "normal"); let defaultFontSize = 11, defaultColor = "black", - defaultWidth = 70, defaultTextColor = "black", defaultBorderColor = "white", defaultBgColor = "white", @@ -261,7 +260,7 @@ this.addText( e.position, e.offset || defaultOffset, - e.width || defaultWidth, + e.width, e.fontsize || defaultFontSize, e.color || defaultTextColor, e.text || "" @@ -319,12 +318,21 @@ this.pdf.doc.setFontStyle("normal"); 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 (!width) { + width = this.pdf.doc.getTextWidth(text); + } + var textLines = this.pdf.doc.splitTextToSize(text, width); + if ( + ["topright", "topleft"].indexOf(position) !== -1 && + y < this.getTextHeight(1) + ) { + y = this.getTextHeight(1); + } if (["topright", "bottomright"].indexOf(position) !== -1) { x = this.pdf.width - offset.x - width; }