Skip to content

Commit

Permalink
[pdf] Move pages
Browse files Browse the repository at this point in the history
  • Loading branch information
KhromovNikita committed Feb 4, 2025
1 parent 5da1111 commit b94c47d
Show file tree
Hide file tree
Showing 21 changed files with 621 additions and 301 deletions.
3 changes: 2 additions & 1 deletion common/Drawings/TrackObjects/MoveTracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,8 @@ function MoveAnnotationTrack(originalObject)
{
// рисуем на отдельном канвасе
let nPage = this.pageIndex;
this.objectToDraw.SetPage(nPage);
let oPageInfo = this.viewer.doc.GetPageInfo(this.pageIndex);
this.objectToDraw.SetParentPage(oPageInfo);

let page = this.viewer.drawingPages[nPage];
if (!page)
Expand Down
2 changes: 2 additions & 0 deletions common/HistoryCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4087,6 +4087,7 @@
window['AscDFH'].historyitem_PDF_Document_RotatePage = window['AscDFH'].historyitem_type_PDF_Document | 5;
window['AscDFH'].historyitem_PDF_Document_RecognizePage = window['AscDFH'].historyitem_type_PDF_Document | 6;
window['AscDFH'].historyitem_PDF_Document_SetDocument = window['AscDFH'].historyitem_type_PDF_Document | 7;
window['AscDFH'].historyitem_PDF_Document_MovePage = window['AscDFH'].historyitem_type_PDF_Document | 8;


AscDFH.historyitem_CustomPropertiesAddProperty = AscDFH.historyitem_type_CustomProperties | 0;
Expand Down Expand Up @@ -4574,6 +4575,7 @@
window['AscDFH'].historydescription_Pdf_ChangeStrokeColor = 0x2b1;
window['AscDFH'].historydescription_Pdf_ChangeFillColor = 0x2b2;
window['AscDFH'].historydescription_Pdf_ChangeOpacity = 0x2b3;
window['AscDFH'].historydescription_Pdf_MovePage = 0x2b4;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
48 changes: 20 additions & 28 deletions pdf/src/annotations/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* Class representing a base annotation.
* @constructor
*/
function CAnnotationBase(sName, nType, nPage, aOrigRect, oDoc)
function CAnnotationBase(sName, nType, aOrigRect, oDoc)
{
// если аннотация не shape based
if (this.Id == undefined) {
Expand All @@ -63,7 +63,6 @@
this._modDate = undefined;
this._name = undefined;
this._opacity = 1;
this._page = undefined;
this._origRect = [];
this._refType = undefined;
this._seqNum = undefined;
Expand Down Expand Up @@ -96,7 +95,6 @@

this.SetDocument(oDoc);
this.SetName(sName);
this.SetPage(nPage);
this.SetRect(aOrigRect);
};
CAnnotationBase.prototype = Object.create(AscFormat.CBaseNoIdObject.prototype);
Expand Down Expand Up @@ -612,39 +610,33 @@
this.parentPage = oParent;
};
CAnnotationBase.prototype.GetParentPage = function() {
let oReplyTo = this.GetReplyTo();
if (oReplyTo && !this.parentPage) {
return oReplyTo.GetParentPage();
}

return this.parentPage;
};
CAnnotationBase.prototype.SetPage = function(nPage) {
let nCurPage = this.GetPage();
if (nPage == nCurPage)
if (this.GetPage() == nPage) {
return;

let oViewer = editor.getDocumentRenderer();
}

let oDoc = this.GetDocument();
let oPageInfo = oViewer.pagesInfo.pages[nCurPage];
let oNewPage = oDoc.GetPageInfo(nPage);

let nCurIdxOnPage = oPageInfo && oPageInfo.annots ? oPageInfo.annots.indexOf(this) : -1;
if (oViewer.pagesInfo.pages[nPage]) {
if (oDoc.annots.indexOf(this) != -1) {
if (nCurIdxOnPage != -1) {
oPageInfo.annots.splice(nCurIdxOnPage, 1);
}

if (this.IsUseInDocument() && oViewer.pagesInfo.pages[nPage].annots.indexOf(this) == -1)
oViewer.pagesInfo.pages[nPage].annots.push(this);

// добавляем в перерисовку исходную страницу
this.AddToRedraw();
}

oDoc.History.Add(new CChangesPDFAnnotPage(this, nCurPage, nPage));
this._page = nPage;
this.selectStartPage = nPage;
this.AddToRedraw();
if (oNewPage) {
oDoc.RemoveAnnot(this.GetId());
oDoc.AddAnnot(this, nPage);
}
};
CAnnotationBase.prototype.GetPage = function() {
return this._page;
let oParentPage = this.GetParentPage();
if (!oParentPage || !(oParentPage instanceof AscPDF.CPageInfo)) {
return -1;
}

return oParentPage.GetIndex();
};
CAnnotationBase.prototype.SetDocument = function(oDoc) {
if (this._doc == oDoc) {
Expand Down Expand Up @@ -1036,7 +1028,7 @@
let oDoc = this.GetDocument();
oDoc.StartNoHistoryMode();

let oNewAnnot = new CAnnotationBase(AscCommon.CreateGUID(), this.type, this.GetPage(), this.GetOrigRect().slice(), oDoc);
let oNewAnnot = new CAnnotationBase(AscCommon.CreateGUID(), this.type, this.GetOrigRect().slice(), oDoc);

oNewAnnot.lazyCopy = true;

Expand Down
6 changes: 3 additions & 3 deletions pdf/src/annotations/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
* Class representing a Ink annotation.
* @constructor
*/
function CAnnotationCircle(sName, nPage, aRect, oDoc)
function CAnnotationCircle(sName, aRect, oDoc)
{
AscPDF.CPdfShape.call(this);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Circle, nPage, aRect, oDoc);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Circle, aRect, oDoc);

AscPDF.initShape(this);
this.spPr.setGeometry(AscFormat.CreateGeometry("ellipse"));
Expand All @@ -66,7 +66,7 @@
let oDoc = this.GetDocument();
oDoc.StartNoHistoryMode();

let oCircle = new CAnnotationCircle(AscCommon.CreateGUID(), this.GetPage(), this.GetOrigRect().slice(), oDoc);
let oCircle = new CAnnotationCircle(AscCommon.CreateGUID(), this.GetOrigRect().slice(), oDoc);
oCircle.lazyCopy = true;

this.fillObject(oCircle);
Expand Down
6 changes: 3 additions & 3 deletions pdf/src/annotations/freeText.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
* Class representing a free text annotation.
* @constructor
*/
function CAnnotationFreeText(sName, nPage, aRect, oDoc)
function CAnnotationFreeText(sName, aRect, oDoc)
{
AscFormat.CGroupShape.call(this);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.FreeText, nPage, aRect, oDoc);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.FreeText, aRect, oDoc);

initGroupShape(this);

Expand Down Expand Up @@ -483,7 +483,7 @@
let oDoc = this.GetDocument();
oDoc.StartNoHistoryMode();

let oFreeText = new CAnnotationFreeText(AscCommon.CreateGUID(), this.GetPage(), this.GetOrigRect().slice(), oDoc);
let oFreeText = new CAnnotationFreeText(AscCommon.CreateGUID(), this.GetOrigRect().slice(), oDoc);

oFreeText.lazyCopy = true;

Expand Down
4 changes: 2 additions & 2 deletions pdf/src/annotations/highlights.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
* Class representing a base highlight annotation.
* @constructor
*/
function CAnnotationTextMarkup(sName, nType, nPage, aRect, oDoc)
function CAnnotationTextMarkup(sName, nType, aRect, oDoc)
{
AscPDF.CAnnotationBase.call(this, sName, nType, nPage, aRect, oDoc);
AscPDF.CAnnotationBase.call(this, sName, nType, aRect, oDoc);

this._quads = [];
this._richContents = undefined;
Expand Down
6 changes: 3 additions & 3 deletions pdf/src/annotations/ink.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
* Class representing a Ink annotation.
* @constructor
*/
function CAnnotationInk(sName, nPage, aRect, oDoc)
function CAnnotationInk(sName, aRect, oDoc)
{
AscPDF.CPdfShape.call(this);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Ink, nPage, aRect, oDoc);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Ink, aRect, oDoc);

AscCommon.History.StartNoHistoryMode();
initShape(this);
Expand Down Expand Up @@ -342,7 +342,7 @@
let oDoc = this.GetDocument();
oDoc.StartNoHistoryMode();

let oNewInk = new CAnnotationInk(AscCommon.CreateGUID(), this.GetPage(), this.GetOrigRect().slice(), oDoc);
let oNewInk = new CAnnotationInk(AscCommon.CreateGUID(), this.GetOrigRect().slice(), oDoc);

oNewInk.lazyCopy = true;

Expand Down
6 changes: 3 additions & 3 deletions pdf/src/annotations/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
* Class representing a Ink annotation.
* @constructor
*/
function CAnnotationLine(sName, nPage, aRect, oDoc)
function CAnnotationLine(sName, aRect, oDoc)
{
AscPDF.CPdfShape.call(this);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Line, nPage, aRect, oDoc);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Line, aRect, oDoc);

AscPDF.initShape(this);

Expand Down Expand Up @@ -194,7 +194,7 @@
let oDoc = this.GetDocument();
oDoc.StartNoHistoryMode();

let oLine = new CAnnotationLine(AscCommon.CreateGUID(), this.GetPage(), this.GetOrigRect().slice(), oDoc);
let oLine = new CAnnotationLine(AscCommon.CreateGUID(), this.GetOrigRect().slice(), oDoc);

oLine.lazyCopy = true;

Expand Down
6 changes: 3 additions & 3 deletions pdf/src/annotations/polyLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
* Class representing a Ink annotation.
* @constructor
*/
function CAnnotationPolyLine(sName, nPage, aRect, oDoc)
function CAnnotationPolyLine(sName, aRect, oDoc)
{
AscPDF.CPdfShape.call(this);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.PolyLine, nPage, aRect, oDoc);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.PolyLine, aRect, oDoc);

