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.

BitmapRenderingSettings.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.bitmap;
  19. import org.apache.xmlgraphics.image.writer.ImageWriterParams;
  20. import org.apache.fop.render.java2d.Java2DRenderingSettings;
  21. import static org.apache.fop.render.bitmap.BitmapRendererOption.ANTI_ALIASING;
  22. import static org.apache.fop.render.bitmap.BitmapRendererOption.COLOR_MODE;
  23. import static org.apache.fop.render.bitmap.BitmapRendererOption.RENDERING_QUALITY;
  24. /**
  25. * This class holds settings used when rendering to bitmaps.
  26. */
  27. public class BitmapRenderingSettings extends Java2DRenderingSettings {
  28. /** ImageWriter parameters */
  29. private ImageWriterParams writerParams;
  30. /** Image Type as parameter for the BufferedImage constructor (see BufferedImage.TYPE_*) */
  31. private int bufferedImageType = (Integer) COLOR_MODE.getDefaultValue();
  32. /** true if anti-aliasing is set */
  33. private boolean antialiasing = (Boolean) ANTI_ALIASING.getDefaultValue();
  34. /** true if qualityRendering is set */
  35. private boolean qualityRendering = (Boolean) RENDERING_QUALITY.getDefaultValue();
  36. /**
  37. * Default constructor. Initializes the settings to their default values.
  38. */
  39. public BitmapRenderingSettings() {
  40. writerParams = new ImageWriterParams();
  41. }
  42. /**
  43. * Returns the image writer parameters used for encoding the bitmap images.
  44. * @return the image writer parameters
  45. */
  46. public ImageWriterParams getWriterParams() {
  47. return this.writerParams;
  48. }
  49. /**
  50. * Returns the BufferedImage type.
  51. * @return one of BufferedImage.TYPE_*
  52. */
  53. public int getBufferedImageType() {
  54. return this.bufferedImageType;
  55. }
  56. /**
  57. * Sets the type of the BufferedImage to use when preparing a new instance.
  58. * @param bufferedImageType a BufferImage.TYPE_* value
  59. */
  60. public void setBufferedImageType(int bufferedImageType) {
  61. this.bufferedImageType = bufferedImageType;
  62. }
  63. /**
  64. * Enables or disables anti-aliasing.
  65. * @param value true to enable anti-aliasing
  66. */
  67. public void setAntiAliasing(boolean value) {
  68. this.antialiasing = value;
  69. }
  70. /**
  71. * Indicates whether anti-aliasing is enabled.
  72. * @return true if anti-aliasing is enabled
  73. */
  74. public boolean isAntiAliasingEnabled() {
  75. return this.antialiasing;
  76. }
  77. /**
  78. * Controls whether to optimize rendering for speed or for quality.
  79. * @param quality true to optimize for quality, false to optimize for speed
  80. */
  81. public void setQualityRendering(boolean quality) {
  82. this.qualityRendering = quality;
  83. }
  84. /**
  85. * Indicates whether quality rendering is enabled.
  86. * @return true indicates optimization for quality, false indicates optimization for speed
  87. */
  88. public boolean isQualityRenderingEnabled() {
  89. return this.qualityRendering;
  90. }
  91. /**
  92. * Sets the compression method for the image writer.
  93. * @param compressionMethod the compression method name
  94. */
  95. public void setCompressionMethod(String compressionMethod) {
  96. writerParams.setCompressionMethod(compressionMethod);
  97. }
  98. /**
  99. * Returns the compression method being used by the image writer.
  100. * @return the compression method in use
  101. */
  102. public String getCompressionMethod() {
  103. return writerParams.getCompressionMethod();
  104. }
  105. /**
  106. * Sets the resolution of the output image.
  107. * @param dpi the dots-per-inch of the image
  108. */
  109. public void setResolution(int dpi) {
  110. writerParams.setResolution(dpi);
  111. }
  112. }