Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

PDFRendererOptionsConfig.java 5.1KB

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