< prev index next >

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

Print this page




  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.EventListener;
  45 import java.util.Hashtable;
  46 import java.util.Locale;
  47 import java.util.Map;
  48 
  49 import sun.awt.ComponentFactory;
  50 import sun.font.StandardGlyphVector;
  51 
  52 import sun.font.AttributeMap;
  53 import sun.font.AttributeValues;
  54 import sun.font.CompositeFont;
  55 import sun.font.CreatedFontTracker;
  56 import sun.font.Font2D;
  57 import sun.font.Font2DHandle;
  58 import sun.font.FontAccess;

  59 import sun.font.FontManager;
  60 import sun.font.FontManagerFactory;
  61 import sun.font.FontUtilities;
  62 import sun.font.GlyphLayout;
  63 import sun.font.FontLineMetrics;
  64 import sun.font.CoreMetrics;
  65 
  66 import static sun.font.EAttribute.*;
  67 
  68 /**
  69  * The {@code Font} class represents fonts, which are used to
  70  * render text in a visible way.
  71  * A font provides the information needed to map sequences of
  72  * <em>characters</em> to sequences of <em>glyphs</em>
  73  * and to render sequences of glyphs on {@code Graphics} and
  74  * {@code Component} objects.
  75  *
  76  * <h3>Characters and Glyphs</h3>
  77  *
  78  * A <em>character</em> is a symbol that represents an item such as a letter,


2586         }
2587         if (limit > chars.length) {
2588             throw new IndexOutOfBoundsException("limit: " + limit);
2589         }
2590         if (beginIndex > limit) {
2591             throw new IndexOutOfBoundsException("range length: " +
2592                                                 (limit - beginIndex));
2593         }
2594 
2595         // this code should be in textlayout
2596         // quick check for simple text, assume GV ok to use if simple
2597 
2598         boolean simple = values == null ||
2599             (values.getKerning() == 0 && values.getLigatures() == 0 &&
2600               values.getBaselineTransform() == null);
2601         if (simple) {
2602             simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
2603         }
2604 
2605         if (simple) {
2606             GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
2607                                                      limit - beginIndex, frc);
2608             return gv.getLogicalBounds();
2609         } else {
2610             // need char array constructor on textlayout
2611             String str = new String(chars, beginIndex, limit - beginIndex);
2612             TextLayout tl = new TextLayout(str, this, frc);
2613             return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
2614                                          tl.getAscent() + tl.getDescent() +
2615                                          tl.getLeading());
2616         }
2617     }
2618 
2619    /**
2620      * Returns the logical bounds of the characters indexed in the
2621      * specified {@link CharacterIterator} in the
2622      * specified {@code FontRenderContext}.  The logical bounds
2623      * contains the origin, ascent, advance, and height, which includes
2624      * the leading.  The logical bounds does not always enclose all the
2625      * text.  For example, in some languages and in some fonts, accent
2626      * marks can be positioned above the ascent or below the descent.
2627      * To obtain a visual bounding box, which encloses all the text,
2628      * use the {@link TextLayout#getBounds() getBounds} method of




  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.EventListener;
  45 import java.util.Hashtable;
  46 import java.util.Locale;
  47 import java.util.Map;
  48 
  49 import sun.awt.ComponentFactory;
  50 import sun.font.StandardGlyphVector;
  51 
  52 import sun.font.AttributeMap;
  53 import sun.font.AttributeValues;
  54 import sun.font.CompositeFont;
  55 import sun.font.CreatedFontTracker;
  56 import sun.font.Font2D;
  57 import sun.font.Font2DHandle;
  58 import sun.font.FontAccess;
  59 import sun.font.FontDesignMetrics;
  60 import sun.font.FontManager;
  61 import sun.font.FontManagerFactory;
  62 import sun.font.FontUtilities;
  63 import sun.font.GlyphLayout;
  64 import sun.font.FontLineMetrics;
  65 import sun.font.CoreMetrics;
  66 
  67 import static sun.font.EAttribute.*;
  68 
  69 /**
  70  * The {@code Font} class represents fonts, which are used to
  71  * render text in a visible way.
  72  * A font provides the information needed to map sequences of
  73  * <em>characters</em> to sequences of <em>glyphs</em>
  74  * and to render sequences of glyphs on {@code Graphics} and
  75  * {@code Component} objects.
  76  *
  77  * <h3>Characters and Glyphs</h3>
  78  *
  79  * A <em>character</em> is a symbol that represents an item such as a letter,


2587         }
2588         if (limit > chars.length) {
2589             throw new IndexOutOfBoundsException("limit: " + limit);
2590         }
2591         if (beginIndex > limit) {
2592             throw new IndexOutOfBoundsException("range length: " +
2593                                                 (limit - beginIndex));
2594         }
2595 
2596         // this code should be in textlayout
2597         // quick check for simple text, assume GV ok to use if simple
2598 
2599         boolean simple = values == null ||
2600             (values.getKerning() == 0 && values.getLigatures() == 0 &&
2601               values.getBaselineTransform() == null);
2602         if (simple) {
2603             simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
2604         }
2605 
2606         if (simple) {
2607             FontDesignMetrics metrics = FontDesignMetrics.getMetrics(this, frc);
2608             return metrics.getSimpleBounds(chars, beginIndex, limit-beginIndex);

2609         } else {
2610             // need char array constructor on textlayout
2611             String str = new String(chars, beginIndex, limit - beginIndex);
2612             TextLayout tl = new TextLayout(str, this, frc);
2613             return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
2614                                          tl.getAscent() + tl.getDescent() +
2615                                          tl.getLeading());
2616         }
2617     }
2618 
2619    /**
2620      * Returns the logical bounds of the characters indexed in the
2621      * specified {@link CharacterIterator} in the
2622      * specified {@code FontRenderContext}.  The logical bounds
2623      * contains the origin, ascent, advance, and height, which includes
2624      * the leading.  The logical bounds does not always enclose all the
2625      * text.  For example, in some languages and in some fonts, accent
2626      * marks can be positioned above the ascent or below the descent.
2627      * To obtain a visual bounding box, which encloses all the text,
2628      * use the {@link TextLayout#getBounds() getBounds} method of


< prev index next >