jdk/src/java.desktop/share/classes/sun/font/GlyphList.java
author prr
Wed, 09 Nov 2016 11:28:13 -0800
changeset 42208 7c1017f0ade5
parent 39870 55d674017343
permissions -rw-r--r--
8155874: Fix java.desktop deprecation warnings about Class.newInstance Reviewed-by: serb, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 23006
diff changeset
     2
 * Copyright (c) 2000, 2013, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.font.GlyphVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.font.FontRenderContext;
39870
55d674017343 8054991: sun.font.GlyphList uses broken double-checked locking
prr
parents: 26037
diff changeset
    31
import java.util.concurrent.atomic.AtomicBoolean;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.java2d.loops.FontInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This class represents a list of actual renderable glyphs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * It can be constructed from a number of text sources, representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * the various ways in which a programmer can ask a Graphics2D object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * to render some text.  Once constructed, it provides a way of iterating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * through the device metrics and graybits of the individual glyphs that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * need to be rendered to the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Note that this class holds pointers to native data which must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * disposed.  It is not marked as finalizable since it is intended
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * to be very lightweight and finalization is a comparitively expensive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * procedure.  The caller must specifically use try{} finally{} to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * manually ensure that the object is disposed after use, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * native data structures might be leaked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Here is a code sample for using this class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * public void drawString(String str, FontInfo info, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *     GlyphList gl = GlyphList.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *     try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *         gl.setFromString(info, str, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *         int strbounds[] = gl.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *         int numglyphs = gl.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *         for (int i = 0; i < numglyphs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *             gl.setGlyphIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *             int metrics[] = gl.getMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *             byte bits[] = gl.getGrayBits();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *             int glyphx = metrics[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *             int glyphy = metrics[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *             int glyphw = metrics[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *             int glyphh = metrics[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *             int off = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *             for (int j = 0; j < glyphh; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *                 for (int i = 0; i < glyphw; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *                     int dx = glyphx + i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *                     int dy = glyphy + j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *                     int alpha = bits[off++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *                     drawPixel(alpha, dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *     } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *         gl.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
public final class GlyphList {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final int MINGRAYLENGTH = 1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final int MAXGRAYLENGTH = 8192;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final int DEFAULT_LENGTH = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    int glyphindex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    int metrics[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    byte graybits[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /* A reference to the strike is needed for the case when the GlyphList
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * may be added to a queue for batch processing, (e.g. OpenGL) and we need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * to be completely certain that the strike is still valid when the glyphs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * images are later referenced.  This does mean that if such code discards
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * GlyphList and places only the data it contains on the queue, that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * strike needs to be part of that data held by a strong reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * In the cases of drawString() and drawChars(), this is a single strike,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * although it may be a composite strike.  In the case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * drawGlyphVector() it may be a single strike, or a list of strikes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    Object strikelist; // hold multiple strikes during rendering of complex gv
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /* In normal usage, the same GlyphList will get recycled, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * it makes sense to allocate arrays that will get reused along with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * it, rather than generating garbage. Garbage will be generated only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * in MP envts where multiple threads are executing. Throughput should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * still be higher in those cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    int len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    int maxLen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    int maxPosLen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    int glyphData[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    char chData[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    long images[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    float positions[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    float x, y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    float gposx, gposy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    boolean usePositions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /* lcdRGBOrder is used only by LCD text rendering. Its here because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * the Graphics may have a different hint value than the one used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * by a GlyphVector, so it has to be stored here - and is obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * from the right FontInfo. Another approach would have been to have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * install a separate pipe for that case but that's a lot of extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * code when a simple boolean will suffice. The overhead to non-LCD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * text is a redundant boolean assign per call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    boolean lcdRGBOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * lcdSubPixPos is used only by LCD text rendering. Its here because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * the Graphics may have a different hint value than the one used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * by a GlyphVector, so it has to be stored here - and is obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * from the right FontInfo. Its also needed by the code which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * calculates glyph positions which already needs to access this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * GlyphList and would otherwise need the FontInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * This is true only if LCD text and fractional metrics hints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * are selected on the graphics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * When this is true and the glyph positions as determined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * advances are non-integral, it requests adjustment of the positions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Setting this for surfaces which do not support it through accelerated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * loops may cause a slow-down as software loops are invoked instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    boolean lcdSubPixPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /* This scheme creates a singleton GlyphList which is checked out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * for use. Callers who find its checked out create one that after use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * is discarded. This means that in a MT-rendering environment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * there's no need to synchronise except for that one instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Fewer threads will then need to synchronise, perhaps helping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * throughput on a MP system. If for some reason the reusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * GlyphList is checked out for a long time (or never returned?) then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * we would end up always creating new ones. That situation should not
23006
7cb4567eb213 8023022: Some more typos in javadoc
igerasim
parents: 17404
diff changeset
   152
     * occur and if it did, it would just lead to some extra garbage being
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
39870
55d674017343 8054991: sun.font.GlyphList uses broken double-checked locking
prr
parents: 26037
diff changeset
   155
    private static final GlyphList reusableGL = new GlyphList();
55d674017343 8054991: sun.font.GlyphList uses broken double-checked locking
prr
parents: 26037
diff changeset
   156
    private static final AtomicBoolean inUse = new AtomicBoolean();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    void ensureCapacity(int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
      /* Note len must not be -ve! only setFromChars should be capable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
       * of passing down a -ve len, and this guards against it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (len < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
          len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (usePositions && len > maxPosLen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            positions = new float[len * 2 + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            maxPosLen = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (maxLen == 0 || len > maxLen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            glyphData = new int[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            chData = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            images = new long[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            maxLen = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private GlyphList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
//         ensureCapacity(DEFAULT_LENGTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
//     private GlyphList(int arraylen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
//          ensureCapacity(arraylen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
//     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public static GlyphList getInstance() {
39870
55d674017343 8054991: sun.font.GlyphList uses broken double-checked locking
prr
parents: 26037
diff changeset
   188
        if (inUse.compareAndSet(false, true)) {
55d674017343 8054991: sun.font.GlyphList uses broken double-checked locking
prr
parents: 26037
diff changeset
   189
            return reusableGL;
55d674017343 8054991: sun.font.GlyphList uses broken double-checked locking
prr
parents: 26037
diff changeset
   190
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            return new GlyphList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /* In some cases the caller may be able to estimate the size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * array needed, and it will usually be long enough. This avoids
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * the unnecessary reallocation that occurs if our default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * values are too small. This is useful because this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * will be discarded so the re-allocation overhead is high.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
//     public static GlyphList getInstance(int sz) {
39870
55d674017343 8054991: sun.font.GlyphList uses broken double-checked locking
prr
parents: 26037
diff changeset
   202
//      if (inUse.compareAndSet(false, true) {
55d674017343 8054991: sun.font.GlyphList uses broken double-checked locking
prr
parents: 26037
diff changeset
   203
//          return reusableGL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
//      } else {
39870
55d674017343 8054991: sun.font.GlyphList uses broken double-checked locking
prr
parents: 26037
diff changeset
   205
//          return new GlyphList(sz);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
//      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
//     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /* GlyphList is in an invalid state until setFrom* method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * After obtaining a new GlyphList it is the caller's responsibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * that one of these methods is executed before handing off the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * GlyphList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public boolean setFromString(FontInfo info, String str, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        this.strikelist = info.fontStrike;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        this.lcdRGBOrder = info.lcdRGBOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        this.lcdSubPixPos = info.lcdSubPixPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        len = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        ensureCapacity(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        str.getChars(0, len, chData, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return mapChars(info, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public boolean setFromChars(FontInfo info, char[] chars, int off, int alen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        this.strikelist = info.fontStrike;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        this.lcdRGBOrder = info.lcdRGBOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        this.lcdSubPixPos = info.lcdSubPixPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        len = alen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (alen < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            len = alen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        ensureCapacity(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        System.arraycopy(chars, off, chData, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return mapChars(info, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
26004
7507a1b93f67 6521783: Unnecessary final modifier for a method in a final class
serb
parents: 23010
diff changeset
   245
    private boolean mapChars(FontInfo info, int len) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        /* REMIND.Is it worthwhile for the iteration to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
         * chars to glyph ids to directly map to images?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (info.font2D.getMapper().charsToGlyphsNS(len, chData, glyphData)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        info.fontStrike.getGlyphImagePtrs(glyphData, images, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        glyphindex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return true;
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
    public void setFromGlyphVector(FontInfo info, GlyphVector gv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                   float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        this.lcdRGBOrder = info.lcdRGBOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        this.lcdSubPixPos = info.lcdSubPixPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        /* A GV may be rendered in different Graphics. It is possible it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
         * used for one case where LCD text is available, and another where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
         * it is not. Pass in the "info". to ensure get a suitable one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        StandardGlyphVector sgv = StandardGlyphVector.getStandardGV(gv, info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // call before ensureCapacity :-
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        usePositions = sgv.needsPositions(info.devTx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        len = sgv.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        ensureCapacity(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        strikelist = sgv.setupGlyphImages(images,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                          usePositions ? positions : null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                          info.devTx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        glyphindex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public int[] getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        /* We co-opt the 5 element array that holds per glyph metrics in order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
         * to return the bounds. So a caller must copy the data out of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
         * array before calling any other methods on this GlyphList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (glyphindex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            throw new InternalError("calling getBounds after setGlyphIndex");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (metrics == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            metrics = new int[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        /* gposx and gposy are used to accumulate the advance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         * Add 0.5f for consistent rounding to pixel position. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        gposx = x + 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        gposy = y + 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        fillBounds(metrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return metrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /* This method now assumes "state", so must be called 0->len
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * The metrics it returns are accumulated on the fly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * So it could be renamed "nextGlyph()".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Note that a laid out GlyphVector which has assigned glyph positions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * doesn't have this stricture..
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public void setGlyphIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        glyphindex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        float gx =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            StrikeCache.unsafe.getFloat(images[i]+StrikeCache.topLeftXOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        float gy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            StrikeCache.unsafe.getFloat(images[i]+StrikeCache.topLeftYOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (usePositions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            metrics[0] = (int)Math.floor(positions[(i<<1)]   + gposx + gx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            metrics[1] = (int)Math.floor(positions[(i<<1)+1] + gposy + gy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            metrics[0] = (int)Math.floor(gposx + gx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            metrics[1] = (int)Math.floor(gposy + gy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            /* gposx and gposy are used to accumulate the advance */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            gposx += StrikeCache.unsafe.getFloat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                (images[i]+StrikeCache.xAdvanceOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            gposy += StrikeCache.unsafe.getFloat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                (images[i]+StrikeCache.yAdvanceOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        metrics[2] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            StrikeCache.unsafe.getChar(images[i]+StrikeCache.widthOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        metrics[3] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            StrikeCache.unsafe.getChar(images[i]+StrikeCache.heightOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        metrics[4] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            StrikeCache.unsafe.getChar(images[i]+StrikeCache.rowBytesOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public int[] getMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return metrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public byte[] getGrayBits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        int len = metrics[4] * metrics[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (graybits == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            graybits = new byte[Math.max(len, MINGRAYLENGTH)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            if (len > graybits.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                graybits = new byte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
17404
47af135a3e95 7191872: Xrender: No text displayed using 64 bit JDK on solaris11-sparc
simonis
parents: 5506
diff changeset
   344
        long pixelDataAddress =
47af135a3e95 7191872: Xrender: No text displayed using 64 bit JDK on solaris11-sparc
simonis
parents: 5506
diff changeset
   345
            StrikeCache.unsafe.getAddress(images[glyphindex] +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                          StrikeCache.pixelDataOffset);
17404
47af135a3e95 7191872: Xrender: No text displayed using 64 bit JDK on solaris11-sparc
simonis
parents: 5506
diff changeset
   347
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (pixelDataAddress == 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            return graybits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        /* unsafe is supposed to be fast, but I doubt if this loop can beat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         * a native call which does a getPrimitiveArrayCritical and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
         * memcpy for the typical amount of image data (30-150 bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
         * Consider a native method if there is a performance problem (which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
         * I haven't seen so far).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        for (int i=0; i<len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            graybits[i] = StrikeCache.unsafe.getByte(pixelDataAddress+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return graybits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public long[] getImages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return images;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public boolean usePositions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return usePositions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    public float[] getPositions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return positions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public float getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public float getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public Object getStrike() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return strikelist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public boolean isSubPixPos() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return lcdSubPixPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public boolean isRGBOrder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        return lcdRGBOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /* There's a reference equality test overhead here, but it allows us
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * to avoid synchronizing for GL's that will just be GC'd. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * helps MP throughput.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (this == reusableGL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if (graybits != null && graybits.length > MAXGRAYLENGTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                graybits = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            usePositions = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            strikelist = null; // remove reference to the strike list
39870
55d674017343 8054991: sun.font.GlyphList uses broken double-checked locking
prr
parents: 26037
diff changeset
   406
            inUse.set(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /* The value here is for use by the rendering engine as it reflects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * the number of glyphs in the array to be blitted. Surrogates pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * may have two slots (the second of these being a dummy entry of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * invisible glyph), whereas an application client would expect only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * one glyph. In other words don't propagate this value up to client code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * {dlf} an application client should have _no_ expectations about the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * number of glyphs per char.  This ultimately depends on the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * technology and layout process used, which in general clients will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * know nothing about.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public int getNumGlyphs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /* We re-do all this work as we iterate through the glyphs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * but it seems unavoidable without re-working the Java TextRenderers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    private void fillBounds(int[] bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        /* Faster to access local variables in the for loop? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        int xOffset = StrikeCache.topLeftXOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        int yOffset = StrikeCache.topLeftYOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        int wOffset = StrikeCache.widthOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        int hOffset = StrikeCache.heightOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        int xAdvOffset = StrikeCache.xAdvanceOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        int yAdvOffset = StrikeCache.yAdvanceOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            bounds[0] = bounds[1] = bounds[2] = bounds[3] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        float bx0, by0, bx1, by1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        bx0 = by0 = Float.POSITIVE_INFINITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        bx1 = by1 = Float.NEGATIVE_INFINITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        int posIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        float glx = x + 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        float gly = y + 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        char gw, gh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        float gx, gy, gx0, gy0, gx1, gy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        for (int i=0; i<len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            gx = StrikeCache.unsafe.getFloat(images[i]+xOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            gy = StrikeCache.unsafe.getFloat(images[i]+yOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            gw = StrikeCache.unsafe.getChar(images[i]+wOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            gh = StrikeCache.unsafe.getChar(images[i]+hOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (usePositions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                gx0 = positions[posIndex++] + gx + glx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                gy0 = positions[posIndex++] + gy + gly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                gx0 = glx + gx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                gy0 = gly + gy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                glx += StrikeCache.unsafe.getFloat(images[i]+xAdvOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                gly += StrikeCache.unsafe.getFloat(images[i]+yAdvOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            gx1 = gx0 + gw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            gy1 = gy0 + gh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            if (bx0 > gx0) bx0 = gx0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            if (by0 > gy0) by0 = gy0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            if (bx1 < gx1) bx1 = gx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            if (by1 < gy1) by1 = gy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        /* floor is safe and correct because all glyph widths, heights
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
         * and offsets are integers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        bounds[0] = (int)Math.floor(bx0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        bounds[1] = (int)Math.floor(by0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        bounds[2] = (int)Math.floor(bx1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        bounds[3] = (int)Math.floor(by1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
}