src/java.desktop/share/classes/sun/font/FontScaler.java
author prr
Thu, 22 Mar 2018 14:10:30 -0700
changeset 49310 edbc57573a1c
parent 49234 3375a8039fde
child 50651 0c94d8cc5081
permissions -rw-r--r--
8199789: Emit a warning message when t2k is selected via system property Reviewed-by: serb, pnarayanan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23288
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 9759
diff changeset
     2
 * Copyright (c) 2007, 2014, 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;
23288
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 9759
diff changeset
    85
    private static Constructor<? extends FontScaler> scalerConstructor = null;
3928
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 {
23288
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 9759
diff changeset
    92
        Class<? extends FontScaler> scalerClass = null;
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 9759
diff changeset
    93
        Class<?>[] arglst = new Class<?>[] {Font2D.class, int.class,
3928
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 {
23288
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 9759
diff changeset
    97
            @SuppressWarnings("unchecked")
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 9759
diff changeset
    98
            Class<? extends FontScaler> tmp = (Class<? extends FontScaler>)
49310
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
    99
                ((!FontUtilities.useT2K && !FontUtilities.useLegacy) ?
23288
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 9759
diff changeset
   100
                 Class.forName("sun.font.FreetypeFontScaler") :
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 9759
diff changeset
   101
                 Class.forName("sun.font.T2KFontScaler"));
b7183846db97 8033624: Fix raw and unchecked lint warnings in sun.font
darcy
parents: 9759
diff changeset
   102
            scalerClass = tmp;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   103
        } catch (ClassNotFoundException e) {
49310
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
   104
            try {
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
   105
                @SuppressWarnings("unchecked")
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
   106
                Class<? extends FontScaler> tmp = (Class<? extends FontScaler>)
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
   107
                    Class.forName("sun.font.FreetypeFontScaler");
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
   108
                scalerClass = tmp;
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
   109
            } catch (ClassNotFoundException e1) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   110
                scalerClass = NullFontScaler.class;
49310
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
   111
            }
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
   112
        } finally {
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
   113
            if (FontUtilities.debugFonts()) {
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
   114
                System.out.println("Scaler class="+scalerClass);
edbc57573a1c 8199789: Emit a warning message when t2k is selected via system property
prr
parents: 49234
diff changeset
   115
            }
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   116
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   117
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   118
        //NB: rewrite using factory? constructor is ugly way
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   119
        try {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   120
            scalerConstructor = scalerClass.getConstructor(arglst);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   121
        } catch (NoSuchMethodException e) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   122
            //should not happen
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   123
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   124
    }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   125
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   126
    /* This is the only place to instantiate new FontScaler.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   127
     * Therefore this is very convinient place to register
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   128
     * scaler with Disposer as well as trigger deregistring bad font
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   129
     * in case when scaler reports this.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   130
     */
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   131
    public static FontScaler getScaler(Font2D font,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   132
                                int indexInCollection,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   133
                                boolean supportsCJK,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   134
                                int filesize) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   135
        FontScaler scaler = null;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   136
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   137
        try {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   138
            Object args[] = new Object[] {font, indexInCollection,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   139
                                          supportsCJK, filesize};
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   140
            scaler = scalerConstructor.newInstance(args);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   141
            Disposer.addObjectRecord(font, scaler);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   142
        } catch (Throwable e) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   143
            scaler = nullScaler;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   144
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   145
            //if we can not instantiate scaler assume bad font
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   146
            //NB: technically it could be also because of internal scaler
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   147
            //    error but here we are assuming scaler is ok.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   148
            FontManager fm = FontManagerFactory.getInstance();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   149
            fm.deRegisterBadFont(font);
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   150
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   151
        return scaler;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   152
    }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   153
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   154
    /*
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   155
     * At the moment it is harmless to create 2 null scalers so, technically,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   156
     * syncronized keyword is not needed.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   157
     *
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   158
     * 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
   159
     * checks like whether scaler is null scaler.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   160
     */
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   161
    public static synchronized FontScaler getNullScaler() {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   162
        if (nullScaler == null) {
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   163
            nullScaler = new NullFontScaler();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   164
        }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   165
        return nullScaler;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   166
    }
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   167
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    protected WeakReference<Font2D> font = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    protected long nativeScaler = 0; //used by decendants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                     //that have native state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    protected boolean disposed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    abstract StrikeMetrics getFontMetrics(long pScalerContext)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    abstract float getGlyphAdvance(long pScalerContext, int glyphCode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    abstract void getGlyphMetrics(long pScalerContext, int glyphCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                  Point2D.Float metrics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *  Returns pointer to native GlyphInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *  Callee is responsible for freeing this memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *  Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *   currently this method has to return not 0L but pointer to valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *   GlyphInfo object. Because Strike and drawing releated logic does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *   expect that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *   In the future we may want to rework this to allow 0L here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    abstract long getGlyphImage(long pScalerContext, int glyphCode)
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
    abstract Rectangle2D.Float getGlyphOutlineBounds(long pContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                                                     int glyphCode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    abstract GeneralPath getGlyphOutline(long pScalerContext, int glyphCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                         float x, float y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    abstract GeneralPath getGlyphVectorOutline(long pScalerContext, int[] glyphs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                                               int numGlyphs, float x, float y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /* Used by Java2D disposer to ensure native resources are released.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
       Note: this method does not release any of created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
             scaler context objects! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public void dispose() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /* At the moment these 3 methods are needed for Type1 fonts only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * For Truetype fonts we extract required info outside of scaler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * on java layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    abstract int getNumGlyphs() throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    abstract int getMissingGlyphCode() throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    abstract int getGlyphCode(char charCode) throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /* This method returns table cache used by native layout engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * This cache is essentially just small collection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * pointers to various truetype tables. See definition of TTLayoutTableCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * in the fontscalerdefs.h for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Note that tables themselves have same format as defined in the truetype
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * specification, i.e. font scaler do not need to perform any preprocessing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Probably it is better to have API to request pointers to each table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * separately instead of requesting pointer to some native structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * (then there is not need to share its definition by different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * implementations of scaler).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * However, this means multiple JNI calls and potential impact on performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Note: return value 0 is legal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *   This means tables are not available (e.g. type1 font).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    abstract long getLayoutTableCache() throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /* Used by the OpenType engine for mark positioning. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    abstract Point2D.Float getGlyphPoint(long pScalerContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                int glyphCode, int ptNumber)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        throws FontScalerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    abstract long getUnitsPerEm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /* Returns pointer to native structure describing rasterization attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
       Format of this structure is scaler-specific.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
       Callee is responsible for freeing scaler context (using free()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
       Note:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         Context is tightly associated with strike and it is actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        freed when corresponding strike is being released.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    abstract long createScalerContext(double[] matrix,
7940
7d20d72dd3b9 6930980: Disable TrueType hinting for fonts known not to hint well
prr
parents: 5506
diff changeset
   257
                                      int aa, int fm,
7d20d72dd3b9 6930980: Disable TrueType hinting for fonts known not to hint well
prr
parents: 5506
diff changeset
   258
                                      float boldness, float italic,
7d20d72dd3b9 6930980: Disable TrueType hinting for fonts known not to hint well
prr
parents: 5506
diff changeset
   259
                                      boolean disableHinting);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /* Marks context as invalid because native scaler is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
       Notes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         - pointer itself is still valid and has to be released
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         - if pointer to native scaler was cached it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
           should not be neither disposed nor used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
           it is very likely it is already disposed by this moment. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    abstract void invalidateScalerContext(long ppScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
}