| 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.internal; |
| 33 |
|
| 34 |
import java.awt.geom.AffineTransform; |
| 35 |
import org.jfree.pdf.dictionary.Dictionary; |
| 36 |
import org.jfree.pdf.shading.Shading; |
| 37 |
import org.jfree.pdf.util.Args; |
| 38 |
import org.jfree.pdf.util.PDFUtils; |
| 39 |
|
| 40 |
/** |
| 41 |
* A pattern object (see the concrete subclass {@link ShadingPattern}). |
| 42 |
*/ |
| 43 |
public abstract class Pattern extends PDFObject { |
| 44 |
|
| 45 |
/** |
| 46 |
* A shading pattern object. |
| 47 |
*/ |
| 48 |
public static final class ShadingPattern extends Pattern { |
| 49 |
|
| 50 |
private Shading shading; |
| 51 |
|
| 52 |
/** |
| 53 |
* Creates a new shading pattern. |
| 54 |
* |
| 55 |
* @param number the PDF object number. |
| 56 |
* @param shading the shading. |
| 57 |
* @param t the transform from the initial page space to Java2D space. |
| 58 |
*/ |
| 59 |
public ShadingPattern(int number, Shading shading, AffineTransform t) { |
| 60 |
super(number); |
| 61 |
this.dictionary.put("/PatternType", "2"); |
| 62 |
this.dictionary.put("/Matrix", PDFUtils.transformToPDF(t)); |
| 63 |
setShading(shading); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Returns the shading. |
| 68 |
* |
| 69 |
* @return The shading (never {@code null}). |
| 70 |
*/ |
| 71 |
public Shading getShading() { |
| 72 |
return this.shading; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Sets the shading. |
| 77 |
* |
| 78 |
* @param shading the shading ({@code null} not permitted). |
| 79 |
*/ |
| 80 |
public void setShading(Shading shading) { |
| 81 |
Args.nullNotPermitted(shading, "shading"); |
| 82 |
this.shading = shading; |
| 83 |
this.dictionary.put("/Shading", this.shading); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
protected Dictionary dictionary; |
| 88 |
|
| 89 |
/** |
| 90 |
* Creates a new pattern object. |
| 91 |
* |
| 92 |
* @param number the PDF object number. |
| 93 |
*/ |
| 94 |
protected Pattern(int number) { |
| 95 |
super(number); |
| 96 |
this.dictionary = new Dictionary("/Pattern"); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Returns the bytes that go between the 'obj' and 'endobj' in the |
| 101 |
* PDF output for this object. |
| 102 |
* |
| 103 |
* @return A byte array. |
| 104 |
*/ |
| 105 |
@Override |
| 106 |
public byte[] getObjectBytes() { |
| 107 |
return this.dictionary.toPDFBytes(); |
| 108 |
} |
| 109 |
} |