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.

PDFSVGHandler.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.render.pdf;
  19. import java.io.OutputStream;
  20. import java.util.Map;
  21. import org.apache.commons.logging.Log;
  22. import org.apache.commons.logging.LogFactory;
  23. import org.apache.fop.configuration.Configuration;
  24. import org.apache.fop.fonts.FontInfo;
  25. import org.apache.fop.pdf.PDFDocument;
  26. import org.apache.fop.pdf.PDFPage;
  27. import org.apache.fop.pdf.PDFResourceContext;
  28. import org.apache.fop.render.AbstractGenericSVGHandler;
  29. import org.apache.fop.render.ImageHandlerUtil;
  30. import org.apache.fop.render.Renderer;
  31. import org.apache.fop.render.RendererContext;
  32. import org.apache.fop.render.RendererContextConstants;
  33. /**
  34. * PDF XML handler for SVG (uses Apache Batik).
  35. * This handler handles XML for foreign objects when rendering to PDF.
  36. * It renders SVG to the PDF document using the PDFGraphics2D.
  37. * The properties from the PDF renderer are subject to change.
  38. */
  39. public class PDFSVGHandler extends AbstractGenericSVGHandler
  40. implements PDFRendererContextConstants {
  41. /** logging instance */
  42. private static Log log = LogFactory.getLog(PDFSVGHandler.class);
  43. /**
  44. * Get the pdf information from the render context.
  45. *
  46. * @param context the renderer context
  47. * @return the pdf information retrieved from the context
  48. */
  49. public static PDFInfo getPDFInfo(RendererContext context) {
  50. PDFInfo pdfi = new PDFInfo();
  51. pdfi.pdfDoc = (PDFDocument)context.getProperty(PDF_DOCUMENT);
  52. pdfi.outputStream = (OutputStream)context.getProperty(OUTPUT_STREAM);
  53. //pdfi.pdfState = (PDFState)context.getProperty(PDF_STATE);
  54. pdfi.pdfPage = (PDFPage)context.getProperty(PDF_PAGE);
  55. pdfi.pdfContext = (PDFResourceContext)context.getProperty(PDF_CONTEXT);
  56. //pdfi.currentStream = (PDFStream)context.getProperty(PDF_STREAM);
  57. pdfi.width = (Integer) context.getProperty(WIDTH);
  58. pdfi.height = (Integer) context.getProperty(HEIGHT);
  59. pdfi.fi = (FontInfo)context.getProperty(PDF_FONT_INFO);
  60. pdfi.currentFontName = (String)context.getProperty(PDF_FONT_NAME);
  61. pdfi.currentFontSize = (Integer) context.getProperty(PDF_FONT_SIZE);
  62. pdfi.currentXPosition = (Integer) context.getProperty(XPOS);
  63. pdfi.currentYPosition = (Integer) context.getProperty(YPOS);
  64. pdfi.cfg = (Configuration)context.getProperty(HANDLER_CONFIGURATION);
  65. Map foreign = (Map)context.getProperty(RendererContextConstants.FOREIGN_ATTRIBUTES);
  66. pdfi.paintAsBitmap = ImageHandlerUtil.isConversionModeBitmap(foreign);
  67. return pdfi;
  68. }
  69. /**
  70. * PDF information structure for drawing the XML document.
  71. */
  72. public static class PDFInfo {
  73. /** see PDF_DOCUMENT */
  74. public PDFDocument pdfDoc;
  75. /** see OUTPUT_STREAM */
  76. public OutputStream outputStream;
  77. /** see PDF_PAGE */
  78. public PDFPage pdfPage;
  79. /** see PDF_CONTEXT */
  80. public PDFResourceContext pdfContext;
  81. /** see PDF_STREAM */
  82. //public PDFStream currentStream;
  83. /** see PDF_WIDTH */
  84. public int width;
  85. /** see PDF_HEIGHT */
  86. public int height;
  87. /** see PDF_FONT_INFO */
  88. public FontInfo fi;
  89. /** see PDF_FONT_NAME */
  90. public String currentFontName;
  91. /** see PDF_FONT_SIZE */
  92. public int currentFontSize;
  93. /** see PDF_XPOS */
  94. public int currentXPosition;
  95. /** see PDF_YPOS */
  96. public int currentYPosition;
  97. /** see PDF_HANDLER_CONFIGURATION */
  98. public Configuration cfg;
  99. /** true if SVG should be rendered as a bitmap instead of natively */
  100. public boolean paintAsBitmap;
  101. }
  102. /** {@inheritDoc} */
  103. public boolean supportsRenderer(Renderer renderer) {
  104. return false;
  105. }
  106. }