jdk/src/share/classes/sun/font/FileFont.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 3928 be186a33df9b
child 8813 d15a9204c2f0
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     2
 * Copyright (c) 2003, 2008, 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 sun.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.ref.Reference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.FontFormatException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.GeneralPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.nio.channels.FileChannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.java2d.Disposer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.java2d.DisposerRecord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.RandomAccessFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.nio.ByteOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.nio.MappedByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.nio.BufferUnderflowException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.nio.channels.ClosedChannelException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public abstract class FileFont extends PhysicalFont {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected boolean useJavaRasterizer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /* I/O and file operations are always synchronized on the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * object. Two threads can be accessing the font and retrieving
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * information, and synchronized only to the extent that filesystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * operations require.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * A limited number of files can be open at a time, to limit the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * absorption of file descriptors. If a file needs to be opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * when there are none free, then the synchronization of all I/O
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * ensures that any in progress operation will complete before some
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * other thread closes the descriptor in order to allocate another one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // NB consider using a RAF. FIS has finalize method so may take a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // little longer to be GC'd. We don't use this stream at all anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // In fact why increase the size of a FileFont object if the stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // isn't needed ..
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    //protected FileInputStream stream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    //protected FileChannel channel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected int fileSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected FontScaler scaler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /* The following variables are used, (and in the case of the arrays,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * only initialised) for select fonts where a native scaler may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * used to get glyph images and metrics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * glyphToCharMap is filled in on the fly and used to do a reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * lookup when a FileFont needs to get the charcode back from a glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * code so it can re-map via a NativeGlyphMapper to get a native glyph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * This isn't a big hit in time, since a boolean test is sufficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * to choose the usual default path, nor in memory for fonts which take
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * the native path, since fonts have contiguous zero-based glyph indexes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * and these obviously do all exist in the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected boolean checkedNatives;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected boolean useNatives;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected NativeFont[] nativeFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected char[] glyphToCharMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @throws FontFormatException - if the font can't be opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    FileFont(String platname, Object nativeNames)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        throws FontFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        super(platname, nativeNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    FontStrike createStrike(FontStrikeDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (!checkedNatives) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
           checkUseNatives();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return new FileFontStrike(this, desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected boolean checkUseNatives() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        checkedNatives = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return useNatives;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /* This method needs to be accessible to FontManager if there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * file pool management. It may be a no-op.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    protected abstract void close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * This is the public interface. The subclasses need to implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * this. The returned block may be longer than the requested length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    abstract ByteBuffer readBlock(int offset, int length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public boolean canDoStyle(int style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 2
diff changeset
   128
    void setFileToRemove(File file, CreatedFontTracker tracker) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Disposer.addObjectRecord(this,
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 2
diff changeset
   130
                         new CreatedFontFileDisposerRecord(file, tracker));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /* This is called when a font scaler is determined to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * be unusable (ie bad).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * We want to replace current scaler with NullFontScaler, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * we never try to use same font scaler again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Scaler native resources could have already been disposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * or they will be eventually by Java2D disposer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * However, it should be safe to call dispose() explicitly here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * For safety we also invalidate all strike's scaler context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * So, in case they cache pointer to native scaler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * it will not ever be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * It also appears desirable to remove all the entries from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * cache so no other code will pick them up. But we can't just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * 'delete' them as code may be using them. And simply dropping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * the reference to the cache will make the reference objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * unreachable and so they will not get disposed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Since a strike may hold (via java arrays) native pointers to many
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * rasterised glyphs, this would be a memory leak.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * The solution is :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * - to move all the entries to another map where they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *   are no longer locatable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * - update FontStrikeDisposer to be able to distinguish which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * map they are held in via a boolean flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Since this isn't expected to be anything other than an extremely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * rare maybe it is not worth doing this last part.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    synchronized void deregisterFontAndClearStrikeCache() {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   161
        SunFontManager fm = SunFontManager.getInstance();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   162
        fm.deRegisterBadFont(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        for (Reference strikeRef : strikeCache.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            if (strikeRef != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                /* NB we know these are all FileFontStrike instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                 * because the cache is on this FileFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                FileFontStrike strike = (FileFontStrike)strikeRef.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                if (strike != null && strike.pScalerContext != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    scaler.invalidateScalerContext(strike.pScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        scaler.dispose();
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   176
        scaler = FontScaler.getNullScaler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    StrikeMetrics getFontMetrics(long pScalerContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return getScaler().getFontMetrics(pScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } catch (FontScalerException fe) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   183
            scaler = FontScaler.getNullScaler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            return getFontMetrics(pScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    float getGlyphAdvance(long pScalerContext, int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            return getScaler().getGlyphAdvance(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        } catch (FontScalerException fe) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   192
            scaler = FontScaler.getNullScaler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return getGlyphAdvance(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    void getGlyphMetrics(long pScalerContext, int glyphCode, Point2D.Float metrics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            getScaler().getGlyphMetrics(pScalerContext, glyphCode, metrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        } catch (FontScalerException fe) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   201
            scaler = FontScaler.getNullScaler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            getGlyphMetrics(pScalerContext, glyphCode, metrics);
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
    long getGlyphImage(long pScalerContext, int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return getScaler().getGlyphImage(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        } catch (FontScalerException fe) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   210
            scaler = FontScaler.getNullScaler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            return getGlyphImage(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    Rectangle2D.Float getGlyphOutlineBounds(long pScalerContext, int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            return getScaler().getGlyphOutlineBounds(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        } catch (FontScalerException fe) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   219
            scaler = FontScaler.getNullScaler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return getGlyphOutlineBounds(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    GeneralPath getGlyphOutline(long pScalerContext, int glyphCode, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return getScaler().getGlyphOutline(pScalerContext, glyphCode, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        } catch (FontScalerException fe) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   228
            scaler = FontScaler.getNullScaler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return getGlyphOutline(pScalerContext, glyphCode, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    GeneralPath getGlyphVectorOutline(long pScalerContext, int[] glyphs, int numGlyphs, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            return getScaler().getGlyphVectorOutline(pScalerContext, glyphs, numGlyphs, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        } catch (FontScalerException fe) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   237
            scaler = FontScaler.getNullScaler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return getGlyphVectorOutline(pScalerContext, glyphs, numGlyphs, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /* T1 & TT implementation differ so this method is abstract.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
       NB: null should not be returned here! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    protected abstract FontScaler getScaler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    protected long getUnitsPerEm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return getScaler().getUnitsPerEm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 2
diff changeset
   250
    private static class CreatedFontFileDisposerRecord
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 2
diff changeset
   251
        implements DisposerRecord {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        File fontFile = null;
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 2
diff changeset
   254
        CreatedFontTracker tracker;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 2
diff changeset
   256
        private CreatedFontFileDisposerRecord(File file,
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 2
diff changeset
   257
                                              CreatedFontTracker tracker) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            fontFile = file;
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 2
diff changeset
   259
            this.tracker = tracker;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                 new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                      public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                          if (fontFile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                              try {
2606
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 2
diff changeset
   268
                                  if (tracker != null) {
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 2
diff changeset
   269
                                      tracker.subBytes((int)fontFile.length());
09ad5edb5330 6632886: Font.createFont can be persuaded to leak temporary files
prr
parents: 2
diff changeset
   270
                                  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                  /* REMIND: is it possible that the file is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                   * still open? It will be closed when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                   * font2D is disposed but could this code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                   * execute first? If so the file would not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                   * be deleted on MS-windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                  fontFile.delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                  /* remove from delete on exit hook list : */
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   279
                                  // FIXME: still need to be refactored
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2606
diff changeset
   280
                                  SunFontManager.getInstance().tmpFontFiles.remove(fontFile);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                              } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                          return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}