AscPDF.initShape(this);

Expand Down Expand Up @@ -139,7 +139,7 @@
let oDoc = this.GetDocument();
oDoc.StartNoHistoryMode();

let oPolyline = new CAnnotationPolyLine(AscCommon.CreateGUID(), this.GetPage(), this.GetOrigRect().slice(), oDoc);
let oPolyline = new CAnnotationPolyLine(AscCommon.CreateGUID(), this.GetOrigRect().slice(), oDoc);
oPolyline.lazyCopy = true;

this.fillObject(oPolyline);
Expand Down
6 changes: 3 additions & 3 deletions pdf/src/annotations/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
* Class representing a Ink annotation.
* @constructor
*/
function CAnnotationPolygon(sName, nPage, aRect, oDoc)
function CAnnotationPolygon(sName, aRect, oDoc)
{
AscPDF.CPdfShape.call(this);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Polygon, nPage, aRect, oDoc);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Polygon, aRect, oDoc);

AscPDF.initShape(this);

Expand Down Expand Up @@ -148,7 +148,7 @@
let oDoc = this.GetDocument();
oDoc.StartNoHistoryMode();

let oPolygon = new CAnnotationPolygon(AscCommon.CreateGUID(), this.GetPage(), this.GetOrigRect().slice(), oDoc);
let oPolygon = new CAnnotationPolygon(AscCommon.CreateGUID(), this.GetOrigRect().slice(), oDoc);
oPolygon.lazyCopy = true;

