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