Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

EMF record rotation for EMR_POLYGON16

0.00/5 (No votes)
17 Nov 2002 1  
EMF record rotation for EMR_POLYGON16

Sample Image - MROT.jpg

Introduction

When I decided to build a PowerPoint-like visual editor, first thing I had to do was pasting clipboard contents to my view. But it's all around MSDN, CodeGuru etc. Like DrawCli, JTDraw, etc..

But the second part, when I had to rotate clipboard image, it was different. I could not find any hints at all.

Maybe it's because of my poor ability to search things.. :( Anyway, I decided to rotate EMF.

The API function SetWorldTransform() is not supported on Win98. Actually I'm working on Win2K, but I wanted to rotate EMF without any GDI transformation functions.

I think the steps to rotate EMF image is as follows.

  1. Draw COleClientItem inherited object to CMetaFileDC(A_DC).
  2. Get EMF from A_DC.
  3. Draw acquired EMF bits as rotated on another CMetaFileDC(B_DC).
  4. Get EMF from B_DC.
  5. Draw rotated EMF file to output DC

Enumerating EMF (or WMF) requires CALLBACK function. Global scope can be used, but I've put it into my CItem class as static member function. No-static member function cannot be used as CALLBACK function in EnumEnhMetaFile.

Included source files were built as following sequence.

  1. Create new MFC (EXE) project with Ole Container options selected.
  2. CblahblahCntrItem class is the COleClientItem inherited class. So, if you want some properties in your item, put your things into C~~CntrItem class.
  3. Add ID_EDIT_PASTE event handler
  4. Customize draw function

That's all.

Download project & build. Run MROT and get some vector image on your system's clipboard, and paste into MROT.

Then you can see the clipart on MROT's view. Then push RIGHT or LEFT cursor key. Then the image will rotate by 5 in degrees.

MROT handles only EMR_POLYGON16 record. So, If your clipart contains other polygonal records or rectangular records.. MROT cannot display & rotate it well.

MSDN\TECHART\1619\EMFDCODE.EXE on you MSDN CD can help you inspect your source clipart.

Now I think, building PowerPoint-like visual editor is not difficult (I say editor..:)) but will take long time if you approach as what I did. I'll move to GDI+, because I don't have to convert any polygon points at all.

P.S. You may wonder what ConvertEMF member function is for. Some cliparts have their own mapping aspects. Mapmode as MM_ANISOTROPIC, and Window/Viewport Extents inversed.. so, same rotation command will act differently on those kind of cliparts... ConvertEMF converts WindowExt inversed cliparts to non-inversed one.

Is there anyone to handle all of EMF records to rotate? :)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here