1 | /* | |
2 | * $Id: ImgWMF.java 4065 2009-09-16 23:09:11Z psoares33 $ | |
3 | * $Name$ | |
4 | * | |
5 | * Copyright 1999, 2000, 2001, 2002 by Paulo Soares. | |
6 | * | |
7 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
8 | * (the "License"); you may not use this file except in compliance with the License. | |
9 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
10 | * | |
11 | * Software distributed under the License is distributed on an "AS IS" basis, | |
12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
13 | * for the specific language governing rights and limitations under the License. | |
14 | * | |
15 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
16 | * | |
17 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
18 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
19 | * All Rights Reserved. | |
20 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
21 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
22 | * | |
23 | * Contributor(s): all the names of the contributors are added in the source code | |
24 | * where applicable. | |
25 | * | |
26 | * Alternatively, the contents of this file may be used under the terms of the | |
27 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
28 | * provisions of LGPL are applicable instead of those above. If you wish to | |
29 | * allow use of your version of this file only under the terms of the LGPL | |
30 | * License and not to allow others to use your version of this file under | |
31 | * the MPL, indicate your decision by deleting the provisions above and | |
32 | * replace them with the notice and other provisions required by the LGPL. | |
33 | * If you do not delete the provisions above, a recipient may use your version | |
34 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
35 | * | |
36 | * This library is free software; you can redistribute it and/or modify it | |
37 | * under the terms of the MPL as stated above or under the terms of the GNU | |
38 | * Library General Public License as published by the Free Software Foundation; | |
39 | * either version 2 of the License, or any later version. | |
40 | * | |
41 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
42 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
43 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
44 | * details. | |
45 | * | |
46 | * If you didn't download this code from the following link, you should check if | |
47 | * you aren't using an obsolete version: | |
48 | * http://www.lowagie.com/iText/ | |
49 | */ | |
50 | ||
51 | package com.lowagie.text; | |
52 | ||
53 | import java.io.IOException; | |
54 | import java.io.InputStream; | |
55 | import java.net.MalformedURLException; | |
56 | import java.net.URL; | |
57 | import com.lowagie.text.error_messages.MessageLocalization; | |
58 | ||
59 | import com.lowagie.text.pdf.PdfTemplate; | |
60 | import com.lowagie.text.pdf.codec.wmf.InputMeta; | |
61 | import com.lowagie.text.pdf.codec.wmf.MetaDo; | |
62 | ||
63 | /** | |
64 | * An <CODE>ImgWMF</CODE> is the representation of a windows metafile | |
65 | * that has to be inserted into the document | |
66 | * | |
67 | * @see Element | |
68 | * @see Image | |
69 | */ | |
70 | ||
71 | public class ImgWMF extends Image { | |
72 | | |
73 | // Constructors | |
74 | | |
75 | ImgWMF(Image image) { | |
76 | super(image); | |
77 | } | |
78 | | |
79 | /** | |
80 | * Constructs an <CODE>ImgWMF</CODE>-object, using an <VAR>url</VAR>. | |
81 | * | |
82 | * @param url the <CODE>URL</CODE> where the image can be found | |
83 | * @throws BadElementException on error | |
84 | * @throws IOException on error | |
85 | */ | |
86 | | |
87 | public ImgWMF(URL url) throws BadElementException, IOException { | |
88 | super(url); | |
89 |
1
1. |
processParameters(); |
90 | } | |
91 | | |
92 | /** | |
93 | * Constructs an <CODE>ImgWMF</CODE>-object, using a <VAR>filename</VAR>. | |
94 | * | |
95 | * @param filename a <CODE>String</CODE>-representation of the file that contains the image. | |
96 | * @throws BadElementException on error | |
97 | * @throws MalformedURLException on error | |
98 | * @throws IOException on error | |
99 | */ | |
100 | | |
101 | public ImgWMF(String filename) throws BadElementException, IOException { | |
102 | this(Utilities.toURL(filename)); | |
103 | } | |
104 | | |
105 | /** | |
106 | * Constructs an <CODE>ImgWMF</CODE>-object from memory. | |
107 | * | |
108 | * @param img the memory image | |
109 | * @throws BadElementException on error | |
110 | * @throws IOException on error | |
111 | */ | |
112 | | |
113 | public ImgWMF(byte[] img) throws BadElementException, IOException { | |
114 | super((URL)null); | |
115 | rawData = img; | |
116 | originalData = img; | |
117 |
1
1. |
processParameters(); |
118 | } | |
119 | | |
120 | /** | |
121 | * This method checks if the image is a valid WMF and processes some parameters. | |
122 | * @throws BadElementException | |
123 | * @throws IOException | |
124 | */ | |
125 | | |
126 | private void processParameters() throws BadElementException, IOException { | |
127 | type = IMGTEMPLATE; | |
128 | originalType = ORIGINAL_WMF; | |
129 | InputStream is = null; | |
130 | try { | |
131 | String errorID; | |
132 |
1
1. processParameters : negated conditional → NO_COVERAGE |
if (rawData == null){ |
133 | is = url.openStream(); | |
134 | errorID = url.toString(); | |
135 | } | |
136 | else{ | |
137 | is = new java.io.ByteArrayInputStream(rawData); | |
138 | errorID = "Byte array"; | |
139 | } | |
140 | InputMeta in = new InputMeta(is); | |
141 |
1
1. processParameters : negated conditional → NO_COVERAGE |
if (in.readInt() != 0x9AC6CDD7) { |
142 | throw new BadElementException(MessageLocalization.getComposedMessage("1.is.not.a.valid.placeable.windows.metafile", errorID)); | |
143 | } | |
144 | in.readWord(); | |
145 | int left = in.readShort(); | |
146 | int top = in.readShort(); | |
147 | int right = in.readShort(); | |
148 | int bottom = in.readShort(); | |
149 | int inch = in.readWord(); | |
150 | dpiX = 72; | |
151 | dpiY = 72; | |
152 |
3
1. processParameters : Replaced integer subtraction with addition → NO_COVERAGE 2. processParameters : Replaced float division with multiplication → NO_COVERAGE 3. processParameters : Replaced float multiplication with division → NO_COVERAGE |
scaledHeight = (float)(bottom - top) / inch * 72f; |
153 |
1
1. processParameters : removed call to com/lowagie/text/ImgWMF::setTop → NO_COVERAGE |
setTop(scaledHeight); |
154 |
3
1. processParameters : Replaced integer subtraction with addition → NO_COVERAGE 2. processParameters : Replaced float division with multiplication → NO_COVERAGE 3. processParameters : Replaced float multiplication with division → NO_COVERAGE |
scaledWidth = (float)(right - left) / inch * 72f; |
155 |
1
1. processParameters : removed call to com/lowagie/text/ImgWMF::setRight → NO_COVERAGE |
setRight(scaledWidth); |
156 | } | |
157 | finally { | |
158 |
1
1. processParameters : negated conditional → NO_COVERAGE |
if (is != null) { |
159 |
1
1. processParameters : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
160 | } | |
161 | plainWidth = getWidth(); | |
162 | plainHeight = getHeight(); | |
163 | } | |
164 | } | |
165 | | |
166 | /** Reads the WMF into a template. | |
167 | * @param template the template to read to | |
168 | * @throws IOException on error | |
169 | * @throws DocumentException on error | |
170 | */ | |
171 | public void readWMF(PdfTemplate template) throws IOException, DocumentException { | |
172 |
1
1. readWMF : removed call to com/lowagie/text/ImgWMF::setTemplateData → NO_COVERAGE |
setTemplateData(template); |
173 |
1
1. readWMF : removed call to com/lowagie/text/pdf/PdfTemplate::setWidth → NO_COVERAGE |
template.setWidth(getWidth()); |
174 |
1
1. readWMF : removed call to com/lowagie/text/pdf/PdfTemplate::setHeight → NO_COVERAGE |
template.setHeight(getHeight()); |
175 | InputStream is = null; | |
176 | try { | |
177 |
1
1. readWMF : negated conditional → NO_COVERAGE |
if (rawData == null){ |
178 | is = url.openStream(); | |
179 | } | |
180 | else{ | |
181 | is = new java.io.ByteArrayInputStream(rawData); | |
182 | } | |
183 | MetaDo meta = new MetaDo(is, template); | |
184 |
1
1. readWMF : removed call to com/lowagie/text/pdf/codec/wmf/MetaDo::readAll → NO_COVERAGE |
meta.readAll(); |
185 | } | |
186 | finally { | |
187 |
1
1. readWMF : negated conditional → NO_COVERAGE |
if (is != null) { |
188 |
1
1. readWMF : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
189 | } | |
190 | } | |
191 | } | |
192 | } | |
Mutations | ||
89 |
1.1 |
|
117 |
1.1 |
|
132 |
1.1 |
|
141 |
1.1 |
|
152 |
1.1 2.2 3.3 |
|
153 |
1.1 |
|
154 |
1.1 2.2 3.3 |
|
155 |
1.1 |
|
158 |
1.1 |
|
159 |
1.1 |
|
172 |
1.1 |
|
173 |
1.1 |
|
174 |
1.1 |
|
177 |
1.1 |
|
184 |
1.1 |
|
187 |
1.1 |
|
188 |
1.1 |