Skip to content

Commit

Permalink
Remove usage of deprected PdfFunction type and derivates
Browse files Browse the repository at this point in the history
DEVSIX-6771
  • Loading branch information
introfog committed Feb 28, 2023
1 parent dfe37db commit 92fb646
Show file tree
Hide file tree
Showing 18 changed files with 222 additions and 236 deletions.
16 changes: 0 additions & 16 deletions kernel/src/main/java/com/itextpdf/kernel/colors/DeviceN.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ This file is part of the iText (R) project.
import com.itextpdf.kernel.pdf.colorspace.PdfColorSpace;
import com.itextpdf.kernel.pdf.colorspace.PdfSpecialCs;
import com.itextpdf.kernel.pdf.function.IPdfFunction;
import com.itextpdf.kernel.pdf.function.PdfFunction;

import java.util.Arrays;
import java.util.List;
Expand All @@ -62,21 +61,6 @@ public DeviceN(PdfSpecialCs.DeviceN cs, float[] value) {
super(cs, value);
}

/**
* Creates a color in new DeviceN color space.
*
* @param names the names oif the components
* @param alternateCs the alternate color space
* @param tintTransform the function to transform color to the alternate color space
* @param value the values for the components of this color
*
* @deprecated Use constructor {@link #DeviceN(List, PdfColorSpace, IPdfFunction, float[])} DeviceN} instead.
*/
@Deprecated
public DeviceN(List<String> names, PdfColorSpace alternateCs, PdfFunction tintTransform, float[] value) {
this(new PdfSpecialCs.DeviceN(names, alternateCs, tintTransform), value);
}

/**
* Creates a color in a new DeviceN color space.
*
Expand Down
18 changes: 0 additions & 18 deletions kernel/src/main/java/com/itextpdf/kernel/colors/Separation.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ This file is part of the iText (R) project.
import com.itextpdf.kernel.pdf.colorspace.PdfColorSpace;
import com.itextpdf.kernel.pdf.colorspace.PdfSpecialCs;
import com.itextpdf.kernel.pdf.function.IPdfFunction;
import com.itextpdf.kernel.pdf.function.PdfFunction;

public class Separation extends Color {

Expand All @@ -59,22 +58,6 @@ public Separation(PdfSpecialCs.Separation cs, float value) {
super(cs, new float[]{value});
}

/**
* Creates a color in a new separation color space.
*
* @param name the name for the separation color
* @param alternateCs the alternative color space
* @param tintTransform the function to transform color to the alternate colorspace
* @param value the color value
*
* @deprecated Use constructor {@link #Separation(String, PdfColorSpace, IPdfFunction, float)} Separation}
* instead
*/
@Deprecated
public Separation(String name, PdfColorSpace alternateCs, PdfFunction tintTransform, float value) {
this(new PdfSpecialCs.Separation(name, alternateCs, tintTransform), value);
}

