jdk/src/share/classes/sun/font/FileFontStrike.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 560 3a8029083a72
child 2390 080fb3a8be94
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
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: 560
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.lang.ref.SoftReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Font;
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
    30
import java.awt.GraphicsEnvironment;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.geom.GeneralPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.geom.NoninvertibleTransformException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.concurrent.ConcurrentHashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import static sun.awt.SunHints.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class FileFontStrike extends PhysicalStrike {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /* fffe and ffff are values we specially interpret as meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * invisible glyphs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final int INVISIBLE_GLYPHS = 0x0fffe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private FileFont fileFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /* REMIND: replace this scheme with one that installs a cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * instance of the appropriate type. It will require changes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * FontStrikeDisposer and NativeStrike etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final int UNINITIALISED = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static final int INTARRAY      = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final int LONGARRAY     = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final int SEGINTARRAY   = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static final int SEGLONGARRAY  = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private int glyphCacheFormat = UNINITIALISED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /* segmented arrays are blocks of 256 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static final int SEGSHIFT = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static final int SEGSIZE  = 1 << SEGSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private boolean segmentedCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private int[][] segIntGlyphImages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private long[][] segLongGlyphImages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /* The "metrics" information requested by clients is usually nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * more than the horizontal advance of the character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * In most cases this advance and other metrics information is stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * in the glyph image cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * But in some cases we do not automatically retrieve the glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * image when the advance is requested. In those cases we want to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * cache the advances since this has been shown to be important for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * The segmented cache is used in cases when the single array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * would be too large.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private float[] horizontalAdvances;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private float[][] segHorizontalAdvances;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /* Outline bounds are used when printing and when drawing outlines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * to the screen. On balance the relative rarity of these cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * and the fact that getting this requires generating a path at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * the scaler level means that its probably OK to store these
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * in a Java-level hashmap as the trade-off between time and space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Later can revisit whether to cache these at all, or elsewhere.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Should also profile whether subsequent to getting the bounds, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * outline itself is also requested. The 1.4 implementation doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * cache outlines so you could generate the path twice - once to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * the bounds and again to return the outline to the client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * If the two uses are coincident then also look into caching outlines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * One simple optimisation is that we could store the last single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * outline retrieved. This assumes that bounds then outline will always
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * be retrieved for a glyph rather than retrieving bounds for all glyphs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * then outlines for all glyphs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    ConcurrentHashMap<Integer, Rectangle2D.Float> boundsMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    SoftReference<ConcurrentHashMap<Integer, Point2D.Float>>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        glyphMetricsMapRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    AffineTransform invertDevTx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    boolean useNatives;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    NativeStrike[] nativeStrikes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   109
    /* Used only for communication to native layer */
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   110
    private int intPtSize;
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   111
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   112
    /* Perform global initialisation needed for Windows native rasterizer */
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   113
    private static native boolean initNative();
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   114
    private static boolean isXPorLater = false;
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   115
    static {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   116
        if (FontManager.isWindows && !FontManager.useT2K &&
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   117
            !GraphicsEnvironment.isHeadless()) {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   118
            isXPorLater = initNative();
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   119
        }
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   120
    }
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   121
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    FileFontStrike(FileFont fileFont, FontStrikeDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        super(fileFont, desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this.fileFont = fileFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (desc.style != fileFont.style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
          /* If using algorithmic styling, the base values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
           * boldness = 1.0, italic = 0.0. The superclass constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
           * initialises these.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
           */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            if ((desc.style & Font.ITALIC) == Font.ITALIC &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                (fileFont.style & Font.ITALIC) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                algoStyle = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                italic = 0.7f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            if ((desc.style & Font.BOLD) == Font.BOLD &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                ((fileFont.style & Font.BOLD) == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                algoStyle = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                boldness = 1.33f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        double[] matrix = new double[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        AffineTransform at = desc.glyphTx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        at.getMatrix(matrix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (!desc.devTx.isIdentity() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            desc.devTx.getType() != AffineTransform.TYPE_TRANSLATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                invertDevTx = desc.devTx.createInverse();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            } catch (NoninvertibleTransformException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        /* If any of the values is NaN then substitute the null scaler context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         * This will return null images, zero advance, and empty outlines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         * as no rendering need take place in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         * We pass in the null scaler as the singleton null context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         * requires it. However
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (Double.isNaN(matrix[0]) || Double.isNaN(matrix[1]) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            Double.isNaN(matrix[2]) || Double.isNaN(matrix[3]) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            fileFont.getScaler() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            pScalerContext = NullFontScaler.getNullScalerContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            pScalerContext = fileFont.getScaler().createScalerContext(matrix,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                    fileFont instanceof TrueTypeFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                    desc.aaHint, desc.fmHint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                    boldness, italic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        mapper = fileFont.getMapper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        int numGlyphs = mapper.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        /* Always segment for fonts with > 2K glyphs, but also for smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
         * fonts with non-typical sizes and transforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         * Segmenting for all non-typical pt sizes helps to minimise memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         * usage when very many distinct strikes are created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         * The size range of 0->5 and 37->INF for segmenting is arbitrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
         * but the intention is that typical GUI integer point sizes (6->36)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         * should not segment unless there's another reason to do so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        float ptSize = (float)matrix[3]; // interpreted only when meaningful.
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   182
        int iSize = intPtSize = (int)ptSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        boolean isSimpleTx = (at.getType() & complexTX) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        segmentedCache =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            (numGlyphs > SEGSIZE << 3) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            ((numGlyphs > SEGSIZE << 1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
             (!isSimpleTx || ptSize != iSize || iSize < 6 || iSize > 36));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        /* This can only happen if we failed to allocate memory for context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * NB: in such case we may still have some memory in java heap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         *     but subsequent attempt to allocate null scaler context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         *     may fail too (cause it is allocate in the native heap).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         *     It is not clear how to make this more robust but on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         *     other hand getting NULL here seems to be extremely unlikely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (pScalerContext == 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            /* REMIND: when the code is updated to install cache objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
             * rather than using a switch this will be more efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            this.disposer = new FontStrikeDisposer(fileFont, desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            initGlyphCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            pScalerContext = NullFontScaler.getNullScalerContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            FontManager.deRegisterBadFont(fileFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   206
        /* First, see if native code should be used to create the glyph.
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   207
         * GDI will return the integer metrics, not fractional metrics, which
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   208
         * may be requested for this strike, so we would require here that :
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   209
         * desc.fmHint != INTVAL_FRACTIONALMETRICS_ON
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   210
         * except that the advance returned by GDI is always overwritten by
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   211
         * the JDK rasteriser supplied one (see getGlyphImageFromWindows()).
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   212
         */
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   213
        if (FontManager.isWindows && isXPorLater &&
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   214
            !FontManager.useT2K &&
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   215
            !GraphicsEnvironment.isHeadless() &&
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   216
            !fileFont.useJavaRasterizer &&
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   217
            (desc.aaHint == INTVAL_TEXT_ANTIALIAS_LCD_HRGB ||
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   218
             desc.aaHint == INTVAL_TEXT_ANTIALIAS_LCD_HBGR) &&
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   219
            (matrix[1] == 0.0 && matrix[2] == 0.0 &&
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   220
             matrix[0] == matrix[3] &&
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   221
             matrix[0] >= 3.0 && matrix[0] <= 100.0) &&
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   222
            !((TrueTypeFont)fileFont).useEmbeddedBitmapsForSize(intPtSize)) {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   223
            useNatives = true;
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   224
        }
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   225
        else if (fileFont.checkUseNatives() && desc.aaHint==0 && !algoStyle) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            /* Check its a simple scale of a pt size in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
             * where native bitmaps typically exist (6-36 pts) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if (matrix[1] == 0.0 && matrix[2] == 0.0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                matrix[0] >= 6.0 && matrix[0] <= 36.0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                matrix[0] == matrix[3]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                useNatives = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                int numNatives = fileFont.nativeFonts.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                nativeStrikes = new NativeStrike[numNatives];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                /* Maybe initialise these strikes lazily?. But we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                 * know we need at least one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                for (int i=0; i<numNatives; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    nativeStrikes[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        new NativeStrike(fileFont.nativeFonts[i], desc, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   243
        if (FontManager.logging && FontManager.isWindows) {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   244
            FontManager.logger.info
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   245
                ("Strike for " + fileFont + " at size = " + intPtSize +
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   246
                 " use natives = " + useNatives +
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   247
                 " useJavaRasteriser = " + fileFont.useJavaRasterizer +
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   248
                 " AAHint = " + desc.aaHint +
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   249
                 " Has Embedded bitmaps = " +
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   250
                 ((TrueTypeFont)fileFont).
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   251
                 useEmbeddedBitmapsForSize(intPtSize));
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   252
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        this.disposer = new FontStrikeDisposer(fileFont, desc, pScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        /* Always get the image and the advance together for smaller sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
         * that are likely to be important to rendering performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         * The pixel size of 48.0 can be thought of as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
         * "maximumSizeForGetImageWithAdvance".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         * This should be no greater than OutlineTextRender.THRESHOLD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
         */
546
06253731a445 6692979: VM Crash when shearing text + rect over a range of values
prr
parents: 2
diff changeset
   261
        double maxSz = 48.0;
06253731a445 6692979: VM Crash when shearing text + rect over a range of values
prr
parents: 2
diff changeset
   262
        getImageWithAdvance =
06253731a445 6692979: VM Crash when shearing text + rect over a range of values
prr
parents: 2
diff changeset
   263
            Math.abs(at.getScaleX()) <= maxSz &&
06253731a445 6692979: VM Crash when shearing text + rect over a range of values
prr
parents: 2
diff changeset
   264
            Math.abs(at.getScaleY()) <= maxSz &&
06253731a445 6692979: VM Crash when shearing text + rect over a range of values
prr
parents: 2
diff changeset
   265
            Math.abs(at.getShearX()) <= maxSz &&
06253731a445 6692979: VM Crash when shearing text + rect over a range of values
prr
parents: 2
diff changeset
   266
            Math.abs(at.getShearY()) <= maxSz;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        /* Some applications request advance frequently during layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
         * If we are not getting and caching the image with the advance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
         * there is a potentially significant performance penalty if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
         * advance is repeatedly requested before requesting the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         * We should at least cache the horizontal advance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         * REMIND: could use info in the font, eg hmtx, to retrieve some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
         * advances. But still want to cache it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (!getImageWithAdvance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            if (!segmentedCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                horizontalAdvances = new float[numGlyphs];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                /* use max float as uninitialised advance */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                for (int i=0; i<numGlyphs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    horizontalAdvances[i] = Float.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                int numSegments = (numGlyphs + SEGSIZE-1)/SEGSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                segHorizontalAdvances = new float[numSegments][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /* A number of methods are delegated by the strike to the scaler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * context which is a shared resource on a physical font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public int getNumGlyphs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return fileFont.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   299
    long getGlyphImageFromNative(int glyphCode) {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   300
        if (FontManager.isWindows) {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   301
            return getGlyphImageFromWindows(glyphCode);
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   302
        } else {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   303
            return getGlyphImageFromX11(glyphCode);
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   304
        }
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   305
    }
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   306
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   307
    /* There's no global state conflicts, so this method is not
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   308
     * presently synchronized.
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   309
     */
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   310
    private native long _getGlyphImageFromWindows(String family,
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   311
                                                  int style,
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   312
                                                  int size,
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   313
                                                  int glyphCode,
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   314
                                                  boolean fracMetrics);
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   315
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   316
    long getGlyphImageFromWindows(int glyphCode) {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   317
        String family = fileFont.getFamilyName(null);
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   318
        int style = desc.style & Font.BOLD | desc.style & Font.ITALIC
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   319
            | fileFont.getStyle();
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   320
        int size = intPtSize;
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   321
        long ptr = _getGlyphImageFromWindows
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   322
            (family, style, size, glyphCode,
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   323
             desc.fmHint == INTVAL_FRACTIONALMETRICS_ON);
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   324
        if (ptr != 0) {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   325
            /* Get the advance from the JDK rasterizer. This is mostly
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   326
             * necessary for the fractional metrics case, but there are
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   327
             * also some very small number (<0.25%) of marginal cases where
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   328
             * there is some rounding difference between windows and JDK.
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   329
             * After these are resolved, we can restrict this extra
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   330
             * work to the FM case.
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   331
             */
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   332
            float advance = getGlyphAdvance(glyphCode, false);
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   333
            StrikeCache.unsafe.putFloat(ptr + StrikeCache.xAdvanceOffset,
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   334
                                        advance);
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   335
            return ptr;
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   336
        } else {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   337
            return fileFont.getGlyphImage(pScalerContext, glyphCode);
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   338
        }
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   339
    }
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   340
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    /* Try the native strikes first, then try the fileFont strike */
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   342
    long getGlyphImageFromX11(int glyphCode) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        long glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        char charCode = fileFont.glyphToCharMap[glyphCode];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        for (int i=0;i<nativeStrikes.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            CharToGlyphMapper mapper = fileFont.nativeFonts[i].getMapper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            int gc = mapper.charToGlyph(charCode)&0xffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            if (gc != mapper.getMissingGlyphCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                glyphPtr = nativeStrikes[i].getGlyphImagePtrNoCache(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                if (glyphPtr != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    return glyphPtr;
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
        return fileFont.getGlyphImage(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    long getGlyphImagePtr(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (glyphCode >= INVISIBLE_GLYPHS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return StrikeCache.invisibleGlyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   362
        long glyphPtr = 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if ((glyphPtr = getCachedGlyphPtr(glyphCode)) != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            return glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            if (useNatives) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                glyphPtr = getGlyphImageFromNative(glyphCode);
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   368
                if (glyphPtr == 0L && FontManager.logging) {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   369
                    FontManager.logger.info
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   370
                        ("Strike for " + fileFont +
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   371
                         " at size = " + intPtSize +
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   372
                         " couldn't get native glyph for code = " + glyphCode);
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   373
                 }
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   374
            } if (glyphPtr == 0L) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                glyphPtr = fileFont.getGlyphImage(pScalerContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                                  glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return setCachedGlyphPtr(glyphCode, glyphPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    void getGlyphImagePtrs(int[] glyphCodes, long[] images, int  len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        for (int i=0; i<len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            int glyphCode = glyphCodes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            if (glyphCode >= INVISIBLE_GLYPHS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                images[i] = StrikeCache.invisibleGlyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            } else if ((images[i] = getCachedGlyphPtr(glyphCode)) != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            } else {
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   392
                long glyphPtr = 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                if (useNatives) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    glyphPtr = getGlyphImageFromNative(glyphCode);
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   395
                } if (glyphPtr == 0L) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    glyphPtr = fileFont.getGlyphImage(pScalerContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                                                      glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                images[i] = setCachedGlyphPtr(glyphCode, glyphPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /* The following method is called from CompositeStrike as a special case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    private static final int SLOTZEROMAX = 0xffffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    int getSlot0GlyphImagePtrs(int[] glyphCodes, long[] images, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        int convertedCnt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        for (int i=0; i<len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            int glyphCode = glyphCodes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            if (glyphCode >= SLOTZEROMAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                return convertedCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                convertedCnt++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            if (glyphCode >= INVISIBLE_GLYPHS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                images[i] = StrikeCache.invisibleGlyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            } else if ((images[i] = getCachedGlyphPtr(glyphCode)) != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            } else {
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   424
                long glyphPtr = 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                if (useNatives) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    glyphPtr = getGlyphImageFromNative(glyphCode);
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   427
                }
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   428
                if (glyphPtr == 0L) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    glyphPtr = fileFont.getGlyphImage(pScalerContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                                      glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                images[i] = setCachedGlyphPtr(glyphCode, glyphPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        return convertedCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    /* Only look in the cache */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    long getCachedGlyphPtr(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        switch (glyphCacheFormat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            case INTARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                return intGlyphImages[glyphCode] & INTMASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            case SEGINTARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                int segIndex = glyphCode >> SEGSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (segIntGlyphImages[segIndex] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    int subIndex = glyphCode % SEGSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    return segIntGlyphImages[segIndex][subIndex] & INTMASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            case LONGARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                return longGlyphImages[glyphCode];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            case SEGLONGARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                segIndex = glyphCode >> SEGSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                if (segLongGlyphImages[segIndex] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    int subIndex = glyphCode % SEGSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    return segLongGlyphImages[segIndex][subIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        /* If reach here cache is UNINITIALISED. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        return 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    private synchronized long setCachedGlyphPtr(int glyphCode, long glyphPtr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        switch (glyphCacheFormat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            case INTARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                if (intGlyphImages[glyphCode] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    intGlyphImages[glyphCode] = (int)glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    return glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    StrikeCache.freeIntPointer((int)glyphPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    return intGlyphImages[glyphCode] & INTMASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            case SEGINTARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                int segIndex = glyphCode >> SEGSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                int subIndex = glyphCode % SEGSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                if (segIntGlyphImages[segIndex] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    segIntGlyphImages[segIndex] = new int[SEGSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                if (segIntGlyphImages[segIndex][subIndex] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    segIntGlyphImages[segIndex][subIndex] = (int)glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    return glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    StrikeCache.freeIntPointer((int)glyphPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    return segIntGlyphImages[segIndex][subIndex] & INTMASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            case LONGARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                if (longGlyphImages[glyphCode] == 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    longGlyphImages[glyphCode] = glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                    return glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    StrikeCache.freeLongPointer(glyphPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                    return longGlyphImages[glyphCode];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
           case SEGLONGARRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                segIndex = glyphCode >> SEGSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                subIndex = glyphCode % SEGSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                if (segLongGlyphImages[segIndex] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    segLongGlyphImages[segIndex] = new long[SEGSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                if (segLongGlyphImages[segIndex][subIndex] == 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    segLongGlyphImages[segIndex][subIndex] = glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    return glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    StrikeCache.freeLongPointer(glyphPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    return segLongGlyphImages[segIndex][subIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        /* Reach here only when the cache is not initialised which is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         * for the first glyph to be initialised in the strike.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
         * Initialise it and recurse. Note that we are already synchronized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        initGlyphCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return setCachedGlyphPtr(glyphCode, glyphPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /* Called only from synchronized code or constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    private void initGlyphCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        int numGlyphs = mapper.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        if (segmentedCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            int numSegments = (numGlyphs + SEGSIZE-1)/SEGSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            if (FontManager.longAddresses) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                glyphCacheFormat = SEGLONGARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                segLongGlyphImages = new long[numSegments][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                this.disposer.segLongGlyphImages = segLongGlyphImages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
             } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                 glyphCacheFormat = SEGINTARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                 segIntGlyphImages = new int[numSegments][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                 this.disposer.segIntGlyphImages = segIntGlyphImages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            if (FontManager.longAddresses) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                glyphCacheFormat = LONGARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                longGlyphImages = new long[numGlyphs];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                this.disposer.longGlyphImages = longGlyphImages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                glyphCacheFormat = INTARRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                intGlyphImages = new int[numGlyphs];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                this.disposer.intGlyphImages = intGlyphImages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   552
    float getGlyphAdvance(int glyphCode) {
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   553
        return getGlyphAdvance(glyphCode, true);
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   554
    }
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   555
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    /* Metrics info is always retrieved. If the GlyphInfo address is non-zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * then metrics info there is valid and can just be copied.
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   558
     * This is in user space coordinates unless getUserAdv == false.
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   559
     * Device space advance should not be propagated out of this class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     */
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   561
    private float getGlyphAdvance(int glyphCode, boolean getUserAdv) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        float advance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if (glyphCode >= INVISIBLE_GLYPHS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            return 0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if (horizontalAdvances != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            advance = horizontalAdvances[glyphCode];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            if (advance != Float.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                return advance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        } else if (segmentedCache && segHorizontalAdvances != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            int segIndex = glyphCode >> SEGSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            float[] subArray = segHorizontalAdvances[segIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            if (subArray != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                advance = subArray[glyphCode % SEGSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                if (advance != Float.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                    return advance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   583
        if (invertDevTx != null || !getUserAdv) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            /* If there is a device transform need x & y advance to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
             * transform back into user space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
             */
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   587
            advance = getGlyphMetrics(glyphCode, getUserAdv).x;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            long glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            if (getImageWithAdvance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                /* A heuristic optimisation says that for most cases its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                 * worthwhile retrieving the image at the same time as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                 * advance. So here we get the image data even if its not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                 * already cached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                glyphPtr = getGlyphImagePtr(glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                glyphPtr = getCachedGlyphPtr(glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            if (glyphPtr != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                advance = StrikeCache.unsafe.getFloat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                    (glyphPtr + StrikeCache.xAdvanceOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                advance = fileFont.getGlyphAdvance(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (horizontalAdvances != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            horizontalAdvances[glyphCode] = advance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        } else if (segmentedCache && segHorizontalAdvances != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            int segIndex = glyphCode >> SEGSHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            int subIndex = glyphCode % SEGSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (segHorizontalAdvances[segIndex] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                segHorizontalAdvances[segIndex] = new float[SEGSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                for (int i=0; i<SEGSIZE; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                     segHorizontalAdvances[segIndex][i] = Float.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            segHorizontalAdvances[segIndex][subIndex] = advance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        return advance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    float getCodePointAdvance(int cp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        return getGlyphAdvance(mapper.charToGlyph(cp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * Result and pt are both in device space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    void getGlyphImageBounds(int glyphCode, Point2D.Float pt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                             Rectangle result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        long ptr = getGlyphImagePtr(glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        float topLeftX, topLeftY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        /* With our current design NULL ptr is not possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
           but if we eventually allow scalers to return NULL pointers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
           this check might be actually useful. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        if (ptr == 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            result.x = (int) Math.floor(pt.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            result.y = (int) Math.floor(pt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            result.width = result.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        topLeftX = StrikeCache.unsafe.getFloat(ptr+StrikeCache.topLeftXOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        topLeftY = StrikeCache.unsafe.getFloat(ptr+StrikeCache.topLeftYOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        result.x = (int)Math.floor(pt.x + topLeftX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        result.y = (int)Math.floor(pt.y + topLeftY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        result.width =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            StrikeCache.unsafe.getShort(ptr+StrikeCache.widthOffset)  &0x0ffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        result.height =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            StrikeCache.unsafe.getShort(ptr+StrikeCache.heightOffset) &0x0ffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        /* HRGB LCD text may have padding that is empty. This is almost always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
         * going to be when topLeftX is -2 or less.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
         * Try to return a tighter bounding box in that case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
         * If the first three bytes of every row are all zero, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
         * add 1 to "x" and reduce "width" by 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        if ((desc.aaHint == INTVAL_TEXT_ANTIALIAS_LCD_HRGB ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
             desc.aaHint == INTVAL_TEXT_ANTIALIAS_LCD_HBGR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            && topLeftX <= -2.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            int minx = getGlyphImageMinX(ptr, (int)result.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            if (minx > result.x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                result.x += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                result.width -=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    private int getGlyphImageMinX(long ptr, int origMinX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        int width = StrikeCache.unsafe.getChar(ptr+StrikeCache.widthOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        int height = StrikeCache.unsafe.getChar(ptr+StrikeCache.heightOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        int rowBytes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            StrikeCache.unsafe.getChar(ptr+StrikeCache.rowBytesOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        if (rowBytes == width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            return origMinX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        long pixelData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        if (StrikeCache.nativeAddressSize == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            pixelData = 0xffffffff &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                StrikeCache.unsafe.getInt(ptr + StrikeCache.pixelDataOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            pixelData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                StrikeCache.unsafe.getLong(ptr + StrikeCache.pixelDataOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        if (pixelData == 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            return origMinX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        for (int y=0;y<height;y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            for (int x=0;x<3;x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                if (StrikeCache.unsafe.getByte(pixelData+y*rowBytes+x) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                    return origMinX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        return origMinX+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /* These 3 metrics methods below should be implemented to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * values in user space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    StrikeMetrics getFontMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        if (strikeMetrics == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            strikeMetrics =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                fileFont.getFontMetrics(pScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            if (invertDevTx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                strikeMetrics.convertToUserSpace(invertDevTx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        return strikeMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    Point2D.Float getGlyphMetrics(int glyphCode) {
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   723
        return getGlyphMetrics(glyphCode, true);
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   724
    }
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   725
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   726
    private Point2D.Float getGlyphMetrics(int glyphCode, boolean getUserAdv) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        Point2D.Float metrics = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        // !!! or do we force sgv user glyphs?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        if (glyphCode >= INVISIBLE_GLYPHS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            return metrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        long glyphPtr;
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   734
        if (getImageWithAdvance && getUserAdv) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            /* A heuristic optimisation says that for most cases its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
             * worthwhile retrieving the image at the same time as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
             * metrics. So here we get the image data even if its not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
             * already cached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            glyphPtr = getGlyphImagePtr(glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
             glyphPtr = getCachedGlyphPtr(glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        if (glyphPtr != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            metrics = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            metrics.x = StrikeCache.unsafe.getFloat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                (glyphPtr + StrikeCache.xAdvanceOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            metrics.y = StrikeCache.unsafe.getFloat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                (glyphPtr + StrikeCache.yAdvanceOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            /* advance is currently in device space, need to convert back
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   751
             * into user space, unless getUserAdv == false.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
             * This must not include the translation component. */
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   753
            if (invertDevTx != null && getUserAdv) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                invertDevTx.deltaTransform(metrics, metrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            /* We sometimes cache these metrics as they are expensive to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
             * generate for large glyphs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
             * We never reach this path if we obtain images with advances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
             * But if we do not obtain images with advances its possible that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
             * we first obtain this information, then the image, and never
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
             * will access this value again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
             */
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   764
            Integer key = Integer.valueOf(glyphCode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            Point2D.Float value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            ConcurrentHashMap<Integer, Point2D.Float> glyphMetricsMap = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            if (glyphMetricsMapRef != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                glyphMetricsMap = glyphMetricsMapRef.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            if (glyphMetricsMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                value = glyphMetricsMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                    metrics.x = value.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                    metrics.y = value.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                    /* already in user space */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    return metrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                fileFont.getGlyphMetrics(pScalerContext, glyphCode, metrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                /* advance is currently in device space, need to convert back
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   782
                 * into user space, unless getUserAdv == false.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                 */
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 546
diff changeset
   784
                if (invertDevTx != null && getUserAdv) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                    invertDevTx.deltaTransform(metrics, metrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                value = new Point2D.Float(metrics.x, metrics.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                /* We aren't synchronizing here so it is possible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                 * overwrite the map with another one but this is harmless.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                if (glyphMetricsMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                    glyphMetricsMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                        new ConcurrentHashMap<Integer, Point2D.Float>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                    glyphMetricsMapRef =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                        new SoftReference<ConcurrentHashMap<Integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                        Point2D.Float>>(glyphMetricsMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                glyphMetricsMap.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        return metrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    Point2D.Float getCharMetrics(char ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        return getGlyphMetrics(mapper.charToGlyph(ch));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    /* The caller of this can be trusted to return a copy of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * return value rectangle to public API. In fact frequently it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * can't use use this return value directly anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * This returns bounds in device space. Currently the only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * caller is SGV and it converts back to user space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * We could change things so that this code does the conversion so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * that all coords coming out of the font system are converted back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * into user space even if they were measured in device space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * The same applies to the other methods that return outlines (below)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * But it may make particular sense for this method that caches its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * There'd be plenty of exceptions, to this too, eg getGlyphPoint needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * device coords as its called from native layout and getGlyphImageBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * is used by GlyphVector.getGlyphPixelBounds which is specified to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * return device coordinates, the image pointers aren't really used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * up in Java code either.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    Rectangle2D.Float getGlyphOutlineBounds(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        if (boundsMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            boundsMap = new ConcurrentHashMap<Integer, Rectangle2D.Float>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   831
        Integer key = Integer.valueOf(glyphCode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        Rectangle2D.Float bounds = boundsMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        if (bounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            bounds = fileFont.getGlyphOutlineBounds(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            boundsMap.put(key, bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        return bounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    public Rectangle2D getOutlineBounds(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        return fileFont.getGlyphOutlineBounds(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    GeneralPath getGlyphOutline(int glyphCode, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        return fileFont.getGlyphOutline(pScalerContext, glyphCode, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    GeneralPath getGlyphVectorOutline(int[] glyphs, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        return fileFont.getGlyphVectorOutline(pScalerContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                                              glyphs, glyphs.length, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    protected void adjustPoint(Point2D.Float pt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        if (invertDevTx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            invertDevTx.deltaTransform(pt, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
}