1 51 52 package com.lowagie.text.rtf; 53 54 import java.io.IOException ; 55 import java.io.OutputStream ; 56 57 import com.lowagie.text.Chunk; 58 import com.lowagie.text.Font; 59 60 71 public class RtfTOCEntry extends Chunk implements RtfField { 72 73 74 private boolean hideText = false; 75 76 private boolean hidePageNumber = false; 77 78 private String entryName; 79 80 private Font entryFont; 81 82 private Font contentFont; 83 84 85 90 public RtfTOCEntry( String content, Font contentFont ) { 91 this( content, contentFont, content, contentFont ); 92 } 96 97 98 105 public RtfTOCEntry( String content, Font contentFont, String entryName, Font entryFont ) { 106 super( content, contentFont ); 107 this.entryName = entryName; 109 this.entryFont = entryFont; 110 this.contentFont = contentFont; 111 } 112 113 116 public void write( RtfWriter writer, OutputStream out ) throws IOException { 117 118 if (!hideText) { 119 writer.writeInitialFontSignature( out, new Chunk("", contentFont) ); 120 out.write( RtfWriter.filterSpecialChar( getContent(), true ).getBytes() ); 121 writer.writeFinishingFontSignature( out, new Chunk("", contentFont) ); 122 } 123 124 if (!entryFont.equals( contentFont )) { 125 writer.writeInitialFontSignature(out, new Chunk("", entryFont) ); 126 writeField( out ); 127 writer.writeFinishingFontSignature(out, new Chunk("", entryFont) ); 128 } else { 129 writer.writeInitialFontSignature(out, new Chunk("", contentFont) ); 130 writeField( out ); 131 writer.writeFinishingFontSignature(out, new Chunk("", contentFont) ); 132 } 133 } 134 135 136 private void writeField( OutputStream out ) throws IOException { 137 138 out.write( RtfWriter.openGroup ); 140 out.write( RtfWriter.escape ); 141 out.write( "v".getBytes() ); 142 143 out.write( RtfWriter.openGroup ); 145 out.write( RtfWriter.escape ); 146 if (!hidePageNumber) { 147 out.write( "tc".getBytes() ); 148 } else { 149 out.write( "tcn".getBytes() ); 150 } 151 out.write( RtfWriter.delimiter ); 152 out.write( RtfWriter.filterSpecialChar( entryName, true ).getBytes() ); 153 out.write( RtfWriter.delimiter ); 154 out.write( RtfWriter.closeGroup ); 155 156 out.write( RtfWriter.closeGroup ); 157 } 158 159 162 public void hideText() { 163 hideText = true; 164 } 165 166 169 public void hidePageNumber() { 170 hidePageNumber = true; 171 } 172 } 173 174 175 | Popular Tags |