LineHeight.java
10 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.text;
import com.adobe.xfa.font.FontInstance;
import com.adobe.xfa.gfx.GFXGlyphOrientation;
import com.adobe.xfa.text.TextAttr;
import com.adobe.xfa.text.TextBaselineShift;
import com.adobe.xfa.text.TextLegacy;
import com.adobe.xfa.text.TextMeasurement;
import com.adobe.xfa.text.Units;
import com.adobe.xfa.ut.UnitSpan;
class LineHeight
extends TextLegacy {
private TextAttr mpoPrevAttr;
private int moAscent;
private int moDescent;
private int moLineGap;
private int moSize;
private int moTextHeight;
private int moOverride;
private int moBefore;
private int moAfter;
private int moFullHeight;
private int moLegacySpacing;
private boolean mbOverrideCancelled;
private boolean mbHasBaselineShift;
private boolean mbBaselineShiftStarted;
LineHeight() {
}
LineHeight(int legacyLevel) {
this.setLegacyLevel(legacyLevel);
}
final int ascent() {
return this.moAscent;
}
final int descent() {
return this.moDescent;
}
final int lineGap() {
return this.moLineGap;
}
final int size() {
return this.moSize;
}
final int textOffset(int eGlyphOrientation) {
int oBottom;
if (this.hasLegacyPositioning()) {
oBottom = this.moOverride == 0 ? this.spacing() : (this.moOverride > this.moTextHeight ? this.moOverride : this.moTextHeight);
oBottom -= this.moDescent;
} else {
oBottom = this.moOverride - this.moLineGap;
if (oBottom < this.moTextHeight) {
oBottom = this.moTextHeight;
}
oBottom = GFXGlyphOrientation.usesHorizontalGlyphs(eGlyphOrientation) ? (oBottom -= this.moDescent) : (oBottom + 1) / 2;
}
return this.moBefore + oBottom;
}
final int spacing() {
return this.moOverride > 0 ? this.moOverride : (this.hasLegacyPositioning() ? this.moLegacySpacing : this.moTextHeight + this.moLineGap);
}
final int override() {
return this.moOverride;
}
final int fullHeight() {
return this.moFullHeight;
}
final int before() {
return this.moBefore;
}
final void before(int oNewBefore) {
this.moBefore = oNewBefore;
}
final int after() {
return this.moAfter;
}
final void after(int oNewAfter) {
this.moAfter = oNewAfter;
}
final boolean hasBaselineShift() {
return this.mbHasBaselineShift;
}
final void accumulateAscent(int oNewAscent) {
if (oNewAscent > this.moAscent) {
this.moAscent = oNewAscent;
}
}
final void accumulateAscent(UnitSpan oNewAscent) {
this.accumulateAscent(Units.toInt(oNewAscent));
}
final void accumulateDescent(int oNewDescent) {
if (oNewDescent > this.moDescent) {
this.moDescent = oNewDescent;
}
}
final void accumulateDescent(UnitSpan oNewDescent) {
this.accumulateDescent(Units.toInt(oNewDescent));
}
final void accumulateLineGap(int oNewLineGap) {
if (oNewLineGap > this.moLineGap) {
this.moLineGap = oNewLineGap;
}
}
final void accumulateLineGap(UnitSpan oNewLineGap) {
this.accumulateLineGap(Units.toInt(oNewLineGap));
}
final void accumulateSize(int oNewSize) {
if (oNewSize > this.moSize) {
this.moSize = oNewSize;
}
}
final void accumulateSize(UnitSpan oNewSize) {
this.accumulateSize(Units.toInt(oNewSize));
}
final void accumulateOverride(int oNewOverride) {
if (oNewOverride > this.moOverride) {
this.moOverride = oNewOverride;
}
}
final void accumulateOverride(UnitSpan oNewOverride) {
this.accumulateOverride(Units.toInt(oNewOverride));
}
final void accumulateLegacySpacing(int oNewLegacySpacing) {
if (oNewLegacySpacing > this.moLegacySpacing) {
this.moLegacySpacing = oNewLegacySpacing;
}
}
final void accumulateLegacySpacing(int oAscent, int oDescent, int oLineGap) {
this.accumulateLegacySpacing(oAscent + oDescent + oLineGap);
}
final void accumulateAfter(int oNewAfter) {
if (oNewAfter > this.moAfter) {
this.moAfter = oNewAfter;
}
}
final void accumulateAfter(UnitSpan oNewAfter) {
this.accumulateAfter(Units.toInt(oNewAfter));
}
final void accumulate(TextAttr poAttr, int eGlyphOrientation, boolean bFirstLineInStream) {
boolean bBaselineShift;
HeightInfo info = this.canProcessAttr(poAttr, true);
if (info == null) {
return;
}
if (GFXGlyphOrientation.usesHorizontalGlyphs(eGlyphOrientation)) {
this.accumulateAscent(info.ascent);
this.accumulateDescent(info.descent);
} else {
this.accumulateSize(info.size);
}
if (!this.hasLegacyPositioning()) {
this.accumulateLineGap(info.lineGap);
} else {
this.accumulateLegacySpacing(info.ascent, info.descent, info.lineGap);
}
boolean bl = bBaselineShift = poAttr.baselineShiftEnable() && !poAttr.baselineShift().isNeutral();
if (bBaselineShift) {
this.mbHasBaselineShift = true;
}
if (poAttr.spacingEnable()) {
boolean bAccumulateOverride = false;
UnitSpan spacing = poAttr.spacing().getLength();
if (!bFirstLineInStream) {
bAccumulateOverride = true;
} else {
int oLineSize = info.size;
if (!this.hasLegacyPositioning()) {
oLineSize += info.lineGap;
}
if (spacing.lt(Units.toUnitSpan(oLineSize))) {
bAccumulateOverride = true;
}
}
if (bAccumulateOverride) {
this.accumulateOverride(spacing);
}
}
}
final void accumulateBaselineShift(TextAttr poAttr) {
HeightInfo info;
if (!this.mbBaselineShiftStarted) {
this.mpoPrevAttr = null;
if (this.moSize <= 0) {
this.moSize = this.moAscent + this.moDescent;
}
this.mbBaselineShiftStarted = true;
}
if ((info = this.canProcessAttr(poAttr, false)) == null) {
return;
}
if (poAttr.baselineShiftEnable() && !poAttr.baselineShift().isNeutral()) {
UnitSpan us = Units.toUnitSpan(info.size);
us = poAttr.baselineShift().applyShift(us, us);
int oNewBaseline = Units.toInt(us);
int oShift = oNewBaseline - info.size;
if (this.hasLegacyPositioning()) {
if (oShift < 0) {
this.accumulateLegacySpacing(info.ascent - oShift, info.descent, info.lineGap);
} else {
this.accumulateAfter(oShift);
}
} else {
this.accumulateAscent(info.ascent - oShift);
this.accumulateDescent(info.descent + oShift);
}
}
}
final void reconcile() {
this.moTextHeight = this.moAscent <= 0 && this.moDescent <= 0 ? this.moSize : this.moAscent + this.moDescent;
if (this.hasLegacyPositioning() && this.moLegacySpacing < this.moTextHeight) {
this.moLegacySpacing = this.moTextHeight;
}
if (this.mbOverrideCancelled) {
this.moOverride = 0;
}
this.moFullHeight = this.moBefore + this.spacing() + this.moAfter;
}
final boolean adjustLineSpacing(UnitSpan oTop) {
if (this.hasLegacyPositioning() || this.moOverride > 0 || oTop.value() >= 0) {
return false;
}
int oDelta = Units.toInt(oTop);
this.moAscent -= oDelta;
this.moTextHeight -= oDelta;
this.moFullHeight -= oDelta;
return true;
}
final void reset() {
this.moAscent = 0;
this.moDescent = 0;
this.moLineGap = 0;
this.moTextHeight = 0;
this.moSize = 0;
this.moOverride = 0;
this.moBefore = 0;
this.moAfter = 0;
this.moLegacySpacing = 0;
this.mbOverrideCancelled = false;
this.mbHasBaselineShift = false;
this.mbBaselineShiftStarted = false;
this.detach();
}
final void cancelOverride() {
this.mbOverrideCancelled = true;
}
final void detach() {
this.mpoPrevAttr = null;
}
private HeightInfo canProcessAttr(TextAttr poAttr, boolean bAccumulateSize) {
int lineGap;
int size;
int ascent;
int descent;
if (poAttr == null || poAttr == this.mpoPrevAttr) {
return null;
}
this.mpoPrevAttr = poAttr;
FontInstance poFontInstance = poAttr.fontInstance();
if (poFontInstance == null) {
return null;
}
if (this.hasLegacyPositioning()) {
ascent = Units.toInt(poFontInstance.getLegacyAscent());
descent = Units.toInt(poFontInstance.getSize()) - ascent;
lineGap = Units.toInt(poFontInstance.getLegacyLineGap());
} else {
ascent = Units.toInt(poFontInstance.getAscent());
descent = Units.toInt(poFontInstance.getDescent());
lineGap = Units.toInt(poFontInstance.getLineGap());
}
if (poAttr.sizeEnable()) {
size = Units.toInt(poAttr.size());
if (bAccumulateSize) {
this.accumulateSize(poAttr.size());
}
} else {
size = ascent + descent;
}
return new HeightInfo(ascent, descent, size, lineGap);
}
private static class HeightInfo {
final int ascent;
final int descent;
final int size;
final int lineGap;
public HeightInfo(int ascent, int descent, int size, int lineGap) {
this.ascent = ascent;
this.descent = descent;
this.size = size;
this.lineGap = lineGap;
}
}
}