MetaState.java

1
/*
2
 * $Id: MetaState.java 3427 2008-05-24 18:32:31Z xlv $
3
 *
4
 * Copyright 2001, 2002 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.codec.wmf;
51
52
import java.awt.Color;
53
import java.awt.Point;
54
import java.util.ArrayList;
55
import java.util.Stack;
56
57
import com.lowagie.text.pdf.PdfContentByte;
58
59
public class MetaState {
60
    
61
    public static final int TA_NOUPDATECP = 0;
62
    public static final int TA_UPDATECP = 1;
63
    public static final int TA_LEFT = 0;
64
    public static final int TA_RIGHT = 2;
65
    public static final int TA_CENTER = 6;
66
    public static final int TA_TOP = 0;
67
    public static final int TA_BOTTOM = 8;
68
    public static final int TA_BASELINE = 24;
69
    
70
    public static final int TRANSPARENT = 1;
71
    public static final int OPAQUE = 2;
72
73
    public static final int ALTERNATE = 1;
74
    public static final int WINDING = 2;
75
76
    public Stack savedStates;
77
    public ArrayList MetaObjects;
78
    public Point currentPoint;
79
    public MetaPen currentPen;
80
    public MetaBrush currentBrush;
81
    public MetaFont currentFont;
82
    public Color currentBackgroundColor = Color.white;
83
    public Color currentTextColor = Color.black;
84
    public int backgroundMode = OPAQUE;
85
    public int polyFillMode = ALTERNATE;
86
    public int lineJoin = 1;
87
    public int textAlign;
88
    public int offsetWx;
89
    public int offsetWy;
90
    public int extentWx;
91
    public int extentWy;
92
    public float scalingX;
93
    public float scalingY;
94
    
95
96
    /** Creates new MetaState */
97
    public MetaState() {
98
        savedStates = new Stack();
99
        MetaObjects = new ArrayList();
100
        currentPoint = new Point(0, 0);
101
        currentPen = new MetaPen();
102
        currentBrush = new MetaBrush();
103
        currentFont = new MetaFont();
104
    }
105
106
    public MetaState(MetaState state) {
107 1 1. : removed call to com/lowagie/text/pdf/codec/wmf/MetaState::setMetaState → NO_COVERAGE
        setMetaState(state);
108
    }
109
    
110
    public void setMetaState(MetaState state) {
111
        savedStates = state.savedStates;
112
        MetaObjects = state.MetaObjects;
113
        currentPoint = state.currentPoint;
114
        currentPen = state.currentPen;
115
        currentBrush = state.currentBrush;
116
        currentFont = state.currentFont;
117
        currentBackgroundColor = state.currentBackgroundColor;
118
        currentTextColor = state.currentTextColor;
119
        backgroundMode = state.backgroundMode;
120
        polyFillMode = state.polyFillMode;
121
        textAlign = state.textAlign;
122
        lineJoin = state.lineJoin;
123
        offsetWx = state.offsetWx;
124
        offsetWy = state.offsetWy;
125
        extentWx = state.extentWx;
126
        extentWy = state.extentWy;
127
        scalingX = state.scalingX;
128
        scalingY = state.scalingY;
129
    }
130
131
    public void addMetaObject(MetaObject object) {
132 2 1. addMetaObject : changed conditional boundary → NO_COVERAGE
2. addMetaObject : negated conditional → NO_COVERAGE
        for (int k = 0; k < MetaObjects.size(); ++k) {
133 1 1. addMetaObject : negated conditional → NO_COVERAGE
            if (MetaObjects.get(k) == null) {
134
                MetaObjects.set(k, object);
135
                return;
136
            }
137
        }
138
        MetaObjects.add(object);
139
    }
140
    
