01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
18: /* $Id: EPSDocumentGraphics2D.java 512838 2007-02-28 16:42:28Z jeremias $ */
19:
20: package org.apache.xmlgraphics.java2d.ps;
21:
22: import java.io.IOException;
23:
24: import org.apache.xmlgraphics.ps.DSCConstants;
25: import org.apache.xmlgraphics.ps.PSProcSets;
26:
27: /**
28: * This class is a wrapper for the <tt>AbstractPSDocumentGraphics2D</tt> that
29: * is used to create EPS (Encapsulated PostScript) files instead of PS file.
30: *
31: * @version $Id: EPSDocumentGraphics2D.java 512838 2007-02-28 16:42:28Z jeremias $
32: * @see org.apache.xmlgraphics.java2d.ps.PSGraphics2D
33: * @see org.apache.xmlgraphics.java2d.ps.AbstractPSDocumentGraphics2D
34: */
35: public class EPSDocumentGraphics2D extends AbstractPSDocumentGraphics2D {
36:
37: /**
38: * Create a new EPSDocumentGraphics2D.
39: * This is used to create a new EPS 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: public EPSDocumentGraphics2D(boolean textAsShapes) {
49: super (textAsShapes);
50: }
51:
52: protected void writeFileHeader() throws IOException {
53: final Long pagewidth = new Long(this .width);
54: final Long pageheight = new Long(this .height);
55:
56: //PostScript Header
57: gen.writeln(DSCConstants.PS_ADOBE_30 + " "
58: + DSCConstants.EPSF_30);
59: gen.writeDSCComment(DSCConstants.CREATOR,
60: new String[] { "Apache XML Graphics Commons"
61: + ": EPS Generator for Java2D" });
62: gen.writeDSCComment(DSCConstants.CREATION_DATE,
63: new Object[] { new java.util.Date() });
64: gen.writeDSCComment(DSCConstants.PAGES, DSCConstants.ATEND);
65: gen.writeDSCComment(DSCConstants.BBOX, new Object[] { ZERO,
66: ZERO, pagewidth, pageheight });
67: gen.writeDSCComment(DSCConstants.LANGUAGE_LEVEL, new Integer(
68: gen.getPSLevel()));
69: gen.writeDSCComment(DSCConstants.END_COMMENTS);
70:
71: //Prolog
72: gen.writeDSCComment(DSCConstants.BEGIN_PROLOG);
73: PSProcSets.writeStdProcSet(gen);
74: PSProcSets.writeEPSProcSet(gen);
75: if (customTextHandler != null) {
76: customTextHandler.writeSetup();
77: }
78: gen.writeDSCComment(DSCConstants.END_PROLOG);
79: }
80:
81: protected void writePageHeader() throws IOException {
82: Integer pageNumber = new Integer(this .pagecount);
83: gen.writeDSCComment(DSCConstants.PAGE, new Object[] {
84: pageNumber.toString(), pageNumber });
85: gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[] {
86: ZERO, ZERO, new Integer(width), new Integer(height) });
87: gen.writeDSCComment(DSCConstants.BEGIN_PAGE_SETUP);
88: if (customTextHandler != null) {
89: customTextHandler.writePageSetup();
90: }
91: }
92:
93: protected void writePageTrailer() throws IOException {
94: //nop, no DSC PageTrailer needed
95: }
96:
97: }
|