libwpg - C++ library to parse WPG

libwpg is a C++ library to read and parse graphics in WPG (WordPerfect Graphics) format. It is cross-platform, at the moment it can be build on Microsoft Windows and Linux.

Refer to the download page on how to obtain and install libwpg.

Using libwpg

The API of libwpg is modelled after the PostScript-like painting interface. Graphics data in WPG format is parsed and the corresponding paint interface functions will be invoked for setting the active pen and brush, drawing shapes and paths, etc.

The main function in libwpg is:

bool libwpg::WPGraphics::parse(const char* buffer, int length, WPGPaintInterface* painter);

Parameter buffer specifies the graphics data location in memory, while length specifies the maximum number of bytes the parse function may read. Parameter painter points to the painting class. The application that uses libwpg must implement such painting class, which must be derived from the abstract interface WPGPaintInterface. The declaration of WPGPaintInterface is as follows:

class WPGPaintInterface {
virtual ~WPGPaintInterface() {}
virtual void startGraphics(double width, double height) = 0;
virtual void setPen(const WPGPen& pen) = 0;
virtual void setBrush(const WPGBrush& brush) = 0;
virtual void setFillRule(FillRule rule ) = 0;
virtual void startLayer(unsigned int id) = 0;
virtual void endLayer(unsigned int id) = 0;
virtual void drawRectangle(const WPGRect& rect, double rx, double ry) = 0;
virtual void drawEllipse(const WPGPoint& center, double rx, double ry) = 0;
virtual void drawPolygon(const WPGPointArray& vertices) = 0;
virtual void drawPath(const WPGPath& path) = 0;
virtual void drawBitmap(const WPGBitmap& bitmap) = 0;
virtual void drawImageObject(const WPGBinaryData& binaryData) = 0;
virtual void endGraphics() = 0;

Functions startDocument() and endDocument() are called at the beginning and at the end, respectively. Functions setPen(), setBrush(), and setFillRule() set the active pen, brush and fill rule. Layers are indicated by startLayer() and endLayer(). The rest of the functions are for drawing different shapes, paths and embedded raster image.

For generating SVG (Scalable Vector Graphics) output, there is a built-in function:

bool libwpg::WPGraphics::generateSVG(const char* buffer, int length, WPGString& output);

Integrating libwpg to the build system

For application which uses automake/autoconf, libwpg can be detected using pkg-config. Example is given below:

libwpg-stream-0.1 >= $LIBWPG_REQUIRED_VERSION

which will set YOURAPP_CFLAGS and YOURAPP_LIBS with the necessary compiler flags and library link respectively. This method is used e.g. in wpg2odg, see its source code for details.

For application which uses CMake, it is possible to detect libwpg using pkg-config. The easiest way is however by using FindLibWpg.cmake macro as shown here:


that defines LIBWPG_INCLUDE_DIR to the installed include directory of libwpg and LIBWPG_LIBRARIES and LIBWPG_STREAM_LIBRARIES to the shared libraries. After that, the application can be linked by adding these variables properly, e.g.:


This method is used e.g. in Perfectspot, see its source code for details and to get FindLibWpg.cmake module.


Check the FAQ, read the documentation, or post to the discussion forum.


This product is not manufactured, approved, or supported by Corel Corporation or Corel Corporation Limited.