Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PDFRendererOptionsConfig.java 4.4KB

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