001: /**
002: * Copyright (c) 2003-2006, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.graphics;
031:
032: import org.pdfbox.util.Matrix;
033:
034: import org.pdfbox.pdmodel.text.PDTextState;
035:
036: import org.pdfbox.pdmodel.graphics.color.PDColorSpaceInstance;
037:
038: /**
039: * This class will hold the current state of the graphics parameters when executing a
040: * content stream.
041: *
042: * @author <a href="ben@benlitchfield.com">Ben Litchfield</a>
043: * @version $Revision: 1.4 $
044: */
045: public class PDGraphicsState implements Cloneable {
046: private Matrix currentTransformationMatrix = new Matrix();
047:
048: //Here are some attributes of the Graphics state, but have not been created yet.
049: //
050: //clippingPath
051: private PDColorSpaceInstance strokingColorSpace = new PDColorSpaceInstance();
052: private PDColorSpaceInstance nonStrokingColorSpace = new PDColorSpaceInstance();
053: private PDTextState textState = new PDTextState();
054: private double lineWidth = 0;
055: private int lineCap = 0;
056: private int lineJoin = 0;
057: private double miterLimit = 0;
058: private PDLineDashPattern lineDashPattern;
059: private String renderingIntent;
060: private boolean strokeAdjustment = false;
061: //blend mode
062: //soft mask
063: private double alphaConstants = 0;
064: private boolean alphaSource = false;
065:
066: //DEVICE DEPENDENT parameters
067: private boolean overprint = false;
068: private double overprintMode = 0;
069: //black generation
070: //undercolor removal
071: //transfer
072: //halftone
073: private double flatness = 1.0;
074: private double smoothness = 0;
075:
076: /**
077: * Get the value of the CTM.
078: *
079: * @return The current transformation matrix.
080: */
081: public Matrix getCurrentTransformationMatrix() {
082: return currentTransformationMatrix;
083: }
084:
085: /**
086: * Set the value of the CTM.
087: *
088: * @param value The current transformation matrix.
089: */
090: public void setCurrentTransformationMatrix(Matrix value) {
091: currentTransformationMatrix = value;
092: }
093:
094: /**
095: * Get the value of the line width.
096: *
097: * @return The current line width.
098: */
099: public double getLineWidth() {
100: return lineWidth;
101: }
102:
103: /**
104: * set the value of the line width.
105: *
106: * @param value The current line width.
107: */
108: public void setLineWidth(double value) {
109: lineWidth = value;
110: }
111:
112: /**
113: * Get the value of the line cap.
114: *
115: * @return The current line cap.
116: */
117: public int getLineCap() {
118: return lineCap;
119: }
120:
121: /**
122: * set the value of the line cap.
123: *
124: * @param value The current line cap.
125: */
126: public void setLineCap(int value) {
127: lineCap = value;
128: }
129:
130: /**
131: * Get the value of the line join.
132: *
133: * @return The current line join value.
134: */
135: public int getLineJoin() {
136: return lineJoin;
137: }
138:
139: /**
140: * Get the value of the line join.
141: *
142: * @param value The current line join
143: */
144: public void setLineJoin(int value) {
145: lineJoin = value;
146: }
147:
148: /**
149: * Get the value of the miter limit.
150: *
151: * @return The current miter limit.
152: */
153: public double getMiterLimit() {
154: return miterLimit;
155: }
156:
157: /**
158: * set the value of the miter limit.
159: *
160: * @param value The current miter limit.
161: */
162: public void setMiterLimit(double value) {
163: miterLimit = value;
164: }
165:
166: /**
167: * Get the value of the stroke adjustment parameter.
168: *
169: * @return The current stroke adjustment.
170: */
171: public boolean isStrokeAdjustment() {
172: return strokeAdjustment;
173: }
174:
175: /**
176: * set the value of the stroke adjustment.
177: *
178: * @param value The value of the stroke adjustment parameter.
179: */
180: public void setStrokeAdjustment(boolean value) {
181: strokeAdjustment = value;
182: }
183:
184: /**
185: * Get the value of the alpha constants property.
186: *
187: * @return The value of the alpha constants parameter.
188: */
189: public double getAlphaConstants() {
190: return alphaConstants;
191: }
192:
193: /**
194: * set the value of the alpha constants property.
195: *
196: * @param value The value of the alpha constants parameter.
197: */
198: public void setAlphaConstants(double value) {
199: alphaConstants = value;
200: }
201:
202: /**
203: * get the value of the alpha source property.
204: *
205: * @return The value of the alpha source parameter.
206: */
207: public boolean isAlphaSource() {
208: return alphaSource;
209: }
210:
211: /**
212: * set the value of the alpha source property.
213: *
214: * @param value The value of the alpha source parameter.
215: */
216: public void setAlphaSource(boolean value) {
217: alphaSource = value;
218: }
219:
220: /**
221: * get the value of the overprint property.
222: *
223: * @return The value of the overprint parameter.
224: */
225: public boolean isOverprint() {
226: return overprint;
227: }
228:
229: /**
230: * set the value of the overprint property.
231: *
232: * @param value The value of the overprint parameter.
233: */
234: public void setOverprint(boolean value) {
235: overprint = value;
236: }
237:
238: /**
239: * get the value of the overprint mode property.
240: *
241: * @return The value of the overprint mode parameter.
242: */
243: public double getOverprintMode() {
244: return overprintMode;
245: }
246:
247: /**
248: * set the value of the overprint mode property.
249: *
250: * @param value The value of the overprint mode parameter.
251: */
252: public void setOverprintMode(double value) {
253: overprintMode = value;
254: }
255:
256: /**
257: * get the value of the flatness property.
258: *
259: * @return The value of the flatness parameter.
260: */
261: public double getFlatness() {
262: return flatness;
263: }
264:
265: /**
266: * set the value of the flatness property.
267: *
268: * @param value The value of the flatness parameter.
269: */
270: public void setFlatness(double value) {
271: flatness = value;
272: }
273:
274: /**
275: * get the value of the smoothness property.
276: *
277: * @return The value of the smoothness parameter.
278: */
279: public double getSmoothness() {
280: return smoothness;
281: }
282:
283: /**
284: * set the value of the smoothness property.
285: *
286: * @param value The value of the smoothness parameter.
287: */
288: public void setSmoothness(double value) {
289: smoothness = value;
290: }
291:
292: /**
293: * This will get the graphics text state.
294: *
295: * @return The graphics text state.
296: */
297: public PDTextState getTextState() {
298: return textState;
299: }
300:
301: /**
302: * This will set the graphics text state.
303: *
304: * @param value The graphics text state.
305: */
306: public void setTextState(PDTextState value) {
307: textState = value;
308: }
309:
310: /**
311: * This will get the current line dash pattern.
312: *
313: * @return The line dash pattern.
314: */
315: public PDLineDashPattern getLineDashPattern() {
316: return lineDashPattern;
317: }
318:
319: /**
320: * This will set the current line dash pattern.
321: *
322: * @param value The new line dash pattern.
323: */
324: public void setLineDashPattern(PDLineDashPattern value) {
325: lineDashPattern = value;
326: }
327:
328: /**
329: * This will get the rendering intent.
330: *
331: * @see PDExtendedGraphicsState
332: *
333: * @return The rendering intent
334: */
335: public String getRenderingIntent() {
336: return renderingIntent;
337: }
338:
339: /**
340: * This will set the rendering intent.
341: *
342: * @param value The new rendering intent.
343: */
344: public void setRenderingIntent(String value) {
345: renderingIntent = value;
346: }
347:
348: /**
349: * {@inheritDoc}
350: */
351: public Object clone() {
352: PDGraphicsState clone = null;
353: try {
354: clone = (PDGraphicsState) super .clone();
355: clone.setTextState((PDTextState) textState.clone());
356: clone
357: .setCurrentTransformationMatrix(currentTransformationMatrix
358: .copy());
359: } catch (CloneNotSupportedException e) {
360: e.printStackTrace();
361: }
362: return clone;
363: }
364:
365: /**
366: * This will get the current stroking colorspace.
367: *
368: * @return The current stroking colorspace.
369: */
370: public PDColorSpaceInstance getStrokingColorSpace() {
371: return strokingColorSpace;
372: }
373:
374: /**
375: * This will set the current stroking colorspace.
376: *
377: * @param value The new stroking colorspace instance.
378: */
379: public void setStrokingColorSpace(PDColorSpaceInstance value) {
380: strokingColorSpace = value;
381: }
382:
383: /**
384: * This will get the nonstroking color space instance.
385: *
386: * @return The colorspace instance.
387: */
388: public PDColorSpaceInstance getNonStrokingColorSpace() {
389: return nonStrokingColorSpace;
390: }
391:
392: /**
393: * This will set the non-stroking colorspace instance.
394: *
395: * @param value The non-stroking colorspace instance.
396: */
397: public void setNonStrokingColorSpace(PDColorSpaceInstance value) {
398: nonStrokingColorSpace = value;
399: }
400: }
|