MDL-42799 Assignment: Min. width/height for widget is set to 1

It was possible for user to add widgets with width/height = 0
which were not displayed to user and doesn't have much meaning to it
This patch will set min. width/height to 1
This commit is contained in:
Rajesh Taneja 2013-11-12 12:18:10 +08:00
parent d214057cad
commit baf881b803
14 changed files with 299 additions and 32 deletions

View file

@ -64,6 +64,10 @@ class pdf extends \FPDI {
const GSPATH_NOTESTFILE = 'notestfile'; const GSPATH_NOTESTFILE = 'notestfile';
/** Any other error */ /** Any other error */
const GSPATH_ERROR = 'error'; const GSPATH_ERROR = 'error';
/** Min. width an annotation should have */
const MIN_ANNOTATION_WIDTH = 5;
/** Min. height an annotation should have */
const MIN_ANNOTATION_HEIGHT = 5;
/** /**
* Combine the given PDF files into a single PDF. Optionally add a coversheet and coversheet fields. * Combine the given PDF files into a single PDF. Optionally add a coversheet and coversheet fields.
@ -300,6 +304,15 @@ class pdf extends \FPDI {
$ry = abs($sy - $ey) / 2; $ry = abs($sy - $ey) / 2;
$sx = min($sx, $ex) + $rx; $sx = min($sx, $ex) + $rx;
$sy = min($sy, $ey) + $ry; $sy = min($sy, $ey) + $ry;
// $rx and $ry should be >= min width and height
if ($rx < self::MIN_ANNOTATION_WIDTH) {
$rx = self::MIN_ANNOTATION_WIDTH;
}
if ($ry < self::MIN_ANNOTATION_HEIGHT) {
$ry = self::MIN_ANNOTATION_HEIGHT;
}
$this->Ellipse($sx, $sy, $rx, $ry); $this->Ellipse($sx, $sy, $rx, $ry);
break; break;
case 'rectangle': case 'rectangle':
@ -307,6 +320,14 @@ class pdf extends \FPDI {
$h = abs($sy - $ey); $h = abs($sy - $ey);
$sx = min($sx, $ex); $sx = min($sx, $ex);
$sy = min($sy, $ey); $sy = min($sy, $ey);
// Width or height should be >= min width and height
if ($w < self::MIN_ANNOTATION_WIDTH) {
$w = self::MIN_ANNOTATION_WIDTH;
}
if ($h < self::MIN_ANNOTATION_HEIGHT) {
$h = self::MIN_ANNOTATION_HEIGHT;
}
$this->Rect($sx, $sy, $w, $h); $this->Rect($sx, $sy, $w, $h);
break; break;
case 'highlight': case 'highlight':
@ -316,6 +337,12 @@ class pdf extends \FPDI {
$sy = min($sy, $ey) + ($h * 0.5); $sy = min($sy, $ey) + ($h * 0.5);
$this->SetAlpha(0.5, 'Normal', 0.5, 'Normal'); $this->SetAlpha(0.5, 'Normal', 0.5, 'Normal');
$this->SetLineWidth(8.0 * $this->scale); $this->SetLineWidth(8.0 * $this->scale);
// width should be >= min width
if ($w < self::MIN_ANNOTATION_WIDTH) {
$w = self::MIN_ANNOTATION_WIDTH;
}
$this->Rect($sx, $sy, $w, $h); $this->Rect($sx, $sy, $w, $h);
$this->SetAlpha(1.0, 'Normal', 1.0, 'Normal'); $this->SetAlpha(1.0, 'Normal', 1.0, 'Normal');
break; break;
@ -326,8 +353,11 @@ class pdf extends \FPDI {
foreach ($points as $point) { foreach ($points as $point) {
$scalepath[] = intval($point) * $this->scale; $scalepath[] = intval($point) * $this->scale;
} }
if (!empty($scalepath)) {
$this->PolyLine($scalepath, 'S'); $this->PolyLine($scalepath, 'S');
} }
}
break; break;
case 'stamp': case 'stamp':
$imgfile = $imagefolder . '/' . clean_filename($path); $imgfile = $imagefolder . '/' . clean_filename($path);
@ -335,6 +365,8 @@ class pdf extends \FPDI {
$h = abs($sy - $ey); $h = abs($sy - $ey);
$sx = min($sx, $ex); $sx = min($sx, $ex);
$sy = min($sy, $ey); $sy = min($sy, $ey);
// Stamp is always more than 40px, so no need to check width/height.
$this->Image($imgfile, $sx, $sy, $w, $h); $this->Image($imgfile, $sx, $sy, $w, $h);
break; break;
default: // Line. default: // Line.

View file

@ -250,6 +250,44 @@ RECT = function(x, y, width, height) {
// Allow chaining. // Allow chaining.
return this; return this;
}; };
/**
* Checks if rect has min width.
* @method has_min_width
* @return bool true if width is more than 5px.
* @public
*/
this.has_min_width = function() {
return (this.width >= 5);
};
/**
* Checks if rect has min height.
* @method has_min_height
* @return bool true if height is more than 5px.
* @public
*/
this.has_min_height = function() {
return (this.height >= 5);
};
/**
* Set min. width of annotation bound.
* @method set_min_width
* @public
*/
this.set_min_width = function() {
this.width = 5;
};
/**
* Set min. height of annotation bound.
* @method set_min_height
* @public
*/
this.set_min_height = function() {
this.height = 5;
};
}; };
M.assignfeedback_editpdf = M.assignfeedback_editpdf || {}; M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
@ -745,6 +783,7 @@ Y.extend(ANNOTATION, Y.Base, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool if width/height is more than min. required.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -758,6 +797,7 @@ Y.extend(ANNOTATION, Y.Base, {
this.endy = bounds.y + bounds.height; this.endy = bounds.y + bounds.height;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = ''; this.path = '';
return (bounds.has_min_width() && bounds.has_min_height());
} }
}); });
@ -860,6 +900,7 @@ Y.extend(ANNOTATIONLINE, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if line bound is more than min width/height, else false.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
this.gradeid = this.editor.get('gradeid'); this.gradeid = this.editor.get('gradeid');
@ -870,6 +911,8 @@ Y.extend(ANNOTATIONLINE, M.assignfeedback_editpdf.annotation, {
this.endy = edit.end.y; this.endy = edit.end.y;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = ''; this.path = '';
return !(((this.endx - this.x) === 0) && ((this.endy - this.y) === 0));
} }
}); });
@ -956,6 +999,14 @@ Y.extend(ANNOTATIONRECTANGLE, M.assignfeedback_editpdf.annotation, {
bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y), bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y),
new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]); new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]);
// Set min. width and height of rectangle.
if (!bounds.has_min_width()) {
bounds.set_min_width();
}
if (!bounds.has_min_height()) {
bounds.set_min_height();
}
shape = this.editor.graphic.addShape({ shape = this.editor.graphic.addShape({
type: Y.Rect, type: Y.Rect,
width: bounds.width, width: bounds.width,
@ -1056,6 +1107,14 @@ Y.extend(ANNOTATIONOVAL, M.assignfeedback_editpdf.annotation, {
bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y), bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y),
new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]); new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]);
// Set min. width and height of oval.
if (!bounds.has_min_width()) {
bounds.set_min_width();
}
if (!bounds.has_min_height()) {
bounds.set_min_height();
}
shape = this.editor.graphic.addShape({ shape = this.editor.graphic.addShape({
type: Y.Ellipse, type: Y.Ellipse,
width: bounds.width, width: bounds.width,
@ -1200,6 +1259,7 @@ Y.extend(ANNOTATIONPEN, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if pen bound is more than min width/height, else false.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(), var bounds = new M.assignfeedback_editpdf.rect(),
@ -1221,6 +1281,8 @@ Y.extend(ANNOTATIONPEN, M.assignfeedback_editpdf.annotation, {
this.endy = bounds.y + bounds.height; this.endy = bounds.y + bounds.height;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = pathlist.join(':'); this.path = pathlist.join(':');
return (bounds.has_min_width() || bounds.has_min_height());
} }
@ -1318,6 +1380,11 @@ Y.extend(ANNOTATIONHIGHLIGHT, M.assignfeedback_editpdf.annotation, {
bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y), bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y),
new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]); new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]);
// Set min. width of highlight.
if (!bounds.has_min_width()) {
bounds.set_min_width();
}
highlightcolour = ANNOTATIONCOLOUR[edit.annotationcolour]; highlightcolour = ANNOTATIONCOLOUR[edit.annotationcolour];
// Add an alpha channel to the rgb colour. // Add an alpha channel to the rgb colour.
@ -1348,6 +1415,7 @@ Y.extend(ANNOTATIONHIGHLIGHT, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if highlight bound is more than min width/height, else false.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -1361,6 +1429,8 @@ Y.extend(ANNOTATIONHIGHLIGHT, M.assignfeedback_editpdf.annotation, {
this.endy = edit.start.y + 16; this.endy = edit.start.y + 16;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.page = ''; this.page = '';
return (bounds.has_min_width());
} }
}); });
@ -1480,6 +1550,7 @@ Y.extend(ANNOTATIONSTAMP, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool if width/height is more than min. required.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -1499,6 +1570,9 @@ Y.extend(ANNOTATIONSTAMP, M.assignfeedback_editpdf.annotation, {
this.endy = bounds.y + bounds.height; this.endy = bounds.y + bounds.height;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = edit.stamp; this.path = edit.stamp;
// Min width and height is always more than 40px.
return true;
}, },
/** /**
@ -2541,6 +2615,7 @@ COMMENT = function(editor, gradeid, pageno, x, y, width, colour, rawtext) {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if comment bound is more than min width/height, else false.
*/ */
this.init_from_edit = function(edit) { this.init_from_edit = function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -2560,6 +2635,8 @@ COMMENT = function(editor, gradeid, pageno, x, y, width, colour, rawtext) {
this.width = bounds.width; this.width = bounds.width;
this.colour = edit.commentcolour; this.colour = edit.commentcolour;
this.rawtext = ''; this.rawtext = '';
return (bounds.has_min_width() && bounds.has_min_height());
}; };
}; };
@ -3617,10 +3694,11 @@ EDITOR.prototype = {
} }
this.currentdrawable = false; this.currentdrawable = false;
comment = new M.assignfeedback_editpdf.comment(this); comment = new M.assignfeedback_editpdf.comment(this);
comment.init_from_edit(this.currentedit); if (comment.init_from_edit(this.currentedit)) {
this.pages[this.currentpage].comments.push(comment); this.pages[this.currentpage].comments.push(comment);
this.drawables.push(comment.draw(true)); this.drawables.push(comment.draw(true));
this.editingcomment = true; this.editingcomment = true;
}
} else { } else {
annotation = this.create_annotation(this.currentedit.tool, {}); annotation = this.create_annotation(this.currentedit.tool, {});
if (annotation) { if (annotation) {
@ -3628,12 +3706,12 @@ EDITOR.prototype = {
this.currentdrawable.erase(); this.currentdrawable.erase();
} }
this.currentdrawable = false; this.currentdrawable = false;
annotation.init_from_edit(this.currentedit); if (annotation.init_from_edit(this.currentedit)) {
this.pages[this.currentpage].annotations.push(annotation); this.pages[this.currentpage].annotations.push(annotation);
this.drawables.push(annotation.draw()); this.drawables.push(annotation.draw());
} }
} }
}
// Save the changes. // Save the changes.
this.save_current_page(); this.save_current_page();

