0011960: print with 300 dpi by default
authorCornelius Weiß <c.weiss@metaways.de>
Fri, 17 Jun 2016 08:07:43 +0000 (10:07 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 21 Jun 2016 10:13:22 +0000 (12:13 +0200)
https://forge.tine20.org/view.php?id=11960

Change-Id: I1949f5e2f3eb63791f9c7b2a93ade851b7f784ef
Reviewed-on: http://gerrit.tine20.com/customers/3254
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/js/ux/Printer/renderers/Base.js

index 7b71ac6..245741d 100644 (file)
@@ -118,7 +118,15 @@ Ext.ux.Printer.BaseRenderer = Ext.extend(Object, {
   doPrint: function(win) {
     if (this.useHtml2Canvas) {
       var me = this;
   doPrint: function(win) {
     if (this.useHtml2Canvas) {
       var me = this;
+
+      var canvas = win.document.createElement("canvas");
+      canvas.width = win.innerWidth;
+      canvas.height = win.innerHeight;
+
+      me.setDPI(canvas, 300);
+
       html2canvas(win.document.body, {
       html2canvas(win.document.body, {
+        canvas: canvas,
         grabMouse: false,
         onrendered: function (canvas) {
           var screenshot = canvas.toDataURL();
         grabMouse: false,
         onrendered: function (canvas) {
           var screenshot = canvas.toDataURL();
@@ -135,6 +143,21 @@ Ext.ux.Printer.BaseRenderer = Ext.extend(Object, {
       }
     }
   },
       }
     }
   },
+
+  setDPI: function (canvas, dpi) {
+    // Set up CSS size if it's not set up already
+    if (!canvas.style.width)
+      canvas.style.width = canvas.width + 'px';
+    if (!canvas.style.height)
+      canvas.style.height = canvas.height + 'px';
+
+    var scaleFactor = dpi / 96;
+    canvas.width = Math.ceil(canvas.width * scaleFactor);
+    canvas.height = Math.ceil(canvas.height * scaleFactor);
+    var ctx = canvas.getContext('2d');
+    ctx.scale(scaleFactor, scaleFactor);
+  },
+
   /**
    * Generates the HTML Markup which wraps whatever this.generateBody produces
    * @param {Ext.Component} component The component to generate HTML for
   /**
    * Generates the HTML Markup which wraps whatever this.generateBody produces
    * @param {Ext.Component} component The component to generate HTML for