From baf881b8038d9da54499d166c28b4af4076680e8 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Tue, 12 Nov 2013 12:18:10 +0800 Subject: [PATCH] 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 --- mod/assign/feedback/editpdf/classes/pdf.php | 34 ++++++- ...dle-assignfeedback_editpdf-editor-debug.js | 94 +++++++++++++++++-- ...oodle-assignfeedback_editpdf-editor-min.js | 15 +-- .../moodle-assignfeedback_editpdf-editor.js | 94 +++++++++++++++++-- .../editpdf/yui/src/editor/js/annotation.js | 2 + .../yui/src/editor/js/annotationhighlight.js | 8 ++ .../yui/src/editor/js/annotationline.js | 3 + .../yui/src/editor/js/annotationoval.js | 8 ++ .../yui/src/editor/js/annotationpen.js | 3 + .../yui/src/editor/js/annotationrectangle.js | 8 ++ .../yui/src/editor/js/annotationstamp.js | 4 + .../editpdf/yui/src/editor/js/comment.js | 3 + .../editpdf/yui/src/editor/js/editor.js | 17 ++-- .../editpdf/yui/src/editor/js/rect.js | 38 ++++++++ 14 files changed, 299 insertions(+), 32 deletions(-) diff --git a/mod/assign/feedback/editpdf/classes/pdf.php b/mod/assign/feedback/editpdf/classes/pdf.php index d7747d18c6a..1eb58aa1d04 100644 --- a/mod/assign/feedback/editpdf/classes/pdf.php +++ b/mod/assign/feedback/editpdf/classes/pdf.php @@ -64,6 +64,10 @@ class pdf extends \FPDI { const GSPATH_NOTESTFILE = 'notestfile'; /** Any other 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. @@ -300,6 +304,15 @@ class pdf extends \FPDI { $ry = abs($sy - $ey) / 2; $sx = min($sx, $ex) + $rx; $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); break; case 'rectangle': @@ -307,6 +320,14 @@ class pdf extends \FPDI { $h = abs($sy - $ey); $sx = min($sx, $ex); $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); break; case 'highlight': @@ -316,6 +337,12 @@ class pdf extends \FPDI { $sy = min($sy, $ey) + ($h * 0.5); $this->SetAlpha(0.5, 'Normal', 0.5, 'Normal'); $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->SetAlpha(1.0, 'Normal', 1.0, 'Normal'); break; @@ -326,7 +353,10 @@ class pdf extends \FPDI { foreach ($points as $point) { $scalepath[] = intval($point) * $this->scale; } - $this->PolyLine($scalepath, 'S'); + + if (!empty($scalepath)) { + $this->PolyLine($scalepath, 'S'); + } } break; case 'stamp': @@ -335,6 +365,8 @@ class pdf extends \FPDI { $h = abs($sy - $ey); $sx = min($sx, $ex); $sy = min($sy, $ey); + + // Stamp is always more than 40px, so no need to check width/height. $this->Image($imgfile, $sx, $sy, $w, $h); break; default: // Line. diff --git a/mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor-debug.js b/mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor-debug.js index 1cafbfeb1fb..c2a2b3a262f 100644 --- a/mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor-debug.js +++ b/mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor-debug.js @@ -250,6 +250,44 @@ RECT = function(x, y, width, height) { // Allow chaining. 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 || {}; @@ -745,6 +783,7 @@ Y.extend(ANNOTATION, Y.Base, { * @public * @method init_from_edit * @param M.assignfeedback_editpdf.edit edit + * @return bool if width/height is more than min. required. */ init_from_edit : function(edit) { var bounds = new M.assignfeedback_editpdf.rect(); @@ -758,6 +797,7 @@ Y.extend(ANNOTATION, Y.Base, { this.endy = bounds.y + bounds.height; this.colour = edit.annotationcolour; this.path = ''; + return (bounds.has_min_width() && bounds.has_min_height()); } }); @@ -860,6 +900,7 @@ Y.extend(ANNOTATIONLINE, M.assignfeedback_editpdf.annotation, { * @public * @method init_from_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) { this.gradeid = this.editor.get('gradeid'); @@ -870,6 +911,8 @@ Y.extend(ANNOTATIONLINE, M.assignfeedback_editpdf.annotation, { this.endy = edit.end.y; this.colour = edit.annotationcolour; 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), 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({ type: Y.Rect, 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), 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({ type: Y.Ellipse, width: bounds.width, @@ -1200,6 +1259,7 @@ Y.extend(ANNOTATIONPEN, M.assignfeedback_editpdf.annotation, { * @public * @method init_from_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) { 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.colour = edit.annotationcolour; 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), 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]; // Add an alpha channel to the rgb colour. @@ -1348,6 +1415,7 @@ Y.extend(ANNOTATIONHIGHLIGHT, M.assignfeedback_editpdf.annotation, { * @public * @method init_from_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) { 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.colour = edit.annotationcolour; this.page = ''; + + return (bounds.has_min_width()); } }); @@ -1480,6 +1550,7 @@ Y.extend(ANNOTATIONSTAMP, M.assignfeedback_editpdf.annotation, { * @public * @method init_from_edit * @param M.assignfeedback_editpdf.edit edit + * @return bool if width/height is more than min. required. */ init_from_edit : function(edit) { 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.colour = edit.annotationcolour; 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 * @method init_from_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) { 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.colour = edit.commentcolour; this.rawtext = ''; + + return (bounds.has_min_width() && bounds.has_min_height()); }; }; @@ -3617,10 +3694,11 @@ EDITOR.prototype = { } this.currentdrawable = false; comment = new M.assignfeedback_editpdf.comment(this); - comment.init_from_edit(this.currentedit); - this.pages[this.currentpage].comments.push(comment); - this.drawables.push(comment.draw(true)); - this.editingcomment = true; + if (comment.init_from_edit(this.currentedit)) { + this.pages[this.currentpage].comments.push(comment); + this.drawables.push(comment.draw(true)); + this.editingcomment = true; + } } else { annotation = this.create_annotation(this.currentedit.tool, {}); if (annotation) { @@ -3628,13 +3706,13 @@ EDITOR.prototype = { this.currentdrawable.erase(); } this.currentdrawable = false; - annotation.init_from_edit(this.currentedit); - this.pages[this.currentpage].annotations.push(annotation); - this.drawables.push(annotation.draw()); + if (annotation.init_from_edit(this.currentedit)) { + this.pages[this.currentpage].annotations.push(annotation); + this.drawables.push(annotation.draw()); + } } } - // Save the changes. this.save_current_page(); diff --git a/mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor-min.js b/mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor-min.js index 428b46b75b4..b4df7a860c9 100644 --- a/mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor-min.js +++ b/mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor-min.js @@ -1,7 +1,8 @@ -YUI.add("moodle-assignfeedback_editpdf-editor",function(e,t){var n=M.cfg.wwwroot+"/mod/assign/feedback/editpdf/ajax.php",r=M.cfg.wwwroot+"/mod/assign/feedback/editpdf/ajax_progress.php",s={DIALOGUE:"assignfeedback_editpdf_widget"},o={PREVIOUSBUTTON:"."+s.DIALOGUE+" .navigate-previous-button",NEXTBUTTON:"."+s.DIALOGUE+" .navigate-next-button",SEARCHCOMMENTSBUTTON:"."+s.DIALOGUE+" .searchcommentsbutton",SEARCHFILTER:".assignfeedback_editpdf_commentsearch input",SEARCHCOMMENTSLIST:".assignfeedback_editpdf_commentsearch ul",PAGESELECT:"."+s.DIALOGUE+" .navigate-page-select",LOADINGICON:"."+s.DIALOGUE+" .loading",PROGRESSBARCONTAINER:"."+s.DIALOGUE+" .progress-info.progress-striped",DRAWINGREGION:"."+s.DIALOGUE+" .drawingregion",DRAWINGCANVAS:"."+s.DIALOGUE+" .drawingcanvas",SAVE:"."+s.DIALOGUE+" .savebutton",COMMENTCOLOURBUTTON:"."+s.DIALOGUE+" .commentcolourbutton",COMMENTMENU:" .commentdrawable a",ANNOTATIONCOLOURBUTTON:"."+s.DIALOGUE+" .annotationcolourbutton",DELETEANNOTATIONBUTTON:"."+s.DIALOGUE+" .deleteannotationbutton",UNSAVEDCHANGESDIV:".assignfeedback_editpdf_unsavedchanges",STAMPSBUTTON:"."+s.DIALOGUE+" .currentstampbutton",DIALOGUE:"."+s.DIALOGUE},u="rgba(200, 200, 255, 0.9)",a="rgba(200, 200, 255, 0.5)",f="rgb(51, 51, 51)",l={white:"rgb(255,255,255)",yellow:"rgb(255,236,174)",red:"rgb(249,181,179)",green:"rgb(214,234,178)",blue:"rgb(203,217,237)",clear:"rgba(255,255,255, 0)"},c={white:"rgb(255,255,255)",yellow:"rgb(255,207,53)",red:"rgb(239,69,64)",green:"rgb(152,202,62)",blue:"rgb(125,159,211)",black:"rgb(51,51,51)"},h=300,p={comment:"."+s.DIALOGUE+" .commentbutton",pen:"."+s.DIALOGUE+" .penbutton",line:"."+s.DIALOGUE+" .linebutton",rectangle:"."+s.DIALOGUE+" .rectanglebutton",oval:"."+s.DIALOGUE+" .ovalbutton",stamp:"."+s.DIALOGUE+" .stampbutton",select:"."+s.DIALOGUE+" .selectbutton",highlight:"."+s.DIALOGUE+" .highlightbutton"},d=4;POINT=function(e,t){this.x=parseInt(e,10),this.y=parseInt(t,10),this.clip=function(e){return this.xe.x+e.width&&(this.x=e.x+e.width),this.ye.y+e.height&&(this.y=e.y+e.height),this}},M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.point=POINT,RECT=function(e,t,n,r){this.x=e,this.y=t,this.width=n,this.height=r,this.bound=function(e){var t=0,n=0,r=0,i=0,s=0,o;for(s=0;sn||s===0)n=o.x;if(o.yi||s===0)i=o.y}return this.x=t,this.y=r,this.width=n-t,this.height=i-r,this}},M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.rect=RECT,EDIT=function(){this.start=!1,this.end=!1,this.starttime=0,this.annotationstart=!1,this.tool="comment",this.commentcolour="yellow",this.annotationcolour="red",this.stamp="",this.path=[]},M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.edit=EDIT,DRAWABLE=function(e){this.editor=e,this.shapes=[],this.nodes=[],this.erase=function(){if(this.shapes)while(this.shapes.length>0)this.editor.graphic.removeShape(this.shapes.pop());if(this.nodes)while(this.nodes.length>0)this.nodes.pop().remove()}},M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.drawable=DRAWABLE,ANNOTATION=function(e){ANNOTATION.superclass.constructor.apply(this,[e])},ANNOTATION.NAME="annotation",ANNOTATION.ATTRS={},e.extend(ANNOTATION,e.Base,{editor:null,gradeid:0,pageno:0,x:0,y:0,endx:0,endy:0,path:"",type:"rect",colour:"red",drawable:!1,initializer:function(e){this.editor=e.editor||null,this.gradeid=parseInt(e.gradeid,10)||0,this.pageno=parseInt(e.pageno,10)||0,this.x=parseInt(e.x,10)||0,this.y=parseInt(e.y,10)||0,this.endx=parseInt(e.endx,10)||0,this.endy=parseInt(e.endy,10)||0,this.path=e.path||"",this.type=e.type||"rect",this.colour=e.colour||"red",this.drawable=!1},clean:function(){return{gradeid:this.gradeid,x:parseInt(this.x,10),y:parseInt(this.y,10),endx:parseInt(this.endx,10),endy:parseInt(this.endy,10),type:this.type,path:this.path,pageno:this.pageno,colour:this.colour}},draw_highlight:function(){var t,n=e.one(o.DRAWINGREGION),r=e.one(o.DRAWINGCANVAS).getXY(),i;if(this.editor.currentannotation===this){t=new M.assignfeedback_editpdf.rect,t.bound([new M.assignfeedback_editpdf.point(this.x,this.y),new M.assignfeedback_editpdf.point(this.endx,this.endy)]),i=this.editor.graphic.addShape({type:e.Rect,width:t.width,height:t.height,stroke:{weight:d,color:u},fill:{color:a},x:t.x,y:t.y}),this.drawable.shapes.push(i);var s=e.Node.create(''),f=e.Node.create('');s.setAttrs({alt:M.util.get_string("deleteannotation","assignfeedback_editpdf")}),s.setStyles({backgroundColor:"white"}),f.addClass("deleteannotationbutton"),f.append(s),n.append(f),f.setData("annotation",this),f.setStyle("zIndex","200"),f.on("click",this.remove,this),f.on("key",this.remove,"space,enter",this),f.setX(r[0]+t.x+t.width-18),f.setY(r[1]+t.y+6),this.drawable.nodes.push(f)}return this.drawable},draw:function(){return this.draw_highlight(),this.drawable},remove:function(e){var t;e.preventDefault(),t=this.editor.pages[this.editor.currentpage].annotations;for(i=0;i"),r.setStyles({position:"absolute",display:"inline-block",backgroundImage:"url("+this.editor.get_stamp_image_url(this.path)+")",width:this.endx-this.x,height:this.endy-this.y,backgroundSize:"100% 100%",zIndex:50}),n.append(r),r.setX(i.x),r.setY(i.y),r.on("gesturemovestart",this.editor.edit_start,null,this.editor),r.on("gesturemove",this.editor.edit_move,null,this.editor),r.on("gesturemoveend",this.editor.edit_end,null,this.editor),t.nodes.push(r),this.drawable=t,ANNOTATIONSTAMP.superclass.draw.apply(this)},draw_current_edit:function(t){var n=new M.assignfeedback_editpdf.rect,r=new M.assignfeedback_editpdf.drawable(this.editor),i=e.one(o.DRAWINGREGION),s,u;return n.bound([t.start,t.end]),u=this.editor.get_window_coordinates(new M.assignfeedback_editpdf.point(n.x,n.y)),s=e.Node.create("
"),s.setStyles({position:"absolute",display:"inline-block",backgroundImage:"url("+this.editor.get_stamp_image_url(t.stamp)+")",width:n.width,height:n.height,backgroundSize:"100% 100%",zIndex:50}),i.append(s),s.setX(u.x),s.setY(u.y),r.nodes.push(s),r},init_from_edit:function(e){var t=new M.assignfeedback_editpdf.rect;t.bound([e.start,e.end]),t.width<40&&(t.width=40),t.height<40&&(t.height=40),this.gradeid=this.editor.get("gradeid"),this.pageno=this.editor.currentpage,this.x=t.x,this.y=t.y,this.endx=t.x+t.width,this.endy=t.y+t.height,this.colour=e.annotationcolour,this.path=e.stamp},move:function(e,t){var n=e-this.x,r=t-this.y;this.x+=n,this.y+=r,this.endx+=n,this.endy+=r,this.drawable&&this.drawable.erase(),this.editor.drawables.push(this.draw())}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.annotationstamp=ANNOTATIONSTAMP;var v="Dropdown menu",m;m=function(e){e.draggable=!1,e.centered=!1,e.width="auto",e.lightbox=!1,e.visible=!1,e.zIndex=100,e.footerContent="",m.superclass.constructor.apply(this,[e])},e.extend(m,M.core.dialogue,{initializer:function(t){var n,r,i,s;m.superclass.initializer.call(this,t),s=this.get("boundingBox"),s.addClass("assignfeedback_editpdf_dropdown"),n=this.get("buttonNode"),r=this.bodyNode,i=e.Node.create("

"),i.addClass("accesshide"),i.setHTML(this.get("headerText")),r.prepend(i),r.on("clickoutside",function(e){this.get("visible")&&e.target!==n&&e.target.ancestor()!==n&&(e.preventDefault(),this.hide())},this),n.on("click",function(e){e.preventDefault(),this.show()},this),n.on("key",this.show,"enter,space",this)},show:function(){var t=this.get("buttonNode");result=m.superclass.show.call(this),this.align(t,[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL])}},{NAME:v,ATTRS:{headerText:{value:""},buttonNode:{value:null}}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.dropdown=m;var g="Colourpicker",b;b=function(e){b.superclass.constructor.apply(this,[e])},e.extend(b,M.assignfeedback_editpdf.dropdown,{initializer:function(t){var n=e.Node.create('