01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
10: http://www.apache.org/licenses/LICENSE-2.0
11:
12: Unless required by applicable law or agreed to in writing, software
13: distributed under the License is distributed on an "AS IS" BASIS,
14: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: See the License for the specific language governing permissions and
16: limitations under the License.
17:
18: */
19: package org.apache.batik.bridge;
20:
21: import java.util.List;
22:
23: import org.apache.batik.gvt.font.GVTFontFamily;
24: import org.w3c.dom.Element;
25:
26: /**
27: * This class represents a <font-face> element or @font-face rule
28: *
29: * @author <a href="mailto:bella.robinson@cmis.csiro.au">Bella Robinson</a>
30: * @version $Id: SVGFontFace.java 475477 2006-11-15 22:44:28Z cam $
31: */
32: public class SVGFontFace extends FontFace {
33:
34: Element fontFaceElement;
35: GVTFontFamily fontFamily = null;
36:
37: /**
38: * Constructes an SVGFontFace with the specfied font-face attributes.
39: */
40: public SVGFontFace(Element fontFaceElement, List srcs,
41: String familyName, float unitsPerEm, String fontWeight,
42: String fontStyle, String fontVariant, String fontStretch,
43: float slope, String panose1, float ascent, float descent,
44: float strikethroughPosition, float strikethroughThickness,
45: float underlinePosition, float underlineThickness,
46: float overlinePosition, float overlineThickness) {
47: super (srcs, familyName, unitsPerEm, fontWeight, fontStyle,
48: fontVariant, fontStretch, slope, panose1, ascent,
49: descent, strikethroughPosition, strikethroughThickness,
50: underlinePosition, underlineThickness,
51: overlinePosition, overlineThickness);
52: this .fontFaceElement = fontFaceElement;
53: }
54:
55: /**
56: * Returns the font associated with this rule or element.
57: */
58: public GVTFontFamily getFontFamily(BridgeContext ctx) {
59: if (fontFamily != null)
60: return fontFamily;
61:
62: Element fontElt = SVGUtilities
63: .getParentElement(fontFaceElement);
64: if (fontElt.getNamespaceURI().equals(SVG_NAMESPACE_URI)
65: && fontElt.getLocalName().equals(SVG_FONT_TAG)) {
66: return new SVGFontFamily(this , fontElt, ctx);
67: }
68:
69: fontFamily = super .getFontFamily(ctx);
70: return fontFamily;
71: }
72:
73: public Element getFontFaceElement() {
74: return fontFaceElement;
75: }
76:
77: /**
78: * Default implementation uses the root element of the document
79: * associated with BridgeContext. This is useful for CSS case.
80: */
81: protected Element getBaseElement(BridgeContext ctx) {
82: if (fontFaceElement != null)
83: return fontFaceElement;
84: return super.getBaseElement(ctx);
85: }
86:
87: }
|