/** * Calculates intersection of the image and the render filter region in the coordinate system relative to the image. * * @return <code>null</code> if the image is not allowed, {@link java.util.List} of * {@link com.itextpdf.text.Rectangle} objects otherwise. */ protected internal virtual IList<Rectangle> GetCoveredAreas(ImageRenderInfo renderInfo) { Rectangle imageRect = CalcImageRect(renderInfo); IList<Rectangle> coveredAreas = new List<Rectangle>(); if (imageRect == null) { return null; } foreach (Rectangle rectangle in rectangles) { Rectangle intersectionRect = Intersection(imageRect, rectangle); if (intersectionRect != null) { // True if the image is completely covered if (imageRect.Equals(intersectionRect)) { return null; } coveredAreas.Add(TransformIntersection(renderInfo.GetImageCTM(), intersectionRect)); } } return coveredAreas; }
/// <summary> /// Converts the Matrix containing the coordinates of an image as stored /// in an ImageRenderInfo object into a Rectangle. /// </summary> /// <param name="imageRenderInfo">Object that contains info about an image</param> /// <returns>coordinates in the form of a Rectangle object</returns> private static Rectangle GetRectangle(ImageRenderInfo imageRenderInfo) { Matrix ctm = imageRenderInfo.GetImageCTM(); return new Rectangle(ctm[6], ctm[7], ctm[6] + ctm[0], ctm[7] + ctm[4]); }
/** * @return Image boundary rectangle in device space. */ private Rectangle CalcImageRect(ImageRenderInfo renderInfo) { Matrix ctm = renderInfo.GetImageCTM(); if (ctm == null) { return null; } Point2D[] points = TransformPoints(ctm, false, new Point(0, 0), new Point(0, 1), new Point(1, 0), new Point(1, 1)); return GetRectangle(points[0], points[1], points[2], points[3]); }