001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /*
018: * @author Oleg V. Khaschansky
019: * @version $Revision$
020: */
021:
022: package org.apache.harmony.awt.gl.font;
023:
024: import java.awt.Graphics2D;
025: import java.awt.Shape;
026: import java.awt.font.TextHitInfo;
027: import java.awt.geom.Rectangle2D;
028:
029: /**
030: * Abstract class which represents the segment of the text with constant attributes
031: * running in one direction (i.e. constant level).
032: */
033: public abstract class TextRunSegment implements Cloneable {
034: float x; // Calculated x location of this segment on the screen
035: float y; // Calculated y location of this segment on the screen
036:
037: BasicMetrics metrics; // Metrics of this text run segment
038: TextDecorator.Decoration decoration; // Underline, srikethrough, etc.
039: Rectangle2D logicalBounds = null; // Logical bounding box for the segment
040: Rectangle2D visualBounds = null; // Visual bounding box for the segment
041:
042: /**
043: * Returns start index of the segment
044: * @return start index
045: */
046: abstract int getStart();
047:
048: /**
049: * Returns end index of the segment
050: * @return end index
051: */
052: abstract int getEnd();
053:
054: /**
055: * Returns the number of characters in the segment
056: * @return number of characters
057: */
058: abstract int getLength();
059:
060: /**
061: * Renders this text run segment
062: * @param g2d - graphics to render to
063: * @param xOffset - X offset from the graphics origin to the
064: * origin of the text layout
065: * @param yOffset - Y offset from the graphics origin to the
066: * origin of the text layout
067: */
068: abstract void draw(Graphics2D g2d, float xOffset, float yOffset);
069:
070: /**
071: * Creates black box bounds shape for the specified range
072: * @param start - range sart
073: * @param limit - range end
074: * @return black box bounds shape
075: */
076: abstract Shape getCharsBlackBoxBounds(int start, int limit);
077:
078: /**
079: * Returns the outline shape
080: * @return outline
081: */
082: abstract Shape getOutline();
083:
084: /**
085: * Returns visual bounds of this segment
086: * @return visual bounds
087: */
088: abstract Rectangle2D getVisualBounds();
089:
090: /**
091: * Returns logical bounds of this segment
092: * @return logical bounds
093: */
094: abstract Rectangle2D getLogicalBounds();
095:
096: /**
097: * Calculates advance of the segment
098: * @return advance
099: */
100: abstract float getAdvance();
101:
102: /**
103: * Calculates advance delta between two characters
104: * @param start - 1st position
105: * @param end - 2nd position
106: * @return advance increment between specified positions
107: */
108: abstract float getAdvanceDelta(int start, int end);
109:
110: /**
111: * Calculates index of the character which advance is equal to
112: * the given. If the given advance is greater then the segment
113: * advance it returns the position after the last character.
114: * @param advance - given advance
115: * @param start - character, from which to start measuring advance
116: * @return character index
117: */
118: abstract int getCharIndexFromAdvance(float advance, int start);
119:
120: /**
121: * Checks if the character doesn't contribute to the text advance
122: * @param index - character index
123: * @return true if the character has zero advance
124: */
125: abstract boolean charHasZeroAdvance(int index);
126:
127: /**
128: * Calculates position of the character on the screen
129: * @param index - character index
130: * @return X coordinate of the character position
131: */
132: abstract float getCharPosition(int index);
133:
134: /**
135: * Returns the advance of the individual character
136: * @param index - character index
137: * @return character advance
138: */
139: abstract float getCharAdvance(int index);
140:
141: /**
142: * Creates text hit info from the hit position
143: * @param x - X coordinate relative to the origin of the layout
144: * @param y - Y coordinate relative to the origin of the layout
145: * @return hit info
146: */
147: abstract TextHitInfo hitTest(float x, float y);
148:
149: /**
150: * Collects justification information into JustificationInfo object
151: * @param jInfo - JustificationInfo object
152: */
153: abstract void updateJustificationInfo(
154: TextRunBreaker.JustificationInfo jInfo);
155:
156: /**
157: * Performs justification of the segment.
158: * Updates positions of individual characters.
159: * @param jInfos - justification information, gathered by the previous passes
160: * @return amount of growth or shrink of the segment
161: */
162: abstract float doJustification(
163: TextRunBreaker.JustificationInfo jInfos[]);
164:
165: @Override
166: public abstract Object clone();
167: }
|