jdk/src/solaris/classes/sun/font/NativeStrike.java
author rkennke
Fri, 07 Aug 2009 18:31:11 +0200
changeset 3928 be186a33df9b
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6795908: Refactor FontManager Reviewed-by: prr, igor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.geom.GeneralPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.geom.NoninvertibleTransformException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 class NativeStrike extends PhysicalStrike {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
     NativeFont nativeFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     int numGlyphs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     AffineTransform invertDevTx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     AffineTransform fontTx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     /* The following method prepares data used in obtaining FontMetrics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
      * This is the one case in which we allow anything other than a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
      * simple scale to be used with a native font. We do this because in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
      * order to ensure that clients get the overall metrics they expect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
      * for a font whatever coordinate system (combination of font and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
      * device transform) they use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
      * X11 fonts can only have a scale applied (remind : non-uniform?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
      * We strip out everything else and if necessary obtain an inverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
      * tx which we use to return metrics for the font in the transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
      * coordinate system of the font. ie we pass X11 a simple scale, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
      * then apply the non-scale part of the font TX to that result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     private int getNativePointSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
         /* Make a copy of the glyphTX in which we will store the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
          * font transform, inverting the devTx if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
         double[] mat = new double[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
         desc.glyphTx.getMatrix(mat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
         fontTx = new AffineTransform(mat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
         /* Now work backwards to get the font transform */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
         if (!desc.devTx.isIdentity() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
             desc.devTx.getType() != AffineTransform.TYPE_TRANSLATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
             try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                 invertDevTx = desc.devTx.createInverse();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                 fontTx.concatenate(invertDevTx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
             } catch (NoninvertibleTransformException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                 e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
         /* At this point the fontTx may be a simple +ve scale, or it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
          * may be something more complex.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
         Point2D.Float pt = new Point2D.Float(1f,1f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         fontTx.deltaTransform(pt, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
         double ptSize = Math.abs(pt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
         int ttype = fontTx.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
         if ((ttype & ~AffineTransform.TYPE_UNIFORM_SCALE) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
             fontTx.getScaleY() <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
             /* We need to create an inverse transform that doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
              * include the point size (strictly the uniform scale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
              */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
             fontTx.scale(1/ptSize, 1/ptSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
             fontTx = null; // no need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         return (int)ptSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     NativeStrike(NativeFont nativeFont, FontStrikeDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         super(nativeFont, desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         this.nativeFont = nativeFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         /* If this is a delegate for bitmaps, we expect to have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
          * been invoked only for a simple scale. If that's not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
          * true, just bail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         if (nativeFont.isBitmapDelegate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
             int ttype = desc.glyphTx.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
             if ((ttype & ~AffineTransform.TYPE_UNIFORM_SCALE) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                 desc.glyphTx.getScaleX() <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
             numGlyphs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
             return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         int ptSize = getNativePointSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         byte [] nameBytes = nativeFont.getPlatformNameBytes(ptSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         double scale = Math.abs(desc.devTx.getScaleX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         pScalerContext = createScalerContext(nameBytes, ptSize, scale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         if (pScalerContext == 0L) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   115
             SunFontManager.getInstance().deRegisterBadFont(nativeFont);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
             pScalerContext = createNullScalerContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
             numGlyphs = 0;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   118
             if (FontUtilities.isLogging()) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   119
                 FontUtilities.getLogger()
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   120
                                   .severe("Could not create native strike " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                           new String(nameBytes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
             return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         numGlyphs = nativeFont.getMapper().getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         this.disposer = new NativeStrikeDisposer(nativeFont, desc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                                  pScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     /* The asymmetry of the following methods is to help preserve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      * performance with minimal textual changes to the calling code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
      * when moving initialisation of these arrays out of the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
      * This may be restructured later when there's more room for changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     private boolean usingIntGlyphImages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         if (intGlyphImages != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return true;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   138
        } else if (longAddresses) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            /* We could obtain minGlyphIndex and index relative to that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
             * if we need to save space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            int glyphLenArray = getMaxGlyph(pScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            /* This shouldn't be necessary - its a precaution */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (glyphLenArray < numGlyphs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                glyphLenArray = numGlyphs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            intGlyphImages = new int[glyphLenArray];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            this.disposer.intGlyphImages = intGlyphImages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     private long[] getLongGlyphImages() {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   157
        if (longGlyphImages == null && longAddresses) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            /* We could obtain minGlyphIndex and index relative to that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
             * if we need to save space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            int glyphLenArray = getMaxGlyph(pScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            /* This shouldn't be necessary - its a precaution */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            if (glyphLenArray < numGlyphs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                glyphLenArray = numGlyphs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            longGlyphImages = new long[glyphLenArray];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            this.disposer.longGlyphImages = longGlyphImages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return longGlyphImages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     NativeStrike(NativeFont nativeFont, FontStrikeDesc desc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                  boolean nocache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         super(nativeFont, desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         this.nativeFont = nativeFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         int ptSize = (int)desc.glyphTx.getScaleY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         double scale = desc.devTx.getScaleX(); // uniform scale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         byte [] nameBytes = nativeFont.getPlatformNameBytes(ptSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         pScalerContext = createScalerContext(nameBytes, ptSize, scale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         int numGlyphs = nativeFont.getMapper().getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     /* We want the native font to be responsible for reporting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
      * font metrics, even if it often delegates to another font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      * The code here isn't yet implementing exactly that. If the glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      * transform was something native couldn't handle, there's no native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
      * context from which to obtain metrics. Need to revise this to obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
      * the metrics and transform them. But currently in such a case it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
      * gets the metrics from a different font - its glyph delegate font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     StrikeMetrics getFontMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         if (strikeMetrics == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
             if (pScalerContext != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                 strikeMetrics = nativeFont.getFontMetrics(pScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
             if (strikeMetrics != null && fontTx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                 strikeMetrics.convertToUserSpace(fontTx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         return strikeMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     private native long createScalerContext(byte[] nameBytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                             int ptSize, double scale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     private native int getMaxGlyph(long pScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     private native long createNullScalerContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     void getGlyphImagePtrs(int[] glyphCodes, long[] images,int  len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         for (int i=0; i<len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
             images[i] = getGlyphImagePtr(glyphCodes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     long getGlyphImagePtr(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         long glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
         if (usingIntGlyphImages()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
             if ((glyphPtr = intGlyphImages[glyphCode] & INTMASK) != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                 return glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
             } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                 glyphPtr = nativeFont.getGlyphImage(pScalerContext,glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                 /* Synchronize in case some other thread has updated this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                  * cache entry already - unlikely but possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                 synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                     if (intGlyphImages[glyphCode] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                         intGlyphImages[glyphCode] = (int)glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                         return glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                     } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                         StrikeCache.freeIntPointer((int)glyphPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                         return intGlyphImages[glyphCode] & INTMASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
         /* must be using long (8 byte) addresses */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
         else if ((glyphPtr = getLongGlyphImages()[glyphCode]) != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
             return glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
             glyphPtr = nativeFont.getGlyphImage(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
             synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                 if (longGlyphImages[glyphCode] == 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                     longGlyphImages[glyphCode] = glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                     return glyphPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                 } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                     StrikeCache.freeLongPointer(glyphPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                     return longGlyphImages[glyphCode];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     /* This is used when a FileFont uses the native names to create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      * delegate NativeFont/Strike to get images from native. This is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      * because Solaris TrueType fonts have external PCF bitmaps rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      * embedded bitmaps. This is really only important for CJK fonts as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
      * for most scripts the external X11 bitmaps aren't much better - if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
      * at all - than the results from hinting the outlines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     long getGlyphImagePtrNoCache(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
         return nativeFont.getGlyphImageNoDefault(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     void getGlyphImageBounds(int glyphcode, Point2D.Float pt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                              Rectangle result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     Point2D.Float getGlyphMetrics(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
         Point2D.Float pt = new Point2D.Float(getGlyphAdvance(glyphCode), 0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         return pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     float getGlyphAdvance(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
         return nativeFont.getGlyphAdvance(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     Rectangle2D.Float getGlyphOutlineBounds(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
         return nativeFont.getGlyphOutlineBounds(pScalerContext, glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     GeneralPath getGlyphOutline(int glyphCode, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         return new GeneralPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     GeneralPath getGlyphVectorOutline(int[] glyphs, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         return new GeneralPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
/* Returned instead of a NativeStrike.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 * It can intercept any request it wants, but mostly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 * passes them on to its delegate strike. It is important that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 * it override all the inherited FontStrike methods to delegate them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 * appropriately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
class DelegateStrike extends NativeStrike {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private FontStrike delegateStrike;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    DelegateStrike(NativeFont nativeFont, FontStrikeDesc desc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                   FontStrike delegate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        super(nativeFont, desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        this.delegateStrike = delegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /* We want the native font to be responsible for reporting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * font metrics, even if it often delegates to another font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * The code here isn't yet implementing exactly that. If the glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * transform was something native couldn't handle, there's no native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * context from which to obtain metrics. Need to revise this to obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * the metrics and transform them. But currently in such a case it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * gets the metrics from a different font - its glyph delegate font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
   StrikeMetrics getFontMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
       if (strikeMetrics == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
           if (pScalerContext != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
               strikeMetrics = super.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if (strikeMetrics == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                strikeMetrics = delegateStrike.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return strikeMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    void getGlyphImagePtrs(int[] glyphCodes, long[] images,int  len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        delegateStrike.getGlyphImagePtrs(glyphCodes, images, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    long getGlyphImagePtr(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return delegateStrike.getGlyphImagePtr(glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    void getGlyphImageBounds(int glyphCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                             Point2D.Float pt, Rectangle result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        delegateStrike.getGlyphImageBounds(glyphCode, pt, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    Point2D.Float getGlyphMetrics(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return delegateStrike.getGlyphMetrics(glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    float getGlyphAdvance(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return delegateStrike.getGlyphAdvance(glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     Point2D.Float getCharMetrics(char ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return delegateStrike.getCharMetrics(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    float getCodePointAdvance(int cp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (cp < 0 || cp >= 0x10000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            cp = 0xffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return delegateStrike.getGlyphAdvance(cp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    Rectangle2D.Float getGlyphOutlineBounds(int glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return delegateStrike.getGlyphOutlineBounds(glyphCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    GeneralPath getGlyphOutline(int glyphCode, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return delegateStrike.getGlyphOutline(glyphCode, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    GeneralPath getGlyphVectorOutline(int[] glyphs, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        return delegateStrike.getGlyphVectorOutline(glyphs, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
}