Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2018 iText Group NV
Authors: Bruno Lowagie, Paulo Soares, et al.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://itextpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using iText.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the iText software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping iText with a closed
source product.
For more information, please contact iText Software Corp. at this
address: [email protected]
*/
package com.itextpdf.kernel.pdf.colorspace;
import com.itextpdf.kernel.PdfException;
import com.itextpdf.kernel.pdf.PdfArray;
import com.itextpdf.kernel.pdf.PdfDictionary;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.PdfNumber;
import com.itextpdf.kernel.pdf.PdfObject;
import com.itextpdf.kernel.pdf.PdfString;
import com.itextpdf.kernel.pdf.function.PdfFunction;
import java.util.Arrays;
import java.util.List;
public abstract class PdfSpecialCs extends PdfColorSpace {
private static final long serialVersionUID = -2725455900398492836L;
protected PdfSpecialCs(PdfArray pdfObject) {
super(pdfObject);
}
/**
* To manually flush a {@code PdfObject} behind this wrapper, you have to ensure
* that this object is added to the document, i.e. it has an indirect reference.
* Basically this means that before flushing you need to explicitly call {@link #makeIndirect(PdfDocument)}.
* For example: wrapperInstance.makeIndirect(document).flush();
* Note that not every wrapper require this, only those that have such warning in documentation.
*/
@Override
public void flush() {
super.flush();
}
@Override
protected boolean isWrappedObjectMustBeIndirect() {
return true;
}
public static class Indexed extends PdfSpecialCs {
private static final long serialVersionUID = -1155418938167317916L;
public Indexed(PdfArray pdfObject) {
super(pdfObject);
}
public Indexed(PdfObject base, int hival, PdfString lookup) {
this(getIndexedCsArray(base, hival, lookup));
}
@Override
public int getNumberOfComponents() {
return 1;
}
public PdfColorSpace getBaseCs() {
return makeColorSpace(((PdfArray)getPdfObject()).get(1));
}
private static PdfArray getIndexedCsArray(PdfObject base, int hival, PdfString lookup) {
PdfArray indexed = new PdfArray();
indexed.add(PdfName.Indexed);
indexed.add(base);
indexed.add(new PdfNumber(hival));
indexed.add(lookup.setHexWriting(true));
return indexed;
}
}
public static class Separation extends PdfSpecialCs {
private static final long serialVersionUID = 4259327393838350842L;
public Separation(PdfArray pdfObject) {
super(pdfObject);
}
public Separation(PdfName name, PdfObject alternateSpace, PdfObject tintTransform) {
this(getSeparationCsArray(name, alternateSpace, tintTransform));
}
public Separation(String name, PdfColorSpace alternateSpace, PdfFunction tintTransform) {
this(new PdfName(name), alternateSpace.getPdfObject(), tintTransform.getPdfObject());
if (!tintTransform.checkCompatibilityWithColorSpace(alternateSpace)) {
throw new PdfException(PdfException.FunctionIsNotCompatibleWitColorSpace, this);
}
}
@Override
public int getNumberOfComponents() {
return 1;
}
public PdfColorSpace getBaseCs() {
return makeColorSpace(((PdfArray)getPdfObject()).get(2));
}
public PdfName getName() {
return ((PdfArray)getPdfObject()).getAsName(1);
}
private static PdfArray getSeparationCsArray(PdfName name, PdfObject alternateSpace, PdfObject tintTransform) {
PdfArray separation = new PdfArray();
separation.add(PdfName.Separation);
separation.add(name);
separation.add(alternateSpace);
separation.add(tintTransform);
return separation;
}
}
public static class DeviceN extends PdfSpecialCs {
private static final long serialVersionUID = 4051693146595260270L;
protected int numOfComponents = 0;
public DeviceN(PdfArray pdfObject) {
super(pdfObject);
numOfComponents = pdfObject.getAsArray(1).size();
}
public DeviceN(PdfArray names, PdfObject alternateSpace, PdfObject tintTransform) {
this(getDeviceNCsArray(names, alternateSpace, tintTransform));
}
public DeviceN(List names, PdfColorSpace alternateSpace, PdfFunction tintTransform) {
this(new PdfArray(names, true), alternateSpace.getPdfObject(), tintTransform.getPdfObject());
if (tintTransform.getInputSize() != getNumberOfComponents() || tintTransform.getOutputSize() != alternateSpace.getNumberOfComponents()) {
throw new PdfException(PdfException.FunctionIsNotCompatibleWitColorSpace, this);
}
}
@Override
public int getNumberOfComponents() {
return numOfComponents;
}
public PdfColorSpace getBaseCs() {
return makeColorSpace(((PdfArray)getPdfObject()).get(2));
}
public PdfArray getNames() {
return ((PdfArray)getPdfObject()).getAsArray(1);
}
protected static PdfArray getDeviceNCsArray(PdfArray names, PdfObject alternateSpace, PdfObject tintTransform) {
PdfArray deviceN = new PdfArray();
deviceN.add(PdfName.DeviceN);
deviceN.add(names);
deviceN.add(alternateSpace);
deviceN.add(tintTransform);
return deviceN;
}
}
public static class NChannel extends DeviceN {
private static final long serialVersionUID = 5352964946869757972L;
public NChannel(PdfArray pdfObject) {
super(pdfObject);
}
public NChannel(PdfArray names, PdfObject alternateSpace, PdfObject tintTransform, PdfDictionary attributes) {
this(getNChannelCsArray(names, alternateSpace, tintTransform, attributes));
}
public NChannel(List 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(PdfException.FunctionIsNotCompatibleWitColorSpace, this);
}
}
protected static PdfArray getNChannelCsArray(PdfArray names, PdfObject alternateSpace, PdfObject tintTransform, PdfDictionary attributes) {
PdfArray nChannel = getDeviceNCsArray(names, alternateSpace, tintTransform);
nChannel.add(attributes);
return nChannel;
}
}
public static class Pattern extends PdfColorSpace {
private static final long serialVersionUID = 8057478102447278706L;
@Override
protected boolean isWrappedObjectMustBeIndirect() {
return false;
}
public Pattern() {
super(PdfName.Pattern);
}
protected Pattern(PdfObject pdfObj) {
super(pdfObj);
}
@Override
public int getNumberOfComponents() {
return 0;
}
}
public static class UncoloredTilingPattern extends Pattern {
private static final long serialVersionUID = -9030226298201261021L;
/**
* To manually flush a {@code PdfObject} behind this wrapper, you have to ensure
* that this object is added to the document, i.e. it has an indirect reference.
* Basically this means that before flushing you need to explicitly call {@link #makeIndirect(PdfDocument)}.
* For example: wrapperInstance.makeIndirect(document).flush();
* Note that not every wrapper require this, only those that have such warning in documentation.
*/
@Override
public void flush() {
super.flush();
}
@Override
protected boolean isWrappedObjectMustBeIndirect() {
return true;
}
public UncoloredTilingPattern(PdfArray pdfObject) {
super(pdfObject);
}
public UncoloredTilingPattern(PdfColorSpace underlyingColorSpace) {
super(new PdfArray(Arrays.asList(PdfName.Pattern, underlyingColorSpace.getPdfObject())));
}
@Override
public int getNumberOfComponents() {
return PdfColorSpace.makeColorSpace(((PdfArray) getPdfObject()).get(1)).getNumberOfComponents();
}
public PdfColorSpace getUnderlyingColorSpace() {
return PdfColorSpace.makeColorSpace(((PdfArray) getPdfObject()).get(1));
}
}
}