PDA

View Full Version : Copying Vector Images to the Windows Clipboard



pherthyl
22nd May 2008, 03:16
Hey Everyone,

I've been thinking about how to solve this for a long time, but haven't come up with anything satisfactory.

Basically, I have a graphicsview scene with some boxes and lines, and I want to be able to copy a part of that scene and paste it into an application like MS Word. The way I do it right now is to find the area that was selected, then render that area to an image and put it into the clipboard buffer. That works ok, but it's rendered as an image, so resizing it in word will degrade the quality very badly.

So what I really want is to copy it in some sort of vector format, so that Word will be able to resize it properly. Now on Windows my best bet seems to be EMF/WMF, which is a vector format basically consisting of GDI drawing commands. Obviously Qt can't export that (as far as I can tell), so I'll need to convert from one of the formats that Qt can create (SVG and PDF would be the best candidates I guess).

So has anyone approached this problem before? I can't find any good libraries that will allow me to convert svg or pdf to EMF/WMF, or more generally, how to copy vector data to the windows clipboard. Any suggestions?

I've tried uniconverter which claims to convert SVG to WMF, but it just produced garbage on a sample file I had. Another shareware converter also produced inaccurate results. Seems like it's not an easy task.

wysota
22nd May 2008, 11:08
Probably the easiest solution would be to export to pdf and then convert it to postscript. There is a good chance M$ cra... apps will handle that.

pherthyl
22nd May 2008, 16:01
Hmm, good idea, I will give that a try. I hate going from the joy of Qt to the hell of Windows API... :)

wysota
22nd May 2008, 17:21
It's not Windows API here that is a problem, it is the point of view of Micro$oft people what to consider a standard (hell... SVG can't be a standard because it wasn't developed in Microsoft, right?).

pherthyl
22nd May 2008, 18:49
Yup. How nice of a world it would be if I could just shove SVG onto the clipboard and have apps handle that. Not like SVG is a hard format to support these days..

It seems to get this to work I have four options:

1. Somehow render my graphicsview using GDI+ commands, which can then be saved as an enhanced metafile. That will probably require me to create a custom paintdevice, which I'm not clear on yet.

2. Export SVG/PDF/PS and find a converter that actually works (difficult!), then copy the converted format to the clipboard.

3. Copy an OLE object. No idea how to approach this yet, but this is how Word/Excel integration works.

4. Use ActiveQt to create an ActiveX server which can then be inserted into word as Insert Object. This is not as desireable, as I want it to work with the regular clipboard.