1 /*
2
3 Licensed to the Apache Software Foundation (ASF) under one or more
4 contributor license agreements. See the NOTICE file distributed with
5 this work for additional information regarding copyright ownership.
6 The ASF licenses this file to You under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with
8 the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17
18 */
19 package org.apache.batik.gvt.text;
20
21 import java.text.AttributedCharacterIterator;
22 import java.text.AttributedString;
23 import java.util.Map;
24 import java.util.Set;
25
26 /**
27 * GVTAttributedCharacterIterator
28 *
29 * Used to implement SVG <tspan> and <text>
30 * attributes. This implementation is designed for efficient support
31 * of per-character attributes (i.e. single character attribute spans).
32 * It supports an extended set of TextAttributes, via inner class
33 * SVGAttributedCharacterIterator.TextAttributes.
34 *
35 * @author <a href="mailto:bill.haneman@ireland.sun.com">Bill Haneman</a>
36 * @version $Id: GVTAttributedCharacterIterator.java 1802297 2017-07-18 13:58:12Z ssteiner $
37 */
38
39 public interface GVTAttributedCharacterIterator extends AttributedCharacterIterator {
40
41 /**
42 * Sets this iterator's contents to an unattributed copy of String s.
43 */
44 void setString(String s);
45
46 /**
47 * Assigns this iterator's contents to be equivalent to AttributedString s.
48 */
49 void setString(AttributedString s);
50
51 /**
52 * Sets values of a per-character attribute associated with the content
53 * string.
54 * Characters from <code>beginIndex</code> to <code>endIndex</code>
55 * (zero-offset) are assigned values for attribute key <code>attr</code>
56 * from the array <code>attValues.</code>
57 * If the length of attValues is less than character span
58 * <code>(endIndex-beginIndex)</code> the last value is duplicated;
59 * if attValues is longer than the character span
60 * the extra values are ignored.
61 * Note that if either beginIndex or endIndex are outside the bounds
62 * of the current character array they are clipped accordingly.
63 */
64 void setAttributeArray(TextAttribute attr,
65 Object[] attValues, int beginIndex, int endIndex);
66
67 //From java.text.AttributedCharacterIterator
68
69 /**
70 * Get the keys of all attributes defined on the iterator's text range.
71 */
72 Set getAllAttributeKeys();
73
74 /**
75 * Get the value of the named attribute for the current
76 * character.
77 */
78 Object getAttribute(AttributedCharacterIterator.Attribute attribute);
79
80 /**
81 * Returns a map with the attributes defined on the current
82 * character.
83 */
84 Map getAttributes();
85
86 /**
87 * Get the index of the first character following the
88 * run with respect to all attributes containing the current
89 * character.
90 */
91 int getRunLimit();
92
93 /**
94 * Get the index of the first character following the
95 * run with respect to the given attribute containing the current
96 * character.
97 */
98 int getRunLimit(AttributedCharacterIterator.Attribute attribute);
99
100 /**
101 * Get the index of the first character following the
102 * run with respect to the given attributes containing the current
103 * character.
104 */
105 int getRunLimit(Set attributes);
106
107 /**
108 * Get the index of the first character of the run with
109 * respect to all attributes containing the current character.
110 */
111 int getRunStart();
112
113 /**
114 * Get the index of the first character of the run with
115 * respect to the given attribute containing the current character.
116 * @param attribute The attribute for whose appearance the first offset
117 * is requested.
118 */
119 int getRunStart(AttributedCharacterIterator.Attribute attribute);
120
121 /**
122 * Get the index of the first character of the run with
123 * respect to the given attributes containing the current character.
124 * @param attributes the Set of attributes which begins at the returned index.
125 */
126 int getRunStart(Set attributes);
127
128 //From CharacterIterator
129
130 /**
131 * Create a copy of this iterator
132 */
133 Object clone();
134
135 /**
136 * Get the character at the current position (as returned
137 * by getIndex()).
138 * <br><b>Specified by:</b> java.text.CharacterIterator.
139 */
140 char current();
141
142 /**
143 * Sets the position to getBeginIndex().
144 * @return the character at the start index of the text.
145 * <br><b>Specified by:</b> java.text.CharacterIterator.
146 */
147 char first();
148
149 /**
150 * Get the start index of the text.
151 * <br><b>Specified by:</b> java.text.CharacterIterator.
152 */
153 int getBeginIndex();
154
155 /**
156 * Get the end index of the text.
157 * <br><b>Specified by:</b> java.text.CharacterIterator.
158 */
159 int getEndIndex();
160
161 /**
162 * Get the current index.
163 * <br><b>Specified by:</b> java.text.CharacterIterator.
164 */
165 int getIndex();
166
167 /**
168 * Sets the position to getEndIndex()-1 (getEndIndex() if
169 * the text is empty) and returns the character at that position.
170 * <br><b>Specified by:</b> java.text.CharacterIterator.
171 */
172 char last();
173
174 /**
175 * Increments the iterator's index by one, returning the next character.
176 * @return the character at the new index.
177 * <br><b>Specified by:</b> java.text.CharacterIterator.
178 */
179 char next();
180
181 /**
182 * Decrements the iterator's index by one and returns
183 * the character at the new index.
184 * <br><b>Specified by:</b> java.text.CharacterIterator.
185 */
186 char previous();
187
188 /**
189 * Sets the position to the specified position in the text.
190 * @param position The new (current) index into the text.
191 * @return the character at new index <em>position</em>.
192 * <br><b>Specified by:</b> java.text.CharacterIterator.
193 */
194 char setIndex(int position);
195
196 //Inner classes:
197
198 /**
199 * Attribute keys that identify SVG text attributes. Anchor point for
200 * attribute values of X, Y, and ROTATION is determined by the character's
201 * font and other attributes.
202 * We duplicate the features of java.awt.font.TextAttribute rather than
203 * subclassing because java.awt.font.TextAttribute is <em>final</em>.
204 */
205 class TextAttribute extends AttributedCharacterIterator.Attribute {
206
207 /** Construct a TextAttribute key with name s */
208 public TextAttribute(String s) {
209 super(s);
210 }
211
212 public static final TextAttribute FLOW_PARAGRAPH =
213 new TextAttribute("FLOW_PARAGRAPH");
214
215 public static final TextAttribute FLOW_EMPTY_PARAGRAPH =
216 new TextAttribute("FLOW_EMPTY_PARAGRAPH");
217
218 public static final TextAttribute FLOW_LINE_BREAK =
219 new TextAttribute("FLOW_LINE_BREAK");
220
221 public static final TextAttribute FLOW_REGIONS =
222 new TextAttribute("FLOW_REGIONS");
223
224 public static final TextAttribute LINE_HEIGHT =
225 new TextAttribute("LINE_HEIGHT");
226
227 public static final TextAttribute PREFORMATTED =
228 new TextAttribute("PREFORMATTED");
229
230 /** Attribute span delimiter - new tspan, tref, or textelement.*/
231 public static final TextAttribute TEXT_COMPOUND_DELIMITER =
232 new TextAttribute("TEXT_COMPOUND_DELIMITER");
233
234 /** Element identifier all chars from same element will share an
235 * ID. */
236 public static final TextAttribute TEXT_COMPOUND_ID =
237 new TextAttribute("TEXT_COMPOUND_ID");
238
239 /** Anchor type.*/
240 public static final TextAttribute ANCHOR_TYPE =
241 new TextAttribute("ANCHOR_TYPE");
242
243 /** Marker attribute indicating explicit glyph layout.*/
244 public static final TextAttribute EXPLICIT_LAYOUT =
245 new TextAttribute("EXPLICIT_LAYOUT");
246
247 /** User-space X coordinate for character.*/
248 public static final TextAttribute X = new TextAttribute("X");
249
250 /** User-space Y coordinate for character.*/
251 public static final TextAttribute Y = new TextAttribute("Y");
252
253 /** User-space relative X coordinate for character.*/
254 public static final TextAttribute DX = new TextAttribute("DX");
255
256 /** User-space relative Y coordinate for character.*/
257 public static final TextAttribute DY = new TextAttribute("DY");
258
259 /** Rotation for character, in degrees.*/
260 public static final TextAttribute ROTATION =
261 new TextAttribute("ROTATION");
262
263 /** All the paint attributes for the text.*/
264 public static final TextAttribute PAINT_INFO =
265 new TextAttribute("PAINT_INFO");
266
267 /** Author-expected width for bounding box containing
268 * all text string glyphs.
269 */
270 public static final TextAttribute BBOX_WIDTH =
271 new TextAttribute("BBOX_WIDTH");
272
273 /** Method specified for adjusting text element layout size.
274 */
275 public static final TextAttribute LENGTH_ADJUST =
276 new TextAttribute("LENGTH_ADJUST");
277
278 /** Convenience flag indicating that non-default glyph spacing is needed.
279 */
280 public static final TextAttribute CUSTOM_SPACING =
281 new TextAttribute("CUSTOM_SPACING");
282
283 /** User-specified inter-glyph kerning value.
284 */
285 public static final TextAttribute KERNING =
286 new TextAttribute("KERNING");
287
288 /** User-specified inter-glyph spacing value.
289 */
290 public static final TextAttribute LETTER_SPACING =
291 new TextAttribute("LETTER_SPACING");
292
293 /** User-specified width for whitespace characters.
294 */
295 public static final TextAttribute WORD_SPACING =
296 new TextAttribute("WORD_SPACING");
297
298 /** Path along which text is to be laid out */
299 public static final TextAttribute TEXTPATH =
300 new TextAttribute("TEXTPATH");
301
302 /** Font variant to be used for this character span.
303 * @see org.apache.batik.gvt.text.GVTAttributedCharacterIterator.TextAttribute#SMALL_CAPS
304 */
305 public static final TextAttribute FONT_VARIANT =
306 new TextAttribute("FONT_VARIANT");
307
308 /** Baseline adjustment to be applied to this character span.
309 */
310 public static final TextAttribute BASELINE_SHIFT =
311 new TextAttribute("BASELINE_SHIFT");
312
313 /** Directional writing mode applied to this character span.
314 */
315 public static final TextAttribute WRITING_MODE =
316 new TextAttribute("WRITING_MODE");
317
318 public static final TextAttribute VERTICAL_ORIENTATION =
319 new TextAttribute("VERTICAL_ORIENTATION");
320
321 public static final TextAttribute VERTICAL_ORIENTATION_ANGLE =
322 new TextAttribute("VERTICAL_ORIENTATION_ANGLE");
323
324 public static final TextAttribute HORIZONTAL_ORIENTATION_ANGLE =
325 new TextAttribute("HORIZONTAL_ORIENTATION_ANGLE");
326
327 public static final TextAttribute GVT_FONT_FAMILIES =
328 new TextAttribute("GVT_FONT_FAMILIES");
329
330 public static final TextAttribute GVT_FONTS =
331 new TextAttribute("GVT_FONTS");
332
333 public static final TextAttribute GVT_FONT =
334 new TextAttribute("GVT_FONT");
335
336 public static final TextAttribute ALT_GLYPH_HANDLER =
337 new TextAttribute("ALT_GLYPH_HANDLER");
338
339 public static final TextAttribute BIDI_LEVEL =
340 new TextAttribute("BIDI_LEVEL");
341
342 public static final TextAttribute CHAR_INDEX =
343 new TextAttribute("CHAR_INDEX");
344
345 public static final TextAttribute ARABIC_FORM =
346 new TextAttribute("ARABIC_FORM");
347
348 public static final TextAttribute SCRIPT =
349 new TextAttribute("SCRIPT");
350
351 public static final TextAttribute LANGUAGE =
352 new TextAttribute("LANGUAGE");
353
354 // VALUES
355
356 /** Value for WRITING_MODE indicating left-to-right */
357 public static final Integer WRITING_MODE_LTR = 0x1;
358
359 /** Value for WRITING_MODE indicating right-to-left */
360 public static final Integer WRITING_MODE_RTL = 0x2;
361
362 /** Value for WRITING_MODE indicating top-to-botton */
363 public static final Integer WRITING_MODE_TTB = 0x3;
364
365 /** Value for VERTICAL_ORIENTATION indicating an angle */
366 public static final Integer ORIENTATION_ANGLE = 0x1;
367
368 /** Value for VERTICAL_ORIENTATION indicating auto */
369 public static final Integer ORIENTATION_AUTO = 0x2;
370
371 /** Value for FONT_VARIANT specifying small caps */
372 public static final Integer SMALL_CAPS = 0x10;
373
374 /** Value for UNDERLINE specifying underlining-on */
375 public static final Integer UNDERLINE_ON =
376 java.awt.font.TextAttribute.UNDERLINE_ON;
377
378 /** Value for OVERLINE specifying overlining-on */
379 public static final Boolean OVERLINE_ON = Boolean.TRUE;
380
381 /** Value for STRIKETHROUGH specifying strikethrough-on */
382 public static final Boolean STRIKETHROUGH_ON =
383 java.awt.font.TextAttribute.STRIKETHROUGH_ON;
384
385 /** Value for LENGTH_ADJUST specifying adjustment to inter-glyph spacing */
386 public static final Integer ADJUST_SPACING =
387 0x0;
388
389 /** Value for LENGTH_ADJUST specifying overall scaling of layout outlines */
390 public static final Integer ADJUST_ALL =
391 0x01;
392
393 // constant values for the arabic glyph forms
394 public static final Integer ARABIC_NONE = 0x0;
395 public static final Integer ARABIC_ISOLATED = 0x1;
396 public static final Integer ARABIC_TERMINAL = 0x2;
397 public static final Integer ARABIC_INITIAL = 0x3;
398 public static final Integer ARABIC_MEDIAL = 0x4;
399
400 }
401
402 /**
403 * Interface for helper class which mutates the attributes of an
404 * AttributedCharacterIterator.
405 * Typically used to convert location and rotation attributes to
406 * TextAttribute.TRANSFORM attributes, or convert between implementations
407 * of AttributedCharacterIterator.Attribute.
408 */
409 interface AttributeFilter {
410
411 /**
412 * Modify an AttributedCharacterIterator's attributes systematically.
413 * Usually returns a copy since AttributedCharacterIterator instances
414 * are often immutable. The effect of the attribute modification
415 * is implementation dependent.
416 * @param aci an AttributedCharacterIterator whose attributes are
417 * to be modified.
418 * @return an instance of AttributedCharacterIterator with mutated
419 * attributes.
420 */
421 AttributedCharacterIterator
422 mutateAttributes(AttributedCharacterIterator aci);
423
424 }
425 }
426
427
428
429
430
431
432
433
434
435