2 * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
\r
4 * The program is provided "as is" without any warranty express or
\r
5 * implied, including the warranty of non-infringement and the implied
\r
6 * warranties of merchantibility and fitness for a particular purpose.
\r
7 * IBM will not be liable for any damages suffered by you as a result
\r
8 * of using the Program. In no event will IBM be liable for any
\r
9 * special, indirect or consequential damages or lost profits even if
\r
10 * IBM has been advised of the possibility of their occurrence. IBM
\r
11 * will not be liable for any third party claims against you.
\r
16 A line of text, possibly containing tab-segments.
\r
19 package com.ibm.richtext.textformat;
\r
21 import java.awt.Color;
\r
22 import java.awt.Rectangle;
\r
25 import java.awt.Graphics2D;
\r
29 import com.ibm.richtext.textlayout.Graphics2D;
\r
32 import com.ibm.richtext.styledtext.MConstText;
\r
34 abstract class LayoutInfo
\r
36 static final String COPYRIGHT =
\r
37 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
38 private int fCharStart; // offset in text to start of line (was fStart)
\r
39 // neg. values indicate distance from end of text
\r
40 private int fGraphicStart; // min pixel offset in fill direction
\r
41 // negative values indicate distance from bottom of text view
\r
44 These methods are for storing Layouts in a gap-storage,
\r
45 relative to either the start of end of text. See AsyncFormatter.
\r
47 If you just want absolute (that is, start-relative) char and
\r
48 graphic starts, don't make them end-relative.
\r
51 public final int getCharStart(int lengthBasis) {
\r
53 if (fCharStart >= 0) {
\r
57 return lengthBasis + fCharStart;
\r
61 public final int getGraphicStart(int graphicBasis) {
\r
63 if (fGraphicStart >= 0) {
\r
64 return fGraphicStart;
\r
67 return graphicBasis + fGraphicStart;
\r
71 public final void setCharStart(int beginningRelativeStart) {
\r
73 if (beginningRelativeStart < 0) {
\r
74 throw new IllegalArgumentException("charStart must be nonnegavitve");
\r
76 fCharStart = beginningRelativeStart;
\r
79 public final void setGraphicStart(int beginningRelativeStart) {
\r
81 if (beginningRelativeStart < 0) {
\r
82 throw new IllegalArgumentException("charStart must be nonnegavitve");
\r
84 fGraphicStart = beginningRelativeStart;
\r
87 public final void makeRelativeToBeginning(int lengthBasis,
\r
90 if (lengthBasis < 0 || graphicBasis < 0) {
\r
91 throw new IllegalArgumentException("Bases must be positive.");
\r
93 if (fCharStart >= 0 || fGraphicStart >= 0) {
\r
94 throw new Error("Already start-relative.");
\r
97 fCharStart += lengthBasis;
\r
98 fGraphicStart += graphicBasis;
\r
101 public final void makeRelativeToEnd(int lengthBasis,
\r
102 int graphicBasis) {
\r
104 if (lengthBasis < 0 || graphicBasis < 0) {
\r
105 throw new IllegalArgumentException("Bases must be positive.");
\r
107 if (fCharStart < 0 || fGraphicStart < 0) {
\r
108 throw new Error("Already end-relative.");
\r
111 fCharStart -= lengthBasis;
\r
112 fGraphicStart -= graphicBasis;
\r
116 public abstract int getCharLength();
\r
117 public abstract int getAscent();
\r
118 public abstract int getDescent();
\r
119 public abstract int getLeading();
\r
121 public abstract int getVisibleAdvance();
\r
122 public abstract int getTotalAdvance();
\r
123 public abstract int getLeadingMargin();
\r
125 public abstract boolean isLeftToRight();
\r
127 public int getHeight() {
\r
129 return getAscent()+getDescent()+getLeading();
\r
133 * Draws text with highlighting.
\r
135 public void renderWithHighlight(int lengthBasis,
\r
140 TextOffset selStart,
\r
141 TextOffset selStop,
\r
142 Color highlightColor)
\r
146 /** Use layout information to render the line at x, y.*/
\r
148 public void render(int lengthBasis,
\r
156 public void renderCaret(MConstText text,
\r
163 Color strongCaretColor,
\r
164 Color weakCaretColor)
\r
169 * Given a point within this line, return the character offset corresponding to that point.
\r
171 * @param result. This may be null, in which case a new TextOffset will be allocated.
\r
172 * This object is modified in place, and also returned as the function result.
\r
173 * @param text Text to inspect.
\r
174 * @param lineX Position on this line relative to top left corner of this line.
\r
175 * @param lineY Position on this line relative to top left corner of this line.
\r
177 public abstract TextOffset pixelToOffset(int lengthBasis,
\r
183 public abstract int strongCaretBaselinePosition(int lengthBasis,
\r
187 public abstract Rectangle caretBounds(MConstText text,
\r
194 public abstract int getNextOffset(int lengthBasis,
\r