@syncfusion/ej2-docx-renderer 0.0.0-stage → 35.2.15
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.
- package/README.md +2 -2
- package/base.d.ts +4 -0
- package/base.js +4 -0
- package/dist/ej2-docx-renderer.umd.min.js +2 -0
- package/dist/ej2-docx-renderer.umd.min.js.map +1 -0
- package/dist/es6/ej2-docx-renderer.es2015.js +52432 -0
- package/dist/es6/ej2-docx-renderer.es2015.js.map +1 -0
- package/dist/es6/ej2-docx-renderer.es5.js +54425 -0
- package/dist/es6/ej2-docx-renderer.es5.js.map +1 -0
- package/dist/global/ej2-docx-renderer.min.js +2 -0
- package/dist/global/ej2-docx-renderer.min.js.map +1 -0
- package/dist/global/index.d.ts +5 -0
- package/format.d.ts +4 -0
- package/format.js +4 -0
- package/helper.d.ts +4 -0
- package/helper.js +4 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/list.d.ts +4 -0
- package/list.js +4 -0
- package/package.json +26 -4
- package/parser.d.ts +4 -0
- package/parser.js +4 -0
- package/src/base/constants.d.ts +2 -0
- package/src/base/constants.js +2 -0
- package/src/base/dictionary.d.ts +52 -0
- package/src/base/dictionary.js +137 -0
- package/src/base/index.d.ts +9 -0
- package/src/base/index.js +9 -0
- package/src/base/keywords.d.ts +422 -0
- package/src/base/keywords.js +422 -0
- package/src/base/types.d.ts +2590 -0
- package/src/base/types.js +1056 -0
- package/src/base/unique-format.d.ts +87 -0
- package/src/base/unique-format.js +858 -0
- package/src/base/unique-formats.d.ts +32 -0
- package/src/base/unique-formats.js +87 -0
- package/src/document-canvas.d.ts +61 -0
- package/src/document-canvas.js +221 -0
- package/src/docx-renderer.d.ts +941 -0
- package/src/docx-renderer.js +2251 -0
- package/src/format/border.d.ts +53 -0
- package/src/format/border.js +600 -0
- package/src/format/borders.d.ts +44 -0
- package/src/format/borders.js +314 -0
- package/src/format/cell-format.d.ts +42 -0
- package/src/format/cell-format.js +309 -0
- package/src/format/character-format.d.ts +152 -0
- package/src/format/character-format.js +1224 -0
- package/src/format/index.d.ts +14 -0
- package/src/format/index.js +14 -0
- package/src/format/list-format.d.ts +32 -0
- package/src/format/list-format.js +238 -0
- package/src/format/paragraph-format.d.ts +103 -0
- package/src/format/paragraph-format.js +854 -0
- package/src/format/row-format.d.ts +119 -0
- package/src/format/row-format.js +545 -0
- package/src/format/section-format.d.ts +89 -0
- package/src/format/section-format.js +689 -0
- package/src/format/shading.d.ts +24 -0
- package/src/format/shading.js +137 -0
- package/src/format/style.d.ts +106 -0
- package/src/format/style.js +286 -0
- package/src/format/table-format.d.ts +51 -0
- package/src/format/table-format.js +395 -0
- package/src/global.js +1 -0
- package/src/helper/document-editor-helper.d.ts +515 -0
- package/src/helper/document-editor-helper.js +1302 -0
- package/src/helper/document-editor-settings.d.ts +293 -0
- package/src/helper/document-editor-settings.js +94 -0
- package/src/helper/index.d.ts +5 -0
- package/src/helper/index.js +5 -0
- package/src/helper/layout-helper-methods.d.ts +539 -0
- package/src/helper/layout-helper-methods.js +1065 -0
- package/src/helper/renderer-hooks.d.ts +74 -0
- package/src/helper/renderer-hooks.js +14 -0
- package/src/helper/revision-helper-methods.d.ts +199 -0
- package/src/helper/revision-helper-methods.js +362 -0
- package/src/index.d.ts +18 -0
- package/src/index.js +18 -0
- package/src/layout-helper.d.ts +190 -0
- package/src/layout-helper.js +1368 -0
- package/src/layout.d.ts +779 -0
- package/src/layout.js +17232 -0
- package/src/list/abstract-list.d.ts +25 -0
- package/src/list/abstract-list.js +67 -0
- package/src/list/index.d.ts +7 -0
- package/src/list/index.js +7 -0
- package/src/list/level-override.d.ts +22 -0
- package/src/list/level-override.js +43 -0
- package/src/list/list-level.d.ts +57 -0
- package/src/list/list-level.js +249 -0
- package/src/list/list.d.ts +30 -0
- package/src/list/list.js +100 -0
- package/src/page.d.ts +4155 -0
- package/src/page.js +11342 -0
- package/src/parser/index.d.ts +1 -0
- package/src/parser/index.js +1 -0
- package/src/parser/sfdt-reader.d.ts +254 -0
- package/src/parser/sfdt-reader.js +4569 -0
- package/src/render.d.ts +226 -0
- package/src/render.js +4222 -0
- package/src/text-helper.d.ts +144 -0
- package/src/text-helper.js +1079 -0
- package/src/text-helpers/index.d.ts +2 -0
- package/src/text-helpers/index.js +2 -0
- package/src/text-helpers/optimized.d.ts +45 -0
- package/src/text-helpers/optimized.js +121 -0
- package/src/text-helpers/regular.d.ts +37 -0
- package/src/text-helpers/regular.js +93 -0
- package/src/themes/font-scheme.d.ts +28 -0
- package/src/themes/font-scheme.js +107 -0
- package/src/themes/index.d.ts +6 -0
- package/src/themes/index.js +6 -0
- package/src/themes/major-minor-font-scheme.d.ts +14 -0
- package/src/themes/major-minor-font-scheme.js +45 -0
- package/src/themes/themes.d.ts +11 -0
- package/src/themes/themes.js +31 -0
- package/src/utility/index.d.ts +1 -0
- package/src/utility/index.js +1 -0
- package/src/utility/path-util.d.ts +133 -0
- package/src/utility/path-util.js +639 -0
- package/text-helpers.d.ts +4 -0
- package/text-helpers.js +4 -0
- package/themes.d.ts +4 -0
- package/themes.js +4 -0
- package/utility.d.ts +4 -0
- package/utility.js +4 -0
|
@@ -0,0 +1,2251 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
4
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
5
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
6
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
10
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
11
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
12
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
13
|
+
function step(op) {
|
|
14
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
15
|
+
while (_) try {
|
|
16
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
17
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
18
|
+
switch (op[0]) {
|
|
19
|
+
case 0: case 1: t = op; break;
|
|
20
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
21
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
22
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
23
|
+
default:
|
|
24
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
25
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
26
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
27
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
28
|
+
if (t[2]) _.ops.pop();
|
|
29
|
+
_.trys.pop(); continue;
|
|
30
|
+
}
|
|
31
|
+
op = body.call(thisArg, _);
|
|
32
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
33
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
import { Dictionary } from './base/dictionary';
|
|
37
|
+
import { WAbstractList } from './list/abstract-list';
|
|
38
|
+
import { WLevelOverride } from './list/level-override';
|
|
39
|
+
import { WCharacterFormat } from './format/character-format';
|
|
40
|
+
import { WParagraphFormat } from './format/paragraph-format';
|
|
41
|
+
import { WStyles } from './format/style';
|
|
42
|
+
import { Layout } from './layout';
|
|
43
|
+
import { isNullOrUndefined } from '@syncfusion/ej2-base';
|
|
44
|
+
import { FieldElementBox, ParagraphWidget, HeaderFooterWidget, TextFrame, Footnote, FootNoteWidget, BodyWidget, TableWidget, TableCellWidget, BookmarkElementBox, Rect } from './page';
|
|
45
|
+
import { TextHelper } from './text-helper';
|
|
46
|
+
import { Themes } from './themes/themes';
|
|
47
|
+
import { PageLayoutHelper } from './layout-helper';
|
|
48
|
+
import { SfdtReader } from './parser/sfdt-reader';
|
|
49
|
+
import { Optimized } from './index';
|
|
50
|
+
import { LayoutHelperMethods } from './index';
|
|
51
|
+
import { Renderer } from './render';
|
|
52
|
+
import { EditorProperties } from './helper/document-editor-helper';
|
|
53
|
+
import { DocumentEditorSettingsModel, DocumentSettingsModel } from './helper/document-editor-settings';
|
|
54
|
+
import { RendererHooks } from './helper/renderer-hooks';
|
|
55
|
+
/**
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
var DocxRenderer = /** @class */ (function () {
|
|
59
|
+
/**
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
function DocxRenderer() {
|
|
63
|
+
// Originated in editor
|
|
64
|
+
/**
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
this.enableLayout = true;
|
|
68
|
+
/**
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
this.layoutType = 'Pages';
|
|
72
|
+
/**
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
this.isLayoutEnabled = true;
|
|
76
|
+
/**
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
this.isShiftingEnabled = false;
|
|
80
|
+
/**
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
this.isEditorModule = false;
|
|
84
|
+
/**
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
this.isSfdtExportModule = false;
|
|
88
|
+
/**
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
this.isSelectionModule = false;
|
|
92
|
+
/**
|
|
93
|
+
* @private
|
|
94
|
+
*/
|
|
95
|
+
this.isFormatPainterModule = false;
|
|
96
|
+
/**
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
this.formatPainterCursor = 'text';
|
|
100
|
+
/**
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
this.formatPainterActive = false;
|
|
104
|
+
/**
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
this.viewerContainer = undefined;
|
|
108
|
+
/**
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
this.isSelectionInHeaderFooter = false;
|
|
112
|
+
/**
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
115
|
+
this.isSpellCheck = false;
|
|
116
|
+
/**
|
|
117
|
+
* Page outline color
|
|
118
|
+
*/
|
|
119
|
+
/**
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
this.pageOutline = '#000000';
|
|
123
|
+
// Originated form sfdt export module
|
|
124
|
+
/**
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
127
|
+
this.copyWithTrackChange = false;
|
|
128
|
+
/**
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
this.currentPage = undefined;
|
|
132
|
+
/**
|
|
133
|
+
* @private
|
|
134
|
+
*/
|
|
135
|
+
this.backgroundColor = '#FFFFFF';
|
|
136
|
+
/**
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
this.enableTrackChanges = false;
|
|
140
|
+
//Document Protection Properties Starts
|
|
141
|
+
/**
|
|
142
|
+
* preserve the format
|
|
143
|
+
*/
|
|
144
|
+
/**
|
|
145
|
+
* @private
|
|
146
|
+
*/
|
|
147
|
+
this.restrictFormatting = false;
|
|
148
|
+
/**
|
|
149
|
+
* preserve the document protection type either readonly or no protection
|
|
150
|
+
*/
|
|
151
|
+
/**
|
|
152
|
+
* @private
|
|
153
|
+
*/
|
|
154
|
+
this.protectionType = 'NoProtection';
|
|
155
|
+
/**
|
|
156
|
+
* Preserve the password protection is enforced or not
|
|
157
|
+
*/
|
|
158
|
+
/**
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
161
|
+
this.isDocumentProtected = false;
|
|
162
|
+
/**
|
|
163
|
+
* preserve the hash value of password
|
|
164
|
+
*/
|
|
165
|
+
/**
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
this.hashValue = '';
|
|
169
|
+
/**
|
|
170
|
+
* @private
|
|
171
|
+
*/
|
|
172
|
+
this.saltValue = '';
|
|
173
|
+
/**
|
|
174
|
+
* @private
|
|
175
|
+
*/
|
|
176
|
+
this.cryptAlgorithmSid = '';
|
|
177
|
+
/**
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
180
|
+
this.cryptAlgorithmType = '';
|
|
181
|
+
/**
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
this.cryptAlgorithmClass = '';
|
|
185
|
+
/**
|
|
186
|
+
* @private
|
|
187
|
+
*/
|
|
188
|
+
this.skipSettingsOps = false;
|
|
189
|
+
/**
|
|
190
|
+
* @private
|
|
191
|
+
*/
|
|
192
|
+
this.fieldStacks = [];
|
|
193
|
+
/**
|
|
194
|
+
* @private
|
|
195
|
+
*/
|
|
196
|
+
this.splittedCellWidgets = [];
|
|
197
|
+
/**
|
|
198
|
+
* @private
|
|
199
|
+
*/
|
|
200
|
+
this.tableLefts = [];
|
|
201
|
+
/**
|
|
202
|
+
* @private
|
|
203
|
+
*/
|
|
204
|
+
this.isFirstLineFitInShiftWidgets = false;
|
|
205
|
+
// document-helper zoomfactor
|
|
206
|
+
/**
|
|
207
|
+
* @private
|
|
208
|
+
*/
|
|
209
|
+
this.zoomFactor = 1;
|
|
210
|
+
/**
|
|
211
|
+
* @private
|
|
212
|
+
*/
|
|
213
|
+
this.fields = [];
|
|
214
|
+
/**
|
|
215
|
+
* @private
|
|
216
|
+
*/
|
|
217
|
+
this.heightInfoCollection = {};
|
|
218
|
+
/**
|
|
219
|
+
* @private
|
|
220
|
+
*/
|
|
221
|
+
this.defaultTabWidth = 36;
|
|
222
|
+
/**
|
|
223
|
+
* @private
|
|
224
|
+
*/
|
|
225
|
+
this.dontUseHtmlParagraphAutoSpacing = false;
|
|
226
|
+
/**
|
|
227
|
+
* @private
|
|
228
|
+
*/
|
|
229
|
+
this.allowSpaceOfSameStyleInTable = false;
|
|
230
|
+
/**
|
|
231
|
+
* @private
|
|
232
|
+
*/
|
|
233
|
+
this.alignTablesRowByRow = false;
|
|
234
|
+
/**
|
|
235
|
+
* @private
|
|
236
|
+
*/
|
|
237
|
+
this.compatibilityMode = 'Word2013';
|
|
238
|
+
/**
|
|
239
|
+
* @private
|
|
240
|
+
*/
|
|
241
|
+
this.lists = [];
|
|
242
|
+
/**
|
|
243
|
+
* @private
|
|
244
|
+
*/
|
|
245
|
+
this.comments = [];
|
|
246
|
+
/**
|
|
247
|
+
* @private
|
|
248
|
+
*/
|
|
249
|
+
this.authors = new Dictionary();
|
|
250
|
+
/**
|
|
251
|
+
* @private
|
|
252
|
+
*/
|
|
253
|
+
this.revisionsInternal = new Dictionary();
|
|
254
|
+
/**
|
|
255
|
+
* @private
|
|
256
|
+
*/
|
|
257
|
+
this.abstractLists = [];
|
|
258
|
+
/**
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
this.styles = new WStyles();
|
|
262
|
+
/**
|
|
263
|
+
* @private
|
|
264
|
+
*/
|
|
265
|
+
this.stylesMap = new Dictionary();
|
|
266
|
+
/**
|
|
267
|
+
* @private
|
|
268
|
+
*/
|
|
269
|
+
this.preDefinedStyles = undefined;
|
|
270
|
+
/**
|
|
271
|
+
* @private
|
|
272
|
+
*/
|
|
273
|
+
this.isRowOrCellResizing = false;
|
|
274
|
+
/**
|
|
275
|
+
* @private
|
|
276
|
+
*/
|
|
277
|
+
this.endBookmarksUpdated = [];
|
|
278
|
+
/**
|
|
279
|
+
* @private
|
|
280
|
+
*/
|
|
281
|
+
this.formFields = [];
|
|
282
|
+
/**
|
|
283
|
+
* @private
|
|
284
|
+
*/
|
|
285
|
+
this.fieldCollection = [];
|
|
286
|
+
/**
|
|
287
|
+
* @private
|
|
288
|
+
*/
|
|
289
|
+
this.isPageField = false;
|
|
290
|
+
/**
|
|
291
|
+
* @private
|
|
292
|
+
*/
|
|
293
|
+
this.isTextInput = false;
|
|
294
|
+
/**
|
|
295
|
+
* @private
|
|
296
|
+
*/
|
|
297
|
+
this.userCollection = [];
|
|
298
|
+
/**
|
|
299
|
+
* @private
|
|
300
|
+
*/
|
|
301
|
+
this.cachedPages = [];
|
|
302
|
+
/**
|
|
303
|
+
* @private
|
|
304
|
+
*/
|
|
305
|
+
this.isIosDevice = false;
|
|
306
|
+
/**
|
|
307
|
+
* @private
|
|
308
|
+
*/
|
|
309
|
+
this.isMobileDevice = false;
|
|
310
|
+
/**
|
|
311
|
+
* @private
|
|
312
|
+
*/
|
|
313
|
+
this.isLinuxOS = false;
|
|
314
|
+
/**
|
|
315
|
+
* @private
|
|
316
|
+
*/
|
|
317
|
+
this.isFormFilling = false;
|
|
318
|
+
/**
|
|
319
|
+
* @private
|
|
320
|
+
*/
|
|
321
|
+
this.fontSubstitutionTable = undefined;
|
|
322
|
+
/**
|
|
323
|
+
* @private
|
|
324
|
+
*/
|
|
325
|
+
this.themes = new Themes();
|
|
326
|
+
/**
|
|
327
|
+
* @private
|
|
328
|
+
*/
|
|
329
|
+
this.hasThemes = false;
|
|
330
|
+
/**
|
|
331
|
+
* @private
|
|
332
|
+
*/
|
|
333
|
+
this.footnotes = new Footnote();
|
|
334
|
+
/**
|
|
335
|
+
* @private
|
|
336
|
+
*/
|
|
337
|
+
this.endnotes = new Footnote();
|
|
338
|
+
/**
|
|
339
|
+
* @private
|
|
340
|
+
*/
|
|
341
|
+
this.isFootnoteWidget = false;
|
|
342
|
+
/**
|
|
343
|
+
* @private
|
|
344
|
+
*/
|
|
345
|
+
this.isUpdatedWhileLoadAsync = false;
|
|
346
|
+
this.isRestartNumbering = false;
|
|
347
|
+
/**
|
|
348
|
+
* @private
|
|
349
|
+
* @param {any} 0 - 0
|
|
350
|
+
* @param {any} 0 - 0
|
|
351
|
+
* @param {any} 816 - 816
|
|
352
|
+
* @param {any} 1056 - 1056
|
|
353
|
+
*/
|
|
354
|
+
this.visibleBoundsIn = new Rect(0, 0, 816, 1056);
|
|
355
|
+
/**
|
|
356
|
+
* @private
|
|
357
|
+
*/
|
|
358
|
+
this.currentDocumentLoadId = 0;
|
|
359
|
+
/**
|
|
360
|
+
* Shared with the editor when one is present. The editor clears these ids.
|
|
361
|
+
* @private
|
|
362
|
+
*/
|
|
363
|
+
this.scheduledTimeouts = {};
|
|
364
|
+
/**
|
|
365
|
+
* @private
|
|
366
|
+
*/
|
|
367
|
+
this.resizerBoundaryWidth = 0;
|
|
368
|
+
/**
|
|
369
|
+
* @private
|
|
370
|
+
*/
|
|
371
|
+
this.isFollowedListLayoutRequired = false;
|
|
372
|
+
/**
|
|
373
|
+
* @private
|
|
374
|
+
*/
|
|
375
|
+
this.externalFonts = [];
|
|
376
|
+
//#endregion
|
|
377
|
+
/**
|
|
378
|
+
* Overrides the global culture and localization value for this component. Default global culture is 'en-US'.
|
|
379
|
+
* @private
|
|
380
|
+
*/
|
|
381
|
+
this.locale = '';
|
|
382
|
+
/**
|
|
383
|
+
* Default locale strings used when the editor has not assigned its locale object.
|
|
384
|
+
* The editor owns the full map and assigns it in setRendererProperties.
|
|
385
|
+
* @private
|
|
386
|
+
*/
|
|
387
|
+
this.defaultLocale = {
|
|
388
|
+
'Header': 'Header',
|
|
389
|
+
'Footer': 'Footer',
|
|
390
|
+
'First Page Header': 'First Page Header',
|
|
391
|
+
'First Page Footer': 'First Page Footer',
|
|
392
|
+
'Even Page Header': 'Even Page Header',
|
|
393
|
+
'Even Page Footer': 'Even Page Footer',
|
|
394
|
+
'Odd Page Header': 'Odd Page Header',
|
|
395
|
+
'Odd Page Footer': 'Odd Page Footer',
|
|
396
|
+
'Same as Previous': 'Same as Previous',
|
|
397
|
+
'Section': 'Section',
|
|
398
|
+
'Page Break': 'Page Break',
|
|
399
|
+
'Column Break': 'Column Break',
|
|
400
|
+
'Section Break Continuous': 'Section Break Continuous',
|
|
401
|
+
'Section Break Next Page': 'Section Break Next Page',
|
|
402
|
+
'This region is locked by': 'This region is locked by'
|
|
403
|
+
};
|
|
404
|
+
this.editorProperties = new EditorProperties(this);
|
|
405
|
+
this.documentEditorSettings = new DocumentEditorSettingsModel();
|
|
406
|
+
this.documentSettings = new DocumentSettingsModel();
|
|
407
|
+
this.hooks = new RendererHooks();
|
|
408
|
+
this.parser = new SfdtReader(this);
|
|
409
|
+
this.pages = [];
|
|
410
|
+
this.lists = [];
|
|
411
|
+
this.abstractLists = [];
|
|
412
|
+
this.characterFormat = new WCharacterFormat(this);
|
|
413
|
+
this.themeFontLanguage = new WCharacterFormat(this);
|
|
414
|
+
this.paragraphFormat = new WParagraphFormat(this);
|
|
415
|
+
this.renderedLists = new Dictionary();
|
|
416
|
+
this.renderedLevelOverrides = [];
|
|
417
|
+
this.headersFooters = [];
|
|
418
|
+
this.styles = new WStyles();
|
|
419
|
+
this.stylesMap = new Dictionary();
|
|
420
|
+
this.preDefinedStyles = new Dictionary();
|
|
421
|
+
this.initalizeStyles();
|
|
422
|
+
this.bookmarks = new Dictionary();
|
|
423
|
+
this.editRanges = new Dictionary();
|
|
424
|
+
this.isIosDevice = typeof window !== 'undefined' ? /Mac|iPad|iPod/i.test(navigator.userAgent) : false;
|
|
425
|
+
this.isMobileDevice = typeof window !== 'undefined' ? /Android|Windows Phone|webOS/i.test(navigator.userAgent) : false;
|
|
426
|
+
this.isLinuxOS = typeof window !== 'undefined' ? /Linux/i.test(navigator.userAgent) : false;
|
|
427
|
+
this.customXmlData = new Dictionary();
|
|
428
|
+
this.fontSubstitutionTable = new Dictionary();
|
|
429
|
+
this.contentControlCollection = [];
|
|
430
|
+
this.footnoteCollection = [];
|
|
431
|
+
this.endnoteCollection = [];
|
|
432
|
+
this.themes = new Themes();
|
|
433
|
+
this.images = new Dictionary();
|
|
434
|
+
this.textMeasureHelper = new Optimized(this);
|
|
435
|
+
this.viewer = new PageLayoutHelper(this);
|
|
436
|
+
this.render = new Renderer(this);
|
|
437
|
+
this.initializeComponents();
|
|
438
|
+
}
|
|
439
|
+
Object.defineProperty(DocxRenderer.prototype, "element", {
|
|
440
|
+
/**
|
|
441
|
+
* @private
|
|
442
|
+
* @returns {HTMLElement} HTMLElement
|
|
443
|
+
*/
|
|
444
|
+
get: function () {
|
|
445
|
+
return this.hostElement ? this.hostElement : this.elementIn;
|
|
446
|
+
},
|
|
447
|
+
/**
|
|
448
|
+
* @private
|
|
449
|
+
* @param {HTMLElement} value - value
|
|
450
|
+
*/
|
|
451
|
+
set: function (value) {
|
|
452
|
+
this.elementIn = value;
|
|
453
|
+
},
|
|
454
|
+
enumerable: true,
|
|
455
|
+
configurable: true
|
|
456
|
+
});
|
|
457
|
+
/**
|
|
458
|
+
* Gets the BodyWidget.
|
|
459
|
+
*
|
|
460
|
+
* @returns {BodyWidget[]} - Returns document BodyWidgets.
|
|
461
|
+
*/
|
|
462
|
+
/**
|
|
463
|
+
* @private
|
|
464
|
+
* @returns {BodyWidget[]} BodyWidget[]
|
|
465
|
+
*/
|
|
466
|
+
DocxRenderer.prototype.getSections = function () {
|
|
467
|
+
return this.sections;
|
|
468
|
+
};
|
|
469
|
+
/**
|
|
470
|
+
* @private
|
|
471
|
+
* @returns {RevisionBase} RevisionBase
|
|
472
|
+
*/
|
|
473
|
+
DocxRenderer.prototype.getInsertedRevision = function () {
|
|
474
|
+
return this.editorProperties.revision;
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* @private
|
|
478
|
+
* @returns {ElementBox | WCharacterFormat | WRowFormat} ElementBox | WCharacterFormat | WRowFormat
|
|
479
|
+
*/
|
|
480
|
+
DocxRenderer.prototype.getRevisionItem = function () {
|
|
481
|
+
return this.editorProperties.revisionItem;
|
|
482
|
+
};
|
|
483
|
+
Object.defineProperty(DocxRenderer.prototype, "currentRenderingPage", {
|
|
484
|
+
/**
|
|
485
|
+
* Gets the current rendering page.
|
|
486
|
+
*
|
|
487
|
+
* @returns {Page} - Returns current rendering page.
|
|
488
|
+
*/
|
|
489
|
+
/**
|
|
490
|
+
* @private
|
|
491
|
+
* @returns {Page} Page
|
|
492
|
+
*/
|
|
493
|
+
get: function () {
|
|
494
|
+
if (this.pages.length === 0) {
|
|
495
|
+
return undefined;
|
|
496
|
+
}
|
|
497
|
+
return this.pages[this.pages.length - 1];
|
|
498
|
+
},
|
|
499
|
+
enumerable: true,
|
|
500
|
+
configurable: true
|
|
501
|
+
});
|
|
502
|
+
Object.defineProperty(DocxRenderer.prototype, "visibleBounds", {
|
|
503
|
+
/**
|
|
504
|
+
* Gets visible bounds.
|
|
505
|
+
*
|
|
506
|
+
* @returns {Rect} - Returns visible bounds.
|
|
507
|
+
*/
|
|
508
|
+
/**
|
|
509
|
+
* @private
|
|
510
|
+
* @returns {Rect} Rect
|
|
511
|
+
*/
|
|
512
|
+
get: function () {
|
|
513
|
+
return this.visibleBoundsIn;
|
|
514
|
+
},
|
|
515
|
+
enumerable: true,
|
|
516
|
+
configurable: true
|
|
517
|
+
});
|
|
518
|
+
Object.defineProperty(DocxRenderer.prototype, "selectionCanvas", {
|
|
519
|
+
/**
|
|
520
|
+
* @private
|
|
521
|
+
* @returns {HTMLCanvasElement} HTMLCanvasElement
|
|
522
|
+
*/
|
|
523
|
+
get: function () {
|
|
524
|
+
if (isNullOrUndefined(this.selectionCanvasIn)) {
|
|
525
|
+
this.selectionCanvasIn = document.createElement('canvas');
|
|
526
|
+
this.selectionCanvas.getContext('2d').save();
|
|
527
|
+
}
|
|
528
|
+
if (!isNullOrUndefined(this.pageContainer)
|
|
529
|
+
&& this.selectionCanvasIn.parentElement !== this.pageContainer) {
|
|
530
|
+
this.pageContainer.appendChild(this.selectionCanvasIn);
|
|
531
|
+
this.syncFormatPainterCursor(this.selectionCanvasIn);
|
|
532
|
+
}
|
|
533
|
+
return this.selectionCanvasIn;
|
|
534
|
+
},
|
|
535
|
+
enumerable: true,
|
|
536
|
+
configurable: true
|
|
537
|
+
});
|
|
538
|
+
Object.defineProperty(DocxRenderer.prototype, "containerCanvas", {
|
|
539
|
+
/**
|
|
540
|
+
* @private
|
|
541
|
+
* @returns {HTMLCanvasElement} HTMLCanvasElement
|
|
542
|
+
*/
|
|
543
|
+
get: function () {
|
|
544
|
+
if (isNullOrUndefined(this.containerCanvasIn)) {
|
|
545
|
+
this.containerCanvasIn = document.createElement('canvas');
|
|
546
|
+
this.containerCanvasIn.getContext('2d').save();
|
|
547
|
+
}
|
|
548
|
+
if (!isNullOrUndefined(this.pageContainer)
|
|
549
|
+
&& this.containerCanvasIn.parentElement !== this.pageContainer) {
|
|
550
|
+
this.pageContainer.appendChild(this.containerCanvasIn);
|
|
551
|
+
this.syncFormatPainterCursor(this.containerCanvasIn);
|
|
552
|
+
}
|
|
553
|
+
return this.containerCanvasIn;
|
|
554
|
+
},
|
|
555
|
+
enumerable: true,
|
|
556
|
+
configurable: true
|
|
557
|
+
});
|
|
558
|
+
Object.defineProperty(DocxRenderer.prototype, "selectionContext", {
|
|
559
|
+
/**
|
|
560
|
+
* Gets selection context.
|
|
561
|
+
*
|
|
562
|
+
* @private
|
|
563
|
+
* @returns {CanvasRenderingContext2D} CanvasRenderingContext2D
|
|
564
|
+
*/
|
|
565
|
+
get: function () {
|
|
566
|
+
return this.selectionCanvas.getContext('2d');
|
|
567
|
+
},
|
|
568
|
+
enumerable: true,
|
|
569
|
+
configurable: true
|
|
570
|
+
});
|
|
571
|
+
DocxRenderer.prototype.initalizeStyles = function () {
|
|
572
|
+
this.preDefinedStyles.add('Normal', '{"type":"Paragraph","name":"Normal","next":"Normal"}');
|
|
573
|
+
this.preDefinedStyles.add('Heading 1', '{"type":"Paragraph","name":"Heading 1","basedOn":"Normal","next":"Normal","link":"Heading 1 Char","characterFormat":{"fontSize":16.0,"fontFamily":"Calibri Light","fontColor":"#2F5496"},"paragraphFormat":{"leftIndent":0.0,"rightIndent":0.0,"firstLineIndent":0.0,"beforeSpacing":12.0,"afterSpacing":0.0,"lineSpacing":1.0791666507720947,"lineSpacingType":"Multiple","textAlignment":"Left","outlineLevel":"Level1"}}');
|
|
574
|
+
this.preDefinedStyles.add('Heading 2', '{"type":"Paragraph","name":"Heading 2","basedOn":"Normal","next":"Normal","link":"Heading 2 Char","characterFormat":{"fontSize":13.0,"fontFamily":"Calibri Light","fontColor":"#2F5496"},"paragraphFormat":{"leftIndent":0.0,"rightIndent":0.0,"firstLineIndent":0.0,"beforeSpacing":2.0,"afterSpacing":0.0,"lineSpacing":1.0791666507720947,"lineSpacingType":"Multiple","textAlignment":"Left","outlineLevel":"Level2"}}');
|
|
575
|
+
this.preDefinedStyles.add('Heading 3', '{"type":"Paragraph","name":"Heading 3","basedOn":"Normal","next":"Normal","link":"Heading 3 Char","characterFormat":{"fontSize":12.0,"fontFamily":"Calibri Light","fontColor":"#1F3763"},"paragraphFormat":{"leftIndent":0.0,"rightIndent":0.0,"firstLineIndent":0.0,"beforeSpacing":2.0,"afterSpacing":0.0,"lineSpacing":1.0791666507720947,"lineSpacingType":"Multiple","textAlignment":"Left","outlineLevel":"Level3"}}');
|
|
576
|
+
this.preDefinedStyles.add('Heading 4', '{"type":"Paragraph","name":"Heading 4","basedOn":"Normal","next":"Normal","link":"Heading 4 Char","characterFormat":{"italic":true,"fontFamily":"Calibri Light","fontColor":"#2F5496"},"paragraphFormat":{"leftIndent":0.0,"rightIndent":0.0,"firstLineIndent":0.0,"beforeSpacing":2.0,"afterSpacing":0.0,"lineSpacing":1.0791666507720947,"lineSpacingType":"Multiple","textAlignment":"Left","outlineLevel":"Level4"}}');
|
|
577
|
+
this.preDefinedStyles.add('Heading 5', '{"type":"Paragraph","name":"Heading 5","basedOn":"Normal","next":"Normal","link":"Heading 5 Char","characterFormat":{"fontFamily":"Calibri Light","fontColor":"#2F5496"},"paragraphFormat":{"leftIndent":0.0,"rightIndent":0.0,"firstLineIndent":0.0,"beforeSpacing":2.0,"afterSpacing":0.0,"lineSpacing":1.0791666507720947,"lineSpacingType":"Multiple","textAlignment":"Left","outlineLevel":"Level5"}}');
|
|
578
|
+
this.preDefinedStyles.add('Heading 6', '{"type":"Paragraph","name":"Heading 6","basedOn":"Normal","next":"Normal","link":"Heading 6 Char","characterFormat":{"fontFamily":"Calibri Light","fontColor":"#1F3763"},"paragraphFormat":{"leftIndent":0.0,"rightIndent":0.0,"firstLineIndent":0.0,"beforeSpacing":2.0,"afterSpacing":0.0,"lineSpacing":1.0791666507720947,"lineSpacingType":"Multiple","textAlignment":"Left","outlineLevel":"Level6"}}');
|
|
579
|
+
this.preDefinedStyles.add('Heading 7', '{"type":"Paragraph","name":"Heading 7","basedOn":"Normal","next":"Normal","link":"Heading 7 Char","characterFormat":{"italic":true,"fontFamily":"Calibri Light","fontColor":"#1F3763"},"paragraphFormat":{"leftIndent":0.0,"rightIndent":0.0,"firstLineIndent":0.0,"beforeSpacing":2.0,"afterSpacing":0.0,"lineSpacing":1.0791666507720947,"lineSpacingType":"Multiple","textAlignment":"Left","outlineLevel":"Level7"}}');
|
|
580
|
+
this.preDefinedStyles.add('Heading 8', '{"type":"Paragraph","name":"Heading 8","basedOn":"Normal","next":"Normal","link":"Heading 8 Char","characterFormat":{"fontSize":10.5,"fontFamily":"Calibri Light","fontColor":"#333333"},"paragraphFormat":{"leftIndent":0.0,"rightIndent":0.0,"firstLineIndent":0.0,"beforeSpacing":2.0,"afterSpacing":0.0,"lineSpacing":1.0791666507720947,"lineSpacingType":"Multiple","textAlignment":"Left","outlineLevel":"Level8"}}');
|
|
581
|
+
this.preDefinedStyles.add('Heading 9', '{"type":"Paragraph","name":"Heading 9","basedOn":"Normal","next":"Normal","link":"Heading 9 Char","characterFormat":{"fontSize":10.5,"italic":true,"fontFamily":"Calibri Light","fontColor":"#333333"},"paragraphFormat":{"leftIndent":0.0,"rightIndent":0.0,"firstLineIndent":0.0,"beforeSpacing":2.0,"afterSpacing":0.0,"lineSpacing":1.0791666507720947,"lineSpacingType":"Multiple","textAlignment":"Left","outlineLevel":"Level9"}}');
|
|
582
|
+
this.preDefinedStyles.add('Default Paragraph Font', '{"type":"Character","name":"Default Paragraph Font"}');
|
|
583
|
+
this.preDefinedStyles.add('Heading 1 Char', '{"type":"Character","name":"Heading 1 Char","basedOn":"Default Paragraph Font","characterFormat":{"fontSize":16.0,"fontFamily":"Calibri Light","fontColor":"#2F5496"}}');
|
|
584
|
+
this.preDefinedStyles.add('Heading 2 Char', '{"type":"Character","name":"Heading 2 Char","basedOn":"Default Paragraph Font","characterFormat":{"fontSize":13.0,"fontFamily":"Calibri Light","fontColor":"#2F5496"}}');
|
|
585
|
+
this.preDefinedStyles.add('Heading 3 Char', '{"type":"Character","name":"Heading 3 Char","basedOn":"Default Paragraph Font","characterFormat":{"fontSize":12.0,"fontFamily":"Calibri Light","fontColor": "#1F3763"}}');
|
|
586
|
+
this.preDefinedStyles.add('Heading 4 Char', '{"type":"Character","name":"Heading 4 Char","basedOn":"Default Paragraph Font","characterFormat":{"italic":true,"fontFamily":"Calibri Light","fontColor":"#2F5496"}}');
|
|
587
|
+
this.preDefinedStyles.add('Heading 5 Char', '{"type":"Character","name":"Heading 5 Char","basedOn":"Default Paragraph Font","characterFormat":{"fontFamily":"Calibri Light","fontColor":"#2F5496"}}');
|
|
588
|
+
this.preDefinedStyles.add('Heading 6 Char', '{"type":"Character","name":"Heading 6 Char","basedOn":"Default Paragraph Font","characterFormat":{"fontFamily":"Calibri Light","fontColor":"#1F3763"}}');
|
|
589
|
+
this.preDefinedStyles.add('Heading 7 Char', '{"type":"Character","name":"Heading 7 Char","basedOn":"Default Paragraph Font","characterFormat":{"italic":true,"fontFamily":"Calibri Light","fontColor":"#1F3763"}}');
|
|
590
|
+
this.preDefinedStyles.add('Heading 8 Char', '{"type":"Character","name":"Heading 8 Char","basedOn":"Default Paragraph Font","characterFormat":{"fontSize":10.5,"fontFamily":"Calibri Light","fontColor":"#333333"}}');
|
|
591
|
+
this.preDefinedStyles.add('Heading 9 Char', '{"type":"Character","name":"Heading 9 Char","basedOn":"Default Paragraph Font","characterFormat":{"fontSize":10.5,"italic":true,"fontFamily":"Calibri Light","fontColor":"#333333"}}');
|
|
592
|
+
this.preDefinedStyles.add('Hyperlink', '{"type":"Character","name":"Hyperlink","basedOn":"Default Paragraph Font","next":"Normal","characterFormat":{"fontColor":"#0563C1","underline": "Single"}}');
|
|
593
|
+
this.preDefinedStyles.add('TOC 1', '{"type":"Paragraph","name":"TOC 1","basedOn":"Normal","next":"Normal","paragraphFormat":{"afterSpacing":5.0}}');
|
|
594
|
+
this.preDefinedStyles.add('TOC 2', '{"type":"Paragraph","name":"TOC 2","basedOn":"Normal","next":"Normal","paragraphFormat":{"leftIndent" :11.0,"afterSpacing":5.0}}');
|
|
595
|
+
this.preDefinedStyles.add('TOC 3', '{"type":"Paragraph","name":"TOC 3","basedOn":"Normal","next":"Normal","paragraphFormat":{"leftIndent" :22.0,"afterSpacing":5.0}}');
|
|
596
|
+
this.preDefinedStyles.add('TOC 4', '{"type":"Paragraph","name":"TOC 4","basedOn":"Normal","next":"Normal","paragraphFormat":{"leftIndent" :33.0,"afterSpacing":5.0}}');
|
|
597
|
+
this.preDefinedStyles.add('TOC 5', '{"type":"Paragraph","name":"TOC 5","basedOn":"Normal","next":"Normal","paragraphFormat":{"leftIndent" :44.0,"afterSpacing":5.0}}');
|
|
598
|
+
this.preDefinedStyles.add('TOC 6', '{"type":"Paragraph","name":"TOC 6","basedOn":"Normal","next":"Normal","paragraphFormat":{"leftIndent" :55.0,"afterSpacing":5.0}}');
|
|
599
|
+
this.preDefinedStyles.add('TOC 7', '{"type":"Paragraph","name":"TOC 7","basedOn":"Normal","next":"Normal","paragraphFormat":{"leftIndent" :66.0,"afterSpacing":5.0}}');
|
|
600
|
+
this.preDefinedStyles.add('TOC 8', '{"type":"Paragraph","name":"TOC 8","basedOn":"Normal","next":"Normal","paragraphFormat":{"leftIndent" :77.0,"afterSpacing":5.0}}');
|
|
601
|
+
this.preDefinedStyles.add('TOC 9', '{"type":"Paragraph","name":"TOC 9","basedOn":"Normal","next":"Normal","paragraphFormat":{"leftIndent" :88.0,"afterSpacing":5.0}}');
|
|
602
|
+
this.preDefinedStyles.add('Header', '{"type":"Paragraph","name":"Header","basedOn":"Normal","next":"Header","paragraphFormat":{"afterSpacing":0,"lineSpacing":1,"lineSpacingType":"Multiple"}}');
|
|
603
|
+
this.preDefinedStyles.add('Footer', '{"type":"Paragraph","name":"Footer","basedOn":"Normal","next":"Footer","paragraphFormat":{"afterSpacing":0,"lineSpacing":1,"lineSpacingType":"Multiple"}}');
|
|
604
|
+
};
|
|
605
|
+
/**
|
|
606
|
+
* Opens the specified document.
|
|
607
|
+
*
|
|
608
|
+
* @private
|
|
609
|
+
* @param {string | Blob} data - data
|
|
610
|
+
* @returns {void}
|
|
611
|
+
*/
|
|
612
|
+
DocxRenderer.prototype.open = function (data) {
|
|
613
|
+
if (isNullOrUndefined(data)) {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (typeof data === 'string' || typeof data === 'object') {
|
|
617
|
+
if (data instanceof Blob) {
|
|
618
|
+
// Handle generic Blob objects
|
|
619
|
+
this.handleBlobOpen(data);
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
var incrementalOps = {};
|
|
623
|
+
this.setDefaultDocumentFormat();
|
|
624
|
+
this.sections = this.parser.convertJsonToDocument(data, incrementalOps);
|
|
625
|
+
// this.layout.layoutItems(this.sections, false);
|
|
626
|
+
// this.render.renderWidgets(this.pages[0], 0, 0, 816, 1056);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return;
|
|
630
|
+
};
|
|
631
|
+
/**
|
|
632
|
+
* Handles opening of Blob objects
|
|
633
|
+
*
|
|
634
|
+
* @private
|
|
635
|
+
* @param {Blob} blob - blob
|
|
636
|
+
* @returns {void}
|
|
637
|
+
*/
|
|
638
|
+
DocxRenderer.prototype.handleBlobOpen = function (blob) {
|
|
639
|
+
var _this = this;
|
|
640
|
+
var reader = new FileReader();
|
|
641
|
+
reader.onload = function () {
|
|
642
|
+
try {
|
|
643
|
+
var result = reader.result;
|
|
644
|
+
// Try to parse as SFDT (JSON)
|
|
645
|
+
JSON.parse(result);
|
|
646
|
+
_this.open(result);
|
|
647
|
+
}
|
|
648
|
+
catch (error) {
|
|
649
|
+
console.error('Failed to parse blob as SFDT:', error);
|
|
650
|
+
// Could implement additional format detection here
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
reader.onerror = function () {
|
|
654
|
+
console.error('Failed to read blob');
|
|
655
|
+
};
|
|
656
|
+
reader.readAsText(blob);
|
|
657
|
+
};
|
|
658
|
+
/**
|
|
659
|
+
* Copies the active Format Painter cursor onto a canvas attached after the mode starts.
|
|
660
|
+
*
|
|
661
|
+
* @private
|
|
662
|
+
* @param {HTMLElement} element - element
|
|
663
|
+
* @returns {void}
|
|
664
|
+
*/
|
|
665
|
+
DocxRenderer.prototype.syncFormatPainterCursor = function (element) {
|
|
666
|
+
if (isNullOrUndefined(element) || isNullOrUndefined(this.isFormatPainterModule)
|
|
667
|
+
|| !this.formatPainterActive) {
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
element.style.cursor = this.viewerContainer && this.viewerContainer.style.cursor
|
|
671
|
+
? this.viewerContainer.style.cursor : this.formatPainterCursor;
|
|
672
|
+
};
|
|
673
|
+
/**
|
|
674
|
+
* @private
|
|
675
|
+
* @returns {void}
|
|
676
|
+
*/
|
|
677
|
+
DocxRenderer.prototype.clearDocumentItems = function () {
|
|
678
|
+
this.editRanges.clear();
|
|
679
|
+
this.headersFooters = [];
|
|
680
|
+
this.fields = [];
|
|
681
|
+
this.layout.lastScrollUpdatePageIndex = -1;
|
|
682
|
+
this.formFields = [];
|
|
683
|
+
for (var i = 0; i < this.comments.length; i++) {
|
|
684
|
+
var commentStart = this.comments[i].commentStart;
|
|
685
|
+
if (commentStart) {
|
|
686
|
+
commentStart.destroy();
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
this.comments = [];
|
|
690
|
+
this.bookmarks.clear();
|
|
691
|
+
this.endBookmarksUpdated = [];
|
|
692
|
+
this.styles.clear();
|
|
693
|
+
this.stylesMap.clear();
|
|
694
|
+
if (this.pages && this.pages.length > 0) {
|
|
695
|
+
for (var i = 0; i < this.pages.length; i++) {
|
|
696
|
+
var page = this.pages[i];
|
|
697
|
+
page.componentDestroy();
|
|
698
|
+
}
|
|
699
|
+
this.pages = [];
|
|
700
|
+
}
|
|
701
|
+
this.authors.clear();
|
|
702
|
+
this.revisionsInternal.clear();
|
|
703
|
+
this.characterFormat.clearFormat();
|
|
704
|
+
this.themeFontLanguage.clearFormat();
|
|
705
|
+
this.paragraphFormat.clearFormat();
|
|
706
|
+
this.setDefaultCharacterValue(this.characterFormat);
|
|
707
|
+
this.setDefaultParagraphValue(this.paragraphFormat);
|
|
708
|
+
this.defaultTabWidth = 36;
|
|
709
|
+
this.userCollection = [];
|
|
710
|
+
this.customXmlData.clear();
|
|
711
|
+
this.fontSubstitutionTable.clear();
|
|
712
|
+
this.images.clear();
|
|
713
|
+
this.contentControlCollection = [];
|
|
714
|
+
this.splittedCellWidgets = [];
|
|
715
|
+
this.endnotes.clear();
|
|
716
|
+
this.footnotes.clear();
|
|
717
|
+
this.footnoteCollection = [];
|
|
718
|
+
this.endnoteCollection = [];
|
|
719
|
+
if (this.lists && this.lists.length > 0) {
|
|
720
|
+
for (var i = 0; i < this.lists.length; i++) {
|
|
721
|
+
var list = this.lists[Number(i)];
|
|
722
|
+
list.clear();
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
this.lists = [];
|
|
726
|
+
this.abstractLists = [];
|
|
727
|
+
this.sections = [];
|
|
728
|
+
this.themes = new Themes();
|
|
729
|
+
this.hasThemes = false;
|
|
730
|
+
this.isRestartNumbering = false;
|
|
731
|
+
this.isUpdatedWhileLoadAsync = false;
|
|
732
|
+
this.isFollowedListLayoutRequired = false;
|
|
733
|
+
};
|
|
734
|
+
/**
|
|
735
|
+
* @private
|
|
736
|
+
* @returns {void}
|
|
737
|
+
*/
|
|
738
|
+
DocxRenderer.prototype.setDefaultDocumentFormat = function () {
|
|
739
|
+
if (!isNullOrUndefined(this.editorCharacterFormat)) {
|
|
740
|
+
this.parser.parseCharacterFormat(0, this.editorCharacterFormat, this.characterFormat);
|
|
741
|
+
}
|
|
742
|
+
if (!isNullOrUndefined(this.editorParagraphFormat)) {
|
|
743
|
+
this.parser.parseParagraphFormat(0, this.editorParagraphFormat, this.paragraphFormat);
|
|
744
|
+
}
|
|
745
|
+
if (!isNullOrUndefined(this.documentCharacterFormat)) {
|
|
746
|
+
this.parser.parseCharacterFormat(0, this.documentCharacterFormat, this.characterFormat);
|
|
747
|
+
}
|
|
748
|
+
if (!isNullOrUndefined(this.documentParagraphFormat)) {
|
|
749
|
+
this.parser.parseParagraphFormat(0, this.documentParagraphFormat, this.paragraphFormat);
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
/**
|
|
753
|
+
* Initializes core layout components without UI
|
|
754
|
+
*
|
|
755
|
+
* @private
|
|
756
|
+
* @returns {void}
|
|
757
|
+
*/
|
|
758
|
+
DocxRenderer.prototype.initializeComponents = function () {
|
|
759
|
+
// Initialize core layout modules
|
|
760
|
+
this.layout = new Layout(this);
|
|
761
|
+
this.textHelper = new TextHelper(this);
|
|
762
|
+
};
|
|
763
|
+
/**
|
|
764
|
+
* @private
|
|
765
|
+
* @param {WCharacterFormat} characterFormat - characterFormat
|
|
766
|
+
* @returns {void}
|
|
767
|
+
*/
|
|
768
|
+
DocxRenderer.prototype.setDefaultCharacterValue = function (characterFormat) {
|
|
769
|
+
characterFormat.bold = false;
|
|
770
|
+
characterFormat.italic = false;
|
|
771
|
+
characterFormat.fontFamily = 'Calibri';
|
|
772
|
+
characterFormat.fontSize = 11;
|
|
773
|
+
characterFormat.underline = 'None';
|
|
774
|
+
characterFormat.strikethrough = 'None';
|
|
775
|
+
characterFormat.fontSizeBidi = 11;
|
|
776
|
+
characterFormat.fontFamilyBidi = 'Calibri';
|
|
777
|
+
characterFormat.baselineAlignment = 'Normal';
|
|
778
|
+
characterFormat.highlightColor = 'NoColor';
|
|
779
|
+
characterFormat.allCaps = false;
|
|
780
|
+
};
|
|
781
|
+
/**
|
|
782
|
+
* @private
|
|
783
|
+
* @param {WParagraphFormat} paragraphFormat - paragraphFormat
|
|
784
|
+
* @returns {void}
|
|
785
|
+
*/
|
|
786
|
+
DocxRenderer.prototype.setDefaultParagraphValue = function (paragraphFormat) {
|
|
787
|
+
paragraphFormat.leftIndent = 0;
|
|
788
|
+
paragraphFormat.rightIndent = 0;
|
|
789
|
+
paragraphFormat.firstLineIndent = 0;
|
|
790
|
+
paragraphFormat.textAlignment = 'Left';
|
|
791
|
+
paragraphFormat.beforeSpacing = 0;
|
|
792
|
+
paragraphFormat.afterSpacing = 0;
|
|
793
|
+
paragraphFormat.lineSpacing = 1;
|
|
794
|
+
paragraphFormat.lineSpacingType = 'Multiple';
|
|
795
|
+
paragraphFormat.bidi = false;
|
|
796
|
+
paragraphFormat.keepWithNext = false;
|
|
797
|
+
paragraphFormat.keepLinesTogether = false;
|
|
798
|
+
paragraphFormat.widowControl = true;
|
|
799
|
+
paragraphFormat.outlineLevel = 'BodyText';
|
|
800
|
+
};
|
|
801
|
+
/**
|
|
802
|
+
* @private
|
|
803
|
+
* @param {number} id - id
|
|
804
|
+
* @param {boolean} isNsid - isNsid
|
|
805
|
+
* @returns {WAbstractList} WAbstractList
|
|
806
|
+
*/
|
|
807
|
+
DocxRenderer.prototype.getAbstractListById = function (id, isNsid) {
|
|
808
|
+
if (isNullOrUndefined(this.abstractLists)) {
|
|
809
|
+
return undefined;
|
|
810
|
+
}
|
|
811
|
+
for (var i = 0; i < this.abstractLists.length; i++) {
|
|
812
|
+
var abstractList = this.abstractLists[i];
|
|
813
|
+
if (!isNullOrUndefined(abstractList)) {
|
|
814
|
+
if (isNsid && abstractList.nsid === id) {
|
|
815
|
+
return abstractList;
|
|
816
|
+
}
|
|
817
|
+
else if (abstractList.abstractListId === id) {
|
|
818
|
+
return abstractList;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
return undefined;
|
|
823
|
+
};
|
|
824
|
+
/**
|
|
825
|
+
* @private
|
|
826
|
+
* @param {number} id - id
|
|
827
|
+
* @param {boolean} isNsid - isNsid
|
|
828
|
+
* @returns {WList} WList
|
|
829
|
+
*/
|
|
830
|
+
DocxRenderer.prototype.getListById = function (id, isNsid) {
|
|
831
|
+
if (isNullOrUndefined(this.lists)) {
|
|
832
|
+
return undefined;
|
|
833
|
+
}
|
|
834
|
+
for (var i = 0; i < this.lists.length; i++) {
|
|
835
|
+
var list = this.lists[i];
|
|
836
|
+
if (!isNullOrUndefined(list)) {
|
|
837
|
+
if (isNsid && list.nsid === id) {
|
|
838
|
+
return list;
|
|
839
|
+
}
|
|
840
|
+
else if (list.listId === id) {
|
|
841
|
+
return list;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
return undefined;
|
|
846
|
+
};
|
|
847
|
+
/**
|
|
848
|
+
* @private
|
|
849
|
+
* @param {WListLevel} listLevel - listLevel
|
|
850
|
+
* @returns {number} number
|
|
851
|
+
*/
|
|
852
|
+
DocxRenderer.getListLevelNumber = function (listLevel) {
|
|
853
|
+
if (listLevel.ownerBase instanceof WLevelOverride) {
|
|
854
|
+
return listLevel.ownerBase.levelNumber;
|
|
855
|
+
}
|
|
856
|
+
else if (listLevel.ownerBase instanceof WAbstractList && !isNullOrUndefined(listLevel.ownerBase.levels)) {
|
|
857
|
+
return listLevel.ownerBase.levels.indexOf(listLevel);
|
|
858
|
+
}
|
|
859
|
+
else {
|
|
860
|
+
return -1;
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
/**
|
|
864
|
+
* @private
|
|
865
|
+
* @param {ImageElementBox} image - image
|
|
866
|
+
* @returns {string} string
|
|
867
|
+
*/
|
|
868
|
+
DocxRenderer.prototype.getImageString = function (image) {
|
|
869
|
+
var base64ImageString = this.images.get(parseInt(image.imageString, 10));
|
|
870
|
+
var imageStr;
|
|
871
|
+
if (isNullOrUndefined(base64ImageString) || base64ImageString.length === 0) {
|
|
872
|
+
return '';
|
|
873
|
+
}
|
|
874
|
+
if (image.isMetaFile && LayoutHelperMethods.formatClippedString(base64ImageString[0]).extension !== '.svg') {
|
|
875
|
+
imageStr = base64ImageString[1];
|
|
876
|
+
}
|
|
877
|
+
else if (LayoutHelperMethods.formatClippedString(base64ImageString[0]).extension === '.tif') {
|
|
878
|
+
imageStr = base64ImageString[1];
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
imageStr = base64ImageString[0];
|
|
882
|
+
}
|
|
883
|
+
return imageStr;
|
|
884
|
+
};
|
|
885
|
+
/**
|
|
886
|
+
* @private
|
|
887
|
+
* @param {ImageElementBox} image - image
|
|
888
|
+
* @returns {Promise<void>} Promise<void>
|
|
889
|
+
*/
|
|
890
|
+
DocxRenderer.prototype.addBase64StringInCollection = function (image) {
|
|
891
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
892
|
+
var key, addToCollection, base64ImageString, i, index, imageStringCol;
|
|
893
|
+
return __generator(this, function (_a) {
|
|
894
|
+
key = this.images.length > 0 ? Math.max.apply(Math, this.images.keys) + 1 : 0;
|
|
895
|
+
addToCollection = true;
|
|
896
|
+
base64ImageString = [];
|
|
897
|
+
for (i = 0; i < this.images.length; i++) {
|
|
898
|
+
index = this.images.keys[parseInt(i.toString(), 10)];
|
|
899
|
+
imageStringCol = this.images.get(index);
|
|
900
|
+
if (image.isMetaFile && image.metaFileImageString === imageStringCol[0]) {
|
|
901
|
+
key = index;
|
|
902
|
+
addToCollection = false;
|
|
903
|
+
break;
|
|
904
|
+
}
|
|
905
|
+
else if (image.imageString === imageStringCol[0]) {
|
|
906
|
+
key = index;
|
|
907
|
+
addToCollection = false;
|
|
908
|
+
break;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
if (addToCollection) {
|
|
912
|
+
if (image.isMetaFile) {
|
|
913
|
+
base64ImageString.push(!isNullOrUndefined(image.metaFileImageString) ? image.metaFileImageString : image.imageString);
|
|
914
|
+
base64ImageString.push(image.imageString === '' ? image.metaFileImageString : image.imageString);
|
|
915
|
+
}
|
|
916
|
+
else {
|
|
917
|
+
base64ImageString.push(image.imageString);
|
|
918
|
+
}
|
|
919
|
+
this.images.add(key, base64ImageString);
|
|
920
|
+
}
|
|
921
|
+
if (image.isMetaFile && !isNullOrUndefined(image.metaFileImageString)) {
|
|
922
|
+
image.metaFileImageString = key.toString();
|
|
923
|
+
}
|
|
924
|
+
image.imageString = key.toString();
|
|
925
|
+
return [2 /*return*/];
|
|
926
|
+
});
|
|
927
|
+
});
|
|
928
|
+
};
|
|
929
|
+
/**
|
|
930
|
+
* Gets the bookmarks.
|
|
931
|
+
* @private
|
|
932
|
+
* @param {boolean} includeHidden - includeHidden
|
|
933
|
+
* @returns {string[]} string[]
|
|
934
|
+
*/
|
|
935
|
+
DocxRenderer.prototype.getBookmarks = function (includeHidden) {
|
|
936
|
+
var bookmarks = [];
|
|
937
|
+
for (var i = 0; i < this.bookmarks.keys.length; i++) {
|
|
938
|
+
var bookmark = this.bookmarks.keys[Number(i)];
|
|
939
|
+
if (includeHidden || bookmark.indexOf('_') !== 0) {
|
|
940
|
+
bookmarks.push(bookmark);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
return bookmarks;
|
|
944
|
+
};
|
|
945
|
+
DocxRenderer.prototype.getBase64 = function (base64String, width, height) {
|
|
946
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
947
|
+
return __generator(this, function (_a) {
|
|
948
|
+
void width;
|
|
949
|
+
void height;
|
|
950
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
951
|
+
var drawImage = new Image();
|
|
952
|
+
drawImage.onload = function () {
|
|
953
|
+
var draw = document.createElement('canvas');
|
|
954
|
+
draw.width = drawImage.naturalWidth;
|
|
955
|
+
draw.height = drawImage.naturalHeight;
|
|
956
|
+
var context = draw.getContext('2d');
|
|
957
|
+
context.drawImage(drawImage, 0, 0, drawImage.naturalWidth, drawImage.naturalHeight);
|
|
958
|
+
var imageString = draw.toDataURL('image/png', 1);
|
|
959
|
+
resolve(imageString);
|
|
960
|
+
};
|
|
961
|
+
drawImage.onerror = function () {
|
|
962
|
+
reject();
|
|
963
|
+
};
|
|
964
|
+
if (base64String && (LayoutHelperMethods.startsWith(base64String, 'http://') || LayoutHelperMethods.startsWith(base64String, 'https://'))) {
|
|
965
|
+
fetch(base64String, { cache: 'no-cache' }).then(function (response) {
|
|
966
|
+
return response.blob();
|
|
967
|
+
}).then(function (blob) {
|
|
968
|
+
return new Promise(function (resolve, reject) {
|
|
969
|
+
var reader = new FileReader();
|
|
970
|
+
reader.onloadend = function () { return resolve(reader.result); };
|
|
971
|
+
reader.onerror = reject;
|
|
972
|
+
reader.readAsDataURL(blob);
|
|
973
|
+
});
|
|
974
|
+
}).then(function (dataUrl) {
|
|
975
|
+
drawImage.src = dataUrl;
|
|
976
|
+
}).catch(function () {
|
|
977
|
+
reject();
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
})];
|
|
981
|
+
});
|
|
982
|
+
});
|
|
983
|
+
};
|
|
984
|
+
/**
|
|
985
|
+
* Stores the setTimeOut id when asynchronous process.
|
|
986
|
+
* @private
|
|
987
|
+
* @param {number} loadId - loadId
|
|
988
|
+
* @param {number} timeoutId - timeoutId
|
|
989
|
+
* @returns {void}
|
|
990
|
+
*/
|
|
991
|
+
DocxRenderer.prototype.storeTimeoutId = function (loadId, timeoutId) {
|
|
992
|
+
if (!this.scheduledTimeouts[loadId]) {
|
|
993
|
+
this.scheduledTimeouts[loadId] = [];
|
|
994
|
+
}
|
|
995
|
+
this.scheduledTimeouts[loadId].push(timeoutId);
|
|
996
|
+
};
|
|
997
|
+
/**
|
|
998
|
+
* @private
|
|
999
|
+
* @param {string} hexColor - hexColor
|
|
1000
|
+
* @param {number} opacity - opacity
|
|
1001
|
+
* @returns {string} string
|
|
1002
|
+
*/
|
|
1003
|
+
DocxRenderer.prototype.convertColorToRGBA = function (hexColor, opacity) {
|
|
1004
|
+
var hex = hexColor.replace('#', '');
|
|
1005
|
+
var r = parseInt(hex.substring(0, 2), 16);
|
|
1006
|
+
var g = parseInt(hex.substring(2, 4), 16);
|
|
1007
|
+
var b = parseInt(hex.substring(4, 6), 16);
|
|
1008
|
+
var clampedOpacity = Math.max(0, Math.min(1, opacity));
|
|
1009
|
+
return "rgba(" + r + ", " + g + ", " + b + ", " + clampedOpacity + ")";
|
|
1010
|
+
};
|
|
1011
|
+
/**
|
|
1012
|
+
* @private
|
|
1013
|
+
* @param {string} author - author
|
|
1014
|
+
* @returns {string} string
|
|
1015
|
+
*/
|
|
1016
|
+
DocxRenderer.prototype.getAuthorColor = function (author) {
|
|
1017
|
+
if (this.authors.containsKey(author)) {
|
|
1018
|
+
return this.authors.get(author);
|
|
1019
|
+
}
|
|
1020
|
+
var color = this.generateRandomColor();
|
|
1021
|
+
this.authors.add(author, color);
|
|
1022
|
+
return color;
|
|
1023
|
+
};
|
|
1024
|
+
/**
|
|
1025
|
+
* @private
|
|
1026
|
+
* @returns {string} string
|
|
1027
|
+
*/
|
|
1028
|
+
DocxRenderer.prototype.generateRandomColor = function () {
|
|
1029
|
+
var defaultColors = ['#b5082e',
|
|
1030
|
+
'#0e76b1',
|
|
1031
|
+
'#bb00ff',
|
|
1032
|
+
'#c14f16',
|
|
1033
|
+
'#128317',
|
|
1034
|
+
'#881824',
|
|
1035
|
+
'#a26400',
|
|
1036
|
+
'#50565e']; //dark grey
|
|
1037
|
+
var userColors = defaultColors;
|
|
1038
|
+
var revisionSettings = this.documentEditorSettings.revisionSettings;
|
|
1039
|
+
if (!isNullOrUndefined(revisionSettings) && !isNullOrUndefined(revisionSettings.revisionColors)
|
|
1040
|
+
&& revisionSettings.revisionColors.length > 0) {
|
|
1041
|
+
var validColors = revisionSettings.revisionColors.filter(function (color) { return !isNullOrUndefined(color) && color !== ''; });
|
|
1042
|
+
if (validColors.length > 0) {
|
|
1043
|
+
userColors = validColors;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
return userColors[(this.authors.length % userColors.length)];
|
|
1047
|
+
};
|
|
1048
|
+
/**
|
|
1049
|
+
* @private
|
|
1050
|
+
* @param {Page} page - page
|
|
1051
|
+
* @returns {number} number
|
|
1052
|
+
*/
|
|
1053
|
+
DocxRenderer.prototype.getPageWidth = function (page) {
|
|
1054
|
+
var width = page.boundingRectangle.width;
|
|
1055
|
+
return width;
|
|
1056
|
+
};
|
|
1057
|
+
/**
|
|
1058
|
+
* Removes specified page.
|
|
1059
|
+
*
|
|
1060
|
+
* @param {Page} page - Specifies page to remove
|
|
1061
|
+
* @returns {void}
|
|
1062
|
+
*/
|
|
1063
|
+
DocxRenderer.prototype.removePage = function (page) {
|
|
1064
|
+
if (this.currentPage === page) {
|
|
1065
|
+
this.currentPage = undefined;
|
|
1066
|
+
}
|
|
1067
|
+
if (page.headerWidgetIn) {
|
|
1068
|
+
page.headerWidgetIn.page = undefined;
|
|
1069
|
+
}
|
|
1070
|
+
if (page.footerWidgetIn) {
|
|
1071
|
+
page.footerWidgetIn.page = undefined;
|
|
1072
|
+
}
|
|
1073
|
+
if (page.headerWidget && page.headerWidget.page === page) {
|
|
1074
|
+
page.headerWidget.page = undefined;
|
|
1075
|
+
}
|
|
1076
|
+
if (page.footerWidget && page.footerWidget.page === page) {
|
|
1077
|
+
page.footerWidget.page = undefined;
|
|
1078
|
+
}
|
|
1079
|
+
var index = this.pages.indexOf(page);
|
|
1080
|
+
if (index > -1) {
|
|
1081
|
+
this.pages.splice(index, 1);
|
|
1082
|
+
}
|
|
1083
|
+
//this.removeRenderedPages();
|
|
1084
|
+
if (!isNullOrUndefined(this.viewer.visiblePages)) {
|
|
1085
|
+
if ((this.viewer.visiblePages).indexOf(page) > -1) {
|
|
1086
|
+
var pageIndex = (this.viewer.visiblePages).indexOf(page);
|
|
1087
|
+
(this.viewer.visiblePages).splice(pageIndex, 1);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
// (viewer as PageLayoutHelper).visiblePages.remove(page);
|
|
1091
|
+
var height = 0;
|
|
1092
|
+
for (var i = 0; i < this.pages.length; i++) {
|
|
1093
|
+
height = height + this.pages[i].boundingRectangle.height;
|
|
1094
|
+
}
|
|
1095
|
+
//Updates the vertical height.
|
|
1096
|
+
height -= page.boundingRectangle.height + 20;
|
|
1097
|
+
//ToDo:Update horizontal width, if removed page has max width.
|
|
1098
|
+
var top = 20;
|
|
1099
|
+
if (index > 0) {
|
|
1100
|
+
top += this.pages[index - 1].boundingRectangle.bottom;
|
|
1101
|
+
}
|
|
1102
|
+
if (index !== -1) {
|
|
1103
|
+
for (var i = index; i < this.pages.length; i++) {
|
|
1104
|
+
//Update bounding rectangle of next pages in collection.
|
|
1105
|
+
page = this.pages[i];
|
|
1106
|
+
page.boundingRectangle = new Rect(page.boundingRectangle.x, top, page.boundingRectangle.width, page.boundingRectangle.height);
|
|
1107
|
+
top = page.boundingRectangle.bottom + 20;
|
|
1108
|
+
if (page.bodyWidgets.length > 0 && !isNullOrUndefined(page.bodyWidgets[0].firstChild) &&
|
|
1109
|
+
!(page.bodyWidgets[0].firstChild instanceof TableWidget && page.bodyWidgets[0].firstChild.header)) {
|
|
1110
|
+
page.repeatHeaderRowTableWidget = false;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
/**
|
|
1116
|
+
* Inserts page in specified index.
|
|
1117
|
+
*
|
|
1118
|
+
* @param {number} index - Specifes index to insert page
|
|
1119
|
+
* @param {Page} page - Page to insert.
|
|
1120
|
+
* @returns {void}
|
|
1121
|
+
*/
|
|
1122
|
+
DocxRenderer.prototype.insertPage = function (index, page) {
|
|
1123
|
+
var isPageMoved = false;
|
|
1124
|
+
if (this.pages.indexOf(page) !== index) {
|
|
1125
|
+
isPageMoved = true;
|
|
1126
|
+
}
|
|
1127
|
+
if (this.pages.indexOf(page) > -1) {
|
|
1128
|
+
this.pages.splice(this.pages.indexOf(page), 1);
|
|
1129
|
+
}
|
|
1130
|
+
this.pages.splice(index, 0, page);
|
|
1131
|
+
var top = 20;
|
|
1132
|
+
if (index > 0) {
|
|
1133
|
+
top += this.pages[index - 1].boundingRectangle.bottom;
|
|
1134
|
+
}
|
|
1135
|
+
for (var i = index; i < this.pages.length; i++) {
|
|
1136
|
+
//Update bounding rectangle of next pages in collection.
|
|
1137
|
+
page = this.pages[i];
|
|
1138
|
+
if (isPageMoved) {
|
|
1139
|
+
page.currentPageNum = 1;
|
|
1140
|
+
}
|
|
1141
|
+
page.boundingRectangle = new Rect(page.boundingRectangle.x, top, page.boundingRectangle.width, page.boundingRectangle.height);
|
|
1142
|
+
top = page.boundingRectangle.bottom + 20;
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
/**
|
|
1146
|
+
* @private
|
|
1147
|
+
* @param {boolean} skipEndLayout - skipEndLayout
|
|
1148
|
+
* @returns {void}
|
|
1149
|
+
*/
|
|
1150
|
+
DocxRenderer.prototype.removeEmptyPages = function (skipEndLayout) {
|
|
1151
|
+
var scrollToLastPage = false;
|
|
1152
|
+
var isLayoutEndnote = false;
|
|
1153
|
+
var pageIndex = !isNullOrUndefined(this.editorProperties.selectionStartPage)
|
|
1154
|
+
? this.editorProperties.selectionStartPage - 1
|
|
1155
|
+
: -1;
|
|
1156
|
+
for (var j = 0; j < this.pages.length; j++) {
|
|
1157
|
+
var page = this.pages[Number(j)];
|
|
1158
|
+
for (var i = 0; i < page.bodyWidgets.length; i++) {
|
|
1159
|
+
var bodyWidget = page.bodyWidgets[Number(i)];
|
|
1160
|
+
if (page.bodyWidgets.length === 0 || bodyWidget.childWidgets.length === 0) {
|
|
1161
|
+
if (page.bodyWidgets.length >= 1) {
|
|
1162
|
+
var startindex = page.bodyWidgets.indexOf(bodyWidget);
|
|
1163
|
+
page.bodyWidgets.splice(startindex, 1);
|
|
1164
|
+
i--;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
if (page.bodyWidgets.length <= 0) {
|
|
1169
|
+
if (j === this.pages.length - 1 && this.viewer.visiblePages.indexOf(page) !== -1) {
|
|
1170
|
+
scrollToLastPage = true;
|
|
1171
|
+
}
|
|
1172
|
+
if (!isNullOrUndefined(page.endnoteWidget) && page.endnoteWidget.bodyWidgets.length > 0) {
|
|
1173
|
+
var endnote = page.endnoteWidget;
|
|
1174
|
+
var previousPage = page.previousPage;
|
|
1175
|
+
if (!isNullOrUndefined(previousPage)) {
|
|
1176
|
+
if (isNullOrUndefined(previousPage.endnoteWidget)) {
|
|
1177
|
+
previousPage.endnoteWidget = new FootNoteWidget();
|
|
1178
|
+
previousPage.endnoteWidget.footNoteType = 'Endnote';
|
|
1179
|
+
previousPage.endnoteWidget.page = previousPage;
|
|
1180
|
+
}
|
|
1181
|
+
for (var k = 0; k < endnote.bodyWidgets.length; k++) {
|
|
1182
|
+
var bodyWidget = endnote.bodyWidgets[k];
|
|
1183
|
+
var isCombined = false;
|
|
1184
|
+
if (previousPage.endnoteWidget.bodyWidgets.length > 0) {
|
|
1185
|
+
var lastBodyWidget = previousPage.endnoteWidget.bodyWidgets[previousPage.endnoteWidget.bodyWidgets.length - 1];
|
|
1186
|
+
if (bodyWidget.index === lastBodyWidget.index &&
|
|
1187
|
+
bodyWidget.footNoteReference === lastBodyWidget.footNoteReference) {
|
|
1188
|
+
lastBodyWidget.combineWidget(this.viewer);
|
|
1189
|
+
endnote.bodyWidgets.splice(k, 1);
|
|
1190
|
+
isCombined = true;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
if (!isCombined) {
|
|
1194
|
+
endnote.bodyWidgets.splice(k, 1);
|
|
1195
|
+
bodyWidget.index = previousPage.endnoteWidget.bodyWidgets.length;
|
|
1196
|
+
previousPage.endnoteWidget.bodyWidgets.push(bodyWidget);
|
|
1197
|
+
bodyWidget.containerWidget = previousPage.endnoteWidget;
|
|
1198
|
+
bodyWidget.page = previousPage;
|
|
1199
|
+
}
|
|
1200
|
+
k--;
|
|
1201
|
+
}
|
|
1202
|
+
if (!isNullOrUndefined(page.endnoteWidget) && page.endnoteWidget.bodyWidgets.length === 0) {
|
|
1203
|
+
page.endnoteWidget = undefined;
|
|
1204
|
+
}
|
|
1205
|
+
isLayoutEndnote = true;
|
|
1206
|
+
scrollToLastPage = false;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
if (this.pages.indexOf(page) !== -1 && !isNullOrUndefined(this.pages[j])) {
|
|
1210
|
+
this.removePage(this.pages[j]);
|
|
1211
|
+
}
|
|
1212
|
+
j--;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
if (!isNullOrUndefined(this.pages[pageIndex])) {
|
|
1216
|
+
var page = this.pages[pageIndex];
|
|
1217
|
+
if (page.headerWidget) {
|
|
1218
|
+
page.headerWidget.page = page;
|
|
1219
|
+
}
|
|
1220
|
+
if (page.footerWidget) {
|
|
1221
|
+
page.footerWidget.page = page;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
if (isLayoutEndnote && !skipEndLayout) {
|
|
1225
|
+
this.layout.reLayoutEndnote();
|
|
1226
|
+
}
|
|
1227
|
+
if (scrollToLastPage) {
|
|
1228
|
+
this.scrollToBottom(this.selectionPage);
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
/**
|
|
1232
|
+
* @private
|
|
1233
|
+
* @param {Page} page - page
|
|
1234
|
+
* @returns {void}
|
|
1235
|
+
*/
|
|
1236
|
+
DocxRenderer.prototype.scrollToBottom = function (page) {
|
|
1237
|
+
if (isNullOrUndefined(page) || isNullOrUndefined(page.boundingRectangle)) {
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
var containerHeight = this.visibleBounds.height;
|
|
1241
|
+
this.viewerContainer.scrollTop = page.boundingRectangle.bottom - containerHeight;
|
|
1242
|
+
};
|
|
1243
|
+
/**
|
|
1244
|
+
* @private
|
|
1245
|
+
* @param {FieldElementBox} fieldBegin - fieldBegin
|
|
1246
|
+
* @param {Page} page - page
|
|
1247
|
+
* @returns {string} string
|
|
1248
|
+
*/
|
|
1249
|
+
DocxRenderer.prototype.getFieldResult = function (fieldBegin, page) {
|
|
1250
|
+
if (!isNullOrUndefined(page) && !isNullOrUndefined(fieldBegin)) {
|
|
1251
|
+
var fieldCode = this.editorProperties.getFieldCode(fieldBegin);
|
|
1252
|
+
var fieldCodes = fieldCode.split('*');
|
|
1253
|
+
var fieldCategory = fieldCodes[0].replace(/[^\w\s]/gi, '').trim().toLowerCase();
|
|
1254
|
+
var fieldPattern = '';
|
|
1255
|
+
if (fieldCodes.length > 1) {
|
|
1256
|
+
if (fieldCodes[1] !== ' MERGEFORMAT') {
|
|
1257
|
+
fieldPattern = fieldCodes[1].replace(/[^\w\s]/gi, '').trim();
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
if (fieldPattern === '') {
|
|
1261
|
+
fieldPattern = page.bodyWidgets[0].sectionFormat.pageNumberStyle;
|
|
1262
|
+
}
|
|
1263
|
+
if (fieldCategory.indexOf(' ') !== -1) {
|
|
1264
|
+
fieldCategory = fieldCategory.split(' ')[0];
|
|
1265
|
+
}
|
|
1266
|
+
switch (fieldCategory) {
|
|
1267
|
+
case 'page':
|
|
1268
|
+
{
|
|
1269
|
+
if (page.bodyWidgets[0].sectionFormat.restartPageNumbering && page.sectionIndex !== 0) {
|
|
1270
|
+
var currentSectionIndex = page.sectionIndex;
|
|
1271
|
+
var previousPage_1 = page.previousPage;
|
|
1272
|
+
this.isRestartNumbering = true;
|
|
1273
|
+
if (currentSectionIndex !== previousPage_1.sectionIndex &&
|
|
1274
|
+
previousPage_1.bodyWidgets[previousPage_1.bodyWidgets.length - 1].sectionIndex !== currentSectionIndex) {
|
|
1275
|
+
page.currentPageNum = (page.bodyWidgets[0].sectionFormat.pageStartingNumber);
|
|
1276
|
+
return this.getFieldText(fieldPattern, page.currentPageNum);
|
|
1277
|
+
}
|
|
1278
|
+
if (previousPage_1.currentPageNum === 1 && currentSectionIndex !== previousPage_1.sectionIndex ||
|
|
1279
|
+
(currentSectionIndex === previousPage_1.sectionIndex &&
|
|
1280
|
+
previousPage_1.footerWidget.headerFooterType === 'FirstPageFooter')) {
|
|
1281
|
+
previousPage_1.currentPageNum = (page.bodyWidgets[0].sectionFormat.pageStartingNumber);
|
|
1282
|
+
}
|
|
1283
|
+
page.currentPageNum = previousPage_1.currentPageNum + 1;
|
|
1284
|
+
return this.getFieldText(fieldPattern, page.currentPageNum);
|
|
1285
|
+
}
|
|
1286
|
+
else if (page.bodyWidgets[0].sectionFormat.restartPageNumbering && page.sectionIndex === 0) {
|
|
1287
|
+
page.currentPageNum = page.bodyWidgets[0].sectionFormat.pageStartingNumber + page.index;
|
|
1288
|
+
return this.getFieldText(fieldPattern, page.currentPageNum);
|
|
1289
|
+
}
|
|
1290
|
+
var previousPage = page.previousPage;
|
|
1291
|
+
var pageStartIndex = -1;
|
|
1292
|
+
var restartPageNumber = false;
|
|
1293
|
+
if (!isNullOrUndefined(page.previousPage)) {
|
|
1294
|
+
restartPageNumber = page.previousPage.bodyWidgets[0].sectionFormat.restartPageNumbering;
|
|
1295
|
+
}
|
|
1296
|
+
if (previousPage && page.sectionIndex !== previousPage.sectionIndex
|
|
1297
|
+
&& previousPage.bodyWidgets[0].sectionFormat.restartPageNumbering && previousPage.currentPageNum === 1) {
|
|
1298
|
+
while (previousPage) {
|
|
1299
|
+
if (!isNullOrUndefined(previousPage.previousPage) &&
|
|
1300
|
+
previousPage.sectionIndex === previousPage.previousPage.sectionIndex) {
|
|
1301
|
+
previousPage = previousPage.previousPage;
|
|
1302
|
+
pageStartIndex = previousPage.index;
|
|
1303
|
+
}
|
|
1304
|
+
else {
|
|
1305
|
+
break;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
if (!restartPageNumber && pageStartIndex >= 0 &&
|
|
1310
|
+
page.previousPage.bodyWidgets[0].sectionFormat.pageStartingNumber +
|
|
1311
|
+
(page.previousPage.index - pageStartIndex) !== page.previousPage.currentPageNum) {
|
|
1312
|
+
page.currentPageNum = page.index + 1;
|
|
1313
|
+
}
|
|
1314
|
+
else if (!isNullOrUndefined(page.previousPage) &&
|
|
1315
|
+
((page.previousPage.bodyWidgets[0].sectionFormat.restartPageNumbering &&
|
|
1316
|
+
page.previousPage.currentPageNum !== 1)
|
|
1317
|
+
|| (this.isRestartNumbering && page.previousPage.currentPageNum !== 1))) {
|
|
1318
|
+
if (page.previousPage.bodyWidgets[0].sectionFormat.restartPageNumbering) {
|
|
1319
|
+
this.isRestartNumbering = true;
|
|
1320
|
+
}
|
|
1321
|
+
page.currentPageNum = page.previousPage.currentPageNum + 1;
|
|
1322
|
+
}
|
|
1323
|
+
else {
|
|
1324
|
+
if (!isNullOrUndefined(previousPage)) {
|
|
1325
|
+
// Traverse backwards to locate the correct anchor page for numbering.
|
|
1326
|
+
while (previousPage.previousPage) {
|
|
1327
|
+
//If the previous page currentPageNum is 1 and the previous page's page number is not restarted.
|
|
1328
|
+
if (previousPage && previousPage.currentPageNum === 1 &&
|
|
1329
|
+
!previousPage.bodyWidgets[0].sectionFormat.restartPageNumbering) {
|
|
1330
|
+
previousPage = previousPage.previousPage;
|
|
1331
|
+
}
|
|
1332
|
+
//If the the current page's page number is restarted. But, the current page section format is equal to previous page section format.
|
|
1333
|
+
else if (previousPage.bodyWidgets[0].sectionFormat.restartPageNumbering &&
|
|
1334
|
+
previousPage.bodyWidgets[0].sectionFormat ===
|
|
1335
|
+
previousPage.previousPage.bodyWidgets[0].sectionFormat) {
|
|
1336
|
+
previousPage = previousPage.previousPage;
|
|
1337
|
+
}
|
|
1338
|
+
else {
|
|
1339
|
+
break;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
//If previousPage exists, the previous page's page number is restarted and its currentPageNum is 1.
|
|
1343
|
+
if (previousPage && previousPage.bodyWidgets[0].sectionFormat.restartPageNumbering &&
|
|
1344
|
+
previousPage.currentPageNum === 1) {
|
|
1345
|
+
page.currentPageNum = previousPage.bodyWidgets[0].sectionFormat.pageStartingNumber +
|
|
1346
|
+
(page.index - previousPage.index);
|
|
1347
|
+
}
|
|
1348
|
+
//If previousPage exists, the previous page's currentPageNumber is not equal to 1.
|
|
1349
|
+
else if (previousPage && previousPage.currentPageNum !== 1) {
|
|
1350
|
+
page.currentPageNum = previousPage.currentPageNum + (page.index - previousPage.index);
|
|
1351
|
+
}
|
|
1352
|
+
else {
|
|
1353
|
+
page.currentPageNum = page.index + 1;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
else {
|
|
1357
|
+
page.currentPageNum = page.index + 1;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
return this.getFieldText(fieldPattern, page.currentPageNum);
|
|
1361
|
+
}
|
|
1362
|
+
case 'numpages':
|
|
1363
|
+
return this.getFieldText(fieldPattern, page.documentHelper.pages.length);
|
|
1364
|
+
case 'sectionpages':
|
|
1365
|
+
{
|
|
1366
|
+
var currentSectionIndex = page.sectionIndex;
|
|
1367
|
+
var currentPageCount = 0;
|
|
1368
|
+
for (var i = 0; i < page.documentHelper.pages.length; i++) {
|
|
1369
|
+
if (page.documentHelper.pages[i].sectionIndex === currentSectionIndex) {
|
|
1370
|
+
currentPageCount++;
|
|
1371
|
+
}
|
|
1372
|
+
else if (currentPageCount !== 0) {
|
|
1373
|
+
break;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
return this.getFieldText(fieldPattern, currentPageCount);
|
|
1377
|
+
}
|
|
1378
|
+
default:
|
|
1379
|
+
break;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
return '';
|
|
1383
|
+
};
|
|
1384
|
+
DocxRenderer.prototype.getFieldText = function (pattern, value) {
|
|
1385
|
+
switch (pattern) {
|
|
1386
|
+
case 'ALPHABETIC':
|
|
1387
|
+
return this.layout.getAsLetter(value).toUpperCase();
|
|
1388
|
+
case 'alphabetic':
|
|
1389
|
+
return this.layout.getAsLetter(value).toLowerCase();
|
|
1390
|
+
case 'roman':
|
|
1391
|
+
return this.layout.getAsRoman(value).toLowerCase();
|
|
1392
|
+
case 'ROMAN':
|
|
1393
|
+
return this.layout.getAsRoman(value).toUpperCase();
|
|
1394
|
+
case 'RomanUpper':
|
|
1395
|
+
return this.layout.getAsRoman(value).toUpperCase();
|
|
1396
|
+
case 'RomanLower':
|
|
1397
|
+
return this.layout.getAsRoman(value).toLowerCase();
|
|
1398
|
+
case 'LetterUpper':
|
|
1399
|
+
return this.layout.getAsLetter(value).toUpperCase();
|
|
1400
|
+
case 'LetterLower':
|
|
1401
|
+
return this.layout.getAsLetter(value).toLowerCase();
|
|
1402
|
+
default:
|
|
1403
|
+
return value.toString();
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
/**
|
|
1407
|
+
* Get Next paragraph in block
|
|
1408
|
+
*
|
|
1409
|
+
* @returns {ParagraphWidget}
|
|
1410
|
+
*/
|
|
1411
|
+
/**
|
|
1412
|
+
* @private
|
|
1413
|
+
* @param {BlockWidget} block - block
|
|
1414
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
1415
|
+
*/
|
|
1416
|
+
DocxRenderer.prototype.getNextParagraphBlock = function (block) {
|
|
1417
|
+
if (block.nextRenderedWidget instanceof ParagraphWidget) {
|
|
1418
|
+
return block.nextRenderedWidget;
|
|
1419
|
+
}
|
|
1420
|
+
else if (block.nextRenderedWidget instanceof TableWidget) {
|
|
1421
|
+
return this.getFirstParagraphInFirstCell(block.nextRenderedWidget);
|
|
1422
|
+
}
|
|
1423
|
+
if (block.containerWidget instanceof TableCellWidget) {
|
|
1424
|
+
return this.getNextParagraphCell(block.containerWidget);
|
|
1425
|
+
}
|
|
1426
|
+
else if (block.containerWidget instanceof BodyWidget) {
|
|
1427
|
+
return this.getNextParagraph(block.containerWidget);
|
|
1428
|
+
}
|
|
1429
|
+
else if (block.containerWidget instanceof HeaderFooterWidget && this.editorProperties.isMoveDownOrMoveUp) {
|
|
1430
|
+
return this.getFirstBlockInNextHeaderFooter(block);
|
|
1431
|
+
}
|
|
1432
|
+
return undefined;
|
|
1433
|
+
};
|
|
1434
|
+
/**
|
|
1435
|
+
* Get Next paragraph from cell
|
|
1436
|
+
* @private
|
|
1437
|
+
* @param {TableCellWidget} cell - cell
|
|
1438
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
1439
|
+
*/
|
|
1440
|
+
DocxRenderer.prototype.getNextParagraphCell = function (cell) {
|
|
1441
|
+
if (cell.nextRenderedWidget && cell.nextRenderedWidget instanceof TableCellWidget) {
|
|
1442
|
+
if (cell.rowIndex === cell.nextRenderedWidget.rowIndex) {
|
|
1443
|
+
//Return first paragraph in cell.
|
|
1444
|
+
cell = cell.nextRenderedWidget;
|
|
1445
|
+
if (cell.getSplitWidgets()[0] instanceof TableCellWidget) {
|
|
1446
|
+
for (var _i = 0, _a = cell.getSplitWidgets(); _i < _a.length; _i++) {
|
|
1447
|
+
var widget = _a[_i];
|
|
1448
|
+
cell = widget;
|
|
1449
|
+
if (cell.firstChild) {
|
|
1450
|
+
break;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
var block = cell.firstChild;
|
|
1455
|
+
if (block) {
|
|
1456
|
+
return this.getFirstParagraphBlock(block);
|
|
1457
|
+
}
|
|
1458
|
+
else {
|
|
1459
|
+
return this.getNextParagraphCell(cell);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
else {
|
|
1463
|
+
cell = cell.nextRenderedWidget;
|
|
1464
|
+
return this.getNextParagraphCell(cell);
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
else if (cell.nextSplitWidget && cell.nextSplitWidget.childWidgets.length === 0) {
|
|
1468
|
+
cell = cell.getSplitWidgets().pop();
|
|
1469
|
+
}
|
|
1470
|
+
return this.getNextParagraphRow(cell.containerWidget);
|
|
1471
|
+
};
|
|
1472
|
+
/**
|
|
1473
|
+
* Get next paragraph in bodyWidget
|
|
1474
|
+
* @private
|
|
1475
|
+
* @param {BodyWidget} section - section
|
|
1476
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
1477
|
+
*/
|
|
1478
|
+
DocxRenderer.prototype.getNextParagraph = function (section) {
|
|
1479
|
+
if (section.nextRenderedWidget instanceof BodyWidget) {
|
|
1480
|
+
var block = section.nextRenderedWidget.childWidgets[0];
|
|
1481
|
+
return this.getFirstParagraphBlock(block);
|
|
1482
|
+
}
|
|
1483
|
+
return undefined;
|
|
1484
|
+
};
|
|
1485
|
+
/**
|
|
1486
|
+
* @private
|
|
1487
|
+
* @param {BlockWidget} block - block
|
|
1488
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
1489
|
+
*/
|
|
1490
|
+
DocxRenderer.prototype.getFirstBlockInNextHeaderFooter = function (block) {
|
|
1491
|
+
var headerFooter = block.containerWidget;
|
|
1492
|
+
var nextBlock;
|
|
1493
|
+
if (headerFooter.headerFooterType.indexOf('Header') !== -1) {
|
|
1494
|
+
nextBlock = headerFooter.page.footerWidget.firstChild;
|
|
1495
|
+
}
|
|
1496
|
+
else if (headerFooter.page.nextPage) {
|
|
1497
|
+
var nextPage = headerFooter.page.nextPage;
|
|
1498
|
+
var headerWidget = nextPage.headerWidget;
|
|
1499
|
+
headerWidget.page = nextPage;
|
|
1500
|
+
if (nextPage.footerWidget) {
|
|
1501
|
+
nextPage.footerWidget.page = nextPage;
|
|
1502
|
+
}
|
|
1503
|
+
nextBlock = headerWidget.firstChild;
|
|
1504
|
+
}
|
|
1505
|
+
else {
|
|
1506
|
+
return undefined;
|
|
1507
|
+
}
|
|
1508
|
+
if (nextBlock instanceof ParagraphWidget) {
|
|
1509
|
+
return nextBlock;
|
|
1510
|
+
}
|
|
1511
|
+
else {
|
|
1512
|
+
return this.getFirstBlockInFirstCell(nextBlock);
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
/**
|
|
1516
|
+
* Get next paragraph for row
|
|
1517
|
+
* @private
|
|
1518
|
+
* @param {BlockWidget} row - row
|
|
1519
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
1520
|
+
*/
|
|
1521
|
+
DocxRenderer.prototype.getNextParagraphRow = function (row) {
|
|
1522
|
+
if (!isNullOrUndefined(row.nextRenderedWidget)) {
|
|
1523
|
+
var cell = row.nextRenderedWidget.childWidgets[0];
|
|
1524
|
+
while (cell.childWidgets.length === 0 && !isNullOrUndefined(cell.previousSplitWidget) &&
|
|
1525
|
+
!isNullOrUndefined(cell.nextRenderedWidget) && cell.nextRenderedWidget instanceof TableCellWidget) {
|
|
1526
|
+
cell = cell.nextRenderedWidget;
|
|
1527
|
+
}
|
|
1528
|
+
var block = cell.childWidgets[0];
|
|
1529
|
+
if (isNullOrUndefined(block)) {
|
|
1530
|
+
return this.getNextParagraphCell(cell);
|
|
1531
|
+
}
|
|
1532
|
+
return this.getFirstParagraphBlock(block);
|
|
1533
|
+
}
|
|
1534
|
+
return this.getNextParagraphBlock(row.ownerTable);
|
|
1535
|
+
};
|
|
1536
|
+
/**
|
|
1537
|
+
* @private
|
|
1538
|
+
* @param {TableWidget} table - table
|
|
1539
|
+
* @returns {BlockWidget} BlockWidget
|
|
1540
|
+
*/
|
|
1541
|
+
DocxRenderer.prototype.getFirstBlockInFirstCell = function (table) {
|
|
1542
|
+
if (table.childWidgets.length > 0) {
|
|
1543
|
+
var firstrow = table.childWidgets[0];
|
|
1544
|
+
for (var i = 0; i < firstrow.childWidgets.length; i++) {
|
|
1545
|
+
var firstcell = firstrow.childWidgets[i];
|
|
1546
|
+
if (firstcell.childWidgets.length > 0) {
|
|
1547
|
+
return firstcell.childWidgets[0];
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
return undefined;
|
|
1552
|
+
};
|
|
1553
|
+
/**
|
|
1554
|
+
* Destroys the internal objects maintained for control.
|
|
1555
|
+
* @private
|
|
1556
|
+
* @returns {void}
|
|
1557
|
+
*/
|
|
1558
|
+
DocxRenderer.prototype.destroy = function () {
|
|
1559
|
+
if (this.styles) {
|
|
1560
|
+
this.styles.destroy();
|
|
1561
|
+
this.styles = undefined;
|
|
1562
|
+
}
|
|
1563
|
+
if (this.stylesMap) {
|
|
1564
|
+
this.stylesMap.destroy();
|
|
1565
|
+
this.stylesMap = undefined;
|
|
1566
|
+
}
|
|
1567
|
+
if (this.characterFormat) {
|
|
1568
|
+
this.characterFormat.destroy();
|
|
1569
|
+
this.characterFormat = undefined;
|
|
1570
|
+
}
|
|
1571
|
+
if (this.themeFontLanguage) {
|
|
1572
|
+
this.themeFontLanguage.destroy();
|
|
1573
|
+
this.themeFontLanguage = undefined;
|
|
1574
|
+
}
|
|
1575
|
+
if (this.paragraphFormat) {
|
|
1576
|
+
this.paragraphFormat.destroy();
|
|
1577
|
+
this.paragraphFormat = undefined;
|
|
1578
|
+
}
|
|
1579
|
+
if (this.pages && this.pages.length > 0) {
|
|
1580
|
+
for (var i = 0; i < this.pages.length; i++) {
|
|
1581
|
+
var page = this.pages[i];
|
|
1582
|
+
page.componentDestroy();
|
|
1583
|
+
}
|
|
1584
|
+
this.pages = [];
|
|
1585
|
+
}
|
|
1586
|
+
this.pages = undefined;
|
|
1587
|
+
if (this.lists && this.lists.length > 0) {
|
|
1588
|
+
for (var i = 0; i < this.lists.length; i++) {
|
|
1589
|
+
var list = this.lists[Number(i)];
|
|
1590
|
+
list.destroy();
|
|
1591
|
+
}
|
|
1592
|
+
this.lists = [];
|
|
1593
|
+
}
|
|
1594
|
+
this.lists = undefined;
|
|
1595
|
+
if (this.abstractLists && this.abstractLists.length > 0) {
|
|
1596
|
+
for (var i = 0; i < this.abstractLists.length; i++) {
|
|
1597
|
+
var abstractList = this.abstractLists[Number(i)];
|
|
1598
|
+
if (!isNullOrUndefined(abstractList)) {
|
|
1599
|
+
abstractList.destroy();
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
this.abstractLists = [];
|
|
1604
|
+
this.abstractLists = undefined;
|
|
1605
|
+
this.fieldStacks = [];
|
|
1606
|
+
this.fieldStacks = undefined;
|
|
1607
|
+
this.splittedCellWidgets = [];
|
|
1608
|
+
this.splittedCellWidgets = undefined;
|
|
1609
|
+
this.fields = [];
|
|
1610
|
+
this.fields = undefined;
|
|
1611
|
+
if (!isNullOrUndefined(this.renderedLists)) {
|
|
1612
|
+
this.renderedLists.destroy();
|
|
1613
|
+
}
|
|
1614
|
+
this.renderedLists = undefined;
|
|
1615
|
+
if (!isNullOrUndefined(this.authors)) {
|
|
1616
|
+
this.authors.destroy();
|
|
1617
|
+
}
|
|
1618
|
+
this.authors = undefined;
|
|
1619
|
+
if (!isNullOrUndefined(this.revisionsInternal)) {
|
|
1620
|
+
this.revisionsInternal.destroy();
|
|
1621
|
+
}
|
|
1622
|
+
this.revisionsInternal = undefined;
|
|
1623
|
+
if (!isNullOrUndefined(this.preDefinedStyles)) {
|
|
1624
|
+
this.preDefinedStyles.destroy();
|
|
1625
|
+
}
|
|
1626
|
+
this.preDefinedStyles = undefined;
|
|
1627
|
+
if (!isNullOrUndefined(this.bookmarks)) {
|
|
1628
|
+
this.bookmarks.destroy();
|
|
1629
|
+
}
|
|
1630
|
+
this.bookmarks = undefined;
|
|
1631
|
+
if (!isNullOrUndefined(this.editRanges)) {
|
|
1632
|
+
this.editRanges.destroy();
|
|
1633
|
+
}
|
|
1634
|
+
this.editRanges = undefined;
|
|
1635
|
+
if (!isNullOrUndefined(this.customXmlData)) {
|
|
1636
|
+
this.customXmlData.destroy();
|
|
1637
|
+
}
|
|
1638
|
+
if (!isNullOrUndefined(this.images)) {
|
|
1639
|
+
this.images.destroy();
|
|
1640
|
+
}
|
|
1641
|
+
if (!isNullOrUndefined(this.fontSubstitutionTable)) {
|
|
1642
|
+
this.fontSubstitutionTable.destroy();
|
|
1643
|
+
}
|
|
1644
|
+
this.fontSubstitutionTable = undefined;
|
|
1645
|
+
this.customXmlData = undefined;
|
|
1646
|
+
this.images = undefined;
|
|
1647
|
+
this.blockToShift = undefined;
|
|
1648
|
+
if (this.comments && this.comments.length > 0) {
|
|
1649
|
+
for (var i = 0; i < this.comments.length; i++) {
|
|
1650
|
+
var comment = this.comments[Number(i)];
|
|
1651
|
+
comment.destroy();
|
|
1652
|
+
}
|
|
1653
|
+
this.comments = [];
|
|
1654
|
+
}
|
|
1655
|
+
this.comments = undefined;
|
|
1656
|
+
if (this.contentControlCollection && this.contentControlCollection.length > 0) {
|
|
1657
|
+
for (var i = 0; i < this.contentControlCollection.length; i++) {
|
|
1658
|
+
var contentControl = this.contentControlCollection[Number(i)];
|
|
1659
|
+
if (!isNullOrUndefined(contentControl)) {
|
|
1660
|
+
contentControl.destroy();
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
this.contentControlCollection = [];
|
|
1665
|
+
this.contentControlCollection = undefined;
|
|
1666
|
+
this.renderedLevelOverrides = [];
|
|
1667
|
+
this.renderedLevelOverrides = undefined;
|
|
1668
|
+
this.headersFooters = [];
|
|
1669
|
+
this.headersFooters = undefined;
|
|
1670
|
+
this.listParagraphs = [];
|
|
1671
|
+
this.listParagraphs = undefined;
|
|
1672
|
+
this.formFields = [];
|
|
1673
|
+
this.formFields = undefined;
|
|
1674
|
+
this.fieldCollection = [];
|
|
1675
|
+
this.fieldCollection = undefined;
|
|
1676
|
+
this.userCollection = [];
|
|
1677
|
+
this.userCollection = undefined;
|
|
1678
|
+
if (this.footnotes) {
|
|
1679
|
+
this.footnotes.componentDestroy();
|
|
1680
|
+
this.footnotes = undefined;
|
|
1681
|
+
}
|
|
1682
|
+
if (this.endnotes) {
|
|
1683
|
+
this.endnotes.componentDestroy();
|
|
1684
|
+
this.endnotes = undefined;
|
|
1685
|
+
}
|
|
1686
|
+
this.footnoteCollection = [];
|
|
1687
|
+
this.footnoteCollection = undefined;
|
|
1688
|
+
this.endnoteCollection = [];
|
|
1689
|
+
this.endnoteCollection = undefined;
|
|
1690
|
+
if (this.layout) {
|
|
1691
|
+
this.layout.destroy();
|
|
1692
|
+
}
|
|
1693
|
+
this.layout = undefined;
|
|
1694
|
+
if (this.textHelper) {
|
|
1695
|
+
this.textHelper.destroy();
|
|
1696
|
+
}
|
|
1697
|
+
this.textHelper = undefined;
|
|
1698
|
+
if (!isNullOrUndefined(this.textMeasureHelper)) {
|
|
1699
|
+
this.textMeasureHelper.destroy();
|
|
1700
|
+
this.textMeasureHelper = undefined;
|
|
1701
|
+
}
|
|
1702
|
+
if (!isNullOrUndefined(this.parser)) {
|
|
1703
|
+
this.parser.destroy();
|
|
1704
|
+
this.parser = undefined;
|
|
1705
|
+
}
|
|
1706
|
+
if (!isNullOrUndefined(this.render)) {
|
|
1707
|
+
this.render.destroy();
|
|
1708
|
+
this.render = undefined;
|
|
1709
|
+
}
|
|
1710
|
+
if (!isNullOrUndefined(this.viewer)) {
|
|
1711
|
+
this.viewer.destroy();
|
|
1712
|
+
this.viewer = undefined;
|
|
1713
|
+
}
|
|
1714
|
+
if (!isNullOrUndefined(this.revisionHelper)) {
|
|
1715
|
+
this.revisionHelper.destroy();
|
|
1716
|
+
this.revisionHelper = undefined;
|
|
1717
|
+
}
|
|
1718
|
+
if (!isNullOrUndefined(this.themes)) {
|
|
1719
|
+
this.themes.destroy();
|
|
1720
|
+
this.themes = undefined;
|
|
1721
|
+
}
|
|
1722
|
+
if (!isNullOrUndefined(this.selectionCanvasIn) && !isNullOrUndefined(this.selectionCanvasIn.parentElement)) {
|
|
1723
|
+
this.selectionCanvasIn.parentElement.removeChild(this.selectionCanvasIn);
|
|
1724
|
+
}
|
|
1725
|
+
this.selectionCanvasIn = undefined;
|
|
1726
|
+
if (!isNullOrUndefined(this.containerCanvasIn) && !isNullOrUndefined(this.containerCanvasIn.parentElement)) {
|
|
1727
|
+
this.containerCanvasIn.parentElement.removeChild(this.containerCanvasIn);
|
|
1728
|
+
}
|
|
1729
|
+
this.containerCanvasIn = undefined;
|
|
1730
|
+
this.sections = [];
|
|
1731
|
+
this.sections = undefined;
|
|
1732
|
+
this.tableLefts = [];
|
|
1733
|
+
this.tableLefts = undefined;
|
|
1734
|
+
this.endBookmarksUpdated = [];
|
|
1735
|
+
this.endBookmarksUpdated = undefined;
|
|
1736
|
+
this.cachedPages = [];
|
|
1737
|
+
this.cachedPages = undefined;
|
|
1738
|
+
this.scheduledTimeouts = {};
|
|
1739
|
+
this.scheduledTimeouts = undefined;
|
|
1740
|
+
this.visibleBoundsIn = undefined;
|
|
1741
|
+
// Drop editor-owned references. Do not destroy them; the editor still owns them.
|
|
1742
|
+
this.editorProperties = undefined;
|
|
1743
|
+
this.documentEditorSettings = undefined;
|
|
1744
|
+
this.documentSettings = undefined;
|
|
1745
|
+
this.viewerContainer = undefined;
|
|
1746
|
+
this.pageContainer = undefined;
|
|
1747
|
+
this.elementIn = undefined;
|
|
1748
|
+
this.hostElement = undefined;
|
|
1749
|
+
this.selectionPage = undefined;
|
|
1750
|
+
this.selectionEndParagraph = undefined;
|
|
1751
|
+
this.selectionCharacterFormat = undefined;
|
|
1752
|
+
this.editorCharacterFormat = undefined;
|
|
1753
|
+
this.editorParagraphFormat = undefined;
|
|
1754
|
+
this.documentCharacterFormat = undefined;
|
|
1755
|
+
this.documentParagraphFormat = undefined;
|
|
1756
|
+
this.lockedPictureContentControl = undefined;
|
|
1757
|
+
this.L10n = undefined;
|
|
1758
|
+
this.defaultLocale = undefined;
|
|
1759
|
+
this.hooks.onRevisionConstructed = undefined;
|
|
1760
|
+
this.hooks.onUpdateScrollBars = undefined;
|
|
1761
|
+
this.hooks.onProcessAsyncPageUpdate = undefined;
|
|
1762
|
+
this.hooks.onPerformUpdateAfterLoad = undefined;
|
|
1763
|
+
this.hooks.onUpdateBookmarkCollection = undefined;
|
|
1764
|
+
this.hooks.onInsertContentControl = undefined;
|
|
1765
|
+
this.hooks.onCommentSelected = undefined;
|
|
1766
|
+
this.hooks.isBlockExistAfter = undefined;
|
|
1767
|
+
this.hooks.getSelectionOffsets = undefined;
|
|
1768
|
+
this.hooks.selectRange = undefined;
|
|
1769
|
+
this.hooks.onTriggerSpellChecker = undefined;
|
|
1770
|
+
this.hooks = undefined;
|
|
1771
|
+
this.heightInfoCollection = undefined;
|
|
1772
|
+
this.isRestartNumbering = false;
|
|
1773
|
+
this.currentDocumentLoadId = 0;
|
|
1774
|
+
};
|
|
1775
|
+
/**
|
|
1776
|
+
* @private
|
|
1777
|
+
* @param {ParagraphWidget} paragraph - paragraph
|
|
1778
|
+
* @returns {BorderRenderInfo} BorderRenderInfo
|
|
1779
|
+
*/
|
|
1780
|
+
DocxRenderer.prototype.canRenderBorder = function (paragraph) {
|
|
1781
|
+
var skipTopBorder = false;
|
|
1782
|
+
var skipBottomBorder = false;
|
|
1783
|
+
var isSameTopBorder;
|
|
1784
|
+
var isSameBottomBorder;
|
|
1785
|
+
var isSameLeftBorder;
|
|
1786
|
+
var isSameRightBorder;
|
|
1787
|
+
var previousBlock = paragraph.previousRenderedWidget;
|
|
1788
|
+
var nextBlock = paragraph.nextRenderedWidget;
|
|
1789
|
+
var previousSplitWidget = paragraph.previousSplitWidget;
|
|
1790
|
+
if (!isNullOrUndefined(previousBlock) && !isNullOrUndefined(previousSplitWidget) && previousBlock === previousSplitWidget) {
|
|
1791
|
+
skipTopBorder = true;
|
|
1792
|
+
}
|
|
1793
|
+
var nextSplitWidget = paragraph.nextSplitWidget;
|
|
1794
|
+
if (!isNullOrUndefined(nextBlock) && !isNullOrUndefined(nextSplitWidget) && nextBlock === nextSplitWidget) {
|
|
1795
|
+
skipBottomBorder = true;
|
|
1796
|
+
}
|
|
1797
|
+
if ((skipTopBorder && skipBottomBorder) ||
|
|
1798
|
+
(skipTopBorder && isNullOrUndefined(nextBlock)) ||
|
|
1799
|
+
(skipBottomBorder && isNullOrUndefined(previousBlock))) {
|
|
1800
|
+
return { skipTopBorder: skipTopBorder, skipBottomBorder: skipBottomBorder };
|
|
1801
|
+
}
|
|
1802
|
+
var paragraphX = this.getParagraphLeftPosition(paragraph);
|
|
1803
|
+
var previousBlockX = 0;
|
|
1804
|
+
var nextBlockX = 0;
|
|
1805
|
+
if (!skipTopBorder && !isNullOrUndefined(previousBlock) && previousBlock instanceof ParagraphWidget) {
|
|
1806
|
+
previousBlockX = this.getParagraphLeftPosition(previousBlock);
|
|
1807
|
+
}
|
|
1808
|
+
if (!skipBottomBorder && !isNullOrUndefined(nextBlock) && nextBlock instanceof ParagraphWidget) {
|
|
1809
|
+
nextBlockX = this.getParagraphLeftPosition(nextBlock);
|
|
1810
|
+
}
|
|
1811
|
+
var topBorder = paragraph.paragraphFormat.borders.top;
|
|
1812
|
+
var bottomBorder = paragraph.paragraphFormat.borders.bottom;
|
|
1813
|
+
var leftBorder = paragraph.paragraphFormat.borders.left;
|
|
1814
|
+
var rightBorder = paragraph.paragraphFormat.borders.right;
|
|
1815
|
+
if (!skipTopBorder && !isNullOrUndefined(previousBlock) && previousBlock instanceof ParagraphWidget &&
|
|
1816
|
+
paragraphX === previousBlockX) {
|
|
1817
|
+
isSameTopBorder = this.checkEqualBorder(topBorder, previousBlock.paragraphFormat.borders.top);
|
|
1818
|
+
isSameBottomBorder = this.checkEqualBorder(bottomBorder, previousBlock.paragraphFormat.borders.bottom);
|
|
1819
|
+
isSameLeftBorder = this.checkEqualBorder(leftBorder, previousBlock.paragraphFormat.borders.left);
|
|
1820
|
+
isSameRightBorder = this.checkEqualBorder(rightBorder, previousBlock.paragraphFormat.borders.right);
|
|
1821
|
+
var horizontalBorder = previousBlock.paragraphFormat.borders.horizontal;
|
|
1822
|
+
if (isSameTopBorder && isSameBottomBorder && isSameLeftBorder && isSameRightBorder
|
|
1823
|
+
&& !isNullOrUndefined(horizontalBorder) && horizontalBorder.lineStyle === 'None') {
|
|
1824
|
+
skipTopBorder = true;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
if (!skipBottomBorder && !isNullOrUndefined(nextBlock) && nextBlock instanceof ParagraphWidget &&
|
|
1828
|
+
(paragraphX === nextBlockX || (this.layout.isInitialLoad && this.skipBottomBorder(paragraph, nextBlock)))) {
|
|
1829
|
+
isSameTopBorder = this.checkEqualBorder(topBorder, nextBlock.paragraphFormat.borders.top);
|
|
1830
|
+
isSameBottomBorder = this.checkEqualBorder(bottomBorder, nextBlock.paragraphFormat.borders.bottom);
|
|
1831
|
+
isSameLeftBorder = this.checkEqualBorder(leftBorder, nextBlock.paragraphFormat.borders.left);
|
|
1832
|
+
isSameRightBorder = this.checkEqualBorder(rightBorder, nextBlock.paragraphFormat.borders.right);
|
|
1833
|
+
if (isSameBottomBorder && isSameTopBorder && isSameLeftBorder && isSameRightBorder) {
|
|
1834
|
+
skipBottomBorder = true;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
return {
|
|
1838
|
+
'skipTopBorder': skipTopBorder,
|
|
1839
|
+
'skipBottomBorder': skipBottomBorder
|
|
1840
|
+
};
|
|
1841
|
+
};
|
|
1842
|
+
DocxRenderer.prototype.checkEqualBorder = function (source, dest) {
|
|
1843
|
+
if (!isNullOrUndefined(source) && !isNullOrUndefined(dest)) {
|
|
1844
|
+
return source.isEqualFormat(dest);
|
|
1845
|
+
}
|
|
1846
|
+
else {
|
|
1847
|
+
if (isNullOrUndefined(source) && isNullOrUndefined(dest)) {
|
|
1848
|
+
return true;
|
|
1849
|
+
}
|
|
1850
|
+
else {
|
|
1851
|
+
return false;
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
};
|
|
1855
|
+
/**
|
|
1856
|
+
* @private
|
|
1857
|
+
* @param {ParagraphWidget} paragraphWidget - paragraphWidget
|
|
1858
|
+
* @returns {number} number
|
|
1859
|
+
*/
|
|
1860
|
+
DocxRenderer.prototype.getParagraphLeftPosition = function (paragraphWidget) {
|
|
1861
|
+
var hangingIndent = 0;
|
|
1862
|
+
var startX = 0;
|
|
1863
|
+
var firstLineIndent = paragraphWidget.paragraphFormat.firstLineIndent;
|
|
1864
|
+
if (firstLineIndent < 0) {
|
|
1865
|
+
hangingIndent = LayoutHelperMethods.convertPointToPixel(Math.abs(firstLineIndent));
|
|
1866
|
+
hangingIndent = parseFloat(hangingIndent.toFixed(5));
|
|
1867
|
+
}
|
|
1868
|
+
var textAlignment = paragraphWidget.paragraphFormat.textAlignment;
|
|
1869
|
+
if (paragraphWidget.isEmpty() && ((textAlignment !== 'Left' && textAlignment !== 'Justify')
|
|
1870
|
+
|| (textAlignment === 'Justify' && paragraphWidget.paragraphFormat.bidi))) {
|
|
1871
|
+
startX = paragraphWidget.clientX > hangingIndent ? paragraphWidget.clientX - hangingIndent : paragraphWidget.clientX;
|
|
1872
|
+
}
|
|
1873
|
+
else {
|
|
1874
|
+
startX = paragraphWidget.x > hangingIndent ? paragraphWidget.x - hangingIndent : paragraphWidget.x;
|
|
1875
|
+
}
|
|
1876
|
+
if (!isNullOrUndefined(startX)) {
|
|
1877
|
+
startX = parseFloat(startX.toFixed(2));
|
|
1878
|
+
}
|
|
1879
|
+
return startX;
|
|
1880
|
+
};
|
|
1881
|
+
/**
|
|
1882
|
+
* @private
|
|
1883
|
+
* @param {ParagraphWidget} paragraph - paragraph
|
|
1884
|
+
* @param {ParagraphWidget} nextWidget - nextWidget
|
|
1885
|
+
* @returns {boolean} boolean
|
|
1886
|
+
*/
|
|
1887
|
+
DocxRenderer.prototype.skipBottomBorder = function (paragraph, nextWidget) {
|
|
1888
|
+
var currentIndent = 0;
|
|
1889
|
+
var previousIndent = 0;
|
|
1890
|
+
if (paragraph.paragraphFormat.leftIndent === nextWidget.paragraphFormat.leftIndent) {
|
|
1891
|
+
return true;
|
|
1892
|
+
}
|
|
1893
|
+
else {
|
|
1894
|
+
currentIndent = paragraph.paragraphFormat.firstLineIndent < 0 ? Math.abs(paragraph.paragraphFormat.firstLineIndent) : 0;
|
|
1895
|
+
previousIndent = nextWidget.paragraphFormat.firstLineIndent < 0 ? Math.abs(nextWidget.paragraphFormat.firstLineIndent) : 0;
|
|
1896
|
+
currentIndent = paragraph.paragraphFormat.leftIndent > currentIndent ? paragraph.paragraphFormat.leftIndent - currentIndent : 0;
|
|
1897
|
+
previousIndent = nextWidget.paragraphFormat.leftIndent > previousIndent ?
|
|
1898
|
+
nextWidget.paragraphFormat.leftIndent - previousIndent : 0;
|
|
1899
|
+
if (currentIndent === previousIndent) {
|
|
1900
|
+
return true;
|
|
1901
|
+
}
|
|
1902
|
+
else {
|
|
1903
|
+
return false;
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
};
|
|
1907
|
+
/**
|
|
1908
|
+
* Get first paragraph in cell
|
|
1909
|
+
* @private
|
|
1910
|
+
* @param {TableCellWidget} cell - cell
|
|
1911
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
1912
|
+
*/
|
|
1913
|
+
DocxRenderer.prototype.getFirstParagraphInCell = function (cell) {
|
|
1914
|
+
var firstBlock = cell.childWidgets[0];
|
|
1915
|
+
if (firstBlock instanceof ParagraphWidget) {
|
|
1916
|
+
return firstBlock;
|
|
1917
|
+
}
|
|
1918
|
+
else {
|
|
1919
|
+
return this.getFirstParagraphInFirstCell(firstBlock);
|
|
1920
|
+
}
|
|
1921
|
+
};
|
|
1922
|
+
/**
|
|
1923
|
+
* Get first paragraph in first cell
|
|
1924
|
+
* @private
|
|
1925
|
+
* @param {TableWidget} table - table
|
|
1926
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
1927
|
+
*/
|
|
1928
|
+
DocxRenderer.prototype.getFirstParagraphInFirstCell = function (table) {
|
|
1929
|
+
if (!isNullOrUndefined(table.childWidgets) && table.childWidgets.length > 0) {
|
|
1930
|
+
var firstRow = table.childWidgets[0];
|
|
1931
|
+
var cell = firstRow.childWidgets[0];
|
|
1932
|
+
var block = cell.childWidgets[0];
|
|
1933
|
+
return this.getFirstParagraphBlock(block);
|
|
1934
|
+
}
|
|
1935
|
+
return undefined;
|
|
1936
|
+
};
|
|
1937
|
+
/**
|
|
1938
|
+
* Get last paragraph in last cell
|
|
1939
|
+
* @private
|
|
1940
|
+
* @param {TableWidget} table - table
|
|
1941
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
1942
|
+
*/
|
|
1943
|
+
DocxRenderer.prototype.getLastParagraphInLastCell = function (table) {
|
|
1944
|
+
if (!isNullOrUndefined(table.childWidgets) && table.childWidgets.length > 0) {
|
|
1945
|
+
var lastrow = table.lastChild;
|
|
1946
|
+
var lastcell = lastrow.lastChild;
|
|
1947
|
+
var lastBlock = lastcell.lastChild;
|
|
1948
|
+
return this.getLastParagraphBlock(lastBlock);
|
|
1949
|
+
}
|
|
1950
|
+
return undefined;
|
|
1951
|
+
};
|
|
1952
|
+
/**
|
|
1953
|
+
* Get first paragraph in block
|
|
1954
|
+
* @private
|
|
1955
|
+
* @param {BlockWidget} block - block
|
|
1956
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
1957
|
+
*/
|
|
1958
|
+
DocxRenderer.prototype.getFirstParagraphBlock = function (block) {
|
|
1959
|
+
if (block instanceof ParagraphWidget) {
|
|
1960
|
+
return block;
|
|
1961
|
+
}
|
|
1962
|
+
else if (block instanceof TableWidget) {
|
|
1963
|
+
return this.getFirstParagraphInFirstCell(block);
|
|
1964
|
+
}
|
|
1965
|
+
return undefined;
|
|
1966
|
+
};
|
|
1967
|
+
/**
|
|
1968
|
+
* Get last paragraph in block
|
|
1969
|
+
*
|
|
1970
|
+
* @private
|
|
1971
|
+
* @param {BlockWidget} block - block
|
|
1972
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
1973
|
+
*/
|
|
1974
|
+
DocxRenderer.prototype.getLastParagraphBlock = function (block) {
|
|
1975
|
+
if (block instanceof ParagraphWidget) {
|
|
1976
|
+
return block;
|
|
1977
|
+
}
|
|
1978
|
+
else if (block instanceof TableWidget) {
|
|
1979
|
+
return this.getLastParagraphInLastCell(block);
|
|
1980
|
+
}
|
|
1981
|
+
return undefined;
|
|
1982
|
+
};
|
|
1983
|
+
/**
|
|
1984
|
+
* Get last paragraph in first row
|
|
1985
|
+
*
|
|
1986
|
+
* @private
|
|
1987
|
+
* @param {TableWidget} table - table
|
|
1988
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
1989
|
+
*/
|
|
1990
|
+
DocxRenderer.prototype.getLastParagraphInFirstRow = function (table) {
|
|
1991
|
+
if (table.childWidgets.length > 0) {
|
|
1992
|
+
var row = table.firstChild;
|
|
1993
|
+
var lastcell = row.lastChild;
|
|
1994
|
+
var lastBlock = lastcell.lastChild;
|
|
1995
|
+
return this.getLastParagraphBlock(lastBlock);
|
|
1996
|
+
}
|
|
1997
|
+
return undefined;
|
|
1998
|
+
};
|
|
1999
|
+
/**
|
|
2000
|
+
* Get first paragraph in last row
|
|
2001
|
+
* @private
|
|
2002
|
+
* @param {TableWidget} table - table
|
|
2003
|
+
* @returns {ParagraphWidget} ParagraphWidget
|
|
2004
|
+
*/
|
|
2005
|
+
DocxRenderer.prototype.getFirstParagraphInLastRow = function (table) {
|
|
2006
|
+
if (table.childWidgets.length > 0) {
|
|
2007
|
+
var lastRow = table.childWidgets[table.childWidgets.length - 1];
|
|
2008
|
+
var lastCell = lastRow.childWidgets[0];
|
|
2009
|
+
var lastBlock = lastCell.childWidgets[0];
|
|
2010
|
+
return this.getFirstParagraphBlock(lastBlock);
|
|
2011
|
+
}
|
|
2012
|
+
return undefined;
|
|
2013
|
+
};
|
|
2014
|
+
/**
|
|
2015
|
+
* Add the given WStyle Object ot stylesMap Dictionary
|
|
2016
|
+
* @private
|
|
2017
|
+
* @param {WStyle} style - style
|
|
2018
|
+
* @returns {void}
|
|
2019
|
+
*/
|
|
2020
|
+
/* eslint-disable */
|
|
2021
|
+
DocxRenderer.prototype.addToStylesMap = function (style) {
|
|
2022
|
+
var returnStyle = {};
|
|
2023
|
+
var returnStyleObject = {};
|
|
2024
|
+
var paraIcon = 'e-list-icon e-de-listview-icon e-de-e-paragraph-style-mark e-icons';
|
|
2025
|
+
var charIcon = 'e-list-icon e-de-listview-icon e-de-e-character-style-mark e-icons';
|
|
2026
|
+
var linkedIcon = 'e-list-icon e-de-listview-icon e-de-e-linked-style-mark e-icons';
|
|
2027
|
+
// StyleName for the dropDownItem
|
|
2028
|
+
if (!isNullOrUndefined(style)) {
|
|
2029
|
+
var styleName = this.L10n ? this.L10n.getConstant(style.name) : style.name;
|
|
2030
|
+
returnStyle.StyleName = (styleName === '') ? style.name : styleName;
|
|
2031
|
+
if (style.type == "Paragraph") {
|
|
2032
|
+
returnStyleObject.paragraphFormat = {};
|
|
2033
|
+
LayoutHelperMethods.writeParagraphFormat(returnStyleObject.paragraphFormat, true, style.paragraphFormat);
|
|
2034
|
+
}
|
|
2035
|
+
returnStyleObject.characterFormat = {};
|
|
2036
|
+
LayoutHelperMethods.writeCharacterFormat(returnStyleObject.characterFormat, true, style.characterFormat);
|
|
2037
|
+
// CSS Style for dropDownItem
|
|
2038
|
+
returnStyle.Style = this.parseStyle(JSON.stringify(returnStyleObject));
|
|
2039
|
+
// Setting type for segregating and adding iconcss
|
|
2040
|
+
if (!isNullOrUndefined(style.type)) {
|
|
2041
|
+
returnStyle.type = style.type;
|
|
2042
|
+
if (returnStyle.type == "Paragraph" && !isNullOrUndefined(style.link)) {
|
|
2043
|
+
returnStyle.type = "Linked";
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
// Adding IconCss to the dropDownItem
|
|
2047
|
+
if (returnStyle.type == "Paragraph") {
|
|
2048
|
+
returnStyle.IconClass = paraIcon;
|
|
2049
|
+
}
|
|
2050
|
+
else if (returnStyle.type == "Character") {
|
|
2051
|
+
returnStyle.IconClass = charIcon;
|
|
2052
|
+
}
|
|
2053
|
+
else {
|
|
2054
|
+
returnStyle.IconClass = linkedIcon;
|
|
2055
|
+
}
|
|
2056
|
+
if (this.stylesMap.get(returnStyle.type)) {
|
|
2057
|
+
this.stylesMap.get(returnStyle.type).push(returnStyle);
|
|
2058
|
+
}
|
|
2059
|
+
else {
|
|
2060
|
+
this.stylesMap.add(returnStyle.type, [returnStyle]);
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
};
|
|
2064
|
+
DocxRenderer.prototype.parseStyle = function (style) {
|
|
2065
|
+
var domStyle = '';
|
|
2066
|
+
var styleObj = JSON.parse(style);
|
|
2067
|
+
var textDecoration = '';
|
|
2068
|
+
if (!isNullOrUndefined(styleObj.characterFormat.baselineAlignment) && styleObj.characterFormat.baselineAlignment !== 'Normal') {
|
|
2069
|
+
var vAlign = '';
|
|
2070
|
+
switch (styleObj.characterFormat.baselineAlignment) {
|
|
2071
|
+
case 'Superscript':
|
|
2072
|
+
vAlign = 'super';
|
|
2073
|
+
break;
|
|
2074
|
+
case 'Subscript':
|
|
2075
|
+
vAlign = 'sub';
|
|
2076
|
+
break;
|
|
2077
|
+
}
|
|
2078
|
+
if (vAlign.length > 1) {
|
|
2079
|
+
domStyle += 'vertical-align:' + vAlign + ';';
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
if (!isNullOrUndefined(styleObj.characterFormat.underline) && styleObj.characterFormat.underline !== 'None') {
|
|
2083
|
+
textDecoration += 'underline ';
|
|
2084
|
+
}
|
|
2085
|
+
if (!isNullOrUndefined(styleObj.characterFormat.strikethrough) && styleObj.characterFormat.strikethrough !== 'None') {
|
|
2086
|
+
textDecoration += 'line-through ';
|
|
2087
|
+
}
|
|
2088
|
+
if (!isNullOrUndefined(styleObj.characterFormat.fontSize)) {
|
|
2089
|
+
domStyle += 'font-size:' + styleObj.characterFormat.fontSize + 'px;';
|
|
2090
|
+
}
|
|
2091
|
+
if (!isNullOrUndefined(styleObj.characterFormat.fontFamily)) {
|
|
2092
|
+
domStyle += 'font-family:' + styleObj.characterFormat.fontFamily + ';';
|
|
2093
|
+
}
|
|
2094
|
+
if (!isNullOrUndefined(styleObj.characterFormat.bold) && styleObj.characterFormat.bold) {
|
|
2095
|
+
domStyle += 'font-weight:bold;';
|
|
2096
|
+
}
|
|
2097
|
+
if (!isNullOrUndefined(styleObj.characterFormat.italic) && styleObj.characterFormat.italic) {
|
|
2098
|
+
domStyle += 'font-style:italic;';
|
|
2099
|
+
}
|
|
2100
|
+
if (!isNullOrUndefined(styleObj.characterFormat.fontColor)) {
|
|
2101
|
+
if (styleObj.characterFormat.fontColor === '#00000000') {
|
|
2102
|
+
domStyle += 'color: ' + '#000000' + ';';
|
|
2103
|
+
}
|
|
2104
|
+
else {
|
|
2105
|
+
domStyle += 'color: ' + styleObj.characterFormat.fontColor + ';';
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
if (textDecoration.length > 1) {
|
|
2109
|
+
domStyle += 'text-decoration:' + textDecoration + ';';
|
|
2110
|
+
}
|
|
2111
|
+
return domStyle;
|
|
2112
|
+
};
|
|
2113
|
+
/**
|
|
2114
|
+
* Get next valid element
|
|
2115
|
+
* @private
|
|
2116
|
+
* @param {ElementBox} inline - inline
|
|
2117
|
+
* @returns {ElementBox} ElementBox
|
|
2118
|
+
*/
|
|
2119
|
+
DocxRenderer.prototype.getNextValidElement = function (inline) {
|
|
2120
|
+
var nextValidInline = undefined;
|
|
2121
|
+
if (inline instanceof BookmarkElementBox && inline.bookmarkType === 1) {
|
|
2122
|
+
return inline;
|
|
2123
|
+
}
|
|
2124
|
+
while (inline instanceof FieldElementBox) {
|
|
2125
|
+
if (inline.fieldType === 0 && !isNullOrUndefined(inline.fieldEnd)) {
|
|
2126
|
+
return isNullOrUndefined(nextValidInline) ? inline : nextValidInline;
|
|
2127
|
+
}
|
|
2128
|
+
else if (inline.fieldType === 1 && !isNullOrUndefined(inline.fieldBegin)) {
|
|
2129
|
+
nextValidInline = inline;
|
|
2130
|
+
}
|
|
2131
|
+
inline = inline.nextNode;
|
|
2132
|
+
}
|
|
2133
|
+
return (isNullOrUndefined(nextValidInline) ? inline : nextValidInline);
|
|
2134
|
+
};
|
|
2135
|
+
/**
|
|
2136
|
+
* @private
|
|
2137
|
+
* @param {ElementBox} firstInline - firstInline
|
|
2138
|
+
* @returns {ElementBox} ElementBox
|
|
2139
|
+
*/
|
|
2140
|
+
DocxRenderer.prototype.getNextValidElementForField = function (firstInline) {
|
|
2141
|
+
if (firstInline instanceof FieldElementBox && firstInline.fieldType === 0
|
|
2142
|
+
&& LayoutHelperMethods.isLinkedFieldCharacter(firstInline)) {
|
|
2143
|
+
var fieldBegin = firstInline;
|
|
2144
|
+
if (isNullOrUndefined(fieldBegin.fieldSeparator)) {
|
|
2145
|
+
firstInline = fieldBegin.fieldEnd;
|
|
2146
|
+
}
|
|
2147
|
+
else {
|
|
2148
|
+
firstInline = fieldBegin.fieldSeparator;
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
var nextValidInline = undefined;
|
|
2152
|
+
if (!isNullOrUndefined(firstInline.nextNode)) {
|
|
2153
|
+
nextValidInline = this.getNextValidElement(firstInline.nextNode);
|
|
2154
|
+
}
|
|
2155
|
+
return nextValidInline;
|
|
2156
|
+
};
|
|
2157
|
+
/**
|
|
2158
|
+
* @private
|
|
2159
|
+
* @returns {BodyWidget[]} BodyWidget[]
|
|
2160
|
+
*/
|
|
2161
|
+
DocxRenderer.prototype.combineSection = function () {
|
|
2162
|
+
var sections = [];
|
|
2163
|
+
var nextSection = this.pages[0].bodyWidgets[0];
|
|
2164
|
+
if (this.isSelectionModule) {
|
|
2165
|
+
this.removeEmptyPages(true);
|
|
2166
|
+
}
|
|
2167
|
+
do {
|
|
2168
|
+
nextSection = this.combineSectionChild(nextSection, sections, false);
|
|
2169
|
+
} while (nextSection);
|
|
2170
|
+
for (var j = 0; j < this.pages.length; j++) {
|
|
2171
|
+
this.pages[j].destroy();
|
|
2172
|
+
j--;
|
|
2173
|
+
}
|
|
2174
|
+
return sections;
|
|
2175
|
+
};
|
|
2176
|
+
/**
|
|
2177
|
+
* @private
|
|
2178
|
+
* @param {BodyWidget} bodyWidget - bodyWidget
|
|
2179
|
+
* @param {BodyWidget[]} sections - sections
|
|
2180
|
+
* @param {boolean} destoryPage - destoryPage
|
|
2181
|
+
* @returns {BodyWidget} BodyWidget
|
|
2182
|
+
*/
|
|
2183
|
+
DocxRenderer.prototype.combineSectionChild = function (bodyWidget, sections, destoryPage) {
|
|
2184
|
+
var previousBodyWidget = bodyWidget;
|
|
2185
|
+
var temp = new BodyWidget();
|
|
2186
|
+
var emptyBody = false;
|
|
2187
|
+
temp.sectionFormat = bodyWidget.sectionFormat;
|
|
2188
|
+
temp.index = previousBodyWidget.index;
|
|
2189
|
+
do {
|
|
2190
|
+
emptyBody = false;
|
|
2191
|
+
previousBodyWidget = bodyWidget;
|
|
2192
|
+
if (bodyWidget.lastChild) {
|
|
2193
|
+
bodyWidget.lastChild.combineWidget(this.viewer);
|
|
2194
|
+
if (this.layout.isMultiColumnDoc) {
|
|
2195
|
+
this.removeEmptyPages();
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
bodyWidget = bodyWidget.nextRenderedWidget;
|
|
2199
|
+
for (var j = 0; j < previousBodyWidget.childWidgets.length; j++) {
|
|
2200
|
+
var block = previousBodyWidget.childWidgets[j];
|
|
2201
|
+
if (block instanceof TableWidget) {
|
|
2202
|
+
this.layout.clearTableWidget(block, true, true, true);
|
|
2203
|
+
}
|
|
2204
|
+
else {
|
|
2205
|
+
block.x = 0;
|
|
2206
|
+
block.y = 0;
|
|
2207
|
+
block.width = 0;
|
|
2208
|
+
block.height = 0;
|
|
2209
|
+
}
|
|
2210
|
+
temp.childWidgets.push(block);
|
|
2211
|
+
previousBodyWidget.childWidgets.splice(j, 1);
|
|
2212
|
+
j--;
|
|
2213
|
+
block.containerWidget = temp;
|
|
2214
|
+
}
|
|
2215
|
+
for (var i = 0; i < previousBodyWidget.page.bodyWidgets.length; i++) {
|
|
2216
|
+
if (previousBodyWidget.page.bodyWidgets[i].childWidgets.length === 0) {
|
|
2217
|
+
emptyBody = true;
|
|
2218
|
+
}
|
|
2219
|
+
else {
|
|
2220
|
+
emptyBody = false;
|
|
2221
|
+
break;
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
if (emptyBody && destoryPage) {
|
|
2225
|
+
previousBodyWidget.page.destroy();
|
|
2226
|
+
}
|
|
2227
|
+
// this.pages.splice(previousBodyWidget.page.index, 1);
|
|
2228
|
+
} while (bodyWidget && previousBodyWidget.index === bodyWidget.index);
|
|
2229
|
+
sections.push(temp);
|
|
2230
|
+
return bodyWidget;
|
|
2231
|
+
};
|
|
2232
|
+
/**
|
|
2233
|
+
* @private
|
|
2234
|
+
* @param {Widget} block - block
|
|
2235
|
+
* @returns {boolean} boolean
|
|
2236
|
+
*/
|
|
2237
|
+
DocxRenderer.prototype.isBlockInHeader = function (block) {
|
|
2238
|
+
while (!(block.containerWidget instanceof HeaderFooterWidget)) {
|
|
2239
|
+
if (!block.containerWidget) {
|
|
2240
|
+
return false;
|
|
2241
|
+
}
|
|
2242
|
+
block = block.containerWidget;
|
|
2243
|
+
if (block instanceof TextFrame) {
|
|
2244
|
+
block = block.containerShape.paragraph;
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
return block.containerWidget.headerFooterType.indexOf('Header') !== -1;
|
|
2248
|
+
};
|
|
2249
|
+
return DocxRenderer;
|
|
2250
|
+
}());
|
|
2251
|
+
export { DocxRenderer };
|