1 50 51 package com.lowagie.text.rtf.style; 52 53 import java.io.ByteArrayOutputStream ; 54 import java.io.IOException ; 55 import java.io.OutputStream ; 56 import java.util.ArrayList ; 57 58 import com.lowagie.text.rtf.RtfElement; 59 import com.lowagie.text.rtf.RtfExtendedElement; 60 import com.lowagie.text.rtf.document.RtfDocument; 61 62 70 public class RtfFontList extends RtfElement implements RtfExtendedElement { 71 72 75 private static final byte[] DEFAULT_FONT = "\\deff".getBytes(); 76 79 private static final byte[] FONT_TABLE = "\\fonttbl".getBytes(); 80 83 public static final byte[] FONT_NUMBER = "\\f".getBytes(); 84 85 88 private ArrayList fontList = new ArrayList (); 89 90 95 public RtfFontList(RtfDocument doc) { 96 super(doc); 97 fontList.add(new RtfFont(document, 0)); 98 } 99 100 104 public byte[] write() 105 { 106 return(new byte[0]); 107 } 108 111 public void writeContent(OutputStream out) throws IOException 112 { 113 } 114 115 122 public int getFontNumber(RtfFont font) { 123 if(font instanceof RtfParagraphStyle) { 124 font = new RtfFont(this.document, font); 125 } 126 int fontIndex = -1; 127 for(int i = 0; i < fontList.size(); i++) { 128 if(fontList.get(i).equals(font)) { 129 fontIndex = i; 130 } 131 } 132 if(fontIndex == -1) { 133 fontIndex = fontList.size(); 134 fontList.add(font); 135 } 136 return fontIndex; 137 } 138 139 145 public byte[] writeDefinition() { 146 ByteArrayOutputStream result = new ByteArrayOutputStream (); 147 try { 148 writeDefinition(result); 149 } catch(IOException ioe) { 150 ioe.printStackTrace(); 151 } 152 return result.toByteArray(); 153 } 154 155 158 public void writeDefinition(final OutputStream result) throws IOException 159 { 160 result.write(DEFAULT_FONT); 161 result.write(intToByteArray(0)); 162 result.write(OPEN_GROUP); 163 result.write(FONT_TABLE); 164 for(int i = 0; i < fontList.size(); i++) { 165 result.write(OPEN_GROUP); 166 result.write(FONT_NUMBER); 167 result.write(intToByteArray(i)); 168 RtfFont rf = (RtfFont) fontList.get(i); 169 rf.writeDefinition(result); 171 result.write(COMMA_DELIMITER); 172 result.write(CLOSE_GROUP); 173 } 174 result.write(CLOSE_GROUP); 175 result.write((byte)'\n'); 176 } 177 178 } 179 | Popular Tags |