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 4.1KB

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