Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 
16
/**
17
 * Provides an in browser PDF editor.
18
 *
19
 * @module moodle-assignfeedback_editpdf-editor
20
 */
21
 
22
/**
23
 * Class representing a pen.
24
 *
25
 * @namespace M.assignfeedback_editpdf
26
 * @class annotationpen
27
 * @extends M.assignfeedback_editpdf.annotation
28
 */
29
var ANNOTATIONPEN = function(config) {
30
    ANNOTATIONPEN.superclass.constructor.apply(this, [config]);
31
};
32
 
33
ANNOTATIONPEN.NAME = "annotationpen";
34
ANNOTATIONPEN.ATTRS = {};
35
 
36
Y.extend(ANNOTATIONPEN, M.assignfeedback_editpdf.annotation, {
37
    /**
38
     * Draw a pen annotation
39
     * @protected
40
     * @method draw
41
     * @return M.assignfeedback_editpdf.drawable
42
     */
43
    draw: function() {
44
        var drawable,
45
            shape,
46
            first,
47
            positions,
48
            xy;
49
 
50
        drawable = new M.assignfeedback_editpdf.drawable(this.editor);
51
 
52
        shape = this.editor.graphic.addShape({
53
           type: Y.Path,
54
            fill: false,
55
            stroke: {
56
                weight: STROKEWEIGHT,
57
                color: ANNOTATIONCOLOUR[this.colour]
58
            }
59
        });
60
 
61
        first = true;
62
        // Recreate the pen path array.
63
        positions = this.path.split(':');
64
        // Redraw all the lines.
65
        Y.each(positions, function(position) {
66
            xy = position.split(',');
67
            if (first) {
68
                shape.moveTo(xy[0], xy[1]);
69
                first = false;
70
            } else {
71
                shape.lineTo(xy[0], xy[1]);
72
            }
73
        }, this);
74
 
75
        shape.end();
76
 
77
        drawable.shapes.push(shape);
78
        this.drawable = drawable;
79
 
80
        return ANNOTATIONPEN.superclass.draw.apply(this);
81
    },
82
 
83
    /**
84
     * Draw the in progress edit.
85
     *
86
     * @public
87
     * @method draw_current_edit
88
     * @param M.assignfeedback_editpdf.edit edit
89
     */
90
    draw_current_edit: function(edit) {
91
        var drawable = new M.assignfeedback_editpdf.drawable(this.editor),
92
            shape,
93
            first;
94
 
95
        shape = this.editor.graphic.addShape({
96
           type: Y.Path,
97
            fill: false,
98
            stroke: {
99
                weight: STROKEWEIGHT,
100
                color: ANNOTATIONCOLOUR[edit.annotationcolour]
101
            }
102
        });
103
 
104
        first = true;
105
        // Recreate the pen path array.
106
        // Redraw all the lines.
107
        Y.each(edit.path, function(position) {
108
            if (first) {
109
                shape.moveTo(position.x, position.y);
110
                first = false;
111
            } else {
112
                shape.lineTo(position.x, position.y);
113
            }
114
        }, this);
115
 
116
        shape.end();
117
 
118
        drawable.shapes.push(shape);
119
 
120
        return drawable;
121
    },
122
 
123
 
124
    /**
125
     * Promote the current edit to a real annotation.
126
     *
127
     * @public
128
     * @method init_from_edit
129
     * @param M.assignfeedback_editpdf.edit edit
130
     * @return bool true if pen bound is more than min width/height, else false.
131
     */
132
    init_from_edit: function(edit) {
133
        var bounds = new M.assignfeedback_editpdf.rect(),
134
            pathlist = [],
135
            i = 0;
136
 
137
        // This will get the boundaries of all points in the path.
138
        bounds.bound(edit.path);
139
 
140
        for (i = 0; i < edit.path.length; i++) {
141
            pathlist.push(parseInt(edit.path[i].x, 10) + ',' + parseInt(edit.path[i].y, 10));
142
        }
143
 
144
        this.gradeid = this.editor.get('gradeid');
145
        this.pageno = this.editor.currentpage;
146
        this.x = bounds.x;
147
        this.y = bounds.y;
148
        this.endx = bounds.x + bounds.width;
149
        this.endy = bounds.y + bounds.height;
150
        this.colour = edit.annotationcolour;
151
        this.path = pathlist.join(':');
152
 
153
        return (bounds.has_min_width() || bounds.has_min_height());
154
    }
155
 
156
 
157
});
158
 
159
M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
160
M.assignfeedback_editpdf.annotationpen = ANNOTATIONPEN;