[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/assign/feedback/editpdf/yui/src/editor/js/ -> annotationpen.js (source)

   1  // This file is part of Moodle - http://moodle.org/
   2  //
   3  // Moodle is free software: you can redistribute it and/or modify
   4  // it under the terms of the GNU General Public License as published by
   5  // the Free Software Foundation, either version 3 of the License, or
   6  // (at your option) any later version.
   7  //
   8  // Moodle is distributed in the hope that it will be useful,
   9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11  // GNU General Public License for more details.
  12  //
  13  // You should have received a copy of the GNU General Public License
  14  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  15  /* global STROKEWEIGHT, ANNOTATIONCOLOUR */
  16  
  17  /**
  18   * Provides an in browser PDF editor.
  19   *
  20   * @module moodle-assignfeedback_editpdf-editor
  21   */
  22  
  23  /**
  24   * Class representing a pen.
  25   *
  26   * @namespace M.assignfeedback_editpdf
  27   * @class annotationpen
  28   * @extends M.assignfeedback_editpdf.annotation
  29   */
  30  var ANNOTATIONPEN = function(config) {
  31      ANNOTATIONPEN.superclass.constructor.apply(this, [config]);
  32  };
  33  
  34  ANNOTATIONPEN.NAME = "annotationpen";
  35  ANNOTATIONPEN.ATTRS = {};
  36  
  37  Y.extend(ANNOTATIONPEN, M.assignfeedback_editpdf.annotation, {
  38      /**
  39       * Draw a pen annotation
  40       * @protected
  41       * @method draw
  42       * @return M.assignfeedback_editpdf.drawable
  43       */
  44      draw: function() {
  45          var drawable,
  46              shape,
  47              first,
  48              positions,
  49              xy;
  50  
  51          drawable = new M.assignfeedback_editpdf.drawable(this.editor);
  52  
  53          shape = this.editor.graphic.addShape({
  54             type: Y.Path,
  55              fill: false,
  56              stroke: {
  57                  weight: STROKEWEIGHT,
  58                  color: ANNOTATIONCOLOUR[this.colour]
  59              }
  60          });
  61  
  62          first = true;
  63          // Recreate the pen path array.
  64          positions = this.path.split(':');
  65          // Redraw all the lines.
  66          Y.each(positions, function(position) {
  67              xy = position.split(',');
  68              if (first) {
  69                  shape.moveTo(xy[0], xy[1]);
  70                  first = false;
  71              } else {
  72                  shape.lineTo(xy[0], xy[1]);
  73              }
  74          }, this);
  75  
  76          shape.end();
  77  
  78          drawable.shapes.push(shape);
  79          this.drawable = drawable;
  80  
  81          return ANNOTATIONPEN.superclass.draw.apply(this);
  82      },
  83  
  84      /**
  85       * Draw the in progress edit.
  86       *
  87       * @public
  88       * @method draw_current_edit
  89       * @param M.assignfeedback_editpdf.edit edit
  90       */
  91      draw_current_edit: function(edit) {
  92          var drawable = new M.assignfeedback_editpdf.drawable(this.editor),
  93              shape,
  94              first;
  95  
  96          shape = this.editor.graphic.addShape({
  97             type: Y.Path,
  98              fill: false,
  99              stroke: {
 100                  weight: STROKEWEIGHT,
 101                  color: ANNOTATIONCOLOUR[edit.annotationcolour]
 102              }
 103          });
 104  
 105          first = true;
 106          // Recreate the pen path array.
 107          // Redraw all the lines.
 108          Y.each(edit.path, function(position) {
 109              if (first) {
 110                  shape.moveTo(position.x, position.y);
 111                  first = false;
 112              } else {
 113                  shape.lineTo(position.x, position.y);
 114              }
 115          }, this);
 116  
 117          shape.end();
 118  
 119          drawable.shapes.push(shape);
 120  
 121          return drawable;
 122      },
 123  
 124  
 125      /**
 126       * Promote the current edit to a real annotation.
 127       *
 128       * @public
 129       * @method init_from_edit
 130       * @param M.assignfeedback_editpdf.edit edit
 131       * @return bool true if pen bound is more than min width/height, else false.
 132       */
 133      init_from_edit: function(edit) {
 134          var bounds = new M.assignfeedback_editpdf.rect(),
 135              pathlist = [],
 136              i = 0;
 137  
 138          // This will get the boundaries of all points in the path.
 139          bounds.bound(edit.path);
 140  
 141          for (i = 0; i < edit.path.length; i++) {
 142              pathlist.push(parseInt(edit.path[i].x, 10) + ',' + parseInt(edit.path[i].y, 10));
 143          }
 144  
 145          this.gradeid = this.editor.get('gradeid');
 146          this.pageno = this.editor.currentpage;
 147          this.x = bounds.x;
 148          this.y = bounds.y;
 149          this.endx = bounds.x + bounds.width;
 150          this.endy = bounds.y + bounds.height;
 151          this.colour = edit.annotationcolour;
 152          this.path = pathlist.join(':');
 153  
 154          return (bounds.has_min_width() || bounds.has_min_height());
 155      }
 156  
 157  
 158  });
 159  
 160  M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
 161  M.assignfeedback_editpdf.annotationpen = ANNOTATIONPEN;


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1