TextSparseStream.java
12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.text;
import com.adobe.xfa.gfx.GFXEnv;
import com.adobe.xfa.text.DispLineWrapped;
import com.adobe.xfa.text.TextAttr;
import com.adobe.xfa.text.TextContext;
import com.adobe.xfa.text.TextDisplay;
import com.adobe.xfa.text.TextFrame;
import com.adobe.xfa.text.TextLayout;
import com.adobe.xfa.text.TextNullFrame;
import com.adobe.xfa.text.TextPosn;
import com.adobe.xfa.text.TextPosnBase;
import com.adobe.xfa.text.TextRange;
import com.adobe.xfa.text.TextStream;
import com.adobe.xfa.ut.Storage;
public abstract class TextSparseStream
extends TextStream {
private final Storage<TextFrame> moFrames = new Storage();
private TextContext mpoContext;
private int meDirection = 0;
private boolean mbLoadingFrame;
public TextSparseStream() {
}
public TextSparseStream(TextSparseStream oSource) {
super(oSource);
this.mpoContext = oSource.mpoContext;
}
public TextSparseStream(String sSource) {
super(sSource);
}
public void setContext(TextContext poContext) {
this.mpoContext = poContext;
}
@Override
public TextContext getContext() {
return this.mpoContext;
}
public void setFrameCount(int nFrames) {
int nOldSize = this.moFrames.size();
if (nFrames < nOldSize) {
this.releaseFrames(nFrames, true);
} else if (nFrames > nOldSize) {
this.updateLastLineFlag(false);
this.moFrames.ensureCapacity(nFrames);
for (int i = nOldSize; i < nFrames; ++i) {
this.moFrames.setSize(i + 1);
this.moFrames.set(i, null);
this.setFrameAt(i, new TextNullFrame());
}
}
}
public int getFrameCount() {
return this.moFrames.size();
}
public TextFrame getFrame(int nIndex) {
return this.getFrame(nIndex, false);
}
public TextFrame insertFrame(int nIndex, TextFrame oFrame, TextLayout poLayout) {
TextFrame poClone = oFrame.cloneFrame();
this.insertFrameRef(nIndex, poClone, poLayout);
return poClone;
}
public void insertFrameRef(int nIndex, TextFrame poFrame, TextLayout poLayout) {
if (nIndex >= this.moFrames.size()) {
this.updateLastLineFlag(false);
}
this.moFrames.add(nIndex, null);
this.setFrameAt(nIndex, poFrame, poLayout);
}
public TextFrame appendFrame(TextFrame oFrame, TextLayout poLayout) {
return this.insertFrame(this.moFrames.size(), oFrame, poLayout);
}
public TextFrame appendFrame(TextFrame oFrame) {
return this.appendFrame(oFrame, null);
}
public void appendFrameRef(TextFrame poFrame, TextLayout poLayout) {
this.insertFrameRef(this.moFrames.size(), poFrame, poLayout);
}
public void appendFrameRef(TextFrame oFrame) {
this.appendFrameRef(oFrame, null);
}
public TextFrame setFrame(int nIndex, TextFrame oFrame, TextLayout poLayout) {
TextFrame poClone = oFrame.cloneFrame();
this.setFrameRef(nIndex, poClone, poLayout);
return poClone;
}
public void setFrameRef(int nIndex, TextFrame poFrame, TextLayout poLayout) {
if (nIndex >= this.moFrames.size()) {
this.setFrameCount(nIndex);
this.moFrames.setSize(nIndex + 1);
this.moFrames.set(nIndex, null);
} else {
this.releaseFrame(nIndex, true, true, poLayout != null);
}
this.setFrameAt(nIndex, poFrame, poLayout);
}
public void removeFrame(int nIndex, boolean bRemoveContent) {
assert (nIndex < this.moFrames.size());
if (bRemoveContent && nIndex > 0 && nIndex + 1 == this.moFrames.size()) {
TextFrame poFrame = this.getFrame(nIndex, true);
TextFrame poPrev = this.getFrame(nIndex - 1);
if (poFrame != null && poPrev != null) {
TextPosn oEnd = poFrame.getStart();
oEnd.tighten(false);
int[] result = oEnd.prevData(1, true);
if (result[0] == 5 || result[1] == 10) {
oEnd.deleteBack(1);
}
}
}
this.releaseFrame(nIndex, true, true, bRemoveContent);
this.moFrames.remove(nIndex);
}
public void removeFrame(int nIndex) {
this.removeFrame(nIndex, false);
}
public int defaultDirection() {
return this.meDirection;
}
public void defaultDirection(int eNewDirection) {
if (eNewDirection == this.defaultDirection()) {
return;
}
this.meDirection = eNewDirection;
if (this.display() != null) {
this.display().update();
}
}
public TextDisplay createDisplay() {
TextDisplay poDisplay = this.display();
if (poDisplay == null) {
poDisplay = new TextDisplay();
poDisplay.connectStream(this);
}
return poDisplay;
}
public abstract TextFrame onLoadFrame(int var1);
public TextFrame onNewFrame() {
return null;
}
public void onRemoveFrame(int nIndex, boolean bForced, boolean bRemoveContent) {
}
public void onFrameRemoved(int nIndex) {
}
TextContext forceContext() {
if (this.mpoContext == null) {
this.mpoContext = new TextContext();
}
return this.mpoContext;
}
TextDisplay forceDisplay(TextAttr poDefaultAttr, GFXEnv poGfxEnv) {
TextDisplay poDisplay = this.display();
if (poDisplay == null) {
poDisplay = new TextDisplay();
}
poDisplay.connectStream(this, false, poDefaultAttr);
return poDisplay;
}
TextFrame getFrame(int nIndex, boolean bShowNullFrames) {
TextFrame poResult = this.moFrames.get(nIndex);
assert (poResult != null);
if (!bShowNullFrames && poResult.isNullFrame() != null) {
return null;
}
return poResult;
}
public TextFrame forceFrame(int nIndex, boolean bReflow) {
TextFrame poFrame = null;
if (nIndex >= this.moFrames.size()) {
while (nIndex >= this.moFrames.size()) {
poFrame = this.onNewFrame();
if (poFrame == null) {
return null;
}
if (bReflow) {
this.appendFrameRef(poFrame);
continue;
}
this.moFrames.add(poFrame);
poFrame.setStream(this);
}
} else {
poFrame = this.getFrame(nIndex, true);
assert (poFrame != null);
if (poFrame.isNullFrame() != null) {
poFrame = this.onLoadFrame(nIndex);
assert (poFrame != null);
}
}
return poFrame;
}
public TextFrame forceFrame(int nIndex) {
return this.forceFrame(nIndex, false);
}
void replaceNullFrame(TextNullFrame poNullFrame) {
int nFrameIndex;
for (nFrameIndex = 0; nFrameIndex < this.moFrames.size() && this.moFrames.get(nFrameIndex) != poNullFrame; ++nFrameIndex) {
}
if (nFrameIndex >= this.moFrames.size()) {
return;
}
this.onLoadFrame(nFrameIndex);
}
void trimFramesOnReflow(int nNewSize) {
if (nNewSize >= this.moFrames.size()) {
return;
}
while (this.moFrames.size() > nNewSize) {
int nLastIndex = this.moFrames.size() - 1;
this.releaseFrame(nLastIndex, true, false);
this.moFrames.setSize(nLastIndex);
}
this.updateLastLineFlag(true);
}
void updateLastLineFlag(boolean bLastLine, int nLastLineIndex) {
if (this.moFrames.size() == 0) {
return;
}
TextFrame poFrame = this.getFrame(this.moFrames.size() - 1);
if (poFrame == null) {
return;
}
int nLines = poFrame.getLineCount();
if (nLines == 0) {
return;
}
int nLineIndex = nLines - 1;
if (nLastLineIndex >= 0 && nLastLineIndex < nLineIndex) {
nLineIndex = nLastLineIndex;
}
DispLineWrapped poLine = poFrame.getLine(nLineIndex);
poLine.setLastLineInStream(bLastLine);
}
void updateLastLineFlag(boolean bLastLine) {
this.updateLastLineFlag(bLastLine, -1);
}
protected void populateFrame(int nFrameIndex, TextLayout poLayout) {
TextPosn oFrameStart = new TextPosn();
this.setFrameStart(nFrameIndex, oFrameStart);
this.loadLayout(nFrameIndex, this.getFrame(nFrameIndex, true), poLayout, oFrameStart);
}
boolean isLoadingFrame() {
return this.mbLoadingFrame;
}
void setLoadingFrame(boolean bLoadingFrame) {
this.mbLoadingFrame = bLoadingFrame;
}
private void releaseFrames(int nStartIndex, boolean bForced) {
for (int i = nStartIndex; i < this.moFrames.size(); ++i) {
this.releaseFrame(i, bForced, bForced, bForced);
}
this.moFrames.setSize(nStartIndex);
}
private void releaseFrame(int nIndex, boolean bInvokeCallback, boolean bForced, boolean bRemoveContent) {
TextFrame poFrame = this.getFrame(nIndex, true);
if (poFrame == null) {
return;
}
TextNullFrame poNullFrame = poFrame.isNullFrame();
if (poNullFrame != null) {
poFrame.getStart().removeNullFrame();
} else {
if (bInvokeCallback) {
this.onRemoveFrame(nIndex, bForced, bRemoveContent);
}
if (bRemoveContent) {
this.removeFrameContent(nIndex);
}
if (bInvokeCallback) {
this.onFrameRemoved(nIndex);
}
}
this.moFrames.set(nIndex, null);
poFrame.setStream(null);
}
private void releaseFrame(int nIndex, boolean bInvokeCallback, boolean bForced) {
this.releaseFrame(nIndex, bInvokeCallback, bForced, false);
}
private void removeFrameContent(int nIndex) {
TextFrame poFrame = this.getFrame(nIndex, true);
if (poFrame == null) {
return;
}
int nNextFrame = nIndex + 1;
int nEnd = nNextFrame >= this.moFrames.size() ? Integer.MAX_VALUE : this.getFrame(nNextFrame, true).getStart().index();
TextRange oRange = new TextRange(this, poFrame.getStart().index(), nEnd);
if (!oRange.isEmpty()) {
oRange.delete();
}
}
private void setFrameAt(int nFrameIndex, TextFrame poFrame, TextLayout poLayout) {
assert (nFrameIndex < this.moFrames.size());
assert (this.moFrames.get(nFrameIndex) == null);
poFrame.setStream(this);
this.moFrames.set(nFrameIndex, poFrame);
TextPosnBase oStart = new TextPosnBase();
this.setFrameStart(nFrameIndex, oStart);
poFrame.setStart(oStart);
TextPosn oEnd = new TextPosn(oStart);
oEnd.position(0);
TextNullFrame poNullFrame = poFrame.isNullFrame();
if (poNullFrame != null) {
oStart.insertNullFrame(poNullFrame);
} else if (poLayout != null) {
this.loadLayout(nFrameIndex, poFrame, poLayout, oEnd);
} else {
oEnd.associate(null);
if (this.display() != null) {
this.display().updateToEnd(poFrame.getStart().stream(), poFrame.getStart().index());
}
}
if (oEnd.stream() != null) {
for (int nNextFrame = nFrameIndex + 1; nNextFrame < this.moFrames.size(); ++nNextFrame) {
TextFrame poNextFrame = this.getFrame(nNextFrame, true);
assert (poNextFrame != null);
if (poNextFrame.getStart() != poFrame.getStart()) break;
poNextFrame.setStart(oEnd);
}
}
}
private void setFrameAt(int nIndex, TextFrame poFrame) {
this.setFrameAt(nIndex, poFrame, null);
}
private void setFrameStart(int nFrameIndex, TextPosnBase oFrameStart) {
int nNextFrame = nFrameIndex + 1;
if (nNextFrame < this.moFrames.size()) {
oFrameStart.copyFrom(this.getFrame(nNextFrame, true).getStart());
} else {
oFrameStart.associate(this, Integer.MAX_VALUE);
}
}
private void loadLayout(int nIndex, TextFrame poFrame, TextLayout poLayout, TextPosn oEnd) {
assert (false);
}
}