Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pdf] Fixed writing Ink annot #3860

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions pdf/src/annotations/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,30 @@
CAnnotationBase.prototype.SetPosition = function(x, y) {
let oViewer = editor.getDocumentRenderer();
let oDoc = this.GetDocument();
let nPage = this.GetPage();
let nPage = this.GetPage();

oDoc.History.Add(new CChangesPDFAnnotPos(this, [this._rect[0], this._rect[1]], [x, y]));
let nOldX = this._rect[0];
let nOldY = this._rect[1];

let nDeltaX = x - nOldX;
let nDeltaY = y - nOldY;

let nScaleY = oViewer.drawingPages[nPage].H / oViewer.file.pages[nPage].H / oViewer.zoom;
let nScaleX = oViewer.drawingPages[nPage].W / oViewer.file.pages[nPage].W / oViewer.zoom;

if (this.IsNeedDrawFromStream() && this.IsInk()) {
let aPath;
for (let i = 0; i < this._gestures.length; i++) {
aPath = this._gestures[i];
for (let j = 0; j < aPath.length; j++) {
aPath[j].x += nDeltaX * g_dKoef_pix_to_mm;
aPath[j].y += nDeltaY * g_dKoef_pix_to_mm;
}
}
}

oDoc.History.Add(new CChangesPDFAnnotPos(this, [this._rect[0], this._rect[1]], [x, y]));

let nWidth = this._pagePos.w;
let nHeight = this._pagePos.h;

Expand Down Expand Up @@ -609,7 +626,7 @@
oDoc.History.Add(new CChangesPDFAnnotReplies(this, this._replies, aReplies));
}
this.SetWasChanged(true);

this._replies = aReplies;
};
CAnnotationBase.prototype.GetReply = function(nPos) {
Expand Down
66 changes: 45 additions & 21 deletions pdf/src/annotations/ink.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,7 @@
}
if (i === selected_objects.length)
selected_objects.push(this);



if (drawingObjectsController) {
drawingObjectsController.onChangeDrawingsSelection();
}
Expand Down Expand Up @@ -814,26 +813,51 @@
let nLineW = this.GetWidth() * g_dKoef_pt_to_mm * g_dKoef_mm_to_pix;
let aBounds = this.GetOrigRect();

let xMin = aBounds[0] + nLineW;
let yMin = aBounds[1] + nLineW;
let xMax = aBounds[2] - nLineW;
let yMax = aBounds[3] - nLineW;

let nWidthMM = (xMax - xMin);
let nHeightMM = (yMax - yMin);

for (let nPath = 0; nPath < aRelPointsPos.length; nPath++) {
let aPath = aRelPointsPos[nPath];
let aShapePath = [];

for (let nPoint = 0; nPoint < aPath.length; nPoint++) {
aShapePath.push({
x: (nWidthMM) * aPath[nPoint].relX + xMin,
y: (nHeightMM) * aPath[nPoint].relY + yMin
});
let xMin;
let yMin;
let xMax;
let yMax;
if (this.IsNeedDrawFromStream() == false) {
xMin = aBounds[0] + nLineW * 0.75;
yMin = aBounds[1] + nLineW * 0.75;
xMax = aBounds[2] - nLineW * 0.75;
yMax = aBounds[3] - nLineW * 0.75;

let nWidthMM = (xMax - xMin);
let nHeightMM = (yMax - yMin);

for (let nPath = 0; nPath < aRelPointsPos.length; nPath++) {
let aPath = aRelPointsPos[nPath];
let aShapePath = [];

for (let nPoint = 0; nPoint < aPath.length; nPoint++) {
aShapePath.push({
x: (nWidthMM) * aPath[nPoint].relX + xMin,
y: (nHeightMM) * aPath[nPoint].relY + yMin
});
}

aShapePaths.push(aShapePath);
}
}
else {
let oViewer = editor.getDocumentRenderer();
let nScaleY = oViewer.drawingPages[this.GetPage()].H / oViewer.file.pages[this.GetPage()].H / oViewer.zoom;
let nScaleX = oViewer.drawingPages[this.GetPage()].W / oViewer.file.pages[this.GetPage()].W / oViewer.zoom;

for (let nPath = 0; nPath < this._gestures.length; nPath++) {
let aPath = this._gestures[nPath];
let aShapePath = [];

for (let nPoint = 0; nPoint < aPath.length; nPoint++) {
aShapePath.push({
x: aPath[nPoint].x * g_dKoef_mm_to_pix / nScaleX,
y: aPath[nPoint].y * g_dKoef_mm_to_pix / nScaleY
});
}

aShapePaths.push(aShapePath);
}

aShapePaths.push(aShapePath);
}

memory.WriteLong(aShapePaths.length);
Expand Down
Loading