@@ -400,9 +400,9 @@ private void dlCollect(RenderingContext c, List<List<DisplayListOperation>> dlPa
400400 PageResult pg = pgResults .get (i );
401401 List <DisplayListOperation > dlPageList = dlPages .get (i );
402402
403- if (!pg .blocks .isEmpty ()) {
404- Map <TableCellBox , List <CollapsedBorderSide >> collapsedTableBorders = pg .tcells .isEmpty () ? null : dlCollectCollapsedTableBorders (c , pg .tcells );
405- DisplayListOperation dlo = new PaintBackgroundAndBorders (pg .blocks , c , collapsedTableBorders );
403+ if (!pg .blocks () .isEmpty ()) {
404+ Map <TableCellBox , List <CollapsedBorderSide >> collapsedTableBorders = pg .tcells () .isEmpty () ? null : dlCollectCollapsedTableBorders (c , pg .tcells () );
405+ DisplayListOperation dlo = new PaintBackgroundAndBorders (pg .blocks () , c , collapsedTableBorders );
406406 dlPageList .add (dlo );
407407 }
408408
@@ -413,18 +413,18 @@ private void dlCollect(RenderingContext c, List<List<DisplayListOperation>> dlPa
413413 }
414414 }
415415
416- if (!pg .blocks .isEmpty ()) {
417- DisplayListOperation dlo = new PaintListMarkers (pg .blocks , c );
416+ if (!pg .blocks () .isEmpty ()) {
417+ DisplayListOperation dlo = new PaintListMarkers (pg .blocks () , c );
418418 dlPageList .add (dlo );
419419 }
420420
421- if (!pg .inlines .isEmpty ()) {
422- DisplayListOperation dlo = new PaintInlineContent (pg .inlines , c );
421+ if (!pg .inlines () .isEmpty ()) {
422+ DisplayListOperation dlo = new PaintInlineContent (pg .inlines () , c );
423423 dlPageList .add (dlo );
424424 }
425425
426- if (!pg .blocks .isEmpty ()) {
427- DisplayListOperation dlo = new PaintReplacedElements (pg .blocks , c );
426+ if (!pg .replaceds () .isEmpty ()) {
427+ DisplayListOperation dlo = new PaintReplacedElements (pg .replaceds () , c );
428428 dlPageList .add (dlo );
429429 }
430430 }
@@ -449,24 +449,24 @@ private void dlCollectFloatAsLayer(RenderingContext c, List<PageBox> pages, Bloc
449449 PageResult pg = pgResults .get (i );
450450 List <DisplayListOperation > dlPageList = dlPages .get (i );
451451
452- if (!pg .blocks .isEmpty ()) {
453- Map <TableCellBox , List <CollapsedBorderSide >> collapsedTableBorders = pg .tcells .isEmpty () ? null : dlCollectCollapsedTableBorders (c , pg .tcells );
454- DisplayListOperation dlo = new PaintBackgroundAndBorders (pg .blocks , c , collapsedTableBorders );
452+ if (!pg .blocks () .isEmpty ()) {
453+ Map <TableCellBox , List <CollapsedBorderSide >> collapsedTableBorders = pg .tcells () .isEmpty () ? null : dlCollectCollapsedTableBorders (c , pg .tcells () );
454+ DisplayListOperation dlo = new PaintBackgroundAndBorders (pg .blocks () , c , collapsedTableBorders );
455455 dlPageList .add (dlo );
456456 }
457457
458- if (!pg .blocks .isEmpty ()) {
459- DisplayListOperation dlo = new PaintListMarkers (pg .blocks , c );
458+ if (!pg .blocks () .isEmpty ()) {
459+ DisplayListOperation dlo = new PaintListMarkers (pg .blocks () , c );
460460 dlPageList .add (dlo );
461461 }
462462
463- if (!pg .inlines .isEmpty ()) {
464- DisplayListOperation dlo = new PaintInlineContent (pg .inlines , c );
463+ if (!pg .inlines () .isEmpty ()) {
464+ DisplayListOperation dlo = new PaintInlineContent (pg .inlines () , c );
465465 dlPageList .add (dlo );
466466 }
467467
468- if (!pg .blocks .isEmpty ()) {
469- DisplayListOperation dlo = new PaintReplacedElements (pg .blocks , c );
468+ if (!pg .replaceds () .isEmpty ()) {
469+ DisplayListOperation dlo = new PaintReplacedElements (pg .replaceds () , c );
470470 dlPageList .add (dlo );
471471 }
472472 }
@@ -555,20 +555,31 @@ private void dlPaintInlineContent(RenderingContext c, List<DisplayListItem> inli
555555 }
556556 }
557557
558- private void dlPaintReplacedElements (RenderingContext c , List <DisplayListItem > blocks ) {
559- for (DisplayListItem dli : blocks ) {
558+ private void dlPaintReplacedElements (RenderingContext c , List <DisplayListItem > replaceds ) {
559+ for (int i = 0 ; i < replaceds .size (); i ++) {
560+ DisplayListItem dli = replaceds .get (i );
561+ DisplayListItem prev = (i - 1 ) >= 0 ? replaceds .get (i - 1 ) : null ;
562+ DisplayListItem next = (i + 1 ) < replaceds .size () ? replaceds .get (i + 1 ) : null ;
563+
560564 if (dli instanceof OperatorClip ) {
565+ if (next instanceof OperatorSetClip ) {
566+ // Its an empty clip/setClip pair with no replaceds between them.
567+ continue ;
568+ }
569+
561570 OperatorClip clip = (OperatorClip ) dli ;
562571 c .getOutputDevice ().clip (clip .getClip ());
563572 } else if (dli instanceof OperatorSetClip ) {
573+ if (prev instanceof OperatorClip ) {
574+ // Its an empty clip/setClip pair with no replaceds between them.
575+ continue ;
576+ }
577+
564578 OperatorSetClip setClip = (OperatorSetClip ) dli ;
565579 c .getOutputDevice ().setClip (setClip .getSetClipShape ());
566580 } else {
567581 BlockBox box = (BlockBox ) dli ;
568-
569- if (box .isReplaced ()) {
570- c .getOutputDevice ().paintReplacedElement (c , box );
571- }
582+ c .getOutputDevice ().paintReplacedElement (c , box );
572583 }
573584 }
574585 }
@@ -610,7 +621,7 @@ public void dlPaint(RenderingContext c, List<DisplayListOperation> pageOperation
610621 } else if (op instanceof PaintReplacedElements ) {
611622
612623 PaintReplacedElements dlo = (PaintReplacedElements ) op ;
613- dlPaintReplacedElements (dlo .getContext (), dlo .getBlocks ());
624+ dlPaintReplacedElements (dlo .getContext (), dlo .getReplaceds ());
614625
615626 } else {
616627
0 commit comments