| 1 |
/* ===================================================================== |
| 2 |
* JFreePDF : a fast, light-weight PDF library for the Java(tm) platform |
| 3 |
* ===================================================================== |
| 4 |
* |
| 5 |
* (C)opyright 2013-2022, by David Gilbert. All rights reserved. |
| 6 |
* |
| 7 |
* https://github.com/jfree/orsonpdf |
| 8 |
* |
| 9 |
* This program is free software: you can redistribute it and/or modify |
| 10 |
* it under the terms of the GNU General Public License as published by |
| 11 |
* the Free Software Foundation, either version 3 of the License, or |
| 12 |
* (at your option) any later version. |
| 13 |
* |
| 14 |
* This program is distributed in the hope that it will be useful, |
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
* GNU General Public License for more details. |
| 18 |
* |
| 19 |
* You should have received a copy of the GNU General Public License |
| 20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
* |
| 22 |
* [Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
| 23 |
* Other names may be trademarks of their respective owners.] |
| 24 |
* |
| 25 |
* If you do not wish to be bound by the terms of the GPL, an alternative |
| 26 |
* runtime license is available to JFree sponsors: |
| 27 |
* |
| 28 |
* https://github.com/sponsors/jfree |
| 29 |
* |
| 30 |
*/ |
| 31 |
|
| 32 |
package org.jfree.pdf.function; |
| 33 |
|
| 34 |
import org.jfree.pdf.PDFGraphics2D; |
| 35 |
import org.jfree.pdf.dictionary.Dictionary; |
| 36 |
import org.jfree.pdf.internal.PDFObject; |
| 37 |
import org.jfree.pdf.util.Args; |
| 38 |
import org.jfree.pdf.util.PDFUtils; |
| 39 |
|
| 40 |
/** |
| 41 |
* A PDF function object. For the {@link PDFGraphics2D} class, only |
| 42 |
* {@code EXPONENTIAL_INTERPOLATION} and {@code STITCHING} are used |
| 43 |
* so far (to support gradient paint implementations). |
| 44 |
*/ |
| 45 |
public abstract class Function extends PDFObject { |
| 46 |
|
| 47 |
/** The function type. */ |
| 48 |
private final FunctionType functionType; |
| 49 |
|
| 50 |
/** The function domain. */ |
| 51 |
private double[] domain; |
| 52 |
|
| 53 |
/** The function dictionary. */ |
| 54 |
protected Dictionary dictionary; |
| 55 |
|
| 56 |
/** |
| 57 |
* Creates a new function. |
| 58 |
* |
| 59 |
* @param number the PDF object number. |
| 60 |
* @param functionType the function type ({@code null} not permitted). |
| 61 |
*/ |
| 62 |
protected Function(int number, FunctionType functionType) { |
| 63 |
super(number); |
| 64 |
Args.nullNotPermitted(functionType, "functionType"); |
| 65 |
this.functionType = functionType; |
| 66 |
this.domain = new double[] {0.0, 1.0}; |
| 67 |
this.dictionary = new Dictionary(); |
| 68 |
this.dictionary.put("/Domain", PDFUtils.toPDFArray(this.domain)); |
| 69 |
this.dictionary.put("/FunctionType", String.valueOf( |
| 70 |
functionType.getNumber())); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Returns the function type. |
| 75 |
* |
| 76 |
* @return The function type (never {@code null}). |
| 77 |
*/ |
| 78 |
public FunctionType getFunctionType() { |
| 79 |
return this.functionType; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Returns the function domain. |
| 84 |
* |
| 85 |
* @return The function domain (never {@code null}). |
| 86 |
*/ |
| 87 |
public double[] getDomain() { |
| 88 |
return this.domain.clone(); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Sets the domain for the function. |
| 93 |
* |
| 94 |
* @param domain the domain ({@code null} not permitted). |
| 95 |
*/ |
| 96 |
public void setDomain(double[] domain) { |
| 97 |
Args.nullNotPermitted(domain, "domain"); |
| 98 |
this.domain = domain.clone(); |
| 99 |
this.dictionary.put("/Domain", PDFUtils.toPDFArray(this.domain)); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Returns the bytes that go between the 'obj' and 'endobj' in the |
| 104 |
* PDF output for this object. |
| 105 |
* |
| 106 |
* @return A byte array. |
| 107 |
*/ |
| 108 |
@Override |
| 109 |
public byte[] getObjectBytes() { |
| 110 |
return this.dictionary.toPDFBytes(); |
| 111 |
} |
| 112 |
|
| 113 |
} |