this.fillObject(oPolygon);
Expand Down
6 changes: 3 additions & 3 deletions pdf/src/annotations/square.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
* Class representing a Ink annotation.
* @constructor
*/
function CAnnotationSquare(sName, nPage, aRect, oDoc)
function CAnnotationSquare(sName, aRect, oDoc)
{
AscPDF.CPdfShape.call(this);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Square, nPage, aRect, oDoc);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Square, aRect, oDoc);

AscPDF.initShape(this);
this.spPr.setGeometry(AscFormat.CreateGeometry("rect"));
Expand All @@ -62,7 +62,7 @@
let oDoc = this.GetDocument();
oDoc.StartNoHistoryMode();

let oSquare = new CAnnotationSquare(AscCommon.CreateGUID(), this.GetPage(), this.GetOrigRect().slice(), oDoc);
let oSquare = new CAnnotationSquare(AscCommon.CreateGUID(), this.GetOrigRect().slice(), oDoc);

oSquare.lazyCopy = true;

Expand Down
6 changes: 3 additions & 3 deletions pdf/src/annotations/stamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
* Class representing a stamp annotation.
* @constructor
*/
function CAnnotationStamp(sName, nPage, aRect, oDoc)
function CAnnotationStamp(sName, aRect, oDoc)
{
AscPDF.CPdfShape.call(this);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Stamp, nPage, aRect, oDoc);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Stamp, aRect, oDoc);

