1 | /* | |
2 | * $Id: LineSeparator.java 3373 2008-05-12 16:21:24Z xlv $ | |
3 | * | |
4 | * Copyright 2008 by Paulo Soares. | |
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.draw; | |
51 | ||
52 | import com.lowagie.text.Element; | |
53 | import com.lowagie.text.pdf.PdfContentByte; | |
54 | ||
55 | import java.awt.Color; | |
56 | ||
57 | /** | |
58 | * Element that draws a solid line from left to right. | |
59 | * Can be added directly to a document or column. | |
60 | * Can also be used to create a separator chunk. | |
61 | * @author Paulo Soares | |
62 | * @since 2.1.2 | |
63 | */ | |
64 | public class LineSeparator extends VerticalPositionMark { | |
65 | | |
66 | /** The thickness of the line. */ | |
67 | protected float lineWidth = 1; | |
68 | /** The width of the line as a percentage of the available page width. */ | |
69 | protected float percentage = 100; | |
70 | /** The color of the line. */ | |
71 | protected Color lineColor; | |
72 | /** The alignment of the line. */ | |
73 | protected int alignment = Element.ALIGN_CENTER; | |
74 | | |
75 | /** | |
76 | * Creates a new instance of the LineSeparator class. | |
77 | * @param lineWidth the thickness of the line | |
78 | * @param percentage the width of the line as a percentage of the available page width | |
79 | * @param lineColor the color of the line | |
80 | * @param align the alignment | |
81 | * @param offset the offset of the line relative to the current baseline (negative = under the baseline) | |
82 | */ | |
83 | public LineSeparator(float lineWidth, float percentage, Color lineColor, int align, float offset) { | |
84 | this.lineWidth = lineWidth; | |
85 | this.percentage = percentage; | |
86 | this.lineColor = lineColor; | |
87 | this.alignment = align; | |
88 | this.offset = offset; | |
89 | } | |
90 | ||
91 | /** | |
92 | * Creates a new instance of the LineSeparator class with | |
93 | * default values: lineWidth 1 user unit, width 100%, centered with offset 0. | |
94 | */ | |
95 | public LineSeparator() { | |
96 | } | |
97 | ||
98 | /** | |
99 | * @see com.lowagie.text.pdf.draw.DrawInterface#draw(com.lowagie.text.pdf.PdfContentByte, float, float, float, float, float) | |
100 | */ | |
101 | public void draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y) { | |
102 |
1
1. draw : removed call to com/lowagie/text/pdf/PdfContentByte::saveState → NO_COVERAGE |
canvas.saveState(); |
103 |
1
1. draw : removed call to com/lowagie/text/pdf/draw/LineSeparator::drawLine → NO_COVERAGE |
drawLine(canvas, llx, urx, y); |
104 |
1
1. draw : removed call to com/lowagie/text/pdf/PdfContentByte::restoreState → NO_COVERAGE |
canvas.restoreState(); |
105 | } | |
106 | ||
107 | /** | |
108 | * Draws a horizontal line. | |
109 | * @param canvas the canvas to draw on | |
110 | * @param leftX the left x coordinate | |
111 | * @param rightX the right x coordindate | |
112 | * @param y the y coordinate | |
113 | */ | |
114 | public void drawLine(PdfContentByte canvas, float leftX, float rightX, float y) { | |
115 | float w; | |
116 |
2
1. drawLine : changed conditional boundary → NO_COVERAGE 2. drawLine : negated conditional → NO_COVERAGE |
if (getPercentage() < 0) |
117 |
1
1. drawLine : removed negation → NO_COVERAGE |
w = -getPercentage(); |
118 | else | |
119 |
3
1. drawLine : Replaced float subtraction with addition → NO_COVERAGE 2. drawLine : Replaced float multiplication with division → NO_COVERAGE 3. drawLine : Replaced float division with multiplication → NO_COVERAGE |
w = (rightX - leftX) * getPercentage() / 100.0f; |
120 | float s; | |
121 | switch (getAlignment()) { | |
122 | case Element.ALIGN_LEFT: | |
123 | s = 0; | |
124 | break; | |
125 | case Element.ALIGN_RIGHT: | |
126 |
2
1. drawLine : Replaced float subtraction with addition → NO_COVERAGE 2. drawLine : Replaced float subtraction with addition → NO_COVERAGE |
s = rightX - leftX - w; |
127 | break; | |
128 | default: | |
129 |
3
1. drawLine : Replaced float subtraction with addition → NO_COVERAGE 2. drawLine : Replaced float subtraction with addition → NO_COVERAGE 3. drawLine : Replaced float division with multiplication → NO_COVERAGE |
s = (rightX - leftX - w) / 2; |
130 | break; | |
131 | } | |
132 |
1
1. drawLine : removed call to com/lowagie/text/pdf/PdfContentByte::setLineWidth → NO_COVERAGE |
canvas.setLineWidth(getLineWidth()); |
133 |
1
1. drawLine : negated conditional → NO_COVERAGE |
if (getLineColor() != null) |
134 |
1
1. drawLine : removed call to com/lowagie/text/pdf/PdfContentByte::setColorStroke → NO_COVERAGE |
canvas.setColorStroke(getLineColor()); |
135 |
3
1. drawLine : Replaced float addition with subtraction → NO_COVERAGE 2. drawLine : Replaced float addition with subtraction → NO_COVERAGE 3. drawLine : removed call to com/lowagie/text/pdf/PdfContentByte::moveTo → NO_COVERAGE |
canvas.moveTo(s + leftX, y + offset); |
136 |
4
1. drawLine : Replaced float addition with subtraction → NO_COVERAGE 2. drawLine : Replaced float addition with subtraction → NO_COVERAGE 3. drawLine : Replaced float addition with subtraction → NO_COVERAGE 4. drawLine : removed call to com/lowagie/text/pdf/PdfContentByte::lineTo → NO_COVERAGE |
canvas.lineTo(s + w + leftX, y + offset); |
137 |
1
1. drawLine : removed call to com/lowagie/text/pdf/PdfContentByte::stroke → NO_COVERAGE |
canvas.stroke(); |
138 | } | |
139 | | |
140 | /** | |
141 | * Getter for the line width. | |
142 | * @return the thickness of the line that will be drawn. | |
143 | */ | |
144 | public float getLineWidth() { | |
145 | return lineWidth; | |
146 | } | |
147 | ||
148 | /** | |
149 | * Setter for the line width. | |
150 | * @param lineWidth the thickness of the line that will be drawn. | |
151 | */ | |
152 | public void setLineWidth(float lineWidth) { | |
153 | this.lineWidth = lineWidth; | |
154 | } | |
155 | ||
156 | /** | |
157 | * Setter for the width as a percentage of the available width. | |
158 | * @return a width percentage | |
159 | */ | |
160 | public float getPercentage() { | |
161 | return percentage; | |
162 | } | |
163 | ||
164 | /** | |
165 | * Setter for the width as a percentage of the available width. | |
166 | * @param percentage a width percentage | |
167 | */ | |
168 | public void setPercentage(float percentage) { | |
169 | this.percentage = percentage; | |
170 | } | |
171 | ||
172 | /** | |
173 | * Getter for the color of the line that will be drawn. | |
174 | * @return a color | |
175 | */ | |
176 | public Color getLineColor() { | |
177 | return lineColor; | |
178 | } | |
179 | ||
180 | /** | |
181 | * Setter for the color of the line that will be drawn. | |
182 | * @param color a color | |
183 | */ | |
184 | public void setLineColor(Color color) { | |
185 | this.lineColor = color; | |
186 | } | |
187 | ||
188 | /** | |
189 | * Getter for the alignment of the line. | |
190 | * @return an alignment value | |
191 | */ | |
192 | public int getAlignment() { | |
193 | return alignment; | |
194 | } | |
195 | ||
196 | /** | |
197 | * Setter for the alignment of the line. | |
198 | * @param align an alignment value | |
199 | */ | |
200 | public void setAlignment(int align) { | |
201 | this.alignment = align; | |
202 | } | |
203 | } | |
Mutations | ||
102 |
1.1 |
|
103 |
1.1 |
|
104 |
1.1 |
|
116 |
1.1 2.2 |
|
117 |
1.1 |
|
119 |
1.1 2.2 3.3 |
|
126 |
1.1 2.2 |
|
129 |
1.1 2.2 3.3 |
|
132 |
1.1 |
|
133 |
1.1 |
|
134 |
1.1 |
|
135 |
1.1 2.2 3.3 |
|
136 |
1.1 2.2 3.3 4.4 |
|
137 |
1.1 |