public virtual void ImageWidthTest02() { PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.Create(imageFolder + "Desert.jpg")); iText.Layout.Element.Image image = new iText.Layout.Element.Image(xObject); ImageRenderer renderer = new ImageRenderer(image); image.SetProperty(Property.MAX_WIDTH, UnitValue.CreatePointValue(50)); MinMaxWidth minMaxWidth = renderer.GetMinMaxWidth(); NUnit.Framework.Assert.AreEqual(50.0, minMaxWidth.GetMaxWidth(), EPSILON); NUnit.Framework.Assert.AreEqual(0.0, minMaxWidth.GetMaxWidth() - minMaxWidth.GetMinWidth(), EPSILON); image.SetProperty(Property.MAX_WIDTH, UnitValue.CreatePercentValue(50)); minMaxWidth = renderer.GetMinMaxWidth(); NUnit.Framework.Assert.AreEqual(1024.0, minMaxWidth.GetMaxWidth(), EPSILON); image.SetProperty(Property.MAX_HEIGHT, UnitValue.CreatePointValue(100f)); minMaxWidth = renderer.GetMinMaxWidth(); NUnit.Framework.Assert.AreEqual(100.0 * 1024.0 / 768.0, minMaxWidth.GetMaxWidth(), EPSILON); image = new iText.Layout.Element.Image(xObject); renderer = new ImageRenderer(image); image.SetProperty(Property.MIN_WIDTH, UnitValue.CreatePointValue(2000)); image.SetProperty(Property.MAX_WIDTH, UnitValue.CreatePointValue(3000)); minMaxWidth = renderer.GetMinMaxWidth(); NUnit.Framework.Assert.AreEqual(2000.0, minMaxWidth.GetMaxWidth(), EPSILON); NUnit.Framework.Assert.AreEqual(0.0, minMaxWidth.GetMaxWidth() - minMaxWidth.GetMinWidth(), EPSILON); image.SetProperty(Property.MIN_HEIGHT, UnitValue.CreatePointValue(100f)); image.SetProperty(Property.HEIGHT, UnitValue.CreatePointValue(100f)); minMaxWidth = renderer.GetMinMaxWidth(); NUnit.Framework.Assert.AreEqual(100.0 * 1024.0 / 768.0, minMaxWidth.GetMaxWidth(), EPSILON); }
protected internal static ImageRenderer CreateLayoutedImageRenderer(float width, float height, Document document ) { PdfFormXObject xObject = new PdfFormXObject(new Rectangle(width, height)); Image img = new Image(xObject); ImageRenderer renderer = (ImageRenderer) new ImageRenderer(img).SetParent(document.GetRenderer()); renderer.Layout(new LayoutContext(new LayoutArea(1, new Rectangle(1000, 1000)))); return(renderer); }
public virtual void ImageRendererAddByIDTest() { DocumentRenderer documentRenderer = new DocumentRenderer(null); ImageRenderer imageRenderer = new ImageRenderer(new Image(ImageDataFactory.CreateRawImage(new byte[] { 50, 21 }))); imageRenderer.SetParent(documentRenderer); String id = "id6"; imageRenderer.SetProperty(Property.ID, id); LayoutContext layoutContext = new LayoutContext(new LayoutArea(4, new Rectangle(50, 50))); imageRenderer.Layout(layoutContext); documentRenderer.GetTargetCounterHandler().PrepareHandlerToRelayout(); NUnit.Framework.Assert.AreEqual((int?)4, TargetCounterHandler.GetPageByID(imageRenderer, id)); }
public virtual void AdjustChildrenYLineImageChildHtmlModeTest() { Document document = CreateDocument(); LineRenderer lineRenderer = new LineRenderer(); lineRenderer.SetParent(document.GetRenderer()); lineRenderer.occupiedArea = new LayoutArea(1, new Rectangle(50, 50, 200, 200)); lineRenderer.maxAscent = 100; PdfFormXObject xObject = new PdfFormXObject(new Rectangle(200, 200)); Image img = new Image(xObject); ImageRenderer childImageRenderer = new ImageRenderer(img); childImageRenderer.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE); childImageRenderer.occupiedArea = new LayoutArea(1, new Rectangle(50, 50, 200, 200)); lineRenderer.AddChild(childImageRenderer); lineRenderer.AdjustChildrenYLine(); NUnit.Framework.Assert.AreEqual(50f, lineRenderer.GetOccupiedAreaBBox().GetBottom(), EPS); NUnit.Framework.Assert.AreEqual(150.0, childImageRenderer.GetOccupiedAreaBBox().GetBottom(), EPS); }