KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > bridge > SVGAltGlyphHandler


1 /*
2
3    Copyright 2001-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.bridge;
19
20 import java.awt.font.FontRenderContext JavaDoc;
21 import java.text.AttributedCharacterIterator JavaDoc;
22
23 import org.apache.batik.gvt.font.AltGlyphHandler;
24 import org.apache.batik.gvt.font.GVTGlyphVector;
25 import org.apache.batik.gvt.font.Glyph;
26 import org.apache.batik.gvt.font.SVGGVTGlyphVector;
27 import org.apache.batik.util.SVGConstants;
28 import org.w3c.dom.Element JavaDoc;
29
30 /**
31  * SVG font altGlyph handler. This class handles the creation of an alternate
32  * GVTGlyphVector for the altGlyph element.
33  *
34  * @author <a HREF="mailto:bella.robinson@cmis.csiro.au">Bella Robinson</a>
35  * @version $Id: SVGAltGlyphHandler.java,v 1.10 2005/03/03 01:19:52 deweese Exp $
36  */

37 public class SVGAltGlyphHandler implements AltGlyphHandler, SVGConstants {
38
39     private BridgeContext ctx;
40     private Element JavaDoc textElement;
41
42     /**
43      * Constructs an SVGAltGlyphHandler.
44      *
45      * @param ctx The bridge context, this is needed during rendering to find
46      * any referenced glyph elements.
47      * @param textElement The element that contains text to be replaced by the
48      * alternate glyphs. This should be an altGlyph element.
49      */

50     public SVGAltGlyphHandler(BridgeContext ctx, Element JavaDoc textElement) {
51         this.ctx = ctx;
52         this.textElement = textElement;
53     }
54
55     /**
56      * Creates a glyph vector containing the alternate glyphs.
57      *
58      * @param frc The current font render context.
59      * @param fontSize The required font size.
60      * @return The GVTGlyphVector containing the alternate glyphs, or null if
61      * the alternate glyphs could not be found.
62      */

63     public GVTGlyphVector createGlyphVector
64         (FontRenderContext JavaDoc frc, float fontSize,
65          AttributedCharacterIterator JavaDoc aci) {
66         try {
67             if (SVG_NAMESPACE_URI.equals(textElement.getNamespaceURI()) &&
68                 SVG_ALT_GLYPH_TAG.equals(textElement.getLocalName())) {
69                 SVGAltGlyphElementBridge altGlyphBridge
70                     = (SVGAltGlyphElementBridge)ctx.getBridge(textElement);
71                 Glyph[] glyphArray = altGlyphBridge.createAltGlyphArray
72                     (ctx, textElement, fontSize, aci);
73                 if (glyphArray != null) {
74                     return new SVGGVTGlyphVector(null, glyphArray, frc);
75                 }
76             }
77         } catch (SecurityException JavaDoc e) {
78             ctx.getUserAgent().displayError(e);
79             // Throw exception because we do not want to continue
80
// processing. In the case of a SecurityException, the
81
// end user would get a lot of exception like this one.
82
throw e;
83         }
84
85         return null;
86     }
87 }
88
89
Popular Tags