Skip to content

Commit 8149cd1

Browse files
IdamkinIitext-teamcity
authored andcommitted
Fix small rotation bugs
If some renderer has not null rotation, but for some reasons this rotation wasn't applied, iText was failing with exception trying to restore not saved graphic state, because of missing check. RotationUtils#retrieveRotatedLayoutWidth was returning full element width, but is expecting to return only content width. Also corresponding tests where added, and already done TODO was removed Autoported commit. Original commit hash: [427e34f]
1 parent 898da01 commit 8149cd1

File tree

12 files changed

+56
-5
lines changed

12 files changed

+56
-5
lines changed

itext.tests/itext.layout.tests/itext/layout/RotationTest.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ source product.
4141
4242
*/
4343
using System;
44+
using iText.IO.Image;
4445
using iText.Kernel.Colors;
4546
using iText.Kernel.Geom;
4647
using iText.Kernel.Pdf;
@@ -598,7 +599,6 @@ public virtual void FixedWidthRotationTest02() {
598599
/// <exception cref="System.Exception"/>
599600
[NUnit.Framework.Test]
600601
public virtual void FixedWidthRotationTest03() {
601-
//TODO: currently is incorrect. See DEVSIX-988
602602
String outFileName = destinationFolder + "fixedWidthRotationTest03.pdf";
603603
String cmpFileName = sourceFolder + cmpPrefix + "fixedWidthRotationTest03.pdf";
604604
Document doc = new Document(new PdfDocument(new PdfWriter(outFileName)));
@@ -613,6 +613,52 @@ public virtual void FixedWidthRotationTest03() {
613613
, "diff"));
614614
}
615615

616+
/// <exception cref="System.IO.IOException"/>
617+
/// <exception cref="System.Exception"/>
618+
[NUnit.Framework.Test]
619+
public virtual void ImageInRotatedBlockTest01() {
620+
String outFileName = destinationFolder + "imageInRotatedBlockTest01.pdf";
621+
String cmpFileName = sourceFolder + "cmp_imageInRotatedBlockTest01.pdf";
622+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
623+
Document doc = new Document(pdfDocument);
624+
iText.Layout.Element.Image image = new Image(ImageDataFactory.Create(sourceFolder + "Desert.jpg"));
625+
image.SetWidth(200);
626+
Div div = new Div();
627+
div.SetRotationAngle(Math.PI / 2);
628+
div.SetBorder(new SolidBorder(Color.BLUE, 1));
629+
div.Add(image);
630+
doc.Add(div);
631+
doc.Add(new Paragraph("Hello!!!").SetBackgroundColor(Color.RED));
632+
doc.Close();
633+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
634+
, "diff"));
635+
}
636+
637+
/// <exception cref="System.IO.IOException"/>
638+
/// <exception cref="System.Exception"/>
639+
[NUnit.Framework.Test]
640+
[LogMessage(iText.IO.LogMessageConstant.CLIP_ELEMENT)]
641+
[LogMessage(iText.IO.LogMessageConstant.ROTATION_WAS_NOT_CORRECTLY_PROCESSED_FOR_RENDERER, Count = 2)]
642+
public virtual void ImageInRotatedBlockTest02() {
643+
String outFileName = destinationFolder + "imageInRotatedBlockTest02.pdf";
644+
String cmpFileName = sourceFolder + "cmp_imageInRotatedBlockTest02.pdf";
645+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
646+
Document doc = new Document(pdfDocument);
647+
iText.Layout.Element.Image image = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder + "Desert.jpg"
648+
));
649+
image.SetWidth(200);
650+
Div div = new Div();
651+
div.SetHeight(100);
652+
div.SetRotationAngle(Math.PI / 2);
653+
div.SetBorder(new SolidBorder(Color.BLUE, 1));
654+
div.Add(image);
655+
doc.Add(div);
656+
doc.Add(new Paragraph("Hello!!!").SetBackgroundColor(Color.RED));
657+
doc.Close();
658+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
659+
, "diff"));
660+
}
661+
616662
/// <exception cref="System.IO.IOException"/>
617663
/// <exception cref="System.Exception"/>
618664
[NUnit.Framework.Test]
Binary file not shown.
826 KB
Loading
Binary file not shown.

itext/itext.layout/itext/layout/renderer/BlockRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ protected internal virtual void BeginRotationIfApplied(PdfCanvas canvas) {
665665

666666
protected internal virtual void EndRotationIfApplied(PdfCanvas canvas) {
667667
float? angle = this.GetPropertyAsFloat(Property.ROTATION_ANGLE);
668-
if (angle != null) {
668+
if (angle != null && HasOwnProperty(Property.ROTATION_INITIAL_HEIGHT)) {
669669
canvas.RestoreState();
670670
}
671671
}

0 commit comments

Comments
 (0)