Skip to content

Commit

Permalink
Merge pull request #3922 from ONLYOFFICE/fix/saveForms
Browse files Browse the repository at this point in the history
[pdf] For saving forms
  • Loading branch information
KhromovNikita authored Oct 25, 2023
2 parents d118cf0 + 092797f commit 6e17dec
Show file tree
Hide file tree
Showing 19 changed files with 1,198 additions and 214 deletions.
47 changes: 26 additions & 21 deletions cell/model/autofilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4950,19 +4950,6 @@
}
}

if (findDateTimeFormat) {
_values.sort(function (a, b) {
if (a.isDateFormat && !b.isDateFormat) {
return -1;
}
if (!a.isDateFormat && b.isDateFormat) {
return 1;
}
if (a.isDateFormat && b.isDateFormat) {
return parseFloat(a.val) > parseFloat(b.val) ? -1 : 1;
}
});
}

return {values: _values, automaticRowCount: automaticRowCount, ignoreCustomFilter: ignoreCustomFilter, isTimeFormat: isTimeFormat};
},
Expand Down Expand Up @@ -5036,20 +5023,38 @@
}

elements.sort(function sortArr(a, b) {
var isNumericA = isNumeric(a.val);
var isNumericB = isNumeric(b.val);
let val1 = a.val;
let val2 = b.val;
let isNumericA = isNumeric(val1);
let isNumericB = isNumeric(val2);
let isDateTimeA = a.isDateFormat;
let isDateTimeB = b.isDateFormat;

if (isDateTimeA && !isDateTimeB) {
//date have max priority
return -1;
} else if (!isDateTimeA && isDateTimeB) {
return 1;
} else if (isDateTimeA && isDateTimeB) {
if (a.year === b.year) {
return parseFloat(val1) > parseFloat(val2) ? 1 : -1;
} else {
return a.year > b.year ? -1 : 1;
}
}

if (a.val === "") {
return 1;
} else if (b.val === "") {
return -1;
} else if (val2 === "") {
return -1;
} else if (isNumericA && isNumericB) {
return (isAscending || isAscending === undefined) ? (a.val - b.val) : (b.val - a.val);
return (isAscending || isAscending === undefined) ? (val1 - val2) : (val2 - val1);
} else if (!isNumericA && !isNumericB) {
var _cmp = 0;
if (a.val > b.val){
let _cmp = 0;
if (val1 > val2) {
_cmp = 1;
}
if (a.val < b.val) {
if (val1 < val2) {
_cmp = -1;
}
return (isAscending || isAscending === undefined) ? _cmp : -_cmp;
Expand Down
2 changes: 1 addition & 1 deletion cell/view/WorksheetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3008,7 +3008,7 @@
vector_koef /= t.getRetinaPixelRatio();
}
t._drawGrid(drawingCtx, range, offsetX, offsetY, printPagesData.pageWidth / vector_koef,
printPagesData.pageHeight / vector_koef, printPagesData.scale, titleHeight, titleWidth);
printPagesData.pageHeight / vector_koef, printPagesData.scale, !titleHeight, !titleWidth);
}

//TODO временно подменяю scale. пересмотреть! подменять либо всегда, либо флаг добавить.
Expand Down
12 changes: 7 additions & 5 deletions pdf/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,17 @@
return false;
}

oDoc.activeForm.EnterText(text);
let isEntered = oDoc.activeForm.EnterText(text);
if (viewer.pagesInfo.pages[oDoc.activeForm._page].needRedrawForms) {
viewer._paint();
viewer.onUpdateOverlay();
}

this.WordControl.m_oDrawingDocument.TargetStart();
// Чтобы при зажатой клавише курсор не пропадал
this.WordControl.m_oDrawingDocument.showTarget(true);
if (isEntered) {
this.WordControl.m_oDrawingDocument.TargetStart();
// Чтобы при зажатой клавише курсор не пропадал
this.WordControl.m_oDrawingDocument.showTarget(true);
}

return true;
};
Expand Down Expand Up @@ -448,7 +450,7 @@

