KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > gvt > text > TextSpanLayout


1 /*
2
3    Copyright 1999-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17 */

18
19 package org.apache.batik.gvt.text;
20
21 import java.awt.Graphics2D JavaDoc;
22 import java.awt.Shape JavaDoc;
23 import java.awt.geom.Point2D JavaDoc;
24 import java.awt.geom.Rectangle2D JavaDoc;
25
26 import org.apache.batik.gvt.font.GVTGlyphMetrics;
27 import org.apache.batik.gvt.font.GVTGlyphVector;
28
29 /**
30  * Class that performs layout of attributed text strings into
31  * glyph sets paintable by TextPainter instances.
32  * Similar to java.awt.font.TextLayout in function and purpose.
33  * Note that while this utility interface is provided for the convenience of
34  * <tt>TextPainter</tt> implementations, conforming <tt>TextPainter</tt>s
35  * are not required to use this class.
36  * @see java.awt.font.TextLayout
37  * @see org.apache.batik.gvt.TextPainter
38  *
39  * @author <a HREF="mailto:bill.haneman@ireland.sun.com">Bill Haneman</a>
40  * @version $Id: TextSpanLayout.java,v 1.18 2005/03/27 08:58:35 cam Exp $
41  */

42 public interface TextSpanLayout {
43
44     public int DECORATION_UNDERLINE = 0x1;
45     public int DECORATION_STRIKETHROUGH = 0x2;
46     public int DECORATION_OVERLINE = 0x4;
47     public int DECORATION_ALL = DECORATION_UNDERLINE |
48                                 DECORATION_OVERLINE |
49                                 DECORATION_STRIKETHROUGH;
50
51     /**
52      * Paints the specified text layout using the
53      * specified Graphics2D and rendering context.
54      * @param g2d the Graphics2D to use
55      */

56     public void draw(Graphics2D JavaDoc g2d);
57
58     /**
59      * Returns the outline of the specified decorations on the glyphs,
60      * transformed by an AffineTransform.
61      * @param decorationType an integer indicating the type(s) of decorations
62      * included in this shape. May be the result of "OR-ing" several
63      * values together:
64      * e.g. <tt>DECORATION_UNDERLINE | DECORATION_STRIKETHROUGH</tt>
65      */

66     public Shape JavaDoc getDecorationOutline(int decorationType);
67
68     /**
69      * Returns the rectangular bounds of the completed glyph layout.
70      * This includes stroking information, this does not include
71      * deocrations.
72      */

73     public Rectangle2D JavaDoc getBounds2D();
74
75     /**
76      * Returns the bounds of the geometry (this is always the bounds
77      * of the outline).
78      */

79     public Rectangle2D JavaDoc getGeometricBounds();
80
81     /**
82      * Returns the outline of the completed glyph layout, transformed
83      * by an AffineTransform.
84      */

85     public Shape JavaDoc getOutline();
86
87     /**
88      * Returns the current text position at the completion
89      * of glyph layout.
90      * (This is the position that should be used for positioning
91      * adjacent layouts.)
92      */

93     public Point2D JavaDoc getAdvance2D();
94
95     /**
96      * Returns the advance between each glyph in text progression direction.
97      */

98     public float [] getGlyphAdvances();
99
100     /**
101      * Returns the Metrics for a particular glyph.
102      */

103     public GVTGlyphMetrics getGlyphMetrics(int glyphIndex);
104
105     public Point2D JavaDoc getTextPathAdvance();
106
107     /**
108      * Returns the current text position at the completion beginning
109      * of glyph layout, before the application of explicit
110      * glyph positioning attributes.
111      */

112     public Point2D JavaDoc getOffset();
113
114     /**
115      * Sets the scaling factor to use for string. if ajdSpacing is
116      * true then only the spacing between glyphs will be adjusted
117      * otherwise the glyphs and the spaces between them will be
118      * adjusted.
119      * @param xScale Scale factor to apply in X direction.
120      * @param yScale Scale factor to apply in Y direction.
121      * @param adjSpacing True if only spaces should be adjusted.
122      */

123     public void setScale(float xScale, float yScale, boolean adjSpacing);
124
125     /**
126      * Sets the text position used for the implicit origin
127      * of glyph layout. Ignored if multiple explicit glyph
128      * positioning attributes are present in ACI
129      * (e.g. if the aci has multiple X or Y values).
130      */

131     public void setOffset(Point2D JavaDoc offset);
132
133     /**
134      * Returns a Shape which encloses the currently selected glyphs
135      * as specified by glyph indices <tt>begin</tt> and <tt>end</tt>.
136      * @param beginCharIndex the index of the first glyph in the contiguous
137      * selection.
138      * @param endCharIndex the index of the last glyph in the contiguous
139      * selection.
140      */

141      public Shape JavaDoc getHighlightShape(int beginCharIndex, int endCharIndex);
142
143     /**
144      * Perform hit testing for coordinate at x, y.
145      * @return a TextHit object encapsulating the character index for
146      * successful hits and whether the hit is on the character
147      * leading edge.
148      * @param x the x coordinate of the point to be tested.
149      * @param y the y coordinate of the point to be tested.
150      */

151     public TextHit hitTestChar(float x, float y);
152
153     /**
154      * Returns true if the advance direction of this text is vertical.
155      */

156     public boolean isVertical();
157
158     /**
159      * Returns true if this layout in on a text path.
160      */

161     public boolean isOnATextPath();
162
163     /**
164      * Returns the number of glyphs in this layout.
165      */

166     public int getGlyphCount();
167
168     /**
169      * Returns the number of chars represented by the glyphs within the
170      * specified range.
171      * @param startGlyphIndex The index of the first glyph in the range.
172      * @param endGlyphIndex The index of the last glyph in the range.
173      * @return The number of chars.
174      */

175     public int getCharacterCount(int startGlyphIndex, int endGlyphIndex);
176
177     /**
178      * Returns the glyph index of the glyph that has the specified char index.
179      *
180      * @param charIndex The original index of the character in the text node's
181      * text string.
182      * @return The index of the matching glyph in this layout's glyph vector,
183      * or -1 if a matching glyph could not be found.
184      */

185     public int getGlyphIndex(int charIndex);
186
187     /**
188      * Returns true if the text direction in this layout is from left to right.
189      */

190     public boolean isLeftToRight();
191
192     /**
193      * Return true is the character index is represented by glyphs
194      * in this layout.
195      *
196      * @param index index of the character in the ACI.
197      * @return true if the layout represents that character.
198      */

199     public boolean hasCharacterIndex(int index);
200
201
202     /**
203      * Return the glyph vector asociated to this layout.
204      *
205      * @return glyph vector
206      */

207     public GVTGlyphVector getGlyphVector();
208
209     /**
210      * Return the rotation angle applied to the
211      * character.
212      *
213      * @param index index of the character in the ACI
214      * @return rotation angle
215      */

216     public double getComputedOrientationAngle(int index);
217
218     /**
219      * Return true if this text run represents
220      * an alt glyph.
221      */

222     public boolean isAltGlyph();
223 }
224
Popular Tags