Skip to content

Commit 8967645

Browse files
committed
Make 'floatMultiplier' and 'arcTolerance' in PdfCleanUpTool non-static configuration
DEVSIX-5770
1 parent 77e3bd9 commit 8967645

File tree

7 files changed

+238
-70
lines changed

7 files changed

+238
-70
lines changed

src/main/java/com/itextpdf/pdfcleanup/CleanUpProperties.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class CleanUpProperties {
3333
private IMetaInfo metaInfo;
3434
private boolean processAnnotations;
3535
private Double overlapRatio;
36+
private PathOffsetApproximationProperties offsetProperties = new PathOffsetApproximationProperties();
3637

3738
/**
3839
* Creates default CleanUpProperties instance.
@@ -54,9 +55,12 @@ IMetaInfo getMetaInfo() {
5455
* Sets additional meta info.
5556
*
5657
* @param metaInfo the meta info to set
58+
*
59+
* @return this {@link CleanUpProperties} instance
5760
*/
58-
public void setMetaInfo(IMetaInfo metaInfo) {
61+
public CleanUpProperties setMetaInfo(IMetaInfo metaInfo) {
5962
this.metaInfo = metaInfo;
63+
return this;
6064
}
6165

6266
/**
@@ -74,9 +78,12 @@ public boolean isProcessAnnotations() {
7478
* Default processing behaviour: remove annotation if there is overlap with a redaction region.
7579
*
7680
* @param processAnnotations is page annotations will be processed
81+
*
82+
* @return this {@link CleanUpProperties} instance
7783
*/
78-
public void setProcessAnnotations(boolean processAnnotations) {
84+
public CleanUpProperties setProcessAnnotations(boolean processAnnotations) {
7985
this.processAnnotations = processAnnotations;
86+
return this;
8087
}
8188

8289
/**
@@ -98,16 +105,42 @@ public Double getOverlapRatio() {
98105
* Example: if the overlap ratio is set to 0.3, the content region will be removed if it overlaps with
99106
* the redaction area by at least 30%.
100107
*
101-
* @param overlapRatio The overlap ratio to set.
108+
* @param overlapRatio the overlap ratio to set
109+
*
110+
* @return this {@link CleanUpProperties} instance
102111
*/
103-
public void setOverlapRatio(Double overlapRatio) {
112+
public CleanUpProperties setOverlapRatio(Double overlapRatio) {
104113
if (overlapRatio == null) {
105114
this.overlapRatio = null;
106-
return;
115+
return this;
107116
}
108117
if (overlapRatio <= 0 || overlapRatio > 1) {
109118
throw new IllegalArgumentException(CleanupExceptionMessageConstant.OVERLAP_RATIO_SHOULD_BE_IN_RANGE);
110119
}
111120
this.overlapRatio = overlapRatio;
121+
return this;
122+
}
123+
124+
/**
125+
* Get {@link PathOffsetApproximationProperties} specifying approximation parameters for
126+
* {@link com.itextpdf.kernel.pdf.canvas.parser.clipper.ClipperOffset} operations.
127+
*
128+
* @return {@link PathOffsetApproximationProperties} parameters
129+
*/
130+
public PathOffsetApproximationProperties getOffsetProperties() {
131+
return offsetProperties;
132+
}
133+
134+
/**
135+
* Set {@link PathOffsetApproximationProperties} specifying approximation parameters for
136+
* {@link com.itextpdf.kernel.pdf.canvas.parser.clipper.ClipperOffset} operations.
137+
*
138+
* @param offsetProperties {@link PathOffsetApproximationProperties} to set
139+
*
140+
* @return this {@link CleanUpProperties} instance
141+
*/
142+
public CleanUpProperties setOffsetProperties(PathOffsetApproximationProperties offsetProperties) {
143+
this.offsetProperties = offsetProperties;
144+
return this;
112145
}
113146
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2024 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.pdfcleanup;
24+
25+
import com.itextpdf.kernel.pdf.canvas.parser.clipper.ClipperBridge;
26+
27+
/**
28+
* Contains properties for {@link com.itextpdf.kernel.pdf.canvas.parser.clipper.ClipperOffset} operations.
29+
*/
30+
public class PathOffsetApproximationProperties {
31+
private double arcTolerance = 0.0025;
32+
private boolean calculateOffsetMultiplierDynamically = false;
33+
34+
/**
35+
* Creates new {@link PathOffsetApproximationProperties} instance.
36+
*/
37+
public PathOffsetApproximationProperties() {
38+
// Empty constructor.
39+
}
40+
41+
/**
42+
* Specifies if floatMultiplier should be calculated dynamically. Default value is {@code false}.
43+
*
44+
* <p>
45+
* When a document with line arts is being cleaned up, there are a lot of calculations with floating point numbers.
46+
* All of them are translated into fixed point numbers by multiplying by this floatMultiplier coefficient.
47+
* It is possible to dynamically adjust the preciseness of the calculations.
48+
*
49+
* @param calculateDynamically {@code true} if floatMultiplier should be calculated dynamically,
50+
* {@code false} for default value specified by {@link ClipperBridge#ClipperBridge()}
51+
*
52+
* @return this {@link PathOffsetApproximationProperties} instance
53+
*/
54+
public PathOffsetApproximationProperties calculateOffsetMultiplierDynamically(boolean calculateDynamically) {
55+
this.calculateOffsetMultiplierDynamically = calculateDynamically;
56+
return this;
57+
}
58+
59+
/**
60+
* Checks whether floatMultiplier should be calculated dynamically.
61+
*
62+
* <p>
63+
* When a document with line arts is being cleaned up, there are a lot of calculations with floating point numbers.
64+
* All of them are translated into fixed point numbers by multiplying by this floatMultiplier coefficient.
65+
* It is possible to dynamically adjust the preciseness of the calculations.
66+
*
67+
* @return {@code true} if floatMultiplier should be calculated dynamically, {@code false} for default value
68+
*/
69+
public boolean calculateOffsetMultiplierDynamically() {
70+
return this.calculateOffsetMultiplierDynamically;
71+
}
72+
73+
/**
74+
* Gets arc tolerance which is the maximum difference between the true and the faceted representation of curves
75+
* (arcs) in units. Used as the criterion of a good approximation of rounded line joins and line caps.
76+
*
77+
* <p>
78+
* Since flattened paths can never perfectly represent arcs, this field/property specifies a maximum acceptable
79+
* imprecision (tolerance) when arcs are approximated in an offsetting operation. Smaller values will increase
80+
* smoothness up to a point though at a cost of performance and in creating more vertices to construct the arc.
81+
*
82+
* @return arc tolerance specifying maximum difference between the true and the faceted representation of arcs
83+
*/
84+
public double getArcTolerance() {
85+
return arcTolerance;
86+
}
87+
88+
/**
89+
* Sets arc tolerance which is the maximum difference between the true and the faceted representation of curves
90+
* (arcs) in units. Used as the criterion of a good approximation of rounded line joins and line caps.
91+
*
92+
* <p>
93+
* Since flattened paths can never perfectly represent arcs, this field/property specifies a maximum acceptable
94+
* imprecision (tolerance) when arcs are approximated in an offsetting operation. Smaller values will increase
95+
* smoothness up to a point though at a cost of performance and in creating more vertices to construct the arc.
96+
*
97+
* @param arcTolerance maximum difference between the true and the faceted representation of arcs
98+
*
99+
* @return this {@link PathOffsetApproximationProperties} instance
100+
*/
101+
public PathOffsetApproximationProperties setArcTolerance(double arcTolerance) {
102+
this.arcTolerance = arcTolerance;
103+
return this;
104+
}
105+
}

0 commit comments

Comments
 (0)