Paste2Xaml and Ab2d.ReaderWmf

Ab2d.ReaderWmf - metafile importer

Use vector graphics from svg files in
WPF and Silverlight applications.
Download now

Ab2d.ReaderWmf - metafile importer

Ab2d.ReaderWmf is a class library that can be used to read Windows metafiles (wmf) and also Enhanced Metafiles (emf) in runtime and import its elements into WPF's Viewbox.

Note that Ab2d.ReaderWmf cannot be used in Silverlight applications - but can be used in XBAP Web Browser application. For Silverlight use Paste2Xaml and select export as Silverlight xaml in the export options.

The library is used by Paste2Xaml application. It can also be used in any other application which is using metafile cliparts. With ReaderWmf library there is no need to convert them into xaml - metafiles can be simple imported at runtime when needed.

Note that Ab2d.ReaderWmf cannot be used in Silverlight applications. But it is possible to convert metafiles into XAML for Silverlight and Windows Store (Windows RT) applications with the Paste2Xaml converter.


Read Windows metafiles (wmf) or Enhanced Metafiles (emf) file in XAML:

  • In project add reference to Ab2d.ReaderWmf
  • Add namespace definition into root xaml element (for example Window):
    xmlns:ab2d="clr-namespace:Ab2d.Controls;assembly=Ab2d.ReaderWmf"
  • Use Ab2d.Controls.WmfViewbox to read a metafile file as Shapes - set Source property to metafile location.
  • Use Ab2d.Controls.WmfDrawing to read a metafile file as Drawings - set Source property to metafile location.

Source property can be uses just as Source of the Image control. Depending on the location and metafile build action use of the following patterns to load the file. The following examples show how to read matafile (as Shapes) from various resources.

Location: samples folder in project, Build Action: Content
<ab2d:WmfViewbox Source="samples/myClipart.emf"/>

Location: samples folder in project, Build Action: Resource - embedded into assembly
<ab2d:WmfViewbox Source="samples/myClipart.emf"/>

Location: internet, Build Action: not included in project
<ab2d:WmfViewbox Source="http://www.myweb.com/images/myClipart.emf"/>

Location: loose emf file on the local disk, Build Action: not included in the project
<ab2d:WmfViewbox Source="c:\temp\myClipart.emf"/>

Location: loose emf file in the application directory, Build Action: not included in the project
<ab2d:WmfViewbox Source="pack://siteoforigin:,,,/myClipart.emf"/>


Related Blog posts
To see the development history of Ab2d.ReaderWmf and Paset2Xaml, check out the related blog posts.


Version history

New in version 7.0

  • Added ConvertPatternBrushesToColor to ReaderWmf - use data from pattern brush to change the color of the shape
  • Added DisableTextScaling property - in case text is wrongly scaled, user can disable scaling of text
  • Improved reading geometries when rectangle or ellipse have both Canvas position (Canvas.Left or Canvas.Top) and transformation set.
  • Improved xaml writer to prevent writing Canvas.Left = "0" and Canvas.Top = "0" (zero values can be skipped).
  • Prevented writing "Canvas.Left" and "Canvas.Top" properties in XAML two times.
  • Added IgnoreRootElementSize property to GeometrySetting - added possibility to remove the transformations or RectangleGeometry based on the size or root element.
  • Fixed problems where some separate lines were connected with additional line but they should not be.
  • Improve reading metafiles that have negative width or height specified in metafile header
  • Prevented throwing "The method or property is only available in Professional version!" under some circumstances.
  • Fixed not showing some texts under some circumstances.

New in version 6.4

  • Added reading images from EMR_ALPHABLEND records. Note that usually those images are not rendered correctly because the blend dwRop operations are not supported by WPF, but at least user can get the image and convert it manually to a transparent image that could be used to achieve correct results.
  • Added ResolveBitmapOperation that is called in processing EMR_ALPHABLEND record - here the user can change the bitmap to get correct results - for example convert black to transparent.
  • Invisible objects (Visibility != Visible) are not exported to geometry any more.
  • Shapes with Opacity set (Opacity < 1.0) are now correctly exported as geometries.

