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

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