jdk/src/share/classes/sun/font/ExtendedTextLabel.java
author mchung
Tue, 29 Sep 2009 16:03:03 -0700
changeset 3938 ef327bd847c0
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes Summary: Replace calls to Logger with sun.util.logging.PlatformLogger Reviewed-by: prr, art, alexp, dcherepanov, igor, dav, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2003 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *
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
package sun.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.font.GlyphJustificationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.font.LineMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * An extension of TextLabel that maintains information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * about characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public abstract class ExtendedTextLabel extends TextLabel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                            implements TextLineComponent{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
   * Return the number of characters represented by this label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  public abstract int getNumCharacters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
   * Return the line metrics for all text in this label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  public abstract CoreMetrics getCoreMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
   * Return the x location of the character at the given logical index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  public abstract float getCharX(int logicalIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
   * Return the y location of the character at the given logical index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  public abstract float getCharY(int logicalIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
   * Return the advance of the character at the given logical index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  public abstract float getCharAdvance(int logicalIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
   * Return the visual bounds of the character at the given logical index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
   * This bounds encloses all the pixels of the character when the label is rendered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
   * at x, y.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  public abstract Rectangle2D getCharVisualBounds(int logicalIndex, float x, float y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
   * Return the visual index of the character at the given logical index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  public abstract int logicalToVisual(int logicalIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
   * Return the logical index of the character at the given visual index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  public abstract int visualToLogical(int visualIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
   * Return the logical index of the character, starting with the character at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
   * logicalStart, whose accumulated advance exceeds width.  If the advances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
   * all characters do not exceed width, return getNumCharacters.  If width is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
   * less than zero, return logicalStart - 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  public abstract int getLineBreakIndex(int logicalStart, float width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
   * Return the accumulated advances of all characters between logicalStart and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
   * logicalLimit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  public abstract float getAdvanceBetween(int logicalStart, int logicalLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
   * Return whether a caret can exist on the leading edge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
   * character at offset.  If the character is part of a ligature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
   * (for example) a caret may not be appropriate at offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  public abstract boolean caretAtOffsetIsValid(int offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
   * A convenience overload of getCharVisualBounds that defaults the label origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
   * to 0, 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
  public Rectangle2D getCharVisualBounds(int logicalIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    return getCharVisualBounds(logicalIndex, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  public abstract TextLineComponent getSubset(int start, int limit, int dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
   * Return the number of justification records this uses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  public abstract int getNumJustificationInfos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
   * Return GlyphJustificationInfo objects for the characters between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
   * charStart and charLimit, starting at offset infoStart.  Infos
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
   * will be in visual order.  All positions between infoStart and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
   * getNumJustificationInfos will be set.  If a position corresponds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
   * to a character outside the provided range, it is set to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  public abstract void getJustificationInfos(GlyphJustificationInfo[] infos, int infoStart, int charStart, int charLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
   * Apply deltas to the data in this component, starting at offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
   * deltaStart, and return the new component.  There are two floats
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
   * for each justification info, for a total of 2 * getNumJustificationInfos.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
   * The first delta is the left adjustment, the second is the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
   * adjustment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
   * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
   * If flags[0] is true on entry, rejustification is allowed.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
   * the new component requires rejustification (ligatures were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
   * formed or split), flags[0] will be set on exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  public abstract TextLineComponent applyJustificationDeltas(float[] deltas, int deltaStart, boolean[] flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}