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.

PSSVGGraphics2D.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.ps.svg;
  19. import java.awt.Graphics;
  20. import java.awt.Paint;
  21. import java.awt.geom.AffineTransform;
  22. import java.io.IOException;
  23. import org.apache.commons.logging.Log;
  24. import org.apache.commons.logging.LogFactory;
  25. import org.apache.batik.ext.awt.LinearGradientPaint;
  26. import org.apache.batik.ext.awt.RadialGradientPaint;
  27. import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
  28. import org.apache.xmlgraphics.ps.PSGenerator;
  29. import org.apache.fop.render.shading.Pattern;
  30. public class PSSVGGraphics2D extends PSGraphics2D {
  31. private static final Log LOG = LogFactory.getLog(PSSVGGraphics2D.class);
  32. /**
  33. * Create a new Graphics2D that generates PostScript code.
  34. * @param textAsShapes True if text should be rendered as graphics
  35. * @see org.apache.xmlgraphics.java2d.AbstractGraphics2D#AbstractGraphics2D(boolean)
  36. */
  37. public PSSVGGraphics2D(boolean textAsShapes) {
  38. super(textAsShapes);
  39. }
  40. /**
  41. * Create a new Graphics2D that generates PostScript code.
  42. * @param textAsShapes True if text should be rendered as graphics
  43. * @param gen PostScript generator to use for output
  44. * @see org.apache.xmlgraphics.java2d.AbstractGraphics2D#AbstractGraphics2D(boolean)
  45. */
  46. public PSSVGGraphics2D(boolean textAsShapes, PSGenerator gen) {
  47. super(textAsShapes, gen);
  48. }
  49. /**
  50. * Constructor for creating copies
  51. * @param g parent PostScript Graphics2D
  52. */
  53. public PSSVGGraphics2D(PSGraphics2D g) {
  54. super(g);
  55. }
  56. protected void applyPaint(Paint paint, boolean fill) {
  57. super.applyPaint(paint, fill);
  58. if (paint instanceof LinearGradientPaint) {
  59. Pattern pattern = new PSGradientMaker()
  60. .makeLinearGradient((LinearGradientPaint) paint, getBaseTransform(), getTransform());
  61. try {
  62. gen.write(pattern.toString());
  63. } catch (IOException ioe) {
  64. handleIOException(ioe);
  65. }
  66. } else if (paint instanceof RadialGradientPaint) {
  67. Pattern pattern = new PSGradientMaker()
  68. .makeRadialGradient((RadialGradientPaint) paint, getBaseTransform(), getTransform());
  69. try {
  70. gen.write(pattern.toString());
  71. } catch (IOException ioe) {
  72. handleIOException(ioe);
  73. }
  74. }
  75. }
  76. protected AffineTransform getBaseTransform() {
  77. AffineTransform at = new AffineTransform(this.getTransform());
  78. return at;
  79. }
  80. /**
  81. * Creates a new <code>Graphics</code> object that is
  82. * a copy of this <code>Graphics</code> object.
  83. * @return a new graphics context that is a copy of
  84. * this graphics context.
  85. */
  86. @Override
  87. public Graphics create() {
  88. preparePainting();
  89. return new PSSVGGraphics2D(this);
  90. }
  91. }