1 49 package com.lowagie.text.pdf; 50 51 import java.io.IOException ; 52 import java.util.ArrayList ; 53 import java.util.HashMap ; 54 import java.util.Iterator ; 55 56 60 public class PdfStructureTreeRoot extends PdfDictionary { 61 62 private HashMap parentTree = new HashMap (); 63 private PdfIndirectReference reference; 64 65 68 private PdfWriter writer; 69 70 71 PdfStructureTreeRoot(PdfWriter writer) { 72 super(PdfName.STRUCTTREEROOT); 73 this.writer = writer; 74 reference = writer.getPdfIndirectReference(); 75 } 76 77 83 public void mapRole(PdfName used, PdfName standard) { 84 PdfDictionary rm = (PdfDictionary)get(PdfName.ROLEMAP); 85 if (rm == null) { 86 rm = new PdfDictionary(); 87 put(PdfName.ROLEMAP, rm); 88 } 89 rm.put(used, standard); 90 } 91 92 96 public PdfWriter getWriter() { 97 return this.writer; 98 } 99 100 104 public PdfIndirectReference getReference() { 105 return this.reference; 106 } 107 108 void setPageMark(int page, PdfIndirectReference struc) { 109 Integer i = new Integer (page); 110 PdfArray ar = (PdfArray)parentTree.get(i); 111 if (ar == null) { 112 ar = new PdfArray(); 113 parentTree.put(i, ar); 114 } 115 ar.add(struc); 116 } 117 118 private void nodeProcess(PdfDictionary struc, PdfIndirectReference reference) throws IOException { 119 PdfObject obj = struc.get(PdfName.K); 120 if (obj != null && obj.isArray() && !((PdfObject)((PdfArray)obj).getArrayList().get(0)).isNumber()) { 121 PdfArray ar = (PdfArray)obj; 122 ArrayList a = ar.getArrayList(); 123 for (int k = 0; k < a.size(); ++k) { 124 PdfStructureElement e = (PdfStructureElement)a.get(k); 125 a.set(k, e.getReference()); 126 nodeProcess(e, e.getReference()); 127 } 128 } 129 if (reference != null) 130 writer.addToBody(struc, reference); 131 } 132 133 void buildTree() throws IOException { 134 HashMap numTree = new HashMap (); 135 for (Iterator it = parentTree.keySet().iterator(); it.hasNext();) { 136 Integer i = (Integer )it.next(); 137 PdfArray ar = (PdfArray)parentTree.get(i); 138 numTree.put(i, writer.addToBody(ar).getIndirectReference()); 139 } 140 PdfDictionary dicTree = PdfNumberTree.writeTree(numTree, writer); 141 if (dicTree != null) 142 put(PdfName.PARENTTREE, writer.addToBody(dicTree).getIndirectReference()); 143 144 nodeProcess(this, reference); 145 } 146 } 147 | Popular Tags |