View file

@ -250,6 +250,44 @@ RECT = function(x, y, width, height) {
// Allow chaining. // Allow chaining.
return this; return this;
}; };
/**
* Checks if rect has min width.
* @method has_min_width
* @return bool true if width is more than 5px.
* @public
*/
this.has_min_width = function() {
return (this.width >= 5);
};
/**
* Checks if rect has min height.
* @method has_min_height
* @return bool true if height is more than 5px.
* @public
*/
this.has_min_height = function() {
return (this.height >= 5);
};
/**
* Set min. width of annotation bound.
* @method set_min_width
* @public
*/
this.set_min_width = function() {
this.width = 5;
};
/**
* Set min. height of annotation bound.
* @method set_min_height
* @public
*/
this.set_min_height = function() {
this.height = 5;
};
}; };
M.assignfeedback_editpdf = M.assignfeedback_editpdf || {}; M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
@ -745,6 +783,7 @@ Y.extend(ANNOTATION, Y.Base, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool if width/height is more than min. required.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -758,6 +797,7 @@ Y.extend(ANNOTATION, Y.Base, {
this.endy = bounds.y + bounds.height; this.endy = bounds.y + bounds.height;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = ''; this.path = '';
return (bounds.has_min_width() && bounds.has_min_height());
} }
}); });
@ -860,6 +900,7 @@ Y.extend(ANNOTATIONLINE, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if line bound is more than min width/height, else false.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
this.gradeid = this.editor.get('gradeid'); this.gradeid = this.editor.get('gradeid');
@ -870,6 +911,8 @@ Y.extend(ANNOTATIONLINE, M.assignfeedback_editpdf.annotation, {
this.endy = edit.end.y; this.endy = edit.end.y;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = ''; this.path = '';
return !(((this.endx - this.x) === 0) && ((this.endy - this.y) === 0));
} }
}); });
@ -956,6 +999,14 @@ Y.extend(ANNOTATIONRECTANGLE, M.assignfeedback_editpdf.annotation, {
bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y), bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y),
new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]); new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]);
// Set min. width and height of rectangle.
if (!bounds.has_min_width()) {
bounds.set_min_width();
}
if (!bounds.has_min_height()) {
bounds.set_min_height();
}
shape = this.editor.graphic.addShape({ shape = this.editor.graphic.addShape({
type: Y.Rect, type: Y.Rect,
width: bounds.width, width: bounds.width,
@ -1056,6 +1107,14 @@ Y.extend(ANNOTATIONOVAL, M.assignfeedback_editpdf.annotation, {
bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y), bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y),
new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]); new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]);
// Set min. width and height of oval.
if (!bounds.has_min_width()) {
bounds.set_min_width();
}
if (!bounds.has_min_height()) {
bounds.set_min_height();
}
shape = this.editor.graphic.addShape({ shape = this.editor.graphic.addShape({
type: Y.Ellipse, type: Y.Ellipse,
width: bounds.width, width: bounds.width,
@ -1200,6 +1259,7 @@ Y.extend(ANNOTATIONPEN, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if pen bound is more than min width/height, else false.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(), var bounds = new M.assignfeedback_editpdf.rect(),
@ -1221,6 +1281,8 @@ Y.extend(ANNOTATIONPEN, M.assignfeedback_editpdf.annotation, {
this.endy = bounds.y + bounds.height; this.endy = bounds.y + bounds.height;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = pathlist.join(':'); this.path = pathlist.join(':');
return (bounds.has_min_width() || bounds.has_min_height());
} }
@ -1318,6 +1380,11 @@ Y.extend(ANNOTATIONHIGHLIGHT, M.assignfeedback_editpdf.annotation, {
bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y), bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y),
new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]); new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]);
// Set min. width of highlight.
if (!bounds.has_min_width()) {
bounds.set_min_width();
}
highlightcolour = ANNOTATIONCOLOUR[edit.annotationcolour]; highlightcolour = ANNOTATIONCOLOUR[edit.annotationcolour];
// Add an alpha channel to the rgb colour. // Add an alpha channel to the rgb colour.
@ -1348,6 +1415,7 @@ Y.extend(ANNOTATIONHIGHLIGHT, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if highlight bound is more than min width/height, else false.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -1361,6 +1429,8 @@ Y.extend(ANNOTATIONHIGHLIGHT, M.assignfeedback_editpdf.annotation, {
this.endy = edit.start.y + 16; this.endy = edit.start.y + 16;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.page = ''; this.page = '';
return (bounds.has_min_width());
} }
}); });
@ -1480,6 +1550,7 @@ Y.extend(ANNOTATIONSTAMP, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool if width/height is more than min. required.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -1499,6 +1570,9 @@ Y.extend(ANNOTATIONSTAMP, M.assignfeedback_editpdf.annotation, {
this.endy = bounds.y + bounds.height; this.endy = bounds.y + bounds.height;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = edit.stamp; this.path = edit.stamp;
// Min width and height is always more than 40px.
return true;
}, },
/** /**
@ -2541,6 +2615,7 @@ COMMENT = function(editor, gradeid, pageno, x, y, width, colour, rawtext) {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if comment bound is more than min width/height, else false.
*/ */
this.init_from_edit = function(edit) { this.init_from_edit = function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -2560,6 +2635,8 @@ COMMENT = function(editor, gradeid, pageno, x, y, width, colour, rawtext) {
this.width = bounds.width; this.width = bounds.width;
this.colour = edit.commentcolour; this.colour = edit.commentcolour;
this.rawtext = ''; this.rawtext = '';
return (bounds.has_min_width() && bounds.has_min_height());
}; };
}; };
@ -3617,10 +3694,11 @@ EDITOR.prototype = {
} }
this.currentdrawable = false; this.currentdrawable = false;
comment = new M.assignfeedback_editpdf.comment(this); comment = new M.assignfeedback_editpdf.comment(this);
comment.init_from_edit(this.currentedit); if (comment.init_from_edit(this.currentedit)) {
this.pages[this.currentpage].comments.push(comment); this.pages[this.currentpage].comments.push(comment);
this.drawables.push(comment.draw(true)); this.drawables.push(comment.draw(true));
this.editingcomment = true; this.editingcomment = true;
}
} else { } else {
annotation = this.create_annotation(this.currentedit.tool, {}); annotation = this.create_annotation(this.currentedit.tool, {});
if (annotation) { if (annotation) {
@ -3628,12 +3706,12 @@ EDITOR.prototype = {
this.currentdrawable.erase(); this.currentdrawable.erase();
} }
this.currentdrawable = false; this.currentdrawable = false;
annotation.init_from_edit(this.currentedit); if (annotation.init_from_edit(this.currentedit)) {
this.pages[this.currentpage].annotations.push(annotation); this.pages[this.currentpage].annotations.push(annotation);
this.drawables.push(annotation.draw()); this.drawables.push(annotation.draw());
} }
} }
}
// Save the changes. // Save the changes.
this.save_current_page(); this.save_current_page();

