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: PSProcSets.java 513830 2007-03-02 16:29:53Z jeremias $ */
019:
020: package org.apache.xmlgraphics.ps;
021:
022: import java.io.IOException;
023:
024: /**
025: * This class defines the basic resources (procsets) used by the Apache XML Graphics project.
026: *
027: * @version $Id: PSProcSets.java 513830 2007-03-02 16:29:53Z jeremias $
028: */
029: public final class PSProcSets {
030:
031: /** the standard procset for the XML Graphics project */
032: public static final PSResource STD_PROCSET = new StdProcSet();
033: /** the EPS procset for the XML Graphics project */
034: public static final PSResource EPS_PROCSET = new EPSProcSet();
035:
036: private static class StdProcSet extends PSProcSet {
037:
038: public StdProcSet() {
039: super ("Apache XML Graphics Std ProcSet", 1.0f, 0);
040: }
041:
042: public void writeTo(PSGenerator gen) throws IOException {
043: gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE,
044: new Object[] { TYPE_PROCSET, getName(),
045: Float.toString(getVersion()),
046: Integer.toString(getRevision()) });
047: gen.writeDSCComment(DSCConstants.VERSION, new Object[] {
048: Float.toString(getVersion()),
049: Integer.toString(getRevision()) });
050: gen
051: .writeDSCComment(
052: DSCConstants.COPYRIGHT,
053: "Copyright 2001-2003 "
054: + "The Apache Software Foundation. "
055: + "License terms: http://www.apache.org/licenses/LICENSE-2.0");
056: gen
057: .writeDSCComment(DSCConstants.TITLE,
058: "Basic set of procedures used by the XML Graphics project (Batik and FOP)");
059:
060: gen.writeln("/bd{bind def}bind def");
061: gen.writeln("/ld{load def}bd");
062: gen.writeln("/M/moveto ld");
063: gen.writeln("/RM/rmoveto ld");
064: gen.writeln("/t/show ld");
065: gen.writeln("/A/ashow ld");
066: gen.writeln("/cp/closepath ld");
067:
068: gen.writeln("/re {4 2 roll M"); //define rectangle
069: gen.writeln("1 index 0 rlineto");
070: gen.writeln("0 exch rlineto");
071: gen.writeln("neg 0 rlineto");
072: gen.writeln("cp } bd");
073:
074: gen.writeln("/_ctm matrix def"); //Holds the current matrix
075: gen.writeln("/_tm matrix def");
076: //BT: save currentmatrix, set _tm to identitymatrix and move to 0/0
077: gen
078: .writeln("/BT { _ctm currentmatrix pop matrix _tm copy pop 0 0 moveto } bd");
079: //ET: restore last currentmatrix
080: gen.writeln("/ET { _ctm setmatrix } bd");
081: gen.writeln("/iTm { _ctm setmatrix _tm concat } bd");
082: gen.writeln("/Tm { _tm astore pop iTm 0 0 moveto } bd");
083:
084: gen.writeln("/ux 0.0 def");
085: gen.writeln("/uy 0.0 def");
086:
087: // <font> <size> F
088: gen.writeln("/F {");
089: gen.writeln(" /Tp exch def");
090: // gen.writeln(" currentdict exch get");
091: gen.writeln(" /Tf exch def");
092: gen.writeln(" Tf findfont Tp scalefont setfont");
093: gen
094: .writeln(" /cf Tf def /cs Tp def /cw ( ) stringwidth pop def");
095: gen.writeln("} bd");
096:
097: gen
098: .writeln("/ULS {currentpoint /uy exch def /ux exch def} bd");
099: gen.writeln("/ULE {");
100: gen.writeln(" /Tcx currentpoint pop def");
101: gen.writeln(" gsave");
102: gen.writeln(" newpath");
103: gen.writeln(" cf findfont cs scalefont dup");
104: gen
105: .writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
106: gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
107: gen
108: .writeln(" /UnderlineThickness get Ts mul /Tt exch def");
109: gen.writeln(" ux uy To add moveto Tcx uy To add lineto");
110: gen.writeln(" Tt setlinewidth stroke");
111: gen.writeln(" grestore");
112: gen.writeln("} bd");
113:
114: gen.writeln("/OLE {");
115: gen.writeln(" /Tcx currentpoint pop def");
116: gen.writeln(" gsave");
117: gen.writeln(" newpath");
118: gen.writeln(" cf findfont cs scalefont dup");
119: gen
120: .writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
121: gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
122: gen
123: .writeln(" /UnderlineThickness get Ts mul /Tt exch def");
124: gen
125: .writeln(" ux uy To add cs add moveto Tcx uy To add cs add lineto");
126: gen.writeln(" Tt setlinewidth stroke");
127: gen.writeln(" grestore");
128: gen.writeln("} bd");
129:
130: gen.writeln("/SOE {");
131: gen.writeln(" /Tcx currentpoint pop def");
132: gen.writeln(" gsave");
133: gen.writeln(" newpath");
134: gen.writeln(" cf findfont cs scalefont dup");
135: gen
136: .writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
137: gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
138: gen
139: .writeln(" /UnderlineThickness get Ts mul /Tt exch def");
140: gen.writeln(" ux uy To add cs 10 mul 26 idiv add moveto "
141: + "Tcx uy To add cs 10 mul 26 idiv add lineto");
142: gen.writeln(" Tt setlinewidth stroke");
143: gen.writeln(" grestore");
144: gen.writeln("} bd");
145:
146: gen.writeln("/QUADTO {");
147: gen.writeln("/Y22 exch store");
148: gen.writeln("/X22 exch store");
149: gen.writeln("/Y21 exch store");
150: gen.writeln("/X21 exch store");
151: gen.writeln("currentpoint");
152: gen.writeln("/Y21 load 2 mul add 3 div exch");
153: gen.writeln("/X21 load 2 mul add 3 div exch");
154: gen.writeln("/X21 load 2 mul /X22 load add 3 div");
155: gen.writeln("/Y21 load 2 mul /Y22 load add 3 div");
156: gen.writeln("/X22 load /Y22 load curveto");
157: gen.writeln("} bd");
158:
159: gen.writeDSCComment(DSCConstants.END_RESOURCE);
160: gen.getResourceTracker().registerSuppliedResource(this );
161: }
162:
163: }
164:
165: private static class EPSProcSet extends PSProcSet {
166:
167: public EPSProcSet() {
168: super ("Apache XML Graphics EPS ProcSet", 1.0f, 0);
169: }
170:
171: public void writeTo(PSGenerator gen) throws IOException {
172: gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE,
173: new Object[] { TYPE_PROCSET, getName(),
174: Float.toString(getVersion()),
175: Integer.toString(getRevision()) });
176: gen.writeDSCComment(DSCConstants.VERSION, new Object[] {
177: Float.toString(getVersion()),
178: Integer.toString(getRevision()) });
179: gen
180: .writeDSCComment(
181: DSCConstants.COPYRIGHT,
182: "Copyright 2002-2003 "
183: + "The Apache Software Foundation. "
184: + "License terms: http://www.apache.org/licenses/LICENSE-2.0");
185: gen
186: .writeDSCComment(DSCConstants.TITLE,
187: "EPS procedures used by the Apache XML Graphics project (Batik and FOP)");
188:
189: gen.writeln("/BeginEPSF { %def");
190: gen
191: .writeln("/b4_Inc_state save def % Save state for cleanup");
192: gen
193: .writeln("/dict_count countdictstack def % Count objects on dict stack");
194: gen
195: .writeln("/op_count count 1 sub def % Count objects on operand stack");
196: gen
197: .writeln("userdict begin % Push userdict on dict stack");
198: gen
199: .writeln("/showpage { } def % Redefine showpage, { } = null proc");
200: gen
201: .writeln("0 setgray 0 setlinecap % Prepare graphics state");
202: gen.writeln("1 setlinewidth 0 setlinejoin");
203: gen.writeln("10 setmiterlimit [ ] 0 setdash newpath");
204: gen
205: .writeln("/languagelevel where % If level not equal to 1 then");
206: gen
207: .writeln("{pop languagelevel % set strokeadjust and");
208: gen
209: .writeln("1 ne % overprint to their defaults.");
210: gen.writeln("{false setstrokeadjust false setoverprint");
211: gen.writeln("} if");
212: gen.writeln("} if");
213: gen.writeln("} bd");
214:
215: gen.writeln("/EndEPSF { %def");
216: gen
217: .writeln("count op_count sub {pop} repeat % Clean up stacks");
218: gen.writeln("countdictstack dict_count sub {end} repeat");
219: gen.writeln("b4_Inc_state restore");
220: gen.writeln("} bd");
221:
222: gen.writeDSCComment(DSCConstants.END_RESOURCE);
223: gen.getResourceTracker().registerSuppliedResource(this );
224: }
225:
226: }
227:
228: /**
229: * Generates a resource defining standard procset with operations used by the XML Graphics
230: * project.
231: * @param gen PSGenerator to use for output
232: * @throws IOException In case of an I/O problem
233: */
234: public static void writeStdProcSet(PSGenerator gen)
235: throws IOException {
236: ((StdProcSet) STD_PROCSET).writeTo(gen);
237: }
238:
239: /**
240: * Generates a resource defining standard procset with operations used by the XML Graphics
241: * project.
242: * @param gen PSGenerator to use for output
243: * @throws IOException In case of an I/O problem
244: * @deprecated Use writeStdProcSet() instead.
245: */
246: public static void writeFOPStdProcSet(PSGenerator gen)
247: throws IOException {
248: writeStdProcSet(gen);
249: }
250:
251: /**
252: * Generates a resource defining a procset for including EPS graphics.
253: * @param gen PSGenerator to use for output
254: * @throws IOException In case of an I/O problem
255: */
256: public static void writeEPSProcSet(PSGenerator gen)
257: throws IOException {
258: ((EPSProcSet) EPS_PROCSET).writeTo(gen);
259: }
260:
261: /**
262: * Generates a resource defining a procset for including EPS graphics.
263: * @param gen PSGenerator to use for output
264: * @throws IOException In case of an I/O problem
265: * @deprecated Use writeEPSProcSet() instead.
266: */
267: public static void writeFOPEPSProcSet(PSGenerator gen)
268: throws IOException {
269: writeEPSProcSet(gen);
270: }
271:
272: }
|