1 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 58 import com.lowagie.text.pdf.PdfTemplate; 59 import com.lowagie.text.pdf.codec.wmf.InputMeta; 60 import com.lowagie.text.pdf.codec.wmf.MetaDo; 61 62 69 70 public class ImgWMF extends Image { 71 72 74 ImgWMF(Image image) { 75 super(image); 76 } 77 78 85 86 public ImgWMF(URL url) throws BadElementException, IOException { 87 super(url); 88 processParameters(); 89 } 90 91 99 100 public ImgWMF(String filename) throws BadElementException, MalformedURLException , IOException { 101 this(Utilities.toURL(filename)); 102 } 103 104 111 112 public ImgWMF(byte[] img) throws BadElementException, IOException { 113 super((URL )null); 114 rawData = img; 115 originalData = img; 116 processParameters(); 117 } 118 119 124 125 private void processParameters() throws BadElementException, IOException { 126 type = IMGTEMPLATE; 127 originalType = ORIGINAL_WMF; 128 InputStream is = null; 129 try { 130 String errorID; 131 if (rawData == null){ 132 is = url.openStream(); 133 errorID = url.toString(); 134 } 135 else{ 136 is = new java.io.ByteArrayInputStream (rawData); 137 errorID = "Byte array"; 138 } 139 InputMeta in = new InputMeta(is); 140 if (in.readInt() != 0x9AC6CDD7) { 141 throw new BadElementException(errorID + " is not a valid placeable windows metafile."); 142 } 143 in.readWord(); 144 int left = in.readShort(); 145 int top = in.readShort(); 146 int right = in.readShort(); 147 int bottom = in.readShort(); 148 int inch = in.readWord(); 149 dpiX = 72; 150 dpiY = 72; 151 scaledHeight = (float)(bottom - top) / inch * 72f; 152 setTop(scaledHeight); 153 scaledWidth = (float)(right - left) / inch * 72f; 154 setRight(scaledWidth); 155 } 156 finally { 157 if (is != null) { 158 is.close(); 159 } 160 plainWidth = getWidth(); 161 plainHeight = getHeight(); 162 } 163 } 164 165 170 public void readWMF(PdfTemplate template) throws IOException , DocumentException { 171 setTemplateData(template); 172 template.setWidth(getWidth()); 173 template.setHeight(getHeight()); 174 InputStream is = null; 175 try { 176 if (rawData == null){ 177 is = url.openStream(); 178 } 179 else{ 180 is = new java.io.ByteArrayInputStream (rawData); 181 } 182 MetaDo meta = new MetaDo(is, template); 183 meta.readAll(); 184 } 185 finally { 186 if (is != null) { 187 is.close(); 188 } 189 } 190 } 191 } 192 | Popular Tags |