/**
* Creates a color in a new separation color space.
*
Expand All @@ -86,5 +69,4 @@ public Separation(String name, PdfColorSpace alternateCs, PdfFunction tintTransf
public Separation(String name, PdfColorSpace alternateCs, IPdfFunction tintTransform, float value) {
this(new PdfSpecialCs.Separation(name, alternateCs, tintTransform), value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ This file is part of the iText (R) project.
import com.itextpdf.io.logs.IoLogMessageConstant;
import com.itextpdf.kernel.colors.Color;
import com.itextpdf.kernel.colors.PatternColor;
import com.itextpdf.kernel.colors.gradients.GradientColorStop.HintOffsetType;
import com.itextpdf.kernel.colors.gradients.GradientColorStop.OffsetType;
import com.itextpdf.kernel.geom.AffineTransform;
import com.itextpdf.kernel.geom.NoninvertibleTransformException;
import com.itextpdf.kernel.geom.Point;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfArray;
import com.itextpdf.kernel.pdf.PdfDictionary;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfNumber;
import com.itextpdf.kernel.pdf.colorspace.PdfDeviceCs;
import com.itextpdf.kernel.pdf.colorspace.PdfPattern;
import com.itextpdf.kernel.pdf.colorspace.PdfShading;
import com.itextpdf.kernel.pdf.function.PdfFunction;
import com.itextpdf.kernel.colors.gradients.GradientColorStop.HintOffsetType;
import com.itextpdf.kernel.colors.gradients.GradientColorStop.OffsetType;
import com.itextpdf.kernel.pdf.function.AbstractPdfFunction;
import com.itextpdf.kernel.pdf.function.IPdfFunction;
import com.itextpdf.kernel.pdf.function.PdfType2Function;
import com.itextpdf.kernel.pdf.function.PdfType3Function;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -552,11 +555,11 @@ private static List<GradientColorStop> adjustNormalizedStopsToCoverDomain(List<G
return adjustedStops;
}

private static PdfFunction constructFunction(List<GradientColorStop> toConstruct) {
private static IPdfFunction constructFunction(List<GradientColorStop> toConstruct) {
int functionsAmount = toConstruct.size() - 1;

double[] bounds = new double[functionsAmount - 1];
List<PdfFunction> type2Functions = new ArrayList<>(functionsAmount);
List<AbstractPdfFunction<? extends PdfDictionary>> type2Functions = new ArrayList<>(functionsAmount);

GradientColorStop currentStop;
GradientColorStop nextStop = toConstruct.get(0);
Expand All @@ -579,11 +582,12 @@ private static PdfFunction constructFunction(List<GradientColorStop> toConstruct
encode[i + 1] = 1d;
}

return new PdfFunction.Type3(new PdfArray(new double[] {domainStart, domainEnd}), null,
type2Functions, new PdfArray(bounds), new PdfArray(encode));
return new PdfType3Function(new double[] {domainStart, domainEnd}, null, type2Functions, bounds, encode);
}

private static PdfFunction constructSingleGradientSegmentFunction(GradientColorStop from, GradientColorStop to) {
private static AbstractPdfFunction<? extends PdfDictionary> constructSingleGradientSegmentFunction(
GradientColorStop from, GradientColorStop to) {

double exponent = 1d;
float[] fromColor = from.getRgbArray();
float[] toColor = to.getRgbArray();
Expand All @@ -598,8 +602,7 @@ private static PdfFunction constructSingleGradientSegmentFunction(GradientColorS
exponent = Math.log(0.5) / Math.log(hintOffset);
}
}
return new PdfFunction.Type2(new PdfArray(new float[] {0f, 1f}), null,
new PdfArray(fromColor), new PdfArray(toColor), new PdfNumber(exponent));
return new PdfType2Function(new float[] {0f, 1f}, null, fromColor, toColor, exponent);
}

private static PdfArray createCoordsPdfArray(Point[] coordsPoints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ This file is part of the iText (R) project.
*/
package com.itextpdf.kernel.pdf.colorspace;

import com.itextpdf.kernel.exceptions.PdfException;
import com.itextpdf.kernel.exceptions.KernelExceptionMessageConstant;
import com.itextpdf.kernel.exceptions.PdfException;
import com.itextpdf.kernel.pdf.PdfArray;
import com.itextpdf.kernel.pdf.PdfDictionary;
import com.itextpdf.kernel.pdf.PdfDocument;
Expand All @@ -53,14 +53,14 @@ This file is part of the iText (R) project.
import com.itextpdf.kernel.pdf.PdfObject;
import com.itextpdf.kernel.pdf.PdfObjectWrapper;
import com.itextpdf.kernel.pdf.PdfStream;
import com.itextpdf.kernel.pdf.function.PdfFunction;
import com.itextpdf.kernel.pdf.function.IPdfFunction;
import com.itextpdf.kernel.pdf.function.PdfType2Function;