141
    public void selectMetaObject(int index, PdfContentByte cb) {
142
        MetaObject obj = (MetaObject)MetaObjects.get(index);
143 1 1. selectMetaObject : negated conditional → NO_COVERAGE
        if (obj == null)
144
            return;
145
        int style;
146
        switch (obj.getType()) {
147
            case MetaObject.META_BRUSH:
148
                currentBrush = (MetaBrush)obj;
149
                style = currentBrush.getStyle();
150 1 1. selectMetaObject : negated conditional → NO_COVERAGE
                if (style == MetaBrush.BS_SOLID) {
151
                    Color color = currentBrush.getColor();
152 1 1. selectMetaObject : removed call to com/lowagie/text/pdf/PdfContentByte::setColorFill → NO_COVERAGE
                    cb.setColorFill(color);
153
                }
154 1 1. selectMetaObject : negated conditional → NO_COVERAGE
                else if (style == MetaBrush.BS_HATCHED) {
155
                    Color color = currentBackgroundColor;
156 1 1. selectMetaObject : removed call to com/lowagie/text/pdf/PdfContentByte::setColorFill → NO_COVERAGE
                    cb.setColorFill(color);
157
                }
158
                break;
159
            case MetaObject.META_PEN:
160
            {
161
                currentPen = (MetaPen)obj;
162
                style = currentPen.getStyle();
163 1 1. selectMetaObject : negated conditional → NO_COVERAGE
                if (style != MetaPen.PS_NULL) {
164
                    Color color = currentPen.getColor();
165 1 1. selectMetaObject : removed call to com/lowagie/text/pdf/PdfContentByte::setColorStroke → NO_COVERAGE
                    cb.setColorStroke(color);
166 3 1. selectMetaObject : Replaced float multiplication with division → NO_COVERAGE
2. selectMetaObject : Replaced float division with multiplication → NO_COVERAGE
3. selectMetaObject : removed call to com/lowagie/text/pdf/PdfContentByte::setLineWidth → NO_COVERAGE
                    cb.setLineWidth(Math.abs(currentPen.getPenWidth() * scalingX / extentWx));
167
                    switch (style) {
168
                        case MetaPen.PS_DASH:
169 1 1. selectMetaObject : removed call to com/lowagie/text/pdf/PdfContentByte::setLineDash → NO_COVERAGE
                            cb.setLineDash(18, 6, 0);
170
                            break;
171
                        case MetaPen.PS_DASHDOT:
172 1 1. selectMetaObject : removed call to com/lowagie/text/pdf/PdfContentByte::setLiteral → NO_COVERAGE
                            cb.setLiteral("[9 6 3 6]0 d\n");
173
                            break;
174
                        case MetaPen.PS_DASHDOTDOT:
175 1 1. selectMetaObject : removed call to com/lowagie/text/pdf/PdfContentByte::setLiteral → NO_COVERAGE
                            cb.setLiteral("[9 3 3 3 3 3]0 d\n");
176
                            break;
177
                        case MetaPen.PS_DOT:
178 1 1. selectMetaObject : removed call to com/lowagie/text/pdf/PdfContentByte::setLineDash → NO_COVERAGE
                            cb.setLineDash(3, 0);
179
                            break;
180
                        default:
181 1 1. selectMetaObject : removed call to com/lowagie/text/pdf/PdfContentByte::setLineDash → NO_COVERAGE
                            cb.setLineDash(0);
182
                            break;                            
183
                    }
184
                }
185
                break;
186
            }
187
            case MetaObject.META_FONT:
188
            {
189
                currentFont = (MetaFont)obj;
190
                break;
191
            }
192
        }
193
    }
194
    
195
    public void deleteMetaObject(int index) {
196
        MetaObjects.set(index, null);
197
    }
198
    
199
    public void saveState(PdfContentByte cb) {
200 1 1. saveState : removed call to com/lowagie/text/pdf/PdfContentByte::saveState → NO_COVERAGE
        cb.saveState();
201
        MetaState state = new MetaState(this);
202
        savedStates.push(state);
203
    }
