Debian Codegraph @

src/main/java/org/jfree/pdf/shading/AxialShading.java

raw
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.shading;
33
34 import org.jfree.pdf.function.Function;
35 import org.jfree.pdf.util.Args;
36 import org.jfree.pdf.util.PDFUtils;
37
38 /**
39 * An axial shading.
40 */
41 public final class AxialShading extends Shading {
42
43 /** Coordinates (x0, y0, x1, y1) defining the axis. */
44 private double[] coords;
45
46 /** The shading function. */
47 private Function function;
48
49 /** The domain. */
50 private double[] domain;
51
52 /** The extend flags (two of them). */
53 private boolean[] extend;
54
55 /**
56 * Creates a new axial shading.
57 *
58 * @param number the object number.
59 * @param coords the coordinates of the axis (x1, y1, x2, y2).
60 * @param function the function object for the shading ({@code null} not
61 * permitted).
62 */
63 public AxialShading(int number, double[] coords, Function function) {
64 super(number, ShadingType.AXIAL);
65 Args.arrayMustHaveLength(4, coords, "coords");
66 Args.nullNotPermitted(function, "function");
67 this.dictionary.put("/ColorSpace", "/DeviceRGB");
68 setCoords(coords);
69 setFunction(function);
70 setExtend(new boolean[] {true, true});
71 this.domain = new double[] {0.0, 1.0};
72 }
73
74 /**
75 * Returns a copy of the axis coordinates array {@code (x1, y1, x2, y2)}.
76 *
77 * @return A copy of the axis coordinates array (never {@code null}).
78 */
79 public double[] getCoords() {
80 return this.coords.clone();
81 }
82
83 /**
84 * Sets the axis coordinates array {@code (x1, y1, x2, y2)}.
85 *
86 * @param coords the axis coordinates ({@code null} not permitted).
87 */
88 public void setCoords(double[] coords) {
89 Args.arrayMustHaveLength(4, coords, "coords");
90 this.coords = coords.clone();
91 this.dictionary.put("/Coords", PDFUtils.toPDFArray(this.coords));
92 }
93
94 /**
95 * Returns the function for this shading.
96 *
97 * @return The function (never {@code null}).
98 */
99 public Function getFunction() {
100 return this.function;
101 }
102
103 /**
104 * Sets the function for this shading.
105 *
106 * @param function the function ({@code null} not permitted).
107 */
108 public void setFunction(Function function) {
109 Args.nullNotPermitted(function, "function");
110 this.function = function;
111 this.dictionary.put("/Function", this.function);
112 }
113
114 /**
115 * Returns the function domain. The default value is {@code [0.0, 1.0]}.
116 *
117 * @return The function domain.
118 */
119 public double[] getDomain() {
120 return this.domain.clone();
121 }
122
123 /**
124 * Sets the domain.
125 *
126 * @param domain the domain (array must have length 2).
127 */
128 public void setDomain(double[] domain) {
129 Args.arrayMustHaveLength(2, domain, "domain");
130 this.domain = domain.clone();
131 this.dictionary.put("/Domain", PDFUtils.toPDFArray(this.domain));
132 }
133
134 /**
135 * Returns the extend array.
136 *
137 * @return The extend array.
138 */
139 public boolean[] getExtend() {
140 return this.extend.clone();
141 }
142
143 /**
144 * Sets the extend array.
145 *
146 * @param extend the extend array (must have length 2).
147 */
148 public void setExtend(boolean[] extend) {
149 Args.arrayMustHaveLength(2, extend, "extend");
150 this.extend = extend.clone();
151 this.dictionary.put("/Extend", PDFUtils.toPDFArray(this.extend));
152 }
153
154 }