DrawRun.java
11.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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.text;
import com.adobe.xfa.font.FontInstance;
import com.adobe.xfa.gfx.GFXDriver;
import com.adobe.xfa.gfx.GFXMappingList;
import com.adobe.xfa.text.ABXY;
import com.adobe.xfa.text.DispLine;
import com.adobe.xfa.text.DispLineWrapped;
import com.adobe.xfa.text.DispMapItem;
import com.adobe.xfa.text.DispPosn;
import com.adobe.xfa.text.DrawAttr;
import com.adobe.xfa.text.DrawParm;
import com.adobe.xfa.text.GlyphLoc;
import com.adobe.xfa.text.MultiMapper;
import com.adobe.xfa.text.RenderInfo;
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.TextMeasurement;
import com.adobe.xfa.text.Units;
import com.adobe.xfa.ut.CoordPair;
import com.adobe.xfa.ut.UniCharIterator;
import com.adobe.xfa.ut.UnitSpan;
class DrawRun {
private final DispLineWrapped mpoLine;
private final DrawParm moParm;
private final DrawAttr moAttr;
private boolean mbAttrChange;
private final DrawAttr.ClipRect moClipRect;
private final StringBuilder msChar = new StringBuilder();
private int mnRunStart;
private int mnRunLength;
private int mnGlyphCount;
private boolean mbGlyphMode;
private boolean mbIsRTL;
private final GFXMappingList moMappingList;
private final int meMappingType;
private float moX;
private float moY;
private float moPrevX;
private float moPrevY;
private boolean mbUnknownWidth;
private float moCharSpacing;
private final boolean mbCharSpacingSupported;
private float moWordSpacing;
private final boolean mbWordSpacingSupported;
private final MultiMapper moMultiple = new MultiMapper();
DrawRun(DispLineWrapped poLine, DrawParm oParm) {
this.mpoLine = poLine;
this.moParm = oParm;
this.moAttr = new DrawAttr(poLine, oParm);
this.mbAttrChange = true;
this.moClipRect = new DrawAttr.ClipRect(oParm);
this.moMappingList = poLine.display().getContext().getMappingList();
this.meMappingType = oParm.driver().getMappingLevel();
this.mbCharSpacingSupported = oParm.driver().charSpacingSupported();
this.mbWordSpacingSupported = oParm.driver().wordSpacingSupported();
if (this.meMappingType == 1) {
this.moMappingList.reset();
}
}
void addGlyph(DrawAttr oCurrentAttr, RenderInfo oRenderInfo, float oX, float oY, boolean bIsRTL) {
boolean bNewGlyphMode;
boolean bl = bNewGlyphMode = oRenderInfo.mcGlyph == 0;
if (bNewGlyphMode != this.mbGlyphMode) {
this.flush();
this.mbGlyphMode = bNewGlyphMode;
}
this.setupRun(oCurrentAttr, oRenderInfo, oX, oY, bIsRTL);
int nRunStart = oRenderInfo.mpoGlyphLoc.getMapIndex();
int nRunLength = oRenderInfo.mpoGlyphLoc.getMapLength();
if (this.mpoLine.hasAXTEMappings()) {
int nAdjustedRunStart = nRunStart;
DispMapItem poPosition = null;
for (int nPosnIndex = 0; nPosnIndex < this.mpoLine.getPositionCount(); ++nPosnIndex) {
DispPosn oPosition = this.mpoLine.getPosition(nPosnIndex);
if (oPosition.getMapIndex() + oPosition.getMapLength() > nRunStart) {
poPosition = oPosition;
break;
}
nAdjustedRunStart += DispLine.getPositionStreamCount(oPosition);
nAdjustedRunStart -= oPosition.getMapLength();
}
assert (poPosition != null);
nRunStart = nAdjustedRunStart;
switch (DispLine.getPositionType((DispPosn)poPosition)) {
case 2: {
assert (poPosition.getMapLength() == 1);
nRunLength = DispLine.getPositionStreamCount((DispPosn)poPosition);
break;
}
case 3: {
nRunStart -= oRenderInfo.mpoGlyphLoc.getMapIndex() - poPosition.getMapIndex();
nRunLength = 1;
}
}
}
if (this.mbGlyphMode) {
int[] oGlyphArray = this.mpoLine.display().getContext().getGlyphArray(this.mnGlyphCount + 1);
oGlyphArray[this.mnGlyphCount] = oRenderInfo.mnGlyphID;
if (this.mnRunLength == 0) {
this.mnRunStart = nRunStart;
this.mnRunLength = nRunLength;
} else {
int nGlyphStart = nRunStart;
int nGlyphMax = nGlyphStart + nRunLength;
int nRunMax = this.mnRunStart + this.mnRunLength;
if (nGlyphStart < this.mnRunStart) {
this.mnRunStart = nGlyphStart;
}
if (nGlyphMax > nRunMax) {
nRunMax = nGlyphMax;
}
this.mnRunLength = nRunMax - this.mnRunStart;
}
this.accumulateMapping(nRunStart, this.mnGlyphCount, nRunLength);
this.updatePosition(oRenderInfo.mpoGlyphLoc, oX, oY, oRenderInfo.mnGlyphID, true);
} else {
this.msChar.append((char)oRenderInfo.mcGlyph);
this.updatePosition(oRenderInfo.mpoGlyphLoc, oX, oY, oRenderInfo.mnGlyphID, false);
this.accumulateMapping(nRunStart, this.mnGlyphCount);
++this.mnRunLength;
}
++this.mnGlyphCount;
}
void flush() {
if (this.mnGlyphCount > 0) {
StringBuilder debugMsg = null;
TextContext context = this.mpoLine.display().getContext();
if (context.debug()) {
debugMsg = new StringBuilder();
}
if (this.mbGlyphMode) {
int[] oGlyphArray = context.getGlyphArray();
if (this.flushCommon(debugMsg)) {
if (debugMsg != null) {
debugMsg.append(" Glyphs:");
for (int i = 0; i < this.mnGlyphCount; ++i) {
debugMsg.append(' ');
debugMsg.append(Integer.toString(oGlyphArray[i]));
}
context.debug(debugMsg.toString());
}
this.moParm.driver().relGlyphs(oGlyphArray, this.mnGlyphCount);
}
} else {
if (this.flushCommon(debugMsg)) {
if (debugMsg != null) {
debugMsg.append(" Chars:");
UniCharIterator iter = new UniCharIterator(this.msChar);
int c = iter.next();
while (c != 0) {
debugMsg.append(' ');
debugMsg.append(Integer.toString(c));
c = iter.next();
}
context.debug(debugMsg.toString());
}
this.moParm.driver().relText(this.msChar.toString());
}
this.msChar.delete(0, this.msChar.length());
}
this.mnRunLength = 0;
this.mnGlyphCount = 0;
}
}
void clear() {
this.moClipRect.detach();
}
void forceAttrChange() {
this.mbAttrChange = true;
}
private void setupRun(DrawAttr oCurrentAttr, RenderInfo oRenderInfo, float oX, float oY, boolean bIsRTL) {
if (!(this.mnGlyphCount <= 0 || this.mbUnknownWidth || this.mpoLine.legacyPositioning() || this.moAttr.getFontOverride() == null && (this.moAttr.getAttr() == null || this.moAttr.getAttr().fontInstance() == null) || oX == this.moPrevX && oY == this.moPrevY || (double)Math.abs(oX - this.moPrevX) <= 0.001 && (double)Math.abs(oY - this.moPrevY) <= 0.001)) {
this.flush();
}
if (this.mnGlyphCount == 0) {
this.moAttr.reset(oCurrentAttr);
this.mnRunStart = oRenderInfo.mpoGlyphLoc.getMapIndex();
this.moX = oX;
this.moY = oY;
this.mbIsRTL = bIsRTL;
this.moCharSpacing = 0.0f;
this.moWordSpacing = 0.0f;
TextAttr poAttr = this.moAttr.getAttr();
if (poAttr != null) {
if (poAttr.charSpacingEnable()) {
this.moCharSpacing = Units.toFloat(poAttr.charSpacing().getLength());
}
if (poAttr.wordSpacingEnable()) {
this.moWordSpacing = Units.toFloat(poAttr.wordSpacing().getLength());
}
}
if (oRenderInfo.mbAttrChange) {
this.mbAttrChange = true;
oRenderInfo.mbAttrChange = false;
}
}
}
private boolean flushCommon(StringBuilder debugMsg) {
boolean attrChange = this.mbAttrChange;
this.mbAttrChange = false;
if (attrChange && !this.moAttr.assertAttrs(this.moClipRect)) {
return false;
}
GFXDriver poDriver = this.moParm.driver();
CoordPair oOffset = new CoordPair(Units.toUnitSpan(this.moX), Units.toUnitSpan(this.moY));
oOffset = ABXY.toXY(this.mpoLine.getXYOrigin(), oOffset, this.mpoLine.frame().getLayoutOrientation());
poDriver.relPosition(oOffset);
if (debugMsg != null) {
debugMsg.append("At Y=");
debugMsg.append(oOffset.y().toString());
debugMsg.append(", X=");
debugMsg.append(oOffset.x().toString());
debugMsg.append(", ");
}
this.flushMultiple();
switch (this.meMappingType) {
case 2: {
poDriver.mapChars(this.mnRunStart, this.mnRunLength);
break;
}
case 1: {
poDriver.mapGlyphs(this.moMappingList, this.mbIsRTL);
this.moMappingList.reset();
}
}
return true;
}
private void updatePosition(GlyphLoc poGlyphLoc, float oX, float oY, int nGlyph, boolean bIsGlyph) {
float oOffset;
boolean bHorizontal;
FontInstance oFontInstance = this.moAttr.getWorkingFont();
this.mbUnknownWidth = true;
this.moPrevX = oX;
this.moPrevY = oY;
if (oFontInstance != null && (oOffset = oFontInstance.getGlyphWidth(nGlyph, bHorizontal = !this.mpoLine.verticalOrientation())) >= 0.0f) {
this.mbUnknownWidth = false;
if (this.mbCharSpacingSupported) {
oOffset += this.moCharSpacing;
}
if (this.mbWordSpacingSupported && this.mpoLine.getBreakClass(poGlyphLoc.getMapIndex()) == 31) {
oOffset += this.moWordSpacing;
}
this.moPrevX += oOffset;
}
}
private void accumulateMapping(int nCharIndex, int nGlyphIndex, int nCharLength) {
if (this.meMappingType != 1) {
return;
}
if (nCharLength != 1) {
this.flushMultiple();
this.moMappingList.addMapping(nCharIndex, nGlyphIndex, nCharLength);
return;
}
if (!this.moMultiple.canAccumulate(nCharIndex, nGlyphIndex)) {
this.flushMultiple();
}
this.moMultiple.accumulate(nCharIndex, nGlyphIndex);
}
private void accumulateMapping(int nCharIndex, int nGlyphIndex) {
this.accumulateMapping(nCharIndex, nGlyphIndex, 1);
}
private void flushMultiple() {
this.moMultiple.flush(this.moMappingList);
}
}