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.

AbstractFOPBridgeContext.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 java.lang.reflect.Constructor;
  21. import org.apache.batik.bridge.Bridge;
  22. import org.apache.batik.bridge.BridgeContext;
  23. import org.apache.batik.bridge.DocumentLoader;
  24. import org.apache.batik.bridge.UserAgent;
  25. import org.apache.fop.fonts.FontInfo;
  26. import org.apache.xmlgraphics.image.loader.ImageManager;
  27. import org.apache.xmlgraphics.image.loader.ImageSessionContext;
  28. /**
  29. * A FOP base implementation of a Batik BridgeContext.
  30. */
  31. public abstract class AbstractFOPBridgeContext extends BridgeContext {
  32. /** The font list. */
  33. protected final FontInfo fontInfo;
  34. protected final ImageManager imageManager;
  35. protected final ImageSessionContext imageSessionContext;
  36. protected final AffineTransform linkTransform;
  37. /**
  38. * Constructs a new bridge context.
  39. * @param userAgent the user agent
  40. * @param loader the Document Loader to use for referenced documents.
  41. * @param fontInfo the font list for the text painter, may be null
  42. * in which case text is painted as shapes
  43. * @param linkTransform AffineTransform to properly place links,
  44. * may be null
  45. * @param imageManager an image manager
  46. * @param imageSessionContext an image session context
  47. * @param linkTransform AffineTransform to properly place links,
  48. * may be null
  49. */
  50. public AbstractFOPBridgeContext(UserAgent userAgent,
  51. DocumentLoader loader,
  52. FontInfo fontInfo,
  53. ImageManager imageManager,
  54. ImageSessionContext imageSessionContext,
  55. AffineTransform linkTransform) {
  56. super(userAgent, loader);
  57. this.fontInfo = fontInfo;
  58. this.imageManager = imageManager;
  59. this.imageSessionContext = imageSessionContext;
  60. this.linkTransform = linkTransform;
  61. }
  62. /**
  63. * Constructs a new bridge context.
  64. * @param userAgent the user agent
  65. * @param fontInfo the font list for the text painter, may be null
  66. * in which case text is painted as shapes
  67. * @param imageManager an image manager
  68. * @param imageSessionContext an image session context
  69. * @param linkTransform AffineTransform to properly place links,
  70. * may be null
  71. */
  72. public AbstractFOPBridgeContext(UserAgent userAgent,
  73. FontInfo fontInfo,
  74. ImageManager imageManager,
  75. ImageSessionContext imageSessionContext,
  76. AffineTransform linkTransform) {
  77. super(userAgent);
  78. this.fontInfo = fontInfo;
  79. this.imageManager = imageManager;
  80. this.imageSessionContext = imageSessionContext;
  81. this.linkTransform = linkTransform;
  82. }
  83. /**
  84. * Constructs a new bridge context.
  85. * @param userAgent the user agent
  86. * @param fontInfo the font list for the text painter, may be null
  87. * in which case text is painted as shapes
  88. * @param imageManager an image manager
  89. * @param imageSessionContext an image session context
  90. */
  91. public AbstractFOPBridgeContext(UserAgent userAgent,
  92. FontInfo fontInfo,
  93. ImageManager imageManager,
  94. ImageSessionContext imageSessionContext) {
  95. this(userAgent, fontInfo, imageManager, imageSessionContext, null);
  96. }
  97. /**
  98. * Returns the ImageManager to be used by the ImageElementBridge.
  99. * @return the image manager
  100. */
  101. public ImageManager getImageManager() {
  102. return this.imageManager;
  103. }
  104. /**
  105. * Returns the ImageSessionContext to be used by the ImageElementBridge.
  106. * @return the image session context
  107. */
  108. public ImageSessionContext getImageSessionContext() {
  109. return this.imageSessionContext;
  110. }
  111. protected void putElementBridgeConditional(String className, String testFor) {
  112. try {
  113. Class.forName(testFor);
  114. //if we get here the test class is available
  115. Class clazz = Class.forName(className);
  116. Constructor constructor = clazz.getConstructor(new Class[] {FontInfo.class});
  117. putBridge((Bridge)constructor.newInstance(new Object[] {fontInfo}));
  118. } catch (Throwable t) {
  119. //simply ignore (bridges instantiated over this method are optional)
  120. }
  121. }
  122. // Make sure any 'sub bridge contexts' also have our bridges.
  123. //TODO There's no matching method in the super-class here
  124. public abstract BridgeContext createBridgeContext();
  125. }