Debian Codegraph @

freehep-graphicsio-ps/src/main/java/org/freehep/graphicsio/ps/PSPathConstructor.java

raw
1 // Copyright 2001-2004 FreeHEP.
2 package org.freehep.graphicsio.ps;
3
4 import java.io.IOException;
5 import java.io.PrintStream;
6
7 import org.freehep.graphicsbase.util.ScientificFormat;
8 import org.freehep.graphicsio.QuadToCubicPathConstructor;
9
10 /**
11 * @author Mark Donszelmann
12 * @version $Id: freehep-graphicsio-ps/src/main/java/org/freehep/graphicsio/ps/PSPathConstructor.java f24bd43ca24b 2005/12/02 00:39:35 duns $
13 */
14 public class PSPathConstructor extends QuadToCubicPathConstructor {
15 private PrintStream os;
16
17 private boolean intPrecision;
18
19 private String moveto, lineto, curveto, close;
20
21 private ScientificFormat scientific = new ScientificFormat(6, 9, false);
22
23 public PSPathConstructor(PrintStream os, boolean useProlog,
24 boolean intPrecision) {
25 super();
26 this.os = os;
27 this.intPrecision = intPrecision;
28 if (useProlog) {
29 moveto = "m";
30 lineto = "l";
31 curveto = "c";
32 close = "h";
33 } else {
34 moveto = "moveto";
35 lineto = "lineto";
36 curveto = "curveto";
37 close = "closepath";
38 }
39 }
40
41 public void move(double x, double y) throws IOException {
42 os.println(fixedPrecision(x) + " " + fixedPrecision(y) + " " + moveto);
43 super.move(x, y);
44 }
45
46 public void line(double x, double y) throws IOException {
47 os.println(fixedPrecision(x) + " " + fixedPrecision(y) + " " + lineto);
48 super.line(x, y);
49 }
50
51 public void cubic(double x1, double y1, double x2, double y2, double x3,
52 double y3) throws IOException {
53 os.println(fixedPrecision(x1) + " " + fixedPrecision(y1) + " "
54 + fixedPrecision(x2) + " " + fixedPrecision(y2) + " "
55 + fixedPrecision(x3) + " " + fixedPrecision(y3) + " " + " "
56 + curveto);
57 super.cubic(x1, y1, x2, y2, x3, y3);
58 }
59
60 public void closePath(double x0, double y0) throws IOException {
61 os.println(close);
62 super.closePath(x0, y0);
63 }
64
65 protected String fixedPrecision(double d) {
66 if (intPrecision) {
67 return Integer.toString((int) d);
68 } else {
69 return scientific.format(d);
70
71 }
72 }
73 }