diff --git a/pdf/api.js b/pdf/api.js index 8f8e540ebe..13079c8520 100644 --- a/pdf/api.js +++ b/pdf/api.js @@ -623,7 +623,9 @@ let oFile = oViewer.file; let oDoc = this.getPDFDoc(); - let nPos = bBefore ? oViewer.currentPage : oViewer.currentPage + 1; + let oThumbnails = oViewer.thumbnails; + let aIndexes = oThumbnails.getSelectedPages(); + let nPos = bBefore ? Math.min.apply(null, aIndexes) : Math.max.apply(null, aIndexes) + 1; oDoc.DoAction(function() { let oPageToClone = bBefore ? oFile.pages[oViewer.currentPage] : (oFile.pages[oViewer.currentPage + 1] || oFile.pages[oViewer.currentPage]); diff --git a/pdf/src/annotations/highlights.js b/pdf/src/annotations/highlights.js index b8fe07f750..a82b5d38d9 100644 --- a/pdf/src/annotations/highlights.js +++ b/pdf/src/annotations/highlights.js @@ -205,12 +205,9 @@ y: aPoints[7] } - let dx1 = oPoint2.x - oPoint1.x; - let dy1 = oPoint2.y - oPoint1.y; - let dx2 = oPoint4.x - oPoint3.x; - let dy2 = oPoint4.y - oPoint3.y; - let angle1 = Math.atan2(dy1, dx1); - let angle2 = Math.atan2(dy2, dx2); + let dx = oPoint2.x - oPoint1.x; + let dy = oPoint2.y - oPoint1.y; + let angle1 = Math.atan2(dy, dx); let rotationAngle = angle1; oGraphicsPDF.SetGlobalAlpha(this.GetOpacity()); @@ -237,6 +234,9 @@ oGraphicsPDF.Fill(); AscPDF.endMultiplyMode(oGraphicsPDF.GetContext()); } + + let aUnitedRegion = this.GetUnitedRegion(); + oGraphicsPDF.DrawLockObjectRect(this.Lock.Get_Type(), aUnitedRegion.regions); }; /** @@ -317,6 +317,9 @@ oGraphicsPDF.Stroke(); } + + let aUnitedRegion = this.GetUnitedRegion(); + oGraphicsPDF.DrawLockObjectRect(this.Lock.Get_Type(), aUnitedRegion.regions); }; /** @@ -391,6 +394,9 @@ oGraphicsPDF.Stroke(); } + + let aUnitedRegion = this.GetUnitedRegion(); + oGraphicsPDF.DrawLockObjectRect(this.Lock.Get_Type(), aUnitedRegion.regions); }; /** @@ -471,6 +477,9 @@ oGraphicsPDF.Stroke(); } + + let aUnitedRegion = this.GetUnitedRegion(); + oGraphicsPDF.DrawLockObjectRect(this.Lock.Get_Type(), aUnitedRegion.regions); }; let CARET_SYMBOL = { @@ -558,6 +567,9 @@ oGraphicsPDF.Stroke(); } + + let aUnitedRegion = this.GetUnitedRegion(); + oGraphicsPDF.DrawLockObjectRect(this.Lock.Get_Type(), aUnitedRegion.regions); }; CAnnotationCaret.prototype.SetCaretSymbol = function(nType) { this._caretSymbol = nType; diff --git a/pdf/src/annotations/text.js b/pdf/src/annotations/text.js index 1e326731fe..1bda780907 100644 --- a/pdf/src/annotations/text.js +++ b/pdf/src/annotations/text.js @@ -253,7 +253,14 @@ oCtx.restore(); - oGraphics.DrawLockObjectRect(this.Lock.Get_Type(), nX, nY, 20 / oDoc.Viewer.zoom, 20 / oDoc.Viewer.zoom); + let aRegions = [[ + [nX + nWidth, nY], + [nX, nY], + [nX, nY + nHeight], + [nX + nWidth, nY + nHeight] + ]]; + + oGraphics.DrawLockObjectRect(this.Lock.Get_Type(), aRegions); //// draw rect // oGraphics.SetLineWidth(1); // oGraphics.SetStrokeStyle(0, 255, 255); diff --git a/pdf/src/document.js b/pdf/src/document.js index 0e1751fddb..0a71672f37 100644 --- a/pdf/src/document.js +++ b/pdf/src/document.js @@ -5804,10 +5804,13 @@ var CPresentation = CPresentation || function(){}; if (false == [AscCommon.c_oAscLockTypes.kLockTypeMine, AscCommon.c_oAscLockTypes.kLockTypeNone].includes(oCurPageInfo.Lock.Type)) return true; - let selected_objects = oController.selectedObjects; + let selected_objects = oController.selectedObjects.slice(); if (oController.selection.groupSelection) { selected_objects.push(oController.selection.groupSelection); } + if (this.mouseDownAnnot) { + selected_objects.push(this.mouseDownAnnot); + } if (isRestrictionView) { for (let i = 0; i < selected_objects.length; i++) { @@ -5855,10 +5858,13 @@ var CPresentation = CPresentation || function(){}; case AscCommon.changestype_2_Comment: { let sCommentId = AdditionalData; - let selected_objects = oController.selectedObjects; + let selected_objects = oController.selectedObjects.slice(); if (oController.selection.groupSelection) { selected_objects.push(oController.selection.groupSelection); } + if (this.mouseDownAnnot) { + selected_objects.push(this.mouseDownAnnot); + } for (let i = 0; i < selected_objects.length; ++i) { if (selected_objects[i].GetId() == sCommentId) { diff --git a/pdf/src/graphics.js b/pdf/src/graphics.js index 21132fd123..5fa84bb60e 100644 --- a/pdf/src/graphics.js +++ b/pdf/src/graphics.js @@ -34,429 +34,469 @@ (function(window, undefined){ -function CPDFGraphics() -{ - this.m_oContext = null; - this.m_lWidthPix = undefined; - this.m_lHeightPix = undefined; - this.m_dPageWidthPix = undefined; - this.m_dPageHeightPix = undefined; - this.lineWidth = 1; - this.fillStyle = null; - this.strokeStyle = null; - this.globalAlpha = 1; - this.bIntegerGrid = false; - - this.m_oCoordTransform = new AscCommon.CMatrix(); -} -CPDFGraphics.prototype.SetCurPage = function(nPage) { - this.curPage = nPage; -}; -CPDFGraphics.prototype.GetCurPage = function() { - return this.curPage; -}; -CPDFGraphics.prototype.GetDrawingPageW = function() { - return this.m_lWidthPix; -}; -CPDFGraphics.prototype.GetDrawingPageH = function() { - return this.m_lHeightPix; -}; -CPDFGraphics.prototype.Clip = function() { - this.m_oContext.clip(); -}; -CPDFGraphics.prototype.SetIntegerGrid = function(bInteger) { - this.bIntegerGrid = bInteger; - - if (true == bInteger) { - this.bIntegerGrid = true; - this.m_oContext.setTransform(1,0,0,1,0,0); - } - else { - this.bIntegerGrid = false; - } -}; -CPDFGraphics.prototype.GetIntegerGrid = function() { - return this.bIntegerGrid; -}; - -CPDFGraphics.prototype.SetStrokeStyle = function(r,g,b,a) { - if (a == undefined) { - a == 255; + function CPDFGraphics() + { + this.m_oContext = null; + this.m_lWidthPix = undefined; + this.m_lHeightPix = undefined; + this.m_dPageWidthPix = undefined; + this.m_dPageHeightPix = undefined; + this.lineWidth = 1; + this.fillStyle = null; + this.strokeStyle = null; + this.globalAlpha = 1; + this.bIntegerGrid = false; + + this.m_oCoordTransform = new AscCommon.CMatrix(); } - - if (this.m_oContext) - this.m_oContext.strokeStyle = "rgb(" + r + "," + g + "," + b + "," + a / 255 +")"; - - this.strokeStyle = { - r: r, - g: g, - b: b + CPDFGraphics.prototype.SetCurPage = function(nPage) { + this.curPage = nPage; }; -}; -CPDFGraphics.prototype.SetFillStyle = function(r,g,b) { - if (this.m_oContext) - this.m_oContext.fillStyle = "rgb(" + r + "," + g + "," + b + ")"; - - this.fillStyle = { - r: r, - g: g, - b: b + CPDFGraphics.prototype.GetCurPage = function() { + return this.curPage; }; -}; -CPDFGraphics.prototype.SetLineWidth = function(width) { - if (this.m_oContext) - this.m_oContext.lineWidth = width + 0.5 >> 0; - - this.lineWidth = width; -}; -CPDFGraphics.prototype.GetLineWidth = function(bTransform) { - if (!bTransform) - return this.lineWidth; - - let tr = this.GetTransform(); - return this.lineWidth * tr.sy + 0.5 >> 0; -}; -CPDFGraphics.prototype.Init = function(context, nWidthPx, nHeightPx, nPageWidthPx, nPageHeightPx) { - this.m_oContext = context; - this.m_lWidthPix = nWidthPx; - this.m_lHeightPix = nHeightPx; - - this.m_dPageWidthPix = nPageWidthPx; - this.m_dPageHeightPix = nPageHeightPx; - - this.m_oCoordTransform.sx = this.m_lWidthPix / this.m_dPageWidthPix; - this.m_oCoordTransform.sy = this.m_lHeightPix / this.m_dPageHeightPix; -}; -CPDFGraphics.prototype.GetTransform = function() { - return this.m_oCoordTransform; -}; -CPDFGraphics.prototype.GetContext = function() { - return this.m_oContext; -} -CPDFGraphics.prototype.Rect = function(x, y, w, h) { - let ctx = this.GetContext(); - ctx.beginPath(); - - if (this.GetIntegerGrid()) - { - let tr = this.GetTransform(); - if (0.0 === tr.shx && 0.0 === tr.shy) - { - let _x = (tr.TransformPointX(x, y) + 0.5) >> 0; - let _y = (tr.TransformPointY(x, y) + 0.5) >> 0; - let _r = (tr.TransformPointX(x + w, y) + 0.5) >> 0; - let _b = (tr.TransformPointY(x, y + h) + 0.5) >> 0; + CPDFGraphics.prototype.GetDrawingPageW = function() { + return this.m_lWidthPix; + }; + CPDFGraphics.prototype.GetDrawingPageH = function() { + return this.m_lHeightPix; + }; + CPDFGraphics.prototype.Clip = function() { + this.m_oContext.clip(); + }; + CPDFGraphics.prototype.SetIntegerGrid = function(bInteger) { + this.bIntegerGrid = bInteger; - ctx.rect(_x, _y, _r - _x, _b - _y); + if (true == bInteger) { + this.bIntegerGrid = true; + this.m_oContext.setTransform(1,0,0,1,0,0); } - else - { - let x1 = tr.TransformPointX(x, y); - let y1 = tr.TransformPointY(x, y); - let x2 = tr.TransformPointX(x + w, y); - let y2 = tr.TransformPointY(x + w, y); - let x3 = tr.TransformPointX(x + w, y + h); - let y3 = tr.TransformPointY(x + w, y + h); - let x4 = tr.TransformPointX(x, y + h); - let y4 = tr.TransformPointY(x, y + h); - - ctx.moveTo(x1, y1); - ctx.lineTo(x2, y2); - ctx.lineTo(x3, y3); - ctx.lineTo(x4, y4); - ctx.closePath(); + else { + this.bIntegerGrid = false; } - } - else { - ctx.save(); - this.EnableTransform(); - ctx.rect(x, y, w, h); - ctx.restore(); - } -}; -CPDFGraphics.prototype.EnableTransform = function() { - let ctx = this.GetContext(); - let tr = this.GetTransform(); - - ctx.setTransform( - tr.sx, // масштаб по оси X - tr.shy, // наклон по оси Y - tr.shx, // наклон по оси X - tr.sy, // масштаб по оси Y - tr.tx, // сдвиг по оси X - tr.ty // сдвиг по оси Y - ); -} -CPDFGraphics.prototype.BeginPath = function() { - this.m_oContext.beginPath(); -}; -CPDFGraphics.prototype.ClosePath = function() { - this.m_oContext.closePath(); -}; -CPDFGraphics.prototype.Stroke = function() { - let ctx = this.GetContext(); - let tr = this.GetTransform(); - let nLineW = this.lineWidth; - - let _nLineW = nLineW * tr.sy + 0.5 >> 0; - - ctx.lineWidth = _nLineW; - ctx.stroke(); - ctx.lineWidth = nLineW; -}; -CPDFGraphics.prototype.MoveTo = function(x, y) { - let ctx = this.GetContext(); - - if (this.GetIntegerGrid()) { - let tr = this.GetTransform(); - var _x = (tr.TransformPointX(x,y)) >> 0; - var _y = (tr.TransformPointY(x,y)) >> 0; - ctx.moveTo(_x + 0.5,_y + 0.5); - } - else { - ctx.save(); - this.EnableTransform(); - ctx.moveTo(x,y); - ctx.restore(); - } -}; -CPDFGraphics.prototype.LineTo = function(x, y) { - let ctx = this.GetContext(); - - if (this.GetIntegerGrid()) { - let tr = this.GetTransform(); - var _x = (tr.TransformPointX(x,y)) >> 0; - var _y = (tr.TransformPointY(x,y)) >> 0; - ctx.lineTo(_x + 0.5,_y + 0.5); - } - else { - ctx.save(); - this.EnableTransform(); - ctx.lineTo(x,y); - ctx.restore(); - } -}; -CPDFGraphics.prototype.FillRect = function(x, y, w, h) { - var ctx = this.m_oContext; - - if (this.GetIntegerGrid()) { - let tr = this.GetTransform(); - - var _x = (tr.TransformPointX(x,y) >> 0) + 0.5; - var _y = (tr.TransformPointY(x,y) >> 0) + 0.5; - var _r = (tr.TransformPointX(x+w,y) >> 0) + 0.5; - var _b = (tr.TransformPointY(x,y+h) >> 0) + 0.5; + }; + CPDFGraphics.prototype.GetIntegerGrid = function() { + return this.bIntegerGrid; + }; - ctx.fillRect(_x - 0.5, _y - 0.5, _r - _x + 1, _b - _y + 1); - } - else { - ctx.save(); - this.EnableTransform(); - ctx.fillRect(x, y, w, h); - ctx.restore(); - } -}; -CPDFGraphics.prototype.DrawImageXY = function(image, dx, dy, rot) { - let tr = this.GetTransform(); + CPDFGraphics.prototype.SetStrokeStyle = function(r,g,b,a) { + if (a == undefined) { + a = 255; + } - let _x = Math.floor(tr.TransformPointX(dx, dy)); - let _y = Math.floor(tr.TransformPointY(dx, dy)); + if (this.m_oContext) + this.m_oContext.strokeStyle = "rgb(" + r + "," + g + "," + b + "," + a / 255 +")"; - let context = this.m_oContext; + this.strokeStyle = { + r: r, + g: g, + b: b + }; + }; + CPDFGraphics.prototype.SetFillStyle = function(r,g,b) { + if (this.m_oContext) + this.m_oContext.fillStyle = "rgb(" + r + "," + g + "," + b + ")"; + + this.fillStyle = { + r: r, + g: g, + b: b + }; + }; + CPDFGraphics.prototype.SetLineWidth = function(width) { + if (this.m_oContext) + this.m_oContext.lineWidth = width + 0.5 >> 0; + + this.lineWidth = width; + }; + CPDFGraphics.prototype.GetLineWidth = function(bTransform) { + if (!bTransform) + return this.lineWidth; - context.save(); - context.translate(_x, _y); + let tr = this.GetTransform(); + return this.lineWidth * tr.sy + 0.5 >> 0; + }; + CPDFGraphics.prototype.Init = function(context, nWidthPx, nHeightPx, nPageWidthPx, nPageHeightPx) { + this.m_oContext = context; + this.m_lWidthPix = nWidthPx; + this.m_lHeightPix = nHeightPx; - if (rot && rot !== 0) { - let W = image.width; - let H = image.height; + this.m_dPageWidthPix = nPageWidthPx; + this.m_dPageHeightPix = nPageHeightPx; - context.translate(Math.floor(W / 2), Math.floor(H / 2)); - context.rotate(rot); - context.translate(Math.floor(-W / 2), Math.floor(-H / 2)); + this.m_oCoordTransform.sx = this.m_lWidthPix / this.m_dPageWidthPix; + this.m_oCoordTransform.sy = this.m_lHeightPix / this.m_dPageHeightPix; + }; + CPDFGraphics.prototype.GetTransform = function() { + return this.m_oCoordTransform; + }; + CPDFGraphics.prototype.GetContext = function() { + return this.m_oContext; } + CPDFGraphics.prototype.Rect = function(x, y, w, h) { + let ctx = this.GetContext(); + ctx.beginPath(); - context.drawImage(image, 0, 0); - context.restore(); -}; -CPDFGraphics.prototype.DrawImage = function(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) { - let ctx = this.GetContext(); - let tr = this.GetTransform(); - - ctx.save(); - - ctx.setTransform( - tr.sx, // масштаб по оси X - tr.shy, // наклон по оси Y - tr.shx, // наклон по оси X - tr.sy, // масштаб по оси Y - tr.tx, // сдвиг по оси X - tr.ty // сдвиг по оси Y - ); - - ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight); - - ctx.restore(); -}; -CPDFGraphics.prototype.SetLineDash = function(dash) { - let tr = this.GetTransform(); - let ctx = this.GetContext(); - ctx.setLineDash(dash.map(function(measure) { - return measure * tr.sy + 0.5 >> 0; - })); -}; -CPDFGraphics.prototype.SetGlobalAlpha = function(value) { - if (this.m_oContext) - this.m_oContext.globalAlpha = value; -}; - -CPDFGraphics.prototype.Arc = function(x, y, radius, startAng, endAng, counterClockwise) { - let ctx = this.GetContext(); - - ctx.save(); - this.EnableTransform(); - ctx.arc(x, y, radius, startAng, endAng, counterClockwise); - ctx.restore(); -}; -CPDFGraphics.prototype.ArcTo = function(x1, y1, x2, y2, r) { - let ctx = this.GetContext(); - - ctx.save(); - this.EnableTransform(); - ctx.arcTo(x1, y1, x2, y2, r); - ctx.restore(); -}; -CPDFGraphics.prototype.Fill = function() { - let ctx = this.GetContext(); - - ctx.save(); - this.EnableTransform(); - ctx.fill(); - ctx.restore(); -}; -CPDFGraphics.prototype.ClearRect = function(x, y, w, h) { - let ctx = this.GetContext(); - - ctx.save(); - this.EnableTransform(); - ctx.clearRect(x, y, w, h); - ctx.restore(); -}; -CPDFGraphics.prototype.HorLine = function(x1, x2, y) { - let ctx = this.GetContext(); - - let nLineW = this.GetLineWidth(true); - - let tr = this.GetTransform(); - - var _x1 = (tr.TransformPointX(x1,y)) >> 0; - var _x2 = (tr.TransformPointX(x2,y)) >> 0; - var _y = (tr.TransformPointY(x1,y)) >> 0; - - let nLineOffsetY = (0 === (nLineW % 2) ? 0 : 0.5); - - ctx.moveTo(_x1, _y + nLineOffsetY); - ctx.lineTo(_x2, _y + nLineOffsetY); -}; -CPDFGraphics.prototype.VerLine = function(y1, y2, x) { - let ctx = this.GetContext(); + if (this.GetIntegerGrid()) + { + let tr = this.GetTransform(); + if (0.0 === tr.shx && 0.0 === tr.shy) + { + let _x = (tr.TransformPointX(x, y) + 0.5) >> 0; + let _y = (tr.TransformPointY(x, y) + 0.5) >> 0; + let _r = (tr.TransformPointX(x + w, y) + 0.5) >> 0; + let _b = (tr.TransformPointY(x, y + h) + 0.5) >> 0; + + ctx.rect(_x, _y, _r - _x, _b - _y); + } + else + { + let x1 = tr.TransformPointX(x, y); + let y1 = tr.TransformPointY(x, y); + let x2 = tr.TransformPointX(x + w, y); + let y2 = tr.TransformPointY(x + w, y); + let x3 = tr.TransformPointX(x + w, y + h); + let y3 = tr.TransformPointY(x + w, y + h); + let x4 = tr.TransformPointX(x, y + h); + let y4 = tr.TransformPointY(x, y + h); + + ctx.moveTo(x1, y1); + ctx.lineTo(x2, y2); + ctx.lineTo(x3, y3); + ctx.lineTo(x4, y4); + ctx.closePath(); + } + } + else { + ctx.save(); + this.EnableTransform(); + ctx.rect(x, y, w, h); + ctx.restore(); + } + }; + CPDFGraphics.prototype.EnableTransform = function() { + let ctx = this.GetContext(); + let tr = this.GetTransform(); + + ctx.setTransform( + tr.sx, // масштаб по оси X + tr.shy, // наклон по оси Y + tr.shx, // наклон по оси X + tr.sy, // масштаб по оси Y + tr.tx, // сдвиг по оси X + tr.ty // сдвиг по оси Y + ); + } + CPDFGraphics.prototype.BeginPath = function() { + this.m_oContext.beginPath(); + }; + CPDFGraphics.prototype.ClosePath = function() { + this.m_oContext.closePath(); + }; + CPDFGraphics.prototype.Stroke = function() { + let ctx = this.GetContext(); + let tr = this.GetTransform(); + let nLineW = this.lineWidth; - let nLineW = this.GetLineWidth(true); + let _nLineW = nLineW * tr.sy + 0.5 >> 0; + + ctx.lineWidth = _nLineW; + ctx.stroke(); + ctx.lineWidth = nLineW; + }; + CPDFGraphics.prototype.MoveTo = function(x, y) { + let ctx = this.GetContext(); + + if (this.GetIntegerGrid()) { + let tr = this.GetTransform(); + var _x = (tr.TransformPointX(x,y)) >> 0; + var _y = (tr.TransformPointY(x,y)) >> 0; + ctx.moveTo(_x + 0.5,_y + 0.5); + } + else { + ctx.save(); + this.EnableTransform(); + ctx.moveTo(x,y); + ctx.restore(); + } + }; + CPDFGraphics.prototype.LineTo = function(x, y) { + let ctx = this.GetContext(); + + if (this.GetIntegerGrid()) { + let tr = this.GetTransform(); + var _x = (tr.TransformPointX(x,y)) >> 0; + var _y = (tr.TransformPointY(x,y)) >> 0; + ctx.lineTo(_x + 0.5,_y + 0.5); + } + else { + ctx.save(); + this.EnableTransform(); + ctx.lineTo(x,y); + ctx.restore(); + } + }; + CPDFGraphics.prototype.FillRect = function(x, y, w, h) { + var ctx = this.m_oContext; - let tr = this.GetTransform(); - - var _y1 = (tr.TransformPointX(x,y1)) >> 0; - var _y2 = (tr.TransformPointX(x,y2)) >> 0; - var _x = (tr.TransformPointY(y1,x)) >> 0; + if (this.GetIntegerGrid()) { + let tr = this.GetTransform(); - let nLineOffsetX = (0 === (nLineW % 2) ? 0 : 0.5); + var _x = (tr.TransformPointX(x,y) >> 0) + 0.5; + var _y = (tr.TransformPointY(x,y) >> 0) + 0.5; + var _r = (tr.TransformPointX(x+w,y) >> 0) + 0.5; + var _b = (tr.TransformPointY(x,y+h) >> 0) + 0.5; - ctx.moveTo(nLineOffsetX + _x, _y1); - ctx.lineTo(nLineOffsetX + _x, _y2); -}; -CPDFGraphics.prototype.DrawLockObjectRect = function(lock_type, x, y, w, h) { - if (Asc.editor.isViewMode || this.IsThumbnail || this.IsDemonstrationMode || lock_type === AscCommon.c_oAscLockTypes.kLockTypeNone) - return; + ctx.fillRect(_x - 0.5, _y - 0.5, _r - _x + 1, _b - _y + 1); + } + else { + ctx.save(); + this.EnableTransform(); + ctx.fillRect(x, y, w, h); + ctx.restore(); + } + }; + CPDFGraphics.prototype.DrawImageXY = function(image, dx, dy, rot) { + let tr = this.GetTransform(); - if (Asc.editor.WordControl) { - if (lock_type === AscCommon.c_oAscLockTypes.kLockTypeMine && true === AscCommon.CollaborativeEditing.Is_Fast()) - return; - if (Asc.editor.WordControl.m_oDrawingDocument.IsLockObjectsEnable === false && lock_type === AscCommon.c_oAscLockTypes.kLockTypeMine) - return; - } + let _x = Math.floor(tr.TransformPointX(dx, dy)); + let _y = Math.floor(tr.TransformPointY(dx, dy)); - if (lock_type === AscCommon.c_oAscLockTypes.kLockTypeMine) { - this.SetStrokeStyle(22, 156, 0, 255); - } - else { - this.SetStrokeStyle(238, 53, 37, 255); - } + let context = this.m_oContext; + context.save(); + context.translate(_x, _y); - let ctx = this.m_oContext; - let bIsInt = this.m_bIntegerGrid; - if (!bIsInt) - this.SetIntegerGrid(true); + if (rot && rot !== 0) { + let W = image.width; + let H = image.height; - ctx.lineWidth = 1; + context.translate(Math.floor(W / 2), Math.floor(H / 2)); + context.rotate(rot); + context.translate(Math.floor(-W / 2), Math.floor(-H / 2)); + } - let w_dot = 2; - let w_dist = 2; + context.drawImage(image, 0, 0); + context.restore(); + }; + CPDFGraphics.prototype.DrawImage = function(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) { + let ctx = this.GetContext(); + let tr = this.GetTransform(); + + ctx.save(); - let eps = 5; + ctx.setTransform( + tr.sx, // масштаб по оси X + tr.shy, // наклон по оси Y + tr.shx, // наклон по оси X + tr.sy, // масштаб по оси Y + tr.tx, // сдвиг по оси X + tr.ty // сдвиг по оси Y + ); - let tr = this.GetTransform(); + ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight); - let _x = (tr.TransformPointX(x, y) >> 0) - eps + 0.5; - let _y = (tr.TransformPointY(x, y) >> 0) - eps + 0.5; + ctx.restore(); + }; + CPDFGraphics.prototype.SetLineDash = function(dash) { + let tr = this.GetTransform(); + let ctx = this.GetContext(); + ctx.setLineDash(dash.map(function(measure) { + return measure * tr.sy + 0.5 >> 0; + })); + }; + CPDFGraphics.prototype.SetGlobalAlpha = function(value) { + if (this.m_oContext) + this.m_oContext.globalAlpha = value; + }; - let _r = (tr.TransformPointX(x + w, y + h) >> 0) + eps + 0.5; - let _b = (tr.TransformPointY(x + w, y + h) >> 0) + eps + 0.5; + CPDFGraphics.prototype.Arc = function(x, y, radius, startAng, endAng, counterClockwise) { + let ctx = this.GetContext(); - this.BeginPath(); + ctx.save(); + this.EnableTransform(); + ctx.arc(x, y, radius, startAng, endAng, counterClockwise); + ctx.restore(); + }; + CPDFGraphics.prototype.ArcTo = function(x1, y1, x2, y2, r) { + let ctx = this.GetContext(); - for (let i = _x; i < _r; i += w_dist) { - ctx.moveTo(i, _y); - i += w_dot; + ctx.save(); + this.EnableTransform(); + ctx.arcTo(x1, y1, x2, y2, r); + ctx.restore(); + }; + CPDFGraphics.prototype.Fill = function() { + let ctx = this.GetContext(); - if (i > _r) - i = _r; + ctx.save(); + this.EnableTransform(); + ctx.fill(); + ctx.restore(); + }; + CPDFGraphics.prototype.ClearRect = function(x, y, w, h) { + let ctx = this.GetContext(); - ctx.lineTo(i, _y); - } - for (let i = _y; i < _b; i += w_dist) { - ctx.moveTo(_r, i); - i += w_dot; + ctx.save(); + this.EnableTransform(); + ctx.clearRect(x, y, w, h); + ctx.restore(); + }; + CPDFGraphics.prototype.HorLine = function(x1, x2, y) { + let ctx = this.GetContext(); - if (i > _b) - i = _b; + let nLineW = this.GetLineWidth(true); - ctx.lineTo(_r, i); - } - for (let i = _r; i > _x; i -= w_dist) { - ctx.moveTo(i, _b); - i -= w_dot; + let tr = this.GetTransform(); + + var _x1 = (tr.TransformPointX(x1,y)) >> 0; + var _x2 = (tr.TransformPointX(x2,y)) >> 0; + var _y = (tr.TransformPointY(x1,y)) >> 0; - if (i < _x) - i = _x; + let nLineOffsetY = (0 === (nLineW % 2) ? 0 : 0.5); - ctx.lineTo(i, _b); - } - for (let i = _b; i > _y; i -= w_dist) { - ctx.moveTo(_x, i); - i -= w_dot; + ctx.moveTo(_x1, _y + nLineOffsetY); + ctx.lineTo(_x2, _y + nLineOffsetY); + }; + CPDFGraphics.prototype.VerLine = function(y1, y2, x) { + let ctx = this.GetContext(); - if (i < _y) - i = _y; + let nLineW = this.GetLineWidth(true); - ctx.lineTo(_x, i); - } + let tr = this.GetTransform(); + + var _y1 = (tr.TransformPointX(x,y1)) >> 0; + var _y2 = (tr.TransformPointX(x,y2)) >> 0; + var _x = (tr.TransformPointY(y1,x)) >> 0; - ctx.stroke(); + let nLineOffsetX = (0 === (nLineW % 2) ? 0 : 0.5); - if (!bIsInt) - this.SetIntegerGrid(false); -}; + ctx.moveTo(nLineOffsetX + _x, _y1); + ctx.lineTo(nLineOffsetX + _x, _y2); + }; + CPDFGraphics.prototype.DrawLockObjectRect = function(lock_type, aRegions) { + if (Asc.editor.isViewMode || this.IsThumbnail || this.IsDemonstrationMode || lock_type === AscCommon.c_oAscLockTypes.kLockTypeNone) + return; + + if (Asc.editor.WordControl) { + if (lock_type === AscCommon.c_oAscLockTypes.kLockTypeMine && true === AscCommon.CollaborativeEditing.Is_Fast()) + return; + if (Asc.editor.WordControl.m_oDrawingDocument.IsLockObjectsEnable === false && lock_type === AscCommon.c_oAscLockTypes.kLockTypeMine) + return; + } + + if (lock_type === AscCommon.c_oAscLockTypes.kLockTypeMine) { + this.SetStrokeStyle(22, 156, 0, 255); + } else { + this.SetStrokeStyle(238, 53, 37, 255); + } + + let ctx = this.m_oContext; + let bIsInt = this.m_bIntegerGrid; + if (!bIsInt) + this.SetIntegerGrid(true); + + ctx.lineWidth = 1; + + let eps = 5; // Коэффициент расширения + + let tr = this.GetTransform(); + + ctx.beginPath(); + for (let i = 0; i < aRegions.length; i++) { + let aPoints = aRegions[i]; // Массив точек [[x1, y1], [x2, y2], ..., [xn, yn]] + let expandedPoints = []; + + let numPoints = aPoints.length; + for (let j = 0; j < numPoints; j++) { + let current = aPoints[j]; + let next = aPoints[(j + 1) % numPoints]; + + // Векторы текущего и следующего ребра + let dx1 = next[0] - current[0]; + let dy1 = next[1] - current[1]; + let dx2 = aPoints[(j + 2) % numPoints][0] - next[0]; + let dy2 = aPoints[(j + 2) % numPoints][1] - next[1]; + + // Нормали к ребрам + let len1 = Math.sqrt(dx1 * dx1 + dy1 * dy1); + let len2 = Math.sqrt(dx2 * dx2 + dy2 * dy2); + let nx1 = -dy1 / len1; + let ny1 = dx1 / len1; + let nx2 = -dy2 / len2; + let ny2 = dx2 / len2; + + // Усредненная нормаль + let avgNx = (nx1 + nx2) / 2; + let avgNy = (ny1 + ny2) / 2; + + // Нормализуем усредненную нормаль + let avgLen = Math.sqrt(avgNx * avgNx + avgNy * avgNy); + if (avgLen === 0) { + avgNx = 0; + avgNy = 0; + } else { + avgNx /= avgLen; + avgNy /= avgLen; + } + + // Смещение точки + let x_expanded = next[0] + avgNx * eps; + let y_expanded = next[1] + avgNy * eps; + + // Преобразуем координаты + let tx = tr.TransformPointX(x_expanded, y_expanded); + let ty = tr.TransformPointY(x_expanded, y_expanded); + + expandedPoints.push([tx, ty]); + } + + // Рисуем пунктир вручную + let w_dot = 2; // Длина штриха + let w_dist = 2; // Расстояние между штрихами + + for (let j = 0; j < expandedPoints.length; j++) { + let start = expandedPoints[j]; + let end = expandedPoints[(j + 1) % expandedPoints.length]; + + let dx = end[0] - start[0]; + let dy = end[1] - start[1]; + let length = Math.sqrt(dx * dx + dy * dy); + + let stepX = (dx / length) * w_dist; + let stepY = (dy / length) * w_dist; + + let x = start[0]; + let y = start[1]; + let dist = 0; + + while (dist < length) { + ctx.moveTo(x, y); + x += (dx / length) * w_dot; + y += (dy / length) * w_dot; + dist += w_dot; + + if (dist > length) { + x = end[0]; + y = end[1]; + } + + ctx.lineTo(x, y); + + x += stepX; + y += stepY; + dist += w_dist; + } + } + + ctx.stroke(); + } + + if (!bIsInt) + this.SetIntegerGrid(false); + }; + + //------------------------------------------------------------export---------------------------------------------------- window['AscPDF'] = window['AscPDF'] || {};