1 18 19 package org.apache.batik.gvt.flow; 20 21 import java.text.AttributedCharacterIterator ; 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import java.util.Iterator ; 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 38 public class FlowTextPainter extends StrokingTextPainter { 39 42 protected static TextPainter singleton = new FlowTextPainter(); 43 44 47 public static TextPainter getInstance() { 48 return singleton; 49 } 50 51 public List getTextRuns(TextNode node, AttributedCharacterIterator aci) { 52 List textRuns = node.getTextRuns(); 53 if (textRuns != null) { 54 return textRuns; 55 } 56 57 AttributedCharacterIterator [] chunkACIs = getTextChunkACIs(aci); 58 textRuns = computeTextRuns(node, aci, chunkACIs); 59 60 aci.first(); 61 List rgns = (List )aci.getAttribute(FLOW_REGIONS); 62 63 if (rgns != null) { 64 Iterator i = textRuns.iterator(); 65 List chunkLayouts = new ArrayList (); 66 TextRun tr = (TextRun)i.next(); 67 List layouts = new ArrayList (); 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 (); 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 |