1 2 17 18 package org.apache.poi.hpsf; 19 20 import org.apache.poi.util.LittleEndian; 21 30 public class Thumbnail 31 { 32 33 38 public static int OFFSET_CFTAG = 4; 39 40 48 public static int OFFSET_CF = 8; 49 50 66 public static int OFFSET_WMFDATA = 20; 67 68 74 public static int CFTAG_WINDOWS = -1; 75 76 82 public static int CFTAG_MACINTOSH = -2; 83 84 90 public static int CFTAG_FMTID = -3; 91 92 98 public static int CFTAG_NODATA = 0; 99 100 108 public static int CF_METAFILEPICT = 3; 109 110 113 public static int CF_DIB = 8; 114 115 118 public static int CF_ENHMETAFILE = 14; 119 120 127 public static int CF_BITMAP = 2; 128 129 133 private byte[] thumbnailData = null; 134 135 136 137 144 public Thumbnail() 145 { 146 super(); 147 } 148 149 150 151 157 public Thumbnail(final byte[] thumbnailData) 158 { 159 this.thumbnailData = thumbnailData; 160 } 161 162 163 164 171 public byte[] getThumbnail() 172 { 173 return thumbnailData; 174 } 175 176 177 178 185 public void setThumbnail(final byte[] thumbnail) 186 { 187 this.thumbnailData = thumbnail; 188 } 189 190 191 192 206 public long getClipboardFormatTag() 207 { 208 long clipboardFormatTag = LittleEndian.getUInt(getThumbnail(), 209 OFFSET_CFTAG); 210 return clipboardFormatTag; 211 } 212 213 214 215 234 public long getClipboardFormat() throws HPSFException 235 { 236 if (!(getClipboardFormatTag() == CFTAG_WINDOWS)) 237 throw new HPSFException("Clipboard Format Tag of Thumbnail must " + 238 "be CFTAG_WINDOWS."); 239 240 return LittleEndian.getUInt(getThumbnail(), OFFSET_CF); 241 } 242 243 244 245 261 public byte[] getThumbnailAsWMF() throws HPSFException 262 { 263 if (!(getClipboardFormatTag() == CFTAG_WINDOWS)) 264 throw new HPSFException("Clipboard Format Tag of Thumbnail must " + 265 "be CFTAG_WINDOWS."); 266 if (!(getClipboardFormat() == CF_METAFILEPICT)) 267 throw new HPSFException("Clipboard Format of Thumbnail must " + 268 "be CF_METAFILEPICT."); 269 else 270 { 271 byte[] thumbnail = getThumbnail(); 272 int wmfImageLength = thumbnail.length - OFFSET_WMFDATA; 273 byte[] wmfImage = new byte[wmfImageLength]; 274 System.arraycopy(thumbnail, 275 OFFSET_WMFDATA, 276 wmfImage, 277 0, 278 wmfImageLength); 279 return wmfImage; 280 } 281 } 282 283 } 284 | Popular Tags |