01: /* -*- mode: Java; c-basic-offset: 2; -*- */
02:
03: /**
04: * LZX Fonts
05: */package org.openlaszlo.compiler;
06:
07: import org.openlaszlo.xml.internal.XMLUtils;
08: import org.jdom.Element;
09: import java.io.File;
10: import java.io.FileNotFoundException;
11: import java.util.*;
12:
13: /**
14: * Compiler for <code>font</code> elements.
15: *
16: * @author Eric Bloch
17: */
18: class FontCompiler extends ElementCompiler {
19: FontCompiler(CompilationEnvironment env) {
20: super (env);
21: }
22:
23: /** Returns true iff this class applies to this element.
24: * @param element an element
25: * @return see doc
26: */
27: public static boolean isElement(Element element) {
28: return element.getName().equals("font");
29: }
30:
31: public void compile(Element element) throws CompilationError {
32: // Can't use <font> in a loadable library
33: String name = XMLUtils.requireAttributeValue(element, "name");
34: String src = element.getAttributeValue("src");
35:
36: if (!mEnv.getEmbedFonts()
37: || "true".equals(element.getAttributeValue("device"))) {
38: mEnv.getGenerator().setDeviceFont(name);
39: } else {
40:
41: if (src != null) {
42: compileFont(name, element);
43: }
44: // Check if children are valid tags to be contained
45: mEnv.checkValidChildContainment(element);
46:
47: for (Iterator iter = element.getChildren("face",
48: element.getNamespace()).iterator(); iter.hasNext();) {
49: compileFont(name, (Element) iter.next());
50: }
51: }
52: }
53:
54: private void compileFont(String name, Element element) {
55: String style = element.getAttributeValue("style");
56: try {
57: String path = mEnv.resolveReference(element)
58: .getAbsolutePath();
59: if (mEnv.isCanvas()) {
60: Element info = new Element("resolve");
61: info.setAttribute("src", element
62: .getAttributeValue("src"));
63: info.setAttribute("pathname", mEnv.resolveReference(
64: element).toString());
65: mEnv.getCanvas().addInfo(info);
66: }
67: mEnv.getGenerator()
68: .importFontStyle(path, name, style, mEnv);
69: } catch (FileNotFoundException e) {
70: throw new CompilationError(element, e);
71: }
72: }
73: }
74:
75: /**
76: * @copyright Copyright 2001-2007 Laszlo Systems, Inc. All Rights
77: * Reserved. Use is subject to license terms.
78: */
|