View file

@ -308,6 +308,7 @@ Y.extend(ANNOTATION, Y.Base, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool if width/height is more than min. required.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -321,6 +322,7 @@ Y.extend(ANNOTATION, Y.Base, {
this.endy = bounds.y + bounds.height; this.endy = bounds.y + bounds.height;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = ''; this.path = '';
return (bounds.has_min_width() && bounds.has_min_height());
} }
}); });

View file

@ -88,6 +88,11 @@ Y.extend(ANNOTATIONHIGHLIGHT, M.assignfeedback_editpdf.annotation, {
bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y), bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y),
new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]); new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]);
// Set min. width of highlight.
if (!bounds.has_min_width()) {
bounds.set_min_width();
}
highlightcolour = ANNOTATIONCOLOUR[edit.annotationcolour]; highlightcolour = ANNOTATIONCOLOUR[edit.annotationcolour];
// Add an alpha channel to the rgb colour. // Add an alpha channel to the rgb colour.
@ -118,6 +123,7 @@ Y.extend(ANNOTATIONHIGHLIGHT, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if highlight bound is more than min width/height, else false.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -131,6 +137,8 @@ Y.extend(ANNOTATIONHIGHLIGHT, M.assignfeedback_editpdf.annotation, {
this.endy = edit.start.y + 16; this.endy = edit.start.y + 16;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.page = ''; this.page = '';
return (bounds.has_min_width());
} }
}); });

