001: /*
002: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
003: *
004: * The program is provided "as is" without any warranty express or
005: * implied, including the warranty of non-infringement and the implied
006: * warranties of merchantibility and fitness for a particular purpose.
007: * IBM will not be liable for any damages suffered by you as a result
008: * of using the Program. In no event will IBM be liable for any
009: * special, indirect or consequential damages or lost profits even if
010: * IBM has been advised of the possibility of their occurrence. IBM
011: * will not be liable for any third party claims against you.
012: */
013: // Requires Java2
014: /** LayoutInfo
015:
016: A line of text, possibly containing tab-segments.
017: */package com.ibm.richtext.textformat;
018:
019: import java.awt.Color;
020: import java.awt.Rectangle;
021:
022: ///*JDK12IMPORTS
023: import java.awt.Graphics2D; //JDK12IMPORTS*/
024:
025: /*JDK11IMPORTS
026: import com.ibm.richtext.textlayout.Graphics2D;
027: JDK11IMPORTS*/
028:
029: import com.ibm.richtext.styledtext.MConstText;
030:
031: abstract class LayoutInfo {
032: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
033: private int fCharStart; // offset in text to start of line (was fStart)
034: // neg. values indicate distance from end of text
035: private int fGraphicStart; // min pixel offset in fill direction
036:
037: // negative values indicate distance from bottom of text view
038:
039: /*
040: These methods are for storing Layouts in a gap-storage,
041: relative to either the start of end of text. See AsyncFormatter.
042:
043: If you just want absolute (that is, start-relative) char and
044: graphic starts, don't make them end-relative.
045: */
046:
047: public final int getCharStart(int lengthBasis) {
048:
049: if (fCharStart >= 0) {
050: return fCharStart;
051: } else {
052: return lengthBasis + fCharStart;
053: }
054: }
055:
056: public final int getGraphicStart(int graphicBasis) {
057:
058: if (fGraphicStart >= 0) {
059: return fGraphicStart;
060: } else {
061: return graphicBasis + fGraphicStart;
062: }
063: }
064:
065: public final void setCharStart(int beginningRelativeStart) {
066:
067: if (beginningRelativeStart < 0) {
068: throw new IllegalArgumentException(
069: "charStart must be nonnegavitve");
070: }
071: fCharStart = beginningRelativeStart;
072: }
073:
074: public final void setGraphicStart(int beginningRelativeStart) {
075:
076: if (beginningRelativeStart < 0) {
077: throw new IllegalArgumentException(
078: "charStart must be nonnegavitve");
079: }
080: fGraphicStart = beginningRelativeStart;
081: }
082:
083: public final void makeRelativeToBeginning(int lengthBasis,
084: int graphicBasis) {
085:
086: if (lengthBasis < 0 || graphicBasis < 0) {
087: throw new IllegalArgumentException(
088: "Bases must be positive.");
089: }
090: if (fCharStart >= 0 || fGraphicStart >= 0) {
091: throw new Error("Already start-relative.");
092: }
093:
094: fCharStart += lengthBasis;
095: fGraphicStart += graphicBasis;
096: }
097:
098: public final void makeRelativeToEnd(int lengthBasis,
099: int graphicBasis) {
100:
101: if (lengthBasis < 0 || graphicBasis < 0) {
102: throw new IllegalArgumentException(
103: "Bases must be positive.");
104: }
105: if (fCharStart < 0 || fGraphicStart < 0) {
106: throw new Error("Already end-relative.");
107: }
108:
109: fCharStart -= lengthBasis;
110: fGraphicStart -= graphicBasis;
111: }
112:
113: public abstract int getCharLength();
114:
115: public abstract int getAscent();
116:
117: public abstract int getDescent();
118:
119: public abstract int getLeading();
120:
121: public abstract int getVisibleAdvance();
122:
123: public abstract int getTotalAdvance();
124:
125: public abstract int getLeadingMargin();
126:
127: public abstract boolean isLeftToRight();
128:
129: public int getHeight() {
130:
131: return getAscent() + getDescent() + getLeading();
132: }
133:
134: /**
135: * Draws text with highlighting.
136: */
137: public void renderWithHighlight(int lengthBasis, Graphics2D g,
138: int lineBound, int x, int y, TextOffset selStart,
139: TextOffset selStop, Color highlightColor) {
140: }
141:
142: /** Use layout information to render the line at x, y.*/
143:
144: public void render(int lengthBasis, Graphics2D g, int lineBound,
145: int x, int y) {
146: }
147:
148: public void renderCaret(MConstText text, int lengthBasis,
149: Graphics2D g, int lineBound, int x, int y, int charOffset,
150: Color strongCaretColor, Color weakCaretColor) {
151: }
152:
153: /**
154: * Given a point within this line, return the character offset corresponding to that point.
155: *
156: * @param result. This may be null, in which case a new TextOffset will be allocated.
157: * This object is modified in place, and also returned as the function result.
158: * @param text Text to inspect.
159: * @param lineX Position on this line relative to top left corner of this line.
160: * @param lineY Position on this line relative to top left corner of this line.
161: */
162: public abstract TextOffset pixelToOffset(int lengthBasis,
163: TextOffset result, int lineBound, int x, int y);
164:
165: public abstract int strongCaretBaselinePosition(int lengthBasis,
166: int lineBound, int charOffset);
167:
168: public abstract Rectangle caretBounds(MConstText text,
169: int lengthBasis, int lineBound, int charOffset, int x, int y);
170:
171: public abstract int getNextOffset(int lengthBasis, int charOffset,
172: short dir);
173: }
|