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.

AFPBridgeContext.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.afp.svg;
  19. import java.awt.geom.AffineTransform;
  20. import org.apache.batik.bridge.BridgeContext;
  21. import org.apache.batik.bridge.DocumentLoader;
  22. import org.apache.batik.bridge.UserAgent;
  23. import org.apache.batik.gvt.TextPainter;
  24. import org.apache.fop.afp.AFPGraphics2D;
  25. import org.apache.fop.fonts.FontInfo;
  26. import org.apache.fop.svg.AbstractFOPBridgeContext;
  27. import org.apache.xmlgraphics.image.loader.ImageManager;
  28. import org.apache.xmlgraphics.image.loader.ImageSessionContext;
  29. /**
  30. * An AFP specific implementation of a Batik BridgeContext
  31. */
  32. public class AFPBridgeContext extends AbstractFOPBridgeContext {
  33. private final AFPGraphics2D g2d;
  34. /**
  35. * Constructs a new bridge context.
  36. *
  37. * @param userAgent the user agent
  38. * @param fontInfo the font list for the text painter, may be null
  39. * in which case text is painted as shapes
  40. * @param imageManager an image manager
  41. * @param imageSessionContext an image session context
  42. * @param linkTransform AffineTransform to properly place links,
  43. * may be null
  44. * @param g2d an AFPGraphics 2D implementation
  45. */
  46. public AFPBridgeContext(UserAgent userAgent, FontInfo fontInfo,
  47. ImageManager imageManager, ImageSessionContext imageSessionContext,
  48. AffineTransform linkTransform, AFPGraphics2D g2d) {
  49. super(userAgent, fontInfo, imageManager, imageSessionContext, linkTransform);
  50. this.g2d = g2d;
  51. }
  52. /**
  53. * Constructs a new bridge context.
  54. * @param userAgent the user agent
  55. * @param loader the Document Loader to use for referenced documents.
  56. * @param fontInfo the font list for the text painter, may be null
  57. * in which case text is painted as shapes
  58. * @param linkTransform AffineTransform to properly place links,
  59. * may be null
  60. * @param imageManager an image manager
  61. * @param imageSessionContext an image session context
  62. * @param linkTransform AffineTransform to properly place links,
  63. * may be null
  64. * @param an AFPGraphics 2D implementation
  65. */
  66. public AFPBridgeContext(UserAgent userAgent, DocumentLoader documentLoader,
  67. FontInfo fontInfo, ImageManager imageManager,
  68. ImageSessionContext imageSessionContext,
  69. AffineTransform linkTransform, AFPGraphics2D g2d) {
  70. super(userAgent, documentLoader, fontInfo, imageManager, imageSessionContext, linkTransform);
  71. this.g2d = g2d;
  72. }
  73. /** {@inheritDoc} */
  74. public void registerSVGBridges() {
  75. super.registerSVGBridges();
  76. if (fontInfo != null) {
  77. AFPTextHandler textHandler = new AFPTextHandler(fontInfo);
  78. g2d.setCustomTextHandler(textHandler);
  79. TextPainter textPainter = new AFPTextPainter(textHandler);
  80. setTextPainter(textPainter);
  81. putBridge(new AFPTextElementBridge(textPainter));
  82. }
  83. putBridge(new AFPImageElementBridge());
  84. }
  85. /** {@inheritDoc} */
  86. public BridgeContext createBridgeContext() {
  87. return new AFPBridgeContext(getUserAgent(), getDocumentLoader(),
  88. fontInfo,
  89. getImageManager(),
  90. getImageSessionContext(),
  91. linkTransform, g2d);
  92. }
  93. }