View file

@ -94,6 +94,7 @@ Y.extend(ANNOTATIONLINE, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if line bound is more than min width/height, else false.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
this.gradeid = this.editor.get('gradeid'); this.gradeid = this.editor.get('gradeid');
@ -104,6 +105,8 @@ Y.extend(ANNOTATIONLINE, M.assignfeedback_editpdf.annotation, {
this.endy = edit.end.y; this.endy = edit.end.y;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = ''; this.path = '';
return !(((this.endx - this.x) === 0) && ((this.endy - this.y) === 0));
} }
}); });

View file

@ -78,6 +78,14 @@ Y.extend(ANNOTATIONOVAL, M.assignfeedback_editpdf.annotation, {
bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y), bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y),
new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]); new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]);
// Set min. width and height of oval.
if (!bounds.has_min_width()) {
bounds.set_min_width();
}
if (!bounds.has_min_height()) {
bounds.set_min_height();
}
shape = this.editor.graphic.addShape({ shape = this.editor.graphic.addShape({
type: Y.Ellipse, type: Y.Ellipse,
width: bounds.width, width: bounds.width,

View file

@ -122,6 +122,7 @@ Y.extend(ANNOTATIONPEN, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if pen bound is more than min width/height, else false.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(), var bounds = new M.assignfeedback_editpdf.rect(),
@ -143,6 +144,8 @@ Y.extend(ANNOTATIONPEN, M.assignfeedback_editpdf.annotation, {
this.endy = bounds.y + bounds.height; this.endy = bounds.y + bounds.height;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = pathlist.join(':'); this.path = pathlist.join(':');
return (bounds.has_min_width() || bounds.has_min_height());
} }

View file

@ -78,6 +78,14 @@ Y.extend(ANNOTATIONRECTANGLE, M.assignfeedback_editpdf.annotation, {
bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y), bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y),
new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]); new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]);
// Set min. width and height of rectangle.
if (!bounds.has_min_width()) {
bounds.set_min_width();
}
if (!bounds.has_min_height()) {
bounds.set_min_height();
}
shape = this.editor.graphic.addShape({ shape = this.editor.graphic.addShape({
type: Y.Rect, type: Y.Rect,
width: bounds.width, width: bounds.width,

View file

@ -111,6 +111,7 @@ Y.extend(ANNOTATIONSTAMP, M.assignfeedback_editpdf.annotation, {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool if width/height is more than min. required.
*/ */
init_from_edit : function(edit) { init_from_edit : function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -130,6 +131,9 @@ Y.extend(ANNOTATIONSTAMP, M.assignfeedback_editpdf.annotation, {
this.endy = bounds.y + bounds.height; this.endy = bounds.y + bounds.height;
this.colour = edit.annotationcolour; this.colour = edit.annotationcolour;
this.path = edit.stamp; this.path = edit.stamp;
// Min width and height is always more than 40px.
return true;
}, },
/** /**

View file

@ -411,6 +411,7 @@ COMMENT = function(editor, gradeid, pageno, x, y, width, colour, rawtext) {
* @public * @public
* @method init_from_edit * @method init_from_edit
* @param M.assignfeedback_editpdf.edit edit * @param M.assignfeedback_editpdf.edit edit
* @return bool true if comment bound is more than min width/height, else false.
*/ */
this.init_from_edit = function(edit) { this.init_from_edit = function(edit) {
var bounds = new M.assignfeedback_editpdf.rect(); var bounds = new M.assignfeedback_editpdf.rect();
@ -430,6 +431,8 @@ COMMENT = function(editor, gradeid, pageno, x, y, width, colour, rawtext) {
this.width = bounds.width; this.width = bounds.width;
this.colour = edit.commentcolour; this.colour = edit.commentcolour;
this.rawtext = ''; this.rawtext = '';
return (bounds.has_min_width() && bounds.has_min_height());
}; };
}; };

View file

@ -785,10 +785,11 @@ EDITOR.prototype = {
} }
this.currentdrawable = false; this.currentdrawable = false;
comment = new M.assignfeedback_editpdf.comment(this); comment = new M.assignfeedback_editpdf.comment(this);
comment.init_from_edit(this.currentedit); if (comment.init_from_edit(this.currentedit)) {
this.pages[this.currentpage].comments.push(comment); this.pages[this.currentpage].comments.push(comment);
this.drawables.push(comment.draw(true)); this.drawables.push(comment.draw(true));
this.editingcomment = true; this.editingcomment = true;
}
} else { } else {
annotation = this.create_annotation(this.currentedit.tool, {}); annotation = this.create_annotation(this.currentedit.tool, {});
if (annotation) { if (annotation) {
@ -796,12 +797,12 @@ EDITOR.prototype = {
this.currentdrawable.erase(); this.currentdrawable.erase();
} }
this.currentdrawable = false; this.currentdrawable = false;
annotation.init_from_edit(this.currentedit); if (annotation.init_from_edit(this.currentedit)) {
this.pages[this.currentpage].annotations.push(annotation); this.pages[this.currentpage].annotations.push(annotation);
this.drawables.push(annotation.draw()); this.drawables.push(annotation.draw());
} }
} }
}
// Save the changes. // Save the changes.
this.save_current_page(); this.save_current_page();

View file

@ -99,6 +99,44 @@ RECT = function(x, y, width, height) {
// Allow chaining. // Allow chaining.
return this; return this;
}; };
/**
* Checks if rect has min width.
* @method has_min_width
* @return bool true if width is more than 5px.
* @public
*/
this.has_min_width = function() {
return (this.width >= 5);
};
/**
* Checks if rect has min height.
* @method has_min_height
* @return bool true if height is more than 5px.
* @public
*/
this.has_min_height = function() {
return (this.height >= 5);
};
/**
* Set min. width of annotation bound.
* @method set_min_width
* @public
*/
this.set_min_width = function() {
this.width = 5;
};
/**
* Set min. height of annotation bound.
* @method set_min_height
* @public
*/
this.set_min_height = function() {
this.height = 5;
};
}; };
M.assignfeedback_editpdf = M.assignfeedback_editpdf || {}; M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};