001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: PSDocumentGraphics2D.java 512838 2007-02-28 16:42:28Z jeremias $ */
019:
020: package org.apache.xmlgraphics.java2d.ps;
021:
022: import java.awt.Graphics;
023: import java.io.OutputStream;
024: import java.io.IOException;
025:
026: import org.apache.xmlgraphics.ps.DSCConstants;
027: import org.apache.xmlgraphics.ps.PSProcSets;
028:
029: /**
030: * This class is a wrapper for the <tt>PSGraphics2D</tt> that
031: * is used to create a full document around the PostScript rendering from
032: * <tt>PSGraphics2D</tt>.
033: *
034: * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
035: * @version $Id: PSDocumentGraphics2D.java 512838 2007-02-28 16:42:28Z jeremias $
036: * @see org.apache.xmlgraphics.java2d.ps.PSGraphics2D
037: */
038: public class PSDocumentGraphics2D extends AbstractPSDocumentGraphics2D {
039:
040: /**
041: * Create a new AbstractPSDocumentGraphics2D.
042: * This is used to create a new PostScript document, the height,
043: * width and output stream can be setup later.
044: * For use by the transcoder which needs font information
045: * for the bridge before the document size is known.
046: * The resulting document is written to the stream after rendering.
047: *
048: * @param textAsShapes set this to true so that text will be rendered
049: * using curves and not the font.
050: */
051: public PSDocumentGraphics2D(boolean textAsShapes) {
052: super (textAsShapes);
053: }
054:
055: /**
056: * Create a new AbstractPSDocumentGraphics2D.
057: * This is used to create a new PostScript document of the given height
058: * and width.
059: * The resulting document is written to the stream after rendering.
060: *
061: * @param textAsShapes set this to true so that text will be rendered
062: * using curves and not the font.
063: * @param stream the stream that the final document should be written to.
064: * @param width the width of the document
065: * @param height the height of the document
066: * @throws IOException an io exception if there is a problem
067: * writing to the output stream
068: */
069: public PSDocumentGraphics2D(boolean textAsShapes,
070: OutputStream stream, int width, int height)
071: throws IOException {
072: this (textAsShapes);
073: setupDocument(stream, width, height);
074: }
075:
076: public void nextPage() throws IOException {
077: closePage();
078: }
079:
080: protected void writeFileHeader() throws IOException {
081: final Long pagewidth = new Long(this .width);
082: final Long pageheight = new Long(this .height);
083:
084: //PostScript Header
085: gen.writeln(DSCConstants.PS_ADOBE_30);
086: gen.writeDSCComment(DSCConstants.CREATOR,
087: new String[] { "Apache XML Graphics Commons"
088: + ": PostScript Generator for Java2D" });
089: gen.writeDSCComment(DSCConstants.CREATION_DATE,
090: new Object[] { new java.util.Date() });
091: gen.writeDSCComment(DSCConstants.PAGES, DSCConstants.ATEND);
092: gen.writeDSCComment(DSCConstants.BBOX, new Object[] { ZERO,
093: ZERO, pagewidth, pageheight });
094: gen.writeDSCComment(DSCConstants.END_COMMENTS);
095:
096: //Defaults
097: gen.writeDSCComment(DSCConstants.BEGIN_DEFAULTS);
098: gen.writeDSCComment(DSCConstants.END_DEFAULTS);
099:
100: //Prolog
101: gen.writeDSCComment(DSCConstants.BEGIN_PROLOG);
102: gen.writeDSCComment(DSCConstants.END_PROLOG);
103:
104: //Setup
105: gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
106: PSProcSets.writeStdProcSet(gen);
107: PSProcSets.writeEPSProcSet(gen);
108: if (customTextHandler != null) {
109: customTextHandler.writeSetup();
110: }
111: gen.writeDSCComment(DSCConstants.END_SETUP);
112: }
113:
114: protected void writePageHeader() throws IOException {
115: Integer pageNumber = new Integer(this .pagecount);
116: gen.writeDSCComment(DSCConstants.PAGE, new Object[] {
117: pageNumber.toString(), pageNumber });
118: gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[] {
119: ZERO, ZERO, new Integer(width), new Integer(height) });
120: gen.writeDSCComment(DSCConstants.BEGIN_PAGE_SETUP);
121: gen.writeln("<<");
122: gen.writeln("/PageSize [" + width + " " + height + "]");
123: gen.writeln("/ImagingBBox null");
124: gen.writeln(">> setpagedevice");
125: if (customTextHandler != null) {
126: customTextHandler.writePageSetup();
127: }
128: }
129:
130: protected void writePageTrailer() throws IOException {
131: gen.writeln("showpage");
132: }
133:
134: /**
135: * This constructor supports the create method
136: * @param g the PostScript document graphics to make a copy of
137: */
138: public PSDocumentGraphics2D(PSDocumentGraphics2D g) {
139: super (g);
140: }
141:
142: /**
143: * Creates a new <code>Graphics</code> object that is
144: * a copy of this <code>Graphics</code> object.
145: * @return a new graphics context that is a copy of
146: * this graphics context.
147: */
148: public Graphics create() {
149: return new PSDocumentGraphics2D(this);
150: }
151:
152: }
|