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.

PDFRendererOptionsConfig.java 4.5KB

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.pdf;
  19. import java.net.URI;
  20. import java.util.EnumMap;
  21. import java.util.List;
  22. import java.util.Map;
  23. import org.apache.fop.pdf.PDFAMode;
  24. import org.apache.fop.pdf.PDFEncryptionParams;
  25. import org.apache.fop.pdf.PDFXMode;
  26. import org.apache.fop.pdf.Version;
  27. import static org.apache.fop.render.pdf.PDFRendererOption.DISABLE_SRGB_COLORSPACE;
  28. import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST;
  29. import static org.apache.fop.render.pdf.PDFRendererOption.MERGE_FONTS;
  30. import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE;
  31. import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE;
  32. import static org.apache.fop.render.pdf.PDFRendererOption.PDF_X_MODE;
  33. import static org.apache.fop.render.pdf.PDFRendererOption.VERSION;
  34. /**
  35. * The renderer options configuration data.
  36. */
  37. public final class PDFRendererOptionsConfig {
  38. static final PDFRendererOptionsConfig DEFAULT;
  39. static {
  40. final EnumMap<PDFRendererOption, Object> props
  41. = new EnumMap<PDFRendererOption, Object>(PDFRendererOption.class);
  42. for (PDFRendererOption option : PDFRendererOption.values()) {
  43. props.put(option, option.getDefaultValue());
  44. }
  45. DEFAULT = new PDFRendererOptionsConfig(props, null);
  46. }
  47. private final Map<PDFRendererOption, Object> properties
  48. = new EnumMap<PDFRendererOption, Object>(PDFRendererOption.class);
  49. private final PDFEncryptionParams encryptionConfig;
  50. PDFRendererOptionsConfig(Map<PDFRendererOption, Object> props,
  51. PDFEncryptionParams encryptionParams) {
  52. properties.putAll(props);
  53. this.encryptionConfig = copyPDFEncryptionParams(encryptionParams);
  54. }
  55. private static PDFEncryptionParams copyPDFEncryptionParams(PDFEncryptionParams source) {
  56. return source == null ? null : new PDFEncryptionParams(source);
  57. }
  58. PDFRendererOptionsConfig merge(PDFRendererOptionsConfig config) {
  59. if (config == null) {
  60. return this;
  61. } else {
  62. return new PDFRendererOptionsConfig(merge(this.properties, config.properties),
  63. config.getEncryptionParameters() == null
  64. ? copyPDFEncryptionParams(this.encryptionConfig)
  65. : copyPDFEncryptionParams(config.getEncryptionParameters()));
  66. }
  67. }
  68. private static Map<PDFRendererOption, Object> merge(
  69. Map<PDFRendererOption, Object> first, Map<PDFRendererOption, Object> second) {
  70. final EnumMap<PDFRendererOption, Object> merged
  71. = new EnumMap<PDFRendererOption, Object>(PDFRendererOption.class);
  72. for (PDFRendererOption option : PDFRendererOption.values()) {
  73. Object value = second.get(option);
  74. if (value != null) {
  75. merged.put(option, value);
  76. } else {
  77. merged.put(option, first.get(option));
  78. }
  79. }
  80. return merged;
  81. }
  82. public Map<String, List<String>> getFilterMap() {
  83. return (Map<String, List<String>>) properties.get(FILTER_LIST);
  84. }
  85. public PDFAMode getPDFAMode() {
  86. return (PDFAMode) properties.get(PDF_A_MODE);
  87. }
  88. public PDFXMode getPDFXMode() {
  89. return (PDFXMode) properties.get(PDF_X_MODE);
  90. }
  91. public PDFEncryptionParams getEncryptionParameters() {
  92. return encryptionConfig;
  93. }
  94. public URI getOutputProfileURI() {
  95. return (URI) properties.get(OUTPUT_PROFILE);
  96. }
  97. public Boolean getDisableSRGBColorSpace() {
  98. return (Boolean) properties.get(DISABLE_SRGB_COLORSPACE);
  99. }
  100. public Version getPDFVersion() {
  101. return (Version) properties.get(VERSION);
  102. }
  103. public Boolean getMergeFontsEnabled() {
  104. return (Boolean)properties.get(MERGE_FONTS);
  105. }
  106. }