@@ -156,11 +156,6 @@ public class PdfCanvas {
156
156
*/
157
157
protected List <Integer > layerDepth ;
158
158
159
- /**
160
- * Used to identify if gState has changed since last pdf/a check.
161
- */
162
- private int gStateIndex = 0 ;
163
-
164
159
/**
165
160
* Creates PdfCanvas from content stream of page, form XObject, pattern etc.
166
161
*
@@ -299,7 +294,6 @@ public PdfCanvas saveState() {
299
294
* @return current canvas.
300
295
*/
301
296
public PdfCanvas restoreState () {
302
- ++gStateIndex ;
303
297
document .checkIsoConformance ('Q' , IsoKey .CANVAS_STACK );
304
298
currentGs = gsStack .pop ();
305
299
contentStream .getOutputStream ().writeBytes (Q );
@@ -389,7 +383,6 @@ public PdfCanvas endVariableText() {
389
383
* @return current canvas.
390
384
*/
391
385
public PdfCanvas setFontAndSize (PdfFont font , float size ) {
392
- ++gStateIndex ;
393
386
if (size < 0.0001f && size > -0.0001f )
394
387
throw new PdfException (PdfException .FontSizeTooSmall , size );
395
388
currentGs .setFontSize (size );
@@ -430,7 +423,6 @@ public PdfCanvas moveText(float x, float y) {
430
423
* @return current canvas.
431
424
*/
432
425
public PdfCanvas setLeading (final float leading ) {
433
- ++gStateIndex ;
434
426
currentGs .setLeading (leading );
435
427
contentStream .getOutputStream ()
436
428
.writeFloat (leading )
@@ -450,7 +442,6 @@ public PdfCanvas setLeading(final float leading) {
450
442
* @return current canvas.
451
443
*/
452
444
public PdfCanvas moveTextWithLeading (final float x , final float y ) {
453
- ++gStateIndex ;
454
445
currentGs .setLeading (-y );
455
446
contentStream .getOutputStream ()
456
447
.writeFloat (x )
@@ -479,7 +470,7 @@ public PdfCanvas newlineText() {
479
470
* @return current canvas.
480
471
*/
481
472
public PdfCanvas newlineShowText (final String text ) {
482
- document .checkShowTextIsoConformance (currentGs , resources , gStateIndex );
473
+ document .checkShowTextIsoConformance (currentGs , resources );
483
474
showTextInt (text );
484
475
contentStream .getOutputStream ()
485
476
.writeByte ((byte ) '\'' )
@@ -496,7 +487,7 @@ public PdfCanvas newlineShowText(final String text) {
496
487
* @return current canvas.
497
488
*/
498
489
public PdfCanvas newlineShowText (final float wordSpacing , final float charSpacing , final String text ) {
499
- document .checkShowTextIsoConformance (currentGs , resources , gStateIndex );
490
+ document .checkShowTextIsoConformance (currentGs , resources );
500
491
contentStream .getOutputStream ()
501
492
.writeFloat (wordSpacing )
502
493
.writeSpace ()
@@ -509,7 +500,6 @@ public PdfCanvas newlineShowText(final float wordSpacing, final float charSpacin
509
500
// (cfr PDF reference v1.6, table 5.6)
510
501
currentGs .setCharSpacing (charSpacing );
511
502
currentGs .setWordSpacing (wordSpacing );
512
- ++gStateIndex ;
513
503
return this ;
514
504
}
515
505
@@ -520,7 +510,6 @@ public PdfCanvas newlineShowText(final float wordSpacing, final float charSpacin
520
510
* @return current canvas.
521
511
*/
522
512
public PdfCanvas setTextRenderingMode (int textRenderingMode ) {
523
- ++gStateIndex ;
524
513
currentGs .setTextRenderingMode (textRenderingMode );
525
514
contentStream .getOutputStream ()
526
515
.writeInteger (textRenderingMode ).writeSpace ()
@@ -537,7 +526,6 @@ public PdfCanvas setTextRenderingMode(int textRenderingMode) {
537
526
* @return current canvas.
538
527
*/
539
528
public PdfCanvas setTextRise (float textRise ) {
540
- ++gStateIndex ;
541
529
currentGs .setTextRise (textRise );
542
530
contentStream .getOutputStream ()
543
531
.writeFloat (textRise ).writeSpace ()
@@ -552,7 +540,6 @@ public PdfCanvas setTextRise(float textRise) {
552
540
* @return current canvas.
553
541
*/
554
542
public PdfCanvas setWordSpacing (float wordSpacing ) {
555
- ++gStateIndex ;
556
543
currentGs .setWordSpacing (wordSpacing );
557
544
contentStream .getOutputStream ()
558
545
.writeFloat (wordSpacing ).writeSpace ()
@@ -567,7 +554,6 @@ public PdfCanvas setWordSpacing(float wordSpacing) {
567
554
* @return current canvas.
568
555
*/
569
556
public PdfCanvas setCharacterSpacing (float charSpacing ) {
570
- ++gStateIndex ;
571
557
currentGs .setCharSpacing (charSpacing );
572
558
contentStream .getOutputStream ()
573
559
.writeFloat (charSpacing ).writeSpace ()
@@ -582,7 +568,6 @@ public PdfCanvas setCharacterSpacing(float charSpacing) {
582
568
* @return current canvas.
583
569
*/
584
570
public PdfCanvas setHorizontalScaling (float scale ) {
585
- ++gStateIndex ;
586
571
currentGs .setHorizontalScaling (scale );
587
572
contentStream .getOutputStream ()
588
573
.writeFloat (scale )
@@ -637,7 +622,7 @@ public PdfCanvas setTextMatrix(float x, float y) {
637
622
* @return current canvas.
638
623
*/
639
624
public PdfCanvas showText (String text ) {
640
- document .checkShowTextIsoConformance (currentGs , resources , gStateIndex );
625
+ document .checkShowTextIsoConformance (currentGs , resources );
641
626
showTextInt (text );
642
627
contentStream .getOutputStream ().writeBytes (Tj );
643
628
return this ;
@@ -650,7 +635,7 @@ public PdfCanvas showText(String text) {
650
635
* @return current canvas.
651
636
*/
652
637
public PdfCanvas showText (GlyphLine text ) {
653
- document .checkShowTextIsoConformance (currentGs , resources , gStateIndex );
638
+ document .checkShowTextIsoConformance (currentGs , resources );
654
639
PdfFont font ;
655
640
if ((font = currentGs .getFont ()) == null ) {
656
641
throw new PdfException (PdfException .FontAndSizeMustBeSetBeforeWritingAnyText , currentGs );
@@ -758,7 +743,7 @@ private float getSubrangeWidth(GlyphLine text, int from, int to) {
758
743
public PdfCanvas showText (PdfArray textArray ) {
759
744
if (currentGs .getFont () == null )
760
745
throw new PdfException (PdfException .FontAndSizeMustBeSetBeforeWritingAnyText , currentGs );
761
- document .checkShowTextIsoConformance (currentGs , resources , gStateIndex );
746
+ document .checkShowTextIsoConformance (currentGs , resources );
762
747
contentStream .getOutputStream ().writeBytes (PdfOutputStream .getIsoBytes ("[" ));
763
748
for (PdfObject obj : textArray ) {
764
749
if (obj .isString ()) {
@@ -1117,7 +1102,7 @@ public PdfCanvas closePath() {
1117
1102
* @return current canvas.
1118
1103
*/
1119
1104
public PdfCanvas closePathEoFillStroke () {
1120
- document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL_STROKE , resources , gStateIndex );
1105
+ document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL_STROKE , resources );
1121
1106
contentStream .getOutputStream ().writeBytes (bStar );
1122
1107
return this ;
1123
1108
}
@@ -1128,7 +1113,7 @@ public PdfCanvas closePathEoFillStroke() {
1128
1113
* @return current canvas.
1129
1114
*/
1130
1115
public PdfCanvas closePathFillStroke () {
1131
- document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL_STROKE , resources , gStateIndex );
1116
+ document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL_STROKE , resources );
1132
1117
contentStream .getOutputStream ().writeBytes (b );
1133
1118
return this ;
1134
1119
}
@@ -1149,7 +1134,7 @@ public PdfCanvas newPath() {
1149
1134
* @return current canvas.
1150
1135
*/
1151
1136
public PdfCanvas stroke () {
1152
- document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_STROKE , resources , gStateIndex );
1137
+ document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_STROKE , resources );
1153
1138
contentStream .getOutputStream ().writeBytes (S );
1154
1139
return this ;
1155
1140
}
@@ -1192,7 +1177,7 @@ public PdfCanvas closePathStroke() {
1192
1177
* @return current canvas.
1193
1178
*/
1194
1179
public PdfCanvas fill () {
1195
- document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL , resources , gStateIndex );
1180
+ document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL , resources );
1196
1181
contentStream .getOutputStream ().writeBytes (f );
1197
1182
return this ;
1198
1183
}
@@ -1203,7 +1188,7 @@ public PdfCanvas fill() {
1203
1188
* @return current canvas.
1204
1189
*/
1205
1190
public PdfCanvas fillStroke () {
1206
- document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL_STROKE , resources , gStateIndex );
1191
+ document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL_STROKE , resources );
1207
1192
contentStream .getOutputStream ().writeBytes (B );
1208
1193
return this ;
1209
1194
}
@@ -1214,7 +1199,7 @@ public PdfCanvas fillStroke() {
1214
1199
* @return current canvas.
1215
1200
*/
1216
1201
public PdfCanvas eoFill () {
1217
- document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL , resources , gStateIndex );
1202
+ document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL , resources );
1218
1203
contentStream .getOutputStream ().writeBytes (fStar );
1219
1204
return this ;
1220
1205
}
@@ -1225,7 +1210,7 @@ public PdfCanvas eoFill() {
1225
1210
* @return current canvas.
1226
1211
*/
1227
1212
public PdfCanvas eoFillStroke () {
1228
- document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL_STROKE , resources , gStateIndex );
1213
+ document .checkIsoConformance (currentGs , IsoKey .DRAWMODE_FILL_STROKE , resources );
1229
1214
contentStream .getOutputStream ().writeBytes (BStar );
1230
1215
return this ;
1231
1216
}
@@ -1240,7 +1225,6 @@ public PdfCanvas setLineWidth(float lineWidth) {
1240
1225
if (currentGs .getLineWidth () == lineWidth ) {
1241
1226
return this ;
1242
1227
}
1243
- ++gStateIndex ;
1244
1228
currentGs .setLineWidth (lineWidth );
1245
1229
contentStream .getOutputStream ()
1246
1230
.writeFloat (lineWidth ).writeSpace ()
@@ -1259,7 +1243,6 @@ public PdfCanvas setLineWidth(float lineWidth) {
1259
1243
public PdfCanvas setLineCapStyle (int lineCapStyle ) {
1260
1244
if (currentGs .getLineCapStyle () == lineCapStyle )
1261
1245
return this ;
1262
- ++gStateIndex ;
1263
1246
currentGs .setLineCapStyle (lineCapStyle );
1264
1247
contentStream .getOutputStream ()
1265
1248
.writeInteger (lineCapStyle ).writeSpace ()
@@ -1278,7 +1261,6 @@ public PdfCanvas setLineCapStyle(int lineCapStyle) {
1278
1261
public PdfCanvas setLineJoinStyle (int lineJoinStyle ) {
1279
1262
if (currentGs .getLineJoinStyle () == lineJoinStyle )
1280
1263
return this ;
1281
- ++gStateIndex ;
1282
1264
currentGs .setLineJoinStyle (lineJoinStyle );
1283
1265
contentStream .getOutputStream ()
1284
1266
.writeInteger (lineJoinStyle ).writeSpace ()
@@ -1296,7 +1278,6 @@ public PdfCanvas setLineJoinStyle(int lineJoinStyle) {
1296
1278
public PdfCanvas setMiterLimit (float miterLimit ) {
1297
1279
if (currentGs .getMiterLimit () == miterLimit )
1298
1280
return this ;
1299
- ++gStateIndex ;
1300
1281
currentGs .setMiterLimit (miterLimit );
1301
1282
contentStream .getOutputStream ()
1302
1283
.writeFloat (miterLimit ).writeSpace ()
@@ -1316,7 +1297,6 @@ public PdfCanvas setMiterLimit(float miterLimit) {
1316
1297
* @return current canvas.
1317
1298
*/
1318
1299
public PdfCanvas setLineDash (final float phase ) {
1319
- ++gStateIndex ;
1320
1300
currentGs .setDashPattern (getDashPatternArray (phase ));
1321
1301
contentStream .getOutputStream ().writeByte ((byte ) '[' ).writeByte ((byte ) ']' ).writeSpace ()
1322
1302
.writeFloat (phase ).writeSpace ()
@@ -1337,7 +1317,6 @@ public PdfCanvas setLineDash(final float phase) {
1337
1317
* @return current canvas.
1338
1318
*/
1339
1319
public PdfCanvas setLineDash (final float unitsOn , final float phase ) {
1340
- ++gStateIndex ;
1341
1320
currentGs .setDashPattern (getDashPatternArray (new float []{unitsOn }, phase ));
1342
1321
contentStream .getOutputStream ().writeByte ((byte ) '[' ).writeFloat (unitsOn ).writeByte ((byte ) ']' ).writeSpace ()
1343
1322
.writeFloat (phase ).writeSpace ()
@@ -1360,7 +1339,6 @@ public PdfCanvas setLineDash(final float unitsOn, final float phase) {
1360
1339
* @return current canvas.
1361
1340
*/
1362
1341
public PdfCanvas setLineDash (final float unitsOn , final float unitsOff , final float phase ) {
1363
- ++gStateIndex ;
1364
1342
currentGs .setDashPattern (getDashPatternArray (new float []{unitsOn , unitsOff }, phase ));
1365
1343
contentStream .getOutputStream ().writeByte ((byte ) '[' ).writeFloat (unitsOn ).writeSpace ()
1366
1344
.writeFloat (unitsOff ).writeByte ((byte ) ']' ).writeSpace ()
@@ -1382,7 +1360,6 @@ public PdfCanvas setLineDash(final float unitsOn, final float unitsOff, final fl
1382
1360
* @return current canvas.
1383
1361
*/
1384
1362
public final PdfCanvas setLineDash (final float [] array , final float phase ) {
1385
- ++gStateIndex ;
1386
1363
currentGs .setDashPattern (getDashPatternArray (array , phase ));
1387
1364
PdfOutputStream out = contentStream .getOutputStream ();
1388
1365
out .writeByte ((byte ) '[' );
@@ -1406,7 +1383,6 @@ public PdfCanvas setRenderingIntent(PdfName renderingIntent) {
1406
1383
document .checkIsoConformance (renderingIntent , IsoKey .RENDERING_INTENT );
1407
1384
if (renderingIntent .equals (currentGs .getRenderingIntent ()))
1408
1385
return this ;
1409
- ++gStateIndex ;
1410
1386
currentGs .setRenderingIntent (renderingIntent );
1411
1387
contentStream .getOutputStream ()
1412
1388
.write (renderingIntent ).writeSpace ()
@@ -1426,7 +1402,6 @@ public PdfCanvas setRenderingIntent(PdfName renderingIntent) {
1426
1402
public PdfCanvas setFlatnessTolerance (float flatnessTolerance ) {
1427
1403
if (currentGs .getFlatnessTolerance () == flatnessTolerance )
1428
1404
return this ;
1429
- ++gStateIndex ;
1430
1405
currentGs .setFlatnessTolerance (flatnessTolerance );
1431
1406
contentStream .getOutputStream ()
1432
1407
.writeFloat (flatnessTolerance ).writeSpace ()
@@ -1753,7 +1728,7 @@ public PdfXObject addImage(Image image, float a, float b, float c, float d, floa
1753
1728
* @return created Image XObject or null in case of in-line image (asInline = true).
1754
1729
*/
1755
1730
public PdfXObject addImage (Image image , float a , float b , float c , float d , float e , float f , boolean asInline ) {
1756
- document .checkIsoConformance (currentGs , IsoKey .GRAPHIC_STATE_ONLY , null , gStateIndex );
1731
+ document .checkIsoConformance (currentGs , IsoKey .GRAPHIC_STATE_ONLY , null );
1757
1732
if (image .getOriginalType () == Image .WMF ) {
1758
1733
WmfImageHelper wmf = new WmfImageHelper (image );
1759
1734
// TODO add matrix parameters
@@ -1968,7 +1943,6 @@ public PdfCanvas addXObject(PdfXObject xObject, float x, float y, float height,
1968
1943
* @return current canvas.
1969
1944
*/
1970
1945
public PdfCanvas setExtGState (PdfExtGState extGState ) {
1971
- ++gStateIndex ;
1972
1946
if (!extGState .isFlushed ())
1973
1947
currentGs .updateFromExtGState (extGState );
1974
1948
PdfName name = resources .addExtGState (extGState );
@@ -2126,7 +2100,7 @@ public PdfStream getContentStream() {
2126
2100
* @on error
2127
2101
*/
2128
2102
protected void addInlineImage (PdfImageXObject imageXObject , float a , float b , float c , float d , float e , float f ) {
2129
- document .checkIsoConformance (imageXObject .getPdfObject (), IsoKey .INLINE_IMAGE , resources , gStateIndex );
2103
+ document .checkIsoConformance (imageXObject .getPdfObject (), IsoKey .INLINE_IMAGE , resources );
2130
2104
saveState ();
2131
2105
concatMatrix (a , b , c , d , e , f );
2132
2106
PdfOutputStream os = contentStream .getOutputStream ();
@@ -2315,7 +2289,6 @@ private PdfCanvas addImage(PdfImageXObject image, float x, float y, float height
2315
2289
}
2316
2290
2317
2291
private void updateGStateColorFields (boolean fill , Color newColor ) {
2318
- ++gStateIndex ;
2319
2292
if (fill ) {
2320
2293
currentGs .setFillColor (newColor );
2321
2294
PdfObject colorSpaceObject = newColor .getColorSpace ().getPdfObject ();
0 commit comments