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: PSSVGFlowRootElementBridge.java 1664570 2015-03-06 09:41:07Z lbernardo $ */ 19 20 package org.apache.fop.render.ps; 21 22 import java.text.AttributedCharacterIterator; 23 import java.util.List; 24 25 import org.apache.batik.bridge.FlowTextPainter; 26 import org.apache.batik.bridge.TextNode; 27 import org.apache.batik.bridge.TextPainter; 28 import org.apache.batik.bridge.svg12.SVGFlowRootElementBridge; 29 import org.apache.batik.gvt.GraphicsNode; 30 31 import org.apache.fop.fonts.FontInfo; 32 33 /** 34 * Element Bridge for SVG 1.2 flow text, so those texts can be painted using 35 * PDF primitives. 36 */ 37 public class PSSVGFlowRootElementBridge extends SVGFlowRootElementBridge { 38 39 private PSTextPainter textPainter; 40 41 /** 42 * Main Constructor. 43 * @param fontInfo the font directory 44 */ PSSVGFlowRootElementBridge(FontInfo fontInfo)45 public PSSVGFlowRootElementBridge(FontInfo fontInfo) { 46 this.textPainter = new PSFlowTextPainter(fontInfo); 47 } 48 49 /** {@inheritDoc} */ instantiateGraphicsNode()50 protected GraphicsNode instantiateGraphicsNode() { 51 GraphicsNode node = super.instantiateGraphicsNode(); 52 if (node != null) { 53 //Set our own text painter 54 ((TextNode)node).setTextPainter(getTextPainter()); 55 } 56 return node; 57 } 58 59 /** 60 * Returns the text painter used by this bridge. 61 * @return the text painter 62 */ getTextPainter()63 public TextPainter getTextPainter() { 64 return this.textPainter; 65 } 66 67 private class PSFlowTextPainter extends PSTextPainter { 68 69 /** 70 * Main constructor 71 * @param fontInfo the font directory 72 */ PSFlowTextPainter(FontInfo fontInfo)73 public PSFlowTextPainter(FontInfo fontInfo) { 74 super(fontInfo); 75 } 76 77 /** {@inheritDoc} */ getTextRuns(TextNode node, AttributedCharacterIterator aci)78 public List getTextRuns(TextNode node, AttributedCharacterIterator aci) { 79 //Text runs are delegated to the normal FlowTextPainter, we just paint the text. 80 FlowTextPainter delegate = (FlowTextPainter)FlowTextPainter.getInstance(); 81 return delegate.getTextRuns(node, aci); 82 } 83 84 } 85 86 } 87