jdk/src/share/classes/java/awt/font/TextLine.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 11081 4a18889223e4
child 25111 080de8ffa3f6
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
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: 11081
diff changeset
     2
 * Copyright (c) 1998, 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: 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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright IBM Corp. 1998-2003, All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
package java.awt.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Graphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Shape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.geom.GeneralPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.im.InputMethodHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.text.Annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.text.AttributedCharacterIterator;
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
    46
import java.text.AttributedCharacterIterator.Attribute;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.text.Bidi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.text.CharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.font.AttributeValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.font.BidiUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.font.CoreMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.font.Decoration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.font.FontLineMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.font.FontResolver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.font.GraphicComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.font.LayoutPathImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.font.LayoutPathImpl.EmptyPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import sun.font.LayoutPathImpl.SegmentPathBuilder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import sun.font.TextLabelFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import sun.font.TextLineComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import sun.text.CodePointIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import java.awt.geom.Line2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
final class TextLine {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    static final class TextLineMetrics {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        public final float ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        public final float descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        public final float leading;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        public final float advance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        public TextLineMetrics(float ascent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                           float descent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                           float leading,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                           float advance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            this.ascent = ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            this.descent = descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            this.leading = leading;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            this.advance = advance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private TextLineComponent[] fComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private float[] fBaselineOffsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private int[] fComponentVisualOrder; // if null, ltr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private float[] locs; // x,y pairs for components in visual order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private char[] fChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private int fCharsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private int fCharsLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private int[] fCharVisualOrder;  // if null, ltr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private int[] fCharLogicalOrder; // if null, ltr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private byte[] fCharLevels;     // if null, 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private boolean fIsDirectionLTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private LayoutPathImpl lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private boolean isSimple;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private Rectangle pixelBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private FontRenderContext frc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private TextLineMetrics fMetrics = null; // built on demand in getMetrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public TextLine(FontRenderContext frc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    TextLineComponent[] components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    float[] baselineOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    char[] chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    int charsStart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    int charsLimit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                    int[] charLogicalOrder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    byte[] charLevels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    boolean isDirectionLTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        int[] componentVisualOrder = computeComponentOrder(components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                                           charLogicalOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        this.frc = frc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        fComponents = components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        fBaselineOffsets = baselineOffsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        fComponentVisualOrder = componentVisualOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        fChars = chars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        fCharsStart = charsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        fCharsLimit = charsLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        fCharLogicalOrder = charLogicalOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        fCharLevels = charLevels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        fIsDirectionLTR = isDirectionLTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        checkCtorArgs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private void checkCtorArgs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        int checkCharCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        for (int i=0; i < fComponents.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            checkCharCount += fComponents[i].getNumCharacters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (checkCharCount != this.characterCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            throw new IllegalArgumentException("Invalid TextLine!  " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                "char count is different from " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                                "sum of char counts of components.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // first, we need to check for graphic components on the TOP or BOTTOM baselines.  So
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        // we perform the work that used to be in getMetrics here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        float ascent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        float descent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        float leading = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        float advance = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // ascent + descent must not be less than this value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        float maxGraphicHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        float maxGraphicHeightWithLeading = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // walk through EGA's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        TextLineComponent tlc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        boolean fitTopAndBottomGraphics = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        isSimple = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        for (int i = 0; i < fComponents.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            tlc = fComponents[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            isSimple &= tlc.isSimple();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            CoreMetrics cm = tlc.getCoreMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            byte baseline = (byte)cm.baselineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            if (baseline >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                float baselineOffset = fBaselineOffsets[baseline];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                ascent = Math.max(ascent, -baselineOffset + cm.ascent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                float gd = baselineOffset + cm.descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                descent = Math.max(descent, gd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                leading = Math.max(leading, gd + cm.leading);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                fitTopAndBottomGraphics = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                float graphicHeight = cm.ascent + cm.descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                float graphicHeightWithLeading = graphicHeight + cm.leading;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                maxGraphicHeight = Math.max(maxGraphicHeight, graphicHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                maxGraphicHeightWithLeading = Math.max(maxGraphicHeightWithLeading,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                                       graphicHeightWithLeading);
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
        if (fitTopAndBottomGraphics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if (maxGraphicHeight > ascent + descent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                descent = maxGraphicHeight - ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            if (maxGraphicHeightWithLeading > ascent + leading) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                leading = maxGraphicHeightWithLeading - ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        leading -= descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        // we now know enough to compute the locs, but we need the final loc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        // for the advance before we can create the metrics object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (fitTopAndBottomGraphics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            // we have top or bottom baselines, so expand the baselines array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // full offsets are needed by CoreMetrics.effectiveBaselineOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            fBaselineOffsets = new float[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                fBaselineOffsets[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                fBaselineOffsets[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                fBaselineOffsets[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                descent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                -ascent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        float x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        float y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        CoreMetrics pcm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        boolean needPath = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        locs = new float[fComponents.length * 2 + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        for (int i = 0, n = 0; i < fComponents.length; ++i, n += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            tlc = fComponents[getComponentLogicalIndex(i)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            CoreMetrics cm = tlc.getCoreMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            if ((pcm != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                (pcm.italicAngle != 0 || cm.italicAngle != 0) &&  // adjust because of italics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                (pcm.italicAngle != cm.italicAngle ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                 pcm.baselineIndex != cm.baselineIndex ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                 pcm.ssOffset != cm.ssOffset)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                // 1) compute the area of overlap - min effective ascent and min effective descent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                // 2) compute the x positions along italic angle of ascent and descent for left and right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                // 3) compute maximum left - right, adjust right position by this value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                // this is a crude form of kerning between textcomponents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                // note glyphvectors preposition glyphs based on offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                // so tl doesn't need to adjust glyphvector position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                // 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                float pb = pcm.effectiveBaselineOffset(fBaselineOffsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                float pa = pb - pcm.ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                float pd = pb + pcm.descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                // pb += pcm.ssOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                float cb = cm.effectiveBaselineOffset(fBaselineOffsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                float ca = cb - cm.ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                float cd = cb + cm.descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                // cb += cm.ssOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                float a = Math.max(pa, ca);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                float d = Math.min(pd, cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                // 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                float pax = pcm.italicAngle * (pb - a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                float pdx = pcm.italicAngle * (pb - d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                float cax = cm.italicAngle * (cb - a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                float cdx = cm.italicAngle * (cb - d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                // 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                float dax = pax - cax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                float ddx = pdx - cdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                float dx = Math.max(dax, ddx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                x += dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                y = cb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                // no italic adjustment for x, but still need to compute y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                y = cm.effectiveBaselineOffset(fBaselineOffsets); // + cm.ssOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            locs[n] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            locs[n+1] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            x += tlc.getAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            pcm = cm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            needPath |= tlc.getBaselineTransform() != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        // do we want italic padding at the right of the line?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (pcm.italicAngle != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            float pb = pcm.effectiveBaselineOffset(fBaselineOffsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            float pa = pb - pcm.ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            float pd = pb + pcm.descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            pb += pcm.ssOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            float d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if (pcm.italicAngle > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                d = pb + pcm.ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                d = pb - pcm.descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            d *= pcm.italicAngle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            x += d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        locs[locs.length - 2] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        // locs[locs.length - 1] = 0; // final offset is always back on baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // ok, build fMetrics since we have the final advance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        advance = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        fMetrics = new TextLineMetrics(ascent, descent, leading, advance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        // build path if we need it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (needPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            isSimple = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            Point2D.Double pt = new Point2D.Double();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            double tx = 0, ty = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            SegmentPathBuilder builder = new SegmentPathBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            builder.moveTo(locs[0], 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            for (int i = 0, n = 0; i < fComponents.length; ++i, n += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                tlc = fComponents[getComponentLogicalIndex(i)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                AffineTransform at = tlc.getBaselineTransform();
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   322
                if (at != null &&
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   323
                    ((at.getType() & AffineTransform.TYPE_TRANSLATION) != 0)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    double dx = at.getTranslateX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    double dy = at.getTranslateY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    builder.moveTo(tx += dx, ty += dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                pt.x = locs[n+2] - locs[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                pt.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                if (at != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    at.deltaTransform(pt, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                builder.lineTo(tx += pt.x, ty += pt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            lp = builder.complete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            if (lp == null) { // empty path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                tlc = fComponents[getComponentLogicalIndex(0)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                AffineTransform at = tlc.getBaselineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                if (at != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    lp = new EmptyPath(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public Rectangle getPixelBounds(FontRenderContext frc, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        Rectangle result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        // if we have a matching frc, set it to null so we don't have to test it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        // for each component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (frc != null && frc.equals(this.frc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            frc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        // only cache integral locations with the default frc, this is a bit strict
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        int ix = (int)Math.floor(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        int iy = (int)Math.floor(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        float rx = x - ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        float ry = y - iy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        boolean canCache = frc == null && rx == 0 && ry == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (canCache && pixelBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            result = new Rectangle(pixelBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            result.x += ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            result.y += iy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        // couldn't use cache, or didn't have it, so compute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if (isSimple) { // all glyphvectors with no decorations, no layout path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            for (int i = 0, n = 0; i < fComponents.length; i++, n += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                Rectangle pb = tlc.getPixelBounds(frc, locs[n] + rx, locs[n+1] + ry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                if (!pb.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                        result = pb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                        result.add(pb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                result = new Rectangle(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        } else { // draw and test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            final int MARGIN = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            Rectangle2D r2d = getVisualBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            if (lp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                r2d = lp.mapShape(r2d).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            Rectangle bounds = r2d.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            BufferedImage im = new BufferedImage(bounds.width + MARGIN * 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                                 bounds.height + MARGIN * 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                                                 BufferedImage.TYPE_INT_ARGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            Graphics2D g2d = im.createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            g2d.setColor(Color.WHITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            g2d.fillRect(0, 0, im.getWidth(), im.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            g2d.setColor(Color.BLACK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            draw(g2d, rx + MARGIN - bounds.x, ry + MARGIN - bounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            result = computePixelBounds(im);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            result.x -= MARGIN - bounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            result.y -= MARGIN - bounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if (canCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            pixelBounds = new Rectangle(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        result.x += ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        result.y += iy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    static Rectangle computePixelBounds(BufferedImage im) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        int w = im.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        int h = im.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        int l = -1, t = -1, r = w, b = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            // get top
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            int[] buf = new int[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            loop: while (++t < h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                im.getRGB(0, t, buf.length, 1, buf, 0, w); // w ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                for (int i = 0; i < buf.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    if (buf[i] != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                        break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        // get bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            int[] buf = new int[w];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            loop: while (--b > t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                im.getRGB(0, b, buf.length, 1, buf, 0, w); // w ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                for (int i = 0; i < buf.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    if (buf[i] != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            ++b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        // get left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            loop: while (++l < r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                for (int i = t; i < b; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    int v = im.getRGB(l, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    if (v != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                        break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        // get right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            loop: while (--r > l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                for (int i = t; i < b; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    int v = im.getRGB(r, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    if (v != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                        break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            ++r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        return new Rectangle(l, t, r-l, b-t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    private abstract static class Function {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        abstract float computeFunction(TextLine line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                                       int componentIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                                       int indexInArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    private static Function fgPosAdvF = new Function() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        float computeFunction(TextLine line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                              int componentIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                              int indexInArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            TextLineComponent tlc = line.fComponents[componentIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                int vi = line.getComponentVisualIndex(componentIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return line.locs[vi * 2] + tlc.getCharX(indexInArray) + tlc.getCharAdvance(indexInArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    private static Function fgAdvanceF = new Function() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        float computeFunction(TextLine line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                              int componentIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                              int indexInArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            TextLineComponent tlc = line.fComponents[componentIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            return tlc.getCharAdvance(indexInArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    private static Function fgXPositionF = new Function() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        float computeFunction(TextLine line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                              int componentIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                              int indexInArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                int vi = line.getComponentVisualIndex(componentIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            TextLineComponent tlc = line.fComponents[componentIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            return line.locs[vi * 2] + tlc.getCharX(indexInArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    private static Function fgYPositionF = new Function() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        float computeFunction(TextLine line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                              int componentIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                              int indexInArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            TextLineComponent tlc = line.fComponents[componentIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            float charPos = tlc.getCharY(indexInArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            // charPos is relative to the component - adjust for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            // baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            return charPos + line.getComponentShift(componentIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public int characterCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        return fCharsLimit - fCharsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    public boolean isDirectionLTR() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        return fIsDirectionLTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    public TextLineMetrics getMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return fMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    public int visualToLogical(int visualIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        if (fCharLogicalOrder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            return visualIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        if (fCharVisualOrder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            fCharVisualOrder = BidiUtils.createInverseMap(fCharLogicalOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return fCharVisualOrder[visualIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public int logicalToVisual(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        return (fCharLogicalOrder == null)?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            logicalIndex : fCharLogicalOrder[logicalIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    public byte getCharLevel(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        return fCharLevels==null? 0 : fCharLevels[logicalIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    public boolean isCharLTR(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        return (getCharLevel(logicalIndex) & 0x1) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public int getCharType(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        return Character.getType(fChars[logicalIndex + fCharsStart]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    public boolean isCharSpace(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        return Character.isSpaceChar(fChars[logicalIndex + fCharsStart]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    public boolean isCharWhitespace(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        return Character.isWhitespace(fChars[logicalIndex + fCharsStart]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    public float getCharAngle(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        return getCoreMetricsAt(logicalIndex).italicAngle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    public CoreMetrics getCoreMetricsAt(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        if (logicalIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            throw new IllegalArgumentException("Negative logicalIndex.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (logicalIndex > fCharsLimit - fCharsStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            throw new IllegalArgumentException("logicalIndex too large.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        int currentTlc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        int tlcStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        int tlcLimit = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            tlcLimit += fComponents[currentTlc].getNumCharacters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            if (tlcLimit > logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            ++currentTlc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            tlcStart = tlcLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        } while(currentTlc < fComponents.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        return fComponents[currentTlc].getCoreMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public float getCharAscent(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        return getCoreMetricsAt(logicalIndex).ascent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    public float getCharDescent(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        return getCoreMetricsAt(logicalIndex).descent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    public float getCharShift(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        return getCoreMetricsAt(logicalIndex).ssOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    private float applyFunctionAtIndex(int logicalIndex, Function f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        if (logicalIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            throw new IllegalArgumentException("Negative logicalIndex.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        int tlcStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        for(int i=0; i < fComponents.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            int tlcLimit = tlcStart + fComponents[i].getNumCharacters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            if (tlcLimit > logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                return f.computeFunction(this, i, logicalIndex - tlcStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                tlcStart = tlcLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        throw new IllegalArgumentException("logicalIndex too large.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public float getCharAdvance(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        return applyFunctionAtIndex(logicalIndex, fgAdvanceF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    public float getCharXPosition(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        return applyFunctionAtIndex(logicalIndex, fgXPositionF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    public float getCharYPosition(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        return applyFunctionAtIndex(logicalIndex, fgYPositionF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    public float getCharLinePosition(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        return getCharXPosition(logicalIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    public float getCharLinePosition(int logicalIndex, boolean leading) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        Function f = isCharLTR(logicalIndex) == leading ? fgXPositionF : fgPosAdvF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        return applyFunctionAtIndex(logicalIndex, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    public boolean caretAtOffsetIsValid(int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        if (offset < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            throw new IllegalArgumentException("Negative offset.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        int tlcStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        for(int i=0; i < fComponents.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            int tlcLimit = tlcStart + fComponents[i].getNumCharacters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            if (tlcLimit > offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                return fComponents[i].caretAtOffsetIsValid(offset-tlcStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                tlcStart = tlcLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        throw new IllegalArgumentException("logicalIndex too large.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * map a component visual index to the logical index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    private int getComponentLogicalIndex(int vi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        if (fComponentVisualOrder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            return vi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        return fComponentVisualOrder[vi];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * map a component logical index to the visual index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    private int getComponentVisualIndex(int li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        if (fComponentVisualOrder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                return li;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        for (int i = 0; i < fComponentVisualOrder.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                if (fComponentVisualOrder[i] == li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        throw new IndexOutOfBoundsException("bad component index: " + li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    public Rectangle2D getCharBounds(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        if (logicalIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            throw new IllegalArgumentException("Negative logicalIndex.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        int tlcStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        for (int i=0; i < fComponents.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            int tlcLimit = tlcStart + fComponents[i].getNumCharacters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            if (tlcLimit > logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                TextLineComponent tlc = fComponents[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                int indexInTlc = logicalIndex - tlcStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                Rectangle2D chBounds = tlc.getCharVisualBounds(indexInTlc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                        int vi = getComponentVisualIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                chBounds.setRect(chBounds.getX() + locs[vi * 2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                                 chBounds.getY() + locs[vi * 2 + 1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                                 chBounds.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                                 chBounds.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                return chBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                tlcStart = tlcLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        throw new IllegalArgumentException("logicalIndex too large.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    private float getComponentShift(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        CoreMetrics cm = fComponents[index].getCoreMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        return cm.effectiveBaselineOffset(fBaselineOffsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    public void draw(Graphics2D g2, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        if (lp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            for (int i = 0, n = 0; i < fComponents.length; i++, n += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                tlc.draw(g2, locs[n] + x, locs[n+1] + y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            AffineTransform oldTx = g2.getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            Point2D.Float pt = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            for (int i = 0, n = 0; i < fComponents.length; i++, n += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                lp.pathToPoint(locs[n], locs[n+1], false, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                pt.x += x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                pt.y += y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                AffineTransform at = tlc.getBaselineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                if (at != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    g2.translate(pt.x - at.getTranslateX(), pt.y - at.getTranslateY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                    g2.transform(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                    tlc.draw(g2, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                    g2.setTransform(oldTx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                    tlc.draw(g2, pt.x, pt.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * Return the union of the visual bounds of all the components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * This incorporates the path.  It does not include logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * bounds (used by carets).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    public Rectangle2D getVisualBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        Rectangle2D result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        for (int i = 0, n = 0; i < fComponents.length; i++, n += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            Rectangle2D r = tlc.getVisualBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            Point2D.Float pt = new Point2D.Float(locs[n], locs[n+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            if (lp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                r.setRect(r.getMinX() + pt.x, r.getMinY() + pt.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                          r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                lp.pathToPoint(pt, false, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                AffineTransform at = tlc.getBaselineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                if (at != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                    AffineTransform tx = AffineTransform.getTranslateInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                        (pt.x - at.getTranslateX(), pt.y - at.getTranslateY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                    tx.concatenate(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    r = tx.createTransformedShape(r).getBounds2D();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                    r.setRect(r.getMinX() + pt.x, r.getMinY() + pt.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                              r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                result = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                result.add(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            result = new Rectangle2D.Float(Float.MAX_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    public Rectangle2D getItalicBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        float left = Float.MAX_VALUE, right = -Float.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        float top = Float.MAX_VALUE, bottom = -Float.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        for (int i=0, n = 0; i < fComponents.length; i++, n += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            Rectangle2D tlcBounds = tlc.getItalicBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            float x = locs[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            float y = locs[n+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            left = Math.min(left, x + (float)tlcBounds.getX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            right = Math.max(right, x + (float)tlcBounds.getMaxX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            top = Math.min(top, y + (float)tlcBounds.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            bottom = Math.max(bottom, y + (float)tlcBounds.getMaxY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        return new Rectangle2D.Float(left, top, right-left, bottom-top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    public Shape getOutline(AffineTransform tx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        GeneralPath dstShape = new GeneralPath(GeneralPath.WIND_NON_ZERO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        for (int i=0, n = 0; i < fComponents.length; i++, n += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            dstShape.append(tlc.getOutline(locs[n], locs[n+1]), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        if (tx != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            dstShape.transform(tx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        return dstShape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        return (fComponents.length << 16) ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                    (fComponents[0].hashCode() << 3) ^ (fCharsLimit-fCharsStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        StringBuilder buf = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        for (int i = 0; i < fComponents.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            buf.append(fComponents[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * Create a TextLine from the text.  The Font must be able to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * display all of the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * attributes==null is equivalent to using an empty Map for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    public static TextLine fastCreateTextLine(FontRenderContext frc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                                              char[] chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                                              Font font,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                                              CoreMetrics lm,
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   908
                                              Map<? extends Attribute, ?> attributes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        boolean isDirectionLTR = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        byte[] levels = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        int[] charsLtoV = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        Bidi bidi = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        int characterCount = chars.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        boolean requiresBidi = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        byte[] embs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        AttributeValues values = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            values = AttributeValues.fromMap(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            if (values.getRunDirection() >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                isDirectionLTR = values.getRunDirection() == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                requiresBidi = !isDirectionLTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            if (values.getBidiEmbedding() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                requiresBidi = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                byte level = (byte)values.getBidiEmbedding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                embs = new byte[characterCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                for (int i = 0; i < embs.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                    embs[i] = level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        // dlf: get baseRot from font for now???
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        if (!requiresBidi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            requiresBidi = Bidi.requiresBidi(chars, 0, chars.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        if (requiresBidi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
          int bidiflags = values == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
              ? Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
              : values.getRunDirection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
          bidi = new Bidi(chars, 0, embs, 0, chars.length, bidiflags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
          if (!bidi.isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
              levels = BidiUtils.getLevels(bidi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
              int[] charsVtoL = BidiUtils.createVisualToLogicalMap(levels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
              charsLtoV = BidiUtils.createInverseMap(charsVtoL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
              isDirectionLTR = bidi.baseIsLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        Decoration decorator = Decoration.getDecoration(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        int layoutFlags = 0; // no extra info yet, bidi determines run and line direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        TextLabelFactory factory = new TextLabelFactory(frc, chars, bidi, layoutFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        TextLineComponent[] components = new TextLineComponent[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        components = createComponentsOnRun(0, chars.length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                                           chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                                           charsLtoV, levels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                                           factory, font, lm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                                           frc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                                           decorator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                                           components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                                           0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        int numComponents = components.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        while (components[numComponents-1] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            numComponents -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        if (numComponents != components.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            TextLineComponent[] temp = new TextLineComponent[numComponents];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            System.arraycopy(components, 0, temp, 0, numComponents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            components = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        return new TextLine(frc, components, lm.baselineOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                            chars, 0, chars.length, charsLtoV, levels, isDirectionLTR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    private static TextLineComponent[] expandArray(TextLineComponent[] orig) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        TextLineComponent[] newComponents = new TextLineComponent[orig.length + 8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        System.arraycopy(orig, 0, newComponents, 0, orig.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        return newComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * Returns an array in logical order of the TextLineComponents on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * the text in the given range, with the given attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    public static TextLineComponent[] createComponentsOnRun(int runStart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                                                            int runLimit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                                                            char[] chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                                                            int[] charsLtoV,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                                                            byte[] levels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                                                            TextLabelFactory factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                                                            Font font,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                                                            CoreMetrics cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                                                            FontRenderContext frc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                                                            Decoration decorator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                                                            TextLineComponent[] components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                                                            int numComponents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        int pos = runStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            int chunkLimit = firstVisualChunk(charsLtoV, levels, pos, runLimit); // <= displayLimit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                int startPos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                int lmCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                if (cm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                    LineMetrics lineMetrics = font.getLineMetrics(chars, startPos, chunkLimit, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                    cm = CoreMetrics.get(lineMetrics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                    lmCount = lineMetrics.getNumChars();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                    lmCount = (chunkLimit-startPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                TextLineComponent nextComponent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                    factory.createExtended(font, cm, decorator, startPos, startPos + lmCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                ++numComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                if (numComponents >= components.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                    components = expandArray(components);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                components[numComponents-1] = nextComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                pos += lmCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            } while (pos < chunkLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        } while (pos < runLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        return components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * Returns an array (in logical order) of the TextLineComponents representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * the text.  The components are both logically and visually contiguous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    public static TextLineComponent[] getComponents(StyledParagraph styledParagraph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                                                    char[] chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                                                    int textStart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                                                    int textLimit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                                                    int[] charsLtoV,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                                                    byte[] levels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                                                    TextLabelFactory factory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        FontRenderContext frc = factory.getFontRenderContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        int numComponents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        TextLineComponent[] tempComponents = new TextLineComponent[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        int pos = textStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            int runLimit = Math.min(styledParagraph.getRunLimit(pos), textLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            Decoration decorator = styledParagraph.getDecorationAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            Object graphicOrFont = styledParagraph.getFontOrGraphicAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            if (graphicOrFont instanceof GraphicAttribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                // AffineTransform baseRot = styledParagraph.getBaselineRotationAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                // !!! For now, let's assign runs of text with both fonts and graphic attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                // a null rotation (e.g. the baseline rotation goes away when a graphic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                // is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                AffineTransform baseRot = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                GraphicAttribute graphicAttribute = (GraphicAttribute) graphicOrFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                    int chunkLimit = firstVisualChunk(charsLtoV, levels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                                    pos, runLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                    GraphicComponent nextGraphic =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                        new GraphicComponent(graphicAttribute, decorator, charsLtoV, levels, pos, chunkLimit, baseRot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                    pos = chunkLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                    ++numComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                    if (numComponents >= tempComponents.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                        tempComponents = expandArray(tempComponents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                    tempComponents[numComponents-1] = nextGraphic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                } while(pos < runLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                Font font = (Font) graphicOrFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                tempComponents = createComponentsOnRun(pos, runLimit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                                                        chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                                                        charsLtoV, levels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                                                        factory, font, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                                                        frc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                                                        decorator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                                                        tempComponents,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                                                        numComponents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                pos = runLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                numComponents = tempComponents.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                while (tempComponents[numComponents-1] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                    numComponents -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        } while (pos < textLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        TextLineComponent[] components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        if (tempComponents.length == numComponents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            components = tempComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            components = new TextLineComponent[numComponents];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            System.arraycopy(tempComponents, 0, components, 0, numComponents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        return components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * Create a TextLine from the Font and character data over the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * range.  The range is relative to both the StyledParagraph and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * character array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    public static TextLine createLineFromText(char[] chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                                              StyledParagraph styledParagraph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                                              TextLabelFactory factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                                              boolean isDirectionLTR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                                              float[] baselineOffsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        factory.setLineContext(0, chars.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        Bidi lineBidi = factory.getLineBidi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        int[] charsLtoV = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        byte[] levels = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        if (lineBidi != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            levels = BidiUtils.getLevels(lineBidi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            int[] charsVtoL = BidiUtils.createVisualToLogicalMap(levels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            charsLtoV = BidiUtils.createInverseMap(charsVtoL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        TextLineComponent[] components =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            getComponents(styledParagraph, chars, 0, chars.length, charsLtoV, levels, factory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        return new TextLine(factory.getFontRenderContext(), components, baselineOffsets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                            chars, 0, chars.length, charsLtoV, levels, isDirectionLTR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * Compute the components order from the given components array and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * logical-to-visual character mapping.  May return null if canonical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    private static int[] computeComponentOrder(TextLineComponent[] components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                                               int[] charsLtoV) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
         * Create a visual ordering for the glyph sets.  The important thing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
         * here is that the values have the proper rank with respect to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
         * each other, not the exact values.  For example, the first glyph
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
         * set that appears visually should have the lowest value.  The last
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
         * should have the highest value.  The values are then normalized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
         * to map 1-1 with positions in glyphs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        int[] componentOrder = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        if (charsLtoV != null && components.length > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            componentOrder = new int[components.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            int gStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            for (int i = 0; i < components.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                componentOrder[i] = charsLtoV[gStart];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                gStart += components[i].getNumCharacters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            componentOrder = BidiUtils.createContiguousOrder(componentOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            componentOrder = BidiUtils.createInverseMap(componentOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        return componentOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * Create a TextLine from the text.  chars is just the text in the iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    public static TextLine standardCreateTextLine(FontRenderContext frc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                                                  AttributedCharacterIterator text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                                                  char[] chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                                                  float[] baselineOffsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        StyledParagraph styledParagraph = new StyledParagraph(text, chars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        Bidi bidi = new Bidi(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        if (bidi.isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            bidi = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        int layoutFlags = 0; // no extra info yet, bidi determines run and line direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        TextLabelFactory factory = new TextLabelFactory(frc, chars, bidi, layoutFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        boolean isDirectionLTR = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        if (bidi != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            isDirectionLTR = bidi.baseIsLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        return createLineFromText(chars, styledParagraph, factory, isDirectionLTR, baselineOffsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * A utility to get a range of text that is both logically and visually
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * contiguous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * If the entire range is ok, return limit, otherwise return the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     * directional change after start.  We could do better than this, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * it doesn't seem worth it at the moment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    private static int firstVisualChunk(int order[], byte direction[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                                        int start, int limit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        if (order != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            int min = order[start];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            int max = order[start];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            int count = limit - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            for (int i = start + 1; i < limit; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                min = Math.min(min, order[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                max = Math.max(max, order[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                if (max - min >= count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                    if (direction != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                        byte baseLevel = direction[start];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                        for (int j = start + 1; j < i; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                            if (direction[j] != baseLevel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                                return j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                    return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        return limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * When this returns, the ACI's current position will be at the start of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     * first run which does NOT contain a GraphicAttribute.  If no such run exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * the ACI's position will be at the end, and this method will return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    static boolean advanceToFirstFont(AttributedCharacterIterator aci) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
  1255
        for (char ch = aci.first();
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
  1256
             ch != CharacterIterator.DONE;
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
  1257
             ch = aci.setIndex(aci.getRunLimit()))
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
  1258
        {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            if (aci.getAttribute(TextAttribute.CHAR_REPLACEMENT) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    static float[] getNormalizedOffsets(float[] baselineOffsets, byte baseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        if (baselineOffsets[baseline] != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            float base = baselineOffsets[baseline];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            float[] temp = new float[baselineOffsets.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            for (int i = 0; i < temp.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                temp[i] = baselineOffsets[i] - base;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            baselineOffsets = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        return baselineOffsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    static Font getFontAtCurrentPos(AttributedCharacterIterator aci) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        Object value = aci.getAttribute(TextAttribute.FONT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            return (Font) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        if (aci.getAttribute(TextAttribute.FAMILY) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            return Font.getFont(aci.getAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        int ch = CodePointIterator.create(aci).next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        if (ch != CodePointIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            FontResolver resolver = FontResolver.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            return resolver.getFont(resolver.getFontIndex(ch), aci.getAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
  /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
   * The new version requires that chunks be at the same level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    private static int firstVisualChunk(int order[], byte direction[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                                        int start, int limit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        if (order != null && direction != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
          byte dir = direction[start];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
          while (++start < limit && direction[start] == dir) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
          return start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        return limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
  /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
   * create a new line with characters between charStart and charLimit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
   * justified using the provided width and ratio.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    public TextLine getJustifiedLine(float justificationWidth, float justifyRatio, int justStart, int justLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        TextLineComponent[] newComponents = new TextLineComponent[fComponents.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        System.arraycopy(fComponents, 0, newComponents, 0, fComponents.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        float leftHang = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        float adv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        float justifyDelta = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        boolean rejustify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            adv = getAdvanceBetween(newComponents, 0, characterCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            // all characters outside the justification range must be in the base direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            // of the layout, otherwise justification makes no sense.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            float justifyAdvance = getAdvanceBetween(newComponents, justStart, justLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            // get the actual justification delta
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            justifyDelta = (justificationWidth - justifyAdvance) * justifyRatio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            // generate an array of GlyphJustificationInfo records to pass to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            // the justifier.  Array is visually ordered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            // get positions that each component will be using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            int[] infoPositions = new int[newComponents.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            int infoCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            for (int visIndex = 0; visIndex < newComponents.length; visIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                    int logIndex = getComponentLogicalIndex(visIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                infoPositions[logIndex] = infoCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                infoCount += newComponents[logIndex].getNumJustificationInfos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            GlyphJustificationInfo[] infos = new GlyphJustificationInfo[infoCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            // get justification infos
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            int compStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            for (int i = 0; i < newComponents.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                TextLineComponent comp = newComponents[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                int compLength = comp.getNumCharacters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                int compLimit = compStart + compLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                if (compLimit > justStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                    int rangeMin = Math.max(0, justStart - compStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                    int rangeMax = Math.min(compLength, justLimit - compStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                    comp.getJustificationInfos(infos, infoPositions[i], rangeMin, rangeMax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                    if (compLimit >= justLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            // records are visually ordered, and contiguous, so start and end are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            // simply the places where we didn't fetch records
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            int infoStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            int infoLimit = infoCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            while (infoStart < infoLimit && infos[infoStart] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                ++infoStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
            while (infoLimit > infoStart && infos[infoLimit - 1] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                --infoLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            // invoke justifier on the records
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            TextJustifier justifier = new TextJustifier(infos, infoStart, infoLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            float[] deltas = justifier.justify(justifyDelta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
            boolean canRejustify = rejustify == false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
            boolean wantRejustify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            boolean[] flags = new boolean[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            // apply justification deltas
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            compStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            for (int i = 0; i < newComponents.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                TextLineComponent comp = newComponents[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                int compLength = comp.getNumCharacters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                int compLimit = compStart + compLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                if (compLimit > justStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                    int rangeMin = Math.max(0, justStart - compStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                    int rangeMax = Math.min(compLength, justLimit - compStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                    newComponents[i] = comp.applyJustificationDeltas(deltas, infoPositions[i] * 2, flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                    wantRejustify |= flags[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                    if (compLimit >= justLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            rejustify = wantRejustify && !rejustify; // only make two passes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
        } while (rejustify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        return new TextLine(frc, newComponents, fBaselineOffsets, fChars, fCharsStart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                            fCharsLimit, fCharLogicalOrder, fCharLevels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                            fIsDirectionLTR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    // return the sum of the advances of text between the logical start and limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    public static float getAdvanceBetween(TextLineComponent[] components, int start, int limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        float advance = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        int tlcStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        for(int i = 0; i < components.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
            TextLineComponent comp = components[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            int tlcLength = comp.getNumCharacters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            int tlcLimit = tlcStart + tlcLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            if (tlcLimit > start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                int measureStart = Math.max(0, start - tlcStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                int measureLimit = Math.min(tlcLength, limit - tlcStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                advance += comp.getAdvanceBetween(measureStart, measureLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                if (tlcLimit >= limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            tlcStart = tlcLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        return advance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    LayoutPathImpl getLayoutPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        return lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
}