survey-pdf 2.2.0 → 2.2.2

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * surveyjs - SurveyJS PDF library v2.2.0
2
+ * surveyjs - SurveyJS PDF library v2.2.2
3
3
  * Copyright (c) 2015-2025 Devsoft Baltic OÜ - http://surveyjs.io/
4
4
  * License: MIT (http://www.opensource.org/licenses/mit-license.php)
5
5
  */
@@ -13,7 +13,6 @@ var SurveyPDFModule = /*#__PURE__*/Object.freeze({
13
13
  get BooleanItemBrick () { return BooleanItemBrick; },
14
14
  get CheckItemBrick () { return CheckItemBrick; },
15
15
  get CheckboxItemBrick () { return CheckboxItemBrick; },
16
- get CommentBrick () { return CommentBrick; },
17
16
  get CompositeBrick () { return CompositeBrick; },
18
17
  get CustomBrick () { return CustomBrick; },
19
18
  get DocController () { return DocController; },
@@ -59,7 +58,6 @@ var SurveyPDFModule = /*#__PURE__*/Object.freeze({
59
58
  get SurveyHelper () { return SurveyHelper; },
60
59
  get SurveyPDF () { return SurveyPDF; },
61
60
  get TextBoldBrick () { return TextBoldBrick; },
62
- get TextBoxBrick () { return TextBoxBrick; },
63
61
  get TextBrick () { return TextBrick; },
64
62
  get TextFieldBrick () { return TextFieldBrick; },
65
63
  get TitlePanelBrick () { return TitlePanelBrick; },
@@ -307,6 +305,7 @@ class FlatSurvey {
307
305
  rowFlats.push(...yield this.generateFlatsPanel(survey, controller, element, currPoint));
308
306
  }
309
307
  else {
308
+ yield element.waitForQuestionIsReady();
310
309
  rowFlats.push(...yield SurveyHelper.generateQuestionFlats(survey, controller, element, currPoint));
311
310
  }
312
311
  }
@@ -644,7 +643,15 @@ class FlatQuestion {
644
643
  const otherTextFlat = yield SurveyHelper.createTextFlat(point, this.question, this.controller, text, TextBrick);
645
644
  const otherPoint = SurveyHelper.createPoint(otherTextFlat);
646
645
  otherPoint.yTop += this.controller.unitHeight * SurveyHelper.GAP_BETWEEN_ROWS;
647
- return new CompositeBrick(otherTextFlat, yield SurveyHelper.createCommentFlat(otherPoint, this.question, this.controller, false, { rows: SurveyHelper.OTHER_ROWS_COUNT }));
646
+ return new CompositeBrick(otherTextFlat, yield SurveyHelper.createCommentFlat(otherPoint, this.question, this.controller, {
647
+ fieldName: this.question.id + '_comment',
648
+ rows: SurveyHelper.OTHER_ROWS_COUNT,
649
+ value: this.question.comment !== undefined && this.question.comment !== null ? this.question.comment : '',
650
+ shouldRenderBorders: settings.readOnlyCommentRenderMode === 'textarea',
651
+ isReadOnly: this.question.isReadOnly,
652
+ isMultiline: true,
653
+ placeholder: ''
654
+ }));
648
655
  });
649
656
  }
650
657
  generateFlatsComposite(point) {
@@ -867,16 +874,142 @@ class DescriptionBrick extends TextBrick {
867
874
  }
868
875
  }
869
876
 
877
+ class LinkBrick extends TextBrick {
878
+ constructor(textFlat, link) {
879
+ super(textFlat.question, textFlat.controller, textFlat, textFlat.text);
880
+ this.link = link;
881
+ this.textColor = LinkBrick.COLOR;
882
+ }
883
+ renderInteractive() {
884
+ const _super = Object.create(null, {
885
+ renderInteractive: { get: () => super.renderInteractive }
886
+ });
887
+ return __awaiter(this, void 0, void 0, function* () {
888
+ let oldTextColor = this.controller.doc.getTextColor();
889
+ this.controller.doc.setTextColor(SurveyHelper.BACKGROUND_COLOR);
890
+ let descent = this.controller.unitHeight *
891
+ (this.controller.doc.getLineHeightFactor() -
892
+ LinkBrick.SCALE_FACTOR_MAGIC);
893
+ let yTopLink = this.yTop +
894
+ (this.yBot - this.yTop) - descent;
895
+ this.controller.doc.textWithLink(this.text, this.xLeft, yTopLink, { url: this.link });
896
+ yield _super.renderInteractive.call(this);
897
+ this.controller.doc.setTextColor(oldTextColor);
898
+ });
899
+ }
900
+ renderReadOnly() {
901
+ const _super = Object.create(null, {
902
+ renderInteractive: { get: () => super.renderInteractive }
903
+ });
904
+ return __awaiter(this, void 0, void 0, function* () {
905
+ if (SurveyHelper.getReadonlyRenderAs(this.question, this.controller) !== 'text') {
906
+ return this.renderInteractive();
907
+ }
908
+ yield _super.renderInteractive.call(this);
909
+ });
910
+ }
911
+ }
912
+ LinkBrick.SCALE_FACTOR_MAGIC = 0.955;
913
+ LinkBrick.COLOR = '#0000EE';
914
+
915
+ class HTMLBrick extends PdfBrick {
916
+ constructor(question, controller, rect, html, isImage = false) {
917
+ super(question, controller, rect);
918
+ this.html = html;
919
+ if (isImage) {
920
+ this.margins = {
921
+ top: 0.0,
922
+ bottom: 0.0
923
+ };
924
+ }
925
+ else {
926
+ this.margins = {
927
+ top: controller.margins.top,
928
+ bottom: controller.margins.bot
929
+ };
930
+ }
931
+ }
932
+ renderInteractive() {
933
+ return __awaiter(this, void 0, void 0, function* () {
934
+ let oldFontSize = this.controller.fontSize;
935
+ this.controller.fontSize = this.fontSize;
936
+ yield new Promise((resolve) => {
937
+ this.controller.doc.fromHTML(this.html, this.xLeft, this.yTop, {
938
+ width: this.width, pagesplit: true,
939
+ }, function () {
940
+ [].slice.call(document.querySelectorAll('.sjs-pdf-hidden-html-div')).forEach(function (el) {
941
+ el.parentNode.removeChild(el);
942
+ });
943
+ resolve();
944
+ }, this.margins);
945
+ });
946
+ this.controller.fontSize = oldFontSize;
947
+ });
948
+ }
949
+ }
950
+
951
+ class ImageBrick extends PdfBrick {
952
+ constructor(question, controller, image, point, originalWidth, originalHeight) {
953
+ super(question, controller, {
954
+ xLeft: point.xLeft,
955
+ xRight: point.xLeft + (originalWidth || 0),
956
+ yTop: point.yTop,
957
+ yBot: point.yTop + (originalHeight || 0)
958
+ });
959
+ this.image = image;
960
+ this.originalWidth = originalWidth;
961
+ this.originalHeight = originalHeight;
962
+ this.isPageBreak = this.originalHeight === undefined;
963
+ }
964
+ renderInteractive() {
965
+ return __awaiter(this, void 0, void 0, function* () {
966
+ yield new Promise((resolve) => {
967
+ try {
968
+ this.controller.doc.addImage(this.image, 'PNG', this.xLeft, this.yTop, this.originalWidth, this.originalHeight);
969
+ }
970
+ finally {
971
+ resolve();
972
+ }
973
+ });
974
+ });
975
+ }
976
+ }
977
+
978
+ class EmptyBrick extends PdfBrick {
979
+ constructor(rect, controller = null, isBorderVisible = false) {
980
+ super(null, controller, rect);
981
+ this.controller = controller;
982
+ this.isBorderVisible = false;
983
+ this.isBorderVisible = isBorderVisible;
984
+ }
985
+ resizeBorder(isIncrease) {
986
+ const coef = isIncrease ? 1 : -1;
987
+ const borderPadding = this.controller.doc.getFontSize() * SurveyHelper.VALUE_READONLY_PADDING_SCALE;
988
+ this.xLeft -= coef * borderPadding;
989
+ this.xRight += coef * borderPadding;
990
+ this.yBot += coef * borderPadding;
991
+ }
992
+ renderInteractive() {
993
+ return __awaiter(this, void 0, void 0, function* () {
994
+ if (this.isBorderVisible) {
995
+ this.resizeBorder(true);
996
+ SurveyHelper.renderFlatBorders(this.controller, this);
997
+ this.resizeBorder(false);
998
+ }
999
+ });
1000
+ }
1001
+ }
1002
+
870
1003
  class TextFieldBrick extends PdfBrick {
871
- constructor(question, controller, rect, isQuestion, fieldName, value, placeholder, isReadOnly, isMultiline, inputType) {
1004
+ constructor(question, controller, rect, options) {
1005
+ var _a, _b, _c, _d;
872
1006
  super(question, controller, rect);
873
- this.isQuestion = isQuestion;
874
- this.fieldName = fieldName;
875
- this.value = value;
876
- this.placeholder = placeholder;
877
- this.isReadOnly = isReadOnly;
878
- this.isMultiline = isMultiline;
879
- this.inputType = inputType;
1007
+ this.question = question;
1008
+ this.options = options;
1009
+ options.isMultiline = (_a = options.isMultiline) !== null && _a !== void 0 ? _a : false;
1010
+ options.placeholder = (_b = options.placeholder) !== null && _b !== void 0 ? _b : '';
1011
+ options.inputType = (_c = options.inputType) !== null && _c !== void 0 ? _c : '';
1012
+ options.value = (_d = options.value) !== null && _d !== void 0 ? _d : '';
880
1013
  this.question = question;
881
1014
  }
882
1015
  renderColorQuestion() {
@@ -887,25 +1020,25 @@ class TextFieldBrick extends PdfBrick {
887
1020
  }
888
1021
  renderInteractive() {
889
1022
  return __awaiter(this, void 0, void 0, function* () {
890
- if (this.inputType === 'color') {
1023
+ if (this.options.inputType === 'color') {
891
1024
  this.renderColorQuestion();
892
1025
  return;
893
1026
  }
894
- const inputField = this.inputType === 'password' ?
1027
+ const inputField = this.options.inputType === 'password' ?
895
1028
  new this.controller.doc.AcroFormPasswordField() :
896
1029
  new this.controller.doc.AcroFormTextField();
897
- inputField.fieldName = this.fieldName;
1030
+ inputField.fieldName = this.options.fieldName;
898
1031
  inputField.fontName = this.controller.fontName;
899
1032
  inputField.fontSize = this.fontSize;
900
1033
  inputField.isUnicode = SurveyHelper.isCustomFont(this.controller, inputField.fontName);
901
- if (this.inputType !== 'password') {
902
- inputField.V = ' ' + this.getCorrectedText(this.value);
903
- inputField.DV = ' ' + this.getCorrectedText(this.placeholder);
1034
+ if (this.options.inputType !== 'password') {
1035
+ inputField.V = ' ' + this.getCorrectedText(this.options.value);
1036
+ inputField.DV = ' ' + this.getCorrectedText(this.options.placeholder);
904
1037
  }
905
1038
  else
906
1039
  inputField.value = '';
907
- inputField.multiline = this.isMultiline;
908
- inputField.readOnly = this.isReadOnly;
1040
+ inputField.multiline = this.options.isMultiline;
1041
+ inputField.readOnly = this.options.isReadOnly;
909
1042
  inputField.color = this.textColor;
910
1043
  let formScale = SurveyHelper.formScale(this.controller, this);
911
1044
  inputField.maxFontSize = this.controller.fontSize * formScale;
@@ -915,10 +1048,10 @@ class TextFieldBrick extends PdfBrick {
915
1048
  });
916
1049
  }
917
1050
  shouldRenderFlatBorders() {
918
- return settings.readOnlyTextRenderMode === 'input';
1051
+ return this.options.shouldRenderBorders;
919
1052
  }
920
1053
  getShouldRenderReadOnly() {
921
- return SurveyHelper.shouldRenderReadOnly(this.question, this.controller, this.isReadOnly);
1054
+ return SurveyHelper.shouldRenderReadOnly(this.question, this.controller, this.options.isReadOnly);
922
1055
  }
923
1056
  get textBrick() {
924
1057
  return this._textBrick;
@@ -969,7 +1102,7 @@ class TextFieldBrick extends PdfBrick {
969
1102
  renderReadOnly() {
970
1103
  return __awaiter(this, void 0, void 0, function* () {
971
1104
  this.controller.pushMargins(this.xLeft, this.controller.paperWidth - this.xRight);
972
- if (this.inputType === 'color') {
1105
+ if (this.options.inputType === 'color') {
973
1106
  this.renderColorQuestion();
974
1107
  }
975
1108
  else {
@@ -979,7 +1112,7 @@ class TextFieldBrick extends PdfBrick {
979
1112
  });
980
1113
  }
981
1114
  unfold() {
982
- if (this.getShouldRenderReadOnly() && this.inputType !== 'color') {
1115
+ if (this.getShouldRenderReadOnly() && this.options.inputType !== 'color') {
983
1116
  return this.textBrick.unfold();
984
1117
  }
985
1118
  else {
@@ -1024,152 +1157,6 @@ class TextFieldBrick extends PdfBrick {
1024
1157
  }
1025
1158
  }
1026
1159
 
1027
- class TextBoxBrick extends TextFieldBrick {
1028
- constructor(question, controller, rect, isQuestion = true, isMultiline = false, index = 0) {
1029
- super(question, controller, rect, isQuestion, question.id + (isQuestion ? '' : '_comment' + index), SurveyHelper.getQuestionOrCommentValue(question, isQuestion), isQuestion && question.locPlaceHolder ? SurveyHelper.getLocString(question.locPlaceHolder) : '', question.isReadOnly, isMultiline, question.inputType);
1030
- this.isQuestion = isQuestion;
1031
- this.isMultiline = isMultiline;
1032
- }
1033
- }
1034
-
1035
- class CommentBrick extends TextBoxBrick {
1036
- constructor(question, controller, rect, isQuestion, index = 0) {
1037
- super(question, controller, rect, isQuestion, true, index);
1038
- this.controller = controller;
1039
- }
1040
- shouldRenderFlatBorders() {
1041
- if (this.isQuestion && this.question.getType() !== 'comment')
1042
- return super.shouldRenderFlatBorders();
1043
- return settings.readOnlyCommentRenderMode === 'textarea';
1044
- }
1045
- }
1046
-
1047
- class LinkBrick extends TextBrick {
1048
- constructor(textFlat, link) {
1049
- super(textFlat.question, textFlat.controller, textFlat, textFlat.text);
1050
- this.link = link;
1051
- this.textColor = LinkBrick.COLOR;
1052
- }
1053
- renderInteractive() {
1054
- const _super = Object.create(null, {
1055
- renderInteractive: { get: () => super.renderInteractive }
1056
- });
1057
- return __awaiter(this, void 0, void 0, function* () {
1058
- let oldTextColor = this.controller.doc.getTextColor();
1059
- this.controller.doc.setTextColor(SurveyHelper.BACKGROUND_COLOR);
1060
- let descent = this.controller.unitHeight *
1061
- (this.controller.doc.getLineHeightFactor() -
1062
- LinkBrick.SCALE_FACTOR_MAGIC);
1063
- let yTopLink = this.yTop +
1064
- (this.yBot - this.yTop) - descent;
1065
- this.controller.doc.textWithLink(this.text, this.xLeft, yTopLink, { url: this.link });
1066
- yield _super.renderInteractive.call(this);
1067
- this.controller.doc.setTextColor(oldTextColor);
1068
- });
1069
- }
1070
- renderReadOnly() {
1071
- const _super = Object.create(null, {
1072
- renderInteractive: { get: () => super.renderInteractive }
1073
- });
1074
- return __awaiter(this, void 0, void 0, function* () {
1075
- if (SurveyHelper.getReadonlyRenderAs(this.question, this.controller) !== 'text') {
1076
- return this.renderInteractive();
1077
- }
1078
- yield _super.renderInteractive.call(this);
1079
- });
1080
- }
1081
- }
1082
- LinkBrick.SCALE_FACTOR_MAGIC = 0.955;
1083
- LinkBrick.COLOR = '#0000EE';
1084
-
1085
- class HTMLBrick extends PdfBrick {
1086
- constructor(question, controller, rect, html, isImage = false) {
1087
- super(question, controller, rect);
1088
- this.html = html;
1089
- if (isImage) {
1090
- this.margins = {
1091
- top: 0.0,
1092
- bottom: 0.0
1093
- };
1094
- }
1095
- else {
1096
- this.margins = {
1097
- top: controller.margins.top,
1098
- bottom: controller.margins.bot
1099
- };
1100
- }
1101
- }
1102
- renderInteractive() {
1103
- return __awaiter(this, void 0, void 0, function* () {
1104
- let oldFontSize = this.controller.fontSize;
1105
- this.controller.fontSize = this.fontSize;
1106
- yield new Promise((resolve) => {
1107
- this.controller.doc.fromHTML(this.html, this.xLeft, this.yTop, {
1108
- width: this.width, pagesplit: true,
1109
- }, function () {
1110
- [].slice.call(document.querySelectorAll('.sjs-pdf-hidden-html-div')).forEach(function (el) {
1111
- el.parentNode.removeChild(el);
1112
- });
1113
- resolve();
1114
- }, this.margins);
1115
- });
1116
- this.controller.fontSize = oldFontSize;
1117
- });
1118
- }
1119
- }
1120
-
1121
- class ImageBrick extends PdfBrick {
1122
- constructor(question, controller, image, point, originalWidth, originalHeight) {
1123
- super(question, controller, {
1124
- xLeft: point.xLeft,
1125
- xRight: point.xLeft + (originalWidth || 0),
1126
- yTop: point.yTop,
1127
- yBot: point.yTop + (originalHeight || 0)
1128
- });
1129
- this.image = image;
1130
- this.originalWidth = originalWidth;
1131
- this.originalHeight = originalHeight;
1132
- this.isPageBreak = this.originalHeight === undefined;
1133
- }
1134
- renderInteractive() {
1135
- return __awaiter(this, void 0, void 0, function* () {
1136
- yield new Promise((resolve) => {
1137
- try {
1138
- this.controller.doc.addImage(this.image, 'PNG', this.xLeft, this.yTop, this.originalWidth, this.originalHeight);
1139
- }
1140
- finally {
1141
- resolve();
1142
- }
1143
- });
1144
- });
1145
- }
1146
- }
1147
-
1148
- class EmptyBrick extends PdfBrick {
1149
- constructor(rect, controller = null, isBorderVisible = false) {
1150
- super(null, controller, rect);
1151
- this.controller = controller;
1152
- this.isBorderVisible = false;
1153
- this.isBorderVisible = isBorderVisible;
1154
- }
1155
- resizeBorder(isIncrease) {
1156
- const coef = isIncrease ? 1 : -1;
1157
- const borderPadding = this.controller.doc.getFontSize() * SurveyHelper.VALUE_READONLY_PADDING_SCALE;
1158
- this.xLeft -= coef * borderPadding;
1159
- this.xRight += coef * borderPadding;
1160
- this.yBot += coef * borderPadding;
1161
- }
1162
- renderInteractive() {
1163
- return __awaiter(this, void 0, void 0, function* () {
1164
- if (this.isBorderVisible) {
1165
- this.resizeBorder(true);
1166
- SurveyHelper.renderFlatBorders(this.controller, this);
1167
- this.resizeBorder(false);
1168
- }
1169
- });
1170
- }
1171
- }
1172
-
1173
1160
  class SurveyHelper {
1174
1161
  static parseWidth(width, maxWidth, columnsCount = 1, defaultUnit) {
1175
1162
  if (width.indexOf('calc') === 0) {
@@ -1537,35 +1524,26 @@ class SurveyHelper {
1537
1524
  static getReadonlyRenderAs(question, controller) {
1538
1525
  return question.readonlyRenderAs === 'auto' ? controller.readonlyRenderAs : question.readonlyRenderAs;
1539
1526
  }
1540
- static createCommentFlat(point_1, question_1, controller_1, isQuestion_1) {
1541
- return __awaiter(this, arguments, void 0, function* (point, question, controller, isQuestion, options = {}) {
1542
- var _a, _b, _c;
1543
- const rect = this.createTextFieldRect(point, controller, (_a = options.rows) !== null && _a !== void 0 ? _a : 1);
1527
+ static createCommentFlat(point, question, controller, options) {
1528
+ return __awaiter(this, void 0, void 0, function* () {
1529
+ var _a, _b;
1530
+ options.rows = (_a = options.rows) !== null && _a !== void 0 ? _a : 1;
1531
+ options.value = (_b = options.value) !== null && _b !== void 0 ? _b : '';
1532
+ const rect = this.createTextFieldRect(point, controller, options.rows);
1544
1533
  let textFlat;
1545
- if ((_b = options.readOnly) !== null && _b !== void 0 ? _b : SurveyHelper.shouldRenderReadOnly(question, controller)) {
1546
- const renderedValue = (_c = options.value) !== null && _c !== void 0 ? _c : this.getQuestionOrCommentValue(question, isQuestion);
1547
- textFlat = yield this.createReadOnlyTextFieldTextFlat(point, controller, question, renderedValue);
1534
+ if (SurveyHelper.shouldRenderReadOnly(question, controller, options.isReadOnly)) {
1535
+ textFlat = yield this.createReadOnlyTextFieldTextFlat(point, controller, question, options.value);
1548
1536
  const padding = controller.unitHeight * this.VALUE_READONLY_PADDING_SCALE;
1549
1537
  if (textFlat.yBot + padding > rect.yBot)
1550
1538
  rect.yBot = textFlat.yBot + padding;
1551
1539
  }
1552
- const comment = new CommentBrick(question, controller, rect, isQuestion, options.index);
1553
- if (options.readOnly !== null && options.readOnly !== undefined) {
1554
- comment.isReadOnly = options.readOnly;
1555
- }
1540
+ const comment = new TextFieldBrick(question, controller, rect, options);
1556
1541
  if (textFlat) {
1557
1542
  comment.textBrick = textFlat;
1558
1543
  }
1559
1544
  return comment;
1560
1545
  });
1561
1546
  }
1562
- static getQuestionOrCommentValue(question, isQuestion = true) {
1563
- return isQuestion ? (question.value !== undefined && question.value !== null ? question.value : '') :
1564
- (question.comment !== undefined && question.comment !== null ? question.comment : '');
1565
- }
1566
- static getQuestionOrCommentDisplayValue(question, isQuestion = true) {
1567
- return isQuestion ? question.displayValue : SurveyHelper.getQuestionOrCommentValue(question, isQuestion);
1568
- }
1569
1547
  static get hasDocument() {
1570
1548
  return typeof document !== 'undefined';
1571
1549
  }
@@ -5623,13 +5601,11 @@ function setRadioAppearance(doc) {
5623
5601
  };
5624
5602
 
5625
5603
  Renderer.prototype.splitFragmentsIntoLines = function (fragments, styles) {
5626
- var currentLineLength, defaultFontSize, ff, fontMetrics, fontMetricsCache, fragment, fragmentChopped, fragmentLength, fragmentSpecificMetrics, fs, k, line, lines, maxLineLength, style;
5604
+ var currentLineLength, defaultFontSize, ff, fragment, fragmentChopped, fragmentLength, fragmentSpecificMetrics, fs, k, line, lines, maxLineLength, style;
5627
5605
  defaultFontSize = 12;
5628
5606
  k = this.pdf.internal.scaleFactor;
5629
- fontMetricsCache = {};
5630
5607
  ff = void 0;
5631
5608
  fs = void 0;
5632
- fontMetrics = void 0;
5633
5609
  fragment = void 0;
5634
5610
  style = void 0;
5635
5611
  fragmentSpecificMetrics = void 0;
@@ -5639,7 +5615,8 @@ function setRadioAppearance(doc) {
5639
5615
  lines = [line];
5640
5616
  currentLineLength = 0;
5641
5617
  maxLineLength = this.settings.width;
5642
-
5618
+ const oldFontName = this.pdf.getFont().fontName;
5619
+ const oldFontStyle = this.pdf.getFont().fontStyle;
5643
5620
  while (fragments.length) {
5644
5621
  fragment = fragments.shift();
5645
5622
  style = styles.shift();
@@ -5647,18 +5624,10 @@ function setRadioAppearance(doc) {
5647
5624
  if (fragment) {
5648
5625
  ff = style["font-family"];
5649
5626
  fs = style["font-style"];
5650
- fontMetrics = fontMetricsCache[ff + fs];
5651
-
5652
- if (!fontMetrics) {
5653
- fontMetrics = this.pdf.internal.getFont(ff, fs).metadata.Unicode;
5654
- fontMetricsCache[ff + fs] = fontMetrics;
5655
- }
5656
-
5627
+ this.pdf.setFont(ff, fs);
5657
5628
  fragmentSpecificMetrics = {
5658
- widths: fontMetrics.widths,
5659
- kerning: fontMetrics.kerning,
5660
- fontSize: style["font-size"] * defaultFontSize,
5661
- textIndent: currentLineLength
5629
+ textIndent: currentLineLength,
5630
+ fontSize: style["font-size"] * defaultFontSize
5662
5631
  };
5663
5632
  fragmentLength = this.pdf.getStringUnitWidth(fragment, fragmentSpecificMetrics) * fragmentSpecificMetrics.fontSize / k;
5664
5633
 
@@ -5707,7 +5676,7 @@ function setRadioAppearance(doc) {
5707
5676
  }
5708
5677
  }
5709
5678
  }
5710
-
5679
+ this.pdf.setFont(oldFontName, oldFontStyle);
5711
5680
  return lines;
5712
5681
  };
5713
5682
 
@@ -7586,42 +7555,6 @@ class SurveyPDF extends SurveyModel {
7586
7555
  // eslint-disable-next-line no-console
7587
7556
  console.error('As of v1.9.101, the haveCommercialLicense property is not supported. To activate your license, use the setLicenseKey(key) method as shown on the following page: https://surveyjs.io/remove-alert-banner');
7588
7557
  }
7589
- ensureQuestionDisplayValue(question) {
7590
- question.displayValue;
7591
- }
7592
- waitForQuestionIsReady(question) {
7593
- return new Promise((resolve) => {
7594
- this.ensureQuestionDisplayValue(question);
7595
- if (question.isReady) {
7596
- resolve();
7597
- }
7598
- else {
7599
- const readyCallback = (_, options) => {
7600
- if (options.isReady) {
7601
- question.onReadyChanged.remove(readyCallback);
7602
- resolve();
7603
- }
7604
- };
7605
- question.onReadyChanged.add(readyCallback);
7606
- }
7607
- });
7608
- }
7609
- waitForCoreIsReady() {
7610
- return __awaiter(this, void 0, void 0, function* () {
7611
- for (const question of this.getAllQuestions()) {
7612
- if (!!question.contentPanel) {
7613
- const list = [];
7614
- question.contentPanel.addQuestionsToList(list);
7615
- for (const innerQuestion of list) {
7616
- yield this.waitForQuestionIsReady(innerQuestion);
7617
- }
7618
- continue;
7619
- }
7620
- else
7621
- yield this.waitForQuestionIsReady(SurveyHelper.getContentQuestion(question));
7622
- }
7623
- });
7624
- }
7625
7558
  getUpdatedCheckItemAcroformOptions(options) {
7626
7559
  this.onRenderCheckItemAcroform.fire(this, options);
7627
7560
  }
@@ -7646,7 +7579,6 @@ class SurveyPDF extends SurveyModel {
7646
7579
  renderSurvey(controller) {
7647
7580
  return __awaiter(this, void 0, void 0, function* () {
7648
7581
  this.visiblePages.forEach(page => page.onFirstRendering());
7649
- yield this.waitForCoreIsReady();
7650
7582
  const flats = yield FlatSurvey.generateFlats(this, controller);
7651
7583
  this.correctBricksPosition(controller, flats);
7652
7584
  const packs = PagePacker.pack(flats, controller);
@@ -7916,7 +7848,14 @@ class FlatSelectBase extends FlatQuestion {
7916
7848
  (typeof this.question.isOtherSelected !== 'undefined' && this.question.isOtherSelected))) {
7917
7849
  const otherPoint = SurveyHelper.createPoint(compositeFlat);
7918
7850
  otherPoint.yTop += this.controller.unitHeight * SurveyHelper.GAP_BETWEEN_ROWS;
7919
- compositeFlat.addBrick(yield SurveyHelper.createCommentFlat(otherPoint, this.question, this.controller, false, { index, rows: SurveyHelper.OTHER_ROWS_COUNT }));
7851
+ compositeFlat.addBrick(yield SurveyHelper.createCommentFlat(otherPoint, this.question, this.controller, {
7852
+ fieldName: this.question.id + '_comment' + index,
7853
+ rows: SurveyHelper.OTHER_ROWS_COUNT,
7854
+ value: this.question.comment !== undefined && this.question.comment !== null ? this.question.comment : '',
7855
+ shouldRenderBorders: settings.readOnlyCommentRenderMode === 'textarea',
7856
+ isReadOnly: this.question.isReadOnly,
7857
+ isMultiline: true,
7858
+ }));
7920
7859
  }
7921
7860
  return compositeFlat;
7922
7861
  });
@@ -7942,11 +7881,41 @@ class FlatSelectBase extends FlatQuestion {
7942
7881
  else if (colCount > 1) {
7943
7882
  currentColCount = (SurveyHelper.getColumnWidth(this.controller, colCount) <
7944
7883
  this.controller.measureText(SurveyHelper.MATRIX_COLUMN_WIDTH).width) ? 1 : colCount;
7884
+ if (currentColCount == colCount) {
7885
+ return yield this.generateColumns(point);
7886
+ }
7945
7887
  }
7946
7888
  return (currentColCount == 1) ? yield this.generateVerticallyItems(point, visibleChoices) :
7947
7889
  yield this.generateHorisontallyItems(point, currentColCount);
7948
7890
  });
7949
7891
  }
7892
+ generateRows(point, rows) {
7893
+ return __awaiter(this, void 0, void 0, function* () {
7894
+ var _a;
7895
+ const visibleChoices = this.getVisibleChoices();
7896
+ const currPoint = SurveyHelper.clone(point);
7897
+ const colCount = ((_a = rows[0]) !== null && _a !== void 0 ? _a : []).length;
7898
+ const flats = [];
7899
+ for (let row of rows) {
7900
+ const rowFlat = new CompositeBrick();
7901
+ this.controller.pushMargins(this.controller.margins.left, this.controller.margins.right);
7902
+ for (let colIndex = 0; colIndex < row.length; colIndex++) {
7903
+ const item = row[colIndex];
7904
+ this.controller.pushMargins(this.controller.margins.left, this.controller.margins.right);
7905
+ SurveyHelper.setColumnMargins(this.controller, colCount, colIndex);
7906
+ currPoint.xLeft = this.controller.margins.left;
7907
+ const itemFlat = yield this.generateFlatComposite(currPoint, item, visibleChoices.indexOf(item));
7908
+ rowFlat.addBrick(itemFlat);
7909
+ this.controller.popMargins();
7910
+ }
7911
+ const rowLineFlat = SurveyHelper.createRowlineFlat(SurveyHelper.createPoint(rowFlat), this.controller);
7912
+ currPoint.yTop = rowLineFlat.yBot +
7913
+ SurveyHelper.GAP_BETWEEN_ROWS * this.controller.unitHeight;
7914
+ flats.push(rowFlat, rowLineFlat);
7915
+ }
7916
+ return flats;
7917
+ });
7918
+ }
7950
7919
  generateVerticallyItems(point, itemValues) {
7951
7920
  return __awaiter(this, void 0, void 0, function* () {
7952
7921
  const currPoint = SurveyHelper.clone(point);
@@ -7959,28 +7928,35 @@ class FlatSelectBase extends FlatQuestion {
7959
7928
  return flats;
7960
7929
  });
7961
7930
  }
7962
- generateHorisontallyItems(point, colCount) {
7931
+ generateColumns(point) {
7963
7932
  return __awaiter(this, void 0, void 0, function* () {
7964
- const visibleChoices = this.getVisibleChoices();
7965
- const currPoint = SurveyHelper.clone(point);
7966
- const flats = [];
7967
- let row = new CompositeBrick();
7968
- for (let i = 0; i < visibleChoices.length; i++) {
7969
- this.controller.pushMargins(this.controller.margins.left, this.controller.margins.right);
7970
- SurveyHelper.setColumnMargins(this.controller, colCount, i % colCount);
7971
- currPoint.xLeft = this.controller.margins.left;
7972
- const itemFlat = yield this.generateFlatComposite(currPoint, visibleChoices[i], i);
7973
- row.addBrick(itemFlat);
7974
- this.controller.popMargins();
7975
- if (i % colCount === colCount - 1 || i === visibleChoices.length - 1) {
7976
- const rowLineFlat = SurveyHelper.createRowlineFlat(SurveyHelper.createPoint(row), this.controller);
7977
- currPoint.yTop = rowLineFlat.yBot +
7978
- SurveyHelper.GAP_BETWEEN_ROWS * this.controller.unitHeight;
7979
- flats.push(row, rowLineFlat);
7980
- row = new CompositeBrick();
7933
+ const columns = this.question.columns;
7934
+ const rowsCount = columns.reduce((max, column) => Math.max(max, column.length), 0);
7935
+ const rows = [];
7936
+ for (let i = 0; i < rowsCount; i++) {
7937
+ const row = [];
7938
+ for (let column of columns) {
7939
+ if (column[i]) {
7940
+ row.push(column[i]);
7941
+ }
7981
7942
  }
7943
+ rows.push(row);
7982
7944
  }
7983
- return flats;
7945
+ return yield this.generateRows(point, rows);
7946
+ });
7947
+ }
7948
+ generateHorisontallyItems(point, colCount) {
7949
+ return __awaiter(this, void 0, void 0, function* () {
7950
+ const rows = [];
7951
+ const visibleChoices = this.getVisibleChoices();
7952
+ visibleChoices.forEach((item, index) => {
7953
+ const rowIndex = Math.floor(index / colCount);
7954
+ const colIndex = index % colCount;
7955
+ if (!rows[rowIndex])
7956
+ rows[rowIndex] = [];
7957
+ rows[rowIndex][colIndex] = item;
7958
+ });
7959
+ return yield this.generateRows(point, rows);
7984
7960
  });
7985
7961
  }
7986
7962
  }
@@ -8125,7 +8101,15 @@ class FlatComment extends FlatQuestion {
8125
8101
  }
8126
8102
  generateFlatsContent(point) {
8127
8103
  return __awaiter(this, void 0, void 0, function* () {
8128
- return [yield SurveyHelper.createCommentFlat(point, this.question, this.controller, true, { rows: this.question.rows })];
8104
+ return [yield SurveyHelper.createCommentFlat(point, this.question, this.controller, {
8105
+ rows: this.question.rows,
8106
+ isReadOnly: this.question.isReadOnly,
8107
+ isMultiline: true,
8108
+ fieldName: this.question.id,
8109
+ placeholder: SurveyHelper.getLocString(this.question.locPlaceHolder),
8110
+ shouldRenderBorders: settings.readOnlyCommentRenderMode === 'textarea',
8111
+ value: this.question.value
8112
+ })];
8129
8113
  });
8130
8114
  }
8131
8115
  }
@@ -8172,12 +8156,25 @@ class FlatDropdown extends FlatQuestion {
8172
8156
  }
8173
8157
  generateFlatsContent(point) {
8174
8158
  return __awaiter(this, void 0, void 0, function* () {
8175
- const valueBrick = !this.shouldRenderAsComment ? new DropdownBrick(this.question, this.controller, SurveyHelper.createTextFieldRect(point, this.controller)) : yield SurveyHelper.createCommentFlat(point, this.question, this.controller, true, { value: SurveyHelper.getDropdownQuestionValue(this.question) });
8159
+ const valueBrick = !this.shouldRenderAsComment ? new DropdownBrick(this.question, this.controller, SurveyHelper.createTextFieldRect(point, this.controller)) : yield SurveyHelper.createCommentFlat(point, this.question, this.controller, {
8160
+ fieldName: this.question.id,
8161
+ shouldRenderBorders: settings.readOnlyTextRenderMode === 'input',
8162
+ value: SurveyHelper.getDropdownQuestionValue(this.question),
8163
+ isReadOnly: this.question.isReadOnly,
8164
+ placeholder: SurveyHelper.getLocString(this.question.locPlaceholder)
8165
+ });
8176
8166
  const compositeFlat = new CompositeBrick(valueBrick);
8177
8167
  if (this.question.isOtherSelected) {
8178
8168
  const otherPoint = SurveyHelper.createPoint(compositeFlat);
8179
8169
  otherPoint.yTop += this.controller.unitHeight * SurveyHelper.GAP_BETWEEN_ROWS;
8180
- compositeFlat.addBrick(yield SurveyHelper.createCommentFlat(otherPoint, this.question, this.controller, false, { rows: SurveyHelper.OTHER_ROWS_COUNT }));
8170
+ compositeFlat.addBrick(yield SurveyHelper.createCommentFlat(otherPoint, this.question, this.controller, {
8171
+ fieldName: this.question.id + '_comment',
8172
+ rows: SurveyHelper.OTHER_ROWS_COUNT,
8173
+ value: this.question.comment !== undefined && this.question.comment !== null ? this.question.comment : '',
8174
+ shouldRenderBorders: settings.readOnlyCommentRenderMode === 'textarea',
8175
+ isReadOnly: this.question.isReadOnly,
8176
+ isMultiline: true,
8177
+ }));
8181
8178
  }
8182
8179
  return [compositeFlat];
8183
8180
  });
@@ -8193,7 +8190,12 @@ class FlatExpression extends FlatQuestion {
8193
8190
  }
8194
8191
  generateFlatsContent(point) {
8195
8192
  return __awaiter(this, void 0, void 0, function* () {
8196
- return [yield SurveyHelper.createCommentFlat(point, this.question, this.controller, true, { value: this.question.displayValue, readOnly: true })];
8193
+ return [yield SurveyHelper.createCommentFlat(point, this.question, this.controller, {
8194
+ value: this.question.displayValue,
8195
+ isReadOnly: true,
8196
+ fieldName: this.question.id,
8197
+ shouldRenderBorders: settings.readOnlyTextRenderMode === 'input',
8198
+ })];
8197
8199
  });
8198
8200
  }
8199
8201
  }
@@ -8751,11 +8753,19 @@ class FlatTextbox extends FlatQuestion {
8751
8753
  }
8752
8754
  generateFlatsContent(point) {
8753
8755
  return __awaiter(this, void 0, void 0, function* () {
8756
+ const options = {
8757
+ fieldName: this.question.id,
8758
+ inputType: this.question.inputType,
8759
+ value: this.question.inputValue,
8760
+ isReadOnly: this.question.isReadOnly,
8761
+ shouldRenderBorders: settings.readOnlyTextRenderMode === 'input',
8762
+ placeholder: SurveyHelper.getLocString(this.question.locPlaceHolder)
8763
+ };
8754
8764
  if (!this.shouldRenderAsComment) {
8755
8765
  const rect = SurveyHelper.createTextFieldRect(point, this.controller);
8756
- return [new TextBoxBrick(this.question, this.controller, rect)];
8766
+ return [new TextFieldBrick(this.question, this.controller, rect, Object.assign({}, options))];
8757
8767
  }
8758
- return [yield SurveyHelper.createCommentFlat(point, this.question, this.controller, true, { rows: FlatTextbox.MULTILINE_TEXT_ROWS_COUNT })];
8768
+ return [yield SurveyHelper.createCommentFlat(point, this.question, this.controller, Object.assign({ rows: FlatTextbox.MULTILINE_TEXT_ROWS_COUNT, isMultiline: true }, options))];
8759
8769
  });
8760
8770
  }
8761
8771
  }
@@ -9280,7 +9290,7 @@ class CustomBrick extends PdfBrick {
9280
9290
  }
9281
9291
  }
9282
9292
 
9283
- checkLibraryVersion(`${"2.2.0"}`, 'survey-pdf');
9293
+ checkLibraryVersion(`${"2.2.2"}`, 'survey-pdf');
9284
9294
 
9285
- export { BooleanItemBrick, CheckItemBrick, CheckboxItemBrick, CommentBrick, CompositeBrick, CustomBrick, DocController, DocOptions, DrawCanvas, DropdownBrick, EmptyBrick, EventHandler, FlatBooleanCheckbox as FlatBoolean, FlatCheckbox, FlatComment, FlatCustomModel, FlatDropdown, FlatExpression, FlatFile, FlatHTML, FlatImage, FlatImagePicker, FlatMatrix, FlatMatrixDynamic, FlatMatrixMultiple, FlatMultipleText, FlatPanelDynamic, FlatQuestion, FlatQuestionDefault, FlatRadiogroup, FlatRanking, FlatRating, FlatRepository, FlatSelectBase, FlatSignaturePad, FlatSurvey, FlatTextbox, HTMLBrick, HorizontalAlign, ImageBrick, LinkBrick, PagePacker, PdfBrick, RadioItemBrick, RankingItemBrick, RowlineBrick, SurveyHelper, SurveyPDF, TextBoldBrick, TextBoxBrick, TextBrick, TextFieldBrick, TitlePanelBrick, VerticalAlign };
9295
+ export { BooleanItemBrick, CheckItemBrick, CheckboxItemBrick, CompositeBrick, CustomBrick, DocController, DocOptions, DrawCanvas, DropdownBrick, EmptyBrick, EventHandler, FlatBooleanCheckbox as FlatBoolean, FlatCheckbox, FlatComment, FlatCustomModel, FlatDropdown, FlatExpression, FlatFile, FlatHTML, FlatImage, FlatImagePicker, FlatMatrix, FlatMatrixDynamic, FlatMatrixMultiple, FlatMultipleText, FlatPanelDynamic, FlatQuestion, FlatQuestionDefault, FlatRadiogroup, FlatRanking, FlatRating, FlatRepository, FlatSelectBase, FlatSignaturePad, FlatSurvey, FlatTextbox, HTMLBrick, HorizontalAlign, ImageBrick, LinkBrick, PagePacker, PdfBrick, RadioItemBrick, RankingItemBrick, RowlineBrick, SurveyHelper, SurveyPDF, TextBoldBrick, TextBrick, TextFieldBrick, TitlePanelBrick, VerticalAlign };
9286
9296
  //# sourceMappingURL=survey.pdf.mjs.map