src/java.desktop/share/classes/java/awt/Font.java

Print this page




  27 
  28 import java.awt.font.FontRenderContext;
  29 import java.awt.font.GlyphVector;
  30 import java.awt.font.LineMetrics;
  31 import java.awt.font.TextAttribute;
  32 import java.awt.font.TextLayout;
  33 import java.awt.geom.AffineTransform;
  34 import java.awt.geom.Point2D;
  35 import java.awt.geom.Rectangle2D;
  36 import java.awt.peer.FontPeer;
  37 import java.io.*;
  38 import java.lang.ref.SoftReference;
  39 import java.nio.file.Files;
  40 import java.security.AccessController;
  41 import java.security.PrivilegedExceptionAction;
  42 import java.text.AttributedCharacterIterator.Attribute;
  43 import java.text.CharacterIterator;
  44 import java.util.Hashtable;
  45 import java.util.Locale;
  46 import java.util.Map;


  47 import sun.font.StandardGlyphVector;
  48 
  49 import sun.font.AttributeMap;
  50 import sun.font.AttributeValues;
  51 import sun.font.CompositeFont;
  52 import sun.font.CreatedFontTracker;
  53 import sun.font.Font2D;
  54 import sun.font.Font2DHandle;
  55 import sun.font.FontAccess;
  56 import sun.font.FontManager;
  57 import sun.font.FontManagerFactory;
  58 import sun.font.FontUtilities;
  59 import sun.font.GlyphLayout;
  60 import sun.font.FontLineMetrics;
  61 import sun.font.CoreMetrics;
  62 
  63 import static sun.font.EAttribute.*;
  64 
  65 /**
  66  * The <code>Font</code> class represents fonts, which are used to


 429      * A cached value used when a transform is required for internal
 430      * use.  This must not be exposed to callers since AffineTransform
 431      * is mutable.
 432      */
 433     private static final AffineTransform identityTx = new AffineTransform();
 434 
 435     /*
 436      * JDK 1.1 serialVersionUID
 437      */
 438     private static final long serialVersionUID = -4206021311591459213L;
 439 
 440     /**
 441      * Gets the peer of this {@code Font}.
 442      *
 443      * @return the peer of the {@code Font}.
 444      */
 445     @SuppressWarnings("deprecation")
 446     private FontPeer getFontPeer() {
 447         if(peer == null) {
 448             Toolkit tk = Toolkit.getDefaultToolkit();
 449             peer = tk.getFontPeer(name, style);


 450         }
 451         return peer;
 452     }
 453 
 454     /**
 455      * Return the AttributeValues object associated with this
 456      * font.  Most of the time, the internal object is null.
 457      * If required, it will be created from the 'standard'
 458      * state on the font.  Only non-default values will be
 459      * set in the AttributeValues object.
 460      *
 461      * <p>Since the AttributeValues object is mutable, and it
 462      * is cached in the font, care must be taken to ensure that
 463      * it is not mutated.
 464      */
 465     private AttributeValues getAttributeValues() {
 466         if (values == null) {
 467             AttributeValues valuesTmp = new AttributeValues();
 468             valuesTmp.setFamily(name);
 469             valuesTmp.setSize(pointSize); // expects the float value.




  27 
  28 import java.awt.font.FontRenderContext;
  29 import java.awt.font.GlyphVector;
  30 import java.awt.font.LineMetrics;
  31 import java.awt.font.TextAttribute;
  32 import java.awt.font.TextLayout;
  33 import java.awt.geom.AffineTransform;
  34 import java.awt.geom.Point2D;
  35 import java.awt.geom.Rectangle2D;
  36 import java.awt.peer.FontPeer;
  37 import java.io.*;
  38 import java.lang.ref.SoftReference;
  39 import java.nio.file.Files;
  40 import java.security.AccessController;
  41 import java.security.PrivilegedExceptionAction;
  42 import java.text.AttributedCharacterIterator.Attribute;
  43 import java.text.CharacterIterator;
  44 import java.util.Hashtable;
  45 import java.util.Locale;
  46 import java.util.Map;
  47 
  48 import sun.awt.ComponentFactory;
  49 import sun.font.StandardGlyphVector;
  50 
  51 import sun.font.AttributeMap;
  52 import sun.font.AttributeValues;
  53 import sun.font.CompositeFont;
  54 import sun.font.CreatedFontTracker;
  55 import sun.font.Font2D;
  56 import sun.font.Font2DHandle;
  57 import sun.font.FontAccess;
  58 import sun.font.FontManager;
  59 import sun.font.FontManagerFactory;
  60 import sun.font.FontUtilities;
  61 import sun.font.GlyphLayout;
  62 import sun.font.FontLineMetrics;
  63 import sun.font.CoreMetrics;
  64 
  65 import static sun.font.EAttribute.*;
  66 
  67 /**
  68  * The <code>Font</code> class represents fonts, which are used to


 431      * A cached value used when a transform is required for internal
 432      * use.  This must not be exposed to callers since AffineTransform
 433      * is mutable.
 434      */
 435     private static final AffineTransform identityTx = new AffineTransform();
 436 
 437     /*
 438      * JDK 1.1 serialVersionUID
 439      */
 440     private static final long serialVersionUID = -4206021311591459213L;
 441 
 442     /**
 443      * Gets the peer of this {@code Font}.
 444      *
 445      * @return the peer of the {@code Font}.
 446      */
 447     @SuppressWarnings("deprecation")
 448     private FontPeer getFontPeer() {
 449         if(peer == null) {
 450             Toolkit tk = Toolkit.getDefaultToolkit();
 451             if (tk instanceof ComponentFactory) {
 452                 peer = ((ComponentFactory) tk).getFontPeer(name, style);
 453             }
 454         }
 455         return peer;
 456     }
 457 
 458     /**
 459      * Return the AttributeValues object associated with this
 460      * font.  Most of the time, the internal object is null.
 461      * If required, it will be created from the 'standard'
 462      * state on the font.  Only non-default values will be
 463      * set in the AttributeValues object.
 464      *
 465      * <p>Since the AttributeValues object is mutable, and it
 466      * is cached in the font, care must be taken to ensure that
 467      * it is not mutated.
 468      */
 469     private AttributeValues getAttributeValues() {
 470         if (values == null) {
 471             AttributeValues valuesTmp = new AttributeValues();
 472             valuesTmp.setFamily(name);
 473             valuesTmp.setSize(pointSize); // expects the float value.