KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > ps > PSTextElementBridge


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 /* $Id: PSTextElementBridge.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.ps;
21
22 import org.apache.batik.bridge.SVGTextElementBridge;
23 import org.apache.batik.bridge.BridgeContext;
24 import org.apache.batik.gvt.GraphicsNode;
25 import org.apache.batik.gvt.TextNode;
26
27 import org.w3c.dom.Element JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29
30 /**
31  * Bridge class for the <text> element.
32  * This bridge will use the direct text painter if the text
33  * for the element is simple.
34  *
35  * @author <a HREF="mailto:fop-dev@xml.apache.org">Apache XML FOP Development Team</a>
36  * @version $Id: PSTextElementBridge.java 426576 2006-07-28 15:44:37Z jeremias $
37  */

38 public class PSTextElementBridge extends SVGTextElementBridge {
39     
40     private PSTextPainter textPainter;
41
42     /**
43      * Constructs a new bridge for the &lt;text> element.
44      * @param textPainter the text painter to use
45      */

46     public PSTextElementBridge(PSTextPainter textPainter) {
47         this.textPainter = textPainter;
48     }
49
50     /**
51      * Create a text element bridge.
52      * This set the text painter on the node if the text is simple.
53      * @param ctx the bridge context
54      * @param e the svg element
55      * @return the text graphics node created by the super class
56      */

57     public GraphicsNode createGraphicsNode(BridgeContext ctx, Element JavaDoc e) {
58         GraphicsNode node = super.createGraphicsNode(ctx, e);
59         /* this code is worthless I think. PSTextPainter does a much better job
60          * at determining whether to stroke or not. */

61         if (true/*node != null && isSimple(ctx, e, node)*/) {
62             ((TextNode)node).setTextPainter(getTextPainter());
63         }
64         return node;
65     }
66
67     private PSTextPainter getTextPainter() {
68         return this.textPainter;
69     }
70
71     /**
72      * Check if text element contains simple text.
73      * This checks the children of the text element to determine
74      * if the text is simple. The text is simple if it can be rendered
75      * with basic text drawing algorithms. This means there are no
76      * alternate characters, the font is known and there are no effects
77      * applied to the text.
78      *
79      * @param ctx the bridge context
80      * @param element the svg text element
81      * @param node the graphics node
82      * @return true if this text is simple of false if it cannot be
83      * easily rendered using normal drawString on the PDFGraphics2D
84      */

85     private boolean isSimple(BridgeContext ctx, Element JavaDoc element, GraphicsNode node) {
86         for (Node n = element.getFirstChild();
87                 n != null;
88                 n = n.getNextSibling()) {
89
90             switch (n.getNodeType()) {
91             case Node.ELEMENT_NODE:
92
93                 if (n.getLocalName().equals(SVG_TSPAN_TAG)
94                         || n.getLocalName().equals(SVG_ALT_GLYPH_TAG)) {
95                     return false;
96                 } else if (n.getLocalName().equals(SVG_TEXT_PATH_TAG)) {
97                     return false;
98                 } else if (n.getLocalName().equals(SVG_TREF_TAG)) {
99                     return false;
100                 }
101                 break;
102             case Node.TEXT_NODE:
103             case Node.CDATA_SECTION_NODE:
104             default:
105             }
106         }
107
108         /*if (CSSUtilities.convertFilter(element, node, ctx) != null) {
109             return false;
110         }*/

111
112         return true;
113     }
114 }
115
116
Popular Tags