src/share/classes/sun/font/Decoration.java

Print this page




  29  */
  30 
  31 package sun.font;
  32 
  33 import java.util.Map;
  34 
  35 import java.awt.BasicStroke;
  36 import java.awt.Color;
  37 import java.awt.Graphics2D;
  38 import java.awt.Paint;
  39 import java.awt.RenderingHints;
  40 import java.awt.Shape;
  41 import java.awt.Stroke;
  42 
  43 import java.awt.font.TextAttribute;
  44 
  45 import java.awt.geom.Area;
  46 import java.awt.geom.Line2D;
  47 import java.awt.geom.Rectangle2D;
  48 import java.awt.geom.GeneralPath;

  49 
  50 import static sun.font.AttributeValues.*;
  51 import static sun.font.EAttribute.*;
  52 
  53 /**
  54  * This class handles underlining, strikethrough, and foreground and
  55  * background styles on text.  Clients simply acquire instances
  56  * of this class and hand them off to ExtendedTextLabels or GraphicComponents.
  57  */
  58 public class Decoration {
  59 
  60     /**
  61      * This interface is implemented by clients that use Decoration.
  62      * Unfortunately, interface methods have to public;  ideally these
  63      * would be package-private.
  64      */
  65     public interface Label {
  66         CoreMetrics getCoreMetrics();
  67         Rectangle2D getLogicalBounds();
  68 


  90 
  91     public static Decoration getDecoration(AttributeValues values) {
  92         if (values == null || !values.anyDefined(VALUES_MASK)) {
  93             return PLAIN;
  94         }
  95 
  96         values = values.applyIMHighlight();
  97 
  98         return new DecorationImpl(values.getForeground(),
  99                                   values.getBackground(),
 100                                   values.getSwapColors(),
 101                                   values.getStrikethrough(),
 102                                   Underline.getUnderline(values.getUnderline()),
 103                                   Underline.getUnderline(values.getInputMethodUnderline()));
 104     }
 105 
 106     /**
 107      * Return a Decoration appropriate for the the given Map.
 108      * @param attributes the Map used to determine the Decoration
 109      */
 110     public static Decoration getDecoration(Map attributes) {
 111         if (attributes == null) {
 112             return PLAIN;
 113         }
 114         return getDecoration(AttributeValues.fromMap(attributes));
 115     }
 116 
 117     public void drawTextAndDecorations(Label label,
 118                                 Graphics2D g2d,
 119                                 float x,
 120                                 float y) {
 121 
 122         label.handleDraw(g2d, x, y);
 123     }
 124 
 125     public Rectangle2D getVisualBounds(Label label) {
 126 
 127         return label.handleGetVisualBounds();
 128     }
 129 
 130     public Rectangle2D getCharVisualBounds(Label label, int index) {




  29  */
  30 
  31 package sun.font;
  32 
  33 import java.util.Map;
  34 
  35 import java.awt.BasicStroke;
  36 import java.awt.Color;
  37 import java.awt.Graphics2D;
  38 import java.awt.Paint;
  39 import java.awt.RenderingHints;
  40 import java.awt.Shape;
  41 import java.awt.Stroke;
  42 
  43 import java.awt.font.TextAttribute;
  44 
  45 import java.awt.geom.Area;
  46 import java.awt.geom.Line2D;
  47 import java.awt.geom.Rectangle2D;
  48 import java.awt.geom.GeneralPath;
  49 import java.text.AttributedCharacterIterator.Attribute;
  50 
  51 import static sun.font.AttributeValues.*;
  52 import static sun.font.EAttribute.*;
  53 
  54 /**
  55  * This class handles underlining, strikethrough, and foreground and
  56  * background styles on text.  Clients simply acquire instances
  57  * of this class and hand them off to ExtendedTextLabels or GraphicComponents.
  58  */
  59 public class Decoration {
  60 
  61     /**
  62      * This interface is implemented by clients that use Decoration.
  63      * Unfortunately, interface methods have to public;  ideally these
  64      * would be package-private.
  65      */
  66     public interface Label {
  67         CoreMetrics getCoreMetrics();
  68         Rectangle2D getLogicalBounds();
  69 


  91 
  92     public static Decoration getDecoration(AttributeValues values) {
  93         if (values == null || !values.anyDefined(VALUES_MASK)) {
  94             return PLAIN;
  95         }
  96 
  97         values = values.applyIMHighlight();
  98 
  99         return new DecorationImpl(values.getForeground(),
 100                                   values.getBackground(),
 101                                   values.getSwapColors(),
 102                                   values.getStrikethrough(),
 103                                   Underline.getUnderline(values.getUnderline()),
 104                                   Underline.getUnderline(values.getInputMethodUnderline()));
 105     }
 106 
 107     /**
 108      * Return a Decoration appropriate for the the given Map.
 109      * @param attributes the Map used to determine the Decoration
 110      */
 111     public static Decoration getDecoration(Map<? extends Attribute, ?> attributes) {
 112         if (attributes == null) {
 113             return PLAIN;
 114         }
 115         return getDecoration(AttributeValues.fromMap(attributes));
 116     }
 117 
 118     public void drawTextAndDecorations(Label label,
 119                                 Graphics2D g2d,
 120                                 float x,
 121                                 float y) {
 122 
 123         label.handleDraw(g2d, x, y);
 124     }
 125 
 126     public Rectangle2D getVisualBounds(Label label) {
 127 
 128         return label.handleGetVisualBounds();
 129     }
 130 
 131     public Rectangle2D getCharVisualBounds(Label label, int index) {