[pdf] Locks for markup annots

This commit is contained in:
Nikita Khromov
2024-11-26 17:15:56 +07:00
parent 23acfa6e79
commit ca91f95f72
5 changed files with 471 additions and 404 deletions

View File

@ -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]);

View File

@ -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;

View File

@ -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);

View File

@ -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) {

View File

@ -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;
}
if (this.m_oContext)
this.m_oContext.strokeStyle = "rgb(" + r + "," + g + "," + b + "," + a / 255 +")";
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;
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())
function CPDFGraphics()
{
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;
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;
ctx.rect(_x, _y, _r - _x, _b - _y);
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
{
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;
};
CPDFGraphics.prototype.GetIntegerGrid = function() {
return this.bIntegerGrid;
};
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();
CPDFGraphics.prototype.SetStrokeStyle = function(r,g,b,a) {
if (a == undefined) {
a = 255;
}
if (this.m_oContext)
this.m_oContext.strokeStyle = "rgb(" + r + "," + g + "," + b + "," + a / 255 +")";
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;
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();
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 (this.GetIntegerGrid()) {
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;
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();
var _x = (tr.TransformPointX(x,y)) >> 0;
var _y = (tr.TransformPointY(x,y)) >> 0;
ctx.lineTo(_x + 0.5,_y + 0.5);
ctx.setTransform(
tr.sx, // масштаб по оси X
tr.shy, // наклон по оси Y
tr.shx, // наклон по оси X
tr.sy, // масштаб по оси Y
tr.tx, // сдвиг по оси X
tr.ty // сдвиг по оси Y
);
}
else {
ctx.save();
this.EnableTransform();
ctx.lineTo(x,y);
ctx.restore();
}
};
CPDFGraphics.prototype.FillRect = function(x, y, w, h) {
var ctx = this.m_oContext;
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;
if (this.GetIntegerGrid()) {
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;
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();
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;
let _x = Math.floor(tr.TransformPointX(dx, dy));
let _y = Math.floor(tr.TransformPointY(dx, dy));
let context = this.m_oContext;
context.save();
context.translate(_x, _y);
if (rot && rot !== 0) {
let W = image.width;
let H = image.height;
context.translate(Math.floor(W / 2), Math.floor(H / 2));
context.rotate(rot);
context.translate(Math.floor(-W / 2), Math.floor(-H / 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();
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.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.arc(x, y, radius, startAng, endAng, counterClockwise);
ctx.restore();
}
};
CPDFGraphics.prototype.DrawImageXY = function(image, dx, dy, rot) {
let tr = this.GetTransform();
};
CPDFGraphics.prototype.ArcTo = function(x1, y1, x2, y2, r) {
let ctx = this.GetContext();
let _x = Math.floor(tr.TransformPointX(dx, dy));
let _y = Math.floor(tr.TransformPointY(dx, dy));
ctx.save();
this.EnableTransform();
ctx.arcTo(x1, y1, x2, y2, r);
ctx.restore();
};
CPDFGraphics.prototype.Fill = function() {
let ctx = this.GetContext();
let context = this.m_oContext;
ctx.save();
this.EnableTransform();
ctx.fill();
ctx.restore();
};
CPDFGraphics.prototype.ClearRect = function(x, y, w, h) {
let ctx = this.GetContext();
context.save();
context.translate(_x, _y);
ctx.save();
this.EnableTransform();
ctx.clearRect(x, y, w, h);
ctx.restore();
};
CPDFGraphics.prototype.HorLine = function(x1, x2, y) {
let ctx = this.GetContext();
if (rot && rot !== 0) {
let W = image.width;
let H = image.height;
let nLineW = this.GetLineWidth(true);
context.translate(Math.floor(W / 2), Math.floor(H / 2));
context.rotate(rot);
context.translate(Math.floor(-W / 2), Math.floor(-H / 2));
}
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;
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 nLineOffsetY = (0 === (nLineW % 2) ? 0 : 0.5);
ctx.setTransform(
tr.sx, // масштаб по оси X
tr.shy, // наклон по оси Y
tr.shx, // наклон по оси X
tr.sy, // масштаб по оси Y
tr.tx, // сдвиг по оси X
tr.ty // сдвиг по оси Y
);
ctx.moveTo(_x1, _y + nLineOffsetY);
ctx.lineTo(_x2, _y + nLineOffsetY);
};
CPDFGraphics.prototype.VerLine = function(y1, y2, x) {
let ctx = this.GetContext();
ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
let nLineW = this.GetLineWidth(true);
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 tr = this.GetTransform();
var _y1 = (tr.TransformPointX(x,y1)) >> 0;
var _y2 = (tr.TransformPointX(x,y2)) >> 0;
var _x = (tr.TransformPointY(y1,x)) >> 0;
CPDFGraphics.prototype.Arc = function(x, y, radius, startAng, endAng, counterClockwise) {
let ctx = this.GetContext();
let nLineOffsetX = (0 === (nLineW % 2) ? 0 : 0.5);
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();
let nLineW = this.GetLineWidth(true);
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;
let nLineOffsetX = (0 === (nLineW % 2) ? 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;
if (Asc.editor.WordControl) {
if (lock_type === AscCommon.c_oAscLockTypes.kLockTypeMine && true === AscCommon.CollaborativeEditing.Is_Fast())
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.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 w_dot = 2;
let w_dist = 2;
let eps = 5;
let tr = this.GetTransform();
let _x = (tr.TransformPointX(x, y) >> 0) - eps + 0.5;
let _y = (tr.TransformPointY(x, y) >> 0) - eps + 0.5;
let _r = (tr.TransformPointX(x + w, y + h) >> 0) + eps + 0.5;
let _b = (tr.TransformPointY(x + w, y + h) >> 0) + eps + 0.5;
this.BeginPath();
for (let i = _x; i < _r; i += w_dist) {
ctx.moveTo(i, _y);
i += w_dot;
if (i > _r)
i = _r;
ctx.lineTo(i, _y);
}
for (let i = _y; i < _b; i += w_dist) {
ctx.moveTo(_r, i);
i += w_dot;
if (i > _b)
i = _b;
ctx.lineTo(_r, i);
}
for (let i = _r; i > _x; i -= w_dist) {
ctx.moveTo(i, _b);
i -= w_dot;
if (i < _x)
i = _x;
ctx.lineTo(i, _b);
}
for (let i = _b; i > _y; i -= w_dist) {
ctx.moveTo(_x, i);
i -= w_dot;
if (i < _y)
i = _y;
ctx.lineTo(_x, i);
}
ctx.stroke();
if (!bIsInt)
this.SetIntegerGrid(false);
};
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'] || {};