001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019:
020: package org.apache.batik.gvt.text;
021:
022: import java.awt.Graphics2D;
023: import java.awt.Shape;
024: import java.awt.geom.Point2D;
025: import java.awt.geom.Rectangle2D;
026:
027: import org.apache.batik.gvt.font.GVTGlyphMetrics;
028: import org.apache.batik.gvt.font.GVTGlyphVector;
029: import org.apache.batik.gvt.font.GVTLineMetrics;
030:
031: /**
032: * Class that performs layout of attributed text strings into
033: * glyph sets paintable by TextPainter instances.
034: * Similar to java.awt.font.TextLayout in function and purpose.
035: * Note that while this utility interface is provided for the convenience of
036: * <tt>TextPainter</tt> implementations, conforming <tt>TextPainter</tt>s
037: * are not required to use this class.
038: * @see java.awt.font.TextLayout
039: * @see org.apache.batik.gvt.TextPainter
040: *
041: * @author <a href="mailto:bill.haneman@ireland.sun.com">Bill Haneman</a>
042: * @version $Id: TextSpanLayout.java 478188 2006-11-22 15:19:17Z dvholten $
043: */
044: public interface TextSpanLayout {
045:
046: int DECORATION_UNDERLINE = 0x1;
047: int DECORATION_STRIKETHROUGH = 0x2;
048: int DECORATION_OVERLINE = 0x4;
049: int DECORATION_ALL = DECORATION_UNDERLINE | DECORATION_OVERLINE
050: | DECORATION_STRIKETHROUGH;
051:
052: /**
053: * Paints the specified text layout using the
054: * specified Graphics2D and rendering context.
055: * @param g2d the Graphics2D to use
056: */
057: void draw(Graphics2D g2d);
058:
059: /**
060: * Returns the outline of the specified decorations on the glyphs,
061: * transformed by an AffineTransform.
062: * @param decorationType an integer indicating the type(s) of decorations
063: * included in this shape. May be the result of "OR-ing" several
064: * values together:
065: * e.g. <tt>DECORATION_UNDERLINE | DECORATION_STRIKETHROUGH</tt>
066: */
067: Shape getDecorationOutline(int decorationType);
068:
069: /**
070: * Returns the rectangular bounds of the completed glyph layout.
071: * This includes stroking information, this does not include
072: * deocrations.
073: */
074: Rectangle2D getBounds2D();
075:
076: /**
077: * Returns the bounds of the geometry (this is always the bounds
078: * of the outline).
079: */
080: Rectangle2D getGeometricBounds();
081:
082: /**
083: * Returns the outline of the completed glyph layout, transformed
084: * by an AffineTransform.
085: */
086: Shape getOutline();
087:
088: /**
089: * Returns the current text position at the completion
090: * of glyph layout.
091: * (This is the position that should be used for positioning
092: * adjacent layouts.)
093: */
094: Point2D getAdvance2D();
095:
096: /**
097: * Returns the advance between each glyph in text progression direction.
098: */
099: float[] getGlyphAdvances();
100:
101: /**
102: * Returns the Metrics for a particular glyph.
103: */
104: GVTGlyphMetrics getGlyphMetrics(int glyphIndex);
105:
106: /**
107: * Returns the Line metrics for this text span.
108: */
109: GVTLineMetrics getLineMetrics();
110:
111: Point2D getTextPathAdvance();
112:
113: /**
114: * Returns the current text position at the completion beginning
115: * of glyph layout, before the application of explicit
116: * glyph positioning attributes.
117: */
118: Point2D getOffset();
119:
120: /**
121: * Sets the scaling factor to use for string. if ajdSpacing is
122: * true then only the spacing between glyphs will be adjusted
123: * otherwise the glyphs and the spaces between them will be
124: * adjusted.
125: * @param xScale Scale factor to apply in X direction.
126: * @param yScale Scale factor to apply in Y direction.
127: * @param adjSpacing True if only spaces should be adjusted.
128: */
129: void setScale(float xScale, float yScale, boolean adjSpacing);
130:
131: /**
132: * Sets the text position used for the implicit origin
133: * of glyph layout. Ignored if multiple explicit glyph
134: * positioning attributes are present in ACI
135: * (e.g. if the aci has multiple X or Y values).
136: */
137: void setOffset(Point2D offset);
138:
139: /**
140: * Returns a Shape which encloses the currently selected glyphs
141: * as specified by glyph indices <tt>begin</tt> and <tt>end</tt>.
142: * @param beginCharIndex the index of the first glyph in the contiguous
143: * selection.
144: * @param endCharIndex the index of the last glyph in the contiguous
145: * selection.
146: */
147: Shape getHighlightShape(int beginCharIndex, int endCharIndex);
148:
149: /**
150: * Perform hit testing for coordinate at x, y.
151: * @return a TextHit object encapsulating the character index for
152: * successful hits and whether the hit is on the character
153: * leading edge.
154: * @param x the x coordinate of the point to be tested.
155: * @param y the y coordinate of the point to be tested.
156: */
157: TextHit hitTestChar(float x, float y);
158:
159: /**
160: * Returns true if the advance direction of this text is vertical.
161: */
162: boolean isVertical();
163:
164: /**
165: * Returns true if this layout in on a text path.
166: */
167: boolean isOnATextPath();
168:
169: /**
170: * Returns the number of glyphs in this layout.
171: */
172: int getGlyphCount();
173:
174: /**
175: * Returns the number of chars represented by the glyphs within the
176: * specified range.
177: * @param startGlyphIndex The index of the first glyph in the range.
178: * @param endGlyphIndex The index of the last glyph in the range.
179: * @return The number of chars.
180: */
181: int getCharacterCount(int startGlyphIndex, int endGlyphIndex);
182:
183: /**
184: * Returns the glyph index of the glyph that has the specified char index.
185: *
186: * @param charIndex The original index of the character in the text node's
187: * text string.
188: * @return The index of the matching glyph in this layout's glyph vector,
189: * or -1 if a matching glyph could not be found.
190: */
191: int getGlyphIndex(int charIndex);
192:
193: /**
194: * Returns true if the text direction in this layout is from left to right.
195: */
196: boolean isLeftToRight();
197:
198: /**
199: * Return true is the character index is represented by glyphs
200: * in this layout.
201: *
202: * @param index index of the character in the ACI.
203: * @return true if the layout represents that character.
204: */
205: boolean hasCharacterIndex(int index);
206:
207: /**
208: * Return the glyph vector asociated to this layout.
209: *
210: * @return glyph vector
211: */
212: GVTGlyphVector getGlyphVector();
213:
214: /**
215: * Return the rotation angle applied to the
216: * character.
217: *
218: * @param index index of the character in the ACI
219: * @return rotation angle
220: */
221: double getComputedOrientationAngle(int index);
222:
223: /**
224: * Return true if this text run represents
225: * an alt glyph.
226: */
227: boolean isAltGlyph();
228: }
|