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.

PDFGraphicsConfiguration.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.svg;
  18. import java.awt.Rectangle;
  19. import java.awt.GraphicsDevice;
  20. import java.awt.Transparency;
  21. import java.awt.image.ColorModel;
  22. import java.awt.geom.AffineTransform;
  23. import java.awt.image.BufferedImage;
  24. /**
  25. * Our implementation of the class that returns information about
  26. * roughly what we can handle and want to see (alpha for example).
  27. */
  28. class PDFGraphicsConfiguration extends GraphicsConfiguration {
  29. // We use this to get a good colormodel..
  30. private static final BufferedImage BI_WITH_ALPHA =
  31. new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
  32. // We use this to get a good colormodel..
  33. private static final BufferedImage BI_WITHOUT_ALPHA =
  34. new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
  35. /**
  36. * Construct a buffered image with an alpha channel, unless
  37. * transparencty is OPAQUE (no alpha at all).
  38. *
  39. * @param width the width of the image
  40. * @param height the height of the image
  41. * @param transparency the alpha value of the image
  42. * @return the new buffered image
  43. */
  44. public BufferedImage createCompatibleImage(int width, int height,
  45. int transparency) {
  46. if (transparency == Transparency.OPAQUE) {
  47. return new BufferedImage(width, height,
  48. BufferedImage.TYPE_INT_RGB);
  49. } else {
  50. return new BufferedImage(width, height,
  51. BufferedImage.TYPE_INT_ARGB);
  52. }
  53. }
  54. /**
  55. * Construct a buffered image with an alpha channel.
  56. *
  57. * @param width the width of the image
  58. * @param height the height of the image
  59. * @return the new buffered image
  60. */
  61. public BufferedImage createCompatibleImage(int width, int height) {
  62. return new BufferedImage(width, height,
  63. BufferedImage.TYPE_INT_ARGB);
  64. }
  65. /**
  66. * TODO: This should return the page bounds in Pts,
  67. * I couldn't figure out how to get this for the current
  68. * page from the PDFDocument (this still works for now,
  69. * but it should be fixed...).
  70. *
  71. * @return the bounds of the PDF document page
  72. */
  73. public Rectangle getBounds() {
  74. return null;
  75. }
  76. /**
  77. * Return a good default color model for this 'device'.
  78. * @return the colour model for the configuration
  79. */
  80. public ColorModel getColorModel() {
  81. return BI_WITH_ALPHA.getColorModel();
  82. }
  83. /**
  84. * Return a good color model given <tt>transparency</tt>
  85. *
  86. * @param transparency the alpha value for the colour model
  87. * @return the colour model for the configuration
  88. */
  89. public ColorModel getColorModel(int transparency) {
  90. if (transparency == Transparency.OPAQUE) {
  91. return BI_WITHOUT_ALPHA.getColorModel();
  92. } else {
  93. return BI_WITH_ALPHA.getColorModel();
  94. }
  95. }
  96. /**
  97. * The default transform (1:1).
  98. *
  99. * @return the default transform for the configuration
  100. */
  101. public AffineTransform getDefaultTransform() {
  102. return new AffineTransform();
  103. }
  104. /**
  105. * The normalizing transform (1:1) (since we currently
  106. * render images at 72dpi, which we might want to change
  107. * in the future).
  108. *
  109. * @return the normalizing transform for the configuration
  110. */
  111. public AffineTransform getNormalizingTransform() {
  112. return new AffineTransform(2, 0, 0, 2, 0, 0);
  113. }
  114. /**
  115. * Return our dummy instance of GraphicsDevice
  116. *
  117. * @return the PDF graphics device
  118. */
  119. public GraphicsDevice getDevice() {
  120. return new PDFGraphicsDevice(this);
  121. }
  122. }