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.5KB

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