jdk/src/share/classes/sun/font/Font2D.java
author prr
Mon, 09 Nov 2009 14:23:49 -0800
changeset 4252 0e645080f74b
parent 715 f16baef3a20e
child 5506 202f599c92aa
permissions -rw-r--r--
6899078: potential deadlock and performance issue in freeing strike resources with D3D pipeline Reviewed-by: tdv, igor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 547
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 sun.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.font.FontRenderContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.ref.Reference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.ref.SoftReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.concurrent.ConcurrentHashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public abstract class Font2D {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /* Note: JRE and FONT_CONFIG ranks are identical. I don't know of a reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * to distingish these. Possibly if a user adds fonts to the JRE font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * directory that are the same font as the ones specified in the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * configuration but that is more likely to be the legitimate intention
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * than a problem. One reason why these should be the same is that on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Linux the JRE fonts ARE the font configuration fonts, and although I
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * believe all are assigned FONT_CONFIG rank, it is conceivable that if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * this were not so, that some JRE font would not be allowed to joint the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * family of its siblings which were assigned FONT_CONFIG rank. Giving
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * them the same rank is the easy solution for now at least.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static final int FONT_CONFIG_RANK   = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static final int JRE_RANK     = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static final int TTF_RANK     = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final int TYPE1_RANK   = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final int NATIVE_RANK  = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static final int UNKNOWN_RANK = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static final int DEFAULT_RANK = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final String[] boldNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        "bold", "demibold", "demi-bold", "demi bold", "negreta", "demi", };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static final String[] italicNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        "italic", "cursiva", "oblique", "inclined", };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static final String[] boldItalicNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
          "bolditalic", "bold-italic", "bold italic",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
          "boldoblique", "bold-oblique", "bold oblique",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
          "demibold italic", "negreta cursiva","demi oblique", };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static final FontRenderContext DEFAULT_FRC =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        new FontRenderContext(null, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public Font2DHandle handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected String familyName;           /* Family font name (english) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected String fullName;             /* Full font name (english)   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected int style = Font.PLAIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected FontFamily family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    protected int fontRank = DEFAULT_RANK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * A mapper can be independent of the strike.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Perhaps the reference to the mapper ought to be held on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * scaler, as it may be implemented via scaler functionality anyway
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * and so the mapper would be useless if its native portion was
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * freed when the scaler was GC'd.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected CharToGlyphMapper mapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * The strike cache is maintained per "Font2D" as that is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * principal object by which you look up fonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * It means more Hashmaps, but look ups can be quicker because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * the map will have fewer entries, and there's no need to try to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * make the Font2D part of the key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected ConcurrentHashMap<FontStrikeDesc, Reference>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        strikeCache = new ConcurrentHashMap<FontStrikeDesc, Reference>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /* Store the last Strike in a Reference object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Similarly to the strike that was stored on a C++ font object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * this is an optimisation which helps if multiple clients (ie
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * typically SunGraphics2D instances) are using the same font, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * as may be typical of many UIs, they are probably using it in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * same style, so it can be a win to first quickly check if the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * strike obtained from this Font2D satifies the needs of the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * client too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * This pre-supposes that a FontStrike is a shareable object, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * it should.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    protected Reference lastFontStrike = new SoftReference(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * POSSIBLE OPTIMISATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Array of length 1024 elements of 64 bits indicating if a font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * contains these. This kind of information can be shared between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * all point sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * if corresponding bit in knownBitmaskMap is set then canDisplayBitmaskMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * is valid. This is 16Kbytes of data per composite font style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * What about UTF-32 and surrogates?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * REMIND: This is too much storage. Probably can only cache this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * information for latin range, although possibly OK to store all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * for just the "logical" fonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Or instead store arrays of subranges of 1024 bits (128 bytes) in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * the range below surrogate pairs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
//     protected long[] knownBitmaskMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
//     protected long[] canDisplayBitmaskMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /* Returns the "real" style of this Font2D. Eg the font face
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Lucida Sans Bold" has a real style of Font.BOLD, even though
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * it may be able to used to simulate bold italic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public int getStyle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    protected void setStyle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        String fName = fullName.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        for (int i=0; i < boldItalicNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if (fName.indexOf(boldItalicNames[i]) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                style = Font.BOLD|Font.ITALIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        for (int i=0; i < italicNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            if (fName.indexOf(italicNames[i]) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                style = Font.ITALIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        for (int i=0; i < boldNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            if (fName.indexOf(boldNames[i]) != -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                style = Font.BOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    int getRank() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return fontRank;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    void setRank(int rank) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        fontRank = rank;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    abstract CharToGlyphMapper getMapper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /* This isn't very efficient but its infrequently used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * StandardGlyphVector uses it when the client assigns the glyph codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * These may not be valid. This validates them substituting the missing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * glyph elsewhere.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    protected int getValidatedGlyphCode(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (glyphCode < 0 || glyphCode >= getMapper().getNumGlyphs()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            glyphCode = getMapper().getMissingGlyphCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return glyphCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Creates an appropriate strike for the Font2D subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    abstract FontStrike createStrike(FontStrikeDesc desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /* this may be useful for APIs like canDisplay where the answer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * is dependent on the font and its scaler, but not the strike.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * If no strike has ever been returned, then create a one that matches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * this font with the default FRC. It will become the lastStrike and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * there's a good chance that the next call will be to get exactly that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * strike.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public FontStrike getStrike(Font font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        FontStrike strike = (FontStrike)lastFontStrike.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (strike != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return strike;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return getStrike(font, DEFAULT_FRC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /* SunGraphics2D has font, tx, aa and fm. From this info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * can get a Strike object from the cache, creating it if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * This code is designed for multi-threaded access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * For that reason it creates a local FontStrikeDesc rather than filling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * in a shared one. Up to two AffineTransforms and one FontStrikeDesc will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * be created by every lookup. This appears to perform more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * adequately. But it may make sense to expose FontStrikeDesc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * as a parameter so a caller can use its own.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * In such a case if a FontStrikeDesc is stored as a key then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * we would need to use a private copy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Note that this code doesn't prevent two threads from creating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * two different FontStrike instances and having one of the threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * overwrite the other in the map. This is likely to be a rare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * occurrence and the only consequence is that these callers will have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * different instances of the strike, and there'd be some duplication of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * population of the strikes. However since users of these strikes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * transient, then the one that was overwritten would soon be freed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * If there is any problem then a small synchronized block would be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * required with its attendant consequences for MP scaleability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public FontStrike getStrike(Font font, AffineTransform devTx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                int aa, int fm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        /* Create the descriptor which is used to identify a strike
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         * in the strike cache/map. A strike is fully described by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         * the attributes of this descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        /* REMIND: generating garbage and doing computation here in order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         * to include pt size in the tx just for a lookup! Figure out a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         * better way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        double ptSize = font.getSize2D();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        AffineTransform glyphTx = (AffineTransform)devTx.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        glyphTx.scale(ptSize, ptSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (font.isTransformed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            glyphTx.concatenate(font.getTransform());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
547
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   244
        if (glyphTx.getTranslateX() != 0 || glyphTx.getTranslateY() != 0) {
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   245
            glyphTx.setTransform(glyphTx.getScaleX(),
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   246
                                 glyphTx.getShearY(),
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   247
                                 glyphTx.getShearX(),
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   248
                                 glyphTx.getScaleY(),
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   249
                                 0.0, 0.0);
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   250
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                                 font.getStyle(), aa, fm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return getStrike(desc, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public FontStrike getStrike(Font font, AffineTransform devTx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                AffineTransform glyphTx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                int aa, int fm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        /* Create the descriptor which is used to identify a strike
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
         * in the strike cache/map. A strike is fully described by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
         * the attributes of this descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                                 font.getStyle(), aa, fm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return getStrike(desc, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public FontStrike getStrike(Font font, FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        AffineTransform at = frc.getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        double ptSize = font.getSize2D();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        at.scale(ptSize, ptSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (font.isTransformed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            at.concatenate(font.getTransform());
547
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   276
            if (at.getTranslateX() != 0 || at.getTranslateY() != 0) {
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   277
                at.setTransform(at.getScaleX(),
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   278
                                at.getShearY(),
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   279
                                at.getShearX(),
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   280
                                at.getScaleY(),
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   281
                                0.0, 0.0);
ff9562f275ab 6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents: 2
diff changeset
   282
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        int aa = FontStrikeDesc.getAAHintIntVal(this, font, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        int fm = FontStrikeDesc.getFMHintIntVal(frc.getFractionalMetricsHint());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        FontStrikeDesc desc = new FontStrikeDesc(frc.getTransform(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                                                 at, font.getStyle(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                                 aa, fm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return getStrike(desc, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    FontStrike getStrike(FontStrikeDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return getStrike(desc, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    private FontStrike getStrike(FontStrikeDesc desc, boolean copy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        /* Before looking in the map, see if the descriptor matches the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         * last strike returned from this Font2D. This should often be a win
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         * since its common for the same font, in the same size to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         * used frequently, for example in many parts of a UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
         * If its not the same then we use the descriptor to locate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
         * Reference to the strike. If it exists and points to a strike,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
         * then we update the last strike to refer to that and return it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         * If the key isn't in the map, or its reference object has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
         * collected, then we create a new strike, put it in the map and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
         * set it to be the last strike.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        FontStrike strike = (FontStrike)lastFontStrike.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (strike != null && desc.equals(strike.desc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            //strike.lastlookupTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            return strike;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            Reference strikeRef = strikeCache.get(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            if (strikeRef != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                strike = (FontStrike)strikeRef.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                if (strike != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    //strike.lastlookupTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    lastFontStrike = new SoftReference(strike);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    StrikeCache.refStrike(strike);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    return strike;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            /* When we create a new FontStrike instance, we *must*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
             * ask the StrikeCache for a reference. We must then ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
             * this reference remains reachable, by storing it in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
             * Font2D's strikeCache map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
             * So long as the Reference is there (reachable) then if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
             * reference is cleared, it will be enqueued for disposal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
             * If for some reason we explicitly remove this reference, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
             * must only be done when holding a strong reference to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
             * referent (the FontStrike), or if the reference is cleared,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
             * then we must explicitly "dispose" of the native resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
             * The only place this currently happens is in this same method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
             * where we find a cleared reference and need to overwrite it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
             * here with a new reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
             * Clearing the whilst holding a strong reference, should only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
             * be done if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (copy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                desc = new FontStrikeDesc(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            strike = createStrike(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            //StrikeCache.addStrike();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            strikeRef = StrikeCache.getStrikeRef(strike);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            strikeCache.put(desc, strikeRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            //strike.lastlookupTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            lastFontStrike = new SoftReference(strike);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            StrikeCache.refStrike(strike);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            return strike;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    void removeFromCache(FontStrikeDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        Reference ref = strikeCache.get(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if (ref != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            Object o = ref.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (o == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                strikeCache.remove(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * The length of the metrics array must be >= 8.  This method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * store the following elements in that array before returning:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *    metrics[0]: ascent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *    metrics[1]: descent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *    metrics[2]: leading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *    metrics[3]: max advance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *    metrics[4]: strikethrough offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *    metrics[5]: strikethrough thickness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *    metrics[6]: underline offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *    metrics[7]: underline thickness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public void getFontMetrics(Font font, AffineTransform at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                               Object aaHint, Object fmHint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                               float metrics[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        /* This is called in just one place in Font with "at" == identity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
         * Perhaps this can be eliminated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        int aa = FontStrikeDesc.getAAHintIntVal(aaHint, this, font.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        int fm = FontStrikeDesc.getFMHintIntVal(fmHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        FontStrike strike = getStrike(font, at, aa, fm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        StrikeMetrics strikeMetrics = strike.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        metrics[0] = strikeMetrics.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        metrics[1] = strikeMetrics.getDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        metrics[2] = strikeMetrics.getLeading();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        metrics[3] = strikeMetrics.getMaxAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        getStyleMetrics(font.getSize2D(), metrics, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * The length of the metrics array must be >= offset+4, and offset must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * >= 0.  Typically offset is 4.  This method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * store the following elements in that array before returning:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *    metrics[off+0]: strikethrough offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *    metrics[off+1]: strikethrough thickness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *    metrics[off+2]: underline offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *    metrics[off+3]: underline thickness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Note that this implementation simply returns default values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * subclasses can override this method to provide more accurate values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public void getStyleMetrics(float pointSize, float[] metrics, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        metrics[offset] = -metrics[0] / 2.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        metrics[offset+1] = pointSize / 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        metrics[offset+2] = metrics[offset+1] / 1.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        metrics[offset+3] = metrics[offset+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * The length of the metrics array must be >= 4.  This method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * store the following elements in that array before returning:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *    metrics[0]: ascent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *    metrics[1]: descent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *    metrics[2]: leading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *    metrics[3]: max advance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    public void getFontMetrics(Font font, FontRenderContext frc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                               float metrics[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        StrikeMetrics strikeMetrics = getStrike(font, frc).getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        metrics[0] = strikeMetrics.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        metrics[1] = strikeMetrics.getDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        metrics[2] = strikeMetrics.getLeading();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        metrics[3] = strikeMetrics.getMaxAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /* Currently the layout code calls this. May be better for layout code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * to check the font class before attempting to run, rather than needing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * to promote this method up from TrueTypeFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    byte[] getTableBytes(int tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /* for layout code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    protected long getUnitsPerEm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return 2048;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    boolean supportsEncoding(String encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public boolean canDoStyle(int style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return (style == this.style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * All the important subclasses override this which is principally for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * the TrueType 'gasp' table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public boolean useAAForPtSize(int ptsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public boolean hasSupplementaryChars() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /* The following methods implement public methods on java.awt.Font */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    public String getPostscriptName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return fullName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    public String getFontName(Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        return fullName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public String getFamilyName(Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        return familyName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public int getNumGlyphs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return getMapper().getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public int charToGlyph(int wchar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        return getMapper().charToGlyph(wchar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public int getMissingGlyphCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        return getMapper().getMissingGlyphCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    public boolean canDisplay(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        return getMapper().canDisplay(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public boolean canDisplay(int cp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        return getMapper().canDisplay(cp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public byte getBaselineFor(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return Font.ROMAN_BASELINE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public float getItalicAngle(Font font, AffineTransform at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                                Object aaHint, Object fmHint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        /* hardwire psz=12 as that's typical and AA vs non-AA for 'gasp' mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         * isn't important for the caret slope of this rarely used API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        int aa = FontStrikeDesc.getAAHintIntVal(aaHint, this, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        int fm = FontStrikeDesc.getFMHintIntVal(fmHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        FontStrike strike = getStrike(font, at, aa, fm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        StrikeMetrics metrics = strike.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (metrics.ascentY == 0 || metrics.ascentX == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            return 0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            /* ascent is "up" from the baseline so its typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
             * a negative value, so we need to compensate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            return metrics.ascentX/-metrics.ascentY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
}