204
205
    public void restoreState(int index, PdfContentByte cb) {
206
        int pops;
207 2 1. restoreState : changed conditional boundary → NO_COVERAGE
2. restoreState : negated conditional → NO_COVERAGE
        if (index < 0)
208 1 1. restoreState : removed negation → NO_COVERAGE
            pops = Math.min(-index, savedStates.size());
209
        else
210 1 1. restoreState : Replaced integer subtraction with addition → NO_COVERAGE
            pops = Math.max(savedStates.size() - index, 0);
211 1 1. restoreState : negated conditional → NO_COVERAGE
        if (pops == 0)
212
            return;
213
        MetaState state = null;
214 2 1. restoreState : Changed increment from -1 to 1 → NO_COVERAGE
2. restoreState : negated conditional → NO_COVERAGE
        while (pops-- != 0) {
215 1 1. restoreState : removed call to com/lowagie/text/pdf/PdfContentByte::restoreState → NO_COVERAGE
            cb.restoreState();
216
            state = (MetaState)savedStates.pop();
217
        }
218 1 1. restoreState : removed call to com/lowagie/text/pdf/codec/wmf/MetaState::setMetaState → NO_COVERAGE
        setMetaState(state);
219
    }
220
    
221
    public void cleanup(PdfContentByte cb) {
222
        int k = savedStates.size();
223 3 1. cleanup : changed conditional boundary → NO_COVERAGE
2. cleanup : Changed increment from -1 to 1 → NO_COVERAGE
3. cleanup : negated conditional → NO_COVERAGE
        while (k-- > 0)
224 1 1. cleanup : removed call to com/lowagie/text/pdf/PdfContentByte::restoreState → NO_COVERAGE
            cb.restoreState();
225
    }
226
    
227
    public float transformX(int x) {
228 4 1. transformX : Replaced float subtraction with addition → NO_COVERAGE
2. transformX : Replaced float multiplication with division → NO_COVERAGE
3. transformX : Replaced float division with multiplication → NO_COVERAGE
4. transformX : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/codec/wmf/MetaState::transformX → NO_COVERAGE
        return ((float)x - offsetWx) * scalingX / extentWx;
229
    }
230
231
    public float transformY(int y) {
232 5 1. transformY : Replaced float subtraction with addition → NO_COVERAGE
2. transformY : Replaced float division with multiplication → NO_COVERAGE
3. transformY : Replaced float subtraction with addition → NO_COVERAGE
4. transformY : Replaced float multiplication with division → NO_COVERAGE
5. transformY : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/codec/wmf/MetaState::transformY → NO_COVERAGE
        return (1f - ((float)y - offsetWy) / extentWy) * scalingY;
233
    }
234
    
235
    public void setScalingX(float scalingX) {
236
        this.scalingX = scalingX;
237
    }
238
    
239
    public void setScalingY(float scalingY) {
240
        this.scalingY = scalingY;
241
    }
242
    
243
    public void setOffsetWx(int offsetWx) {
244
        this.offsetWx = offsetWx;
245
    }
246
    
247
    public void setOffsetWy(int offsetWy) {
248
        this.offsetWy = offsetWy;
249
    }
250
    
251
    public void setExtentWx(int extentWx) {
252
        this.extentWx = extentWx;
253
    }
254
    
255
    public void setExtentWy(int extentWy) {
256
        this.extentWy = extentWy;
257
    }
258
    
259
    public float transformAngle(float angle) {
260 3 1. transformAngle : changed conditional boundary → NO_COVERAGE
2. transformAngle : removed negation → NO_COVERAGE
3. transformAngle : negated conditional → NO_COVERAGE
        float ta = scalingY < 0 ? -angle : angle;
261 4 1. transformAngle : changed conditional boundary → NO_COVERAGE
2. transformAngle : Replaced double subtraction with addition → NO_COVERAGE
3. transformAngle : negated conditional → NO_COVERAGE
4. transformAngle : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/codec/wmf/MetaState::transformAngle → NO_COVERAGE
        return (float)(scalingX < 0 ? Math.PI - ta : ta);
262
    }
263
    
264
    public void setCurrentPoint(Point p) {
265
        currentPoint = p;
266
    }
