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

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