jdk/src/share/classes/sun/font/PhysicalStrike.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 438 2ae294e4518c
child 3928 be186a33df9b
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: 438
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.GeneralPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.concurrent.ConcurrentHashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public abstract class PhysicalStrike extends FontStrike {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    static final long INTMASK = 0xffffffffL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private PhysicalFont physicalFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    protected CharToGlyphMapper mapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /* the ScalerContext is a native structure pre-filled with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * info needed to setup the scaler for this strike. Its immutable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * so we set it up when the strike is created and free it when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * strike is disposed. There's then no need to pass the info down
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * separately to native on every call to the scaler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected long pScalerContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /* Only one of these two arrays is non-null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * use the one that matches size of an address (32 or 64 bits)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected long[] longGlyphImages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected int[] intGlyphImages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /* Used by the TrueTypeFont subclass, which is the only client
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * of getGlyphPoint(). The field and method are here because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * there is no TrueTypeFontStrike subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * This map is a cache of the positions of points on the outline
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * of a TrueType glyph. It is used by the OpenType layout engine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * to perform mark positioning. Without this cache every position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * request involves scaling and hinting the glyph outline potentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * over and over again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    ConcurrentHashMap<Integer, Point2D.Float> glyphPointMapCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected boolean getImageWithAdvance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected static final int complexTX =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        AffineTransform.TYPE_FLIP |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        AffineTransform.TYPE_GENERAL_SCALE |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        AffineTransform.TYPE_GENERAL_ROTATION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        AffineTransform.TYPE_GENERAL_TRANSFORM |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        AffineTransform.TYPE_QUADRANT_ROTATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    PhysicalStrike(PhysicalFont physicalFont, FontStrikeDesc desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        this.physicalFont = physicalFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        this.desc = desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected PhysicalStrike() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /* A number of methods are delegated by the strike to the scaler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * context which is a shared resource on a physical font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public int getNumGlyphs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return physicalFont.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /* These 3 metrics methods below should be implemented to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * values in user space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    StrikeMetrics getFontMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (strikeMetrics == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            strikeMetrics =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                physicalFont.getFontMetrics(pScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return strikeMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    float getCodePointAdvance(int cp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return getGlyphAdvance(physicalFont.getMapper().charToGlyph(cp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
   Point2D.Float getCharMetrics(char ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return getGlyphMetrics(physicalFont.getMapper().charToGlyph(ch));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    int getSlot0GlyphImagePtrs(int[] glyphCodes, long[] images, int  len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /* Used by the OpenType engine for mark positioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    Point2D.Float getGlyphPoint(int glyphCode, int ptNumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        Point2D.Float gp = null;
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   117
        Integer ptKey = Integer.valueOf(glyphCode<<16|ptNumber);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (glyphPointMapCache == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                if (glyphPointMapCache == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    glyphPointMapCache =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                        new ConcurrentHashMap<Integer, Point2D.Float>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            gp = glyphPointMapCache.get(ptKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (gp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            gp = (physicalFont.getGlyphPoint(pScalerContext, glyphCode, ptNumber));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            adjustPoint(gp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            glyphPointMapCache.put(ptKey, gp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return gp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    protected void adjustPoint(Point2D.Float pt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
}