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.6KB

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