changeset 3154:b6c10b30d6bd

client: pdf-gen: add one pdf-template element * add textbox function to mixins * implemet this function in pdf-template for waterlevel diagram
author Fadi Abbud <fadi.abbud@intevation.de>
date Fri, 03 May 2019 15:08:27 +0200
parents 8159bd2aaf93
children f09f142239a5
files client/src/components/gauge/Waterlevel.vue client/src/lib/mixins.js
diffstat 2 files changed, 59 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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
+              );
+            }
           }
         });
       }
--- 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
+      );
     }
   }
 };