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: PDFBridgeContext.java 1664570 2015-03-06 09:41:07Z lbernardo $ */ 19 20 package org.apache.fop.svg; 21 22 import java.awt.geom.AffineTransform; 23 24 import org.apache.batik.anim.dom.SVGOMDocument; 25 import org.apache.batik.bridge.BridgeContext; 26 import org.apache.batik.bridge.DocumentLoader; 27 import org.apache.batik.bridge.SVGTextElementBridge; 28 import org.apache.batik.bridge.TextPainter; 29 import org.apache.batik.bridge.UserAgent; 30 31 import org.apache.xmlgraphics.image.loader.ImageManager; 32 import org.apache.xmlgraphics.image.loader.ImageSessionContext; 33 34 import org.apache.fop.fonts.FontInfo; 35 36 /** 37 * BridgeContext which registers the custom bridges for PDF output. 38 */ 39 public class PDFBridgeContext extends AbstractFOPBridgeContext { 40 41 /** 42 * Constructs a new bridge context. 43 * @param userAgent the user agent 44 * @param documentLoader the Document Loader to use for referenced documents. 45 * @param fontInfo the font list for the text painter, may be null 46 * in which case text is painted as shapes 47 * @param imageManager an image manager 48 * @param imageSessionContext an image session context 49 * @param linkTransform AffineTransform to properly place links, 50 * may be null 51 */ PDFBridgeContext(UserAgent userAgent, DocumentLoader documentLoader, FontInfo fontInfo, ImageManager imageManager, ImageSessionContext imageSessionContext, AffineTransform linkTransform)52 public PDFBridgeContext(UserAgent userAgent, DocumentLoader documentLoader, 53 FontInfo fontInfo, ImageManager imageManager, 54 ImageSessionContext imageSessionContext, 55 AffineTransform linkTransform) { 56 super(userAgent, documentLoader, fontInfo, 57 imageManager, imageSessionContext, linkTransform); 58 } 59 60 /** 61 * Constructs a new bridge context. 62 * @param userAgent the user agent 63 * @param fontInfo the font list for the text painter, may be null 64 * in which case text is painted as shapes 65 * @param imageManager an image manager 66 * @param imageSessionContext an image session context 67 */ PDFBridgeContext(UserAgent userAgent, FontInfo fontInfo, ImageManager imageManager, ImageSessionContext imageSessionContext)68 public PDFBridgeContext(UserAgent userAgent, FontInfo fontInfo, 69 ImageManager imageManager, ImageSessionContext imageSessionContext) { 70 super(userAgent, fontInfo, imageManager, imageSessionContext); 71 } 72 73 /** 74 * Constructs a new bridge context. 75 * @param userAgent the user agent 76 * @param fontInfo the font list for the text painter, may be null 77 * in which case text is painted as shapes 78 * @param imageManager an image manager 79 * @param imageSessionContext an image session context 80 * @param linkTransform AffineTransform to properly place links, 81 * may be null 82 */ PDFBridgeContext(SVGUserAgent userAgent, FontInfo fontInfo, ImageManager imageManager, ImageSessionContext imageSessionContext, AffineTransform linkTransform)83 public PDFBridgeContext(SVGUserAgent userAgent, FontInfo fontInfo, 84 ImageManager imageManager, ImageSessionContext imageSessionContext, 85 AffineTransform linkTransform) { 86 super(userAgent, fontInfo, imageManager, imageSessionContext, linkTransform); 87 } 88 89 /** {@inheritDoc} */ 90 @Override registerSVGBridges()91 public void registerSVGBridges() { 92 super.registerSVGBridges(); 93 94 if (fontInfo != null) { 95 TextPainter textPainter = new PDFTextPainter(fontInfo); 96 SVGTextElementBridge textElementBridge = new PDFTextElementBridge(textPainter); 97 putBridge(textElementBridge); 98 99 //Batik flow text extension (may not always be available) 100 //putBridge(new PDFBatikFlowTextElementBridge(fontInfo); 101 putElementBridgeConditional( 102 "org.apache.fop.svg.PDFBatikFlowTextElementBridge", 103 "org.apache.batik.extension.svg.BatikFlowTextElementBridge"); 104 105 //SVG 1.2 flow text support 106 //putBridge(new PDFSVG12TextElementBridge(fontInfo)); //-->Batik 1.7 107 putElementBridgeConditional( 108 "org.apache.fop.svg.PDFSVG12TextElementBridge", 109 "org.apache.batik.bridge.svg12.SVG12TextElementBridge"); 110 111 //putBridge(new PDFSVGFlowRootElementBridge(fontInfo)); 112 putElementBridgeConditional( 113 "org.apache.fop.svg.PDFSVGFlowRootElementBridge", 114 "org.apache.batik.bridge.svg12.SVGFlowRootElementBridge"); 115 } 116 117 PDFAElementBridge pdfAElementBridge = new PDFAElementBridge(); 118 if (linkTransform != null) { 119 pdfAElementBridge.setCurrentTransform(linkTransform); 120 } else { 121 pdfAElementBridge.setCurrentTransform(new AffineTransform()); 122 } 123 putBridge(pdfAElementBridge); 124 125 putBridge(new PDFImageElementBridge()); 126 } 127 128 /** {@inheritDoc} */ 129 @Override createBridgeContext()130 public BridgeContext createBridgeContext() { 131 //Retained for pre-Batik-1.7 compatibility 132 return createBridgeContext(null); 133 } 134 135 /** {@inheritDoc} */ 136 @Override createBridgeContext(SVGOMDocument doc)137 public BridgeContext createBridgeContext(SVGOMDocument doc) { 138 // Make sure any 'sub bridge contexts' also have our bridges. 139 return new PDFBridgeContext(getUserAgent(), getDocumentLoader(), 140 fontInfo, 141 getImageManager(), 142 getImageSessionContext(), 143 linkTransform); 144 } 145 146 } 147