KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > pdf > PDFGState


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: PDFGState.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.pdf;
21
22 import java.util.Map JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 /**
26  * Class representing a /ExtGState object.
27  */

28 public class PDFGState extends PDFObject {
29
30     /** Line width (LW) */
31     public static final String JavaDoc GSTATE_LINE_WIDTH = "LW";
32     /** Line cap (LC) */
33     public static final String JavaDoc GSTATE_LINE_CAP = "LC";
34     /** Line join (LJ) */
35     public static final String JavaDoc GSTATE_LINE_JOIN = "LJ";
36     /** Miter limit (ML) */
37     public static final String JavaDoc GSTATE_MITER_LIMIT = "ML";
38     /** Dash pattern (D) */
39     public static final String JavaDoc GSTATE_DASH_PATTERN = "D";
40     /** Rendering intent (RI) */
41     public static final String JavaDoc GSTATE_RENDERING_INTENT = "RI";
42     /** Overprint for stroke (OP) */
43     public static final String JavaDoc GSTATE_OVERPRINT_STROKE = "OP";
44     /** Overprint for fill (op) */
45     public static final String JavaDoc GSTATE_OVERPRINT_FILL = "op";
46     /** Overprint mode (OPM) */
47     public static final String JavaDoc GSTATE_OVERPRINT_MODE = "OPM";
48     /** Font (Font) */
49     public static final String JavaDoc GSTATE_FONT = "Font";
50     /** Black generation (BG) */
51     public static final String JavaDoc GSTATE_BLACK_GENERATION = "BG";
52     /** Black generation with default (BG2) */
53     public static final String JavaDoc GSTATE_BLACK_GENERATION2 = "BG2";
54     /** Undercolor removal function (UCR) */
55     public static final String JavaDoc GSTATE_UNDERCOLOR_REMOVAL = "UCR";
56     /** Undercolor removal function with default (UCR2) */
57     public static final String JavaDoc GSTATE_UNDERCOLOR_REMOVAL2 = "UCR2";
58     /** Transfer function (TR) */
59     public static final String JavaDoc GSTATE_TRANSFER_FUNCTION = "TR";
60     /** Transfer function with default (TR2) */
61     public static final String JavaDoc GSTATE_TRANSFER_FUNCTION2 = "TR2";
62     /** Halftone dictionary or stream (HT) */
63     public static final String JavaDoc GSTATE_HALFTONE_DICT = "HT";
64     /** Halftone phase (HTP, does not show up anymore in PDF 1.4)*/
65     public static final String JavaDoc GSTATE_HALFTONE_PHASE = "HTP";
66     /** Flatness (FL) */
67     public static final String JavaDoc GSTATE_FLATNESS = "FL";
68     /** Smoothness (SM) */
69     public static final String JavaDoc GSTATE_SMOOTHNESS = "SM";
70     /** Strike adjustment (SA) */
71     public static final String JavaDoc GSTATE_STRIKE_ADJ = "SA";
72     /** Blend mode (BM, PDF 1.4) */
73     public static final String JavaDoc GSTATE_BLEND_MODE = "BM";
74     /** Soft mask (SMask, PDF 1.4) */
75     public static final String JavaDoc GSTATE_SOFT_MASK = "SMask";
76     /** Stroking Alpha (CA, PDF 1.4) */
77     public static final String JavaDoc GSTATE_ALPHA_STROKE = "CA";
78     /** Nonstroking Alpha (ca, PDF 1.4) */
79     public static final String JavaDoc GSTATE_ALPHA_NONSTROKE = "ca";
80     /** Alpha Source Flag (AIS, PDF 1.4) */
81     public static final String JavaDoc GSTATE_ALPHA_SOURCE_FLAG = "AIS";
82     /** Text Knockout Flag (TK, PDF 1.4) */
83     public static final String JavaDoc GSTATE_TEXT_KNOCKOUT = "TK";
84     
85
86     /** Default GState object */
87     public static final PDFGState DEFAULT;
88
89     static {
90         DEFAULT = new PDFGState();
91         Map JavaDoc vals = DEFAULT.values;
92         /*vals.put(LW, new Float(1.0));
93         vals.put(LC, new Integer(0));
94         vals.put(LJ, new Integer(0));
95         vals.put(ML, new Float(10.0));
96         vals.put(D, "0 []");
97         vals.put(RI, "RelativeColorimetric");
98         vals.put(OP, Boolean.FALSE);
99         vals.put(op, Boolean.FALSE);
100         vals.put(OPM, new Integer(1));
101         vals.put(Font, "");*/

102         
103         vals.put(GSTATE_ALPHA_STROKE, new Float JavaDoc(1.0));
104         vals.put(GSTATE_ALPHA_NONSTROKE, new Float JavaDoc(1.0));
105     }
106
107     private Map JavaDoc values = new java.util.HashMap JavaDoc();
108
109     /**
110      * Returns the name of this object
111      * @return the name
112      */

113     public String JavaDoc getName() {
114         return "GS" + getObjectNumber();
115     }
116
117     /**
118      * Sets the alpha value.
119      * @param val alpha value (0.0 - 1.0)
120      * @param fill True if alpha should be set for non-stroking operations,
121      * False if for stroking operations
122      */

123     public void setAlpha(float val, boolean fill) {
124         if (fill) {
125             values.put(GSTATE_ALPHA_NONSTROKE, new Float JavaDoc(val));
126         } else {
127             values.put(GSTATE_ALPHA_STROKE, new Float JavaDoc(val));
128         }
129     }
130
131     /**
132      * Adds all values from another GState object to this one.
133      * @param state source object to copy from
134      */

135     public void addValues(PDFGState state) {
136         values.putAll(state.values);
137     }
138
139     /**
140      * Adds all values from a Map to this object.
141      * @param vals source object to copy from
142      */

143     public void addValues(Map JavaDoc vals) {
144         values.putAll(vals);
145     }
146
147     /**
148      * @see org.apache.fop.pdf.PDFObject#toPDFString()
149      */

150     public String JavaDoc toPDFString() {
151         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(64);
152         sb.append(getObjectID());
153         sb.append("<<\n/Type /ExtGState\n");
154         appendVal(sb, GSTATE_ALPHA_NONSTROKE);
155         appendVal(sb, GSTATE_ALPHA_STROKE);
156
157         sb.append(">>\nendobj\n");
158         return sb.toString();
159     }
160
161     private void appendVal(StringBuffer JavaDoc sb, String JavaDoc name) {
162         Object JavaDoc val = values.get(name);
163         if (val != null) {
164             sb.append("/" + name + " " + val + "\n");
165         }
166     }
167
168     /*
169      * example
170      * 29 0 obj
171      * <<
172      * /Type /ExtGState
173      * /ca 0.5
174      * >>
175      * endobj
176      */

177
178     /**
179      * @see java.lang.Object#equals(Object)
180      */

181     public boolean equals(Object JavaDoc obj) {
182         if (obj == this) {
183             return true;
184         }
185         if (!(obj instanceof PDFGState)) {
186             return false;
187         }
188         Map JavaDoc vals1 = values;
189         Map JavaDoc vals2 = ((PDFGState)obj).values;
190         if (vals1.size() != vals2.size()) {
191             return false;
192         }
193         for (Iterator JavaDoc iter = vals1.keySet().iterator(); iter.hasNext();) {
194             Object JavaDoc str = iter.next();
195             Object JavaDoc obj1 = vals1.get(str);
196             if (!obj1.equals(vals2.get(str))) {
197                 return false;
198             }
199         }
200         return true;
201     }
202 }
203
204
Popular Tags