/* ====================================================================
Licensed To the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for Additional information regarding copyright ownership.
The ASF licenses this file To You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed To in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
/* ================================================================
* About NPOI
* Author: Tony Qu
* Author's email: tonyqus (at) gmail.com
* Author's Blog: tonyqus.wordpress.com.cn (wp.tonyqus.cn)
* HomePage: http://www.codeplex.com/npoi
* Contributors:
*
* ==============================================================*/
namespace HH.WMS.Utils.NPOI.HPSF
{
using System;
using HH.WMS.Utils.NPOI.Util;
///
/// Class To manipulate data in the Clipboard Variant (Variant#VT_CF VT_CF) format.
/// @author Drew Varner (Drew.Varner inOrAround sc.edu)
/// @since 2002-04-29
///
public class Thumbnail
{
///
/// OffSet in bytes where the Clipboard Format Tag starts in the byte[] returned by SummaryInformation#GetThumbnail()
///
public const int OFFSet_CFTAG = 4;
///
/// OffSet in bytes where the Clipboard Format starts in the byte[] returned by SummaryInformation#GetThumbnail()
///
/// This is only valid if the Clipboard Format Tag is CFTAG_WINDOWS
public const int OFFSet_CF = 8;
///
/// OffSet in bytes where the Windows Metafile (WMF) image data starts in the byte[] returned by SummaryInformation#GetThumbnail()
/// There is only WMF data at this point in the
/// byte[] if the Clipboard Format Tag is
/// CFTAG_WINDOWS and the Clipboard Format is
/// CF_METAFILEPICT.
///
/// Note: The byte[] that starts at
/// OFFSet_WMFDATA and ends at
/// GetThumbnail().Length - 1 forms a complete WMF
/// image. It can be saved To disk with a .wmf file
/// type and Read using a WMF-capable image viewer.
public const int OFFSet_WMFDATA = 20;
///
/// Clipboard Format Tag - Windows clipboard format
///
/// A DWORD indicating a built-in Windows clipboard format value
public const int CFTAG_WINDOWS = -1;
///
/// Clipboard Format Tag - Macintosh clipboard format
///
/// A DWORD indicating a Macintosh clipboard format value
public const int CFTAG_MACINTOSH = -2;
///
/// Clipboard Format Tag - Format ID
///
/// A GUID containing a format identifier (FMTID). This is rarely used.
public const int CFTAG_FMTID = -3;
///
/// Clipboard Format Tag - No Data
///
/// A DWORD indicating No data. This is rarely used.
public const int CFTAG_NODATA = 0;
///
/// Clipboard Format - Windows metafile format. This is the recommended way To store thumbnails in Property Streams.
///
/// Note:This is not the same format used in
/// regular WMF images. The clipboard version of this format has an
/// extra clipboard-specific header.
public const int CF_METAFILEPICT = 3;
///
/// Clipboard Format - Device Independent Bitmap
///
public const int CF_DIB = 8;
///
/// Clipboard Format - Enhanced Windows metafile format
///
public const int CF_ENHMETAFILE = 14;
///
/// Clipboard Format - Bitmap
///
/// see msdn.microsoft.com/library/en-us/dnw98bk/html/clipboardoperations.asp
[Obsolete]
public const int CF_BITMAP = 2;
/**
* A byte[] To hold a thumbnail image in (
* Variant#VT_CF VT_CF) format.
*/
private byte[] thumbnailData = null;
///
/// Default Constructor. If you use it then one you'll have To Add
/// the thumbnail byte[] from {@link
/// SummaryInformation#GetThumbnail()} To do any useful
/// manipulations, otherwise you'll Get a
/// NullPointerException.
///
public Thumbnail()
{
}
///
/// Initializes a new instance of the class.
///
/// The thumbnail data.
public Thumbnail(byte[] thumbnailData)
{
this.thumbnailData = thumbnailData;
}
///
/// Gets or sets the thumbnail as a byte[] in {@link
/// Variant#VT_CF VT_CF} format.
///
/// The thumbnail value
public byte[] ThumbnailData
{
get
{
return thumbnailData;
}
set { this.thumbnailData = value; }
}
///
/// Returns an int representing the Clipboard
/// Format Tag
/// Possible return values are:
///
/// - {@link #CFTAG_WINDOWS CFTAG_WINDOWS}
/// - {@link #CFTAG_MACINTOSH CFTAG_MACINTOSH}
/// - {@link #CFTAG_FMTID CFTAG_FMTID}
/// - {@link #CFTAG_NODATA CFTAG_NODATA}
///
///
/// A flag indicating the Clipboard Format Tag
public long ClipboardFormatTag
{
get
{
long clipboardFormatTag = LittleEndian.GetUInt(this.ThumbnailData,
OFFSet_CFTAG);
return clipboardFormatTag;
}
}
///
/// Returns an int representing the Clipboard
/// Format
/// Will throw an exception if the Thumbnail's Clipboard Format
/// Tag is not {@link Thumbnail#CFTAG_WINDOWS CFTAG_WINDOWS}.
/// Possible return values are:
///
/// - {@link #CF_METAFILEPICT CF_METAFILEPICT}
/// - {@link #CF_DIB CF_DIB}
/// - {@link #CF_ENHMETAFILE CF_ENHMETAFILE}
/// - {@link #CF_BITMAP CF_BITMAP}
///
///
/// a flag indicating the Clipboard Format
public long GetClipboardFormat()
{
if (!(ClipboardFormatTag == CFTAG_WINDOWS))
throw new HPSFException("Clipboard Format Tag of Thumbnail must " +
"be CFTAG_WINDOWS.");
return LittleEndian.GetUInt(this.ThumbnailData, OFFSet_CF);
}
///
/// Returns the Thumbnail as a byte[] of WMF data
/// if the Thumbnail's Clipboard Format Tag is {@link
/// #CFTAG_WINDOWS CFTAG_WINDOWS} and its Clipboard Format is
/// {@link #CF_METAFILEPICT CF_METAFILEPICT}
/// This
/// byte[] is in the traditional WMF file, not the
/// clipboard-specific version with special headers.
/// See http://www.wvware.com/caolan/ora-wmf.html
/// for more information on the WMF image format.
/// @return A WMF image of the Thumbnail
/// @throws HPSFException if the Thumbnail isn't CFTAG_WINDOWS and
/// CF_METAFILEPICT
///
///
public byte[] GetThumbnailAsWMF()
{
if (!(ClipboardFormatTag == CFTAG_WINDOWS))
throw new HPSFException("Clipboard Format Tag of Thumbnail must " +
"be CFTAG_WINDOWS.");
if (!(GetClipboardFormat() == CF_METAFILEPICT))
throw new HPSFException("Clipboard Format of Thumbnail must " +
"be CF_METAFILEPICT.");
else
{
byte[] thumbnail = this.ThumbnailData;
int wmfImageLength = thumbnail.Length - OFFSet_WMFDATA;
byte[] wmfImage = new byte[wmfImageLength];
Array.Copy(thumbnail,
OFFSet_WMFDATA,
wmfImage,
0,
wmfImageLength);
return wmfImage;
}
}
}
}