Click here to Skip to main content
15,891,762 members
Articles / Multimedia / GDI+

Crossing the bridge between Ghostscript and GDI+

Rate me:
Please Sign up or sign in to vote.
4.91/5 (32 votes)
1 Dec 20027 min read 354.6K   3.2K   73  
A C++ wrapper for the Ghostscript DLL that enables to render PS directly to GDI+ Bitmap
// GSModule.h: interface for the CGSModule class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_GSMODULE_H__D8F656B4_60BC_40F2_8552_44A40FE805E4__INCLUDED_)
#define AFX_GSMODULE_H__D8F656B4_60BC_40F2_8552_44A40FE805E4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <tchar.h>
#include <string>

#ifndef _TSTLSTRING
#define _TSTLSTRING
#ifndef _UNICODE
	namespace std
	{
		typedef ios				_tios;
		typedef string			_tstring;
	}
#else
	namespace std
	{
		typedef wios			_tios;
		typedef wstring			_tstring;
	};
#endif
#endif

namespace gsdll
{

/*!\brief Ghostscript dll loader

This class handles the loading, unloading of gsdll32.dll	
*/
class CModule  
{
public:
	CModule();
	virtual ~CModule();

	HMODULE GetModule();
	bool IsDllLoaded() const;

private:
	void LoadModule();
	HMODULE m_module;
};

typedef struct gsapi_revision_s {
    const char *product;
    const char *copyright;
    long revision;
    long revisiondate;
} gsapi_revision_t;

struct display_callback_s {
    /* Size of this structure */
    /* Used for checking if we have been handed a valid structure */
    int size;

    /* Major version of this structure  */
    /* The major version number will change if this structure changes. */
    int version_major;

    /* Minor version of this structure */
    /* The minor version number will change if new features are added
     * without changes to this structure.  For example, a new color
     * format.
     */
    int version_minor;

    /* New device has been opened */
    /* This is the first event from this device. */
    int (*display_open)(void *handle, void *device);

    /* Device is about to be closed. */
    /* Device will not be closed until this function returns. */
    int (*display_preclose)(void *handle, void *device);

    /* Device has been closed. */
    /* This is the last event from this device. */
    int (*display_close)(void *handle, void *device);

    /* Device is about to be resized. */
    /* Resize will only occur if this function returns 0. */
    /* raster is byte count of a row. */
    int (*display_presize)(void *handle, void *device,
	int width, int height, int raster, unsigned int format);
   
    /* Device has been resized. */
    /* New pointer to raster returned in pimage */
    int (*display_size)(void *handle, void *device, int width, int height, 
	int raster, unsigned int format, unsigned char *pimage);

    /* flushpage */
    int (*display_sync)(void *handle, void *device);

    /* showpage */
    /* If you want to pause on showpage, then don't return immediately */
    int (*display_page)(void *handle, void *device, int copies, int flush);

    /* Notify the caller whenever a portion of the raster is updated. */
    /* This can be used for cooperative multitasking or for
     * progressive update of the display.
     * This function pointer may be set to NULL if not required.
     */
    int (*display_update)(void *handle, void *device, int x, int y, 
	int w, int h);

    /* Allocate memory for bitmap */
    /* This is provided in case you need to create memory in a special
     * way, e.g. shared.  If this is NULL, the Ghostscript memory device 
     * allocates the bitmap. This will only called to allocate the
     * image buffer. The first row will be placed at the address 
     * returned by display_memalloc.
     */
    void *(*display_memalloc)(void *handle, void *device, unsigned long size);

    /* Free memory for bitmap */
    /* If this is NULL, the Ghostscript memory device will free the bitmap */
    int (*display_memfree)(void *handle, void *device, void *mem);
   
};

typedef struct gs_main_instance_s gs_main_instance;
typedef struct display_callback_s display_callback;


#define DISPLAY_VERSION_MAJOR 1
#define DISPLAY_VERSION_MINOR 0

};

#endif // !defined(AFX_GSMODULE_H__D8F656B4_60BC_40F2_8552_44A40FE805E4__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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


Written By
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions