KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > gvt > flow > FlowTextPainter


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.gvt.flow;
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: FlowTextPainter.java,v 1.2 2005/03/27 08:58:34 cam Exp $
37  */

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

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

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