1 52 53 package com.lowagie.text.rtf.text; 54 55 import java.io.ByteArrayOutputStream ; 56 import java.io.IOException ; 57 import java.io.OutputStream ; 58 59 import com.lowagie.text.rtf.RtfAddableElement; 60 61 76 public class RtfTab extends RtfAddableElement { 77 78 81 public static final int TAB_LEFT_ALIGN = 0; 82 85 public static final int TAB_CENTER_ALIGN = 1; 86 89 public static final int TAB_RIGHT_ALIGN = 2; 90 94 public static final int TAB_DECIMAL_ALIGN = 3; 95 96 99 private int position = 0; 100 103 private int type = TAB_LEFT_ALIGN; 104 105 113 public RtfTab(float position, int type) { 114 this.position = (int) Math.round(position * TWIPS_FACTOR); 115 switch(type) { 116 case TAB_LEFT_ALIGN: this.type = TAB_LEFT_ALIGN; break; 117 case TAB_CENTER_ALIGN: this.type = TAB_CENTER_ALIGN; break; 118 case TAB_RIGHT_ALIGN: this.type = TAB_RIGHT_ALIGN; break; 119 case TAB_DECIMAL_ALIGN: this.type = TAB_DECIMAL_ALIGN; break; 120 default: this.type = TAB_LEFT_ALIGN; break; 121 } 122 } 123 124 128 public byte[] write() { 129 ByteArrayOutputStream result = new ByteArrayOutputStream (); 130 try { 131 writeContent(result); 132 } catch(IOException ioe) { 133 ioe.printStackTrace(); 134 } 135 return result.toByteArray(); 136 } 137 138 141 public void writeContent(final OutputStream result) throws IOException 142 { 143 switch(this.type) { 144 case TAB_CENTER_ALIGN: result.write("\\tqc".getBytes()); break; 145 case TAB_RIGHT_ALIGN: result.write("\\tqr".getBytes()); break; 146 case TAB_DECIMAL_ALIGN: result.write("\\tqdec".getBytes()); break; 147 } 148 result.write("\\tx".getBytes()); 149 result.write(intToByteArray(this.position)); 150 } 151 152 } 153 | Popular Tags |