New in version 6.3

  • Added Ab2d.Common.ReaderWmf.TrueTransform class that can be used to transform the read objects.
  • Added Transform method to ReadeWmf to transform the read metafile objects.
  • Improved positioning text elements under some cases.

New in version 6.2

  • Improved positioning some elements (in case ViewPortExtentX or ViewPortExtentY is set).

New in version 6.1

  • Improved positioning text where its bounds and ptrReference is not set.

New in version 6.0

  • Change build target framework from .Net 3.0 to 3.5 Client Profile.
  • Added support for XAML export for Windows Store applications (Windows Runtime). This can be done with passing an instance of WinRtXamlWriterSettings class to GetXaml method.

New in version 5.6

  • Improved scaling text. Before sometimes the text was not correctly scaled - for example when pasting cells from excel the text can go out of bounds. The text is scaled with using RenderTransform on TextBlocks. Note that scaling can be turned off with setting ProcessCharacterSpacing property to false.
  • Added support for text that is defined by glyphs indexes instead of unicode characters (usually when the metafile was created from the data that was sent to printer).
  • Fixed processing character spacing for special charter marks that are shown over another character like carets, etc.
  • Fixed exporting to XAML when the content of the Text property contains curly brackets. Before parser wanted to use them for binding expression.
  • Added ResolveRasterOperation delegate that enables using custom brush when an unsupported raster operation is used in metafile.

New in version 5.5

  • The Read and ReadGeometry methods that take stream as parameter now read the metafiles directly from the stream and do not create a temp file from stream as before.
  • Fixed leaking GDI+ handles under some circumstances. This could lead to "Cannot open wmf file!" exception after opening a few thousands metafiles.

New in version 5.4

  • Improved using brush styles - BS_NULL is now correctly used.
  • Improved drawing Paths - in some cases only path stroke should be drawn without using any fill.
  • Added support for monochrome brushes.
  • Improved commercial licensing code to prevent delay caused in RSACryptoServiceProvider under some circumstances.
  • Added Ab2d.ZoomPanel.LicenseHelper.EmbeddedLicenseAssembly property to speed-up looking for embedded license key in commercial version.

New in version 5.3

  • Added support for pattern brushes. Because there are some differences between handling pattern brushes in GDI+ and WPF, it is possible to disable reading pattern brushes by setting ReadPatternBrushes to false.
  • Improved design time support for WmfViewbox and WmfDrawing controls - now the metafile is shown in design time.
  • Added MetafileLoading and MetafileLoaded events to WmfViewbox and WmfDrawing controls.
  • Fixed reading some embedded images that have their width or height negative.

New in version 5.2

  • Added MetafileUnits property. It specifies the units in which the metafile is read. By default its value is set to Pixel. It can be also set to Millimeter, Inch or GdiCompatable. This can be useful to preserve the positions and other properties when the drawing is created in millimeter or inch units.
  • Added GetSize(units) method that can be used to get the size of the read metafile in the specified units.
  • The size of the read metafile is now by default (if MetafileUnits is Pixel) the same as the size shown when metafile is opened by Window.
  • Improved reading metafiles that use MM_LOMETRIC, MM_HIMETRIC, MM_LOENGLISH, MM_HIENGLISH or MM_TWIPS mapping mode.
  • When reading polyline from a metafile and it has only 2 points a Line is used instead of a Polyline.
  • Added AutoSize property - defines if size of the root canvas is get from metafiles bounds or its frame. When bounds is used, the root canvas size is just as big as its containing objects.
  • Added UsedMinLineWidthFactor to get the used minimal line width.
  • Improved Ab2d.Utility.ReaderWmf.ResourceDictionaryWriter - now the process of creating ResourceDictionary from metafiles can be better customized by creating a derived class.
  • Removed obsolete Ab2d.WmfViewbox control - the control has been obsolete for a few versions - Ab2d.Controls.WmfViewbox should be used instead. This also removes the need for Designer assemblies to remove the obsolete control from Designer ToolBox.

