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.

TIFFRendererConfig.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 java.util.EnumMap;
  20. import org.apache.xmlgraphics.image.writer.Endianness;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.apps.FOUserAgent;
  23. import org.apache.fop.apps.MimeConstants;
  24. import org.apache.fop.configuration.Configuration;
  25. import org.apache.fop.fonts.DefaultFontConfig;
  26. import org.apache.fop.fonts.DefaultFontConfig.DefaultFontConfigParser;
  27. import org.apache.fop.fonts.FontEventAdapter;
  28. import org.apache.fop.render.RendererConfigOption;
  29. import static org.apache.fop.render.bitmap.TIFFCompressionValue.PACKBITS;
  30. /**
  31. * The renderer configuration object for the TIFF renderer.
  32. */
  33. public final class TIFFRendererConfig extends BitmapRendererConfig {
  34. public enum TIFFRendererOption implements RendererConfigOption {
  35. COMPRESSION("compression", PACKBITS),
  36. /** option to encode one row per strip or a all rows in a single strip*/
  37. SINGLE_STRIP("single-strip", Boolean.FALSE),
  38. /** option to determine whether to use little or big endian encoding */
  39. ENDIANNESS("endianness", Endianness.DEFAULT);
  40. private final String name;
  41. private final Object defaultValue;
  42. private TIFFRendererOption(String name, Object defaultValue) {
  43. this.name = name;
  44. this.defaultValue = defaultValue;
  45. }
  46. public String getName() {
  47. return name;
  48. }
  49. public Object getDefaultValue() {
  50. return defaultValue;
  51. }
  52. }
  53. private final EnumMap<TIFFRendererOption, Object> params
  54. = new EnumMap<TIFFRendererOption, Object>(TIFFRendererOption.class);
  55. private TIFFRendererConfig(DefaultFontConfig fontConfig) {
  56. super(fontConfig);
  57. }
  58. public TIFFCompressionValue getCompressionType() {
  59. return (TIFFCompressionValue) params.get(TIFFRendererOption.COMPRESSION);
  60. }
  61. /**
  62. * @return True if all rows are contained in a single strip, False each strip contains one row or null
  63. * if not set.
  64. */
  65. public Boolean isSingleStrip() {
  66. return (Boolean) params.get(TIFFRendererOption.SINGLE_STRIP);
  67. }
  68. /**
  69. * @return returns an object to determine whether little or big endian encoding is used
  70. */
  71. public Endianness getEndianness() {
  72. return (Endianness) params.get(TIFFRendererOption.ENDIANNESS);
  73. }
  74. /**
  75. * The TIFF renderer configuration parser.
  76. */
  77. public static final class TIFFRendererConfigParser extends BitmapRendererConfigParser {
  78. public TIFFRendererConfigParser() {
  79. super(MimeConstants.MIME_TIFF);
  80. }
  81. private TIFFRendererConfig config;
  82. private void setParam(TIFFRendererOption option, Object value) {
  83. config.params.put(option, value != null ? value : option.getDefaultValue());
  84. }
  85. private String getValue(Configuration cfg, TIFFRendererOption option) {
  86. return cfg.getChild(option.getName()).getValue(null);
  87. }
  88. /** {@inheritDoc} */
  89. public TIFFRendererConfig build(FOUserAgent userAgent, Configuration cfg) throws FOPException {
  90. config = new TIFFRendererConfig(new DefaultFontConfigParser()
  91. .parse(cfg, userAgent.validateStrictly(),
  92. new FontEventAdapter(userAgent.getEventBroadcaster())));
  93. super.build(config, userAgent, cfg);
  94. if (cfg != null) {
  95. setParam(TIFFRendererOption.COMPRESSION,
  96. TIFFCompressionValue.getType(getValue(cfg, TIFFRendererOption.COMPRESSION)));
  97. setParam(TIFFRendererOption.SINGLE_STRIP, Boolean.valueOf(getValue(cfg,
  98. TIFFRendererOption.SINGLE_STRIP)));
  99. setParam(TIFFRendererOption.ENDIANNESS,
  100. Endianness.getEndianType(getValue(cfg, TIFFRendererOption.ENDIANNESS)));
  101. }
  102. return config;
  103. }
  104. }
  105. }