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 1805173 2017-08-16 10:50:04Z ssteiner $ */
19 
20 package org.apache.fop.render.ps;
21 
22 import org.w3c.dom.Element;
23 
24 import org.apache.batik.bridge.BridgeContext;
25 import org.apache.batik.bridge.SVGTextElementBridge;
26 import org.apache.batik.bridge.TextNode;
27 import org.apache.batik.bridge.TextPainter;
28 import org.apache.batik.gvt.GraphicsNode;
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 public class PSTextElementBridge extends SVGTextElementBridge {
36 
37     private TextPainter textPainter;
38 
39     /**
40      * Constructs a new bridge for the <text> element.
41      * @param textPainter the text painter to use
42      */
PSTextElementBridge(TextPainter textPainter)43     public PSTextElementBridge(TextPainter textPainter) {
44         this.textPainter = textPainter;
45     }
46 
47     /**
48      * Create a text element bridge.
49      * This set the text painter on the node if the text is simple.
50      * @param ctx the bridge context
51      * @param e the svg element
52      * @return the text graphics node created by the super class
53      */
createGraphicsNode(BridgeContext ctx, Element e)54     public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
55         GraphicsNode node = super.createGraphicsNode(ctx, e);
56         ((TextNode)node).setTextPainter(getTextPainter());
57         return node;
58     }
59 
getTextPainter()60     private TextPainter getTextPainter() {
61         return this.textPainter;
62     }
63 
64 }
65