Package com.itextpdf.text.pdf.pdfcleanup
Class PdfCleanUpRegionFilter
- java.lang.Object
-
- com.itextpdf.text.pdf.parser.RenderFilter
-
- com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRegionFilter
-
class PdfCleanUpRegionFilter extends RenderFilter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classPdfCleanUpRegionFilter.StandardLine
-
Field Summary
Fields Modifier and Type Field Description private static doublecircleApproximationConstprivate java.util.List<Rectangle>rectangles
-
Constructor Summary
Constructors Constructor Description PdfCleanUpRegionFilter(java.util.List<Rectangle> rectangles)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidaddContour(Path path, java.util.List<Point.LongPoint> contour, java.lang.Boolean close)private static java.util.List<Subpath>addPath(ClipperOffset offset, Path path, Clipper.JoinType joinType, Clipper.EndType endType)Adds all subpaths of the path to theClipperOffsetobject with one note: it doesn't add degenerate subpaths.private static voidaddPath(Clipper clipper, Path path)private static voidaddRect(Clipper clipper, Point2D[] rectVertices, Clipper.PolyType polyType)booleanallowImage(ImageRenderInfo renderInfo)booleanallowText(TextRenderInfo renderInfo)Checks if the text is inside render filter region.private static floatapplyDash(Path dashedPath, Point2D segStart, Point2D segEnd, Point2D dashTo, boolean isGap)private static PathapplyDashPattern(Path path, LineDashPattern lineDashPattern)private static BezierCurve[]approximateCircle(Point2D center, double radius)private RectanglecalcImageRect(ImageRenderInfo renderInfo)private static Point2DcomponentwiseDiff(Point2D minuend, Point2D subtrahend)private static SubpathconstructSquare(Point2D squareCenter, double widthHalf, double rotationAngle)private static java.util.List<Subpath>convertToCircles(java.util.List<Subpath> degenerateSubpaths, double radius)Converts specified degenerate subpaths to circles.private static java.util.List<Point2D>convertToFloatPoints(java.util.List<Point.LongPoint> points)private static PathconvertToIntPoints(java.util.List<Point2D> points)private static PathconvertToPath(PolyTree result)private static java.util.List<Subpath>convertToSquares(java.util.List<Subpath> degenerateSubpaths, double squareWidth, Path sourcePath)Converts specified degenerate subpaths to squares.protected PathfilterFillPath(Path path, Matrix ctm, int fillingRule)Note: this method will close all unclosed subpaths of the passed path.protected PathfilterStrokePath(Path sourcePath, Matrix ctm, float lineWidth, int lineCapStyle, int lineJoinStyle, float miterLimit, LineDashPattern lineDashPattern)protected java.util.List<Rectangle>getCoveredAreas(ImageRenderInfo renderInfo)Calculates intersection of the image and the render filter region in the coordinate system relative to the image.private static Clipper.EndTypegetEndType(int lineCapStyle)private static Clipper.JoinTypegetJoinType(int lineJoinStyle)private static Point2DgetNextPoint(Point2D segStart, Point2D segEnd, float dist)private static java.util.List<Point2D>getPathApproximation(Path path)private RectanglegetRectangle(Point2D p1, Point2D p2, Point2D p3, Point2D p4)Constructs Rectangle object on the given pointsprivate static Point2D[]getRotatedSquareVertices(Point2D[] orthogonalSquareVertices, double angle, Point2D squareCenter)private static Point2DgetUnitVector(Point2D vector)private static doublegetVectorEuclideanNorm(Point2D vector)private Point2D[]getVertices(Rectangle rect)private booleanintersect(Point2D[] rect1, Point2D[] rect2)private Rectangleintersection(Rectangle rect1, Rectangle rect2)private static booleanliesOnSegment(Point2D segStart, Point2D segEnd, Point2D point)private RectangletransformIntersection(Matrix imageCTM, Rectangle rect)Transforms the given Rectangle into the image coordinate system which is [0,1]x[0,1] by defaultprivate Point2D[]transformPoints(Matrix transormationMatrix, boolean inverse, Point2D... points)
-
-
-
Field Detail
-
rectangles
private java.util.List<Rectangle> rectangles
-
circleApproximationConst
private static final double circleApproximationConst
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PdfCleanUpRegionFilter
public PdfCleanUpRegionFilter(java.util.List<Rectangle> rectangles)
-
-
Method Detail
-
allowText
public boolean allowText(TextRenderInfo renderInfo)
Checks if the text is inside render filter region.- Overrides:
allowTextin classRenderFilter- Returns:
- true if the text render operation should be performed
-
allowImage
public boolean allowImage(ImageRenderInfo renderInfo)
- Overrides:
allowImagein classRenderFilter- Returns:
- true if the image render operation should be performed
-
getCoveredAreas
protected java.util.List<Rectangle> getCoveredAreas(ImageRenderInfo renderInfo)
Calculates intersection of the image and the render filter region in the coordinate system relative to the image.- Returns:
nullif the image is not allowed,ListofRectangleobjects otherwise.
-
filterStrokePath
protected Path filterStrokePath(Path sourcePath, Matrix ctm, float lineWidth, int lineCapStyle, int lineJoinStyle, float miterLimit, LineDashPattern lineDashPattern)
-
filterFillPath
protected Path filterFillPath(Path path, Matrix ctm, int fillingRule)
Note: this method will close all unclosed subpaths of the passed path.- Parameters:
fillingRule- If the subpath is contour, pass any value.
-
getJoinType
private static Clipper.JoinType getJoinType(int lineJoinStyle)
-
getEndType
private static Clipper.EndType getEndType(int lineCapStyle)
-
convertToCircles
private static java.util.List<Subpath> convertToCircles(java.util.List<Subpath> degenerateSubpaths, double radius)
Converts specified degenerate subpaths to circles. Note: actually the resultant subpaths are not real circles but approximated.- Parameters:
radius- Radius of each constructed circle.- Returns:
Listconsisting of circles constructed on given degenerated subpaths.
-
convertToSquares
private static java.util.List<Subpath> convertToSquares(java.util.List<Subpath> degenerateSubpaths, double squareWidth, Path sourcePath)
Converts specified degenerate subpaths to squares. Note: the list of degenerate subpaths should contain at least 2 elements. Otherwise we can't determine the direction which the rotation of each square depends on.- Parameters:
squareWidth- Width of each constructed square.sourcePath- The path which dash pattern applied to. Needed to calc rotation angle of each square.- Returns:
Listconsisting of squares constructed on given degenerated subpaths.
-
constructSquare
private static Subpath constructSquare(Point2D squareCenter, double widthHalf, double rotationAngle)
-
getRotatedSquareVertices
private static Point2D[] getRotatedSquareVertices(Point2D[] orthogonalSquareVertices, double angle, Point2D squareCenter)
-
addPath
private static java.util.List<Subpath> addPath(ClipperOffset offset, Path path, Clipper.JoinType joinType, Clipper.EndType endType)
Adds all subpaths of the path to theClipperOffsetobject with one note: it doesn't add degenerate subpaths.- Returns:
Listconsisting of all degenerate subpaths of the path.
-
approximateCircle
private static BezierCurve[] approximateCircle(Point2D center, double radius)
-
addRect
private static void addRect(Clipper clipper, Point2D[] rectVertices, Clipper.PolyType polyType)
-
convertToFloatPoints
private static java.util.List<Point2D> convertToFloatPoints(java.util.List<Point.LongPoint> points)
-
addContour
private static void addContour(Path path, java.util.List<Point.LongPoint> contour, java.lang.Boolean close)
-
calcImageRect
private Rectangle calcImageRect(ImageRenderInfo renderInfo)
- Returns:
- Image boundary rectangle in device space.
-
intersection
private Rectangle intersection(Rectangle rect1, Rectangle rect2)
- Returns:
- null if the intersection is empty,
Rectanglerepresenting intersection otherwise
-
transformIntersection
private Rectangle transformIntersection(Matrix imageCTM, Rectangle rect)
Transforms the given Rectangle into the image coordinate system which is [0,1]x[0,1] by default
-
getRectangle
private Rectangle getRectangle(Point2D p1, Point2D p2, Point2D p3, Point2D p4)
Constructs Rectangle object on the given points
-
applyDashPattern
private static Path applyDashPattern(Path path, LineDashPattern lineDashPattern)
-
getVectorEuclideanNorm
private static double getVectorEuclideanNorm(Point2D vector)
-
applyDash
private static float applyDash(Path dashedPath, Point2D segStart, Point2D segEnd, Point2D dashTo, boolean isGap)
-
liesOnSegment
private static boolean liesOnSegment(Point2D segStart, Point2D segEnd, Point2D point)
-
-