# HG changeset patch # User Fadi Abbud # Date 1556888907 -7200 # Node ID b6c10b30d6bdbce55c5f99824878657037096416 # Parent 8159bd2aaf930885e5a9f8f2637ed7c99f9e90ac client: pdf-gen: add one pdf-template element * add textbox function to mixins * implemet this function in pdf-template for waterlevel diagram diff -r 8159bd2aaf93 -r b6c10b30d6bd client/src/components/gauge/Waterlevel.vue --- a/client/src/components/gauge/Waterlevel.vue Fri May 03 14:23:47 2019 +0200 +++ b/client/src/components/gauge/Waterlevel.vue Fri May 03 15:08:27 2019 +0200 @@ -223,6 +223,7 @@ defaultBorderColor = "white", defaultBgColor = "white", defaultRounding = 2, + defaultPadding = 2, defaultOffset = { x: 0, y: 0 }; this.templateData.elements.forEach(e => { switch (e.type) { @@ -272,6 +273,21 @@ ); break; } + case "textbox": { + this.addTextBox( + e.position, + e.offset || defaultOffset, + e.width, + e.height, + e.rounding === 0 || e.rounding ? e.rounding : defaultRounding, + e.padding || defaultPadding, + e.fontSize || defaultFontSize, + e.color || defaultTextColor, + e.background || defaultBgColor, + e.text, + e.brcolor || defaultBorderColor + ); + } } }); } diff -r 8159bd2aaf93 -r b6c10b30d6bd client/src/lib/mixins.js --- a/client/src/lib/mixins.js Fri May 03 14:23:47 2019 +0200 +++ b/client/src/lib/mixins.js Fri May 03 15:08:27 2019 +0200 @@ -125,6 +125,49 @@ this.pdf.doc.setDrawColor(brcolor); this.pdf.doc.setFillColor(color); this.pdf.doc.roundedRect(x, y, w, h, rounding, rounding, "FD"); + }, + 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 + ); } } };