KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > extension > svg > FlowExtTextPainter


1 /*
2
3    Copyright 2004 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.extension.svg;
20
21 import java.text.AttributedCharacterIterator JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 import org.apache.batik.gvt.TextNode;
27 import org.apache.batik.gvt.TextPainter;
28 import org.apache.batik.gvt.renderer.StrokingTextPainter;
29
30 /**
31  * One line Class Desc
32  *
33  * Complete Class Desc
34  *
35  * @author <a HREF="mailto:deweese@apache.org">deweese</a>
36  * @version $Id: FlowExtTextPainter.java,v 1.2 2005/03/27 08:58:33 cam Exp $
37  */

38 public class FlowExtTextPainter extends StrokingTextPainter {
39
40     /**
41      * A unique instance of this class.
42      */

43     protected static TextPainter singleton = new FlowExtTextPainter();
44
45     /**
46      * Returns a unique instance of this class.
47      */

48     public static TextPainter getInstance() {
49     return singleton;
50     }
51
52     public List JavaDoc getTextRuns(TextNode node, AttributedCharacterIterator JavaDoc aci) {
53         List JavaDoc textRuns = node.getTextRuns();
54         if (textRuns != null) {
55             return textRuns;
56         }
57
58         AttributedCharacterIterator JavaDoc[] chunkACIs = getTextChunkACIs(aci);
59         textRuns = computeTextRuns(node, aci, chunkACIs);
60
61         aci.first();
62         List JavaDoc rgns = (List JavaDoc)aci.getAttribute(FLOW_REGIONS);
63
64         if (rgns != null) {
65             Iterator JavaDoc i = textRuns.iterator();
66             List JavaDoc chunkLayouts = new ArrayList JavaDoc();
67             TextRun tr = (TextRun)i.next();
68             List JavaDoc layouts = new ArrayList JavaDoc();
69             chunkLayouts.add(layouts);
70             layouts.add(tr.getLayout());
71             while (i.hasNext()) {
72                 tr = (TextRun)i.next();
73                 if (tr.isFirstRunInChunk()) {
74                     layouts = new ArrayList JavaDoc();
75                     chunkLayouts.add(layouts);
76                 }
77                 layouts.add(tr.getLayout());
78             }
79
80             FlowExtGlyphLayout.textWrapTextChunk
81                 (chunkACIs, chunkLayouts, rgns);
82         }
83
84         node.setTextRuns(textRuns);
85         return textRuns;
86     }
87 };
88
Popular Tags