1 /* RenderingHints.java --
2 Copyright (C) 2000, 2001, 2002 Free Software Foundation
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import java
.util
.Collection
;
42 import java
.util
.Collections
;
43 import java
.util
.HashMap
;
50 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
51 * @author Eric Blake <ebb9@email.byu.edu>
53 public class RenderingHints
implements Map
, Cloneable
55 public abstract static class Key
57 private final int key
;
59 protected Key(int privateKey
)
64 public abstract boolean isCompatibleValue(Object value
);
66 protected final int intKey()
71 public final int hashCode()
73 return System
.identityHashCode(this);
76 public final boolean equals(Object other
)
82 private static final class KeyImpl
extends Key
84 final String description
;
89 KeyImpl(int privateKey
, String description
,
90 Object v1
, Object v2
, Object v3
)
93 this.description
= description
;
99 public boolean isCompatibleValue(Object value
)
101 return value
== v1
|| value
== v2
|| value
== v3
;
104 public String
toString()
110 private HashMap hintMap
= new HashMap();
112 public static final Key KEY_ANTIALIASING
;
114 public static final Object VALUE_ANTIALIAS_ON
115 = "Antialiased rendering mode";
117 public static final Object VALUE_ANTIALIAS_OFF
118 = "Nonantialiased rendering mode";
120 public static final Object VALUE_ANTIALIAS_DEFAULT
121 = "Default antialiasing rendering mode";
123 public static final Key KEY_RENDERING
;
125 public static final Object VALUE_RENDER_SPEED
126 = "Fastest rendering methods";
128 public static final Object VALUE_RENDER_QUALITY
129 = "Highest quality rendering methods";
131 public static final Object VALUE_RENDER_DEFAULT
132 = "Default rendering methods";
134 public static final Key KEY_DITHERING
;
136 public static final Object VALUE_DITHER_DISABLE
137 = "Nondithered rendering mode";
139 public static final Object VALUE_DITHER_ENABLE
140 = "Dithered rendering mode";
142 public static final Object VALUE_DITHER_DEFAULT
143 = "Default dithering mode";
145 public static final Key KEY_TEXT_ANTIALIASING
;
147 public static final Object VALUE_TEXT_ANTIALIAS_ON
148 = "Antialiased text mode";
150 public static final Object VALUE_TEXT_ANTIALIAS_OFF
151 = "Nonantialiased text mode";
153 public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT
154 = "Default antialiasing text mode";
156 public static final Key KEY_FRACTIONALMETRICS
;
158 public static final Object VALUE_FRACTIONALMETRICS_OFF
159 = "Integer text metrics mode";
161 public static final Object VALUE_FRACTIONALMETRICS_ON
162 = "Fractional text metrics mode";
164 public static final Object VALUE_FRACTIONALMETRICS_DEFAULT
165 = "Default fractional text metrics mode";
167 public static final Key KEY_INTERPOLATION
;
169 public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR
170 = "Nearest Neighbor image interpolation mode";
172 public static final Object VALUE_INTERPOLATION_BILINEAR
173 = "Bilinear image interpolation mode";
175 public static final Object VALUE_INTERPOLATION_BICUBIC
176 = "Bicubic image interpolation mode";
178 public static final Key KEY_ALPHA_INTERPOLATION
;
180 public static final Object VALUE_ALPHA_INTERPOLATION_SPEED
181 = "Fastest alpha blending methods";
183 public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY
184 = "Highest quality alpha blending methods";
186 public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT
187 = "Default alpha blending methods";
189 public static final Key KEY_COLOR_RENDERING
;
191 public static final Object VALUE_COLOR_RENDER_SPEED
192 = "Fastest color rendering mode";
194 public static final Object VALUE_COLOR_RENDER_QUALITY
195 = "Highest quality color rendering mode";
197 public static final Object VALUE_COLOR_RENDER_DEFAULT
198 = "Default color rendering mode";
200 public static final Key KEY_STROKE_CONTROL
;
202 public static final Object VALUE_STROKE_DEFAULT
203 = "Default stroke normalization";
205 public static final Object VALUE_STROKE_NORMALIZE
206 = "Normalize strokes for consistent rendering";
208 public static final Object VALUE_STROKE_PURE
209 = "Pure stroke conversion for accurate paths";
213 KEY_ANTIALIASING
= new KeyImpl(1, "Global antialiasing enable key",
216 VALUE_ANTIALIAS_DEFAULT
);
217 KEY_RENDERING
= new KeyImpl(2, "Global rendering quality key",
219 VALUE_RENDER_QUALITY
,
220 VALUE_RENDER_DEFAULT
);
221 KEY_DITHERING
= new KeyImpl(3, "Dithering quality key",
222 VALUE_DITHER_DISABLE
,
224 VALUE_DITHER_DEFAULT
);
225 KEY_TEXT_ANTIALIASING
226 = new KeyImpl(4, "Text-specific antialiasing enable key",
227 VALUE_TEXT_ANTIALIAS_ON
,
228 VALUE_TEXT_ANTIALIAS_OFF
,
229 VALUE_TEXT_ANTIALIAS_DEFAULT
);
230 KEY_FRACTIONALMETRICS
= new KeyImpl(5, "Fractional metrics enable key",
231 VALUE_FRACTIONALMETRICS_OFF
,
232 VALUE_FRACTIONALMETRICS_ON
,
233 VALUE_FRACTIONALMETRICS_DEFAULT
);
234 KEY_INTERPOLATION
= new KeyImpl(6, "Image interpolation method key",
235 VALUE_INTERPOLATION_NEAREST_NEIGHBOR
,
236 VALUE_INTERPOLATION_BILINEAR
,
237 VALUE_INTERPOLATION_BICUBIC
);
238 KEY_ALPHA_INTERPOLATION
239 = new KeyImpl(7, "Alpha blending interpolation method key",
240 VALUE_ALPHA_INTERPOLATION_SPEED
,
241 VALUE_ALPHA_INTERPOLATION_QUALITY
,
242 VALUE_ALPHA_INTERPOLATION_DEFAULT
);
243 KEY_COLOR_RENDERING
= new KeyImpl(8, "Color rendering quality key",
244 VALUE_COLOR_RENDER_SPEED
,
245 VALUE_COLOR_RENDER_QUALITY
,
246 VALUE_COLOR_RENDER_DEFAULT
);
247 KEY_STROKE_CONTROL
= new KeyImpl(9, "Stroke normalization control key",
248 VALUE_STROKE_DEFAULT
,
249 VALUE_STROKE_NORMALIZE
,
253 public RenderingHints(Map init
)
258 public RenderingHints(Key key
, Object value
)
265 return hintMap
.size();
268 public boolean isEmpty()
270 return hintMap
.isEmpty();
273 public boolean containsKey(Object key
)
276 throw new NullPointerException();
277 return hintMap
.containsKey((Key
) key
);
280 public boolean containsValue(Object value
)
282 return hintMap
.containsValue(value
);
285 public Object
get(Object key
)
287 return hintMap
.get((Key
) key
);
290 public Object
put(Object key
, Object value
)
292 if (key
== null || value
== null)
293 throw new NullPointerException();
294 if (! ((Key
) key
).isCompatibleValue(value
))
295 throw new IllegalArgumentException();
296 return hintMap
.put(key
, value
);
299 public void add(RenderingHints hints
)
301 hintMap
.putAll(hints
);
309 public Object
remove(Object key
)
311 return remove((Key
) key
);
314 public void putAll(Map m
)
321 return hintMap
.keySet();
324 public Collection
values()
326 return hintMap
.values();
329 public Set
entrySet()
331 return Collections
.unmodifiableSet(hintMap
.entrySet());
334 public boolean equals(Object o
)
336 return hintMap
.equals(o
);
339 public int hashCode()
341 return hintMap
.hashCode();
344 public Object
clone()
348 RenderingHints copy
= (RenderingHints
) super.clone();
349 copy
.hintMap
= (HashMap
) hintMap
.clone();
352 catch (CloneNotSupportedException e
)
354 throw (Error
) new InternalError().initCause(e
); // Impossible
358 public String
toString()
360 return hintMap
.toString();
362 } // class RenderingHints