Skip to content

Commit

Permalink
Merge pull request 'fix/pdf-bugs' (#96) from fix/pdf-bugs into releas…
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillovIlya committed Sep 30, 2024
2 parents f78743d + a1042f2 commit 3e0b455
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 24 deletions.
2 changes: 1 addition & 1 deletion common/Drawings/Format/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@

CImageShape.prototype.recalculateGeometry = function () {
this.calcGeometry = null;
if (isRealObject(this.spPr.geometry)) {
if (isRealObject(this.spPr && this.spPr.geometry)) {
this.calcGeometry = this.spPr.geometry;
} else {
var hierarchy = this.getHierarchy();
Expand Down
2 changes: 2 additions & 0 deletions pdf/src/annotations/freeText.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
return;
}

AscCommon.History.Add(new CChangesPDFFreeTextRotate(this, this._rotate, nAngle));

let oBodyPr = oTxShape.txBody.bodyPr;

switch (nAngle) {
Expand Down
11 changes: 9 additions & 2 deletions pdf/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ var CPresentation = CPresentation || function(){};

let oFile = this.Viewer.file;
for (let i = 0; i < oFile.pages.length; i++) {
let oPage = this.Viewer.drawingPages[i];
let oPage = this.Viewer.drawingPages[i];
if (!oPage) {
continue;
}

let nAngle = this.Viewer.getPageRotate(i);

let oPageTr = new AscCommon.CMatrix();
Expand Down Expand Up @@ -2331,7 +2335,8 @@ var CPresentation = CPresentation || function(){};
}
});

oViewer.resize();
oViewer.resize(true);
oViewer.paint();
};
/**
* Adds an interactive field to document.
Expand Down Expand Up @@ -4213,6 +4218,7 @@ var CPresentation = CPresentation || function(){};
return;
}

Asc.editor.canSave = false;
this.StartAction(AscDFH.historydescription_Pdf_EditPage);
let oDrDoc = this.GetDrawingDocument();

Expand Down Expand Up @@ -4306,6 +4312,7 @@ var CPresentation = CPresentation || function(){};
_t.Viewer.paint(function() {
_t.Viewer.thumbnails._repaintPage(nPage);
});
Asc.editor.canSave = true;
};
if(aUrls.length > 0) {
AscCommon.sendImgUrls(Asc.editor, aUrls, function (data) {
Expand Down
2 changes: 1 addition & 1 deletion pdf/src/forms/apiFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
let nSelEnd = oDoc.event["selEnd"];

function isValidNumber(str) {
return !isNaN(str) && isFinite(str);
return !isNaN(str) && isFinite(str) && false == /\s/.test(str);
}

let sNewValue = sValue.slice(0, nSelStart) + sChange + sValue.slice(nSelEnd);
Expand Down
10 changes: 8 additions & 2 deletions pdf/src/forms/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
if (this.IsNeedRecalc() == false)
return;

if (this.IsNeedCheckAlign()) {
this.CheckAlignInternal();
}

if (this.GetTextSize() == 0) {
if (null == this.getFormRelRect()) {
this.CalculateContentClipRect();
Expand Down Expand Up @@ -324,7 +328,7 @@

this.content.MoveCursorToStartPos();
if (!Asc.editor.getDocumentRenderer().IsOpenFormsInProgress)
this.CheckAlignInternal();
this.SetNeedCheckAlign(true);
};
CComboBoxField.prototype.SetCurIdxs = function(aIdxs) {
if (this.IsWidget()) {
Expand Down Expand Up @@ -515,7 +519,7 @@
// когда выравнивание посередине или справа, то после того
// как ширина контента будет больше чем размер формы, выравнивание становится слева, пока текста вновь не станет меньше чем размер формы
aFields.forEach(function(field) {
field.CheckAlignInternal();
field.SetNeedCheckAlign(true);
});

this.SetNeedCommit(false);
Expand Down Expand Up @@ -784,6 +788,8 @@
CComboBoxField.prototype.onMouseUp = AscPDF.CTextField.prototype.onMouseUp;
CComboBoxField.prototype.OnContentChange = AscPDF.CTextField.prototype.OnContentChange;
CComboBoxField.prototype.UpdateSelectionByEvent = AscPDF.CTextField.prototype.UpdateSelectionByEvent;
CComboBoxField.prototype.SetNeedCheckAlign = AscPDF.CTextField.prototype.SetNeedCheckAlign;
CComboBoxField.prototype.IsNeedCheckAlign = AscPDF.CTextField.prototype.IsNeedCheckAlign;

window["AscPDF"].CComboBoxField = CComboBoxField;
})();
Expand Down
18 changes: 13 additions & 5 deletions pdf/src/forms/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,10 @@
if (this.IsNeedRecalc() == false)
return;

if (this.IsNeedCheckAlign()) {
this.CheckAlignInternal();
}

this.RecalcMeasureContent();

if (this.GetTextSize() == 0) {
Expand Down Expand Up @@ -1015,33 +1019,37 @@
return true;
};
CTextField.prototype.CheckAlignInternal = function() {
this.SetNeedCheckAlign(false);

// если выравнивание по центру или справа, то оно должно переключаться на left если ширина контента выходит за пределы формы
// вызывается на момент коммита формы
if ([AscPDF.ALIGN_TYPE.center, AscPDF.ALIGN_TYPE.right].includes(this.GetAlign())) {

if (this.IsTextOutOfForm(this.content).hor) {
if (this.content.GetAlign() != AscPDF.ALIGN_TYPE.left) {
this.content.SetAlign(AscPDF.ALIGN_TYPE.left);
this.SetNeedRecalc(true);
}
}
else if (this.content.GetAlign() != this.GetAlign()) {
this.content.SetAlign(this.GetAlign());
this.SetNeedRecalc(true);
}

if (this.IsTextOutOfForm(this.contentFormat).hor) {
if (this.contentFormat.GetAlign() != AscPDF.ALIGN_TYPE.left) {
this.contentFormat.SetAlign(AscPDF.ALIGN_TYPE.left);
this.SetNeedRecalc(true);
}
}
else if (this.contentFormat.GetAlign() != this.GetAlign()) {
this.contentFormat.SetAlign(this.GetAlign());
this.SetNeedRecalc(true);
}
}
};
CTextField.prototype.SetNeedCheckAlign = function(bCheck) {
this._needCheckAlign = bCheck;
};
CTextField.prototype.IsNeedCheckAlign = function() {
return this._needCheckAlign;
};
CTextField.prototype.InsertChars = function(aChars) {
this.content.EnterText(aChars);
};
Expand Down Expand Up @@ -1158,7 +1166,7 @@
// когда выравнивание посередине или справа, то после того
// как ширина контента будет больше чем размер формы, выравнивание становится слева, пока текста вновь не станет меньше чем размер формы
aFields.forEach(function(field) {
field.CheckAlignInternal();
field.SetNeedCheckAlign(true);
});

this.SetNeedCommit(false);
Expand Down
4 changes: 3 additions & 1 deletion pdf/src/history/documentChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,9 @@ CChangesPDFDocumentRecognizePage.prototype.private_SetValue = function(bRecogniz
let nPage = this.Page;

oFile.pages[nPage].isConvertedToShapes = bRecognize;
delete oDoc.Viewer.drawingPages[nPage].Image;
if (oDoc.Viewer.drawingPages[nPage]) {
delete oDoc.Viewer.drawingPages[nPage].Image;
}

oDoc.Viewer.paint(function() {
oDoc.Viewer.thumbnails._repaintPage(nPage);
Expand Down
42 changes: 30 additions & 12 deletions pdf/src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@
_t.startTimer();
}

if (_t.isStarted && _t.pageDetector && _t.IsOpenFormsInProgress == false) {
if (_t.isStarted && _t.pageDetector && !oDoc.fontLoader.isWorking() && _t.IsOpenFormsInProgress == false) {
_t.sendEvent("onFileOpened");

_t.sendEvent("onPagesCount", _t.file.pages.length);
Expand Down Expand Up @@ -2713,6 +2713,8 @@
oDrDoc.m_lDrawingEnd = lEndPage;
this.startVisiblePage = lStartPage;
this.endVisiblePage = lEndPage;

this.updatePageDetector();
};
this._paint = function()
{
Expand Down Expand Up @@ -2752,8 +2754,6 @@
ctx.strokeStyle = AscCommon.GlobalSkin.PageOutline;
ctx.lineWidth = lineW;

this.pageDetector = new CCurrentPageDetector(this.canvas.width, this.canvas.height);

let isStretchPaint = this.isStretchPaint();
if (this.isClearPages)
isStretchPaint = false;
Expand Down Expand Up @@ -2875,14 +2875,6 @@

if (this.Api.watermarkDraw)
this.Api.watermarkDraw.Draw(ctx, x, y, w, h);

if (this.isLandscapePage(i)) {
let x = ((xCenter * AscCommon.AscBrowser.retinaPixelRatio) >> 0) - (h >> 1);
this.pageDetector.addPage(i, x, y, h, w);
}
else {
this.pageDetector.addPage(i, x, y, w, h);
}
}

this.isClearPages = false;
Expand All @@ -2905,6 +2897,32 @@
// Обязательно делаем в конце, т.к. во время отрисовки происходит пересчет
this._checkTargetUpdate();
};
this.updatePageDetector = function() {
this.pageDetector = new CCurrentPageDetector(this.canvas.width, this.canvas.height);

let yPos = this.scrollY >> 0;
let xCenter = this.width >> 1;

for (let i = this.startVisiblePage; i <= this.endVisiblePage; i++)
{
let page = this.drawingPages[i];
if (!page)
break;

let w = AscCommon.AscBrowser.convertToRetinaValue(page.W, true);
let h = AscCommon.AscBrowser.convertToRetinaValue(page.H, true);
let x = ((xCenter * AscCommon.AscBrowser.retinaPixelRatio) >> 0) - (w >> 1);
let y = ((page.Y - yPos) * AscCommon.AscBrowser.retinaPixelRatio) >> 0;

if (this.isLandscapePage(i)) {
let x = ((xCenter * AscCommon.AscBrowser.retinaPixelRatio) >> 0) - (h >> 1);
this.pageDetector.addPage(i, x, y, h, w);
}
else {
this.pageDetector.addPage(i, x, y, w, h);
}
}
};
this.isStretchPaint = function() {
return this.Api.WordControl.NoneRepaintPages;
};
Expand Down Expand Up @@ -4299,7 +4317,7 @@
if (this.scrollY >= this.scrollMaxY)
this.scrollY = this.scrollMaxY;

if (this.zoomCoordinate && this.isDocumentContentReady)
if (this.zoomCoordinate && this.isDocumentContentReady && Asc.editor.isDocumentLoadComplete)
{
var newPoint = this.ConvertCoordsToCursor(this.zoomCoordinate.x, this.zoomCoordinate.y, this.zoomCoordinate.index);
// oldsize используется чтобы при смене ориентации экрана был небольшой скролл
Expand Down

0 comments on commit 3e0b455

Please sign in to comment.