/**
* The abstract PdfShading class that represents the Shading Dictionary PDF object.
*/
public abstract class PdfShading extends PdfObjectWrapper<PdfDictionary> {



/**
* constants of shading type (see ISO-320001 Table 78)
*/
Expand Down Expand Up @@ -196,23 +196,23 @@ public PdfObject getFunction() {
* Sets the function that represents color transitions
* across the shading geometry as one object.
*
* @param function The {@link PdfFunction} to set.
* @param function The {@link IPdfFunction} to set.
*/
public void setFunction(PdfFunction function) {
getPdfObject().put(PdfName.Function, function.getPdfObject());
public void setFunction(IPdfFunction function) {
getPdfObject().put(PdfName.Function, function.getAsPdfObject());
setModified();
}

/**
* Sets the function object that represents color transitions
* across the shading geometry as an array of functions.
*
* @param functions The array of {@link PdfFunction} to be set.
* @param functions The array of {@link IPdfFunction} to be set.
*/
public void setFunction(PdfFunction[] functions) {
public void setFunction(IPdfFunction[] functions) {
PdfArray arr = new PdfArray();
for (PdfFunction func : functions) {
arr.add(func.getPdfObject());
for (IPdfFunction func : functions) {
arr.add(func.getAsPdfObject());
}
getPdfObject().put(PdfName.Function, arr);
setModified();
Expand Down Expand Up @@ -258,19 +258,19 @@ protected FunctionBased(PdfDictionary pdfDictionary) {
* Creates the new instance of the class.
*
* @param colorSpace the {@link PdfColorSpace} object in which colour values shall be expressed.
* @param function the {@link PdfFunction}, that is used to calculate color transitions.
* @param function the {@link IPdfFunction}, that is used to calculate color transitions.
*/
public FunctionBased(PdfColorSpace colorSpace, PdfFunction function) {
public FunctionBased(PdfColorSpace colorSpace, IPdfFunction function) {
this(colorSpace.getPdfObject(), function);
}

/**
* Creates the new instance of the class.
*
* @param colorSpace the {@link PdfObject}, that represents color space in which colour values shall be expressed.
* @param function the {@link PdfFunction}, that is used to calculate color transitions.
* @param function the {@link IPdfFunction}, that is used to calculate color transitions.
*/
public FunctionBased(PdfObject colorSpace, PdfFunction function) {
public FunctionBased(PdfObject colorSpace, IPdfFunction function) {
super(new PdfDictionary(), ShadingType.FUNCTION_BASED, PdfColorSpace.makeColorSpace(colorSpace));

setFunction(function);
Expand Down Expand Up @@ -380,8 +380,7 @@ public Axial(PdfColorSpace cs, float x0, float y0, float[] color0, float x1, flo
super(new PdfDictionary(), ShadingType.AXIAL, cs);

setCoords(x0, y0, x1, y1);
PdfFunction func = new PdfFunction.Type2(new PdfArray(new float[] {0, 1}), null,
new PdfArray(color0), new PdfArray(color1), new PdfNumber(1));
IPdfFunction func = new PdfType2Function(new float[] {0, 1}, null, color0, color1, 1);
setFunction(func);
}

Expand Down Expand Up @@ -415,9 +414,9 @@ public Axial(PdfColorSpace cs, float x0, float y0, float[] color0, float x1, flo
* The special Pattern space isn't excepted.
* @param coords the {@link PdfArray} of four numbers [x0 y0 x1 y1] that specified the starting
* and the endings coordinates of thew axis, expressed in the shading's target coordinate space.
* @param function the {@link PdfFunction} object, that is used to calculate color transitions.
* @param function the {@link IPdfFunction} object, that is used to calculate color transitions.
*/
public Axial(PdfColorSpace cs, PdfArray coords, PdfFunction function) {
public Axial(PdfColorSpace cs, PdfArray coords, IPdfFunction function) {
this(cs, coords, null, function);
}

Expand All @@ -432,9 +431,9 @@ public Axial(PdfColorSpace cs, PdfArray coords, PdfFunction function) {
* @param domain the {@link PdfArray} of two numbers [t0 t1] specifying the limiting values
* of a parametric variable t which is considered to vary linearly between
* these two values and becomes the input argument to the colour function.
* @param function the {@link PdfFunction} object, that is used to calculate color transitions.
* @param function the {@link IPdfFunction} object, that is used to calculate color transitions.
*/
public Axial(PdfColorSpace cs, PdfArray coords, PdfArray domain, PdfFunction function) {
public Axial(PdfColorSpace cs, PdfArray coords, PdfArray domain, IPdfFunction function) {
super(new PdfDictionary(), ShadingType.AXIAL, cs);
setCoords(coords);
if (domain != null) {
Expand Down Expand Up @@ -592,8 +591,8 @@ public Radial(PdfColorSpace cs, float x0, float y0, float r0, float[] color0, fl
super(new PdfDictionary(), ShadingType.RADIAL, cs);

setCoords(x0, y0, r0, x1, y1, r1);
PdfFunction func = new PdfFunction.Type2(new PdfArray(new float[] {0, 1}), null,
new PdfArray(color0), new PdfArray(color1), new PdfNumber(1));
IPdfFunction func = new PdfType2Function(new float[] {0, 1}, null,
color0, color1, 1);
setFunction(func);
}

Expand Down Expand Up @@ -637,9 +636,9 @@ public Radial(PdfColorSpace cs, float x0, float y0, float r0, float[] color0, fl
* The radii r0 and r1 shall both be greater than or equal to 0.
* If one radius is 0, the corresponding circle shall be treated as a point;
* if both are 0, nothing shall be painted.
* @param function the {@link PdfFunction} object, that is used to calculate color transitions.
* @param function the {@link IPdfFunction} object, that is used to calculate color transitions.
*/
public Radial(PdfColorSpace cs, PdfArray coords, PdfFunction function) {
public Radial(PdfColorSpace cs, PdfArray coords, IPdfFunction function) {
super(new PdfDictionary(), ShadingType.RADIAL, cs);
setCoords(coords);
setFunction(function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ This file is part of the iText (R) project.
import com.itextpdf.kernel.pdf.PdfObject;
import com.itextpdf.kernel.pdf.PdfString;
import com.itextpdf.kernel.pdf.function.IPdfFunction;
import com.itextpdf.kernel.pdf.function.PdfFunction;
import com.itextpdf.kernel.pdf.function.PdfFunctionFactory;

import java.util.Arrays;
Expand Down Expand Up @@ -125,25 +124,6 @@ public Separation(PdfName name, PdfObject alternateSpace, PdfObject tintTransfor
this(getSeparationCsArray(name, alternateSpace, tintTransform));
}

/**
* Creates a new separation color space.
*
* @param name The name for the separation color
* @param alternateSpace The alternate colorspace
* @param tintTransform The function how the transform colors in the separation color space
* to the alternate color space
* @deprecated This constructor has been replaced
* by {@link #Separation(String, PdfColorSpace, IPdfFunction)}
*/
@Deprecated
public Separation(String name, PdfColorSpace alternateSpace, PdfFunction tintTransform) {
this(new PdfName(name), alternateSpace.getPdfObject(), tintTransform.getPdfObject());
if (!tintTransform.checkCompatibilityWithColorSpace(alternateSpace)) {
throw new PdfException(
KernelExceptionMessageConstant.FUNCTION_IS_NOT_COMPATIBLE_WITH_COLOR_SPACE, this);
}
}

/**
* Creates a new separation color space.
*
Expand Down Expand Up @@ -208,26 +188,6 @@ public DeviceN(PdfArray names, PdfObject alternateSpace, PdfObject tintTransform
this(getDeviceNCsArray(names, alternateSpace, tintTransform));
}

/**
* Creates a new DeviceN colorspace.
*
* @param names the names of the components
* @param alternateSpace the alternate colorspace
* @param tintTransform the function to transform colors to the alternate colorspace
*
* @deprecated Use constructor {@link #DeviceN(List, PdfColorSpace, IPdfFunction)} instead.
*/

@Deprecated
public DeviceN(List<String> names, PdfColorSpace alternateSpace, PdfFunction tintTransform) {
this(new PdfArray(names, true), alternateSpace.getPdfObject(), tintTransform.getPdfObject());
if (tintTransform.getInputSize() != numOfComponents ||
tintTransform.getOutputSize() != alternateSpace.getNumberOfComponents()) {
throw new PdfException(
KernelExceptionMessageConstant.FUNCTION_IS_NOT_COMPATIBLE_WITH_COLOR_SPACE, this);
}
}

/**
* Creates a new DiviceN colorspace.
*
Expand Down Expand Up @@ -280,27 +240,6 @@ public NChannel(PdfArray names, PdfObject alternateSpace, PdfObject tintTransfor
this(getNChannelCsArray(names, alternateSpace, tintTransform, attributes));
}

/**
* Creates a new NChannel colorspace.
*
* @param names the names for the components
* @param alternateSpace the alternative colorspace
* @param tintTransform the function to transform colors to the alternate color space
* @param attributes NChannel specific attributes
* @deprecated Use constructor {@link #NChannel(PdfArray, PdfObject, PdfObject, PdfDictionary) NChannel} instead
*/

@Deprecated
public NChannel(List<String> names, PdfColorSpace alternateSpace, PdfFunction tintTransform,
PdfDictionary attributes) {
this(new PdfArray(names, true), alternateSpace.getPdfObject(), tintTransform.getPdfObject(), attributes);
if (tintTransform.getInputSize() != 1 ||
tintTransform.getOutputSize() != alternateSpace.getNumberOfComponents()) {
throw new PdfException(
KernelExceptionMessageConstant.FUNCTION_IS_NOT_COMPATIBLE_WITH_COLOR_SPACE, this);
}
}

/**
* Creates a new NChannel colorspace.
*
Expand Down
Loading

0 comments on commit 92fb646

Please sign in to comment.