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.

TIFFRendererConfigurator.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.bitmap;
  19. import org.apache.commons.logging.Log;
  20. import org.apache.commons.logging.LogFactory;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.apps.FOUserAgent;
  23. import org.apache.fop.render.Renderer;
  24. import org.apache.fop.render.RendererConfig.RendererConfigParser;
  25. import org.apache.fop.render.bitmap.TIFFRendererConfig.TIFFRendererConfigParser;
  26. import org.apache.fop.render.intermediate.IFDocumentHandler;
  27. import static org.apache.fop.render.bitmap.TIFFCompressionValue.NONE;
  28. /**
  29. * TIFF Renderer configurator
  30. */
  31. public class TIFFRendererConfigurator extends BitmapRendererConfigurator {
  32. private static final Log LOG = LogFactory.getLog(TIFFRendererConfigurator.class);
  33. /**
  34. * Default constructor
  35. * @param userAgent user agent
  36. */
  37. public TIFFRendererConfigurator(FOUserAgent userAgent, RendererConfigParser rendererConfigParser) {
  38. super(userAgent, rendererConfigParser);
  39. }
  40. /**
  41. * Configure the TIFF renderer. Get the configuration to be used for
  42. * compression
  43. * @param renderer tiff renderer
  44. * @throws FOPException fop exception
  45. * {@inheritDoc}
  46. */
  47. public void configure(Renderer renderer) throws FOPException {
  48. final TIFFRendererConfig config = (TIFFRendererConfig) getRendererConfig(renderer);
  49. if (config != null) {
  50. TIFFRenderer tiffRenderer = (TIFFRenderer) renderer;
  51. setCompressionMethod(config.getCompressionType(), tiffRenderer.getRenderingSettings());
  52. }
  53. super.configure(renderer);
  54. }
  55. private void setCompressionMethod(TIFFCompressionValue compression,
  56. BitmapRenderingSettings settings) throws FOPException {
  57. if (compression != null) {
  58. if (compression != NONE) {
  59. settings.setCompressionMethod(compression.getName());
  60. }
  61. if (LOG.isInfoEnabled()) {
  62. LOG.info("TIFF compression set to " + compression.getName());
  63. }
  64. if (compression.hasCCITTCompression()) {
  65. settings.setBufferedImageType(compression.getImageType());
  66. }
  67. }
  68. }
  69. private boolean isSingleStrip(TIFFRendererConfig config) {
  70. Boolean singleRowPerStrip = config.isSingleStrip();
  71. return singleRowPerStrip == null ? false : singleRowPerStrip;
  72. }
  73. @Override
  74. public void configure(IFDocumentHandler documentHandler) throws FOPException {
  75. final TIFFRendererConfig config = (TIFFRendererConfig) getRendererConfig(documentHandler);
  76. if (config != null) {
  77. TIFFDocumentHandler tiffHandler = (TIFFDocumentHandler) documentHandler;
  78. BitmapRenderingSettings settings = tiffHandler.getSettings();
  79. configure(documentHandler, settings, new TIFFRendererConfigParser());
  80. setCompressionMethod(config.getCompressionType(), settings);
  81. settings.getWriterParams().setSingleStrip(isSingleStrip(config));
  82. }
  83. }
  84. }