1 4 5 9 10 package org.openlaszlo.compiler; 11 12 import org.openlaszlo.xml.internal.XMLUtils; 13 import org.jdom.Element; 14 import java.io.File ; 15 import java.io.FileNotFoundException ; 16 import java.util.*; 17 18 23 class FontCompiler extends ElementCompiler { 24 FontCompiler(CompilationEnvironment env) { 25 super(env); 26 } 27 28 32 public static boolean isElement(Element element) { 33 return element.getName().equals("font"); 34 } 35 36 public void compile(Element element) 37 throws CompilationError 38 { 39 String name = XMLUtils.requireAttributeValue(element, "name"); 41 String src = element.getAttributeValue("src"); 42 43 if (mEnv.isImportLib()) { 44 mEnv.warn("A loadable library cannot embed fonts; If you want to use this font, add it to the main application sources.", element); 45 } 46 47 if (!mEnv.getEmbedFonts() || 48 "true".equals(element.getAttributeValue("device"))) { 49 mEnv.getGenerator().setDeviceFont(name); 50 } else { 51 52 if (src != null) { 53 compileFont(name, element); 54 } 55 for (Iterator iter = element.getChildren("face", element.getNamespace()).iterator(); 56 iter.hasNext(); ) { 57 compileFont(name, (Element) iter.next()); 58 } 59 } 60 } 61 62 private void compileFont(String name, Element element) { 63 String style = element.getAttributeValue("style"); 64 try { 65 String path = mEnv.resolveReference(element).getAbsolutePath(); 66 Element info = new Element("resolve"); 67 info.setAttribute("src", element.getAttributeValue("src")); 68 info.setAttribute("pathname", mEnv.resolveReference(element).toString()); 69 mEnv.getCanvas().addInfo(info); 70 mEnv.getGenerator().importFontStyle(path, name, style, mEnv); 71 } catch (FileNotFoundException e) { 72 throw new CompilationError(element, e); 73 } 74 } 75 } 76 | Popular Tags |