267
268
    public Point getCurrentPoint() {
269
        return currentPoint;
270
    }
271
    
272
    public MetaBrush getCurrentBrush() {
273
        return currentBrush;
274
    }
275
276
    public MetaPen getCurrentPen() {
277
        return currentPen;
278
    }
279
280
    public MetaFont getCurrentFont() {
281
        return currentFont;
282
    }
283
    
284
    /** Getter for property currentBackgroundColor.
285
     * @return Value of property currentBackgroundColor.
286
     */
287
    public Color getCurrentBackgroundColor() {
288
        return currentBackgroundColor;
289
    }
290
    
291
    /** Setter for property currentBackgroundColor.
292
     * @param currentBackgroundColor New value of property currentBackgroundColor.
293
     */
294
    public void setCurrentBackgroundColor(Color currentBackgroundColor) {
295
        this.currentBackgroundColor = currentBackgroundColor;
296
    }
297
    
298
    /** Getter for property currentTextColor.
299
     * @return Value of property currentTextColor.
300
     */
301
    public Color getCurrentTextColor() {
302
        return currentTextColor;
303
    }
304
    
305
    /** Setter for property currentTextColor.
306
     * @param currentTextColor New value of property currentTextColor.
307
     */
308
    public void setCurrentTextColor(Color currentTextColor) {
309
        this.currentTextColor = currentTextColor;
310
    }
311
    
312
    /** Getter for property backgroundMode.
313
     * @return Value of property backgroundMode.
314
     */
315
    public int getBackgroundMode() {
316
        return backgroundMode;
317
    }
318
    
319
    /** Setter for property backgroundMode.
320
     * @param backgroundMode New value of property backgroundMode.
321
     */
322
    public void setBackgroundMode(int backgroundMode) {
323
        this.backgroundMode = backgroundMode;
324
    }
325
    
326
    /** Getter for property textAlign.
327
     * @return Value of property textAlign.
328
     */
329
    public int getTextAlign() {
330
        return textAlign;
331
    }
332
    
333
    /** Setter for property textAlign.
334
     * @param textAlign New value of property textAlign.
335
     */
336
    public void setTextAlign(int textAlign) {
337
        this.textAlign = textAlign;
338
    }
339
    
340
    /** Getter for property polyFillMode.
341
     * @return Value of property polyFillMode.
342
     */
343
    public int getPolyFillMode() {
344
        return polyFillMode;
345
    }
346
    
347
    /** Setter for property polyFillMode.
348
     * @param polyFillMode New value of property polyFillMode.
349
     */
350
    public void setPolyFillMode(int polyFillMode) {
351
        this.polyFillMode = polyFillMode;
352
    }
353
    
354
    public void setLineJoinRectangle(PdfContentByte cb) {
355 1 1. setLineJoinRectangle : negated conditional → NO_COVERAGE
        if (lineJoin != 0) {
356
            lineJoin = 0;
357 1 1. setLineJoinRectangle : removed call to com/lowagie/text/pdf/PdfContentByte::setLineJoin → NO_COVERAGE
            cb.setLineJoin(0);
358
        }
359
    }
360
    
361
    public void setLineJoinPolygon(PdfContentByte cb) {
362 1 1. setLineJoinPolygon : negated conditional → NO_COVERAGE
        if (lineJoin == 0) {
363
            lineJoin = 1;
364 1 1. setLineJoinPolygon : removed call to com/lowagie/text/pdf/PdfContentByte::setLineJoin → NO_COVERAGE
            cb.setLineJoin(1);
365
        }
366
    }
367
    
368
    public boolean getLineNeutral() {
369 2 1. getLineNeutral : negated conditional → NO_COVERAGE
2. getLineNeutral : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return (lineJoin == 0);
370
    }
371
    
372
}

Mutations

107

1.1
Location :
Killed by : none
removed call to com/lowagie/text/pdf/codec/wmf/MetaState::setMetaState → NO_COVERAGE

132

