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

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