Skip to content

Commit c77860f

Browse files
author
glenn.volckaert
committed
Add getAsPdfObject to IPdfFunction to avoid casting
DEVSIX-3538
1 parent 1798b0b commit c77860f

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/colorspace/PdfSpecialCs.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ This file is part of the iText (R) project.
5252
import com.itextpdf.kernel.pdf.PdfNumber;
5353
import com.itextpdf.kernel.pdf.PdfObject;
5454
import com.itextpdf.kernel.pdf.PdfString;
55-
import com.itextpdf.kernel.pdf.function.AbstractPdfFunction;
5655
import com.itextpdf.kernel.pdf.function.IPdfFunction;
5756
import com.itextpdf.kernel.pdf.function.PdfFunction;
5857
import com.itextpdf.kernel.pdf.function.PdfFunctionFactory;
@@ -155,7 +154,7 @@ public Separation(String name, PdfColorSpace alternateSpace, PdfFunction tintTra
155154
*/
156155
public Separation(String name, PdfColorSpace alternateSpace, IPdfFunction tintTransform) {
157156
this(new PdfName(name), alternateSpace.getPdfObject(),
158-
((AbstractPdfFunction<PdfDictionary>)tintTransform).getPdfObject());
157+
tintTransform.getAsPdfObject());
159158
if (!tintTransform.checkCompatibilityWithColorSpace(alternateSpace)) {
160159
throw new PdfException(
161160
KernelExceptionMessageConstant.FUNCTION_IS_NOT_COMPATIBLE_WITH_COLOR_SPACE, this);
@@ -238,7 +237,7 @@ public DeviceN(List<String> names, PdfColorSpace alternateSpace, PdfFunction tin
238237
*/
239238
public DeviceN(List<String> names, PdfColorSpace alternateSpace, IPdfFunction tintTransform) {
240239
this(new PdfArray(names, true), alternateSpace.getPdfObject(),
241-
((AbstractPdfFunction<PdfDictionary>)tintTransform).getPdfObject());
240+
tintTransform.getAsPdfObject());
242241
if (tintTransform.getInputSize() != numOfComponents ||
243242
tintTransform.getOutputSize() != alternateSpace.getNumberOfComponents()) {
244243
throw new PdfException(
@@ -313,7 +312,7 @@ public NChannel(List<String> names, PdfColorSpace alternateSpace, PdfFunction ti
313312
public NChannel(List<String> names, PdfColorSpace alternateSpace, IPdfFunction tintTransform,
314313
PdfDictionary attributes) {
315314
this(new PdfArray(names, true), alternateSpace.getPdfObject(),
316-
((AbstractPdfFunction<PdfDictionary>)tintTransform).getPdfObject(), attributes);
315+
tintTransform.getAsPdfObject(), attributes);
317316
if (tintTransform.getInputSize() != 1 ||
318317
tintTransform.getOutputSize() != alternateSpace.getNumberOfComponents()) {
319318
throw new PdfException(

kernel/src/main/java/com/itextpdf/kernel/pdf/function/AbstractPdfFunction.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ This file is part of the iText (R) project.
4848
import com.itextpdf.kernel.pdf.PdfDictionary;
4949
import com.itextpdf.kernel.pdf.PdfName;
5050
import com.itextpdf.kernel.pdf.PdfNumber;
51+
import com.itextpdf.kernel.pdf.PdfObject;
5152
import com.itextpdf.kernel.pdf.PdfObjectWrapper;
5253
import com.itextpdf.kernel.pdf.PdfStream;
5354
import com.itextpdf.kernel.pdf.colorspace.PdfColorSpace;
@@ -105,14 +106,6 @@ protected AbstractPdfFunction(T pdfObject) {
105106
range = rangeObj == null ? null : rangeObj.toDoubleArray();
106107
}
107108

108-
/**
109-
* The function type, (see ISO-320001 Table 38)
110-
functionType = pdfObject.getAsNumber(PdfName.FunctionType).intValue();
111-
domain = pdfObject.getAsArray(PdfName.Domain).toDoubleArray();
112-
final PdfArray rangeObj = pdfObject.getAsArray(PdfName.Range);
113-
range = rangeObj == null ? null : rangeObj.toDoubleArray();
114-
}
115-
116109
/**
117110
* The function type, (see ISO-320001 Table 38).
118111
*
@@ -283,7 +276,6 @@ public byte[] calculateFromByteArray(byte[] bytes, int offset, int length, int w
283276
return actualOutputConvertor.convert(outValues);
284277
}
285278

286-
287279
/**
288280
* Clip input values to the allowed domain.
289281
*
@@ -324,6 +316,11 @@ public double[] clipOutput(double[] input) {
324316
return clip(input, range);
325317
}
326318

319+
@Override
320+
public PdfObject getAsPdfObject() {
321+
return super.getPdfObject();
322+
}
323+
327324
protected static double[] clip(double[] values, double[] limits) {
328325
assert (values.length * 2 == limits.length);
329326

kernel/src/main/java/com/itextpdf/kernel/pdf/function/IPdfFunction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ This file is part of the iText (R) project.
4343
*/
4444
package com.itextpdf.kernel.pdf.function;
4545

46+
import com.itextpdf.kernel.pdf.PdfObject;
4647
import com.itextpdf.kernel.pdf.colorspace.PdfColorSpace;
4748
import com.itextpdf.kernel.pdf.function.BaseInputOutPutConvertors.IInputConversionFunction;
4849
import com.itextpdf.kernel.pdf.function.BaseInputOutPutConvertors.IOutputConversionFunction;
@@ -86,4 +87,6 @@ byte[] calculateFromByteArray(byte[] bytes, int offset, int length, int wordSize
8687
double[] clipInput(double[] input);
8788

8889
double[] clipOutput(double[] input);
90+
91+
PdfObject getAsPdfObject();
8992
}

0 commit comments

Comments
 (0)