1 49 50 package com.lowagie.text.pdf; 51 52 57 public class PdfStructureElement extends PdfDictionary { 58 59 62 private PdfStructureElement parent; 63 private PdfStructureTreeRoot top; 64 65 68 private PdfIndirectReference reference; 69 70 75 public PdfStructureElement(PdfStructureElement parent, PdfName structureType) { 76 top = parent.top; 77 init(parent, structureType); 78 this.parent = parent; 79 put(PdfName.P, parent.reference); 80 } 81 82 87 public PdfStructureElement(PdfStructureTreeRoot parent, PdfName structureType) { 88 top = parent; 89 init(parent, structureType); 90 put(PdfName.P, parent.getReference()); 91 } 92 93 private void init(PdfDictionary parent, PdfName structureType) { 94 PdfObject kido = parent.get(PdfName.K); 95 PdfArray kids = null; 96 if (kido != null && !kido.isArray()) 97 throw new IllegalArgumentException ("The parent has already another function."); 98 if (kido == null) { 99 kids = new PdfArray(); 100 parent.put(PdfName.K, kids); 101 } 102 else 103 kids = (PdfArray)kido; 104 kids.add(this); 105 put(PdfName.S, structureType); 106 reference = top.getWriter().getPdfIndirectReference(); 107 } 108 109 113 public PdfDictionary getParent() { 114 return parent; 115 } 116 117 void setPageMark(int page, int mark) { 118 if (mark >= 0) 119 put(PdfName.K, new PdfNumber(mark)); 120 top.setPageMark(page, reference); 121 } 122 123 127 public PdfIndirectReference getReference() { 128 return this.reference; 129 } 130 } 131 | Popular Tags |