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 highlight.
24
 *
25
 * @namespace M.assignfeedback_editpdf
26
 * @class annotationhighlight
27
 * @extends M.assignfeedback_editpdf.annotation
28
 * @module moodle-assignfeedback_editpdf-editor
29
 */
30
var ANNOTATIONHIGHLIGHT = function(config) {
31
    ANNOTATIONHIGHLIGHT.superclass.constructor.apply(this, [config]);
32
};
33
 
34
ANNOTATIONHIGHLIGHT.NAME = "annotationhighlight";
35
ANNOTATIONHIGHLIGHT.ATTRS = {};
36
 
37
Y.extend(ANNOTATIONHIGHLIGHT, M.assignfeedback_editpdf.annotation, {
38
    /**
39
     * Draw a highlight annotation
40
     * @protected
41
     * @method draw
42
     * @return M.assignfeedback_editpdf.drawable
43
     */
44
    draw: function() {
45
        var drawable,
46
            shape,
47
            bounds,
48
            highlightcolour;
49
 
50
        drawable = new M.assignfeedback_editpdf.drawable(this.editor);
51
        bounds = new M.assignfeedback_editpdf.rect();
52
        bounds.bound([new M.assignfeedback_editpdf.point(this.x, this.y),
53
                      new M.assignfeedback_editpdf.point(this.endx, this.endy)]);
54
 
55
        highlightcolour = ANNOTATIONCOLOUR[this.colour];
56
 
57
        // Add an alpha channel to the rgb colour.
58
 
59
        highlightcolour = highlightcolour.replace('rgb', 'rgba');
60
        highlightcolour = highlightcolour.replace(')', ',0.5)');
61
 
62
        shape = this.editor.graphic.addShape({
63
            type: Y.Rect,
64
            width: bounds.width,
65
            height: bounds.height,
66
            stroke: false,
67
            fill: {
68
                color: highlightcolour
69
            },
70
            x: bounds.x,
71
            y: bounds.y
72
        });
73
 
74
        drawable.shapes.push(shape);
75
        this.drawable = drawable;
76
 
77
        return ANNOTATIONHIGHLIGHT.superclass.draw.apply(this);
78
    },
79
 
80
    /**
81
     * Draw the in progress edit.
82
     *
83
     * @public
84
     * @method draw_current_edit
85
     * @param M.assignfeedback_editpdf.edit edit
86
     */
87
    draw_current_edit: function(edit) {
88
        var drawable = new M.assignfeedback_editpdf.drawable(this.editor),
89
            shape,
90
            bounds,
91
            highlightcolour;
92
 
93
        bounds = new M.assignfeedback_editpdf.rect();
94
        bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y),
95
                      new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]);
96
 
97
        // Set min. width of highlight.
98
        if (!bounds.has_min_width()) {
99
            bounds.set_min_width();
100
        }
101
 
102
        highlightcolour = ANNOTATIONCOLOUR[edit.annotationcolour];
103
        // Add an alpha channel to the rgb colour.
104
 
105
        highlightcolour = highlightcolour.replace('rgb', 'rgba');
106
        highlightcolour = highlightcolour.replace(')', ',0.5)');
107
 
108
        // We will draw a box with the current background colour.
109
        shape = this.editor.graphic.addShape({
110
            type: Y.Rect,
111
            width: bounds.width,
112
            height: 20,
113
            stroke: false,
114
            fill: {
115
               color: highlightcolour
116
            },
117
            x: bounds.x,
118
            y: edit.start.y - 10
119
        });
120
 
121
        drawable.shapes.push(shape);
122
 
123
        return drawable;
124
    },
125
 
126
    /**
127
     * Promote the current edit to a real annotation.
128
     *
129
     * @public
130
     * @method init_from_edit
131
     * @param M.assignfeedback_editpdf.edit edit
132
     * @return bool true if highlight bound is more than min width/height, else false.
133
     */
134
    init_from_edit: function(edit) {
135
        var bounds = new M.assignfeedback_editpdf.rect();
136
        bounds.bound([edit.start, edit.end]);
137
 
138
        this.gradeid = this.editor.get('gradeid');
139
        this.pageno = this.editor.currentpage;
140
        this.x = bounds.x;
141
        this.y = edit.start.y - 10;
142
        this.endx = bounds.x + bounds.width;
143
        this.endy = edit.start.y + 10;
144
        this.colour = edit.annotationcolour;
145
        this.page = '';
146
 
147
        return (bounds.has_min_width());
148
    }
149
 
150
});
151
 
152
M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
153
M.assignfeedback_editpdf.annotationhighlight = ANNOTATIONHIGHLIGHT;