this._rotate = 0;
this._stampType = undefined;
Expand Down Expand Up @@ -373,7 +373,7 @@
let oDoc = this.GetDocument();
oDoc.StartNoHistoryMode();

let oNewStamp = new CAnnotationStamp(AscCommon.CreateGUID(), this.GetPage(), this.GetOrigRect().slice(), oDoc);
let oNewStamp = new CAnnotationStamp(AscCommon.CreateGUID(), this.GetOrigRect().slice(), oDoc);

oNewStamp.inRect = this.inRect;
oNewStamp.lazyCopy = true;
Expand Down
14 changes: 7 additions & 7 deletions pdf/src/annotations/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
* Class representing a text annotation.
* @constructor
*/
function CAnnotationText(sName, nPage, aOrigRect, oDoc)
function CAnnotationText(sName, aOrigRect, oDoc)
{
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Text, nPage, aOrigRect, oDoc);
AscPDF.CAnnotationBase.call(this, sName, AscPDF.ANNOTATIONS_TYPES.Text, aOrigRect, oDoc);

this._noteIcon = NOTE_ICONS_TYPES.Comment;
this._point = undefined;
Expand Down Expand Up @@ -131,7 +131,7 @@
this._replies = [];
};
CAnnotationText.prototype.AddReply = function(CommentData, nPos) {
let oReply = new CAnnotationText(AscCommon.CreateGUID(), this.GetPage(), this.GetOrigRect().slice(), this.GetDocument());
let oReply = new CAnnotationText(AscCommon.CreateGUID(), this.GetOrigRect().slice(), this.GetDocument());

oReply.SetCreationDate(CommentData.m_sOOTime);
oReply.SetModDate(CommentData.m_sOOTime);
Expand Down Expand Up @@ -226,7 +226,7 @@
let oDoc = this.GetDocument();
oDoc.StartNoHistoryMode();

let oNewAnnot = new CAnnotationText(AscCommon.CreateGUID(), this.GetPage(), this.GetOrigRect().slice(), oDoc);
let oNewAnnot = new CAnnotationText(AscCommon.CreateGUID(), this.GetOrigRect().slice(), oDoc);

oNewAnnot.lazyCopy = true;
oNewAnnot._originView = this._originView;
Expand Down Expand Up @@ -262,15 +262,15 @@

let nX = aOrigRect[0];
let nY = aOrigRect[1];
let nWidth = 21 / oDoc.Viewer.zoom;
let nHeight = 21 / oDoc.Viewer.zoom;
let nWidth = 21 / (oGraphics.isThumbnails ? 1 : oDoc.Viewer.zoom);
let nHeight = 21 / (oGraphics.isThumbnails ? 1 : oDoc.Viewer.zoom);

let oCtx = oGraphics.GetContext();
oCtx.save();
oGraphics.EnableTransform();
oCtx.iconFill = "rgb(" + oRGB.r + "," + oRGB.g + "," + oRGB.b + ")";

let nScale = 1 / oDoc.Viewer.zoom;
let nScale = 1 / (oGraphics.isThumbnails ? 1 : oDoc.Viewer.zoom);
let drawFunc = this.GetIconDrawFunc();
drawFunc(oCtx, nX , nY, nScale, nScale, -nRotAngle * Math.PI / 180);

Expand Down
9 changes: 9 additions & 0 deletions pdf/src/defines.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,17 @@
FIELD_TYPES["listbox"] = FIELD_TYPES.listbox;
FIELD_TYPES["signature"] = FIELD_TYPES.signature;

let CommandType = {
editPage: 0,
addPage: 1,
removePage: 2,
widgetInfo: 3,
movePage: 4
}

Object.freeze(FIELD_TYPES);
asc["FIELD_TYPES"] = asc.FIELD_TYPES = FIELD_TYPES;
asc["BORDER_EFFECT_STYLES"] = asc.BORDER_EFFECT_STYLES = BORDER_EFFECT_STYLES;
asc["REF_TO_REASON"] = asc.REF_TO_REASON = REF_TO_REASON;
asc.CommandType = CommandType;
})();
Loading

0 comments on commit b94c47d

Please sign in to comment.