New in version 5.1

  • Fixed reading some embedded images (before sometimes FileFormatException was thrown).
  • Improved positioning text and handling rotated texts.
  • Fixed reading arc and pie segments for some cases.
  • Improved GetXaml method - now the images are written to xaml without need to specify ResolveImagePath delegate. The uri format can be specified with the new DefaultImageUriFormatString property in XamlWritterSettings.
  • Added ImageFileExtention string to EmbeddedImageData.
  • Improved setting minimal line thickness. In metafile a line thickness can be specified to 1 pixel regardless of the zoom level - this is not possible in WPF and Silverlight. The algorithm that sets the line thickness has been improved to prevent getting too thick lines.

New in version 5.0

  • Improved reading detailed images from EMF+ records.
  • Optimizing gradients defined in metafiles.
  • Reading character spacing information.
  • Controlling the size of read metafile with CustomContentWidth, CustomContentHeight properties.
  • Added workaround for displaying Paths for Silverlight xaml.
  • PathGeometry is now written in xaml as collection of PathFigures instead of data string.
  • Each PathGeometry is analyzed and if possible it is converted into RectangleGeometry.
  • Fixed problems when running on 64-bit OS.
  • Fixed reading images that have width or height value defined as negative numbers.
  • Added IsClipboardMetafileAvailable, GetFromClipboard, GetGeometryFromClipboard methods.
  • Added RemoveEmptyTextBlocks property.
  • Added ProgressChanged event.
  • Improved ResourceDictionaryWriter class.

New in version 4.0

  • Greatly improved performance when reading metafiles.
  • Greatly improved reading and pasting objects from MS Office - images are now read from EMF+ part of the matafile and are much better quality than images stored in EMF part of the metafile.
  • Added support for Pie and Chord elements.
  • Added support for stretched text (condensed, widened).
  • fixed licensing issues on 64 bit Windows.
  • Fixed importing text rotated by 180 degrees.
  • Added ReadGeometry methods without geometry settings parameters that use default NoOptimization geometry settings (simplified use of ReadGeometry).
  • Improved support for clipping.
  • Changed calculation of MinLineWidthFactor (see help for more info).
  • Imporved GetXaml - now know colors are by default displayed by their name (Black, Red, ect.). This can be turned off by setting UseColorNames property on XamlWriterSettings.
  • Separate evaluation and commercial version.

New in version 3.0

  • Implemented export as Drawings.
  • Added options for optimizing geometry.
  • Added ReadGeometry class.
  • Added GetXaml class.
  • Added ResourceDictionaryWriter class.
  • Improved licensing with added evaluation support

New in version 2.0

  • Integrated licensing system - first commercial version.

New in version 1.4

  • Added support for pen's LineJoin, LineCap and Dash Style.
  • Added support for Arc.
  • Improved placing text in some metafiles.
  • Corrected the width of the lines.
  • Correctly use Polyline and Polygon.

New in version 1.3

  • fixed problems with some wmf files that were imported with some anomalies (lost details).

New in version 1.2

  • Fixed reading some wmf files - especially files exported from Autocad are converted properly now.
  • Added MinLineWidthFactor property - useful for metafiles with lots of lines. With the property it is possible to adjust thickness of the lines.
  • Added EmbeddedBitmapImages property that replaced the obsolete MetafileImages (because of misunderstanding of the property)
  • Added support for reading pixels (individual points) from metafiles - they are converted to Ellipse elements with the specified radius.

New in version 1.1

  • Added WmfViewbox control.
  • Added support for PenStyle (solid, dash, dashDot, dashDotDot, null)
  • Added EmbeddedBitmapImages property that replaced the obsolete MetafileImages (because of misunderstanding the property)
  • Fixed StrokeEndLineCap and StrokeStartLineCap when none (set to round) or only LineJoin is defined (set to the same as LineJoin)

 

Information about changes:
Subscribe to RSS feed to all Blog posts.
Subscribe to RSS feed to Blog posts related to Ab2d.ReaderWmf and Paste2Xaml.
Subscribe to newsletter - enter your email into Newsletter box on my Blog.