@@ -25,7 +25,6 @@ You should have received a copy of the GNU Affero General Public License
25
25
using iText . Commons . Utils ;
26
26
using iText . IO . Font . Constants ;
27
27
using iText . IO . Source ;
28
- using iText . Kernel . Exceptions ;
29
28
using iText . Kernel . Font ;
30
29
using iText . Kernel . Geom ;
31
30
using iText . Kernel . Pdf ;
@@ -466,21 +465,69 @@ public virtual void TestReadOcgFromApAnnotation() {
466
465
}
467
466
}
468
467
469
- //TODO DEVSIX-8490 remove this test when implemented
470
468
[ NUnit . Framework . Test ]
471
- public virtual void AddSecondParentlayerTest ( ) {
472
- using ( ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ) {
473
- using ( PdfDocument doc = new PdfDocument ( new PdfWriter ( outputStream ) ) ) {
474
- PdfLayer childLayer = new PdfLayer ( "childLayer" , doc ) ;
475
- PdfLayer parentLayer1 = new PdfLayer ( "firstParentLayer" , doc ) ;
476
- PdfLayer parentLayer2 = new PdfLayer ( "secondParentLayer" , doc ) ;
477
- parentLayer1 . AddChild ( childLayer ) ;
478
- PdfIndirectReference @ref = childLayer . GetIndirectReference ( ) ;
479
- Exception e = NUnit . Framework . Assert . Catch ( typeof ( PdfException ) , ( ) => parentLayer2 . AddChild ( childLayer ) ) ;
480
- NUnit . Framework . Assert . AreEqual ( MessageFormatUtil . Format ( KernelExceptionMessageConstant . UNABLE_TO_ADD_SECOND_PARENT_LAYER
481
- , @ref . ToString ( ) ) , e . Message ) ;
482
- }
483
- }
469
+ public virtual void NestedLayerTwoParentsTest ( ) {
470
+ String outPdf = destinationFolder + "nestedLayerTwoParents.pdf" ;
471
+ String cmpPdf = sourceFolder + "cmp_nestedLayerTwoParents.pdf" ;
472
+ PdfDocument pdfDoc = new PdfDocument ( CompareTool . CreateTestPdfWriter ( outPdf ) ) ;
473
+ PdfFont font = PdfFontFactory . CreateFont ( ) ;
474
+ PdfLayer parentLayer1 = new PdfLayer ( "Parent layer 1" , pdfDoc ) ;
475
+ PdfLayer parentLayer2 = new PdfLayer ( "Parent layer 2" , pdfDoc ) ;
476
+ PdfLayer nestedLayer = new PdfLayer ( "Nested layer 1" , pdfDoc ) ;
477
+ parentLayer1 . AddChild ( nestedLayer ) ;
478
+ parentLayer2 . AddChild ( nestedLayer ) ;
479
+ PdfCanvas canvas = new PdfCanvas ( pdfDoc . AddNewPage ( ) ) ;
480
+ canvas . SetFontAndSize ( font , 12 ) ;
481
+ PdfLayerTestUtils . AddTextInsideLayer ( parentLayer1 , canvas , "Parent layer 1 text" , 50 , 750 ) ;
482
+ PdfLayerTestUtils . AddTextInsideLayer ( parentLayer2 , canvas , "Parent layer 2 text" , 50 , 700 ) ;
483
+ PdfLayerTestUtils . AddTextInsideLayer ( nestedLayer , canvas , "Nested layer 1 text" , 100 , 650 ) ;
484
+ canvas . Release ( ) ;
485
+ pdfDoc . Close ( ) ;
486
+ PdfLayerTestUtils . CompareLayers ( outPdf , cmpPdf ) ;
487
+ }
488
+
489
+ [ NUnit . Framework . Test ]
490
+ public virtual void NestedLayerTwoParentsWithOneParentTest ( ) {
491
+ String outPdf = destinationFolder + "nestedLayerTwoParentsWithOneParent.pdf" ;
492
+ String cmpPdf = sourceFolder + "cmp_nestedLayerTwoParentsWithOneParent.pdf" ;
493
+ PdfDocument pdfDoc = new PdfDocument ( CompareTool . CreateTestPdfWriter ( outPdf ) ) ;
494
+ PdfFont font = PdfFontFactory . CreateFont ( ) ;
495
+ PdfLayer parentLayer = new PdfLayer ( "Parent layer" , pdfDoc ) ;
496
+ PdfLayer layer1 = new PdfLayer ( "Layer 1" , pdfDoc ) ;
497
+ PdfLayer layer2 = new PdfLayer ( "Layer 2" , pdfDoc ) ;
498
+ PdfLayer nestedLayer = new PdfLayer ( "Nested layer 1" , pdfDoc ) ;
499
+ layer1 . AddChild ( nestedLayer ) ;
500
+ layer2 . AddChild ( nestedLayer ) ;
501
+ parentLayer . AddChild ( layer1 ) ;
502
+ parentLayer . AddChild ( layer2 ) ;
503
+ PdfCanvas canvas = new PdfCanvas ( pdfDoc . AddNewPage ( ) ) ;
504
+ canvas . SetFontAndSize ( font , 12 ) ;
505
+ PdfLayerTestUtils . AddTextInsideLayer ( parentLayer , canvas , "Parent layer text" , 50 , 750 ) ;
506
+ PdfLayerTestUtils . AddTextInsideLayer ( layer1 , canvas , "layer 1 text" , 100 , 700 ) ;
507
+ PdfLayerTestUtils . AddTextInsideLayer ( layer2 , canvas , "layer 2 text" , 100 , 650 ) ;
508
+ PdfLayerTestUtils . AddTextInsideLayer ( nestedLayer , canvas , "Nested layer text" , 150 , 600 ) ;
509
+ canvas . Release ( ) ;
510
+ pdfDoc . Close ( ) ;
511
+ PdfLayerTestUtils . CompareLayers ( outPdf , cmpPdf ) ;
512
+ }
513
+
514
+ [ NUnit . Framework . Test ]
515
+ public virtual void DuplicatedNestedLayersTest ( ) {
516
+ String outPdf = destinationFolder + "duplicatedNestedLayers.pdf" ;
517
+ String cmpPdf = sourceFolder + "cmp_duplicatedNestedLayers.pdf" ;
518
+ PdfDocument pdfDoc = new PdfDocument ( CompareTool . CreateTestPdfWriter ( outPdf ) ) ;
519
+ PdfFont font = PdfFontFactory . CreateFont ( ) ;
520
+ PdfLayer parentLayer = new PdfLayer ( "Parent layer" , pdfDoc ) ;
521
+ PdfLayer nestedLayer1 = new PdfLayer ( "Nested layer" , pdfDoc ) ;
522
+ parentLayer . AddChild ( nestedLayer1 ) ;
523
+ parentLayer . AddChild ( nestedLayer1 ) ;
524
+ PdfCanvas canvas = new PdfCanvas ( pdfDoc . AddNewPage ( ) ) ;
525
+ canvas . SetFontAndSize ( font , 12 ) ;
526
+ PdfLayerTestUtils . AddTextInsideLayer ( parentLayer , canvas , "Parent layer text" , 50 , 750 ) ;
527
+ PdfLayerTestUtils . AddTextInsideLayer ( nestedLayer1 , canvas , "Nested layer text" , 100 , 700 ) ;
528
+ canvas . Release ( ) ;
529
+ pdfDoc . Close ( ) ;
530
+ PdfLayerTestUtils . CompareLayers ( outPdf , cmpPdf ) ;
484
531
}
485
532
}
486
533
}
0 commit comments