QWMF class (inherits QPaintDevice) Implements WMF export and can be used more or less like QPrinter. In general, it works rather well; unsupported as of now are clipping and viewport operations and pixmaps. Using the transformation matrix seems to work most of the time, but I still have to iron out some strance cases which appear with QtiPlot. Any help is greatly appreciated! Options: setFileName(QString filename) - set filename setInch(int) - set DPI = number of (logical) pixels per inch setHeight(int) - set max number of (logical) pixels in y direction setWidth(int) - set max number of (logical) pixels in x direction Currently, all images start at (0,0) and extend to (width,height). Supported paint commands (see QPainter and QPaintDevice::cmd for details): - PdcBegin - PdcEnd - PdcSave - PdcRestore - PdcSetROP - PdcSetFont - PdcSetBkMode - PdcSetBkColor - PdcSetBrush (Dense*Pattern style not yet supported) - PdcSetPen (MPenStyle is currently not supported) - PdcSetWXform - PdcSetWMatrix - PdcDrawPie (need to add WMatrix support) - PdcDrawRect - PdcMoveTo - PdcLineTo - PdcDrawLine - PdcDrawPolyline - PdcDrawLineSegments - PdcDrawPoint - PdcDrawEllipse (need to add WMatrix support) - PdcDrawPolygon - PdcDrawText - PdcDrawText2 - PdcDrawTextFormatted - PdcDrawText2Formatted Unsupported: - PdcDrawRoundRect * - PdcDrawArc * - PdcDrawChord *<--- these are pretty easy to implement(other might also be, not checked) - PdcDrawCubicBezier - PdcDrawPixmap - PdcDrawImage - PdcDrawTextItem - PdcSetDev - PdcSetBrushOrigin - PdcSetTabStops - PdcSetTabArray - PdcSetUnit - PdcSetVXform - PdcSetWindow - PdcSetViewport - PdcSaveWMatrix - PdcRestoreWMatrix - PdcSetClip - PdcSetClipRegion Bugs: - Missing functionallity (see above) - SelectObject could call DeleteObject, is this useful? - Comments are missing - support height() etc. to return set values - should optimize - check for off by one problems (e.g. MoveTo(x,y)->LineTo(x+1) draws only a dot) not that easy to fix, maybe moveTo(x,y)->LineTo(x,y)->LineTo(x,y+1)? - check when true and when false needs to be returned in ::cmd seems to be rather arbitrary, but some of the values (esp. false) are tested for in qpainter.cpp - check whether endian problems exist Missing features: - See above - EMF should be supported - ClipBoard format should be supported - Plain WMF w/o placeable header should be supported (trivial, remove one block) Then META_SETMAPMODE matters! -> myInch is then determined by MM_TEXT, MM_LOMETRIC,MM_HIMETRIC, MM_LOENGLISH, MM_HIENGLISH,MM_TWIPS,MM_ISOTROPIC,MM_ANISOTROPIC (not all of them make sense ?!?) Example: 1. Drop the two files into ./chart/ of the Qt examples 2. Add this block to chartform_files.cpp void ChartForm::fileSaveAsWmf() { QString filename = QFileDialog::getSaveFileName( QString::null, "WMF (*.wmf)", this, "file save as wmf", "Chart -- File Save As WMF" ); if(filename.isEmpty()) return; if ( !m_wmf ) m_wmf = new QWMF(); m_wmf->file(filename); QPainter painter( m_wmf ); m_canvas->drawArea( QRect( 0, 0, m_canvas->width(), m_canvas->height() ), &painter, FALSE ); } 3. Declare this function in chartform.h and add "QWMF *m_wmf;" and #include "qwmf.h" 4. You may want to set m_wmf to 0 in ChartForm::ChartForm and to delete it in the destructor 5. Add this to chartform.cpp fileSaveAsWmfAction = new QAction( "Save Chart As WMF", QPixmap( file_save ), "Save As &WMF...", CTRL+Key_W, this, "save as WMF" ); connect( fileSaveAsWmfAction, SIGNAL( activated() ), this, SLOT( fileSaveAsWmf() ) ); 6. Try it out and be happy Credits: See qwmf.h for details, special thank goes to the libwmf authors, to Murray and van Ryper, to Caolán McNamara, and (indirectly) to the WINE authors. Tobias [dot] Burnus [At-sign] Physik [dot] FU-Berlin [dot] De November 2004