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.

PSDocumentGraphics2D.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.render.ps;
  18. //Java
  19. import java.awt.Graphics;
  20. import java.io.OutputStream;
  21. import java.io.IOException;
  22. //FOP
  23. import org.apache.fop.apps.Fop;
  24. import org.apache.fop.fonts.FontInfo;
  25. import org.apache.fop.fonts.FontSetup;
  26. /**
  27. * This class is a wrapper for the <tt>PSGraphics2D</tt> that
  28. * is used to create a full document around the PostScript rendering from
  29. * <tt>PSGraphics2D</tt>.
  30. *
  31. * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
  32. * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a>
  33. * @version $Id$
  34. * @see org.apache.fop.render.ps.PSGraphics2D
  35. */
  36. public class PSDocumentGraphics2D extends AbstractPSDocumentGraphics2D {
  37. /**
  38. * Create a new AbstractPSDocumentGraphics2D.
  39. * This is used to create a new PostScript document, the height,
  40. * width and output stream can be setup later.
  41. * For use by the transcoder which needs font information
  42. * for the bridge before the document size is known.
  43. * The resulting document is written to the stream after rendering.
  44. *
  45. * @param textAsShapes set this to true so that text will be rendered
  46. * using curves and not the font.
  47. */
  48. PSDocumentGraphics2D(boolean textAsShapes) {
  49. super(textAsShapes);
  50. if (!textAsShapes) {
  51. fontInfo = new FontInfo();
  52. FontSetup.setup(fontInfo, null);
  53. }
  54. }
  55. /**
  56. * Create a new AbstractPSDocumentGraphics2D.
  57. * This is used to create a new PostScript document of the given height
  58. * and width.
  59. * The resulting document is written to the stream after rendering.
  60. *
  61. * @param textAsShapes set this to true so that text will be rendered
  62. * using curves and not the font.
  63. * @param stream the stream that the final document should be written to.
  64. * @param width the width of the document
  65. * @param height the height of the document
  66. * @throws IOException an io exception if there is a problem
  67. * writing to the output stream
  68. */
  69. public PSDocumentGraphics2D(boolean textAsShapes, OutputStream stream,
  70. int width, int height) throws IOException {
  71. this(textAsShapes);
  72. setupDocument(stream, width, height);
  73. }
  74. public void nextPage() throws IOException {
  75. closePage();
  76. }
  77. protected void writeFileHeader() throws IOException {
  78. final Long pagewidth = new Long(this.width);
  79. final Long pageheight = new Long(this.height);
  80. //PostScript Header
  81. gen.writeln(DSCConstants.PS_ADOBE_30);
  82. gen.writeDSCComment(DSCConstants.CREATOR,
  83. new String[] {"Apache FOP " + Fop.getVersion()
  84. + ": PostScript Transcoder for SVG"});
  85. gen.writeDSCComment(DSCConstants.CREATION_DATE,
  86. new Object[] {new java.util.Date()});
  87. gen.writeDSCComment(DSCConstants.PAGES, PSGenerator.ATEND);
  88. gen.writeDSCComment(DSCConstants.BBOX, new Object[]
  89. {ZERO, ZERO, pagewidth, pageheight});
  90. gen.writeDSCComment(DSCConstants.END_COMMENTS);
  91. //Defaults
  92. gen.writeDSCComment(DSCConstants.BEGIN_DEFAULTS);
  93. gen.writeDSCComment(DSCConstants.END_DEFAULTS);
  94. //Prolog
  95. gen.writeDSCComment(DSCConstants.BEGIN_PROLOG);
  96. gen.writeDSCComment(DSCConstants.END_PROLOG);
  97. //Setup
  98. gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
  99. PSProcSets.writeFOPStdProcSet(gen);
  100. PSProcSets.writeFOPEPSProcSet(gen);
  101. if (fontInfo != null) {
  102. PSProcSets.writeFontDict(gen, fontInfo);
  103. }
  104. gen.writeDSCComment(DSCConstants.END_SETUP);
  105. }
  106. protected void writePageHeader() throws IOException {
  107. Integer pageNumber = new Integer(this.pagecount);
  108. gen.writeDSCComment(DSCConstants.PAGE, new Object[]
  109. {pageNumber.toString(), pageNumber});
  110. gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[]
  111. {ZERO, ZERO, new Integer(width), new Integer(height)});
  112. gen.writeDSCComment(DSCConstants.BEGIN_PAGE_SETUP);
  113. gen.writeln("<<");
  114. gen.writeln("/PageSize [" + width + " " + height + "]");
  115. gen.writeln("/ImagingBBox null");
  116. gen.writeln(">> setpagedevice");
  117. if (fontInfo != null) {
  118. gen.writeln("FOPFonts begin");
  119. }
  120. }
  121. protected void writePageTrailer() throws IOException {
  122. gen.writeln("showpage");
  123. gen.writeDSCComment(DSCConstants.PAGE_TRAILER);
  124. gen.writeDSCComment(DSCConstants.END_PAGE);
  125. }
  126. /**
  127. * This constructor supports the create method
  128. * @param g the PostScript document graphics to make a copy of
  129. */
  130. public PSDocumentGraphics2D(PSDocumentGraphics2D g) {
  131. super(g);
  132. }
  133. /**
  134. * Creates a new <code>Graphics</code> object that is
  135. * a copy of this <code>Graphics</code> object.
  136. * @return a new graphics context that is a copy of
  137. * this graphics context.
  138. */
  139. public Graphics create() {
  140. return new PSDocumentGraphics2D(this);
  141. }
  142. }