001: /**
002: * Path.java
003: *
004: Copyright (c) 2007, Innovatics Inc.
005:
006: All rights reserved.
007:
008: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
009:
010: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
011: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
012:
013: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
014: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
015: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
016: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
017: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
018: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
019: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
020: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
021: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
022: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
023: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
024: */package com.pdfjet;
025:
026: import java.lang.*;
027: import java.util.*;
028:
029: //>>>>pdfjet {
030: public class Path {
031:
032: private double[] color = { 0.0, 0.0, 0.0 };
033: private double width = 0.3;
034: private String pattern = "[] 0";
035: private boolean fill_shape = false;
036: private boolean close_path = false;
037:
038: private List<Point> points = null;
039:
040: private double box_x = 0.0;
041: private double box_y = 0.0;
042:
043: public Path() {
044: points = new ArrayList<Point>();
045: }
046:
047: public void add(Point point) {
048: points.add(point);
049: }
050:
051: public void setPattern(String pattern) {
052: this .pattern = pattern;
053: }
054:
055: public void setWidth(double width) {
056: this .width = width;
057: }
058:
059: public void setColor(double[] color) {
060: this .color = color;
061: }
062:
063: public void setClosePath(boolean close_path) {
064: this .close_path = close_path;
065: }
066:
067: public void setFillShape(boolean fill_shape) {
068: this .fill_shape = fill_shape;
069: }
070:
071: public void placeIn(Box box, double x_offset, double y_offset)
072: throws Exception {
073: box_x = box.x + x_offset;
074: box_y = box.y + y_offset;
075: }
076:
077: public void scaleBy(double factor) throws Exception {
078: for (int i = 0; i < points.size(); i++) {
079: Point point = points.get(i);
080: point.x *= factor;
081: point.y *= factor;
082: }
083: }
084:
085: public void drawOn(Page page) throws Exception {
086: if (fill_shape) {
087: page.setBrushColor(color[0], color[1], color[2]);
088: } else {
089: page.setPenColor(color[0], color[1], color[2]);
090: }
091: page.setPenWidth(width);
092: page.setLinePattern(pattern);
093:
094: for (int i = 0; i < points.size(); i++) {
095: Point point = points.get(i);
096: point.x += box_x;
097: point.y += box_y;
098: }
099:
100: if (fill_shape) {
101: page.drawPath(points, 'f');
102: } else {
103: if (close_path) {
104: page.drawPath(points, 's');
105: } else {
106: page.drawPath(points, 'S');
107: }
108: }
109:
110: for (int i = 0; i < points.size(); i++) {
111: Point point = points.get(i);
112: point.x -= box_x;
113: point.y -= box_y;
114: }
115: }
116:
117: } // End of Path.java
118: //>>>>}
|