1 | /* | |
2 | * $Id: PolylineShapeIterator.java 4065 2009-09-16 23:09:11Z psoares33 $ | |
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; | |
53 | import java.awt.geom.PathIterator; | |
54 | import java.util.NoSuchElementException; | |
55 | import com.lowagie.text.error_messages.MessageLocalization; | |
56 | /** | |
57 | * PathIterator for PolylineShape. | |
58 | * This class was originally written by wil - amristar.com.au | |
59 | * and integrated into iText by Bruno. | |
60 | */ | |
61 | public class PolylineShapeIterator implements PathIterator { | |
62 | /** The polyline over which we are going to iterate. */ | |
63 | protected PolylineShape poly; | |
64 | /** an affine transformation to be performed on the polyline. */ | |
65 | protected AffineTransform affine; | |
66 | /** the index of the current segment in the iterator. */ | |
67 | protected int index; | |
68 | | |
69 | /** Creates a PolylineShapeIterator. */ | |
70 | PolylineShapeIterator(PolylineShape l, AffineTransform at) { | |
71 | this.poly = l; | |
72 | this.affine = at; | |
73 | } | |
74 | | |
75 | /** | |
76 | * Returns the coordinates and type of the current path segment in | |
77 | * the iteration. The return value is the path segment type: | |
78 | * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. | |
79 | * A double array of length 6 must be passed in and may be used to | |
80 | * store the coordinates of the point(s). | |
81 | * Each point is stored as a pair of double x,y coordinates. | |
82 | * SEG_MOVETO and SEG_LINETO types will return one point, | |
83 | * SEG_QUADTO will return two points, | |
84 | * SEG_CUBICTO will return 3 points | |
85 | * and SEG_CLOSE will not return any points. | |
86 | * @see #SEG_MOVETO | |
87 | * @see #SEG_LINETO | |
88 | * @see #SEG_QUADTO | |
89 | * @see #SEG_CUBICTO | |
90 | * @see #SEG_CLOSE | |
91 | * @see java.awt.geom.PathIterator#currentSegment(double[]) | |
92 | */ | |
93 | public int currentSegment(double[] coords) { | |
94 |
1
1. currentSegment : negated conditional → NO_COVERAGE |
if (isDone()) { |
95 | throw new NoSuchElementException(MessageLocalization.getComposedMessage("line.iterator.out.of.bounds")); | |
96 | } | |
97 |
1
1. currentSegment : negated conditional → NO_COVERAGE |
int type = (index==0)?SEG_MOVETO:SEG_LINETO; |
98 | coords[0] = poly.x[index]; | |
99 | coords[1] = poly.y[index]; | |
100 |
1
1. currentSegment : negated conditional → NO_COVERAGE |
if (affine != null) { |
101 |
1
1. currentSegment : removed call to java/awt/geom/AffineTransform::transform → NO_COVERAGE |
affine.transform(coords, 0, coords, 0, 1); |
102 | } | |
103 |
1
1. currentSegment : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return type; |
104 | } | |
105 | | |
106 | /** | |
107 | * Returns the coordinates and type of the current path segment in | |
108 | * the iteration. The return value is the path segment type: | |
109 | * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. | |
110 | * A double array of length 6 must be passed in and may be used to | |
111 | * store the coordinates of the point(s). | |
112 | * Each point is stored as a pair of double x,y coordinates. | |
113 | * SEG_MOVETO and SEG_LINETO types will return one point, | |
114 | * SEG_QUADTO will return two points, | |
115 | * SEG_CUBICTO will return 3 points | |
116 | * and SEG_CLOSE will not return any points. | |
117 | * @see #SEG_MOVETO | |
118 | * @see #SEG_LINETO | |
119 | * @see #SEG_QUADTO | |
120 | * @see #SEG_CUBICTO | |
121 | * @see #SEG_CLOSE | |
122 | * @see java.awt.geom.PathIterator#currentSegment(float[]) | |
123 | */ | |
124 | public int currentSegment(float[] coords) { | |
125 |
1
1. currentSegment : negated conditional → NO_COVERAGE |
if (isDone()) { |
126 | throw new NoSuchElementException(MessageLocalization.getComposedMessage("line.iterator.out.of.bounds")); | |
127 | } | |
128 |
1
1. currentSegment : negated conditional → NO_COVERAGE |
int type = (index==0)?SEG_MOVETO:SEG_LINETO; |
129 | coords[0] = poly.x[index]; | |
130 | coords[1] = poly.y[index]; | |
131 |
1
1. currentSegment : negated conditional → NO_COVERAGE |
if (affine != null) { |
132 |
1
1. currentSegment : removed call to java/awt/geom/AffineTransform::transform → NO_COVERAGE |
affine.transform(coords, 0, coords, 0, 1); |
133 | } | |
134 |
1
1. currentSegment : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return type; |
135 | } | |
136 | ||
137 | /** | |
138 | * Return the winding rule for determining the insideness of the | |
139 | * path. | |
140 | * @see #WIND_EVEN_ODD | |
141 | * @see #WIND_NON_ZERO | |
142 | * @see java.awt.geom.PathIterator#getWindingRule() | |
143 | */ | |
144 | public int getWindingRule() { | |
145 | return WIND_NON_ZERO; | |
146 | } | |
147 | ||
148 | /** | |
149 | * Tests if there are more points to read. | |
150 | * @return true if there are more points to read | |
151 | * @see java.awt.geom.PathIterator#isDone() | |
152 | */ | |
153 | public boolean isDone() { | |
154 |
3
1. isDone : changed conditional boundary → NO_COVERAGE 2. isDone : negated conditional → NO_COVERAGE 3. isDone : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (index >= poly.np); |
155 | } | |
156 | ||
157 | /** | |
158 | * Moves the iterator to the next segment of the path forwards | |
159 | * along the primary direction of traversal as long as there are | |
160 | * more points in that direction. | |
161 | * @see java.awt.geom.PathIterator#next() | |
162 | */ | |
163 | public void next() { | |
164 |
1
1. next : Replaced integer addition with subtraction → NO_COVERAGE |
index++; |
165 | } | |
166 | ||
167 | } | |
Mutations | ||
94 |
1.1 |
|
97 |
1.1 |
|
100 |
1.1 |
|
101 |
1.1 |
|
103 |
1.1 |
|
125 |
1.1 |
|
128 |
1.1 |
|
131 |
1.1 |
|
132 |
1.1 |
|
134 |
1.1 |
|
154 |
1.1 2.2 3.3 |
|
164 |
1.1 |