|
| 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