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