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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.avalon.framework.configuration.Configuration;
  21. import org.apache.xmlgraphics.util.MimeConstants;
  22. import org.apache.fop.apps.FOPException;
  23. import org.apache.fop.apps.FOUserAgent;
  24. import org.apache.fop.fonts.DefaultFontConfig;
  25. import org.apache.fop.fonts.DefaultFontConfig.DefaultFontConfigParser;
  26. import org.apache.fop.render.RendererConfigOption;
  27. /**
  28. * The renderer configuration object for the TIFF renderer.
  29. */
  30. public final class TIFFRendererConfig extends BitmapRendererConfig {
  31. public enum TIFFRendererOption implements RendererConfigOption {
  32. COMPRESSION("compression", TIFFCompressionValue.PACKBITS);
  33. private final String name;
  34. private final Object defaultValue;
  35. private TIFFRendererOption(String name, Object defaultValue) {
  36. this.name = name;
  37. this.defaultValue = defaultValue;
  38. }
  39. public String getName() {
  40. return name;
  41. }
  42. public Object getDefaultValue() {
  43. return defaultValue;
  44. }
  45. }
  46. private final EnumMap<TIFFRendererOption, Object> params
  47. = new EnumMap<TIFFRendererOption, Object>(TIFFRendererOption.class);
  48. private TIFFRendererConfig(DefaultFontConfig fontConfig) {
  49. super(fontConfig);
  50. }
  51. public TIFFCompressionValue getCompressionType() {
  52. return (TIFFCompressionValue) params.get(TIFFRendererOption.COMPRESSION);
  53. }
  54. /**
  55. * The TIFF renderer configuration parser.
  56. */
  57. public static final class TIFFRendererConfigParser extends BitmapRendererConfigParser {
  58. public TIFFRendererConfigParser() {
  59. super(MimeConstants.MIME_TIFF);
  60. }
  61. private TIFFRendererConfig config;
  62. private void setParam(TIFFRendererOption option, Object value) {
  63. config.params.put(option, value != null ? value : option.getDefaultValue());
  64. }
  65. private String getValue(Configuration cfg, TIFFRendererOption option) {
  66. return cfg.getChild(option.getName()).getValue(null);
  67. }
  68. /** {@inheritDoc} */
  69. public TIFFRendererConfig build(FOUserAgent userAgent, Configuration cfg) throws FOPException {
  70. config = new TIFFRendererConfig(new DefaultFontConfigParser()
  71. .parse(cfg, userAgent.validateStrictly()));
  72. super.build(config, userAgent, cfg);
  73. if (cfg != null) {
  74. setParam(TIFFRendererOption.COMPRESSION,
  75. TIFFCompressionValue.getType(getValue(cfg, TIFFRendererOption.COMPRESSION)));
  76. }
  77. return config;
  78. }
  79. }
  80. }