You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PDFBridgeContext.java 5.8KB

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