Skip to content

Commit 84f7910

Browse files
author
Samuel Huylebroeck
committed
Add autoscaling test and setHeight method
setHeight method taking UnitValue Tests for autoscaling DEVSIX-1658
1 parent c52e807 commit 84f7910

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

layout/src/main/java/com/itextpdf/layout/ElementPropertyContainer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ public T setHeight(float height) {
188188
return (T) (Object) this;
189189
}
190190

191+
/**
192+
* Sets the width property of the Element with a {@link UnitValue}.
193+
*
194+
* @param height a {@link UnitValue} object
195+
* @return this Element.
196+
*/
197+
public T setHeight(UnitValue height) {
198+
setProperty(Property.HEIGHT, height);
199+
return (T) (Object) this;
200+
}
191201
/**
192202
* Sets values for a relative repositioning of the Element. Also has as a
193203
* side effect that the Element's {@link Property#POSITION} is changed to

layout/src/test/java/com/itextpdf/layout/ImageTest.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,78 @@ public void imageTest17() throws IOException, InterruptedException {
471471
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"));
472472
}
473473

474+
@Test
475+
public void imageTest18() throws IOException, InterruptedException {
476+
String outFileName = destinationFolder + "imageTest18.pdf";
477+
String cmpFileName = sourceFolder + "cmp_imageTest18.pdf";
478+
479+
PdfWriter writer = new PdfWriter(outFileName);
480+
PdfDocument pdfDoc = new PdfDocument(writer);
481+
Document doc = new Document(pdfDoc);
482+
483+
Image image = new Image(ImageDataFactory.create(sourceFolder + "Desert.jpg"));
484+
image.setAutoScale(true);
485+
486+
Div container = new Div();
487+
container.setBorder(new SolidBorder(1f));
488+
container.setWidth(UnitValue.createPercentValue(50f));
489+
container.setHeight(UnitValue.createPointValue(300f));
490+
container.add(image);
491+
doc.add(container);
492+
493+
doc.close();
494+
495+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"));
496+
}
497+
@Ignore("DEVSIX-1658")
498+
@Test
499+
public void imageTest19() throws IOException, InterruptedException {
500+
String outFileName = destinationFolder + "imageTest19.pdf";
501+
String cmpFileName = sourceFolder + "cmp_imageTest19.pdf";
502+
503+
PdfWriter writer = new PdfWriter(outFileName);
504+
PdfDocument pdfDoc = new PdfDocument(writer);
505+
Document doc = new Document(pdfDoc);
506+
507+
Image image = new Image(ImageDataFactory.create(sourceFolder + "Desert.jpg"));
508+
image.setAutoScaleHeight(true);
509+
510+
Div container = new Div();
511+
container.setBorder(new SolidBorder(1f));
512+
container.setWidth(UnitValue.createPercentValue(50f));
513+
container.setHeight(UnitValue.createPointValue(300f));
514+
container.add(image);
515+
doc.add(container);
516+
517+
doc.close();
518+
519+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"));
520+
}
521+
522+
@Test
523+
public void imageTest20() throws IOException, InterruptedException {
524+
String outFileName = destinationFolder + "imageTest20.pdf";
525+
String cmpFileName = sourceFolder + "cmp_imageTest20.pdf";
526+
527+
PdfWriter writer = new PdfWriter(outFileName);
528+
PdfDocument pdfDoc = new PdfDocument(writer);
529+
Document doc = new Document(pdfDoc);
530+
531+
Image image = new Image(ImageDataFactory.create(sourceFolder + "Desert.jpg"));
532+
image.setAutoScaleWidth(true);
533+
534+
Div container = new Div();
535+
container.setBorder(new SolidBorder(1f));
536+
container.setWidth(UnitValue.createPercentValue(60f));
537+
container.setHeight(UnitValue.createPointValue(300f));
538+
container.add(image);
539+
doc.add(container);
540+
541+
doc.close();
542+
543+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"));
544+
}
545+
474546
/**
475547
* Image can be reused in layout, so flushing it on the very first draw is a bad thing.
476548
*/
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)