oField.SelectOption(nIdx);
let isNeedRedraw = oField.IsNeedCommit();
if (oField._commitOnSelChange && oField.IsNeedCommit()) {
if (oField.IsCommitOnSelChange() && oField.IsNeedCommit()) {
oField.Commit();
isNeedRedraw = true;

Expand Down
6 changes: 3 additions & 3 deletions pdf/src/annotations/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
}
CAnnotationText.prototype = Object.create(AscPDF.CAnnotationBase.prototype);
CAnnotationText.prototype.constructor = CAnnotationText;

CAnnotationText.prototype.SetState = function(nType) {
this._state = nType;
};
Expand Down Expand Up @@ -245,8 +245,8 @@

let nScaleX = nWidth / imgW;
let nScaleY = nHeight / imgH;
let wScaled = imgW * nScaleX + 0.5 >> 0;
let hScaled = imgH * nScaleY + 0.5 >> 0;
let wScaled = Math.max(imgW * nScaleX + 0.5 >> 0, 40);
let hScaled = Math.max(imgH * nScaleY + 0.5 >> 0, 40);

let canvas = document.createElement('canvas');
let context = canvas.getContext('2d');
Expand Down
16 changes: 8 additions & 8 deletions pdf/src/apiPDF.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@
get: function() {
let oField = this.field.GetDocument().GetField(this.field.GetFullName());
if (oField && oField.IsWidget()) {
return oField.GetButtonFitBounds();
return oField.IsButtonFitBounds();
}
else {
throw Error("InvalidGetError: Get not possible, invalid or unknown.");
Expand Down Expand Up @@ -1067,12 +1067,12 @@
if (typeof(bValue) == "boolean") {
let aFields = this._doc.GetFields(this.name);
aFields.forEach(function(field) {
field._radiosInUnison = bValue;
field.SetRadiosInUnison(bValue);
});
}
},
get: function() {
return this._radiosInUnison;
return this.IsRadiosInUnison();
}
},
"value": {
Expand Down Expand Up @@ -1283,7 +1283,7 @@
get: function() {
let oField = this.field.GetDocument().GetField(this.field.GetFullName());
if (oField && oField.IsWidget()) {
return oField.GetDoNotScroll();
return oField.IsDoNotScroll();
}
else {
throw Error("InvalidGetError: Get not possible, invalid or unknown.");
Expand Down Expand Up @@ -1350,7 +1350,7 @@
get: function() {
let oField = this.field.GetDocument().GetField(this.field.GetFullName());
if (oField && oField.IsWidget()) {
return oField.GetFileSelect();
return oField.IsFileSelect();
}
else {
throw Error("InvalidGetError: Get not possible, invalid or unknown.");
Expand Down Expand Up @@ -1506,7 +1506,7 @@
get: function() {
let oField = this.field.GetDocument().GetField(this.field.GetFullName());
if (oField && oField.IsWidget()) {
return oField.GetCommitOnSelChange();
return oField.IsCommitOnSelChange();
}
else {
throw Error("InvalidGetError: Get not possible, invalid or unknown.");
Expand Down Expand Up @@ -1864,7 +1864,7 @@
}
},
get: function() {
return this._multipleSelection;
return this.field.IsMultipleSelection();
}
},
"value": {
Expand Down Expand Up @@ -1953,7 +1953,7 @@
this.SelectOption(0, true);
this.UnionLastHistoryPoints();

if (this._multipleSelection)
if (this.field.IsMultipleSelection())
this._currentValueIndices = [0];
else
this._currentValueIndices = 0;
Expand Down
70 changes: 28 additions & 42 deletions pdf/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,50 +211,23 @@ var CPresentation = CPresentation || function(){};
let h = (oPage.H * AscCommon.AscBrowser.retinaPixelRatio) >> 0;

let oFile = oViewer.file;
let aIconsInfo = oFile.nativeFile["getButtonIcons"](i, w, h);
let aIconsInfo = oFile.nativeFile["getButtonIcons"](i, w, h, undefined, true);

if (aIconsInfo["View"] == null)
return;

let aIconsToLoad = [];
let oIconsMap = {};

// load images
for (let nIcon = 0; nIcon < aIconsInfo["View"].length; nIcon++) {
let canvas = document.createElement("canvas");
let ctx = canvas.getContext("2d");
let nWidth = aIconsInfo["View"][nIcon]["w"];
let nHeight = aIconsInfo["View"][nIcon]["h"];

canvas.width = nWidth;
canvas.height = nHeight;

let nRetValue = aIconsInfo["View"][nIcon]["retValue"];

let supportImageDataConstructor = (AscCommon.AscBrowser.isIE && !AscCommon.AscBrowser.isIeEdge) ? false : true;
let mappedBuffer = new Uint8ClampedArray(oFile.memory().buffer, nRetValue, 4 * nWidth * nHeight);
let imageData = null;

if (supportImageDataConstructor) {
imageData = new ImageData(mappedBuffer, nWidth, nHeight);
}
else {
imageData = ctx.createImageData(nWidth, nHeight);
imageData.data.set(mappedBuffer, 0);
}

if (ctx) {
ctx.putImageData(imageData, 0, 0);
}

oFile.free(nRetValue);
let sBase64 = aIconsInfo["View"][nIcon]["retValue"];

aIconsToLoad.push({
Image: {
width: nWidth,
height: nHeight,
width: aIconsInfo["View"][nIcon]["w"],
height: aIconsInfo["View"][nIcon]["h"],
},
src: canvas.toDataURL()
src: "data:image/png;base64," + sBase64
});

for (let nField = 0; nField < aIconsInfo["MK"].length; nField++) {
Expand Down Expand Up @@ -725,7 +698,10 @@ var CPresentation = CPresentation || function(){};
if (!this.checkDefaultFieldFonts(function(){_t.OnMouseDownField(oField, event)}))
return;

oField.Recalculate();
if (oField.IsNeedDrawFromStream()) {
oField.Recalculate();
oField.SetNeedRecalc(true);
}

// суть в том, что мы рисуем background только когда форма активна, если неактивна - рисуем highlight вместо него.
if (oField.GetBackgroundColor())
Expand Down Expand Up @@ -2045,22 +2021,32 @@ var CPresentation = CPresentation || function(){};
* Note: This method used by forms actions.
* @memberof CPDFDoc
* @param {CBaseField[]} aNames - array with forms names to reset. If param is undefined or array is empty then resets all forms.
* @param {boolean} bAllExcept - reset all fields except aNames
* @typeofeditors ["PDF"]
*/
CPDFDoc.prototype.ResetForms = function(aNames) {
CPDFDoc.prototype.ResetForms = function(aNames, bAllExcept) {
let oActionsQueue = this.GetActionsQueue();
let oThis = this;

if (aNames.length > 0) {
aNames.forEach(function(name) {
let aFields = oThis.GetFields(name);
if (aFields.length > 0)
AscCommon.History.Clear()

aFields.forEach(function(field) {
field.Reset();
if (bAllExcept) {
for (let nField = 0; nField < this.widgets.length; nField++) {
let oField = this.widgets[nField];
if (aNames.includes(oField.GetFullName()) == false)
oField.Reset();
}
}
else {
aNames.forEach(function(name) {
let aFields = oThis.GetFields(name);
if (aFields.length > 0)
AscCommon.History.Clear()

aFields.forEach(function(field) {
field.Reset();
});
});
});
}
}
else {
this.widgets.forEach(function(field) {
Expand Down
12 changes: 9 additions & 3 deletions pdf/src/engine/drawingfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,9 +984,9 @@ else
}
if (flags & (1 << 14))
{
rec["NameOfYes"] = reader.readString();
rec["ExportValue"] = reader.readString();
if (flags & (1 << 9))
rec["value"] = rec["NameOfYes"];
rec["value"] = rec["ExportValue"];
}
// 12.7.4.2.1
rec["NoToggleToOff"] = (rec["flag"] >> 14) & 1; // NoToggleToOff
Expand Down Expand Up @@ -1048,7 +1048,7 @@ else
};
// optional nWidget - rec["AP"]["i"]
// optional sView - N/D/R
// optional sButtonView - state pushbutton-annotation - Off/Yes(or rec["NameOfYes"])
// optional sButtonView - state pushbutton-annotation - Off/Yes(or rec["ExportValue"])
CFile.prototype["getInteractiveFormsAP"] = function(pageIndex, width, height, backgroundColor, nWidget, sView, sButtonView)
{
let nView = -1;
Expand All @@ -1066,7 +1066,9 @@ else
nButtonView = (sButtonView == "Off" ? 0 : 1);

let res = [];
self.drawingFileCurrentPageIndex = pageIndex;
let ext = Module["_GetInteractiveFormsAP"](this.nativeFile, width, height, backgroundColor === undefined ? 0xFFFFFF : backgroundColor, pageIndex, nWidget === undefined ? -1 : nWidget, nView, nButtonView);
self.drawingFileCurrentPageIndex = -1;
if (ext == 0)
return res;

Expand Down Expand Up @@ -1109,7 +1111,9 @@ else
}

let res = {};
self.drawingFileCurrentPageIndex = pageIndex;
let ext = Module["_GetButtonIcons"](this.nativeFile, width, height, backgroundColor === undefined ? 0xFFFFFF : backgroundColor, pageIndex, nWidget === undefined ? -1 : nWidget, nView);
self.drawingFileCurrentPageIndex = -1;
if (ext == 0)
return res;

Expand Down Expand Up @@ -1451,7 +1455,9 @@ else
}

let res = [];
self.drawingFileCurrentPageIndex = pageIndex;
let ext = Module["_GetAnnotationsAP"](this.nativeFile, width, height, backgroundColor === undefined ? 0xFFFFFF : backgroundColor, pageIndex, nAnnot === undefined ? -1 : nAnnot, nView);
self.drawingFileCurrentPageIndex = -1;
if (ext == 0)
return res;

Expand Down
Loading

0 comments on commit 6e17dec

Please sign in to comment.