1.1
Location : addMetaObject
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : addMetaObject
Killed by : none
negated conditional → NO_COVERAGE

133

1.1
Location : addMetaObject
Killed by : none
negated conditional → NO_COVERAGE

143

1.1
Location : selectMetaObject
Killed by : none
negated conditional → NO_COVERAGE

150

1.1
Location : selectMetaObject
Killed by : none
negated conditional → NO_COVERAGE

152

1.1
Location : selectMetaObject
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setColorFill → NO_COVERAGE

154

1.1
Location : selectMetaObject
Killed by : none
negated conditional → NO_COVERAGE

156

1.1
Location : selectMetaObject
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setColorFill → NO_COVERAGE

163

1.1
Location : selectMetaObject
Killed by : none
negated conditional → NO_COVERAGE

165

1.1
Location : selectMetaObject
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setColorStroke → NO_COVERAGE

166

1.1
Location : selectMetaObject
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : selectMetaObject
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

3.3
Location : selectMetaObject
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setLineWidth → NO_COVERAGE

169

1.1
Location : selectMetaObject
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setLineDash → NO_COVERAGE

172

1.1
Location : selectMetaObject
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setLiteral → NO_COVERAGE

175

1.1
Location : selectMetaObject
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setLiteral → NO_COVERAGE

178

1.1
Location : selectMetaObject
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setLineDash → NO_COVERAGE

181

1.1
Location : selectMetaObject
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setLineDash → NO_COVERAGE

200

1.1
Location : saveState
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::saveState → NO_COVERAGE

207

1.1
Location : restoreState
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : restoreState
Killed by : none
negated conditional → NO_COVERAGE

208

1.1
Location : restoreState
Killed by : none
removed negation → NO_COVERAGE

210

1.1
Location : restoreState
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

211

1.1
Location : restoreState
Killed by : none
negated conditional → NO_COVERAGE

214

1.1
Location : restoreState
Killed by : none
Changed increment from -1 to 1 → NO_COVERAGE

2.2
Location : restoreState
Killed by : none
negated conditional → NO_COVERAGE

215

1.1
Location : restoreState
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::restoreState → NO_COVERAGE

218

1.1
Location : restoreState
Killed by : none
removed call to com/lowagie/text/pdf/codec/wmf/MetaState::setMetaState → NO_COVERAGE

223

1.1
Location : cleanup
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : cleanup
Killed by : none
Changed increment from -1 to 1 → NO_COVERAGE

3.3
Location : cleanup
Killed by : none
negated conditional → NO_COVERAGE

224

1.1
Location : cleanup
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::restoreState → NO_COVERAGE

228

1.1
Location : transformX
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

2.2
Location : transformX
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

3.3
Location : transformX
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

4.4
Location : transformX
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/pdf/codec/wmf/MetaState::transformX → NO_COVERAGE

232

1.1
Location : transformY
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

2.2
Location : transformY
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

3.3
Location : transformY
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

4.4
Location : transformY
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

5.5
Location : transformY
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/pdf/codec/wmf/MetaState::transformY → NO_COVERAGE

260

1.1
Location : transformAngle
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : transformAngle
Killed by : none
removed negation → NO_COVERAGE

3.3
Location : transformAngle
Killed by : none
negated conditional → NO_COVERAGE

261

1.1
Location : transformAngle
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : transformAngle
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

3.3
Location : transformAngle
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : transformAngle
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/pdf/codec/wmf/MetaState::transformAngle → NO_COVERAGE

355

1.1
Location : setLineJoinRectangle
Killed by : none
negated conditional → NO_COVERAGE

357

1.1
Location : setLineJoinRectangle
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setLineJoin → NO_COVERAGE

362

1.1
Location : setLineJoinPolygon
Killed by : none
negated conditional → NO_COVERAGE

364

1.1
Location : setLineJoinPolygon
Killed by : none
removed call to com/lowagie/text/pdf/PdfContentByte::setLineJoin → NO_COVERAGE

369

1.1
Location : getLineNeutral
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getLineNeutral
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2