MarkupXHTMLIn.java
59.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.text.markup;
import com.adobe.xfa.font.FontService;
import com.adobe.xfa.gfx.GFXColour;
import com.adobe.xfa.text.TextAttr;
import com.adobe.xfa.text.TextBaselineShift;
import com.adobe.xfa.text.TextField;
import com.adobe.xfa.text.TextGfxSource;
import com.adobe.xfa.text.TextMarkupBase;
import com.adobe.xfa.text.TextMeasurement;
import com.adobe.xfa.text.TextPosn;
import com.adobe.xfa.text.TextResolver;
import com.adobe.xfa.text.TextStream;
import com.adobe.xfa.text.TextTab;
import com.adobe.xfa.text.TextTabList;
import com.adobe.xfa.text.markup.MarkupAttr;
import com.adobe.xfa.text.markup.MarkupEngineIn;
import com.adobe.xfa.text.markup.MarkupXHTMLAttr;
import com.adobe.xfa.text.markup.XMLParserBase;
import com.adobe.xfa.ut.Storage;
import com.adobe.xfa.ut.StringUtils;
import com.adobe.xfa.ut.UniCharIterator;
import com.adobe.xfa.ut.UnitSpan;
import org.xml.sax.Attributes;
public class MarkupXHTMLIn
extends MarkupEngineIn {
static final int SPACE_SUPPRESS_BREAK = 0;
static final int SPACE_SUPPRESS = 1;
static final int SPACE_NORMAL = 2;
static final int SPACE_XML = 3;
static final int SPACE_RUN = 4;
static final int SPACE_FORCED = 5;
private static final int PENDING_DEFAULT = 0;
private static final int PENDING_NONE = 1;
private static final int PENDING_DIV = 2;
private static final int PENDING_SPACE = 3;
private static final int PENDING_BREAK = 4;
private static final String gsXHTMLNS = "http://www.w3.org/1999/xhtml`";
private static final String gsDefaultTypefaceDefault = "Arial";
private static final String gsNewLine = "\n";
private static final String gsAPIVersion = "xfa:APIVersion";
private static final String gsRGBStart = "rgb(";
private static final String gsRGBEnd = ")";
private static final String gsNumeric = "-0123456789.";
private static final int[] gnVersion_1_0_0_0 = new int[]{1, 0, 0, 0};
private static final int[] gnVersion_2_5_6129_0 = new int[]{2, 5, 6129, 0};
private XHTMLParser mpoParser;
private final Stack moStack = new Stack();
private boolean mbVersionDetermined;
private boolean mbTextAccumulated;
private boolean mbParaStarted;
private boolean mbAmbientSupplied;
private int mePending;
private final TextAttr moPendingAttr = new TextAttr();
private final TextAttr moPrevParaAttr = new TextAttr();
private final TextResolver mpoResolver;
private UniCharIterator mIterator;
private LeaderInfo mpoLeaderInfo;
private int mnTabCount;
public MarkupXHTMLIn(String oMarkupSource, MarkupAttr pMarkupAttr, TextAttr poAmbientAttr, TextResolver poResolver) {
super(oMarkupSource, pMarkupAttr == null ? MarkupXHTMLAttr.getDefault() : pMarkupAttr);
this.mpoResolver = poResolver;
this.initialize(poAmbientAttr);
}
void commit() {
if (this.mpoLeaderInfo != null) {
this.mpoLeaderInfo.mpoIn.commitTabs(this.mpoLeaderInfo);
}
}
@Override
public void translate() {
this.mbVersionDetermined = false;
this.moCurrentAttr.setDefault(true);
this.moCurrentAttr.typefaceEnable(false);
this.moCurrentAttr.sizeEnable(false);
if (this.mbAmbientSupplied) {
this.moCurrentAttr.override(this.moAmbientAttr);
}
this.moCurrentAttr.colourBgEnable(false);
this.moCurrentAttr.transparentEnable(false);
if (!this.moCurrentAttr.specialEnable()) {
this.moCurrentAttr.special(TextMeasurement.zero());
}
if (!this.moCurrentAttr.justifyVEnable()) {
this.moCurrentAttr.justifyV(1);
}
if (!this.moCurrentAttr.justifyHEnable()) {
this.moCurrentAttr.justifyH(5);
}
if (!this.moCurrentAttr.tabsEnable()) {
this.moCurrentAttr.tabs(new TextTabList());
}
if (!this.moCurrentAttr.spacingEnable()) {
this.moCurrentAttr.spacing(TextMeasurement.zero());
}
this.attr(this.moCurrentAttr);
this.moAttrList.add(this.moCurrentAttr);
this.moStack.add(new Frame(47, 2));
if (this.mpoParser == null) {
XHTMLParser oParser;
this.mpoParser = oParser = new XHTMLParser(this);
oParser.processText(this.sourceText());
this.mpoParser = null;
this.commit();
}
}
public static void tabDefault(String sAttrValue, TextAttr oAttr, MarkupAttr pMarkupAttr) {
TextTab oTab = MarkupXHTMLIn.extractTab(pMarkupAttr, sAttrValue, 4);
TextTabList oTabList = MarkupXHTMLIn.getTabList(oAttr);
if (oTab.value() <= 0) {
oTabList.noUniform(true);
} else {
oTabList.uniform(oTab);
}
oAttr.tabs(oTabList);
}
public static void tabSet(String sAttrValue, TextAttr oAttr, MarkupAttr pMarkupAttr) {
TextTabList oTabList = MarkupXHTMLIn.getTabList(oAttr);
int nOffset = 0;
int nFoundAt = sAttrValue.indexOf(32);
while (nFoundAt >= nOffset) {
String sAlign = sAttrValue.substring(nOffset, nFoundAt);
nOffset = nFoundAt + 1;
nFoundAt = sAttrValue.indexOf(32, nOffset);
if (nFoundAt < 0) {
nFoundAt = sAttrValue.length();
}
String sValue = sAttrValue.substring(nOffset, nFoundAt);
UnitSpan oValue = new UnitSpan(sValue);
TextTab oTab = new TextTab(oValue, MarkupXHTMLIn.stringToAlign(pMarkupAttr, sAlign));
oTabList.set(oTab);
nOffset = nFoundAt + 1;
nFoundAt = sAttrValue.indexOf(32, nOffset);
}
oAttr.tabs(oTabList);
}
@Override
public String defaultTypeface() {
return "Arial";
}
@Override
public boolean skipThisCommand(int eTag) {
return false;
}
MarkupXHTMLIn onStartTag(String pcName, Attributes attributes) {
String sTagName = pcName;
int nPos = sTagName.indexOf("http://www.w3.org/1999/xhtml`");
if (nPos > 0) {
StringBuilder noNS = new StringBuilder();
noNS.append(pcName, 0, nPos);
noNS.append(pcName, nPos + "http://www.w3.org/1999/xhtml`".length(), pcName.length());
sTagName = noNS.toString();
}
this.mnTabCount = 0;
String sAttr = null;
if (this.inUnknownElement()) {
this.moStack.push(new Frame(0, this.moStack.top().meSpace));
} else {
int eTag = this.markupAttr().lookup(sTagName);
this.moStack.push(new Frame(eTag, this.moStack.top().meSpace));
this.updateSpaceStatus(eTag);
switch (eTag) {
case 22: {
this.onCommand(22, "");
break;
}
case 77: {
this.onCommand(77, "");
break;
}
case 79: {
this.onCommand(79, "");
break;
}
case 46: {
String sVersion;
if (!this.mbVersionDetermined && (sVersion = this.getAttr(attributes, "xfa:APIVersion")) != null) {
this.mbVersionDetermined = true;
int[] nVersion = new int[4];
if (MarkupXHTMLIn.extractHTMLVersion(sVersion, nVersion)) {
if (MarkupXHTMLIn.compareHTMLVersions(nVersion, gnVersion_1_0_0_0) == 0) {
this.switchToFF99Mode();
} else if (MarkupXHTMLIn.compareHTMLVersions(nVersion, gnVersion_2_5_6129_0) >= 0) {
this.setLegacyBlankLineMode(false);
for (int i = 0; i < this.moStack.size(); ++i) {
if (this.moStack.frameAt((int)i).meSpace != 0) continue;
this.moStack.frameAt((int)i).meSpace = 1;
}
}
}
}
this.pushAttr();
this.handleStylingAttributes(attributes, true);
this.onCommand(46, "");
break;
}
case 47: {
this.pushAttr();
this.handleStylingAttributes(attributes, true);
this.onCommand(47, "");
break;
}
case 18:
case 154: {
if (this.legacyBlankLineMode() && eTag == 18 || !this.mbParaStarted) {
if (this.legacyPositioning()) {
this.para();
} else {
this.pushAttr();
this.attr(this.moPrevParaAttr);
this.para();
this.popAttr();
}
}
this.pushAttr();
if (!this.handleStylingAttributes(attributes, eTag == 18)) {
TextAttr oParaAttrs = new TextAttr(this.textAttr());
oParaAttrs.isolatePara(true, this.posn().legacyPositioning());
this.attr(oParaAttrs);
}
this.onCommand(eTag, "");
break;
}
case 113: {
this.onCommand(113, "");
break;
}
case 115: {
this.onCommand(115, "");
break;
}
case 38:
case 40: {
this.flushPendingText(3);
this.openScopedBlock();
this.pushAttr();
if (this.handleStylingAttributes(attributes)) {
if (this.mnTabCount != 0) {
if (this.moCurrentAttr.leaderPatternEnable() && this.moCurrentAttr.leaderPattern() == 3) {
LeaderInfo poLeaderInfo = new LeaderInfo(this);
MarkupXHTMLIn poReturn = new MarkupXHTMLIn(poLeaderInfo);
return poReturn;
}
this.commitTabs(null);
}
} else {
String sExpression = this.getAttr(attributes, 42);
if (sExpression != null) {
this.flushPendingText(3);
int eEmbedType = 0;
int eEmbedMode = 1;
sAttr = this.getAttr(attributes, 44);
if (sAttr != null) {
if (sAttr.equals("uri")) {
eEmbedType = 1;
} else if (sAttr.equals("som")) {
eEmbedType = 0;
}
}
if ((sAttr = this.getAttr(attributes, 43)) != null) {
if (sAttr.equals("raw")) {
eEmbedMode = 0;
} else if (sAttr.equals("formatted")) {
eEmbedMode = 1;
}
}
this.embed(sExpression, eEmbedType, eEmbedMode);
if (!this.legacyBlankLineMode()) {
this.mbParaStarted = false;
}
}
}
this.onCommand(38, "");
break;
}
case 92: {
this.onCommand(92, "");
}
}
}
return null;
}
void onEndTag(String pcTag) {
int eTag = this.moStack.top().meTag;
this.moStack.removeLast();
if (this.moStack.top().meSpace < 2) {
this.moStack.top().meSpace = 2;
}
switch (eTag) {
case 18: {
this.onCommand(19, "");
break;
}
case 154: {
this.onCommand(155, "");
break;
}
case 77: {
this.onCommand(78, "");
break;
}
case 92: {
this.onCommand(90, "");
break;
}
case 79: {
this.onCommand(80, "");
break;
}
case 115: {
this.onCommand(116, "");
break;
}
case 113: {
this.onCommand(114, "");
break;
}
case 46: {
this.onCommand(48, "");
break;
}
case 47: {
this.onCommand(49, "");
break;
}
case 38:
case 40: {
this.onCommand(39, "");
}
}
this.updateSpaceStatus(eTag, true);
}
void onHandleText(String sText) {
if (this.inUnknownElement()) {
return;
}
StringBuilder sAccumulate = new StringBuilder();
int eSpace = this.moStack.top().meSpace;
if (this.mIterator == null) {
this.mIterator = new UniCharIterator();
}
this.mIterator.attach(sText);
int c = this.mIterator.next();
while (c != 0) {
switch (eSpace) {
case 1: {
if (this.legacyBlankLineMode()) {
this.flushPendingText(4);
}
if (MarkupXHTMLIn.isXHTMLSpace(c)) break;
if (!this.legacyBlankLineMode()) {
this.flushPendingText(4);
}
UniCharIterator.append(sAccumulate, c);
eSpace = 2;
this.moStack.top().meSpace = 2;
break;
}
case 0: {
if (!this.legacyBlankLineMode()) break;
this.flushPendingText(4);
if (MarkupXHTMLIn.isXHTMLSpace(c)) break;
UniCharIterator.append(sAccumulate, c);
eSpace = 2;
this.moStack.top().meSpace = 2;
break;
}
case 2: {
if (MarkupXHTMLIn.isXHTMLSpace(c)) {
if (this.mePending == 1) {
this.mePending = 3;
}
} else {
switch (this.mePending) {
case 3: {
sAccumulate.append(' ');
break;
}
case 2: {
if (!this.legacyBlankLineMode() || !this.mbTextAccumulated) break;
sAccumulate.append('\n');
break;
}
case 4: {
sAccumulate.append('\n');
}
}
this.mePending = 1;
UniCharIterator.append(sAccumulate, c);
}
if (this.mePending != 3) break;
this.moPendingAttr.copyFrom(this.textAttr());
break;
}
case 4: {
if (this.legacyBlankLineMode()) {
this.flushPendingText(1);
}
if (c == 160) {
c = 32;
}
if (MarkupXHTMLIn.isXHTMLSpace(c) && c != 32) break;
if (!this.legacyBlankLineMode()) {
this.flushPendingText(1);
}
UniCharIterator.append(sAccumulate, c);
break;
}
case 3: {
this.flushPendingText(1);
UniCharIterator.append(sAccumulate, c);
break;
}
case 5: {
if (this.legacyBlankLineMode() && this.mePending == 2 || this.mePending == 4) {
if (this.mbTextAccumulated || this.mePending == 4) {
sAccumulate.append('\n');
}
this.mePending = 1;
}
if (c == 10) {
this.mePending = 4;
break;
}
UniCharIterator.append(sAccumulate, c);
}
}
c = this.mIterator.next();
}
if (sAccumulate.length() > 0) {
this.text(sAccumulate.toString());
}
}
private MarkupXHTMLIn(LeaderInfo poLeaderInfo) {
super("", poLeaderInfo.mpoIn.markupAttr());
this.mpoParser = poLeaderInfo.mpoIn.mpoParser;
this.mpoResolver = poLeaderInfo.mpoIn.mpoResolver;
this.mpoLeaderInfo = poLeaderInfo;
this.initialize(poLeaderInfo.mpoIn.moCurrentAttr);
this.setup(poLeaderInfo.moPosn, null);
this.moStack.add(new Frame(38, 2));
this.updateSpaceStatus(38);
}
public String getAttr(Attributes attrlist, int eTag) {
return this.getAttr(attrlist, this.markupAttr().lookup(eTag));
}
public String getAttr(Attributes attrlist, String sName) {
if (attrlist == null) {
return null;
}
String result = attrlist.getValue(sName);
if (result != null && result.length() == 0) {
result = null;
}
return result;
}
@Override
public void text(String sText) {
super.text(sText);
this.mbTextAccumulated = true;
this.mbParaStarted = false;
this.moPrevParaAttr.setDefault(false);
}
@Override
protected boolean onCommand(int eTag, String sParameter) {
TextMeasurement oMeasure = null;
boolean bCommandHandled = false;
block0 : switch (eTag) {
case 18:
case 154: {
this.mbTextAccumulated = false;
this.mbParaStarted = true;
break;
}
case 22: {
if (this.legacyBlankLineMode()) {
if (this.moStack.top().meSpace == 0) break;
this.flushPendingText(4);
this.mePending = 4;
this.moPendingAttr.setDefault(false);
this.mbTextAccumulated = false;
break;
}
this.flushPendingText(4);
this.mePending = 4;
this.moPendingAttr.setDefault(false);
this.mbTextAccumulated = false;
this.mbParaStarted = false;
break;
}
case 38:
case 46:
case 47: {
this.mbTextAccumulated = false;
break;
}
case 48:
case 49: {
this.popAttr();
this.mbTextAccumulated = false;
break;
}
case 39: {
if (this.legacyBlankLineMode()) {
this.flushPendingText(4);
}
this.moPrevParaAttr.copyFrom(this.moCurrentAttr);
this.closeScopedBlock();
this.popAttr();
break;
}
case 50: {
switch (this.markupAttr().lookup(sParameter)) {
case 51: {
this.moStack.top().meSpace = 4;
break block0;
}
case 52: {
this.moStack.top().meSpace = this.moStack.frameAt((int)(this.moStack.size() - 2)).meSpace;
}
}
break;
}
case 57: {
oMeasure = TextMeasurement.fromString(sParameter, MarkupXHTMLIn.stringToUnit(this.markupAttr(), sParameter));
this.moCurrentAttr.special(oMeasure);
break;
}
case 58: {
if (sParameter.length() == 0) {
this.flushAttr();
break;
}
oMeasure = TextMeasurement.fromString(sParameter, MarkupXHTMLIn.stringToUnit(this.markupAttr(), sParameter));
this.moCurrentAttr.marginL(oMeasure);
break;
}
case 59: {
oMeasure = TextMeasurement.fromString(sParameter, MarkupXHTMLIn.stringToUnit(this.markupAttr(), sParameter));
this.moCurrentAttr.marginR(oMeasure);
break;
}
case 61: {
oMeasure = TextMeasurement.fromString(sParameter, MarkupXHTMLIn.stringToUnit(this.markupAttr(), sParameter));
this.moCurrentAttr.spaceBefore(oMeasure);
break;
}
case 62: {
oMeasure = TextMeasurement.fromString(sParameter, MarkupXHTMLIn.stringToUnit(this.markupAttr(), sParameter));
this.moCurrentAttr.spaceAfter(oMeasure);
break;
}
case 64: {
StringBuilder sCmd = new StringBuilder(sParameter);
StringUtils.trimStart(sCmd);
int nCount = 0;
int nFoundAt = sCmd.indexOf(" ");
int nOffset = 0;
while (nFoundAt >= 0 && nCount < 4) {
String sSize = sCmd.substring(nOffset, nFoundAt);
oMeasure = TextMeasurement.fromString(sSize, MarkupXHTMLIn.stringToUnit(this.markupAttr(), sSize));
if (++nCount == 1) {
this.moCurrentAttr.marginL(oMeasure);
this.moCurrentAttr.marginR(oMeasure);
this.moCurrentAttr.spaceBefore(oMeasure);
this.moCurrentAttr.spaceAfter(oMeasure);
} else if (nCount == 2) {
this.moCurrentAttr.marginL(oMeasure);
this.moCurrentAttr.marginR(oMeasure);
} else if (nCount == 3) {
this.moCurrentAttr.spaceAfter(oMeasure);
} else if (nCount == 4) {
this.moCurrentAttr.marginL(oMeasure);
}
nOffset = nFoundAt + 1;
nFoundAt = sCmd.indexOf(" ", nOffset);
}
break;
}
case 53: {
oMeasure = TextMeasurement.fromString(sParameter, MarkupXHTMLIn.stringToUnit(this.markupAttr(), sParameter));
this.moCurrentAttr.spacing(oMeasure);
break;
}
case 65: {
this.moCurrentAttr.typeface(sParameter);
break;
}
case 66: {
UnitSpan size = new UnitSpan(sParameter, MarkupXHTMLIn.stringToUnit(this.markupAttr(), sParameter), false);
this.moCurrentAttr.size(size);
break;
}
case 67: {
this.updateWeight(sParameter);
break;
}
case 68: {
this.updateItalic(sParameter);
break;
}
case 69: {
this.updateFont(sParameter);
break;
}
case 72: {
double dScale = TextAttr.parsePercent(sParameter, true);
if (Double.isNaN(dScale)) break;
this.moCurrentAttr.horizontalScale(dScale);
break;
}
case 73: {
double dScale = TextAttr.parsePercent(sParameter, true);
if (Double.isNaN(dScale)) break;
this.moCurrentAttr.verticalScale(dScale);
break;
}
case 75: {
int lR = 0;
int lG = 0;
int lB = 0;
if (sParameter.charAt(0) == '#') {
lR = Integer.parseInt(sParameter.substring(1, 3), 16);
lG = Integer.parseInt(sParameter.substring(3, 5), 16);
lB = Integer.parseInt(sParameter.substring(5, 7), 16);
} else if (sParameter.substring(0, 4).equalsIgnoreCase("rgb(") && sParameter.substring(sParameter.length() - 1).equals(")")) {
int nOffset = 4;
int nFound = sParameter.indexOf(44, nOffset);
lR = Integer.parseInt(sParameter.substring(nOffset, nFound));
nOffset = nFound + 1;
nFound = sParameter.indexOf(44, nOffset);
lG = Integer.parseInt(sParameter.substring(nOffset, nFound));
nOffset = nFound + 1;
nFound = sParameter.indexOf(44, nOffset);
lB = Integer.parseInt(sParameter.substring(nOffset, nFound));
}
GFXColour oColour = new GFXColour(lR, lG, lB, 255);
this.moCurrentAttr.colour(oColour);
break;
}
case 110: {
int eStrikeCode = 1;
if (this.findAttr(sParameter, 81)) {
eStrikeCode = 18;
}
this.moCurrentAttr.strikeout(eStrikeCode);
int nUnderType = 1;
int nUnderCount = 0;
if (this.findAttr(sParameter, 85)) {
nUnderType = 2;
nUnderCount = 16;
}
if (this.findAttr(sParameter, 86)) {
nUnderType = 2;
nUnderCount = 32;
}
if (this.findAttr(sParameter, 87)) {
nUnderType = 3;
if (nUnderCount == 0) {
nUnderCount = 16;
}
}
this.moCurrentAttr.underline(nUnderType | nUnderCount);
break;
}
case 169: {
switch (this.markupAttr().lookup(sParameter)) {
case 4: {
this.moCurrentAttr.kerning(false);
break block0;
}
case 170: {
this.moCurrentAttr.kerning(true);
}
}
break;
}
case 77: {
this.pushAttr();
this.moCurrentAttr.weight(700);
this.flushPendingText(0);
this.attr(this.moCurrentAttr);
break;
}
case 79: {
this.pushAttr();
this.moCurrentAttr.italic(true);
this.flushPendingText(0);
this.attr(this.moCurrentAttr);
break;
}
case 92: {
this.pushAttr();
this.moCurrentAttr.underline(18);
this.flushPendingText(0);
this.attr(this.moCurrentAttr);
break;
}
case 90: {
this.moPrevParaAttr.copyFrom(this.moCurrentAttr);
this.popAttr();
break;
}
case 119: {
switch (this.markupAttr().lookup(sParameter)) {
case 120: {
this.moCurrentAttr.justifyH(8);
break block0;
}
case 121: {
this.moCurrentAttr.justifyH(9);
break block0;
}
case 156: {
this.moCurrentAttr.justifyH(5);
break block0;
}
case 157: {
this.moCurrentAttr.justifyH(6);
break block0;
}
case 158: {
this.moCurrentAttr.justifyH(7);
break block0;
}
case 125: {
this.moCurrentAttr.justifyH(11);
break block0;
}
case 126: {
this.moCurrentAttr.justifyH(12);
break block0;
}
case 127: {
this.moCurrentAttr.justifyH(13);
}
}
break;
}
case 128:
case 132: {
switch (this.markupAttr().lookup(sParameter)) {
case 129: {
this.moCurrentAttr.justifyV(1);
break block0;
}
case 130: {
this.moCurrentAttr.justifyV(2);
break block0;
}
case 131: {
this.moCurrentAttr.justifyV(3);
break block0;
}
}
boolean bSuppressInversion = this.moStack.size() > 0 && this.moStack.frameAt((int)0).meSpace == 5;
TextBaselineShift oShift = new TextBaselineShift(sParameter, bSuppressInversion);
this.moCurrentAttr.baselineShift(oShift);
break;
}
case 113: {
this.pushAttr();
UnitSpan oShift = this.textAttr().size();
oShift = oShift.multiply(-0.31);
if (this.moCurrentAttr.baselineShiftEnable()) {
UnitSpan oBase = new UnitSpan(this.moCurrentAttr.baselineShift().getString(false));
oShift = oShift.add(oBase);
}
this.moCurrentAttr.baselineShift(new TextBaselineShift(oShift));
this.moCurrentAttr.size(this.moCurrentAttr.size().multiply(0.66));
this.flushPendingText(0);
this.attr(this.moCurrentAttr);
break;
}
case 78:
case 80:
case 114:
case 116: {
this.flushPendingText(4);
this.moPrevParaAttr.copyFrom(this.moCurrentAttr);
this.popAttr();
break;
}
case 19:
case 155: {
this.moPrevParaAttr.copyFrom(this.moCurrentAttr);
this.popAttr();
this.mbTextAccumulated = false;
break;
}
case 115: {
this.pushAttr();
UnitSpan oShift = this.moCurrentAttr.size();
oShift = oShift.multiply(0.15);
if (this.moCurrentAttr.baselineShiftEnable()) {
UnitSpan oBase = new UnitSpan(this.moCurrentAttr.baselineShift().getString(false));
oShift = oShift.add(oBase);
}
this.moCurrentAttr.baselineShift(new TextBaselineShift(oShift));
this.moCurrentAttr.size(this.moCurrentAttr.size().multiply(0.66));
this.flushPendingText(0);
this.attr(this.moCurrentAttr);
break;
}
case 137: {
MarkupXHTMLIn.tabDefault(sParameter, this.moCurrentAttr, this.markupAttr());
break;
}
case 136: {
break;
}
case 138: {
MarkupXHTMLIn.tabSet(sParameter, this.moCurrentAttr, this.markupAttr());
break;
}
case 156: {
this.pendingTab(0);
break;
}
case 157: {
this.pendingTab(1);
break;
}
case 158: {
this.pendingTab(2);
break;
}
case 142: {
this.pendingTab(3);
break;
}
case 143: {
int tabs;
Integer count = StringUtils.number(sParameter);
if (count == null || (tabs = count.intValue()) <= 0) break;
this.mnTabCount += tabs;
break;
}
case 159: {
int eParm = this.markupAttr().lookup(sParameter);
int eDigits = 0;
switch (eParm) {
case 161: {
eDigits = 1;
break;
}
case 162: {
eDigits = 2;
}
}
this.moCurrentAttr.digits(eDigits);
break;
}
case 167: {
int eLigature;
int eParm = this.markupAttr().lookup(sParameter);
switch (eParm) {
case 169: {
eLigature = 1;
break;
}
default: {
eLigature = 0;
}
}
this.moCurrentAttr.ligature(eLigature);
break;
}
case 54: {
oMeasure = TextMeasurement.fromString(sParameter, MarkupXHTMLIn.stringToUnit(this.markupAttr(), sParameter));
this.moCurrentAttr.charSpacing(oMeasure);
break;
}
case 55: {
oMeasure = TextMeasurement.fromString(sParameter, MarkupXHTMLIn.stringToUnit(this.markupAttr(), sParameter));
this.moCurrentAttr.wordSpacing(oMeasure);
break;
}
case 171: {
int eParm = this.markupAttr().lookup(sParameter);
if (eParm == 3) {
if (!this.moCurrentAttr.hyphLevelEnable() || this.moCurrentAttr.hyphLevel() != 0) break;
this.moCurrentAttr.hyphLevel(2);
break;
}
this.moCurrentAttr.hyphLevel(0);
break;
}
case 172: {
int eParm = this.markupAttr().lookup(sParameter);
int eLevel = 0;
switch (eParm) {
case 173: {
eLevel = 1;
break;
}
case 5: {
eLevel = 2;
break;
}
case 2: {
eLevel = 3;
}
}
if (eLevel == 0) break;
this.moCurrentAttr.hyphLevel(eLevel);
break;
}
case 174: {
int nValues;
int result;
Integer convert;
String sToken;
StringBuilder sTokens = new StringBuilder(sParameter);
int[] nMin = new int[3];
for (nValues = 0; nValues < 3 && (sToken = StringUtils.parseToken(sTokens)) != null && (convert = StringUtils.number(sToken)) != null && (result = convert.intValue()) >= 0; ++nValues) {
nMin[nValues] = result;
}
if (nValues <= 0) break;
this.moCurrentAttr.hyphMinWord(nMin[0]);
if (nValues <= 1) break;
this.moCurrentAttr.hyphMinPrefix(nMin[1]);
if (nValues <= 2) break;
this.moCurrentAttr.hyphMinSuffix(nMin[2]);
break;
}
case 175: {
boolean bAcronyms = this.markupAttr().lookup(sParameter) == 3;
this.moCurrentAttr.hyphSuppressAcronyms(!bAcronyms);
break;
}
case 176: {
boolean bNames = this.markupAttr().lookup(sParameter) == 3;
this.moCurrentAttr.hyphSuppressNames(!bNames);
break;
}
case 177: {
int eAlign = 0;
if (this.markupAttr().lookup(sParameter) == 178) {
eAlign = 1;
}
this.moCurrentAttr.leaderAlign(eAlign);
break;
}
case 179: {
int ePattern = 0;
switch (this.markupAttr().lookup(sParameter)) {
case 181: {
ePattern = 1;
break;
}
case 182: {
ePattern = 2;
break;
}
case 183:
case 184: {
ePattern = 3;
}
}
this.moCurrentAttr.leaderPattern(ePattern);
break;
}
case 185: {
oMeasure = TextMeasurement.fromString(sParameter);
this.moCurrentAttr.leaderPatternWidth(oMeasure);
break;
}
case 186: {
int eStyle = 1;
switch (this.markupAttr().lookup(sParameter)) {
case 4: {
eStyle = 0;
break;
}
case 187: {
eStyle = 2;
break;
}
case 188: {
eStyle = 3;
}
}
this.moCurrentAttr.ruleStyle(eStyle);
break;
}
case 189: {
oMeasure = TextMeasurement.fromString(sParameter);
this.moCurrentAttr.ruleThickness(oMeasure);
break;
}
default: {
bCommandHandled = false;
}
}
return bCommandHandled;
}
private boolean handleStylingAttributes(Attributes attributes, boolean bIsPara) {
boolean bHasStyle = false;
String sAttr = this.getAttr(attributes, 41);
if (sAttr != null) {
this.parseStyleAttr(sAttr, false);
bHasStyle = true;
}
if ((sAttr = this.getAttr(attributes, 163)) != null) {
int eParm = this.markupAttr().lookup(sAttr);
int eDirection = 0;
switch (eParm) {
case 165: {
eDirection = 1;
break;
}
case 166: {
eDirection = 2;
}
}
if (bIsPara) {
this.moCurrentAttr.paraDirection(eDirection);
} else {
this.moCurrentAttr.direction(eDirection);
}
this.attr(this.moCurrentAttr);
bHasStyle = true;
}
return bHasStyle;
}
private void initialize(TextAttr poAmbientAttr) {
this.mbVersionDetermined = false;
this.mbTextAccumulated = false;
this.mbParaStarted = true;
this.mePending = 1;
this.mnTabCount = 0;
this.mbAmbientSupplied = false;
if (poAmbientAttr != null) {
this.moAmbientAttr = poAmbientAttr;
this.mbAmbientSupplied = true;
}
}
private boolean handleStylingAttributes(Attributes attributes) {
return this.handleStylingAttributes(attributes, false);
}
private void parseStyleAttr(String sAttr, boolean bIsInlineTag) {
boolean BIT_INDENT_LEFT = true;
int BIT_SPACE_BEFORE = 2;
int BIT_INDENT_RIGHT = 4;
int BIT_SPACE_AFTER = 8;
int BIT_INDENT_FIRST_LINE = 16;
int BIT_LINE_HEIGHT = 32;
int BIT_JUSTIFY_VERT = 64;
int BIT_JUSTIFY = 128;
int BIT_TAB_DEFAULT = 256;
int BIT_ALL_PARA = 511;
int nBits = 0;
String sName = null;
int nItalic = -1;
int nWeight = 0;
UnitSpan oSize = null;
StyleInfo info = new StyleInfo(sAttr);
while (this.extractStyleElement(info)) {
String value = info.parameter.toString();
switch (info.commandEnum) {
case 65: {
sName = value;
break;
}
case 67: {
if (this.findAttr(value, 70)) {
nWeight = 700;
break;
}
if (!this.findAttr(value, 5)) break;
nWeight = 400;
break;
}
case 68: {
if (this.findAttr(value, 71)) {
nItalic = 1;
break;
}
if (!this.findAttr(value, 5)) break;
nItalic = 0;
break;
}
case 66: {
oSize = new UnitSpan(value, MarkupXHTMLIn.stringToUnit(this.markupAttr(), value), false);
}
}
}
if (sName != null || nWeight != 0 || nItalic != -1 || oSize != null) {
this.moCurrentAttr.typeface(sName, oSize, nWeight, nItalic);
}
info.offset = 0;
while (this.extractStyleElement(info)) {
if (info.commandEnum != 65 && info.commandEnum != 67 && info.commandEnum != 68 && info.commandEnum != 66) {
this.onCommand(info.commandEnum, info.parameter.toString());
}
switch (info.commandEnum) {
case 58: {
nBits |= 1;
break;
}
case 61: {
nBits |= 2;
break;
}
case 59: {
nBits |= 4;
break;
}
case 62: {
nBits |= 8;
break;
}
case 57: {
nBits |= 16;
break;
}
case 53: {
nBits |= 32;
break;
}
case 132: {
nBits |= 64;
break;
}
case 119: {
nBits |= 128;
break;
}
case 137: {
nBits |= 256;
}
}
}
if (!this.mbVersionDetermined) {
this.mbVersionDetermined = true;
if (nBits == 511) {
this.switchToFF99Mode();
}
}
this.flushPendingText(bIsInlineTag ? 0 : 4);
this.attr(this.moCurrentAttr);
}
private static int stringToUnit(MarkupAttr pMarkupAttr, String sString) {
int lStart = StringUtils.skipOver(sString, "-0123456789.", 0);
String sUnit = sString.substring(lStart);
if (sUnit.equals(pMarkupAttr.lookup(144))) {
return 1;
}
if (sUnit.equals(pMarkupAttr.lookup(145))) {
return 19;
}
if (sUnit.equals(pMarkupAttr.lookup(146))) {
return 3;
}
if (sUnit.equals(pMarkupAttr.lookup(147))) {
return 17;
}
return 255;
}
private static int stringToAlign(MarkupAttr pMarkupAttr, String sString) {
if (sString.equals(pMarkupAttr.lookup(156))) {
return 0;
}
if (sString.equals(pMarkupAttr.lookup(158))) {
return 2;
}
if (sString.equals(pMarkupAttr.lookup(157))) {
return 1;
}
if (sString.equals(pMarkupAttr.lookup(142))) {
return 3;
}
return 0;
}
private void updateWeight(String sString) {
if (this.findAttr(sString, 70)) {
this.moCurrentAttr.weight(700);
} else if (this.findAttr(sString, 5)) {
this.moCurrentAttr.weight(400);
}
}
private void updateItalic(String sString) {
if (this.findAttr(sString, 71)) {
this.moCurrentAttr.italic(true);
} else if (this.findAttr(sString, 5)) {
this.moCurrentAttr.italic(false);
}
}
private void updateFont(String sString) {
this.updateWeight(sString);
this.updateItalic(sString);
int nFoundAt = sString.indexOf(32);
int nOffset = 0;
while (nFoundAt >= nOffset) {
String sCmd = sString.substring(nOffset, nFoundAt);
int eCmd = this.markupAttr().lookup(sCmd);
if (eCmd != 70 && eCmd != 5 && eCmd != 71) {
char c;
char c2 = c = sCmd.length() == 0 ? '\u0000' : sCmd.charAt(0);
if (c >= '0' && c <= '9') {
int nFoundLH = sCmd.indexOf(47);
if (nFoundLH >= 0) {
String sLineHeight = sCmd.substring(nFoundLH + 1);
this.onCommand(53, sLineHeight);
sCmd = sCmd.substring(nFoundLH);
}
this.onCommand(66, sCmd);
} else {
if (c == '\'' || c == '\"') {
nFoundAt = sString.indexOf(c, nFoundAt + 1);
sCmd = sString.substring(nOffset, nFoundAt);
}
this.onCommand(65, sCmd);
}
}
nOffset = nFoundAt + 1;
nFoundAt = sString.indexOf(32, nOffset);
}
}
private boolean findAttr(String sCommand, int eTag) {
return sCommand.contains(this.markupAttr().lookup(eTag));
}
private void embed(String sExpression, int eEmbedType, int eEmbedMode) {
TextField oTextField = new TextField(eEmbedType, eEmbedMode, sExpression);
oTextField.fontService(this.fontService());
if (this.mpoResolver != null) {
this.mpoResolver.embedContent(oTextField);
}
this.field(oTextField);
}
private void switchToFF99Mode() {
for (int i = 0; i < this.moStack.size(); ++i) {
if (this.moStack.frameAt((int)i).meSpace > 2) continue;
this.moStack.frameAt((int)i).meSpace = 5;
}
}
private boolean extractStyleElement(StyleInfo info) {
int nCommandInitialAlloc = 32;
int nParameterInitialAlloc = 128;
if (this.mIterator == null) {
this.mIterator = new UniCharIterator();
}
this.mIterator.attach(info.attrValue, info.offset);
info.commandEnum = 0;
while (info.commandEnum == 0 && this.mIterator.getIndex() < info.attrValue.length()) {
info.command.delete(0, info.command.length());
info.parameter.delete(0, info.parameter.length());
int nAlloc = info.attrValue.length() - info.offset;
if (nAlloc < 32) {
nAlloc = 32;
}
info.command.ensureCapacity(nAlloc);
int cQuote = 0;
int nQuoteStart = 0;
boolean STATE_PRE_COMMAND = false;
boolean STATE_COMMAND = true;
int STATE_POST_COMMAND = 2;
int STATE_PRE_PARAMETER = 3;
int STATE_PARAMETER = 4;
int STATE_DONE = 5;
int eState = 0;
while (this.mIterator.getIndex() < info.attrValue.length() && eState != 5) {
int nPrevOffset = this.mIterator.getIndex();
int c = this.mIterator.next();
if (cQuote != 0) {
if (c != cQuote) continue;
cQuote = 0;
switch (eState) {
case 3:
case 4: {
info.parameter.append(info.attrValue, nQuoteStart, nPrevOffset);
}
}
continue;
}
if (c == 34 || c == 39) {
nQuoteStart = nPrevOffset + 1;
cQuote = c;
continue;
}
block3 : switch (eState) {
case 0: {
switch (c) {
case 32:
case 58:
case 59: {
break block3;
}
}
UniCharIterator.append(info.command, c);
eState = 1;
break;
}
case 1: {
switch (c) {
case 32: {
eState = 2;
break block3;
}
case 59: {
eState = 5;
break block3;
}
case 58: {
eState = 3;
break block3;
}
}
UniCharIterator.append(info.command, c);
break;
}
case 2: {
switch (c) {
case 59: {
eState = 5;
break block3;
}
case 58: {
eState = 3;
}
}
break;
}
case 3: {
switch (c) {
case 59: {
eState = 5;
break block3;
}
case 32: {
break block3;
}
}
nAlloc = info.attrValue.length() - this.mIterator.getIndex();
if (nAlloc < 128) {
nAlloc = 128;
}
info.parameter.ensureCapacity(nAlloc);
UniCharIterator.append(info.parameter, c);
eState = 4;
break;
}
case 4: {
switch (c) {
case 59: {
eState = 5;
break block3;
}
}
UniCharIterator.append(info.parameter, c);
}
}
}
if (eState == 0) continue;
info.command.append(':');
String cmd = info.command.toString();
info.commandEnum = this.markupAttr().lookup(cmd);
int nLength = info.parameter.length();
while (nLength > 0) {
if (MarkupXHTMLIn.isXHTMLSpace(info.parameter.charAt(--nLength))) continue;
++nLength;
break;
}
info.parameter.delete(nLength, info.parameter.length());
}
info.offset = this.mIterator.getIndex();
return info.commandEnum != 0;
}
private boolean inUnknownElement() {
return this.moStack.top().meTag == 0;
}
private static boolean isXHTMLSpace(int c) {
return c == 32 || c == 10 || c == 13 || c == 9 || c == 12;
}
private void updateSpaceStatus(int eTag, boolean bEnd) {
int eSpace = this.moStack.top().meSpace;
if (eTag == 18 || eTag == 46 || eTag == 154 || eTag == 47) {
if (!bEnd || eTag == 46) {
if (eSpace == 2 || eSpace == 1) {
this.moStack.top().meSpace = this.legacyBlankLineMode() ? 0 : 1;
}
this.mePending = 1;
} else if (this.mePending == 3) {
this.flushPendingText(0);
}
} else if (eTag == 22) {
if (eSpace == 2) {
this.moStack.top().meSpace = 1;
}
} else if (eSpace < 2) {
this.moStack.top().meSpace = 2;
}
}
private void updateSpaceStatus(int eTag) {
this.updateSpaceStatus(eTag, false);
}
private void flushPendingText(int ePending) {
if (ePending == 0) {
int n = ePending = this.legacyBlankLineMode() ? 2 : 1;
}
if (this.mePending >= ePending || this.legacyBlankLineMode() && ePending == 1) {
String psText = null;
switch (this.mePending) {
case 2: {
if (!this.legacyBlankLineMode() || !this.mbTextAccumulated) break;
psText = "\n";
break;
}
case 4: {
psText = "\n";
break;
}
case 3: {
if (this.legacyBlankLineMode() && ePending == 1) break;
psText = " ";
}
}
if (psText != null) {
this.pushAttr();
this.attr(this.moPendingAttr);
this.text(psText);
if (this.moStack.top().meSpace == 2) {
this.moStack.top().meSpace = 1;
}
this.popAttr();
this.mePending = 1;
}
}
}
private static boolean extractHTMLVersion(String sVersion, int[] nVersion) {
int nVersionIndex;
if (sVersion.length() == 0) {
return false;
}
for (nVersionIndex = 0; nVersionIndex < 4; ++nVersionIndex) {
nVersion[nVersionIndex] = 0;
}
int nChar = 0;
int nStartChar = 0;
nVersionIndex = 0;
while (nChar < sVersion.length()) {
int nEndChar = nChar;
char c = sVersion.charAt(nChar);
++nChar;
if (c != '.') continue;
if (nEndChar >= nStartChar) {
String sComponent = sVersion.substring(nStartChar, nEndChar);
Integer value = StringUtils.number(sComponent);
if (value == null) {
return false;
}
nVersion[nVersionIndex] = value;
}
if (++nVersionIndex >= 4) {
return true;
}
nStartChar = nChar;
}
return true;
}
private static int compareHTMLVersions(int[] nVersion1, int[] nVersion2) {
for (int i = 0; i < 4; ++i) {
if (nVersion1[i] < nVersion2[i]) {
return -1;
}
if (nVersion1[i] <= nVersion2[i]) continue;
return 1;
}
return 0;
}
private static TextTab extractTab(MarkupAttr markupAttr, String measurement, int tabType) {
UnitSpan oValue = new UnitSpan(measurement, MarkupXHTMLIn.stringToUnit(markupAttr, measurement), false);
return new TextTab(oValue, tabType);
}
private static TextTabList getTabList(TextAttr attr) {
return attr == null || !attr.tabsEnable() ? new TextTabList() : new TextTabList(attr.tabs());
}
private void commitTabs(LeaderInfo poLeaderInfo) {
if (poLeaderInfo != null) {
this.moCurrentAttr.leaderContent(poLeaderInfo.moContent);
this.attr(this.moCurrentAttr);
}
StringBuilder sTabs = new StringBuilder();
sTabs.ensureCapacity(this.mnTabCount);
for (int i = 0; i < this.mnTabCount; ++i) {
sTabs.append('\t');
}
this.text(sTabs.toString());
this.mnTabCount = 0;
this.closeScopedBlock();
this.popAttr();
this.moStack.top().meTag = 0;
}
private static class XHTMLParser
extends XMLParserBase {
private MarkupXHTMLIn mpoCurrent;
private final Storage<StackData> moStack = new Storage();
private int mnDepth;
private int mnPopDepth;
XHTMLParser(MarkupXHTMLIn poXHTMLIn) {
this.mpoCurrent = poXHTMLIn;
this.push(poXHTMLIn);
}
void cleanup() {
while (this.moStack.size() > 0) {
this.pop();
}
}
@Override
public void onStartTag(String name, Attributes attributes) {
++this.mnDepth;
MarkupXHTMLIn poProcessor = this.mpoCurrent.onStartTag(name, attributes);
if (poProcessor != null) {
this.push(poProcessor);
}
}
@Override
public void onEndTag(String name) {
if (this.mnDepth == this.mnPopDepth) {
this.pop();
}
this.mpoCurrent.onEndTag(name);
assert (this.mnDepth > 0);
--this.mnDepth;
}
@Override
public void onContent(String content) {
this.mpoCurrent.onHandleText(content);
}
private void push(MarkupXHTMLIn poProcessor) {
StackData oStackData = new StackData(poProcessor, this.mnDepth);
this.moStack.add(oStackData);
this.mpoCurrent = poProcessor;
this.mnPopDepth = this.mnDepth;
}
private void pop() {
assert (this.moStack.size() > 0);
if (this.mnPopDepth > 0) {
this.mpoCurrent.commit();
}
this.moStack.removeLast();
if (this.moStack.size() > 0) {
StackData oStackData = this.moStack.last();
this.mpoCurrent = oStackData.mpoProcessor;
this.mnPopDepth = oStackData.mnPopDepth;
}
}
private static class StackData {
final MarkupXHTMLIn mpoProcessor;
final int mnPopDepth;
StackData(MarkupXHTMLIn processor, int popDepth) {
this.mpoProcessor = processor;
this.mnPopDepth = popDepth;
}
}
}
private static class StyleInfo {
final String attrValue;
int offset;
int commandEnum;
final StringBuilder command = new StringBuilder();
final StringBuilder parameter = new StringBuilder();
StyleInfo(String attrValue) {
this.attrValue = attrValue;
}
}
private static class LeaderInfo {
final MarkupXHTMLIn mpoIn;
final TextStream moContent;
final TextPosn moPosn;
public LeaderInfo(MarkupXHTMLIn poIn) {
this.mpoIn = poIn;
this.moContent = new TextStream();
this.moPosn = new TextPosn(this.moContent);
}
}
private static class Stack
extends Storage<Frame> {
static final long serialVersionUID = 1010338834063169704L;
Stack() {
}
final Frame frameAt(int index) {
return (Frame)this.get(index);
}
final Frame top() {
return this.frameAt(this.size() - 1);
}
final void push(Frame frame) {
this.add(frame);
}
final void pop() {
this.removeLast();
}
}
private static class Frame {
int meTag;
int meSpace;
Frame() {
this.meTag = 0;
this.meSpace = 2;
}
Frame(int eTag, int eSpace) {
this.meTag = eTag;
this.meSpace = eSpace;
}
}
}