jdk/src/share/classes/java/awt/Font.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8520 a9e798f494cb
child 11270 d7b0b63bd082
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8520
diff changeset
     2
 * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.font.FontRenderContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.font.GlyphVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.font.LineMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.font.TextAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.font.TextLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.peer.FontPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.ref.SoftReference;
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
    39
import java.security.AccessController;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
    40
import java.security.PrivilegedExceptionAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.text.AttributedCharacterIterator.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.text.CharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.text.StringCharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.font.StandardGlyphVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.font.AttributeMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.font.AttributeValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.font.CompositeFont;
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
    52
import sun.font.CreatedFontTracker;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.font.Font2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.font.Font2DHandle;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
    55
import sun.font.FontAccess;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.font.FontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
    57
import sun.font.FontManagerFactory;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
    58
import sun.font.FontUtilities;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.font.GlyphLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import sun.font.FontLineMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import sun.font.CoreMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import static sun.font.EAttribute.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * The <code>Font</code> class represents fonts, which are used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * render text in a visible way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * A font provides the information needed to map sequences of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <em>characters</em> to sequences of <em>glyphs</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * and to render sequences of glyphs on <code>Graphics</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <code>Component</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <h4>Characters and Glyphs</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * A <em>character</em> is a symbol that represents an item such as a letter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * a digit, or punctuation in an abstract way. For example, <code>'g'</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <font size=-1>LATIN SMALL LETTER G</font>, is a character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * A <em>glyph</em> is a shape used to render a character or a sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * characters. In simple writing systems, such as Latin, typically one glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * represents one character. In general, however, characters and glyphs do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * have one-to-one correspondence. For example, the character '&aacute;'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <font size=-1>LATIN SMALL LETTER A WITH ACUTE</font>, can be represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * two glyphs: one for 'a' and one for '&acute;'. On the other hand, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * two-character string "fi" can be represented by a single glyph, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * "fi" ligature. In complex writing systems, such as Arabic or the South
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * and South-East Asian writing systems, the relationship between characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * and glyphs can be more complicated and involve context-dependent selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * of glyphs as well as glyph reordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * A font encapsulates the collection of glyphs needed to render a selected set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * of characters as well as the tables needed to map sequences of characters to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * corresponding sequences of glyphs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <h4>Physical and Logical Fonts</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * The Java Platform distinguishes between two kinds of fonts:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * <em>physical</em> fonts and <em>logical</em> fonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <em>Physical</em> fonts are the actual font libraries containing glyph data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * and tables to map from character sequences to glyph sequences, using a font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * technology such as TrueType or PostScript Type 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * All implementations of the Java Platform must support TrueType fonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * support for other font technologies is implementation dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * Physical fonts may use names such as Helvetica, Palatino, HonMincho, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * any number of other font names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * Typically, each physical font supports only a limited set of writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * systems, for example, only Latin characters or only Japanese and Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * Latin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * The set of available physical fonts varies between configurations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * Applications that require specific fonts can bundle them and instantiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * them using the {@link #createFont createFont} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <em>Logical</em> fonts are the five font families defined by the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * platform which must be supported by any Java runtime environment:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * Serif, SansSerif, Monospaced, Dialog, and DialogInput.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * These logical fonts are not actual font libraries. Instead, the logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * font names are mapped to physical fonts by the Java runtime environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * The mapping is implementation and usually locale dependent, so the look
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * and the metrics provided by them vary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * Typically, each logical font name maps to several physical fonts in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * cover a large range of characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * Peered AWT components, such as {@link Label Label} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * {@link TextField TextField}, can only use logical fonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * For a discussion of the relative advantages and disadvantages of using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * physical or logical fonts, see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * <a href="http://java.sun.com/j2se/corejava/intl/reference/faqs/index.html#desktop-rendering">Internationalization FAQ</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * <h4>Font Faces and Names</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * A <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * can have many faces, such as heavy, medium, oblique, gothic and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * regular. All of these faces have similar typographic design.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * There are three different names that you can get from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * <code>Font</code> object.  The <em>logical font name</em> is simply the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * name that was used to construct the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * The <em>font face name</em>, or just <em>font name</em> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * short, is the name of a particular font face, like Helvetica Bold. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <em>family name</em> is the name of the font family that determines the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * typographic design across several faces, like Helvetica.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * The <code>Font</code> class represents an instance of a font face from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * a collection of  font faces that are present in the system resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * of the host system.  As examples, Arial Bold and Courier Bold Italic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * are font faces.  There can be several <code>Font</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * associated with a font face, each differing in size, style, transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * and font features.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * The {@link GraphicsEnvironment#getAllFonts() getAllFonts} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * of the <code>GraphicsEnvironment</code> class returns an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * array of all font faces available in the system. These font faces are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * returned as <code>Font</code> objects with a size of 1, identity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * transform and default font features. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * base fonts can then be used to derive new <code>Font</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * with varying sizes, styles, transforms and font features via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * <code>deriveFont</code> methods in this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * <h4>Font and TextAttribute</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * <p><code>Font</code> supports most
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * <code>TextAttribute</code>s.  This makes some operations, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * rendering underlined text, convenient since it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * necessary to explicitly construct a <code>TextLayout</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * Attributes can be set on a Font by constructing or deriving it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * using a <code>Map</code> of <code>TextAttribute</code> values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * <p>The values of some <code>TextAttributes</code> are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * serializable, and therefore attempting to serialize an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * <code>Font</code> that has such values will not serialize them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * This means a Font deserialized from such a stream will not compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * equal to the original Font that contained the non-serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * attributes.  This should very rarely pose a problem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * since these attributes are typically used only in special
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * circumstances and are unlikely to be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * <li><code>FOREGROUND</code> and <code>BACKGROUND</code> use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * <code>Paint</code> values. The subclass <code>Color</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * serializable, while <code>GradientPaint</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * <code>TexturePaint</code> are not.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * <li><code>CHAR_REPLACEMENT</code> uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * <code>GraphicAttribute</code> values.  The subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * <code>ShapeGraphicAttribute</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * <code>ImageGraphicAttribute</code> are not serializable.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * <li><code>INPUT_METHOD_HIGHLIGHT</code> uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * <code>InputMethodHighlight</code> values, which are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * not serializable.  See {@link java.awt.im.InputMethodHighlight}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * Clients who create custom subclasses of <code>Paint</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * <code>GraphicAttribute</code> can make them serializable and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * avoid this problem.  Clients who use input method highlights can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * convert these to the platform-specific attributes for that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * highlight on the current platform and set them on the Font as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * a workaround.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * <p>The <code>Map</code>-based constructor and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * <code>deriveFont</code> APIs ignore the FONT attribute, and it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * not retained by the Font; the static {@link #getFont} method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * be used if the FONT attribute might be present.  See {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * java.awt.font.TextAttribute#FONT} for more information.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * <p>Several attributes will cause additional rendering overhead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * and potentially invoke layout.  If a <code>Font</code> has such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * attributes, the <code>{@link #hasLayoutAttributes()}</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * will return true.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * <p>Note: Font rotations can cause text baselines to be rotated.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * order to account for this (rare) possibility, font APIs are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * specified to return metrics and take parameters 'in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * baseline-relative coordinates'.  This maps the 'x' coordinate to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * the advance along the baseline, (positive x is forward along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * baseline), and the 'y' coordinate to a distance along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 * perpendicular to the baseline at 'x' (positive y is 90 degrees
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * clockwise from the baseline vector).  APIs for which this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * especially important are called out as having 'baseline-relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * coordinates.'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
public class Font implements java.io.Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
{
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   225
    private static class FontAccessImpl extends FontAccess {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   226
        public Font2D getFont2D(Font font) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   227
            return font.getFont2D();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   228
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   229
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   230
        public void setFont2D(Font font, Font2DHandle handle) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   231
            font.font2DHandle = handle;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   232
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   233
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   234
        public void setCreatedFont(Font font) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   235
            font.createdFont = true;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   236
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   237
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   238
        public boolean isCreatedFont(Font font) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   239
            return font.createdFont;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   240
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   241
    }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   242
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        initIDs();
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   247
        FontAccess.setFontAccess(new FontAccessImpl());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * This is now only used during serialization.  Typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * it is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @see #getAttributes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    private Hashtable fRequestedAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Constants to be used for logical font family names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * A String constant for the canonical family name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * logical font "Dialog". It is useful in Font construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * to provide compile-time verification of the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public static final String DIALOG = "Dialog";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * A String constant for the canonical family name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * logical font "DialogInput". It is useful in Font construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * to provide compile-time verification of the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public static final String DIALOG_INPUT = "DialogInput";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * A String constant for the canonical family name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * logical font "SansSerif". It is useful in Font construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * to provide compile-time verification of the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public static final String SANS_SERIF = "SansSerif";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * A String constant for the canonical family name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * logical font "Serif". It is useful in Font construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * to provide compile-time verification of the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public static final String SERIF = "Serif";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * A String constant for the canonical family name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * logical font "Monospaced". It is useful in Font construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * to provide compile-time verification of the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public static final String MONOSPACED = "Monospaced";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Constants to be used for styles. Can be combined to mix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * styles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * The plain style constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public static final int PLAIN       = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * The bold style constant.  This can be combined with the other style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * constants (except PLAIN) for mixed styles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public static final int BOLD        = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * The italicized style constant.  This can be combined with the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * style constants (except PLAIN) for mixed styles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public static final int ITALIC      = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * The baseline used in most Roman scripts when laying out text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public static final int ROMAN_BASELINE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * The baseline used in ideographic scripts like Chinese, Japanese,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * and Korean when laying out text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public static final int CENTER_BASELINE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * The baseline used in Devanigiri and similar scripts when laying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * out text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public static final int HANGING_BASELINE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Identify a font resource of type TRUETYPE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Used to specify a TrueType font resource to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * {@link #createFont} method.
5578
c25ebb5bc2d6 6954424: Support OpenType/CFF fonts in JDK 7
prr
parents: 3928
diff changeset
   346
     * The TrueType format was extended to become the OpenType
c25ebb5bc2d6 6954424: Support OpenType/CFF fonts in JDK 7
prr
parents: 3928
diff changeset
   347
     * format, which adds support for fonts with Postscript outlines,
c25ebb5bc2d6 6954424: Support OpenType/CFF fonts in JDK 7
prr
parents: 3928
diff changeset
   348
     * this tag therefore references these fonts, as well as those
c25ebb5bc2d6 6954424: Support OpenType/CFF fonts in JDK 7
prr
parents: 3928
diff changeset
   349
     * with TrueType outlines.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public static final int TRUETYPE_FONT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Identify a font resource of type TYPE1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Used to specify a Type1 font resource to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * {@link #createFont} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public static final int TYPE1_FONT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * The logical name of this <code>Font</code>, as passed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @see #getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    protected String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * The style of this <code>Font</code>, as passed to the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * This style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @see #getStyle()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    protected int style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * The point size of this <code>Font</code>, rounded to integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @see #getSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    protected int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * The point size of this <code>Font</code> in <code>float</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @see #getSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @see #getSize2D()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    protected float pointSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * The platform specific font information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    private transient FontPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    private transient long pData;       // native JDK1.1 font pointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    private transient Font2DHandle font2DHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    private transient AttributeValues values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    private transient boolean hasLayoutAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * If the origin of a Font is a created font then this attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * must be set on all derived fonts too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    private transient boolean createdFont = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * This is true if the font transform is not identity.  It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * is used to avoid unnecessary instantiation of an AffineTransform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    private transient boolean nonIdentityTx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * A cached value used when a transform is required for internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * use.  This must not be exposed to callers since AffineTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * is mutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    private static final AffineTransform identityTx = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    private static final long serialVersionUID = -4206021311591459213L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Gets the peer of this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @return  the peer of the <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @deprecated Font rendering is now platform independent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    public FontPeer getPeer(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        return getPeer_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    // NOTE: This method is called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    //       We implement this functionality in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    final FontPeer getPeer_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if(peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            Toolkit tk = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            this.peer = tk.getFontPeer(name, style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * Return the AttributeValues object associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * font.  Most of the time, the internal object is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * If required, it will be created from the 'standard'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * state on the font.  Only non-default values will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * set in the AttributeValues object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * <p>Since the AttributeValues object is mutable, and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * is cached in the font, care must be taken to ensure that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * it is not mutated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    private AttributeValues getAttributeValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (values == null) {
3017
217bf37bb0ea 6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents: 2624
diff changeset
   470
            AttributeValues valuesTmp = new AttributeValues();
217bf37bb0ea 6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents: 2624
diff changeset
   471
            valuesTmp.setFamily(name);
217bf37bb0ea 6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents: 2624
diff changeset
   472
            valuesTmp.setSize(pointSize); // expects the float value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            if ((style & BOLD) != 0) {
3017
217bf37bb0ea 6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents: 2624
diff changeset
   475
                valuesTmp.setWeight(2); // WEIGHT_BOLD
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            if ((style & ITALIC) != 0) {
3017
217bf37bb0ea 6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents: 2624
diff changeset
   479
                valuesTmp.setPosture(.2f); // POSTURE_OBLIQUE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            }
3017
217bf37bb0ea 6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents: 2624
diff changeset
   481
            valuesTmp.defineAll(PRIMARY_MASK); // for streaming compatibility
217bf37bb0ea 6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents: 2624
diff changeset
   482
            values = valuesTmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        return values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    private Font2D getFont2D() {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   489
        FontManager fm = FontManagerFactory.getInstance();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   490
        if (fm.usingPerAppContextComposites() &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            font2DHandle != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            font2DHandle.font2D instanceof CompositeFont &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   494
            return fm.findFont2D(name, style,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                          FontManager.LOGICAL_FALLBACK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        } else if (font2DHandle == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            font2DHandle =
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   498
                fm.findFont2D(name, style,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   499
                              FontManager.LOGICAL_FALLBACK).handle;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        /* Do not cache the de-referenced font2D. It must be explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         * de-referenced to pick up a valid font in the event that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         * original one is marked invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        return font2DHandle.font2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * Creates a new <code>Font</code> from the specified name, style and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * point size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * The font name can be a font face name or a font family name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * It is used together with the style to find an appropriate font face.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * When a font family name is specified, the style argument is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * select the most appropriate face from the family. When a font face
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * name is specified, the face's style and the style argument are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * merged to locate the best matching font from the same family.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * For example if face name "Arial Bold" is specified with style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * <code>Font.ITALIC</code>, the font system looks for a face in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * "Arial" family that is bold and italic, and may associate the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * instance with the physical font face "Arial Bold Italic".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * The style argument is merged with the specified face's style, not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * added or subtracted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * This means, specifying a bold face and a bold style does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * double-embolden the font, and specifying a bold face and a plain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * style does not lighten the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * If no face for the requested style can be found, the font system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * may apply algorithmic styling to achieve the desired style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * For example, if <code>ITALIC</code> is requested, but no italic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * face is available, glyphs from the plain face may be algorithmically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * obliqued (slanted).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Font name lookup is case insensitive, using the case folding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * rules of the US locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * If the <code>name</code> parameter represents something other than a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * logical font, i.e. is interpreted as a physical font face or family, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * this cannot be mapped by the implementation to a physical font or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * compatible alternative, then the font system will map the Font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * instance to "Dialog", such that for example, the family as reported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * by {@link #getFamily() getFamily} will be "Dialog".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @param name the font name.  This can be a font face name or a font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * family name, and may represent either a logical font or a physical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * font found in this {@code GraphicsEnvironment}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * The family names for logical fonts are: Dialog, DialogInput,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * Monospaced, Serif, or SansSerif. Pre-defined String constants exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * for all of these names, for example, {@code DIALOG}. If {@code name} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * {@code null}, the <em>logical font name</em> of the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * {@code Font} as returned by {@code getName()} is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * the name "Default".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @param style the style constant for the {@code Font}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * The style argument is an integer bitmask that may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * be {@code PLAIN}, or a bitwise union of {@code BOLD} and/or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * {@code ITALIC} (for example, {@code ITALIC} or {@code BOLD|ITALIC}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * If the style argument does not conform to one of the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * integer bitmasks then the style is set to {@code PLAIN}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @param size the point size of the {@code Font}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @see GraphicsEnvironment#getAllFonts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @see GraphicsEnvironment#getAvailableFontFamilyNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    public Font(String name, int style, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        this.name = (name != null) ? name : "Default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        this.style = (style & ~0x03) == 0 ? style : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        this.size = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        this.pointSize = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    private Font(String name, int style, float sizePts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        this.name = (name != null) ? name : "Default";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        this.style = (style & ~0x03) == 0 ? style : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        this.size = (int)(sizePts + 0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        this.pointSize = sizePts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    /* This constructor is used by deriveFont when attributes is null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    private Font(String name, int style, float sizePts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                 boolean created, Font2DHandle handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        this(name, style, sizePts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        this.createdFont = created;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        /* Fonts created from a stream will use the same font2D instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
         * as the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
         * One exception is that if the derived font is requested to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
         * in a different style, then also check if its a CompositeFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
         * and if so build a new CompositeFont from components of that style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
         * CompositeFonts can only be marked as "created" if they are used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         * to add fall backs to a physical font. And non-composites are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
         * always from "Font.createFont()" and shouldn't get this treatment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        if (created) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            if (handle.font2D instanceof CompositeFont &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                handle.font2D.getStyle() != style) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   596
                FontManager fm = FontManagerFactory.getInstance();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   597
                this.font2DHandle = fm.getNewComposite(null, style, handle);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                this.font2DHandle = handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    /* used to implement Font.createFont */
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   605
    private Font(File fontFile, int fontFormat,
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   606
                 boolean isCopy, CreatedFontTracker tracker)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        throws FontFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        this.createdFont = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        /* Font2D instances created by this method track their font file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
         * so that when the Font2D is GC'd it can also remove the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
         */
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   612
        FontManager fm = FontManagerFactory.getInstance();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   613
        this.font2DHandle = fm.createFont2D(fontFile, fontFormat, isCopy,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   614
                                            tracker).handle;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        this.name = this.font2DHandle.font2D.getFontName(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        this.style = Font.PLAIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        this.size = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        this.pointSize = 1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /* This constructor is used when one font is derived from another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * Fonts created from a stream will use the same font2D instance as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * parent. They can be distinguished because the "created" argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * will be "true". Since there is no way to recreate these fonts they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * need to have the handle to the underlying font2D passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * "created" is also true when a special composite is referenced by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * handle for essentially the same reasons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * But when deriving a font in these cases two particular attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * need special attention: family/face and style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * The "composites" in these cases need to be recreated with optimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * fonts for the new values of family and style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * For fonts created with createFont() these are treated differently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * JDK can often synthesise a different style (bold from plain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * for example). For fonts created with "createFont" this is a reasonable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * solution but its also possible (although rare) to derive a font with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * different family attribute. In this case JDK needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * to break the tie with the original Font2D and find a new Font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * The oldName and oldStyle are supplied so they can be compared with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * what the Font2D and the values. To speed things along :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * oldName == null will be interpreted as the name is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * oldStyle = -1 will be interpreted as the style is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * In these cases there is no need to interrogate "values".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    private Font(AttributeValues values, String oldName, int oldStyle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                 boolean created, Font2DHandle handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        this.createdFont = created;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        if (created) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            this.font2DHandle = handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            String newName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            if (oldName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                newName = values.getFamily();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                if (oldName.equals(newName)) newName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            int newStyle = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            if (oldStyle == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                newStyle = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                if (values.getWeight() >= 2f)   newStyle  = BOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                if (values.getPosture() >= .2f) newStyle |= ITALIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                if (oldStyle == newStyle)       newStyle  = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            if (handle.font2D instanceof CompositeFont) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                if (newStyle != -1 || newName != null) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   666
                    FontManager fm = FontManagerFactory.getInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    this.font2DHandle =
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
   668
                        fm.getNewComposite(newName, newStyle, handle);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            } else if (newName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                this.createdFont = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                this.font2DHandle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        initFromValues(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * Creates a new <code>Font</code> with the specified attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * Only keys defined in {@link java.awt.font.TextAttribute TextAttribute}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * are recognized.  In addition the FONT attribute is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *  not recognized by this constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * (see {@link #getAvailableAttributes}). Only attributes that have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * values of valid types will affect the new <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * If <code>attributes</code> is <code>null</code>, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * <code>Font</code> is initialized with default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @see java.awt.font.TextAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * @param attributes the attributes to assign to the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *          <code>Font</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    public Font(Map<? extends Attribute, ?> attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        initFromValues(AttributeValues.fromMap(attributes, RECOGNIZED_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * Creates a new <code>Font</code> from the specified <code>font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * This constructor is intended for use by subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @param font from which to create this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * @throws NullPointerException if <code>font</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    protected Font(Font font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        if (font.values != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            initFromValues(font.getAttributeValues().clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            this.name = font.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            this.style = font.style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            this.size = font.size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            this.pointSize = font.pointSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        this.font2DHandle = font.font2DHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        this.createdFont = font.createdFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * Font recognizes all attributes except FONT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    private static final int RECOGNIZED_MASK = AttributeValues.MASK_ALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        & ~AttributeValues.getMask(EFONT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * These attributes are considered primary by the FONT attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    private static final int PRIMARY_MASK =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        AttributeValues.getMask(EFAMILY, EWEIGHT, EWIDTH, EPOSTURE, ESIZE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                                ETRANSFORM, ESUPERSCRIPT, ETRACKING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * These attributes are considered secondary by the FONT attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    private static final int SECONDARY_MASK =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        RECOGNIZED_MASK & ~PRIMARY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * These attributes are handled by layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    private static final int LAYOUT_MASK =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        AttributeValues.getMask(ECHAR_REPLACEMENT, EFOREGROUND, EBACKGROUND,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                EUNDERLINE, ESTRIKETHROUGH, ERUN_DIRECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                                EBIDI_EMBEDDING, EJUSTIFICATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                                EINPUT_METHOD_HIGHLIGHT, EINPUT_METHOD_UNDERLINE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                ESWAP_COLORS, ENUMERIC_SHAPING, EKERNING,
534
be8500bc69b2 6684056: SUPERSCRIPT TextAttribute on font needs to trigger layout.
prr
parents: 2
diff changeset
   744
                                ELIGATURES, ETRACKING, ESUPERSCRIPT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    private static final int EXTRA_MASK =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            AttributeValues.getMask(ETRANSFORM, ESUPERSCRIPT, EWIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * Initialize the standard Font fields from the values object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    private void initFromValues(AttributeValues values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        this.values = values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        values.defineAll(PRIMARY_MASK); // for 1.5 streaming compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        this.name = values.getFamily();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        this.pointSize = values.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        this.size = (int)(values.getSize() + 0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        if (values.getWeight() >= 2f) this.style |= BOLD; // not == 2f
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        if (values.getPosture() >= .2f) this.style |= ITALIC; // not  == .2f
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        this.nonIdentityTx = values.anyNonDefault(EXTRA_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        this.hasLayoutAttributes =  values.anyNonDefault(LAYOUT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * Returns a <code>Font</code> appropriate to the attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * If <code>attributes</code>contains a <code>FONT</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * with a valid <code>Font</code> as its value, it will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * merged with any remaining attributes.  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * {@link java.awt.font.TextAttribute#FONT} for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * @param attributes the attributes to assign to the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     *          <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * @return a new <code>Font</code> created with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     *          attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @throws NullPointerException if <code>attributes</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @see java.awt.font.TextAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    public static Font getFont(Map<? extends Attribute, ?> attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        // optimize for two cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        // 1) FONT attribute, and nothing else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        // 2) attributes, but no FONT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        // avoid turning the attributemap into a regular map for no reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        if (attributes instanceof AttributeMap &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            ((AttributeMap)attributes).getValues() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            AttributeValues values = ((AttributeMap)attributes).getValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            if (values.isNonDefault(EFONT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                Font font = values.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                if (!values.anyDefined(SECONDARY_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                    return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                // merge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                values = font.getAttributeValues().clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                values.merge(attributes, SECONDARY_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                return new Font(values, font.name, font.style,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                                font.createdFont, font.font2DHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            return new Font(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        Font font = (Font)attributes.get(TextAttribute.FONT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        if (font != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            if (attributes.size() > 1) { // oh well, check for anything else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                AttributeValues values = font.getAttributeValues().clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                values.merge(attributes, SECONDARY_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                return new Font(values, font.name, font.style,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                                font.createdFont, font.font2DHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        return new Font(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    /**
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   821
     * Used with the byte count tracker for fonts created from streams.
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   822
     * If a thread can create temp files anyway, no point in counting
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   823
     * font bytes.
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   824
     */
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   825
    private static boolean hasTempPermission() {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   826
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   827
        if (System.getSecurityManager() == null) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   828
            return true;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   829
        }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   830
        File f = null;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   831
        boolean hasPerm = false;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   832
        try {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   833
            f = File.createTempFile("+~JT", ".tmp", null);
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   834
            f.delete();
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   835
            f = null;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   836
            hasPerm = true;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   837
        } catch (Throwable t) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   838
            /* inc. any kind of SecurityException */
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   839
        }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   840
        return hasPerm;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   841
    }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   842
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   843
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * Returns a new <code>Font</code> using the specified font type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * and input data.  The new <code>Font</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * created with a point size of 1 and style {@link #PLAIN PLAIN}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * This base font can then be used with the <code>deriveFont</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * methods in this class to derive new <code>Font</code> objects with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * varying sizes, styles, transforms and font features.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * method does not close the {@link InputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * To make the <code>Font</code> available to Font constructors the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * returned <code>Font</code> must be registered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * <code>GraphicsEnviroment</code> by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * {@link GraphicsEnvironment#registerFont(Font) registerFont(Font)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * @param fontFormat the type of the <code>Font</code>, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * {@link #TRUETYPE_FONT TRUETYPE_FONT} if a TrueType resource is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * or {@link #TYPE1_FONT TYPE1_FONT} if a Type 1 resource is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @param fontStream an <code>InputStream</code> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * input data for the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @return a new <code>Font</code> created with the specified font type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * @throws IllegalArgumentException if <code>fontFormat</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     *     <code>TRUETYPE_FONT</code>or<code>TYPE1_FONT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * @throws FontFormatException if the <code>fontStream</code> data does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     *     not contain the required font tables for the specified format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * @throws IOException if the <code>fontStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     *     cannot be completely read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * @see GraphicsEnvironment#registerFont(Font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    public static Font createFont(int fontFormat, InputStream fontStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        throws java.awt.FontFormatException, java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        if (fontFormat != Font.TRUETYPE_FONT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            fontFormat != Font.TYPE1_FONT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            throw new IllegalArgumentException ("font format not recognized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        }
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   878
        boolean copiedFontData = false;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   879
        try {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   880
            final File tFile = AccessController.doPrivileged(
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   881
                new PrivilegedExceptionAction<File>() {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   882
                    public File run() throws IOException {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   883
                        return File.createTempFile("+~JF", ".tmp", null);
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   884
                    }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   885
                }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   886
            );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   888
            int totalSize = 0;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   889
            CreatedFontTracker tracker = null;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   890
            try {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   891
                final OutputStream outStream =
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   892
                    AccessController.doPrivileged(
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   893
                        new PrivilegedExceptionAction<OutputStream>() {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   894
                            public OutputStream run() throws IOException {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   895
                                return new FileOutputStream(tFile);
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   896
                            }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   897
                        }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   898
                    );
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   899
                if (!hasTempPermission()) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   900
                    tracker = CreatedFontTracker.getTracker();
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   901
                }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   902
                try {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   903
                    byte[] buf = new byte[8192];
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   904
                    for (;;) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   905
                        int bytesRead = fontStream.read(buf);
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   906
                        if (bytesRead < 0) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   907
                            break;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   908
                        }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   909
                        if (tracker != null) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   910
                            if (totalSize+bytesRead > tracker.MAX_FILE_SIZE) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   911
                                throw new IOException("File too big.");
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   912
                            }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   913
                            if (totalSize+tracker.getNumBytes() >
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   914
                                tracker.MAX_TOTAL_BYTES)
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   915
                              {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   916
                                throw new IOException("Total files too big.");
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   917
                            }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   918
                            totalSize += bytesRead;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   919
                            tracker.addBytes(bytesRead);
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   920
                        }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   921
                        outStream.write(buf, 0, bytesRead);
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   922
                    }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   923
                    /* don't close the input stream */
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   924
                } finally {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   925
                    outStream.close();
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   926
                }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   927
                /* After all references to a Font2D are dropped, the file
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   928
                 * will be removed. To support long-lived AppContexts,
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   929
                 * we need to then decrement the byte count by the size
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   930
                 * of the file.
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   931
                 * If the data isn't a valid font, the implementation will
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   932
                 * delete the tmp file and decrement the byte count
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   933
                 * in the tracker object before returning from the
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   934
                 * constructor, so we can set 'copiedFontData' to true here
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   935
                 * without waiting for the results of that constructor.
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   936
                 */
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   937
                copiedFontData = true;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   938
                Font font = new Font(tFile, fontFormat, true, tracker);
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   939
                return font;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   940
            } finally {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   941
                if (!copiedFontData) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   942
                    if (tracker != null) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   943
                        tracker.subBytes(totalSize);
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   944
                    }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   945
                    AccessController.doPrivileged(
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   946
                        new PrivilegedExceptionAction<Void>() {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   947
                            public Void run() {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   948
                                tFile.delete();
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   949
                                return null;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   950
                            }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   951
                        }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   952
                    );
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   953
                }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   954
            }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   955
        } catch (Throwable t) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   956
            if (t instanceof FontFormatException) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   957
                throw (FontFormatException)t;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   958
            }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   959
            if (t instanceof IOException) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   960
                throw (IOException)t;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   961
            }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   962
            Throwable cause = t.getCause();
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   963
            if (cause instanceof FontFormatException) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   964
                throw (FontFormatException)cause;
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   965
            }
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
   966
            throw new IOException("Problem reading font data.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * Returns a new <code>Font</code> using the specified font type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * and the specified font file.  The new <code>Font</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * created with a point size of 1 and style {@link #PLAIN PLAIN}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * This base font can then be used with the <code>deriveFont</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * methods in this class to derive new <code>Font</code> objects with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * varying sizes, styles, transforms and font features.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * @param fontFormat the type of the <code>Font</code>, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * {@link #TRUETYPE_FONT TRUETYPE_FONT} if a TrueType resource is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * specified or {@link #TYPE1_FONT TYPE1_FONT} if a Type 1 resource is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * So long as the returned font, or its derived fonts are referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * the implementation may continue to access <code>fontFile</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * to retrieve font data. Thus the results are undefined if the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * is changed, or becomes inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * To make the <code>Font</code> available to Font constructors the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * returned <code>Font</code> must be registered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * <code>GraphicsEnviroment</code> by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * {@link GraphicsEnvironment#registerFont(Font) registerFont(Font)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * @param fontFile a <code>File</code> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * input data for the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * @return a new <code>Font</code> created with the specified font type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @throws IllegalArgumentException if <code>fontFormat</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     *     <code>TRUETYPE_FONT</code>or<code>TYPE1_FONT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * @throws NullPointerException if <code>fontFile</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * @throws IOException if the <code>fontFile</code> cannot be read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * @throws FontFormatException if <code>fontFile</code> does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     *     not contain the required font tables for the specified format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * @throws SecurityException if the executing code does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * permission to read from the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * @see GraphicsEnvironment#registerFont(Font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    public static Font createFont(int fontFormat, File fontFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        throws java.awt.FontFormatException, java.io.IOException {
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
  1006
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
  1007
        fontFile = new File(fontFile.getPath());
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
  1008
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        if (fontFormat != Font.TRUETYPE_FONT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            fontFormat != Font.TYPE1_FONT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            throw new IllegalArgumentException ("font format not recognized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            FilePermission filePermission =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                new FilePermission(fontFile.getPath(), "read");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            sm.checkPermission(filePermission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        if (!fontFile.canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            throw new IOException("Can't read " + fontFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 547
diff changeset
  1022
        return new Font(fontFile, fontFormat, false, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * Returns a copy of the transform associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * <code>Font</code>.  This transform is not necessarily the one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * used to construct the font.  If the font has algorithmic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * superscripting or width adjustment, this will be incorporated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * into the returned <code>AffineTransform</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * Typically, fonts will not be transformed.  Clients generally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * should call {@link #isTransformed} first, and only call this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * method if <code>isTransformed</code> returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * @return an {@link AffineTransform} object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     *          transform attribute of this <code>Font</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    public AffineTransform getTransform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        /* The most common case is the identity transform.  Most callers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
         * should call isTransformed() first, to decide if they need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
         * get the transform, but some may not.  Here we check to see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
         * if we have a nonidentity transform, and only do the work to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
         * fetch and/or compute it if so, otherwise we return a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
         * identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
         * Note that the transform is _not_ necessarily the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
         * the transform passed in as an Attribute in a Map, as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
         * transform returned will also reflect the effects of WIDTH and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
         * SUPERSCRIPT attributes.  Clients who want the actual transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
         * need to call getRequestedAttributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        if (nonIdentityTx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            AttributeValues values = getAttributeValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            AffineTransform at = values.isNonDefault(ETRANSFORM)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                ? new AffineTransform(values.getTransform())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                : new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            if (values.getSuperscript() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                // can't get ascent and descent here, recursive call to this fn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                // so use pointsize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                // let users combine super- and sub-scripting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                int superscript = values.getSuperscript();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                double trans = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                boolean up = superscript > 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                int sign = up ? -1 : 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                int ss = up ? superscript : -superscript;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                while ((ss & 7) > n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                    int newn = ss & 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                    trans += sign * (ssinfo[newn] - ssinfo[n]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                    ss >>= 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                    sign = -sign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                    n = newn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                trans *= pointSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                double scale = Math.pow(2./3., n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                at.preConcatenate(AffineTransform.getTranslateInstance(0, trans));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                at.scale(scale, scale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                // note on placement and italics
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                // We preconcatenate the transform because we don't want to translate along
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                // the italic angle, but purely perpendicular to the baseline.  While this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                // looks ok for superscripts, it can lead subscripts to stack on each other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                // and bring the following text too close.  The way we deal with potential
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                // collisions that can occur in the case of italics is by adjusting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                // horizontal spacing of the adjacent glyphvectors.  Examine the italic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                // angle of both vectors, if one is non-zero, compute the minimum ascent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                // and descent, and then the x position at each for each vector along its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                // italic angle starting from its (offset) baseline.  Compute the difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                // between the x positions and use the maximum difference to adjust the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                // position of the right gv.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            if (values.isNonDefault(EWIDTH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                at.scale(values.getWidth(), 1f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            return at;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        return new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    // x = r^0 + r^1 + r^2... r^n
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    // rx = r^1 + r^2 + r^3... r^(n+1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    // x - rx = r^0 - r^(n+1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    // x (1 - r) = r^0 - r^(n+1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    // x = (r^0 - r^(n+1)) / (1 - r)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    // x = (1 - r^(n+1)) / (1 - r)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    // scale ratio is 2/3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    // trans = 1/2 of ascent * x
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    // assume ascent is 3/4 of point size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    private static final float[] ssinfo = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        0.0f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        0.375f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        0.625f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        0.7916667f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        0.9027778f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        0.9768519f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        1.0262346f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        1.0591564f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * Returns the family name of this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * <p>The family name of a font is font specific. Two fonts such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * Helvetica Italic and Helvetica Bold have the same family name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * <i>Helvetica</i>, whereas their font face names are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * <i>Helvetica Bold</i> and <i>Helvetica Italic</i>. The list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * available family names may be obtained by using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * {@link GraphicsEnvironment#getAvailableFontFamilyNames()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * <p>Use <code>getName</code> to get the logical name of the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * Use <code>getFontName</code> to get the font face name of the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * @return a <code>String</code> that is the family name of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     *          <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * @see #getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * @see #getFontName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    public String getFamily() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        return getFamily_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    // NOTE: This method is called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    //       We implement this functionality in a package-private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    //       method to insure that it cannot be overridden by client
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    //       subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    final String getFamily_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        return getFamily(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * Returns the family name of this <code>Font</code>, localized for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * <p>The family name of a font is font specific. Two fonts such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * Helvetica Italic and Helvetica Bold have the same family name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * <i>Helvetica</i>, whereas their font face names are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * <i>Helvetica Bold</i> and <i>Helvetica Italic</i>. The list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * available family names may be obtained by using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * {@link GraphicsEnvironment#getAvailableFontFamilyNames()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * <p>Use <code>getFontName</code> to get the font face name of the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * @param l locale for which to get the family name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * @return a <code>String</code> representing the family name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     *          font, localized for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * @see #getFontName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * @see java.util.Locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    public String getFamily(Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            throw new NullPointerException("null locale doesn't mean default");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        return getFont2D().getFamilyName(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * Returns the postscript name of this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * Use <code>getFamily</code> to get the family name of the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * Use <code>getFontName</code> to get the font face name of the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * @return a <code>String</code> representing the postscript name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     *          this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    public String getPSName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        return getFont2D().getPostscriptName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * Returns the logical name of this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * Use <code>getFamily</code> to get the family name of the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * Use <code>getFontName</code> to get the font face name of the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * @return a <code>String</code> representing the logical name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     *          this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * @see #getFamily
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * @see #getFontName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * Returns the font face name of this <code>Font</code>.  For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * Helvetica Bold could be returned as a font face name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * Use <code>getFamily</code> to get the family name of the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     * Use <code>getName</code> to get the logical name of the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * @return a <code>String</code> representing the font face name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     *          this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * @see #getFamily
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * @see #getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    public String getFontName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
      return getFontName(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * Returns the font face name of the <code>Font</code>, localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * for the specified locale. For example, Helvetica Fett could be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * returned as the font face name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * Use <code>getFamily</code> to get the family name of the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * @param l a locale for which to get the font face name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * @return a <code>String</code> representing the font face name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     *          localized for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * @see #getFamily
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * @see java.util.Locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    public String getFontName(Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            throw new NullPointerException("null locale doesn't mean default");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        return getFont2D().getFontName(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * Returns the style of this <code>Font</code>.  The style can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     * PLAIN, BOLD, ITALIC, or BOLD+ITALIC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * @return the style of this <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * @see #isPlain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * @see #isBold
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * @see #isItalic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    public int getStyle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        return style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * Returns the point size of this <code>Font</code>, rounded to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * an integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * Most users are familiar with the idea of using <i>point size</i> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * specify the size of glyphs in a font. This point size defines a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * measurement between the baseline of one line to the baseline of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * following line in a single spaced text document. The point size is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * based on <i>typographic points</i>, approximately 1/72 of an inch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * The Java(tm)2D API adopts the convention that one point is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * equivalent to one unit in user coordinates.  When using a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * normalized transform for converting user space coordinates to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * device space coordinates 72 user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * space units equal 1 inch in device space.  In this case one point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * is 1/72 of an inch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * @return the point size of this <code>Font</code> in 1/72 of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     *          inch units.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * @see #getSize2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * @see GraphicsConfiguration#getDefaultTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * @see GraphicsConfiguration#getNormalizingTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * Returns the point size of this <code>Font</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     * <code>float</code> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * @return the point size of this <code>Font</code> as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * <code>float</code> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    public float getSize2D() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        return pointSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * Indicates whether or not this <code>Font</code> object's style is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * PLAIN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * @return    <code>true</code> if this <code>Font</code> has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     *            PLAIN sytle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     *            <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * @see       java.awt.Font#getStyle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    public boolean isPlain() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        return style == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * Indicates whether or not this <code>Font</code> object's style is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * BOLD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * @return    <code>true</code> if this <code>Font</code> object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     *            style is BOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     *            <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * @see       java.awt.Font#getStyle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    public boolean isBold() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        return (style & BOLD) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * Indicates whether or not this <code>Font</code> object's style is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * ITALIC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * @return    <code>true</code> if this <code>Font</code> object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     *            style is ITALIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     *            <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * @see       java.awt.Font#getStyle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    public boolean isItalic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        return (style & ITALIC) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     * Indicates whether or not this <code>Font</code> object has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * transform that affects its size in addition to the Size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * @return  <code>true</code> if this <code>Font</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     *          has a non-identity AffineTransform attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     *          <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * @see     java.awt.Font#getTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * @since   1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    public boolean isTransformed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        return nonIdentityTx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * Return true if this Font contains attributes that require extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * layout processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * @return true if the font has layout attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    public boolean hasLayoutAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        return hasLayoutAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * Returns a <code>Font</code> object from the system properties list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * <code>nm</code> is treated as the name of a system property to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     * obtained.  The <code>String</code> value of this property is then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     * interpreted as a <code>Font</code> object according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     * specification of <code>Font.decode(String)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * If the specified property is not found, or the executing code does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * not have permission to read the property, null is returned instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * @param nm the property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * @return a <code>Font</code> object that the property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     *          describes, or null if no such property exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * @throws NullPointerException if nm is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * @see #decode(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    public static Font getFont(String nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        return getFont(nm, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * Returns the <code>Font</code> that the <code>str</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     * argument describes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * To ensure that this method returns the desired Font,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * format the <code>str</code> parameter in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * one of these ways
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * <li><em>fontname-style-pointsize</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * <li><em>fontname-pointsize</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     * <li><em>fontname-style</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * <li><em>fontname</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     * <li><em>fontname style pointsize</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     * <li><em>fontname pointsize</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * <li><em>fontname style</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * <li><em>fontname</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * in which <i>style</i> is one of the four
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * case-insensitive strings:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * <code>"PLAIN"</code>, <code>"BOLD"</code>, <code>"BOLDITALIC"</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * <code>"ITALIC"</code>, and pointsize is a positive decimal integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * representation of the point size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * For example, if you want a font that is Arial, bold, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * a point size of 18, you would call this method with:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * "Arial-BOLD-18".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * This is equivalent to calling the Font constructor :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * <code>new Font("Arial", Font.BOLD, 18);</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * and the values are interpreted as specified by that constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * A valid trailing decimal field is always interpreted as the pointsize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * Therefore a fontname containing a trailing decimal value should not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * be used in the fontname only form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * If a style name field is not one of the valid style strings, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * interpreted as part of the font name, and the default style is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * Only one of ' ' or '-' may be used to separate fields in the input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * The identified separator is the one closest to the end of the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * which separates a valid pointsize, or a valid style name from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * the rest of the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * Null (empty) pointsize and style fields are treated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * as valid fields with the default value for that field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * Some font names may include the separator characters ' ' or '-'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * If <code>str</code> is not formed with 3 components, e.g. such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * <code>style</code> or <code>pointsize</code> fields are not present in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     * <code>str</code>, and <code>fontname</code> also contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * character determined to be the separator character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * then these characters where they appear as intended to be part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * <code>fontname</code> may instead be interpreted as separators
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * so the font name may not be properly recognised.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * The default size is 12 and the default style is PLAIN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     * If <code>str</code> does not specify a valid size, the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * <code>Font</code> has a size of 12.  If <code>str</code> does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * specify a valid style, the returned Font has a style of PLAIN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * If you do not specify a valid font name in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * the <code>str</code> argument, this method will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * a font with the family name "Dialog".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * To determine what font family names are available on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * your system, use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * {@link GraphicsEnvironment#getAvailableFontFamilyNames()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     * If <code>str</code> is <code>null</code>, a new <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * is returned with the family name "Dialog", a size of 12 and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * PLAIN style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * @param str the name of the font, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * @return the <code>Font</code> object that <code>str</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     *          describes, or a new default <code>Font</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     *          <code>str</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * @see #getFamily
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    public static Font decode(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        String fontName = str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        String styleName = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        int fontSize = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        int fontStyle = Font.PLAIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        if (str == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            return new Font(DIALOG, fontStyle, fontSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        int lastHyphen = str.lastIndexOf('-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        int lastSpace = str.lastIndexOf(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        char sepChar = (lastHyphen > lastSpace) ? '-' : ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        int sizeIndex = str.lastIndexOf(sepChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        int styleIndex = str.lastIndexOf(sepChar, sizeIndex-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        int strlen = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        if (sizeIndex > 0 && sizeIndex+1 < strlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                fontSize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                    Integer.valueOf(str.substring(sizeIndex+1)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                if (fontSize <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                    fontSize = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                /* It wasn't a valid size, if we didn't also find the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                 * start of the style string perhaps this is the style */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                styleIndex = sizeIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                sizeIndex = strlen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                if (str.charAt(sizeIndex-1) == sepChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                    sizeIndex--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        if (styleIndex >= 0 && styleIndex+1 < strlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            styleName = str.substring(styleIndex+1, sizeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            styleName = styleName.toLowerCase(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            if (styleName.equals("bolditalic")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                fontStyle = Font.BOLD | Font.ITALIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            } else if (styleName.equals("italic")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                fontStyle = Font.ITALIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            } else if (styleName.equals("bold")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                fontStyle = Font.BOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            } else if (styleName.equals("plain")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                fontStyle = Font.PLAIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                /* this string isn't any of the expected styles, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                 * assume its part of the font name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                styleIndex = sizeIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                if (str.charAt(styleIndex-1) == sepChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                    styleIndex--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            fontName = str.substring(0, styleIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            int fontEnd = strlen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            if (styleIndex > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                fontEnd = styleIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            } else if (sizeIndex > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                fontEnd = sizeIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
            if (fontEnd > 0 && str.charAt(fontEnd-1) == sepChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                fontEnd--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            fontName = str.substring(0, fontEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        return new Font(fontName, fontStyle, fontSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
     * Gets the specified <code>Font</code> from the system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     * list.  As in the <code>getProperty</code> method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     * <code>System</code>, the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     * argument is treated as the name of a system property to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     * obtained.  The <code>String</code> value of this property is then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     * interpreted as a <code>Font</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * The property value should be one of the forms accepted by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     * <code>Font.decode(String)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     * If the specified property is not found, or the executing code does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     * have permission to read the property, the <code>font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     * argument is returned instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     * @param nm the case-insensitive property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     * @param font a default <code>Font</code> to return if property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     *          <code>nm</code> is not defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     * @return    the <code>Font</code> value of the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     * @throws NullPointerException if nm is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     * @see #decode(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
    public static Font getFont(String nm, Font font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        String str = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            str =System.getProperty(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        } catch(SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        if (str == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        return decode ( str );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
    transient int hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
     * Returns a hashcode for this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     * @return     a hashcode value for this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
     * @since      JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        if (hash == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
            hash = name.hashCode() ^ style ^ size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            /* It is possible many fonts differ only in transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
             * So include the transform in the hash calculation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
             * nonIdentityTx is set whenever there is a transform in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
             * 'values'. The tests for null are required because it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
             * also be set for other reasons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            if (nonIdentityTx &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                values != null && values.getTransform() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                hash ^= values.getTransform().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * Compares this <code>Font</code> object to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     * <code>Object</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * @param obj the <code>Object</code> to compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * @return <code>true</code> if the objects are the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     *          or if the argument is a <code>Font</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     *          describing the same font as this object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     *          <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        if (obj == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
        if (obj != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                Font font = (Font)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                if (size == font.size &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                    style == font.style &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                    nonIdentityTx == font.nonIdentityTx &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                    hasLayoutAttributes == font.hasLayoutAttributes &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                    pointSize == font.pointSize &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                    name.equals(font.name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                    /* 'values' is usually initialized lazily, except when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                     * the font is constructed from a Map, or derived using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                     * a Map or other values. So if only one font has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                     * the field initialized we need to initialize it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                     * the other instance and compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                    if (values == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                        if (font.values == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                            return getAttributeValues().equals(font.values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                        return values.equals(font.getAttributeValues());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
            catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     * Converts this <code>Font</code> object to a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     * representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     * @return     a <code>String</code> representation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
     *          <code>Font</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     * @since      JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        String  strStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        if (isBold()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
            strStyle = isItalic() ? "bolditalic" : "bold";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            strStyle = isItalic() ? "italic" : "plain";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
        return getClass().getName() + "[family=" + getFamily() + ",name=" + name + ",style=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
            strStyle + ",size=" + size + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    } // toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
    /** Serialization support.  A <code>readObject</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     *  method is neccessary because the constructor creates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
     *  the font's peer, and we can't serialize the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
     *  Similarly the computed font "family" may be different
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     *  at <code>readObject</code> time than at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     *  <code>writeObject</code> time.  An integer version is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     *  written so that future versions of this class will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     *  able to recognize serialized output from this one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     * The <code>Font</code> Serializable Data Form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    private int fontSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     * Writes default serializable fields to a stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     * @param s the <code>ObjectOutputStream</code> to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
     * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     * @see #readObject(java.io.ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
      throws java.lang.ClassNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
             java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        if (values != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
          synchronized(values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            // transient
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
            fRequestedAttributes = values.toSerializableHashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
            s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            fRequestedAttributes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
          s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     * Reads the <code>ObjectInputStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * @param s the <code>ObjectInputStream</code> to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * @see #writeObject(java.io.ObjectOutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
      throws java.lang.ClassNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
             java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        if (pointSize == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
            pointSize = (float)size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        // Handle fRequestedAttributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
        // in 1.5, we always streamed out the font values plus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
        // TRANSFORM, SUPERSCRIPT, and WIDTH, regardless of whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
        // values were default or not.  In 1.6 we only stream out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        // defined values.  So, 1.6 streams in from a 1.5 stream,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        // it check each of these values and 'undefines' it if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
        // value is the default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        if (fRequestedAttributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
            values = getAttributeValues(); // init
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
            AttributeValues extras =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                AttributeValues.fromSerializableHashtable(fRequestedAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
            if (!AttributeValues.is16Hashtable(fRequestedAttributes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                extras.unsetDefault(); // if legacy stream, undefine these
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
            values = getAttributeValues().merge(extras);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
            this.nonIdentityTx = values.anyNonDefault(EXTRA_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
            this.hasLayoutAttributes =  values.anyNonDefault(LAYOUT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
            fRequestedAttributes = null; // don't need it any more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     * Returns the number of glyphs in this <code>Font</code>. Glyph codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     * for this <code>Font</code> range from 0 to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     * <code>getNumGlyphs()</code> - 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     * @return the number of glyphs in this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
    public int getNumGlyphs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        return  getFont2D().getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     * Returns the glyphCode which is used when this <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     * does not have a glyph for a specified unicode code point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     * @return the glyphCode of this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
    public int getMissingGlyphCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        return getFont2D().getMissingGlyphCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     * Returns the baseline appropriate for displaying this character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
     * Large fonts can support different writing systems, and each system can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
     * use a different baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
     * The character argument determines the writing system to use. Clients
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
     * should not assume all characters use the same baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     * @param c a character used to identify the writing system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     * @return the baseline appropriate for the specified character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     * @see LineMetrics#getBaselineOffsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     * @see #ROMAN_BASELINE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     * @see #CENTER_BASELINE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * @see #HANGING_BASELINE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
    public byte getBaselineFor(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        return getFont2D().getBaselineFor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     * Returns a map of font attributes available in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * <code>Font</code>.  Attributes include things like ligatures and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * glyph substitution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     * @return the attributes map of this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
    public Map<TextAttribute,?> getAttributes(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        return new AttributeMap(getAttributeValues());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
     * Returns the keys of all the attributes supported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
     * <code>Font</code>.  These attributes can be used to derive other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * fonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     * @return an array containing the keys of all the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     *          supported by this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
    public Attribute[] getAvailableAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
        // FONT is not supported by Font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        Attribute attributes[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            TextAttribute.FAMILY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
            TextAttribute.WEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            TextAttribute.WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            TextAttribute.POSTURE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
            TextAttribute.SIZE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
            TextAttribute.TRANSFORM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
            TextAttribute.SUPERSCRIPT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
            TextAttribute.CHAR_REPLACEMENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
            TextAttribute.FOREGROUND,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
            TextAttribute.BACKGROUND,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
            TextAttribute.UNDERLINE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
            TextAttribute.STRIKETHROUGH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            TextAttribute.RUN_DIRECTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
            TextAttribute.BIDI_EMBEDDING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            TextAttribute.JUSTIFICATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
            TextAttribute.INPUT_METHOD_HIGHLIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            TextAttribute.INPUT_METHOD_UNDERLINE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            TextAttribute.SWAP_COLORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
            TextAttribute.NUMERIC_SHAPING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
            TextAttribute.KERNING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
            TextAttribute.LIGATURES,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
            TextAttribute.TRACKING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
        return attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * Creates a new <code>Font</code> object by replicating this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     * <code>Font</code> object and applying a new style and size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * @param style the style for the new <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     * @param size the size for the new <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * @return a new <code>Font</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
    public Font deriveFont(int style, float size){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
        if (values == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
            return new Font(name, style, size, createdFont, font2DHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        AttributeValues newValues = getAttributeValues().clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
        int oldStyle = (this.style != style) ? this.style : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        applyStyle(style, newValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
        newValues.setSize(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
        return new Font(newValues, null, oldStyle, createdFont, font2DHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     * Creates a new <code>Font</code> object by replicating this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     * <code>Font</code> object and applying a new style and transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     * @param style the style for the new <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     * @param trans the <code>AffineTransform</code> associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     * new <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     * @return a new <code>Font</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     * @throws IllegalArgumentException if <code>trans</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     *         <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
    public Font deriveFont(int style, AffineTransform trans){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
        AttributeValues newValues = getAttributeValues().clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
        int oldStyle = (this.style != style) ? this.style : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
        applyStyle(style, newValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
        applyTransform(trans, newValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
        return new Font(newValues, null, oldStyle, createdFont, font2DHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * Creates a new <code>Font</code> object by replicating the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     * <code>Font</code> object and applying a new size to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     * @param size the size for the new <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     * @return a new <code>Font</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
    public Font deriveFont(float size){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        if (values == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            return new Font(name, style, size, createdFont, font2DHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        AttributeValues newValues = getAttributeValues().clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
        newValues.setSize(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        return new Font(newValues, null, -1, createdFont, font2DHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     * Creates a new <code>Font</code> object by replicating the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     * <code>Font</code> object and applying a new transform to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     * @param trans the <code>AffineTransform</code> associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     * new <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
     * @return a new <code>Font</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
     * @throws IllegalArgumentException if <code>trans</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
     *         <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
    public Font deriveFont(AffineTransform trans){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
        AttributeValues newValues = getAttributeValues().clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
        applyTransform(trans, newValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
        return new Font(newValues, null, -1, createdFont, font2DHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
     * Creates a new <code>Font</code> object by replicating the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
     * <code>Font</code> object and applying a new style to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     * @param style the style for the new <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * @return a new <code>Font</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
    public Font deriveFont(int style){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        if (values == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
           return new Font(name, style, size, createdFont, font2DHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
        AttributeValues newValues = getAttributeValues().clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        int oldStyle = (this.style != style) ? this.style : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
        applyStyle(style, newValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        return new Font(newValues, null, oldStyle, createdFont, font2DHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
     * Creates a new <code>Font</code> object by replicating the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
     * <code>Font</code> object and applying a new set of font attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     * to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     * @param attributes a map of attributes enabled for the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     * <code>Font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
     * @return a new <code>Font</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
    public Font deriveFont(Map<? extends Attribute, ?> attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        AttributeValues newValues = getAttributeValues().clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
        newValues.merge(attributes, RECOGNIZED_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
        return new Font(newValues, name, style, createdFont, font2DHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     * Checks if this <code>Font</code> has a glyph for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     * character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * <p> <b>Note:</b> This method cannot handle <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     * href="../../java/lang/Character.html#supplementary"> supplementary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * characters</a>. To support all Unicode characters, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     * supplementary characters, use the {@link #canDisplay(int)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     * method or <code>canDisplayUpTo</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
     * @param c the character for which a glyph is needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
     * @return <code>true</code> if this <code>Font</code> has a glyph for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
     *          character; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
    public boolean canDisplay(char c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
        return getFont2D().canDisplay(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     * Checks if this <code>Font</code> has a glyph for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     * character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     * @param codePoint the character (Unicode code point) for which a glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     *        is needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     * @return <code>true</code> if this <code>Font</code> has a glyph for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     *          character; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * @throws IllegalArgumentException if the code point is not a valid Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     *          code point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     * @see Character#isValidCodePoint(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
    public boolean canDisplay(int codePoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        if (!Character.isValidCodePoint(codePoint)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
            throw new IllegalArgumentException("invalid code point: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                                               Integer.toHexString(codePoint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        return getFont2D().canDisplay(codePoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
     * Indicates whether or not this <code>Font</code> can display a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
     * specified <code>String</code>.  For strings with Unicode encoding,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
     * it is important to know if a particular font can display the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
     * string. This method returns an offset into the <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
     * <code>str</code> which is the first character this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
     * <code>Font</code> cannot display without using the missing glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
     * code. If the <code>Font</code> can display all characters, -1 is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
     * @param str a <code>String</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
     * @return an offset into <code>str</code> that points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
     *          to the first character in <code>str</code> that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
     *          <code>Font</code> cannot display; or <code>-1</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
     *          this <code>Font</code> can display all characters in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
     *          <code>str</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
    public int canDisplayUpTo(String str) {
8520
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1988
        Font2D font2d = getFont2D();
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1989
        int len = str.length();
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1990
        for (int i = 0; i < len; i++) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1991
            char c = str.charAt(i);
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1992
            if (font2d.canDisplay(c)) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1993
                continue;
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1994
            }
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1995
            if (!Character.isHighSurrogate(c)) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1996
                return i;
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1997
            }
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1998
            if (!font2d.canDisplay(str.codePointAt(i))) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  1999
                return i;
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2000
            }
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2001
            i++;
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2002
        }
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2003
        return -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
     * Indicates whether or not this <code>Font</code> can display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
     * the characters in the specified <code>text</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
     * starting at <code>start</code> and ending at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
     * <code>limit</code>.  This method is a convenience overload.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
     * @param text the specified array of <code>char</code> values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
     * @param start the specified starting offset (in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
     *              <code>char</code>s) into the specified array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
     *              <code>char</code> values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
     * @param limit the specified ending offset (in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
     *              <code>char</code>s) into the specified array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
     *              <code>char</code> values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
     * @return an offset into <code>text</code> that points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
     *          to the first character in <code>text</code> that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
     *          <code>Font</code> cannot display; or <code>-1</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
     *          this <code>Font</code> can display all characters in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
     *          <code>text</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
    public int canDisplayUpTo(char[] text, int start, int limit) {
8520
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2026
        Font2D font2d = getFont2D();
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2027
        for (int i = start; i < limit; i++) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2028
            char c = text[i];
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2029
            if (font2d.canDisplay(c)) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2030
                continue;
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2031
            }
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2032
            if (!Character.isHighSurrogate(c)) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2033
                return i;
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2034
            }
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2035
            if (!font2d.canDisplay(Character.codePointAt(text, i, limit))) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2036
                return i;
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2037
            }
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2038
            i++;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
        }
8520
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2040
        return -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     * Indicates whether or not this <code>Font</code> can display the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     * text specified by the <code>iter</code> starting at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     * <code>start</code> and ending at <code>limit</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     * @param iter  a {@link CharacterIterator} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     * @param start the specified starting offset into the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     *              <code>CharacterIterator</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     * @param limit the specified ending offset into the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     *              <code>CharacterIterator</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     * @return an offset into <code>iter</code> that points
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     *          to the first character in <code>iter</code> that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     *          <code>Font</code> cannot display; or <code>-1</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     *          this <code>Font</code> can display all characters in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     *          <code>iter</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
    public int canDisplayUpTo(CharacterIterator iter, int start, int limit) {
8520
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2061
        Font2D font2d = getFont2D();
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2062
        char c = iter.setIndex(start);
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2063
        for (int i = start; i < limit; i++, c = iter.next()) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2064
            if (font2d.canDisplay(c)) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2065
                continue;
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2066
            }
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2067
            if (!Character.isHighSurrogate(c)) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2068
                return i;
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2069
            }
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2070
            char c2 = iter.next();
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2071
            // c2 could be CharacterIterator.DONE which is not a low surrogate.
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2072
            if (!Character.isLowSurrogate(c2)) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2073
                return i;
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2074
            }
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2075
            if (!font2d.canDisplay(Character.toCodePoint(c, c2))) {
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2076
                return i;
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2077
            }
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2078
            i++;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
        }
8520
a9e798f494cb 6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents: 7668
diff changeset
  2080
        return -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
     * Returns the italic angle of this <code>Font</code>.  The italic angle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
     * is the inverse slope of the caret which best matches the posture of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
     * <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
     * @see TextAttribute#POSTURE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
     * @return the angle of the ITALIC style of this <code>Font</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
    public float getItalicAngle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
        return getItalicAngle(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
    /* The FRC hints don't affect the value of the italic angle but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
     * we need to pass them in to look up a strike.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
     * If we can pass in ones already being used it can prevent an extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
     * strike from being allocated. Note that since italic angle is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
     * a property of the font, the font transform is needed not the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
     * device transform. Finally, this is private but the only caller of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
     * in the JDK - and the only likely caller - is in this same class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
    private float getItalicAngle(FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        Object aa, fm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
        if (frc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            aa = RenderingHints.VALUE_TEXT_ANTIALIAS_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
            fm = RenderingHints.VALUE_FRACTIONALMETRICS_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
            aa = frc.getAntiAliasingHint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
            fm = frc.getFractionalMetricsHint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
        }
547
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 534
diff changeset
  2111
        return getFont2D().getItalicAngle(this, identityTx, aa, fm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
     * Checks whether or not this <code>Font</code> has uniform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
     * line metrics.  A logical <code>Font</code> might be a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
     * composite font, which means that it is composed of different
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
     * physical fonts to cover different code ranges.  Each of these
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
     * fonts might have different <code>LineMetrics</code>.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
     * logical <code>Font</code> is a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
     * font then the metrics would be uniform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
     * @return <code>true</code> if this <code>Font</code> has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
     * uniform line metrics; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
    public boolean hasUniformLineMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        return false;   // REMIND always safe, but prevents caller optimize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
    private transient SoftReference flmref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
    private FontLineMetrics defaultLineMetrics(FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
        FontLineMetrics flm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
        if (flmref == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
            || (flm = (FontLineMetrics)flmref.get()) == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
            || !flm.frc.equals(frc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
            /* The device transform in the frc is not used in obtaining line
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
             * metrics, although it probably should be: REMIND find why not?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
             * The font transform is used but its applied in getFontMetrics, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
             * just pass identity here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
            float [] metrics = new float[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
            getFont2D().getFontMetrics(this, identityTx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
                                       frc.getAntiAliasingHint(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
                                       frc.getFractionalMetricsHint(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
                                       metrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
            float ascent  = metrics[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
            float descent = metrics[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
            float leading = metrics[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
            float ssOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
            if (values != null && values.getSuperscript() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
                ssOffset = (float)getTransform().getTranslateY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
                ascent -= ssOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
                descent += ssOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            float height = ascent + descent + leading;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
            int baselineIndex = 0; // need real index, assumes roman for everything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            // need real baselines eventually
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
            float[] baselineOffsets = { 0, (descent/2f - ascent) / 2f, -ascent };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
            float strikethroughOffset = metrics[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
            float strikethroughThickness = metrics[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
            float underlineOffset = metrics[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            float underlineThickness = metrics[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
            float italicAngle = getItalicAngle(frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
            if (isTransformed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
                AffineTransform ctx = values.getCharTransform(); // extract rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
                if (ctx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
                    Point2D.Float pt = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
                    pt.setLocation(0, strikethroughOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
                    ctx.deltaTransform(pt, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
                    strikethroughOffset = pt.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
                    pt.setLocation(0, strikethroughThickness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
                    ctx.deltaTransform(pt, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
                    strikethroughThickness = pt.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
                    pt.setLocation(0, underlineOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
                    ctx.deltaTransform(pt, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
                    underlineOffset = pt.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
                    pt.setLocation(0, underlineThickness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
                    ctx.deltaTransform(pt, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
                    underlineThickness = pt.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
            strikethroughOffset += ssOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
            underlineOffset += ssOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
            CoreMetrics cm = new CoreMetrics(ascent, descent, leading, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
                                             baselineIndex, baselineOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
                                             strikethroughOffset, strikethroughThickness,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
                                             underlineOffset, underlineThickness,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
                                             ssOffset, italicAngle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
            flm = new FontLineMetrics(0, cm, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
            flmref = new SoftReference(flm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
        return (FontLineMetrics)flm.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
     * Returns a {@link LineMetrics} object created with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     * <code>String</code> and {@link FontRenderContext}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
     * @param str the specified <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
     * @return a <code>LineMetrics</code> object created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
     * specified <code>String</code> and {@link FontRenderContext}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
    public LineMetrics getLineMetrics( String str, FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
        FontLineMetrics flm = defaultLineMetrics(frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
        flm.numchars = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
        return flm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     * Returns a <code>LineMetrics</code> object created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     * specified arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * @param str the specified <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     * @param beginIndex the initial offset of <code>str</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     * @param limit the end offset of <code>str</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     * @return a <code>LineMetrics</code> object created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
     * specified arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
    public LineMetrics getLineMetrics( String str,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
                                    int beginIndex, int limit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
                                    FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
        FontLineMetrics flm = defaultLineMetrics(frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
        int numChars = limit - beginIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
        flm.numchars = (numChars < 0)? 0: numChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        return flm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
     * Returns a <code>LineMetrics</code> object created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
     * specified arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
     * @param chars an array of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
     * @param beginIndex the initial offset of <code>chars</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
     * @param limit the end offset of <code>chars</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
     * @return a <code>LineMetrics</code> object created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
     * specified arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
    public LineMetrics getLineMetrics(char [] chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
                                    int beginIndex, int limit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
                                    FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
        FontLineMetrics flm = defaultLineMetrics(frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
        int numChars = limit - beginIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
        flm.numchars = (numChars < 0)? 0: numChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
        return flm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
     * Returns a <code>LineMetrics</code> object created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
     * specified arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
     * @param ci the specified <code>CharacterIterator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
     * @param beginIndex the initial offset in <code>ci</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
     * @param limit the end offset of <code>ci</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
     * @return a <code>LineMetrics</code> object created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
     * specified arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
    public LineMetrics getLineMetrics(CharacterIterator ci,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
                                    int beginIndex, int limit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
                                    FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
        FontLineMetrics flm = defaultLineMetrics(frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
        int numChars = limit - beginIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        flm.numchars = (numChars < 0)? 0: numChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
        return flm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
     * Returns the logical bounds of the specified <code>String</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
     * the specified <code>FontRenderContext</code>.  The logical bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
     * contains the origin, ascent, advance, and height, which includes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
     * the leading.  The logical bounds does not always enclose all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
     * text.  For example, in some languages and in some fonts, accent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
     * marks can be positioned above the ascent or below the descent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
     * To obtain a visual bounding box, which encloses all the text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
     * use the {@link TextLayout#getBounds() getBounds} method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
     * <code>TextLayout</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
     * <p>Note: The returned bounds is in baseline-relative coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
     * (see {@link java.awt.Font class notes}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     * @param str the specified <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
     * @return a {@link Rectangle2D} that is the bounding box of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
     * specified <code>String</code> in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
     * <code>FontRenderContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
     * @see FontRenderContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
     * @see Font#createGlyphVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
    public Rectangle2D getStringBounds( String str, FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
        char[] array = str.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
        return getStringBounds(array, 0, array.length, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
     * Returns the logical bounds of the specified <code>String</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
     * the specified <code>FontRenderContext</code>.  The logical bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
     * contains the origin, ascent, advance, and height, which includes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
     * the leading.  The logical bounds does not always enclose all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
     * text.  For example, in some languages and in some fonts, accent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
     * marks can be positioned above the ascent or below the descent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
     * To obtain a visual bounding box, which encloses all the text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
     * use the {@link TextLayout#getBounds() getBounds} method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
     * <code>TextLayout</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
     * <p>Note: The returned bounds is in baseline-relative coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
     * (see {@link java.awt.Font class notes}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
     * @param str the specified <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     * @param beginIndex the initial offset of <code>str</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     * @param limit the end offset of <code>str</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     * @return a <code>Rectangle2D</code> that is the bounding box of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     * specified <code>String</code> in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     * <code>FontRenderContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     *         less than zero, or <code>limit</code> is greater than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     *         length of <code>str</code>, or <code>beginIndex</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     *         is greater than <code>limit</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
     * @see FontRenderContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     * @see Font#createGlyphVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
    public Rectangle2D getStringBounds( String str,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
                                    int beginIndex, int limit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
                                        FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
        String substr = str.substring(beginIndex, limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
        return getStringBounds(substr, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
     * Returns the logical bounds of the specified array of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
     * in the specified <code>FontRenderContext</code>.  The logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
     * bounds contains the origin, ascent, advance, and height, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
     * includes the leading.  The logical bounds does not always enclose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
     * all the text.  For example, in some languages and in some fonts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
     * accent marks can be positioned above the ascent or below the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
     * descent.  To obtain a visual bounding box, which encloses all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
     * text, use the {@link TextLayout#getBounds() getBounds} method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
     * <code>TextLayout</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
     * <p>Note: The returned bounds is in baseline-relative coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
     * (see {@link java.awt.Font class notes}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
     * @param chars an array of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
     * @param beginIndex the initial offset in the array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
     * characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
     * @param limit the end offset in the array of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
     * @return a <code>Rectangle2D</code> that is the bounding box of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     * specified array of characters in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
     * <code>FontRenderContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
     * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
     *         less than zero, or <code>limit</code> is greater than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
     *         length of <code>chars</code>, or <code>beginIndex</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
     *         is greater than <code>limit</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
     * @see FontRenderContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
     * @see Font#createGlyphVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
    public Rectangle2D getStringBounds(char [] chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                                    int beginIndex, int limit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
                                       FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
        if (beginIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
            throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
        if (limit > chars.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
            throw new IndexOutOfBoundsException("limit: " + limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
        if (beginIndex > limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            throw new IndexOutOfBoundsException("range length: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
                                                (limit - beginIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
        // this code should be in textlayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
        // quick check for simple text, assume GV ok to use if simple
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
        boolean simple = values == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
            (values.getKerning() == 0 && values.getLigatures() == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
              values.getBaselineTransform() == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
        if (simple) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3017
diff changeset
  2383
            simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
        if (simple) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
            GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
                                                     limit - beginIndex, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
            return gv.getLogicalBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
            // need char array constructor on textlayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
            String str = new String(chars, beginIndex, limit - beginIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
            TextLayout tl = new TextLayout(str, this, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
                                         tl.getAscent() + tl.getDescent() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
                                         tl.getLeading());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
     * Returns the logical bounds of the characters indexed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
     * specified {@link CharacterIterator} in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
     * specified <code>FontRenderContext</code>.  The logical bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
     * contains the origin, ascent, advance, and height, which includes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
     * the leading.  The logical bounds does not always enclose all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
     * text.  For example, in some languages and in some fonts, accent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
     * marks can be positioned above the ascent or below the descent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
     * To obtain a visual bounding box, which encloses all the text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
     * use the {@link TextLayout#getBounds() getBounds} method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
     * <code>TextLayout</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
     * <p>Note: The returned bounds is in baseline-relative coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
     * (see {@link java.awt.Font class notes}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
     * @param ci the specified <code>CharacterIterator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
     * @param beginIndex the initial offset in <code>ci</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
     * @param limit the end offset in <code>ci</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
     * @return a <code>Rectangle2D</code> that is the bounding box of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
     * characters indexed in the specified <code>CharacterIterator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     * in the specified <code>FontRenderContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
     * @see FontRenderContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
     * @see Font#createGlyphVector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
     * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
     *         less than the start index of <code>ci</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     *         <code>limit</code> is greater than the end index of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
     *         <code>ci</code>, or <code>beginIndex</code> is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
     *         than <code>limit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
    public Rectangle2D getStringBounds(CharacterIterator ci,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
                                    int beginIndex, int limit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
                                       FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
        int start = ci.getBeginIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        int end = ci.getEndIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
        if (beginIndex < start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
            throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
        if (limit > end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
            throw new IndexOutOfBoundsException("limit: " + limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
        if (beginIndex > limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
            throw new IndexOutOfBoundsException("range length: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
                                                (limit - beginIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
        char[]  arr = new char[limit - beginIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
        ci.setIndex(beginIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
        for(int idx = 0; idx < arr.length; idx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
            arr[idx] = ci.current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
            ci.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
        return getStringBounds(arr,0,arr.length,frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
     * Returns the bounds for the character with the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
     * bounds as defined in the specified <code>FontRenderContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
     * <p>Note: The returned bounds is in baseline-relative coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
     * (see {@link java.awt.Font class notes}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
     * @return a <code>Rectangle2D</code> that is the bounding box
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
     * for the character with the maximum bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
    public Rectangle2D getMaxCharBounds(FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
        float [] metrics = new float[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
        getFont2D().getFontMetrics(this, frc, metrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
        return new Rectangle2D.Float(0, -metrics[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
                                metrics[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
                                metrics[0] + metrics[1] + metrics[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
     * Creates a {@link java.awt.font.GlyphVector GlyphVector} by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
     * mapping characters to glyphs one-to-one based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
     * Unicode cmap in this <code>Font</code>.  This method does no other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
     * processing besides the mapping of glyphs to characters.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
     * means that this method is not useful for some scripts, such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
     * as Arabic, Hebrew, Thai, and Indic, that require reordering,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
     * shaping, or ligature substitution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
     * @param str the specified <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
     * @return a new <code>GlyphVector</code> created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
     * specified <code>String</code> and the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     * <code>FontRenderContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
    public GlyphVector createGlyphVector(FontRenderContext frc, String str)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
        return (GlyphVector)new StandardGlyphVector(this, str, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
     * Creates a {@link java.awt.font.GlyphVector GlyphVector} by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
     * mapping characters to glyphs one-to-one based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
     * Unicode cmap in this <code>Font</code>.  This method does no other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
     * processing besides the mapping of glyphs to characters.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
     * means that this method is not useful for some scripts, such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
     * as Arabic, Hebrew, Thai, and Indic, that require reordering,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
     * shaping, or ligature substitution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
     * @param chars the specified array of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
     * @return a new <code>GlyphVector</code> created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
     * specified array of characters and the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
     * <code>FontRenderContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
    public GlyphVector createGlyphVector(FontRenderContext frc, char[] chars)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        return (GlyphVector)new StandardGlyphVector(this, chars, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
     * Creates a {@link java.awt.font.GlyphVector GlyphVector} by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
     * mapping the specified characters to glyphs one-to-one based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
     * Unicode cmap in this <code>Font</code>.  This method does no other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
     * processing besides the mapping of glyphs to characters.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
     * means that this method is not useful for some scripts, such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
     * as Arabic, Hebrew, Thai, and Indic, that require reordering,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
     * shaping, or ligature substitution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
     * @param ci the specified <code>CharacterIterator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
     * @return a new <code>GlyphVector</code> created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
     * specified <code>CharacterIterator</code> and the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
     * <code>FontRenderContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
    public GlyphVector createGlyphVector(   FontRenderContext frc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
                                            CharacterIterator ci)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
        return (GlyphVector)new StandardGlyphVector(this, ci, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
     * Creates a {@link java.awt.font.GlyphVector GlyphVector} by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
     * mapping characters to glyphs one-to-one based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
     * Unicode cmap in this <code>Font</code>.  This method does no other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
     * processing besides the mapping of glyphs to characters.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
     * means that this method is not useful for some scripts, such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
     * as Arabic, Hebrew, Thai, and Indic, that require reordering,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
     * shaping, or ligature substitution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
     * @param glyphCodes the specified integer array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
     * @return a new <code>GlyphVector</code> created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
     * specified integer array and the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
     * <code>FontRenderContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
    public GlyphVector createGlyphVector(   FontRenderContext frc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
                                            int [] glyphCodes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
        return (GlyphVector)new StandardGlyphVector(this, glyphCodes, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
     * Returns a new <code>GlyphVector</code> object, performing full
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     * layout of the text if possible.  Full layout is required for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
     * complex text, such as Arabic or Hindi.  Support for different
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
     * scripts depends on the font and implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
     * Layout requires bidi analysis, as performed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
     * <code>Bidi</code>, and should only be performed on text that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
     * has a uniform direction.  The direction is indicated in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
     * flags parameter,by using LAYOUT_RIGHT_TO_LEFT to indicate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
     * right-to-left (Arabic and Hebrew) run direction, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
     * LAYOUT_LEFT_TO_RIGHT to indicate a left-to-right (English)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
     * run direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
     * In addition, some operations, such as Arabic shaping, require
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
     * context, so that the characters at the start and limit can have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
     * the proper shapes.  Sometimes the data in the buffer outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
     * the provided range does not have valid data.  The values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
     * LAYOUT_NO_START_CONTEXT and LAYOUT_NO_LIMIT_CONTEXT can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
     * added to the flags parameter to indicate that the text before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * start, or after limit, respectively, should not be examined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     * for context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     * All other values for the flags parameter are reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     * @param frc the specified <code>FontRenderContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
     * @param text the text to layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
     * @param start the start of the text to use for the <code>GlyphVector</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
     * @param limit the limit of the text to use for the <code>GlyphVector</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
     * @param flags control flags as described above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
     * @return a new <code>GlyphVector</code> representing the text between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
     * start and limit, with glyphs chosen and positioned so as to best represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
     * the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
     * @throws ArrayIndexOutOfBoundsException if start or limit is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
     * out of bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
     * @see java.text.Bidi
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
     * @see #LAYOUT_LEFT_TO_RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
     * @see #LAYOUT_RIGHT_TO_LEFT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
     * @see #LAYOUT_NO_START_CONTEXT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
     * @see #LAYOUT_NO_LIMIT_CONTEXT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
    public GlyphVector layoutGlyphVector(FontRenderContext frc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
                                         char[] text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
                                         int start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
                                         int limit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
                                         int flags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
        GlyphLayout gl = GlyphLayout.get(null); // !!! no custom layout engines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
        StandardGlyphVector gv = gl.layout(this, frc, text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
                                           start, limit-start, flags, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
        GlyphLayout.done(gl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
        return gv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
     * A flag to layoutGlyphVector indicating that text is left-to-right as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
     * determined by Bidi analysis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
    public static final int LAYOUT_LEFT_TO_RIGHT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
     * A flag to layoutGlyphVector indicating that text is right-to-left as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
     * determined by Bidi analysis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
    public static final int LAYOUT_RIGHT_TO_LEFT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
     * A flag to layoutGlyphVector indicating that text in the char array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
     * before the indicated start should not be examined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
    public static final int LAYOUT_NO_START_CONTEXT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
     * A flag to layoutGlyphVector indicating that text in the char array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
     * after the indicated limit should not be examined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
    public static final int LAYOUT_NO_LIMIT_CONTEXT = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
    private static void applyTransform(AffineTransform trans, AttributeValues values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
        if (trans == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
            throw new IllegalArgumentException("transform must not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
        values.setTransform(trans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
    private static void applyStyle(int style, AttributeValues values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
        // WEIGHT_BOLD, WEIGHT_REGULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
        values.setWeight((style & BOLD) != 0 ? 2f : 1f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
        // POSTURE_OBLIQUE, POSTURE_REGULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
        values.setPosture((style & ITALIC) != 0 ? .2f : 0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
}