1 17 18 19 20 package org.apache.fop.render.rtf.rtflib.rtfdoc; 21 22 28 29 import java.io.IOException ; 30 import java.util.Hashtable ; 31 import java.util.Vector ; 32 33 37 public final class RtfFontManager { 38 42 43 private static RtfFontManager instance = null; 44 45 46 private Hashtable fontIndex = null; 47 48 private Vector fontTable = null; 49 50 51 55 58 private RtfFontManager () { 59 fontTable = new Vector (); 60 fontIndex = new Hashtable (); 61 62 init (); 63 } 64 65 70 public static RtfFontManager getInstance () { 71 if (instance == null) { 72 instance = new RtfFontManager (); 73 } 74 75 return instance; 76 } 77 78 79 83 86 private void init () { 87 88 getFontNumber ("Arial"); 91 getFontNumber ("Symbol"); getFontNumber ("Times New Roman"); 93 94 103 } 104 105 106 110 111 118 public int getFontNumber (String family) { 119 120 Object o = fontIndex.get(getFontKey(family)); 121 int retVal; 122 123 if (o == null) { 124 addFont (family); 125 126 retVal = fontTable.size() - 1; 127 } else { 128 retVal = ((Integer )o).intValue(); 129 } 130 131 return retVal; 132 } 133 134 141 public void writeFonts (RtfHeader header) throws IOException { 142 if (fontTable == null || fontTable.size () == 0) { 143 return; 144 } 145 146 header.newLine(); 147 header.writeGroupMark (true); 148 header.writeControlWord ("fonttbl;"); 149 150 int len = fontTable.size (); 151 152 for (int i = 0; i < len; i++) { 153 header.writeGroupMark (true); 154 header.newLine(); 155 header.write ("\\f" + i); 156 header.write (" " + (String ) fontTable.elementAt (i)); 157 header.writeGroupMark (false); 158 } 159 160 header.newLine(); 161 header.writeGroupMark (false); 162 } 163 164 165 169 private String getFontKey(String family) { 170 return family.toLowerCase(); 171 } 172 173 178 private void addFont(String family) { 179 fontIndex.put(getFontKey(family), new Integer (fontTable.size())); 180 fontTable.addElement(family); 181 } 182 } 183 | Popular Tags |