Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PDFGraphicsConfiguration.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.svg;
  19. import java.awt.GraphicsDevice;
  20. import java.awt.Rectangle;
  21. import java.awt.Transparency;
  22. import java.awt.geom.AffineTransform;
  23. import java.awt.image.BufferedImage;
  24. import java.awt.image.ColorModel;
  25. /**
  26. * Our implementation of the class that returns information about
  27. * roughly what we can handle and want to see (alpha for example).
  28. */
  29. class PDFGraphicsConfiguration extends GraphicsConfiguration {
  30. // We use this to get a good colormodel..
  31. private static final BufferedImage BI_WITH_ALPHA
  32. = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
  33. // We use this to get a good colormodel..
  34. private static final BufferedImage BI_WITHOUT_ALPHA
  35. = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
  36. /**
  37. * Construct a buffered image with an alpha channel, unless
  38. * transparencty is OPAQUE (no alpha at all).
  39. *
  40. * @param width the width of the image
  41. * @param height the height of the image
  42. * @param transparency the alpha value of the image
  43. * @return the new buffered image
  44. */
  45. public BufferedImage createCompatibleImage(int width, int height,
  46. int transparency) {
  47. if (transparency == Transparency.OPAQUE) {
  48. return new BufferedImage(width, height,
  49. BufferedImage.TYPE_INT_RGB);
  50. } else {
  51. return new BufferedImage(width, height,
  52. BufferedImage.TYPE_INT_ARGB);
  53. }
  54. }
  55. /**
  56. * Construct a buffered image with an alpha channel.
  57. *
  58. * @param width the width of the image
  59. * @param height the height of the image
  60. * @return the new buffered image
  61. */
  62. public BufferedImage createCompatibleImage(int width, int height) {
  63. return new BufferedImage(width, height,
  64. BufferedImage.TYPE_INT_ARGB);
  65. }
  66. /**
  67. * TODO: This should return the page bounds in Pts,
  68. * I couldn't figure out how to get this for the current
  69. * page from the PDFDocument (this still works for now,
  70. * but it should be fixed...).
  71. *
  72. * @return the bounds of the PDF document page
  73. */
  74. public Rectangle getBounds() {
  75. return null;
  76. }
  77. /**
  78. * Return a good default color model for this 'device'.
  79. * @return the colour model for the configuration
  80. */
  81. public ColorModel getColorModel() {
  82. return BI_WITH_ALPHA.getColorModel();
  83. }
  84. /**
  85. * Return a good color model given <code>transparency</code>
  86. *
  87. * @param transparency the alpha value for the colour model
  88. * @return the colour model for the configuration
  89. */
  90. public ColorModel getColorModel(int transparency) {
  91. if (transparency == Transparency.OPAQUE) {
  92. return BI_WITHOUT_ALPHA.getColorModel();
  93. } else {
  94. return BI_WITH_ALPHA.getColorModel();
  95. }
  96. }
  97. /**
  98. * The default transform (1:1).
  99. *
  100. * @return the default transform for the configuration
  101. */
  102. public AffineTransform getDefaultTransform() {
  103. return new AffineTransform();
  104. }
  105. /**
  106. * The normalizing transform (1:1) (since we currently
  107. * render images at 72dpi, which we might want to change
  108. * in the future).
  109. *
  110. * @return the normalizing transform for the configuration
  111. */
  112. public AffineTransform getNormalizingTransform() {
  113. return new AffineTransform(2, 0, 0, 2, 0, 0);
  114. }
  115. /**
  116. * Return our dummy instance of GraphicsDevice
  117. *
  118. * @return the PDF graphics device
  119. */
  120. public GraphicsDevice getDevice() {
  121. return new PDFGraphicsDevice(this);
  122. }
  123. }