1 17 18 19 20 package org.apache.fop.fonts; 21 22 import org.apache.fop.fonts.base14.Helvetica; 24 import org.apache.fop.fonts.base14.HelveticaBold; 25 import org.apache.fop.fonts.base14.HelveticaOblique; 26 import org.apache.fop.fonts.base14.HelveticaBoldOblique; 27 import org.apache.fop.fonts.base14.TimesRoman; 28 import org.apache.fop.fonts.base14.TimesBold; 29 import org.apache.fop.fonts.base14.TimesItalic; 30 import org.apache.fop.fonts.base14.TimesBoldItalic; 31 import org.apache.fop.fonts.base14.Courier; 32 import org.apache.fop.fonts.base14.CourierBold; 33 import org.apache.fop.fonts.base14.CourierOblique; 34 import org.apache.fop.fonts.base14.CourierBoldOblique; 35 import org.apache.fop.fonts.base14.Symbol; 36 import org.apache.fop.fonts.base14.ZapfDingbats; 37 38 import org.apache.commons.logging.Log; 40 import org.apache.commons.logging.LogFactory; 41 42 import org.apache.avalon.framework.configuration.Configuration; 44 import org.apache.avalon.framework.configuration.ConfigurationException; 45 46 import java.util.List ; 48 49 import javax.xml.transform.Source ; 50 import javax.xml.transform.stream.StreamSource ; 51 52 59 public class FontSetup { 60 61 64 protected static Log log = LogFactory.getLog("org.apache.fop.fonts"); 65 66 76 public static void setup(FontInfo fontInfo, List embedList, FontResolver resolver) { 77 setup(fontInfo, embedList, resolver, false); 78 } 79 80 91 public static void setup(FontInfo fontInfo, List embedList, FontResolver resolver, 92 boolean enableBase14Kerning) { 93 94 fontInfo.addMetrics("F1", new Helvetica(enableBase14Kerning)); 95 fontInfo.addMetrics("F2", new HelveticaOblique(enableBase14Kerning)); 96 fontInfo.addMetrics("F3", new HelveticaBold(enableBase14Kerning)); 97 fontInfo.addMetrics("F4", new HelveticaBoldOblique(enableBase14Kerning)); 98 fontInfo.addMetrics("F5", new TimesRoman(enableBase14Kerning)); 99 fontInfo.addMetrics("F6", new TimesItalic(enableBase14Kerning)); 100 fontInfo.addMetrics("F7", new TimesBold(enableBase14Kerning)); 101 fontInfo.addMetrics("F8", new TimesBoldItalic(enableBase14Kerning)); 102 fontInfo.addMetrics("F9", new Courier(enableBase14Kerning)); 103 fontInfo.addMetrics("F10", new CourierOblique(enableBase14Kerning)); 104 fontInfo.addMetrics("F11", new CourierBold(enableBase14Kerning)); 105 fontInfo.addMetrics("F12", new CourierBoldOblique(enableBase14Kerning)); 106 fontInfo.addMetrics("F13", new Symbol()); 107 fontInfo.addMetrics("F14", new ZapfDingbats()); 108 109 114 115 fontInfo.addFontProperties("F5", "any", "normal", Font.NORMAL); 116 fontInfo.addFontProperties("F6", "any", "italic", Font.NORMAL); 117 fontInfo.addFontProperties("F6", "any", "oblique", Font.NORMAL); 118 fontInfo.addFontProperties("F7", "any", "normal", Font.BOLD); 119 fontInfo.addFontProperties("F8", "any", "italic", Font.BOLD); 120 fontInfo.addFontProperties("F8", "any", "oblique", Font.BOLD); 121 122 fontInfo.addFontProperties("F1", "sans-serif", "normal", Font.NORMAL); 123 fontInfo.addFontProperties("F2", "sans-serif", "oblique", Font.NORMAL); 124 fontInfo.addFontProperties("F2", "sans-serif", "italic", Font.NORMAL); 125 fontInfo.addFontProperties("F3", "sans-serif", "normal", Font.BOLD); 126 fontInfo.addFontProperties("F4", "sans-serif", "oblique", Font.BOLD); 127 fontInfo.addFontProperties("F4", "sans-serif", "italic", Font.BOLD); 128 fontInfo.addFontProperties("F5", "serif", "normal", Font.NORMAL); 129 fontInfo.addFontProperties("F6", "serif", "oblique", Font.NORMAL); 130 fontInfo.addFontProperties("F6", "serif", "italic", Font.NORMAL); 131 fontInfo.addFontProperties("F7", "serif", "normal", Font.BOLD); 132 fontInfo.addFontProperties("F8", "serif", "oblique", Font.BOLD); 133 fontInfo.addFontProperties("F8", "serif", "italic", Font.BOLD); 134 fontInfo.addFontProperties("F9", "monospace", "normal", Font.NORMAL); 135 fontInfo.addFontProperties("F10", "monospace", "oblique", Font.NORMAL); 136 fontInfo.addFontProperties("F10", "monospace", "italic", Font.NORMAL); 137 fontInfo.addFontProperties("F11", "monospace", "normal", Font.BOLD); 138 fontInfo.addFontProperties("F12", "monospace", "oblique", Font.BOLD); 139 fontInfo.addFontProperties("F12", "monospace", "italic", Font.BOLD); 140 141 fontInfo.addFontProperties("F1", "Helvetica", "normal", Font.NORMAL); 142 fontInfo.addFontProperties("F2", "Helvetica", "oblique", Font.NORMAL); 143 fontInfo.addFontProperties("F2", "Helvetica", "italic", Font.NORMAL); 144 fontInfo.addFontProperties("F3", "Helvetica", "normal", Font.BOLD); 145 fontInfo.addFontProperties("F4", "Helvetica", "oblique", Font.BOLD); 146 fontInfo.addFontProperties("F4", "Helvetica", "italic", Font.BOLD); 147 fontInfo.addFontProperties("F5", "Times", "normal", Font.NORMAL); 148 fontInfo.addFontProperties("F6", "Times", "oblique", Font.NORMAL); 149 fontInfo.addFontProperties("F6", "Times", "italic", Font.NORMAL); 150 fontInfo.addFontProperties("F7", "Times", "normal", Font.BOLD); 151 fontInfo.addFontProperties("F8", "Times", "oblique", Font.BOLD); 152 fontInfo.addFontProperties("F8", "Times", "italic", Font.BOLD); 153 fontInfo.addFontProperties("F9", "Courier", "normal", Font.NORMAL); 154 fontInfo.addFontProperties("F10", "Courier", "oblique", Font.NORMAL); 155 fontInfo.addFontProperties("F10", "Courier", "italic", Font.NORMAL); 156 fontInfo.addFontProperties("F11", "Courier", "normal", Font.BOLD); 157 fontInfo.addFontProperties("F12", "Courier", "oblique", Font.BOLD); 158 fontInfo.addFontProperties("F12", "Courier", "italic", Font.BOLD); 159 fontInfo.addFontProperties("F13", "Symbol", "normal", Font.NORMAL); 160 fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", Font.NORMAL); 161 162 167 168 fontInfo.addFontProperties("F5", "Times-Roman", "normal", Font.NORMAL); 169 fontInfo.addFontProperties("F6", "Times-Roman", "oblique", Font.NORMAL); 170 fontInfo.addFontProperties("F6", "Times-Roman", "italic", Font.NORMAL); 171 fontInfo.addFontProperties("F7", "Times-Roman", "normal", Font.BOLD); 172 fontInfo.addFontProperties("F8", "Times-Roman", "oblique", Font.BOLD); 173 fontInfo.addFontProperties("F8", "Times-Roman", "italic", Font.BOLD); 174 fontInfo.addFontProperties("F5", "Times Roman", "normal", Font.NORMAL); 175 fontInfo.addFontProperties("F6", "Times Roman", "oblique", Font.NORMAL); 176 fontInfo.addFontProperties("F6", "Times Roman", "italic", Font.NORMAL); 177 fontInfo.addFontProperties("F7", "Times Roman", "normal", Font.BOLD); 178 fontInfo.addFontProperties("F8", "Times Roman", "oblique", Font.BOLD); 179 fontInfo.addFontProperties("F8", "Times Roman", "italic", Font.BOLD); 180 fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter", 181 "normal", Font.NORMAL); 182 183 184 addConfiguredFonts(fontInfo, embedList, 15, resolver); 185 } 186 187 194 public static void addConfiguredFonts(FontInfo fontInfo, List fontInfoList 195 , int num, FontResolver resolver) { 196 if (fontInfoList == null) { 197 return; } 199 200 if (resolver == null) { 201 resolver = createMinimalFontResolver(); 203 } 204 205 String internalName = null; 206 208 for (int i = 0; i < fontInfoList.size(); i++) { 209 EmbedFontInfo configFontInfo = (EmbedFontInfo) fontInfoList.get(i); 210 211 String metricsFile = configFontInfo.getMetricsFile(); 212 internalName = "F" + num; 213 num++; 214 220 LazyFont font = new LazyFont(configFontInfo.getEmbedFile(), 221 metricsFile, 222 configFontInfo.getKerning(), 223 resolver); 224 fontInfo.addMetrics(internalName, font); 225 226 List triplets = configFontInfo.getFontTriplets(); 227 for (int c = 0; c < triplets.size(); c++) { 228 FontTriplet triplet = (FontTriplet) triplets.get(c); 229 230 if (log.isDebugEnabled()) { 231 log.debug("Registering: " + triplet + " under " + internalName); 232 } 233 fontInfo.addFontProperties(internalName, triplet); 234 } 235 } 236 } 237 238 239 private static FontResolver createMinimalFontResolver() { 240 return new FontResolver() { 241 242 243 public Source resolve(String href) { 244 return new StreamSource (href); 246 } 247 248 }; 249 } 250 256 public static List buildFontListFromConfiguration(Configuration cfg) 257 throws ConfigurationException { 258 List fontList = new java.util.ArrayList (); 259 Configuration[] font = cfg.getChild("fonts").getChildren("font"); 260 for (int i = 0; i < font.length; i++) { 261 Configuration[] triple = font[i].getChildren("font-triplet"); 262 List tripleList = new java.util.ArrayList (); 263 for (int j = 0; j < triple.length; j++) { 264 int weight = FontUtil.parseCSS2FontWeight(triple[j].getAttribute("weight")); 265 tripleList.add(FontInfo.createFontKey(triple[j].getAttribute("name"), 266 triple[j].getAttribute("style"), 267 weight)); 268 } 269 270 EmbedFontInfo efi; 271 efi = new EmbedFontInfo(font[i].getAttribute("metrics-url", null), 272 font[i].getAttributeAsBoolean("kerning", false), 273 tripleList, font[i].getAttribute("embed-url", null)); 274 275 if (log.isDebugEnabled()) { 276 log.debug("Adding font " + efi.getEmbedFile() 277 + ", metric file " + efi.getMetricsFile()); 278 for (int j = 0; j < tripleList.size(); ++j) { 279 FontTriplet triplet = (FontTriplet) tripleList.get(j); 280 log.debug("Font triplet " 281 + triplet.getName() + ", " 282 + triplet.getStyle() + ", " 283 + triplet.getWeight()); 284 } 285 } 286 287 fontList.add(efi); 288 } 289 return fontList; 290 } 291 } 292 293 | Popular Tags |