KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > pdf > internal > PolylineShapeIterator


1 /*
2  * $Id: PolylineShapeIterator.java 2772 2007-05-21 14:06:08Z blowagie $
3  *
4  * Copyright 2007 Bruno Lowagie and Wil
5  *
6  * The contents of this file are subject to the Mozilla Public License Version 1.1
7  * (the "License"); you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the License.
13  *
14  * The Original Code is 'iText, a free JAVA-PDF library'.
15  *
16  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
17  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
18  * All Rights Reserved.
19  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
20  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source code
23  * where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
34  *
35  * This library is free software; you can redistribute it and/or modify it
36  * under the terms of the MPL as stated above or under the terms of the GNU
37  * Library General Public License as published by the Free Software Foundation;
38  * either version 2 of the License, or any later version.
39  *
40  * This library is distributed in the hope that it will be useful, but WITHOUT
41  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
42  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
43  * details.
44  *
45  * If you didn't download this code from the following link, you should check if
46  * you aren't using an obsolete version:
47  * http://www.lowagie.com/iText/
48  */

49
50 package com.lowagie.text.pdf.internal;
51
52 import java.awt.geom.AffineTransform JavaDoc;
53 import java.awt.geom.PathIterator JavaDoc;
54 import java.util.NoSuchElementException JavaDoc;
55 /**
56  * PathIterator for PolylineShape.
57  * This class was originally written by wil - amristar.com.au
58  * and integrated into iText by Bruno.
59  */

60 public class PolylineShapeIterator implements PathIterator JavaDoc {
61     /** The polyline over which we are going to iterate. */
62     protected PolylineShape poly;
63     /** an affine transformation to be performed on the polyline. */
64     protected AffineTransform JavaDoc affine;
65     /** the index of the current segment in the iterator. */
66     protected int index;
67     
68     /** Creates a PolylineShapeIterator. */
69     PolylineShapeIterator(PolylineShape l, AffineTransform JavaDoc at) {
70         this.poly = l;
71         this.affine = at;
72     }
73     
74     /**
75      * Returns the coordinates and type of the current path segment in
76      * the iteration. The return value is the path segment type:
77      * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
78      * A double array of length 6 must be passed in and may be used to
79      * store the coordinates of the point(s).
80      * Each point is stored as a pair of double x,y coordinates.
81      * SEG_MOVETO and SEG_LINETO types will return one point,
82      * SEG_QUADTO will return two points,
83      * SEG_CUBICTO will return 3 points
84      * and SEG_CLOSE will not return any points.
85      * @see #SEG_MOVETO
86      * @see #SEG_LINETO
87      * @see #SEG_QUADTO
88      * @see #SEG_CUBICTO
89      * @see #SEG_CLOSE
90      * @see java.awt.geom.PathIterator#currentSegment(double[])
91      */

92     public int currentSegment(double[] coords) {
93         if (isDone()) {
94             throw new NoSuchElementException JavaDoc("line iterator out of bounds");
95         }
96         int type = (index==0)?SEG_MOVETO:SEG_LINETO;
97         coords[0] = (double) poly.x[index];
98         coords[1] = (double) poly.y[index];
99         if (affine != null) {
100             affine.transform(coords, 0, coords, 0, 1);
101         }
102         return type;
103     }
104     
105     /**
106      * Returns the coordinates and type of the current path segment in
107      * the iteration. The return value is the path segment type:
108      * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
109      * A double array of length 6 must be passed in and may be used to
110      * store the coordinates of the point(s).
111      * Each point is stored as a pair of double x,y coordinates.
112      * SEG_MOVETO and SEG_LINETO types will return one point,
113      * SEG_QUADTO will return two points,
114      * SEG_CUBICTO will return 3 points
115      * and SEG_CLOSE will not return any points.
116      * @see #SEG_MOVETO
117      * @see #SEG_LINETO
118      * @see #SEG_QUADTO
119      * @see #SEG_CUBICTO
120      * @see #SEG_CLOSE
121      * @see java.awt.geom.PathIterator#currentSegment(float[])
122      */

123     public int currentSegment(float[] coords) {
124         if (isDone()) {
125             throw new NoSuchElementException JavaDoc("line iterator out of bounds");
126         }
127         int type = (index==0)?SEG_MOVETO:SEG_LINETO;
128         coords[0] = (float) poly.x[index];
129         coords[1] = (float) poly.y[index];
130         if (affine != null) {
131             affine.transform(coords, 0, coords, 0, 1);
132         }
133         return type;
134     }
135
136     /**
137      * Return the winding rule for determining the insideness of the
138      * path.
139      * @see #WIND_EVEN_ODD
140      * @see #WIND_NON_ZERO
141      * @see java.awt.geom.PathIterator#getWindingRule()
142      */

143     public int getWindingRule() {
144         return WIND_NON_ZERO;
145     }
146
147     /**
148      * Tests if there are more points to read.
149      * @return true if there are more points to read
150      * @see java.awt.geom.PathIterator#isDone()
151      */

152     public boolean isDone() {
153         return (index >= poly.np);
154     }
155
156     /**
157      * Moves the iterator to the next segment of the path forwards
158      * along the primary direction of traversal as long as there are
159      * more points in that direction.
160      * @see java.awt.geom.PathIterator#next()
161      */

162     public void next() {
163         index++;
164     }
165
166 }
167
Popular Tags