jdk/src/share/classes/sun/font/FontScaler.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7940 7d20d72dd3b9
child 9759 90976a831a86
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7940
diff changeset
     2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.geom.GeneralPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.ref.WeakReference;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    32
import java.lang.reflect.Constructor;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    33
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    34
import sun.java2d.Disposer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.java2d.DisposerRecord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/* FontScaler is "internal interface" to font rasterizer library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Access to native rasterizers without going through this interface is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * strongly discouraged. In particular, this is important because native
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * data could be disposed due to runtime font processing error at any time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * FontScaler represents combination of particular rasterizer implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * and particular font. It does not include rasterization attributes such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * transform. These attributes are part of native scalerContext object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * This approach allows to share same scaler for different requests related
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * to the same font file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Note that scaler may throw FontScalerException on any operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Generally this means that runtime error had happened and scaler is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * usable.  Subsequent calls to this scaler should not cause crash but will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * likely cause exceptions to be thrown again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * It is recommended that callee should replace its reference to the scaler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * with something else. For instance it could be FontManager.getNullScaler().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Note that NullScaler is trivial and will not actually rasterize anything.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Alternatively, callee can use more sophisticated error recovery strategies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * and for instance try to substitute failed scaler with new scaler instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * using another font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Note that in case of error there is no need to call dispose(). Moreover,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * dispose() generally is called by Disposer thread and explicit calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * dispose might have unexpected sideeffects because scaler can be shared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Current disposing logic is the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *   - scaler is registered in the Disposer by the FontManager (on creation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *   - scalers are disposed when associated Font2D object (e.g. TruetypeFont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *     is garbage collected. That's why this object implements DisposerRecord
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *     interface directly (as it is not used as indicator when it is safe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *     to release native state) and that's why we have to use WeakReference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *     to Font internally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *   - Majority of Font2D objects are linked from various mapping arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *     (e.g. FontManager.localeFullNamesToFont). So, they are not collected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *     This logic only works for fonts created with Font.createFont()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *  Notes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *   - Eventually we may consider releasing some of the scaler resources if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *     it was not used for a while but we do not want to be too aggressive on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *     this (and this is probably more important for Type1 fonts).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
public abstract class FontScaler implements DisposerRecord {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    83
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    84
    private static FontScaler nullScaler = null;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    85
    private static Constructor<FontScaler> scalerConstructor = null;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    86
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    87
    //Find preferred font scaler
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    88
    //
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    89
    //NB: we can allow property based preferences
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    90
    //   (theoretically logic can be font type specific)
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    91
    static {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    92
        Class scalerClass = null;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    93
        Class arglst[] = new Class[] {Font2D.class, int.class,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    94
        boolean.class, int.class};
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    95
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    96
        try {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    97
            if (FontUtilities.isOpenJDK) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    98
                scalerClass = Class.forName("sun.font.FreetypeFontScaler");
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    99
            } else {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   100
                scalerClass = Class.forName("sun.font.T2KFontScaler");
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   101
            }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   102
        } catch (ClassNotFoundException e) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   103
                scalerClass = NullFontScaler.class;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   104
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   105
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   106
        //NB: rewrite using factory? constructor is ugly way
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   107
        try {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   108
            scalerConstructor = scalerClass.getConstructor(arglst);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   109
        } catch (NoSuchMethodException e) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   110
            //should not happen
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   111
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   112
    }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   113
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   114
    /* This is the only place to instantiate new FontScaler.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   115
     * Therefore this is very convinient place to register
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   116
     * scaler with Disposer as well as trigger deregistring bad font
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   117
     * in case when scaler reports this.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   118
     */
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   119
    public static FontScaler getScaler(Font2D font,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   120
                                int indexInCollection,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   121
                                boolean supportsCJK,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   122
                                int filesize) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   123
        FontScaler scaler = null;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   124
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   125
        try {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   126
            Object args[] = new Object[] {font, indexInCollection,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   127
                                          supportsCJK, filesize};
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   128
            scaler = scalerConstructor.newInstance(args);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   129
            Disposer.addObjectRecord(font, scaler);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   130
        } catch (Throwable e) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   131
            scaler = nullScaler;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   132
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   133
            //if we can not instantiate scaler assume bad font
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   134
            //NB: technically it could be also because of internal scaler
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   135
            //    error but here we are assuming scaler is ok.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   136
            FontManager fm = FontManagerFactory.getInstance();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   137
            fm.deRegisterBadFont(font);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   138
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   139
        return scaler;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   140
    }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   141
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   142
    /*
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   143
     * At the moment it is harmless to create 2 null scalers so, technically,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   144
     * syncronized keyword is not needed.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   145
     *
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   146
     * But it is safer to keep it to avoid subtle problems if we will be adding
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   147
     * checks like whether scaler is null scaler.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   148
     */
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   149
    public static synchronized FontScaler getNullScaler() {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   150
        if (nullScaler == null) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   151
            nullScaler = new NullFontScaler();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   152
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   153
        return nullScaler;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   154
    }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   155
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    protected WeakReference<Font2D> font = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    protected long nativeScaler = 0; //used by decendants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                     //that have native state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    protected boolean disposed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    abstract StrikeMetrics getFontMetrics(long pScalerContext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    abstract float getGlyphAdvance(long pScalerContext, int glyphCode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    abstract void getGlyphMetrics(long pScalerContext, int glyphCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                  Point2D.Float metrics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *  Returns pointer to native GlyphInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *  Callee is responsible for freeing this memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *  Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *   currently this method has to return not 0L but pointer to valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *   GlyphInfo object. Because Strike and drawing releated logic does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *   expect that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *   In the future we may want to rework this to allow 0L here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    abstract long getGlyphImage(long pScalerContext, int glyphCode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    abstract Rectangle2D.Float getGlyphOutlineBounds(long pContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                                     int glyphCode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    abstract GeneralPath getGlyphOutline(long pScalerContext, int glyphCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                         float x, float y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    abstract GeneralPath getGlyphVectorOutline(long pScalerContext, int[] glyphs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                               int numGlyphs, float x, float y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /* Used by Java2D disposer to ensure native resources are released.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
       Note: this method does not release any of created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
             scaler context objects! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public void dispose() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /* At the moment these 3 methods are needed for Type1 fonts only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * For Truetype fonts we extract required info outside of scaler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * on java layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    abstract int getNumGlyphs() throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    abstract int getMissingGlyphCode() throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    abstract int getGlyphCode(char charCode) throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /* This method returns table cache used by native layout engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * This cache is essentially just small collection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * pointers to various truetype tables. See definition of TTLayoutTableCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * in the fontscalerdefs.h for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Note that tables themselves have same format as defined in the truetype
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * specification, i.e. font scaler do not need to perform any preprocessing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Probably it is better to have API to request pointers to each table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * separately instead of requesting pointer to some native structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * (then there is not need to share its definition by different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * implementations of scaler).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * However, this means multiple JNI calls and potential impact on performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Note: return value 0 is legal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *   This means tables are not available (e.g. type1 font).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    abstract long getLayoutTableCache() throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /* Used by the OpenType engine for mark positioning. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    abstract Point2D.Float getGlyphPoint(long pScalerContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                int glyphCode, int ptNumber)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    abstract long getUnitsPerEm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /* Returns pointer to native structure describing rasterization attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
       Format of this structure is scaler-specific.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
       Callee is responsible for freeing scaler context (using free()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
       Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
         Context is tightly associated with strike and it is actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        freed when corresponding strike is being released.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    abstract long createScalerContext(double[] matrix,
7940
7d20d72dd3b9 6930980: Disable TrueType hinting for fonts known not to hint well
prr
parents: 5506
diff changeset
   245
                                      boolean fontType,
7d20d72dd3b9 6930980: Disable TrueType hinting for fonts known not to hint well
prr
parents: 5506
diff changeset
   246
                                      int aa, int fm,
7d20d72dd3b9 6930980: Disable TrueType hinting for fonts known not to hint well
prr
parents: 5506
diff changeset
   247
                                      float boldness, float italic,
7d20d72dd3b9 6930980: Disable TrueType hinting for fonts known not to hint well
prr
parents: 5506
diff changeset
   248
                                      boolean disableHinting);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /* Marks context as invalid because native scaler is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
       Notes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
         - pointer itself is still valid and has to be released
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         - if pointer to native scaler was cached it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
           should not be neither disposed nor used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
           it is very likely it is already disposed by this moment. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    abstract void invalidateScalerContext(long ppScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}