1 /* 2 * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.awt; 27 28 import java.awt.RenderingHints; 29 30 /** 31 * This class contains rendering hints that can be used by the 32 * {@link java.awt.Graphics2D} class, and classes that implement 33 * {@link java.awt.image.BufferedImageOp} and 34 * {@link java.awt.image.Raster}. 35 */ 36 public class SunHints { 37 /** 38 * Defines the type of all keys used to control various 39 * aspects of the rendering and imaging pipelines. Instances 40 * of this class are immutable and unique which means that 41 * tests for matches can be made using the == operator instead 42 * of the more expensive equals() method. 43 */ 44 public static class Key extends RenderingHints.Key { 45 String description; 46 47 /** 48 * Construct a key using the indicated private key. Each 49 * subclass of Key maintains its own unique domain of integer 50 * keys. No two objects with the same integer key and of the 51 * same specific subclass can be constructed. An exception 52 * will be thrown if an attempt is made to construct another 53 * object of a given class with the same integer key as a 54 * pre-existing instance of that subclass of Key. 55 */ 56 public Key(int privatekey, String description) { 57 super(privatekey); 58 this.description = description; 59 } 60 61 /** 62 * Returns the numeric index associated with this Key. This 63 * is useful for use in switch statements and quick lookups 64 * of the setting of a particular key. 65 */ 66 public final int getIndex() { 67 return intKey(); 68 } 69 70 /** 71 * Returns a string representation of the Key. 72 */ 73 public final String toString() { 74 return description; 75 } 76 77 /** 78 * Returns true if the specified object is a valid value 79 * for this Key. 80 */ 81 public boolean isCompatibleValue(Object val) { 82 if (val instanceof Value) { 83 return ((Value)val).isCompatibleKey(this); 84 } 85 return false; 86 } 87 } 88 89 /** 90 * Defines the type of all "enumerative" values used to control 91 * various aspects of the rendering and imaging pipelines. Instances 92 * of this class are immutable and unique which means that 93 * tests for matches can be made using the == operator instead 94 * of the more expensive equals() method. 95 */ 96 public static class Value { 97 private SunHints.Key myKey; 98 private int index; 99 private String description; 100 101 private static Value[][] ValueObjects = 102 new Value[NUM_KEYS][VALS_PER_KEY]; 103 104 private synchronized static void register(SunHints.Key key, 105 Value value) { 106 int kindex = key.getIndex(); 107 int vindex = value.getIndex(); 108 if (ValueObjects[kindex][vindex] != null) { 109 throw new InternalError("duplicate index: "+vindex); 110 } 111 ValueObjects[kindex][vindex] = value; 112 } 113 114 public static Value get(int keyindex, int valueindex) { 115 return ValueObjects[keyindex][valueindex]; 116 } 117 118 /** 119 * Construct a value using the indicated private index. Each 120 * subclass of Value maintains its own unique domain of integer 121 * indices. Enforcing the uniqueness of the integer indices 122 * is left to the subclass. 123 */ 124 public Value(SunHints.Key key, int index, String description) { 125 this.myKey = key; 126 this.index = index; 127 this.description = description; 128 129 register(key, this); 130 } 131 132 /** 133 * Returns the numeric index associated with this Key. This 134 * is useful for use in switch statements and quick lookups 135 * of the setting of a particular key. 136 */ 137 public final int getIndex() { 138 return index; 139 } 140 141 /** 142 * Returns a string representation of this Value. 143 */ 144 public final String toString() { 145 return description; 146 } 147 148 /** 149 * Returns true if the specified object is a valid Key 150 * for this Value. 151 */ 152 public final boolean isCompatibleKey(Key k) { 153 return myKey == k; 154 } 155 156 /** 157 * The hash code for all SunHints.Value objects will be the same 158 * as the system identity code of the object as defined by the 159 * System.identityHashCode() method. 160 */ 161 public final int hashCode() { 162 return System.identityHashCode(this); 163 } 164 165 /** 166 * The equals method for all SunHints.Value objects will return 167 * the same result as the equality operator '=='. 168 */ 169 public final boolean equals(Object o) { 170 return this == o; 171 } 172 } 173 174 private static final int NUM_KEYS = 9; 175 private static final int VALS_PER_KEY = 8; 176 177 /** 178 * Rendering hint key and values 179 */ 180 public static final int INTKEY_RENDERING = 0; 181 public static final int INTVAL_RENDER_DEFAULT = 0; 182 public static final int INTVAL_RENDER_SPEED = 1; 183 public static final int INTVAL_RENDER_QUALITY = 2; 184 185 /** 186 * Antialiasing hint key and values 187 */ 188 public static final int INTKEY_ANTIALIASING = 1; 189 public static final int INTVAL_ANTIALIAS_DEFAULT = 0; 190 public static final int INTVAL_ANTIALIAS_OFF = 1; 191 public static final int INTVAL_ANTIALIAS_ON = 2; 192 193 /** 194 * Text antialiasing hint key and values 195 */ 196 public static final int INTKEY_TEXT_ANTIALIASING = 2; 197 public static final int INTVAL_TEXT_ANTIALIAS_DEFAULT = 0; 198 public static final int INTVAL_TEXT_ANTIALIAS_OFF = 1; 199 public static final int INTVAL_TEXT_ANTIALIAS_ON = 2; 200 public static final int INTVAL_TEXT_ANTIALIAS_GASP = 3; 201 public static final int INTVAL_TEXT_ANTIALIAS_LCD_HRGB = 4; 202 public static final int INTVAL_TEXT_ANTIALIAS_LCD_HBGR = 5; 203 public static final int INTVAL_TEXT_ANTIALIAS_LCD_VRGB = 6; 204 public static final int INTVAL_TEXT_ANTIALIAS_LCD_VBGR = 7; 205 206 /** 207 * Font fractional metrics hint key and values 208 */ 209 public static final int INTKEY_FRACTIONALMETRICS = 3; 210 public static final int INTVAL_FRACTIONALMETRICS_DEFAULT = 0; 211 public static final int INTVAL_FRACTIONALMETRICS_OFF = 1; 212 public static final int INTVAL_FRACTIONALMETRICS_ON = 2; 213 214 /** 215 * Dithering hint key and values 216 */ 217 public static final int INTKEY_DITHERING = 4; 218 public static final int INTVAL_DITHER_DEFAULT = 0; 219 public static final int INTVAL_DITHER_DISABLE = 1; 220 public static final int INTVAL_DITHER_ENABLE = 2; 221 222 /** 223 * Interpolation hint key and values 224 */ 225 public static final int INTKEY_INTERPOLATION = 5; 226 public static final int INTVAL_INTERPOLATION_NEAREST_NEIGHBOR = 0; 227 public static final int INTVAL_INTERPOLATION_BILINEAR = 1; 228 public static final int INTVAL_INTERPOLATION_BICUBIC = 2; 229 230 /** 231 * Alpha interpolation hint key and values 232 */ 233 public static final int INTKEY_ALPHA_INTERPOLATION = 6; 234 public static final int INTVAL_ALPHA_INTERPOLATION_DEFAULT = 0; 235 public static final int INTVAL_ALPHA_INTERPOLATION_SPEED = 1; 236 public static final int INTVAL_ALPHA_INTERPOLATION_QUALITY = 2; 237 238 /** 239 * Color rendering hint key and values 240 */ 241 public static final int INTKEY_COLOR_RENDERING = 7; 242 public static final int INTVAL_COLOR_RENDER_DEFAULT = 0; 243 public static final int INTVAL_COLOR_RENDER_SPEED = 1; 244 public static final int INTVAL_COLOR_RENDER_QUALITY = 2; 245 246 /** 247 * Stroke normalization control hint key and values 248 */ 249 public static final int INTKEY_STROKE_CONTROL = 8; 250 public static final int INTVAL_STROKE_DEFAULT = 0; 251 public static final int INTVAL_STROKE_NORMALIZE = 1; 252 public static final int INTVAL_STROKE_PURE = 2; 253 254 /** 255 * LCD text contrast control hint key. 256 * Value is "100" to make discontiguous with the others which 257 * are all enumerative and are of a different class. 258 */ 259 public static final int INTKEY_AATEXT_LCD_CONTRAST = 100; 260 261 /** 262 * Rendering hint key and value objects 263 */ 264 public static final Key KEY_RENDERING = 265 new SunHints.Key(SunHints.INTKEY_RENDERING, 266 "Global rendering quality key"); 267 public static final Object VALUE_RENDER_SPEED = 268 new SunHints.Value(KEY_RENDERING, 269 SunHints.INTVAL_RENDER_SPEED, 270 "Fastest rendering methods"); 271 public static final Object VALUE_RENDER_QUALITY = 272 new SunHints.Value(KEY_RENDERING, 273 SunHints.INTVAL_RENDER_QUALITY, 274 "Highest quality rendering methods"); 275 public static final Object VALUE_RENDER_DEFAULT = 276 new SunHints.Value(KEY_RENDERING, 277 SunHints.INTVAL_RENDER_DEFAULT, 278 "Default rendering methods"); 279 280 /** 281 * Antialiasing hint key and value objects 282 */ 283 public static final Key KEY_ANTIALIASING = 284 new SunHints.Key(SunHints.INTKEY_ANTIALIASING, 285 "Global antialiasing enable key"); 286 public static final Object VALUE_ANTIALIAS_ON = 287 new SunHints.Value(KEY_ANTIALIASING, 288 SunHints.INTVAL_ANTIALIAS_ON, 289 "Antialiased rendering mode"); 290 public static final Object VALUE_ANTIALIAS_OFF = 291 new SunHints.Value(KEY_ANTIALIASING, 292 SunHints.INTVAL_ANTIALIAS_OFF, 293 "Nonantialiased rendering mode"); 294 public static final Object VALUE_ANTIALIAS_DEFAULT = 295 new SunHints.Value(KEY_ANTIALIASING, 296 SunHints.INTVAL_ANTIALIAS_DEFAULT, 297 "Default antialiasing rendering mode"); 298 299 /** 300 * Text antialiasing hint key and value objects 301 */ 302 public static final Key KEY_TEXT_ANTIALIASING = 303 new SunHints.Key(SunHints.INTKEY_TEXT_ANTIALIASING, 304 "Text-specific antialiasing enable key"); 305 public static final Object VALUE_TEXT_ANTIALIAS_ON = 306 new SunHints.Value(KEY_TEXT_ANTIALIASING, 307 SunHints.INTVAL_TEXT_ANTIALIAS_ON, 308 "Antialiased text mode"); 309 public static final Object VALUE_TEXT_ANTIALIAS_OFF = 310 new SunHints.Value(KEY_TEXT_ANTIALIASING, 311 SunHints.INTVAL_TEXT_ANTIALIAS_OFF, 312 "Nonantialiased text mode"); 313 public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT = 314 new SunHints.Value(KEY_TEXT_ANTIALIASING, 315 SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT, 316 "Default antialiasing text mode"); 317 public static final Object VALUE_TEXT_ANTIALIAS_GASP = 318 new SunHints.Value(KEY_TEXT_ANTIALIASING, 319 SunHints.INTVAL_TEXT_ANTIALIAS_GASP, 320 "gasp antialiasing text mode"); 321 public static final Object VALUE_TEXT_ANTIALIAS_LCD_HRGB = 322 new SunHints.Value(KEY_TEXT_ANTIALIASING, 323 SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB, 324 "LCD HRGB antialiasing text mode"); 325 public static final Object VALUE_TEXT_ANTIALIAS_LCD_HBGR = 326 new SunHints.Value(KEY_TEXT_ANTIALIASING, 327 SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HBGR, 328 "LCD HBGR antialiasing text mode"); 329 public static final Object VALUE_TEXT_ANTIALIAS_LCD_VRGB = 330 new SunHints.Value(KEY_TEXT_ANTIALIASING, 331 SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB, 332 "LCD VRGB antialiasing text mode"); 333 public static final Object VALUE_TEXT_ANTIALIAS_LCD_VBGR = 334 new SunHints.Value(KEY_TEXT_ANTIALIASING, 335 SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VBGR, 336 "LCD VBGR antialiasing text mode"); 337 338 /** 339 * Font fractional metrics hint key and value objects 340 */ 341 public static final Key KEY_FRACTIONALMETRICS = 342 new SunHints.Key(SunHints.INTKEY_FRACTIONALMETRICS, 343 "Fractional metrics enable key"); 344 public static final Object VALUE_FRACTIONALMETRICS_ON = 345 new SunHints.Value(KEY_FRACTIONALMETRICS, 346 SunHints.INTVAL_FRACTIONALMETRICS_ON, 347 "Fractional text metrics mode"); 348 public static final Object VALUE_FRACTIONALMETRICS_OFF = 349 new SunHints.Value(KEY_FRACTIONALMETRICS, 350 SunHints.INTVAL_FRACTIONALMETRICS_OFF, 351 "Integer text metrics mode"); 352 public static final Object VALUE_FRACTIONALMETRICS_DEFAULT = 353 new SunHints.Value(KEY_FRACTIONALMETRICS, 354 SunHints.INTVAL_FRACTIONALMETRICS_DEFAULT, 355 "Default fractional text metrics mode"); 356 357 /** 358 * Dithering hint key and value objects 359 */ 360 public static final Key KEY_DITHERING = 361 new SunHints.Key(SunHints.INTKEY_DITHERING, 362 "Dithering quality key"); 363 public static final Object VALUE_DITHER_ENABLE = 364 new SunHints.Value(KEY_DITHERING, 365 SunHints.INTVAL_DITHER_ENABLE, 366 "Dithered rendering mode"); 367 public static final Object VALUE_DITHER_DISABLE = 368 new SunHints.Value(KEY_DITHERING, 369 SunHints.INTVAL_DITHER_DISABLE, 370 "Nondithered rendering mode"); 371 public static final Object VALUE_DITHER_DEFAULT = 372 new SunHints.Value(KEY_DITHERING, 373 SunHints.INTVAL_DITHER_DEFAULT, 374 "Default dithering mode"); 375 376 /** 377 * Interpolation hint key and value objects 378 */ 379 public static final Key KEY_INTERPOLATION = 380 new SunHints.Key(SunHints.INTKEY_INTERPOLATION, 381 "Image interpolation method key"); 382 public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR = 383 new SunHints.Value(KEY_INTERPOLATION, 384 SunHints.INTVAL_INTERPOLATION_NEAREST_NEIGHBOR, 385 "Nearest Neighbor image interpolation mode"); 386 public static final Object VALUE_INTERPOLATION_BILINEAR = 387 new SunHints.Value(KEY_INTERPOLATION, 388 SunHints.INTVAL_INTERPOLATION_BILINEAR, 389 "Bilinear image interpolation mode"); 390 public static final Object VALUE_INTERPOLATION_BICUBIC = 391 new SunHints.Value(KEY_INTERPOLATION, 392 SunHints.INTVAL_INTERPOLATION_BICUBIC, 393 "Bicubic image interpolation mode"); 394 395 /** 396 * Alpha interpolation hint key and value objects 397 */ 398 public static final Key KEY_ALPHA_INTERPOLATION = 399 new SunHints.Key(SunHints.INTKEY_ALPHA_INTERPOLATION, 400 "Alpha blending interpolation method key"); 401 public static final Object VALUE_ALPHA_INTERPOLATION_SPEED = 402 new SunHints.Value(KEY_ALPHA_INTERPOLATION, 403 SunHints.INTVAL_ALPHA_INTERPOLATION_SPEED, 404 "Fastest alpha blending methods"); 405 public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY = 406 new SunHints.Value(KEY_ALPHA_INTERPOLATION, 407 SunHints.INTVAL_ALPHA_INTERPOLATION_QUALITY, 408 "Highest quality alpha blending methods"); 409 public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT = 410 new SunHints.Value(KEY_ALPHA_INTERPOLATION, 411 SunHints.INTVAL_ALPHA_INTERPOLATION_DEFAULT, 412 "Default alpha blending methods"); 413 414 /** 415 * Color rendering hint key and value objects 416 */ 417 public static final Key KEY_COLOR_RENDERING = 418 new SunHints.Key(SunHints.INTKEY_COLOR_RENDERING, 419 "Color rendering quality key"); 420 public static final Object VALUE_COLOR_RENDER_SPEED = 421 new SunHints.Value(KEY_COLOR_RENDERING, 422 SunHints.INTVAL_COLOR_RENDER_SPEED, 423 "Fastest color rendering mode"); 424 public static final Object VALUE_COLOR_RENDER_QUALITY = 425 new SunHints.Value(KEY_COLOR_RENDERING, 426 SunHints.INTVAL_COLOR_RENDER_QUALITY, 427 "Highest quality color rendering mode"); 428 public static final Object VALUE_COLOR_RENDER_DEFAULT = 429 new SunHints.Value(KEY_COLOR_RENDERING, 430 SunHints.INTVAL_COLOR_RENDER_DEFAULT, 431 "Default color rendering mode"); 432 433 /** 434 * Stroke normalization control hint key and value objects 435 */ 436 public static final Key KEY_STROKE_CONTROL = 437 new SunHints.Key(SunHints.INTKEY_STROKE_CONTROL, 438 "Stroke normalization control key"); 439 public static final Object VALUE_STROKE_DEFAULT = 440 new SunHints.Value(KEY_STROKE_CONTROL, 441 SunHints.INTVAL_STROKE_DEFAULT, 442 "Default stroke normalization"); 443 public static final Object VALUE_STROKE_NORMALIZE = 444 new SunHints.Value(KEY_STROKE_CONTROL, 445 SunHints.INTVAL_STROKE_NORMALIZE, 446 "Normalize strokes for consistent rendering"); 447 public static final Object VALUE_STROKE_PURE = 448 new SunHints.Value(KEY_STROKE_CONTROL, 449 SunHints.INTVAL_STROKE_PURE, 450 "Pure stroke conversion for accurate paths"); 451 452 453 public static class LCDContrastKey extends Key { 454 455 public LCDContrastKey(int privatekey, String description) { 456 super(privatekey, description); 457 } 458 459 /** 460 * Returns true if the specified object is a valid value 461 * for this Key. The allowable range is 100 to 250. 462 */ 463 public final boolean isCompatibleValue(Object val) { 464 if (val instanceof Integer) { 465 int ival = ((Integer)val).intValue(); 466 return ival >= 100 && ival <= 250; 467 } 468 return false; 469 } 470 471 } 472 473 /** 474 * LCD text contrast hint key 475 */ 476 public static final RenderingHints.Key 477 KEY_TEXT_ANTIALIAS_LCD_CONTRAST = 478 new LCDContrastKey(SunHints.INTKEY_AATEXT_LCD_CONTRAST, 479 "Text-specific LCD contrast key"); 480 }