diff --git a/apps/documenteditor/main/app/template/ImageSettings.template b/apps/documenteditor/main/app/template/ImageSettings.template index 0976f8f32..7160c4105 100644 --- a/apps/documenteditor/main/app/template/ImageSettings.template +++ b/apps/documenteditor/main/app/template/ImageSettings.template @@ -17,6 +17,11 @@ + + + + +
diff --git a/apps/documenteditor/main/app/view/ImageSettings.js b/apps/documenteditor/main/app/view/ImageSettings.js index 90d5fc967..6b7243c99 100644 --- a/apps/documenteditor/main/app/view/ImageSettings.js +++ b/apps/documenteditor/main/app/view/ImageSettings.js @@ -151,6 +151,11 @@ define([ }); this.lockedControls.push(this.btnOriginalSize); + this.btnFitMargins = new Common.UI.Button({ + el: $('#image-button-fit-margins') + }); + this.lockedControls.push(this.btnFitMargins); + this.btnInsertFromFile = new Common.UI.Button({ el: $('#image-button-from-file') }); @@ -176,6 +181,7 @@ define([ if (this.api) this.api.asc_startEditCurrentOleObject(); this.fireEvent('editcomplete', this); }, this)); + this.btnFitMargins.on('click', _.bind(this.setFitMargins, this)); this.linkAdvanced = $('#image-advanced-link'); this.lblReplace = $('#image-lbl-replace'); @@ -305,6 +311,57 @@ define([ } }, + setFitMargins: function() { + if (this.api) { + var section = this.api.asc_GetSectionProps(), + ratio = (this._state.Height>0) ? this._state.Width/this._state.Height : 1, + pagew = section.get_W() - section.get_LeftMargin() - section.get_RightMargin(), + pageh = section.get_H() - section.get_TopMargin() - section.get_BottomMargin(), + pageratio = pagew/pageh, + w, h; + + if (ratio>pageratio) { + w = pagew; + h = w/ratio; + } else if (ratio=1) { + var position = new Asc.CImagePositionH(); + position.put_UseAlign(true); + position.put_Percent(false); + position.put_RelativeFrom(Asc.c_oAscRelativeFromH.Margin); + position.put_Align(Asc.c_oAscAlignH.Left); + properties.put_PositionH(position); + } + if (ratio<=1) { + position = new Asc.CImagePositionV(); + position.put_UseAlign(true); + position.put_Percent(false); + position.put_RelativeFrom(Asc.c_oAscRelativeFromV.Margin); + position.put_Align(Asc.c_oAscAlignV.Top); + properties.put_PositionV(position); + } + } + + this.api.ImgApply(properties); + this.fireEvent('editcomplete', this); + } + }, + insertFromUrl: function() { var me = this; (new Common.Views.ImageFromUrlDialog({ @@ -397,7 +454,8 @@ define([ txtBehind: 'Behind', txtInFront: 'In front', textEditObject: 'Edit Object', - textEdit: 'Edit' + textEdit: 'Edit', + textFitMargins: 'Fit to Margin' }, DE.Views.ImageSettings || {})); }); \ No newline at end of file diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index 509f8293e..889e70e7d 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -1019,6 +1019,7 @@ "DE.Views.ImageSettings.txtThrough": "Through", "DE.Views.ImageSettings.txtTight": "Tight", "DE.Views.ImageSettings.txtTopAndBottom": "Top and bottom", + "DE.Views.ImageSettings.textFitMargins": "Fit to Margin", "DE.Views.ImageSettingsAdvanced.cancelButtonText": "Cancel", "DE.Views.ImageSettingsAdvanced.okButtonText": "OK", "DE.Views.ImageSettingsAdvanced.strMargins": "Text Padding",