1 #Region "Microsoft.VisualBasic::fc835d3e5aac0f293ed406ae1813779d, Microsoft.VisualBasic.Core\Extensions\Image\Wmf.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Class Wmf
35     
36     '         Properties: FilePath, Size
37     
38     '         Constructor: (+1 OverloadsSub New
39     '         Sub: __release, Dispose, DrawCircle
40     
41     
42     ' /********************************************************************************/
43
44 #End Region
45
46 Imports System.Drawing
47 Imports System.Drawing.Drawing2D
48 Imports System.Drawing.Imaging
49
50 Namespace Imaging
51
52     ''' <summary>
53     ''' Windows Metafile (WMF) is an image file format originally designed for Microsoft Windows in the 1990s. 
54     ''' Windows Metafiles are intended to be portable between applications and may contain both vector graphics 
55     ''' and bitmap components. It acts in a similar manner to SVG files.
56     ''' 
57     ''' Essentially, a WMF file stores a list of function calls that have to be issued to the Windows Graphics 
58     ''' Device Interface (GDI) layer to display an image on screen. Since some GDI functions accept pointers 
59     ''' to callback functions for error handling, a WMF file may erroneously include executable code.
60     ''' 
61     ''' WMF Is a 16-bit format introduced in Windows 3.0. It Is the native vector format for Microsoft Office 
62     ''' applications such as Word, PowerPoint, And Publisher. As of 2015 revision 12 of the Windows Metafile 
63     ''' Format specification Is available for online reading Or download as PDF.
64     ''' </summary>
65     ''' <remarks>
66     ''' The original 16 bit WMF file format was fully specified in volume 4 of the 1992 Windows 3.1 SDK documentation
67     ''' (at least if combined with the descriptions of the individual functions and structures in the other volumes), 
68     ''' but that specification was vague about a few details. These manuals were published as printed books available 
69     ''' in bookstores with no click through EULA or other unusual licensing restrictions (just a general warning that 
70     ''' if purchased as part of a software bundle, the software would be subject to one).
71     ''' 
72     ''' Over time the existence Of that historic specification was largely forgotten And some alternative implementations 
73     ''' resorted To reverse engineering To figure out the file format from existing WMF files, which was difficult And 
74     ''' Error prone. In September 2006, Microsoft again published the WMF file format specification In the context Of 
75     ''' the Microsoft Open Specification Promise, promising To Not assert patent rights To file format implementors. 
76     ''' </remarks>
77     Public Class Wmf : Inherits GDICanvas
78         Implements IDisposable
79
80         ReadOnly curMetafile As Metafile
81         ReadOnly gSource As Graphics
82         ReadOnly hdc As IntPtr
83
84         ''' <summary>
85         ''' The file path of the target wmf image file.
86         ''' </summary>
87         ''' <returns></returns>
88         Public ReadOnly Property FilePath As String
89         Public Overrides ReadOnly Property Size As Size
90
91         ''' <summary>
92         ''' The WMF format was designed to be executed by the Windows GDI layer in order to restore the image, but as 
93         ''' the WMF binary files contain the definition of the GDI graphic primitives that constitute this image, it is 
94         ''' possible to design alternative libraries that render WMF binary files, like the Kyktir application does, or 
95         ''' convert them into other graphic formats. For example, the Batik library is able to render WMF files and 
96         ''' convert them to their Scalable Vector Graphics (SVG) equivalent. The Vector Graphics package of the FreeHEP 
97         ''' Java library allows the saving of Java2D drawings as Enhanced Metafiles (EMF). Inkscape and XnView can export 
98         ''' to WMF or EMF.
99         ''' </summary>
100         ''' <param name="size"></param>
101         ''' <param name="save$"></param>
102         ''' <param name="backgroundColor$"></param>
103         Sub New(size As Size, save$, Optional backgroundColor$ = NameOf(Color.Transparent))
104             Dim bitmap As New Bitmap(size.Width, size.Height)
105
106             gSource = Graphics.FromImage(bitmap)
107             gSource.Clear(backgroundColor.TranslateColor)
108
109             hdc = gSource.GetHdc()
110             size = bitmap.Size
111             curMetafile = New Metafile(save, hdc)
112             Graphics = Graphics.FromImage(curMetafile)
113             Graphics.SmoothingMode = SmoothingMode.HighQuality
114
115             FilePath = save
116         End Sub
117
118         Private Sub __release()
119             Call gSource.ReleaseHdc(hdc)
120             Call Graphics.Dispose()
121             Call gSource.Dispose()
122         End Sub
123
124         Public Overrides Sub Dispose()
125             Call __release()
126             MyBase.Dispose()
127         End Sub
128
129         Public Overrides Sub DrawCircle(center As PointF, fill As Color, stroke As Pen, radius As Single)
130             Throw New NotImplementedException()
131         End Sub
132     End Class
133 End Namespace