@syncfusion/ej2-pdf 24.2.8 → 24.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9325,6 +9325,13 @@ var PdfField = /** @__PURE__ @class */ (function () {
9325
9325
  this._textAlignment = value;
9326
9326
  this._stringFormat = new PdfStringFormat(value, PdfVerticalAlignment.middle);
9327
9327
  };
9328
+ PdfField.prototype._parseItems = function () {
9329
+ var collection = [];
9330
+ for (var i = 0; i < this.itemsCount; i++) {
9331
+ collection.push(this.itemAt(i));
9332
+ }
9333
+ return collection;
9334
+ };
9328
9335
  return PdfField;
9329
9336
  }());
9330
9337
  /**
@@ -42302,7 +42309,7 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42302
42309
  for (var i = 0; i < this._fieldCollection.length; i++) {
42303
42310
  var field = this._fieldCollection[Number.parseInt(i.toString(), 10)];
42304
42311
  if (field.page) {
42305
- var index = _getPageIndex(document_1, field.page._pageDictionary);
42312
+ var index = _getPageIndex(document_1, this._sortItemByPageIndex(field, true)._pageDictionary);
42306
42313
  if (index >= 0) {
42307
42314
  if (fieldCollection.has(index)) {
42308
42315
  value = fieldCollection.get(index);
@@ -42326,16 +42333,18 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42326
42333
  var fieldsCount_1 = 0;
42327
42334
  fieldCollection.forEach(function (value, key) {
42328
42335
  _this._tabOrder = _this._tabCollection.get(key);
42329
- var fields = value;
42330
- fields.sort(function (pdfField1, pdfField2) {
42331
- return _this._compareFields(pdfField1, pdfField2);
42332
- });
42333
- for (var j = 0; j < fields.length; j++) {
42334
- var fieldIndex = _this._fieldCollection.indexOf(fields[Number.parseInt(j.toString(), 10)]);
42335
- if (fieldIndex !== -1 && fieldIndex !== fieldsCount_1 + j) {
42336
- var field = _this._fieldCollection[Number.parseInt(fieldIndex.toString(), 10)];
42337
- _this._fieldCollection.splice(fieldIndex, 1);
42338
- _this._fieldCollection.splice(fieldsCount_1 + j, 0, field);
42336
+ if (_this._tabOrder !== PdfFormFieldsTabOrder.structure) {
42337
+ var fields = value;
42338
+ fields.sort(function (pdfField1, pdfField2) {
42339
+ return _this._compareFields(pdfField1, pdfField2);
42340
+ });
42341
+ for (var j = 0; j < fields.length; j++) {
42342
+ var fieldIndex = _this._fieldCollection.indexOf(fields[Number.parseInt(j.toString(), 10)]);
42343
+ if (fieldIndex !== -1 && fieldIndex !== fieldsCount_1 + j) {
42344
+ var field = _this._fieldCollection[Number.parseInt(fieldIndex.toString(), 10)];
42345
+ _this._fieldCollection.splice(fieldIndex, 1);
42346
+ _this._fieldCollection.splice(fieldsCount_1 + j, 0, field);
42347
+ }
42339
42348
  }
42340
42349
  }
42341
42350
  fieldsCount_1 += value.length;
@@ -42575,10 +42584,24 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42575
42584
  var page1 = field1.page;
42576
42585
  var page2 = field2.page;
42577
42586
  if (page1 && page1 instanceof PdfPage && page2 && page2 instanceof PdfPage) {
42578
- var page1Index = page1._pageIndex;
42579
- var page2Index = page2._pageIndex;
42580
- var rectangle1 = this._getRectangle(field1._dictionary);
42581
- var rectangle2 = this._getRectangle(field2._dictionary);
42587
+ var page1Index = this._sortItemByPageIndex(field1, false)._pageIndex;
42588
+ var page2Index = this._sortItemByPageIndex(field2, false)._pageIndex;
42589
+ var rectangle1 = void 0;
42590
+ if (field1._dictionary.has('Kids')) {
42591
+ rectangle1 = this._getItemRectangle(field1);
42592
+ }
42593
+ else {
42594
+ rectangle1 = this._getRectangle(field1._dictionary);
42595
+ }
42596
+ var rectangle2 = void 0;
42597
+ if (field2._dictionary.has('Kids')) {
42598
+ rectangle2 = this._getItemRectangle(field2);
42599
+ }
42600
+ else {
42601
+ rectangle2 = this._getRectangle(field2._dictionary);
42602
+ }
42603
+ var firstHeight = rectangle1[3] - rectangle1[1];
42604
+ var secondHeight = rectangle2[3] - rectangle2[1];
42582
42605
  if (rectangle1 && rectangle1.length >= 2 && rectangle2 && rectangle2.length >= 2) {
42583
42606
  var x1 = rectangle1[0];
42584
42607
  var y1 = rectangle1[1];
@@ -42589,6 +42612,13 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42589
42612
  index = page1Index - page2Index;
42590
42613
  if (this._tabOrder === PdfFormFieldsTabOrder.row) {
42591
42614
  xdiff = this._compare(y2, y1);
42615
+ if (xdiff !== 0) {
42616
+ var isValid = xdiff === -1 && y1 > y2 && (y1 - firstHeight / 2) < y2;
42617
+ isValid = isValid || (xdiff === 1 && y2 > y1 && (y2 - secondHeight / 2) < y1);
42618
+ if (isValid) {
42619
+ xdiff = 0;
42620
+ }
42621
+ }
42592
42622
  if (index !== 0) {
42593
42623
  result = index;
42594
42624
  }
@@ -42631,28 +42661,32 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42631
42661
  return result;
42632
42662
  };
42633
42663
  PdfForm.prototype._getRectangle = function (dictionary) {
42634
- var _this = this;
42664
+ var rect;
42635
42665
  if (dictionary.has('Rect')) {
42636
- var rect = dictionary.get('Rect');
42637
- if (rect) {
42638
- return rect;
42639
- }
42666
+ rect = dictionary.getArray('Rect');
42640
42667
  }
42641
- else {
42642
- if (dictionary.has('Kids')) {
42643
- var kidsArray = dictionary.get('Kids');
42644
- if (kidsArray) {
42645
- if (kidsArray.length > 1) {
42646
- kidsArray.sort(function (x, y) {
42647
- return _this._compareKidsElement(x, y);
42648
- });
42668
+ return rect;
42669
+ };
42670
+ PdfForm.prototype._getItemRectangle = function (field) {
42671
+ var result;
42672
+ var dictionary = field._dictionary;
42673
+ if (dictionary.has('Kids')) {
42674
+ var kids = dictionary.getArray('Kids');
42675
+ if (kids && kids.length >= 1) {
42676
+ if (kids.length === 1) {
42677
+ result = this._getRectangle(kids[0]);
42678
+ }
42679
+ else {
42680
+ if (field && field.itemsCount > 1) {
42681
+ result = this._getRectangle(field.itemAt(0)._dictionary);
42682
+ }
42683
+ else {
42684
+ result = this._getRectangle(kids[0]);
42649
42685
  }
42650
- var dictionary_1 = this._crossReference._fetch(kidsArray[0]);
42651
- return this._getRectangle(dictionary_1);
42652
42686
  }
42653
42687
  }
42654
42688
  }
42655
- return null;
42689
+ return result;
42656
42690
  };
42657
42691
  PdfForm.prototype._compare = function (x, y) {
42658
42692
  if (x > y) {
@@ -42670,6 +42704,7 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42670
42704
  var yDictionary = this._crossReference._fetch(y);
42671
42705
  var xRect = this._getRectangle(xDictionary);
42672
42706
  var yRect = this._getRectangle(yDictionary);
42707
+ var result;
42673
42708
  if (xRect && xRect.length >= 2 && yRect && yRect.length >= 2) {
42674
42709
  var x1 = xRect[0];
42675
42710
  var y1 = xRect[1];
@@ -42677,7 +42712,6 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42677
42712
  var y2 = yRect[1];
42678
42713
  if (typeof x1 === 'number' && typeof x2 === 'number' &&
42679
42714
  typeof y1 === 'number' && typeof y2 === 'number') {
42680
- var result = 0;
42681
42715
  var xdiff = void 0;
42682
42716
  if (this._tabOrder === PdfFormFieldsTabOrder.row) {
42683
42717
  xdiff = this._compare(y2, y1);
@@ -42697,10 +42731,90 @@ var PdfForm = /** @__PURE__ @class */ (function () {
42697
42731
  result = this._compare(y2, y1);
42698
42732
  }
42699
42733
  }
