KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2000-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 package org.apache.batik.gvt.text;
19
20 import java.text.AttributedCharacterIterator JavaDoc;
21 import java.text.AttributedString JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.Set JavaDoc;
24
25 /**
26  * GVTAttributedCharacterIterator
27  *
28  * Used to implement SVG <tspan> and <text>
29  * attributes. This implementation is designed for efficient support
30  * of per-character attributes (i.e. single character attribute spans).
31  * It supports an extended set of TextAttributes, via inner class
32  * SVGAttributedCharacterIterator.TextAttributes.
33  *
34  * @author <a HREF="mailto:bill.haneman@ireland.sun.com">Bill Haneman</a>
35  * @version $Id: GVTAttributedCharacterIterator.java,v 1.25 2004/11/18 01:47:00 deweese Exp $
36  */

37
38 public interface GVTAttributedCharacterIterator extends AttributedCharacterIterator JavaDoc {
39
40     /**
41      * Sets this iterator's contents to an unattributed copy of String s.
42      */

43     public void setString(String JavaDoc s);
44
45     /**
46      * Assigns this iterator's contents to be equivalent to AttributedString s.
47      */

48     public void setString(AttributedString JavaDoc s);
49
50     /**
51      * Sets values of a per-character attribute associated with the content
52      * string.
53      * Characters from <tt>beginIndex</tt> to <tt>endIndex</tt>
54      * (zero-offset) are assigned values for attribute key <tt>attr</tt>
55      * from the array <tt>attValues.</tt>
56      * If the length of attValues is less than character span
57      * <tt>(endIndex-beginIndex)</tt> the last value is duplicated;
58      * if attValues is longer than the character span
59      * the extra values are ignored.
60      * Note that if either beginIndex or endIndex are outside the bounds
61      * of the current character array they are clipped accordingly.
62      */

63     public void setAttributeArray(TextAttribute attr,
64                         Object JavaDoc[] attValues, int beginIndex, int endIndex);
65
66     //From java.text.AttributedCharacterIterator
67

68     /**
69      * Get the keys of all attributes defined on the iterator's text range.
70      */

71     public Set JavaDoc getAllAttributeKeys();
72
73     /**
74      * Get the value of the named attribute for the current
75      * character.
76      */

77     public Object JavaDoc getAttribute(AttributedCharacterIterator.Attribute JavaDoc attribute);
78
79     /**
80      * Returns a map with the attributes defined on the current
81      * character.
82      */

83     public Map JavaDoc getAttributes();
84
85     /**
86      * Get the index of the first character following the
87      * run with respect to all attributes containing the current
88      * character.
89      */

90     public int getRunLimit();
91
92     /**
93      * Get the index of the first character following the
94      * run with respect to the given attribute containing the current
95      * character.
96      */

97     public int getRunLimit(AttributedCharacterIterator.Attribute JavaDoc attribute);
98
99     /**
100      * Get the index of the first character following the
101      * run with respect to the given attributes containing the current
102      * character.
103      */

104     public int getRunLimit(Set JavaDoc attributes);
105
106     /**
107      * Get the index of the first character of the run with
108      * respect to all attributes containing the current character.
109      */

110     public int getRunStart();
111
112     /**
113      * Get the index of the first character of the run with
114      * respect to the given attribute containing the current character.
115      * @param attribute The attribute for whose appearance the first offset
116      * is requested.
117      */

118     public int getRunStart(AttributedCharacterIterator.Attribute JavaDoc attribute);
119
120     /**
121      * Get the index of the first character of the run with
122      * respect to the given attributes containing the current character.
123      * @param attributes the Set of attributes which begins at the returned index.
124      */

125     public int getRunStart(Set JavaDoc attributes);
126
127     //From CharacterIterator
128

129     /**
130      * Create a copy of this iterator
131      */

132     public Object JavaDoc clone();
133
134     /**
135      * Get the character at the current position (as returned
136      * by getIndex()).
137      * <br><b>Specified by:</b> java.text.CharacterIterator.
138      */

139     public char current();
140
141     /**
142      * Sets the position to getBeginIndex().
143      * @return the character at the start index of the text.
144      * <br><b>Specified by:</b> java.text.CharacterIterator.
145      */

146     public char first();
147
148     /**
149      * Get the start index of the text.
150      * <br><b>Specified by:</b> java.text.CharacterIterator.
151      */

152     public int getBeginIndex();
153
154     /**
155      * Get the end index of the text.
156      * <br><b>Specified by:</b> java.text.CharacterIterator.
157      */

158     public int getEndIndex();
159
160     /**
161      * Get the current index.
162      * <br><b>Specified by:</b> java.text.CharacterIterator.
163      */

164     public int getIndex();
165
166     /**
167      * Sets the position to getEndIndex()-1 (getEndIndex() if
168      * the text is empty) and returns the character at that position.
169      * <br><b>Specified by:</b> java.text.CharacterIterator.
170      */

171     public char last();
172
173     /**
174      * Increments the iterator's index by one, returning the next character.
175      * @return the character at the new index.
176      * <br><b>Specified by:</b> java.text.CharacterIterator.
177      */

178     public char next();
179
180     /**
181      * Decrements the iterator's index by one and returns
182      * the character at the new index.
183      * <br><b>Specified by:</b> java.text.CharacterIterator.
184      */

185     public char previous();
186
187     /**
188      * Sets the position to the specified position in the text.
189      * @param position The new (current) index into the text.
190      * @return the character at new index <em>position</em>.
191      * <br><b>Specified by:</b> java.text.CharacterIterator.
192      */

193     public char setIndex(int position);
194
195     //Inner classes:
196

197     /**
198      * Attribute keys that identify SVG text attributes. Anchor point for
199      * attribute values of X, Y, and ROTATION is determined by the character's
200      * font and other attributes.
201      * We duplicate the features of java.awt.font.TextAttribute rather than
202      * subclassing because java.awt.font.TextAttribute is <em>final</em>.
203      */

204     public static class TextAttribute extends AttributedCharacterIterator.Attribute JavaDoc {
205
206         /** Construct a TextAttribute key with name s */
207         public TextAttribute(String JavaDoc s) {
208             super(s);
209         }
210
211         public final static TextAttribute FLOW_PARAGRAPH =
212             new TextAttribute("FLOW_PARAGRAPH");
213
214         public final static TextAttribute FLOW_EMPTY_PARAGRAPH =
215             new TextAttribute("FLOW_EMPTY_PARAGRAPH");
216
217         public final static TextAttribute FLOW_LINE_BREAK =
218             new TextAttribute("FLOW_LINE_BREAK");
219
220         public final static TextAttribute FLOW_REGIONS =
221             new TextAttribute("FLOW_REGIONS");
222
223         public final static TextAttribute LINE_HEIGHT =
224             new TextAttribute("LINE_HEIGHT");
225
226         public final static TextAttribute PREFORMATTED =
227             new TextAttribute("PREFORMATTED");
228
229         /** Attribute span delimiter - new tspan, tref, or textelement.*/
230         public final static TextAttribute TEXT_COMPOUND_DELIMITER =
231                               new TextAttribute("TEXT_COMPOUND_DELIMITER");
232
233         /** Anchor type.*/
234         public final static TextAttribute ANCHOR_TYPE =
235                               new TextAttribute("ANCHOR_TYPE");
236
237         /** Marker attribute indicating explicit glyph layout.*/
238         public final static TextAttribute EXPLICIT_LAYOUT =
239                               new TextAttribute("EXPLICIT_LAYOUT");
240
241         /** User-space X coordinate for character.*/
242         public final static TextAttribute X = new TextAttribute("X");
243
244         /** User-space Y coordinate for character.*/
245         public final static TextAttribute Y = new TextAttribute("Y");
246
247         /** User-space relative X coordinate for character.*/
248         public final static TextAttribute DX = new TextAttribute("DX");
249
250         /** User-space relative Y coordinate for character.*/
251         public final static TextAttribute DY = new TextAttribute("DY");
252
253         /** Rotation for character, in degrees.*/
254         public final static TextAttribute ROTATION =
255                                           new TextAttribute("ROTATION");
256
257         /** All the paint attributes for the text.*/
258         public final static TextAttribute PAINT_INFO =
259                                           new TextAttribute("PAINT_INFO");
260
261         /** Author-expected width for bounding box containing
262          * all text string glyphs.
263          */

264         public final static TextAttribute BBOX_WIDTH =
265                                           new TextAttribute("BBOX_WIDTH");
266
267         /** Method specified for adjusting text element layout size.
268          */

269         public final static TextAttribute LENGTH_ADJUST =
270                                           new TextAttribute("LENGTH_ADJUST");
271
272         /** Convenience flag indicating that non-default glyph spacing is needed.
273          */

274         public final static TextAttribute CUSTOM_SPACING =
275                                           new TextAttribute("CUSTOM_SPACING");
276
277         /** User-specified inter-glyph kerning value.
278          */

279         public final static TextAttribute KERNING =
280                                           new TextAttribute("KERNING");
281
282         /** User-specified inter-glyph spacing value.
283          */

284         public final static TextAttribute LETTER_SPACING =
285                                           new TextAttribute("LETTER_SPACING");
286
287         /** User-specified width for whitespace characters.
288          */

289         public final static TextAttribute WORD_SPACING =
290                                           new TextAttribute("WORD_SPACING");
291
292         /** Path along which text is to be laid out */
293         public final static TextAttribute TEXTPATH =
294                                           new TextAttribute("TEXTPATH");
295
296         /** Font variant to be used for this character span.
297          * @see org.apache.batik.gvt.text.GVTAttributedCharacterIterator.TextAttribute#SMALL_CAPS
298          */

299         public final static TextAttribute FONT_VARIANT =
300                                           new TextAttribute("FONT_VARIANT");
301
302         /** Baseline adjustment to be applied to this character span.
303          */

304         public final static TextAttribute BASELINE_SHIFT =
305                                           new TextAttribute("BASELINE_SHIFT");
306
307         /** Directional writing mode applied to this character span.
308          */

309         public final static TextAttribute WRITING_MODE =
310                                           new TextAttribute("WRITING_MODE");
311
312         public final static TextAttribute VERTICAL_ORIENTATION =
313                                           new TextAttribute("VERTICAL_ORIENTATION");
314
315         public final static TextAttribute VERTICAL_ORIENTATION_ANGLE =
316                                           new TextAttribute("VERTICAL_ORIENTATION_ANGLE");
317
318         public final static TextAttribute HORIZONTAL_ORIENTATION_ANGLE =
319                                           new TextAttribute("HORIZONTAL_ORIENTATION_ANGLE");
320
321         public final static TextAttribute GVT_FONT_FAMILIES =
322                                           new TextAttribute("GVT_FONT_FAMILIES");
323
324         public final static TextAttribute GVT_FONT =
325                                           new TextAttribute("GVT_FONT");
326
327         public final static TextAttribute ALT_GLYPH_HANDLER =
328                                           new TextAttribute("ALT_GLYPH_HANDLER");
329
330         public final static TextAttribute BIDI_LEVEL =
331                                           new TextAttribute("BIDI_LEVEL");
332
333         public final static TextAttribute CHAR_INDEX =
334                                           new TextAttribute("CHAR_INDEX");
335
336         public final static TextAttribute ARABIC_FORM =
337                                           new TextAttribute("ARABIC_FORM");
338
339         // VALUES
340

341         /** Value for WRITING_MODE indicating left-to-right */
342         public final static Integer JavaDoc WRITING_MODE_LTR = new Integer JavaDoc(0x1);
343
344         /** Value for WRITING_MODE indicating right-to-left */
345         public final static Integer JavaDoc WRITING_MODE_RTL = new Integer JavaDoc(0x2);
346
347         /** Value for WRITING_MODE indicating top-to-botton */
348         public final static Integer JavaDoc WRITING_MODE_TTB = new Integer JavaDoc(0x3);
349
350         /** Value for VERTICAL_ORIENTATION indicating an angle */
351         public final static Integer JavaDoc ORIENTATION_ANGLE = new Integer JavaDoc(0x1);
352
353         /** Value for VERTICAL_ORIENTATION indicating auto */
354         public final static Integer JavaDoc ORIENTATION_AUTO = new Integer JavaDoc(0x2);
355
356         /** Value for FONT_VARIANT specifying small caps */
357         public final static Integer JavaDoc SMALL_CAPS = new Integer JavaDoc(0x10);
358
359         /** Value for UNDERLINE specifying underlining-on */
360         public final static Integer JavaDoc UNDERLINE_ON =
361                             java.awt.font.TextAttribute.UNDERLINE_ON;
362
363         /** Value for OVERLINE specifying overlining-on */
364         public final static Boolean JavaDoc OVERLINE_ON = new Boolean JavaDoc(true);
365
366         /** Value for STRIKETHROUGH specifying strikethrough-on */
367         public final static Boolean JavaDoc STRIKETHROUGH_ON =
368                             java.awt.font.TextAttribute.STRIKETHROUGH_ON;
369
370         /** Value for LENGTH_ADJUST specifying adjustment to inter-glyph spacing */
371         public final static Integer JavaDoc ADJUST_SPACING =
372                             new Integer JavaDoc(0x0);
373
374         /** Value for LENGTH_ADJUST specifying overall scaling of layout outlines */
375         public final static Integer JavaDoc ADJUST_ALL =
376                             new Integer JavaDoc(0x01);
377
378         // constant values for the arabic glyph forms
379
public final static Integer JavaDoc ARABIC_NONE = new Integer JavaDoc(0x0);
380         public final static Integer JavaDoc ARABIC_ISOLATED = new Integer JavaDoc(0x1);
381         public final static Integer JavaDoc ARABIC_TERMINAL = new Integer JavaDoc(0x2);
382         public final static Integer JavaDoc ARABIC_INITIAL = new Integer JavaDoc(0x3);
383         public final static Integer JavaDoc ARABIC_MEDIAL = new Integer JavaDoc(0x4);
384
385     }
386
387     /**
388      * Interface for helper class which mutates the attributes of an
389      * AttributedCharacterIterator.
390      * Typically used to convert location and rotation attributes to
391      * TextAttribute.TRANSFORM attributes, or convert between implementations
392      * of AttributedCharacterIterator.Attribute.
393      */

394     public interface AttributeFilter {
395
396         /**
397          * Modify an AttributedCharacterIterator's attributes systematically.
398          * Usually returns a copy since AttributedCharacterIterator instances
399          * are often immutable. The effect of the attribute modification
400          * is implementation dependent.
401          * @param aci an AttributedCharacterIterator whose attributes are
402          * to be modified.
403          * @return an instance of AttributedCharacterIterator with mutated
404          * attributes.
405          */

406         public AttributedCharacterIterator JavaDoc
407             mutateAttributes(AttributedCharacterIterator JavaDoc aci);
408
409     }
410 }
411
412
413
414
415
416
417
418
419
420
Popular Tags