@@ -76,6 +76,7 @@ This file is part of the iText (R) project.
76
76
import com .itextpdf .kernel .pdf .PdfString ;
77
77
import com .itextpdf .kernel .pdf .canvas .CanvasTag ;
78
78
import com .itextpdf .kernel .pdf .canvas .PdfCanvasConstants ;
79
+ import com .itextpdf .kernel .pdf .canvas .parser .data .AbstractRenderInfo ;
79
80
import com .itextpdf .kernel .pdf .canvas .parser .data .ClippingPathInfo ;
80
81
import com .itextpdf .kernel .pdf .canvas .parser .data .IEventData ;
81
82
import com .itextpdf .kernel .pdf .canvas .parser .data .ImageRenderInfo ;
@@ -297,7 +298,7 @@ public void processContent(byte[] contentBytes, PdfResources resources) {
297
298
public void processPageContent (PdfPage page ) {
298
299
initClippingPath (page );
299
300
ParserGraphicsState gs = getGraphicsState ();
300
- eventOccurred (new ClippingPathInfo (gs .getClippingPath (), gs .getCtm ()), EventType .CLIP_PATH_CHANGED );
301
+ eventOccurred (new ClippingPathInfo (gs , gs .getClippingPath (), gs .getCtm ()), EventType .CLIP_PATH_CHANGED );
301
302
processContent (page .getContentBytes (), page .getResources ());
302
303
}
303
304
@@ -425,14 +426,14 @@ protected void populateOperators() {
425
426
* In case it isn't applicable pass any <CODE>byte</CODE> value.
426
427
*/
427
428
protected void paintPath (int operation , int rule ) {
428
- PathRenderInfo renderInfo = new PathRenderInfo (currentPath , operation , rule , isClip , clippingRule , getGraphicsState ());
429
+ ParserGraphicsState gs = getGraphicsState ();
430
+ PathRenderInfo renderInfo = new PathRenderInfo (this .markedContentStack , gs , currentPath , operation , rule , isClip , clippingRule );
429
431
eventOccurred (renderInfo , EventType .RENDER_PATH );
430
432
431
433
if (isClip ) {
432
434
isClip = false ;
433
- ParserGraphicsState gs = getGraphicsState ();
434
435
gs .clip (currentPath , clippingRule );
435
- eventOccurred (new ClippingPathInfo (gs .getClippingPath (), gs .getCtm ()), EventType .CLIP_PATH_CHANGED );
436
+ eventOccurred (new ClippingPathInfo (gs , gs .getClippingPath (), gs .getCtm ()), EventType .CLIP_PATH_CHANGED );
436
437
}
437
438
438
439
currentPath = new Path ();
@@ -532,10 +533,8 @@ protected void eventOccurred(IEventData data, EventType type) {
532
533
if (supportedEvents == null || supportedEvents .contains (type )) {
533
534
eventListener .eventOccurred (data , type );
534
535
}
535
- if (data instanceof TextRenderInfo ) {
536
- ((TextRenderInfo ) data ).releaseGraphicsState ();
537
- } else if (data instanceof PathRenderInfo ) {
538
- ((PathRenderInfo ) data ).releaseGraphicsState ();
536
+ if (data instanceof AbstractRenderInfo ) {
537
+ ((AbstractRenderInfo ) data ).releaseGraphicsState ();
539
538
}
540
539
}
541
540
@@ -553,23 +552,24 @@ private void displayPdfString(PdfString string) {
553
552
/**
554
553
* Displays an XObject using the registered handler for this XObject's subtype
555
554
*
556
- * @param xobjectName the name of the XObject to retrieve from the resource dictionary
555
+ * @param resourceName the name of the XObject to retrieve from the resource dictionary
557
556
*/
558
- private void displayXObject (PdfName xobjectName ) {
559
- PdfStream xobjectStream = getXObjectStream (xobjectName );
557
+ private void displayXObject (PdfName resourceName ) {
558
+ PdfStream xobjectStream = getXObjectStream (resourceName );
560
559
PdfName subType = xobjectStream .getAsName (PdfName .Subtype );
561
560
IXObjectDoHandler handler = xobjectDoHandlers .get (subType );
562
561
563
562
if (handler == null ) {
564
563
handler = xobjectDoHandlers .get (PdfName .Default );
565
564
}
566
565
567
- handler .handleXObject (this , xobjectStream );
566
+ handler .handleXObject (this , this . markedContentStack , xobjectStream , resourceName );
568
567
}
569
568
570
- private void displayImage (PdfStream imageStream , boolean isInline ) {
569
+ private void displayImage (Stack < CanvasTag > canvasTagHierarchy , PdfStream imageStream , PdfName resourceName , boolean isInline ) {
571
570
PdfDictionary colorSpaceDic = getResources ().getResource (PdfName .ColorSpace );
572
- ImageRenderInfo renderInfo = new ImageRenderInfo (getGraphicsState ().getCtm (), imageStream , colorSpaceDic , isInline );
571
+ ImageRenderInfo renderInfo = new ImageRenderInfo (canvasTagHierarchy , getGraphicsState (), getGraphicsState ().getCtm (),
572
+ imageStream , resourceName , colorSpaceDic , isInline );
573
573
eventOccurred (renderInfo , EventType .RENDER_IMAGE );
574
574
}
575
575
@@ -1054,7 +1054,7 @@ protected static class PopGraphicsStateOperator implements IContentOperator {
1054
1054
public void invoke (PdfCanvasProcessor processor , PdfLiteral operator , List <PdfObject > operands ) {
1055
1055
processor .gsStack .pop ();
1056
1056
ParserGraphicsState gs = processor .getGraphicsState ();
1057
- processor .eventOccurred (new ClippingPathInfo (gs .getClippingPath (), gs .getCtm ()), EventType .CLIP_PATH_CHANGED );
1057
+ processor .eventOccurred (new ClippingPathInfo (gs , gs .getClippingPath (), gs .getCtm ()), EventType .CLIP_PATH_CHANGED );
1058
1058
}
1059
1059
}
1060
1060
@@ -1281,8 +1281,8 @@ private static class DoOperator implements IContentOperator {
1281
1281
* {@inheritDoc}
1282
1282
*/
1283
1283
public void invoke (PdfCanvasProcessor processor , PdfLiteral operator , List <PdfObject > operands ) {
1284
- PdfName xobjectName = (PdfName ) operands .get (0 );
1285
- processor .displayXObject (xobjectName );
1284
+ PdfName resourceName = (PdfName ) operands .get (0 );
1285
+ processor .displayXObject (resourceName );
1286
1286
}
1287
1287
}
1288
1288
@@ -1298,7 +1298,7 @@ private static class EndImageOperator implements IContentOperator {
1298
1298
*/
1299
1299
public void invoke (PdfCanvasProcessor processor , PdfLiteral operator , List <PdfObject > operands ) {
1300
1300
PdfStream imageStream = (PdfStream ) operands .get (0 );
1301
- processor .displayImage (imageStream , true );
1301
+ processor .displayImage (processor . markedContentStack , imageStream , null , true );
1302
1302
}
1303
1303
}
1304
1304
@@ -1374,9 +1374,10 @@ public void invoke(PdfCanvasProcessor processor, PdfLiteral oper, List<PdfObject
1374
1374
* An XObject subtype handler for FORM
1375
1375
*/
1376
1376
private static class FormXObjectDoHandler implements IXObjectDoHandler {
1377
- public void handleXObject (PdfCanvasProcessor processor , PdfStream stream ) {
1378
1377
1379
- PdfDictionary resourcesDic = stream .getAsDictionary (PdfName .Resources );
1378
+ public void handleXObject (PdfCanvasProcessor processor , Stack <CanvasTag > canvasTagHierarchy , PdfStream xObjectStream , PdfName xObjectName ) {
1379
+
1380
+ PdfDictionary resourcesDic = xObjectStream .getAsDictionary (PdfName .Resources );
1380
1381
PdfResources resources ;
1381
1382
if (resourcesDic == null ) {
1382
1383
resources = processor .getResources ();
@@ -1388,8 +1389,8 @@ public void handleXObject(PdfCanvasProcessor processor, PdfStream stream) {
1388
1389
// this is probably not necessary (if we fail on this, probably the entire content stream processing
1389
1390
// operation should be rejected
1390
1391
byte [] contentBytes ;
1391
- contentBytes = stream .getBytes ();
1392
- final PdfArray matrix = stream .getAsArray (PdfName .Matrix );
1392
+ contentBytes = xObjectStream .getBytes ();
1393
+ final PdfArray matrix = xObjectStream .getAsArray (PdfName .Matrix );
1393
1394
1394
1395
new PushGraphicsStateOperator ().invoke (processor , null , null );
1395
1396
@@ -1407,26 +1408,24 @@ public void handleXObject(PdfCanvasProcessor processor, PdfStream stream) {
1407
1408
processor .processContent (contentBytes , resources );
1408
1409
1409
1410
new PopGraphicsStateOperator ().invoke (processor , null , null );
1410
-
1411
1411
}
1412
-
1413
1412
}
1414
1413
1415
1414
/**
1416
1415
* An XObject subtype handler for IMAGE
1417
1416
*/
1418
1417
private static class ImageXObjectDoHandler implements IXObjectDoHandler {
1419
1418
1420
- public void handleXObject (PdfCanvasProcessor processor , PdfStream xobjectStream ) {
1421
- processor .displayImage (xobjectStream , false );
1419
+ public void handleXObject (PdfCanvasProcessor processor , Stack < CanvasTag > canvasTagHierarchy , PdfStream xObjectStream , PdfName resourceName ) {
1420
+ processor .displayImage (canvasTagHierarchy , xObjectStream , resourceName , false );
1422
1421
}
1423
1422
}
1424
1423
1425
1424
/**
1426
1425
* An XObject subtype handler that does nothing
1427
1426
*/
1428
1427
private static class IgnoreXObjectDoHandler implements IXObjectDoHandler {
1429
- public void handleXObject (PdfCanvasProcessor processor , PdfStream xobjectStream ) {
1428
+ public void handleXObject (PdfCanvasProcessor processor , Stack < CanvasTag > canvasTagHierarchy , PdfStream xObjectStream , PdfName xObjectName ) {
1430
1429
// ignore XObject subtype
1431
1430
}
1432
1431
}
0 commit comments