42734
+ else {
42735
+ result = 0;
42736
+ }
42700
42737
  return result;
42701
42738
  }
42702
42739
  }
42703
- return null;
42740
+ return result;
42741
+ };
42742
+ PdfForm.prototype._sortItemByPageIndex = function (field, hasPageTabOrder) {
42743
+ var page = field.page;
42744
+ var tabOrder = this._tabOrder;
42745
+ this._tabOrder = hasPageTabOrder ? field.page.tabOrder : tabOrder;
42746
+ this._sortFieldItems(field);
42747
+ if (field._isLoaded && field._kidsCount > 1) {
42748
+ page = field.itemAt(0).page;
42749
+ }
42750
+ this._tabOrder = tabOrder;
42751
+ if (typeof page === 'undefined') {
42752
+ page = field.page;
42753
+ }
42754
+ return page;
42755
+ };
42756
+ PdfForm.prototype._sortFieldItems = function (field) {
42757
+ var _this = this;
42758
+ if (field._isLoaded && (field instanceof PdfTextBoxField ||
42759
+ field instanceof PdfListBoxField ||
42760
+ field instanceof PdfCheckBoxField ||
42761
+ field instanceof PdfRadioButtonListField)) {
42762
+ var collection = field._parseItems(); // eslint-disable-line
42763
+ collection.sort(function (item1, item2) {
42764
+ return _this._compareFieldItem(item1, item2);
42765
+ });
42766
+ field._parsedItems.clear();
42767
+ for (var i = 0; i < collection.length; i++) {
42768
+ field._parsedItems.set(i, collection[Number.parseInt(i.toString(), 10)]);
42769
+ }
42770
+ }
42771
+ };
42772
+ PdfForm.prototype._compareFieldItem = function (item1, item2) {
42773
+ var result = 0;
42774
+ if (typeof item1 !== 'undefined' && typeof item2 !== 'undefined') {
42775
+ var page1 = item1.page;
42776
+ var page2 = item2.page;
42777
+ var array1 = this._getRectangle(item1._dictionary);
42778
+ var array2 = this._getRectangle(item2._dictionary);
42779
+ if (array1 && array2) {
42780
+ var x1 = array1[0];
42781
+ var y1 = array1[1];
42782
+ var x2 = array2[0];
42783
+ var y2 = array2[1];
42784
+ var xdiff = void 0;
42785
+ if (this._tabOrder === PdfFormFieldsTabOrder.row) {
42786
+ xdiff = this._compare(page1._pageIndex, page2._pageIndex);
42787
+ if (xdiff !== 0) {
42788
+ result = xdiff;
42789
+ }
42790
+ else {
42791
+ xdiff = this._compare(y2, y1);
42792
+ if (xdiff !== 0) {
42793
+ result = xdiff;
42794
+ }
42795
+ else {
42796
+ result = this._compare(x1, x2);
42797
+ }
42798
+ }
42799
+ }
42800
+ else if (this._tabOrder === PdfFormFieldsTabOrder.column) {
42801
+ xdiff = this._compare(page1._pageIndex, page2._pageIndex);
42802
+ if (xdiff !== 0) {
42803
+ result = xdiff;
42804
+ }
42805
+ else {
42806
+ xdiff = this._compare(x1, x2);
42807
+ if (xdiff !== 0) {
42808
+ result = xdiff;
42809
+ }
42810
+ else {
42811
+ result = this._compare(y2, y1);
42812
+ }
42813
+ }
42814
+ }
42815
+ }
42816
+ }
42817
+ return result;
42704
42818
  };
42705
42819
  PdfForm.prototype._clear = function () {
42706
42820
  this._fields = [];