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.

PDFRendererOption.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.net.URISyntaxException;
  21. import org.apache.fop.apps.io.InternalResourceResolver;
  22. import org.apache.fop.pdf.PDFAMode;
  23. import org.apache.fop.pdf.PDFUAMode;
  24. import org.apache.fop.pdf.PDFVTMode;
  25. import org.apache.fop.pdf.PDFXMode;
  26. import org.apache.fop.pdf.Version;
  27. import org.apache.fop.render.RendererConfigOption;
  28. public enum PDFRendererOption implements RendererConfigOption {
  29. FILTER_LIST("filterList", null) {
  30. @Override
  31. Object deserialize(String value) {
  32. throw new UnsupportedOperationException();
  33. }
  34. },
  35. /** Rendering Options key for the PDF/A mode, default: {@link PDFAMode#DISABLED} */
  36. PDF_A_MODE("pdf-a-mode", PDFAMode.DISABLED) {
  37. @Override
  38. PDFAMode deserialize(String value) {
  39. return PDFAMode.getValueOf(value);
  40. }
  41. },
  42. PDF_UA_MODE("pdf-ua-mode", PDFUAMode.DISABLED) {
  43. @Override
  44. PDFUAMode deserialize(String value) {
  45. return PDFUAMode.getValueOf(value);
  46. }
  47. },
  48. /** Rendering Options key for the PDF/X mode, default: {@link PDFXMode#DISABLED} */
  49. PDF_X_MODE("pdf-x-mode", PDFXMode.DISABLED) {
  50. @Override
  51. PDFXMode deserialize(String value) {
  52. return PDFXMode.getValueOf(value);
  53. }
  54. },
  55. /** Rendering Options key for the PDF/VT mode, default: {@link PDFVTMode#DISABLED} */
  56. PDF_VT_MODE("pdf-vt-mode", PDFVTMode.DISABLED) {
  57. @Override
  58. PDFVTMode deserialize(String value) {
  59. return PDFVTMode.getValueOf(value);
  60. }
  61. },
  62. /** PDF version entry: specify the version of the PDF document created, datatype: String */
  63. VERSION("version") {
  64. @Override
  65. Version deserialize(String value) {
  66. return Version.getValueOf(value);
  67. }
  68. },
  69. /**
  70. * Rendering Options key for disabling the sRGB color space (only possible if no PDF/A or
  71. * PDF/X profile is active), default: false
  72. */
  73. DISABLE_SRGB_COLORSPACE("disable-srgb-colorspace", false) {
  74. @Override
  75. Boolean deserialize(String value) {
  76. return Boolean.valueOf(value);
  77. }
  78. },
  79. MERGE_FONTS("merge-fonts", false) {
  80. @Override
  81. Boolean deserialize(String value) {
  82. return Boolean.valueOf(value);
  83. }
  84. },
  85. LINEARIZATION("linearization", false) {
  86. @Override
  87. Boolean deserialize(String value) {
  88. return Boolean.valueOf(value);
  89. }
  90. },
  91. /** Rendering Options key for the ICC profile for the output intent. */
  92. OUTPUT_PROFILE("output-profile") {
  93. @Override
  94. URI deserialize(String value) {
  95. try {
  96. return InternalResourceResolver.cleanURI(value);
  97. } catch (URISyntaxException e) {
  98. throw new RuntimeException(e);
  99. }
  100. }
  101. };
  102. private final String name;
  103. private final Object defaultValue;
  104. private PDFRendererOption(String name, Object defaultValue) {
  105. this.name = name;
  106. this.defaultValue = defaultValue;
  107. }
  108. private PDFRendererOption(String name) {
  109. this(name, null);
  110. }
  111. public String getName() {
  112. return name;
  113. }
  114. public Object getDefaultValue() {
  115. return defaultValue;
  116. }
  117. public Object parse(Object object) {
  118. if (object instanceof String) {
  119. return deserialize((String) object);
  120. } else {
  121. return object;
  122. }
  123. }
  124. abstract Object deserialize(String value);
  125. }