KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > compiler > FontCompiler


1 /******************************************************************************
2  * FontNode.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.compiler;
11
12 import org.openlaszlo.xml.internal.XMLUtils;
13 import org.jdom.Element;
14 import java.io.File JavaDoc;
15 import java.io.FileNotFoundException JavaDoc;
16 import java.util.*;
17
18 /**
19  * Compiler for <code>font</code> elements.
20  *
21  * @author Eric Bloch
22  */

23 class FontCompiler extends ElementCompiler {
24     FontCompiler(CompilationEnvironment env) {
25         super(env);
26     }
27
28     /** Returns true iff this class applies to this element.
29      * @param element an element
30      * @return see doc
31      */

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         // Can't use <font> in a loadable library
40
String JavaDoc name = XMLUtils.requireAttributeValue(element, "name");
41         String JavaDoc 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 JavaDoc name, Element element) {
63         String JavaDoc style = element.getAttributeValue("style");
64         try {
65             String JavaDoc 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 JavaDoc e) {
72             throw new CompilationError(element, e);
73         }
74     }
75 }
76
Popular Tags