Path: blob/master/src/java.desktop/share/classes/sun/awt/SunHints.java
41152 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt;2627import java.awt.RenderingHints;28import java.lang.annotation.Native;2930/**31* This class contains rendering hints that can be used by the32* {@link java.awt.Graphics2D} class, and classes that implement33* {@link java.awt.image.BufferedImageOp} and34* {@link java.awt.image.Raster}.35*/36public class SunHints {37/**38* Defines the type of all keys used to control various39* aspects of the rendering and imaging pipelines. Instances40* of this class are immutable and unique which means that41* tests for matches can be made using the == operator instead42* of the more expensive equals() method.43*/44public static class Key extends RenderingHints.Key {45String description;4647/**48* Construct a key using the indicated private key. Each49* subclass of Key maintains its own unique domain of integer50* keys. No two objects with the same integer key and of the51* same specific subclass can be constructed. An exception52* will be thrown if an attempt is made to construct another53* object of a given class with the same integer key as a54* pre-existing instance of that subclass of Key.55*/56public Key(int privatekey, String description) {57super(privatekey);58this.description = description;59}6061/**62* Returns the numeric index associated with this Key. This63* is useful for use in switch statements and quick lookups64* of the setting of a particular key.65*/66public final int getIndex() {67return intKey();68}6970/**71* Returns a string representation of the Key.72*/73public final String toString() {74return description;75}7677/**78* Returns true if the specified object is a valid value79* for this Key.80*/81public boolean isCompatibleValue(Object val) {82if (val instanceof Value) {83return ((Value)val).isCompatibleKey(this);84}85return false;86}87}8889/**90* Defines the type of all "enumerative" values used to control91* various aspects of the rendering and imaging pipelines. Instances92* of this class are immutable and unique which means that93* tests for matches can be made using the == operator instead94* of the more expensive equals() method.95*/96public static class Value {97private SunHints.Key myKey;98private int index;99private String description;100101private static Value[][] ValueObjects =102new Value[NUM_KEYS][VALS_PER_KEY];103104private static synchronized void register(SunHints.Key key,105Value value) {106int kindex = key.getIndex();107int vindex = value.getIndex();108if (ValueObjects[kindex][vindex] != null) {109throw new InternalError("duplicate index: "+vindex);110}111ValueObjects[kindex][vindex] = value;112}113114public static Value get(int keyindex, int valueindex) {115return ValueObjects[keyindex][valueindex];116}117118/**119* Construct a value using the indicated private index. Each120* subclass of Value maintains its own unique domain of integer121* indices. Enforcing the uniqueness of the integer indices122* is left to the subclass.123*/124public Value(SunHints.Key key, int index, String description) {125this.myKey = key;126this.index = index;127this.description = description;128129register(key, this);130}131132/**133* Returns the numeric index associated with this Key. This134* is useful for use in switch statements and quick lookups135* of the setting of a particular key.136*/137public final int getIndex() {138return index;139}140141/**142* Returns a string representation of this Value.143*/144public final String toString() {145return description;146}147148/**149* Returns true if the specified object is a valid Key150* for this Value.151*/152public final boolean isCompatibleKey(Key k) {153return myKey == k;154}155156/**157* The hash code for all SunHints.Value objects will be the same158* as the system identity code of the object as defined by the159* System.identityHashCode() method.160*/161public final int hashCode() {162return System.identityHashCode(this);163}164165/**166* The equals method for all SunHints.Value objects will return167* the same result as the equality operator '=='.168*/169public final boolean equals(Object o) {170return this == o;171}172}173174private static final int NUM_KEYS = 10;175private static final int VALS_PER_KEY = 8;176177/**178* Rendering hint key and values179*/180@Native public static final int INTKEY_RENDERING = 0;181@Native public static final int INTVAL_RENDER_DEFAULT = 0;182@Native public static final int INTVAL_RENDER_SPEED = 1;183@Native public static final int INTVAL_RENDER_QUALITY = 2;184185/**186* Antialiasing hint key and values187*/188@Native public static final int INTKEY_ANTIALIASING = 1;189@Native public static final int INTVAL_ANTIALIAS_DEFAULT = 0;190@Native public static final int INTVAL_ANTIALIAS_OFF = 1;191@Native public static final int INTVAL_ANTIALIAS_ON = 2;192193/**194* Text antialiasing hint key and values195*/196@Native public static final int INTKEY_TEXT_ANTIALIASING = 2;197@Native public static final int INTVAL_TEXT_ANTIALIAS_DEFAULT = 0;198@Native public static final int INTVAL_TEXT_ANTIALIAS_OFF = 1;199@Native public static final int INTVAL_TEXT_ANTIALIAS_ON = 2;200@Native public static final int INTVAL_TEXT_ANTIALIAS_GASP = 3;201@Native public static final int INTVAL_TEXT_ANTIALIAS_LCD_HRGB = 4;202@Native public static final int INTVAL_TEXT_ANTIALIAS_LCD_HBGR = 5;203@Native public static final int INTVAL_TEXT_ANTIALIAS_LCD_VRGB = 6;204@Native public static final int INTVAL_TEXT_ANTIALIAS_LCD_VBGR = 7;205206/**207* Font fractional metrics hint key and values208*/209@Native public static final int INTKEY_FRACTIONALMETRICS = 3;210@Native public static final int INTVAL_FRACTIONALMETRICS_DEFAULT = 0;211@Native public static final int INTVAL_FRACTIONALMETRICS_OFF = 1;212@Native public static final int INTVAL_FRACTIONALMETRICS_ON = 2;213214/**215* Dithering hint key and values216*/217@Native public static final int INTKEY_DITHERING = 4;218@Native public static final int INTVAL_DITHER_DEFAULT = 0;219@Native public static final int INTVAL_DITHER_DISABLE = 1;220@Native public static final int INTVAL_DITHER_ENABLE = 2;221222/**223* Interpolation hint key and values224*/225@Native public static final int INTKEY_INTERPOLATION = 5;226@Native public static final int INTVAL_INTERPOLATION_NEAREST_NEIGHBOR = 0;227@Native public static final int INTVAL_INTERPOLATION_BILINEAR = 1;228@Native public static final int INTVAL_INTERPOLATION_BICUBIC = 2;229230/**231* Alpha interpolation hint key and values232*/233@Native public static final int INTKEY_ALPHA_INTERPOLATION = 6;234@Native public static final int INTVAL_ALPHA_INTERPOLATION_DEFAULT = 0;235@Native public static final int INTVAL_ALPHA_INTERPOLATION_SPEED = 1;236@Native public static final int INTVAL_ALPHA_INTERPOLATION_QUALITY = 2;237238/**239* Color rendering hint key and values240*/241@Native public static final int INTKEY_COLOR_RENDERING = 7;242@Native public static final int INTVAL_COLOR_RENDER_DEFAULT = 0;243@Native public static final int INTVAL_COLOR_RENDER_SPEED = 1;244@Native public static final int INTVAL_COLOR_RENDER_QUALITY = 2;245246/**247* Stroke normalization control hint key and values248*/249@Native public static final int INTKEY_STROKE_CONTROL = 8;250@Native public static final int INTVAL_STROKE_DEFAULT = 0;251@Native public static final int INTVAL_STROKE_NORMALIZE = 1;252@Native public static final int INTVAL_STROKE_PURE = 2;253254/**255* Image scaling hint key and values256*/257@Native public static final int INTKEY_RESOLUTION_VARIANT = 9;258@Native public static final int INTVAL_RESOLUTION_VARIANT_DEFAULT = 0;259@Native public static final int INTVAL_RESOLUTION_VARIANT_BASE = 1;260@Native public static final int INTVAL_RESOLUTION_VARIANT_SIZE_FIT = 2;261@Native public static final int INTVAL_RESOLUTION_VARIANT_DPI_FIT = 3;262263/**264* LCD text contrast control hint key.265* Value is "100" to make discontiguous with the others which266* are all enumerative and are of a different class.267*/268@Native public static final int INTKEY_AATEXT_LCD_CONTRAST = 100;269270/**271* Rendering hint key and value objects272*/273public static final Key KEY_RENDERING =274new SunHints.Key(SunHints.INTKEY_RENDERING,275"Global rendering quality key");276public static final Object VALUE_RENDER_SPEED =277new SunHints.Value(KEY_RENDERING,278SunHints.INTVAL_RENDER_SPEED,279"Fastest rendering methods");280public static final Object VALUE_RENDER_QUALITY =281new SunHints.Value(KEY_RENDERING,282SunHints.INTVAL_RENDER_QUALITY,283"Highest quality rendering methods");284public static final Object VALUE_RENDER_DEFAULT =285new SunHints.Value(KEY_RENDERING,286SunHints.INTVAL_RENDER_DEFAULT,287"Default rendering methods");288289/**290* Antialiasing hint key and value objects291*/292public static final Key KEY_ANTIALIASING =293new SunHints.Key(SunHints.INTKEY_ANTIALIASING,294"Global antialiasing enable key");295public static final Object VALUE_ANTIALIAS_ON =296new SunHints.Value(KEY_ANTIALIASING,297SunHints.INTVAL_ANTIALIAS_ON,298"Antialiased rendering mode");299public static final Object VALUE_ANTIALIAS_OFF =300new SunHints.Value(KEY_ANTIALIASING,301SunHints.INTVAL_ANTIALIAS_OFF,302"Nonantialiased rendering mode");303public static final Object VALUE_ANTIALIAS_DEFAULT =304new SunHints.Value(KEY_ANTIALIASING,305SunHints.INTVAL_ANTIALIAS_DEFAULT,306"Default antialiasing rendering mode");307308/**309* Text antialiasing hint key and value objects310*/311public static final Key KEY_TEXT_ANTIALIASING =312new SunHints.Key(SunHints.INTKEY_TEXT_ANTIALIASING,313"Text-specific antialiasing enable key");314public static final Object VALUE_TEXT_ANTIALIAS_ON =315new SunHints.Value(KEY_TEXT_ANTIALIASING,316SunHints.INTVAL_TEXT_ANTIALIAS_ON,317"Antialiased text mode");318public static final Object VALUE_TEXT_ANTIALIAS_OFF =319new SunHints.Value(KEY_TEXT_ANTIALIASING,320SunHints.INTVAL_TEXT_ANTIALIAS_OFF,321"Nonantialiased text mode");322public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT =323new SunHints.Value(KEY_TEXT_ANTIALIASING,324SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT,325"Default antialiasing text mode");326public static final Object VALUE_TEXT_ANTIALIAS_GASP =327new SunHints.Value(KEY_TEXT_ANTIALIASING,328SunHints.INTVAL_TEXT_ANTIALIAS_GASP,329"gasp antialiasing text mode");330public static final Object VALUE_TEXT_ANTIALIAS_LCD_HRGB =331new SunHints.Value(KEY_TEXT_ANTIALIASING,332SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB,333"LCD HRGB antialiasing text mode");334public static final Object VALUE_TEXT_ANTIALIAS_LCD_HBGR =335new SunHints.Value(KEY_TEXT_ANTIALIASING,336SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HBGR,337"LCD HBGR antialiasing text mode");338public static final Object VALUE_TEXT_ANTIALIAS_LCD_VRGB =339new SunHints.Value(KEY_TEXT_ANTIALIASING,340SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB,341"LCD VRGB antialiasing text mode");342public static final Object VALUE_TEXT_ANTIALIAS_LCD_VBGR =343new SunHints.Value(KEY_TEXT_ANTIALIASING,344SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VBGR,345"LCD VBGR antialiasing text mode");346347/**348* Font fractional metrics hint key and value objects349*/350public static final Key KEY_FRACTIONALMETRICS =351new SunHints.Key(SunHints.INTKEY_FRACTIONALMETRICS,352"Fractional metrics enable key");353public static final Object VALUE_FRACTIONALMETRICS_ON =354new SunHints.Value(KEY_FRACTIONALMETRICS,355SunHints.INTVAL_FRACTIONALMETRICS_ON,356"Fractional text metrics mode");357public static final Object VALUE_FRACTIONALMETRICS_OFF =358new SunHints.Value(KEY_FRACTIONALMETRICS,359SunHints.INTVAL_FRACTIONALMETRICS_OFF,360"Integer text metrics mode");361public static final Object VALUE_FRACTIONALMETRICS_DEFAULT =362new SunHints.Value(KEY_FRACTIONALMETRICS,363SunHints.INTVAL_FRACTIONALMETRICS_DEFAULT,364"Default fractional text metrics mode");365366/**367* Dithering hint key and value objects368*/369public static final Key KEY_DITHERING =370new SunHints.Key(SunHints.INTKEY_DITHERING,371"Dithering quality key");372public static final Object VALUE_DITHER_ENABLE =373new SunHints.Value(KEY_DITHERING,374SunHints.INTVAL_DITHER_ENABLE,375"Dithered rendering mode");376public static final Object VALUE_DITHER_DISABLE =377new SunHints.Value(KEY_DITHERING,378SunHints.INTVAL_DITHER_DISABLE,379"Nondithered rendering mode");380public static final Object VALUE_DITHER_DEFAULT =381new SunHints.Value(KEY_DITHERING,382SunHints.INTVAL_DITHER_DEFAULT,383"Default dithering mode");384385/**386* Interpolation hint key and value objects387*/388public static final Key KEY_INTERPOLATION =389new SunHints.Key(SunHints.INTKEY_INTERPOLATION,390"Image interpolation method key");391public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR =392new SunHints.Value(KEY_INTERPOLATION,393SunHints.INTVAL_INTERPOLATION_NEAREST_NEIGHBOR,394"Nearest Neighbor image interpolation mode");395public static final Object VALUE_INTERPOLATION_BILINEAR =396new SunHints.Value(KEY_INTERPOLATION,397SunHints.INTVAL_INTERPOLATION_BILINEAR,398"Bilinear image interpolation mode");399public static final Object VALUE_INTERPOLATION_BICUBIC =400new SunHints.Value(KEY_INTERPOLATION,401SunHints.INTVAL_INTERPOLATION_BICUBIC,402"Bicubic image interpolation mode");403404/**405* Alpha interpolation hint key and value objects406*/407public static final Key KEY_ALPHA_INTERPOLATION =408new SunHints.Key(SunHints.INTKEY_ALPHA_INTERPOLATION,409"Alpha blending interpolation method key");410public static final Object VALUE_ALPHA_INTERPOLATION_SPEED =411new SunHints.Value(KEY_ALPHA_INTERPOLATION,412SunHints.INTVAL_ALPHA_INTERPOLATION_SPEED,413"Fastest alpha blending methods");414public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY =415new SunHints.Value(KEY_ALPHA_INTERPOLATION,416SunHints.INTVAL_ALPHA_INTERPOLATION_QUALITY,417"Highest quality alpha blending methods");418public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT =419new SunHints.Value(KEY_ALPHA_INTERPOLATION,420SunHints.INTVAL_ALPHA_INTERPOLATION_DEFAULT,421"Default alpha blending methods");422423/**424* Color rendering hint key and value objects425*/426public static final Key KEY_COLOR_RENDERING =427new SunHints.Key(SunHints.INTKEY_COLOR_RENDERING,428"Color rendering quality key");429public static final Object VALUE_COLOR_RENDER_SPEED =430new SunHints.Value(KEY_COLOR_RENDERING,431SunHints.INTVAL_COLOR_RENDER_SPEED,432"Fastest color rendering mode");433public static final Object VALUE_COLOR_RENDER_QUALITY =434new SunHints.Value(KEY_COLOR_RENDERING,435SunHints.INTVAL_COLOR_RENDER_QUALITY,436"Highest quality color rendering mode");437public static final Object VALUE_COLOR_RENDER_DEFAULT =438new SunHints.Value(KEY_COLOR_RENDERING,439SunHints.INTVAL_COLOR_RENDER_DEFAULT,440"Default color rendering mode");441442/**443* Stroke normalization control hint key and value objects444*/445public static final Key KEY_STROKE_CONTROL =446new SunHints.Key(SunHints.INTKEY_STROKE_CONTROL,447"Stroke normalization control key");448public static final Object VALUE_STROKE_DEFAULT =449new SunHints.Value(KEY_STROKE_CONTROL,450SunHints.INTVAL_STROKE_DEFAULT,451"Default stroke normalization");452public static final Object VALUE_STROKE_NORMALIZE =453new SunHints.Value(KEY_STROKE_CONTROL,454SunHints.INTVAL_STROKE_NORMALIZE,455"Normalize strokes for consistent rendering");456public static final Object VALUE_STROKE_PURE =457new SunHints.Value(KEY_STROKE_CONTROL,458SunHints.INTVAL_STROKE_PURE,459"Pure stroke conversion for accurate paths");460461/**462* Image resolution variant hint key and value objects463*/464public static final Key KEY_RESOLUTION_VARIANT =465new SunHints.Key(SunHints.INTKEY_RESOLUTION_VARIANT,466"Global image resolution variant key");467public static final Object VALUE_RESOLUTION_VARIANT_DEFAULT =468new SunHints.Value(KEY_RESOLUTION_VARIANT,469SunHints.INTVAL_RESOLUTION_VARIANT_DEFAULT,470"Choose image resolutions based on a default"471+ "heuristic");472public static final Object VALUE_RESOLUTION_VARIANT_BASE =473new SunHints.Value(KEY_RESOLUTION_VARIANT,474SunHints.INTVAL_RESOLUTION_VARIANT_BASE,475"Use only the standard resolution of an image");476public static final Object VALUE_RESOLUTION_VARIANT_SIZE_FIT =477new SunHints.Value(KEY_RESOLUTION_VARIANT,478SunHints.INTVAL_RESOLUTION_VARIANT_SIZE_FIT,479"Choose image resolutions based on the DPI"480+ "of the screen and transform"481+ "in the Graphics2D context");482public static final Object VALUE_RESOLUTION_VARIANT_DPI_FIT =483new SunHints.Value(KEY_RESOLUTION_VARIANT,484SunHints.INTVAL_RESOLUTION_VARIANT_DPI_FIT,485"Choose image resolutions based only on the DPI"486+ " of the screen");487488public static class LCDContrastKey extends Key {489490public LCDContrastKey(int privatekey, String description) {491super(privatekey, description);492}493494/**495* Returns true if the specified object is a valid value496* for this Key. The allowable range is 100 to 250.497*/498public final boolean isCompatibleValue(Object val) {499if (val instanceof Integer) {500int ival = ((Integer)val).intValue();501return ival >= 100 && ival <= 250;502}503return false;504}505506}507508/**509* LCD text contrast hint key510*/511public static final RenderingHints.Key512KEY_TEXT_ANTIALIAS_LCD_CONTRAST =513new LCDContrastKey(SunHints.INTKEY_AATEXT_LCD_CONTRAST,514"Text-specific LCD contrast key");515}516517518