WINMETA LIBRARY
===============

This library paints windows metafiles. It should cope with most metafiles,
including WMF and EMF types. If you get a metafile that doesn't work, and it's
not too big, please send it to <peter@manglais.com>, where it can be checked.

This library will tend to go where the metafile commands lead it - usually off
the screen. So it's best if you create an OS/2 metafile or a bitmap from the
Windows Metafile, and then paint that where you actually want it to be!

This library is extracted from the Maul Publisher metafile handler, where it
works fine, this extracted code has not been independantly tested. Please let
me know if it works, or if it doesn't!

LICENSE
=======

 2007 Peter Koller, Maison Anglais. All Rights Reserved

* You can use this library in any OS/2 application or dll, commercial or otherwise.
* You must give credit somewhere to indicate that you are using this library.
* Don't try and reverse engineer this library, you can't fix it, and you can't learn
  anything by doing so. It also breaches the copyright.
* You can compress, pack, or zip up this library in order to install the necessary
  parts with your application.

EXAMPLE TO CREATE AN OS/2 METAFILE
==================================
ULONG APIENTRY WinGdiWarnProc(HWND hWnd, ULONG errcode)
	{
		char 	text[256];

		FormatMetafileErrorMsg(text, errcode);
		//display an error message
		return 0;
	}

HMF ImportWindowsMetafile(HAB hab, HWND hWnd, PCHAR metadata, ULONG metasize)
	{
        DEVOPENSTRUC    	dop = {0};
		SIZEL				sizel = {0};
        HMF             	hmf;
		HPS                 hps;
		HDC                 hdc;
		ULONG				errcode;

        dop.pszDriverName = "DISPLAY";
        hdc = DevOpenDC(pmh->hab, OD_METAFILE, "*", 5, (PDEVOPENDATA)&dop, 0L);
        if(!hdc || (hdc == DEV_ERROR)) return 0;
		hps = GpiCreatePS(pmh->hab, hdc, &sizel, PU_PELS | GPIF_DEFAULT | GPIT_NORMAL | GPIA_ASSOC);
		if(hps == GPI_ERROR)
			{
				DevCloseDC(hdc);
				return 0;
			}
		errcode = InitWinMetafile(hab, hps, NULL, 0, WINGDI_DEFAULTOPTS); //we are not looking for warnings
		if(!errcode)
			{
				errcode = PaintWinMetafile(hps, metadata, metasize);
			}
		else WinGdiWarnProc(hWnd, errcode); //but we want to catch errors

		GpiAssociate(hps, NULLHANDLE);
		GpiDestroyPS(hps);
        hmf = DevCloseDC(hdc);
		return hmf;
	}

The WINMETA functions in detail
===============================

BOOL	APIENTRY	IsWinMetafile(PCHAR metadata, ULONG metasize);
------------------------------------------------------------------
This function checks to see that the file type is recognised as a Windows
metafile. Returns TRUE if the file type is recognised.


ULONG	APIENTRY	InitWinMetafile(HAB hab, HPS hps, PFNWARNPROC warnproc, PVOID warnprocData, ULONG useOpts);
---------------------------------------------------------------------------------------------------------------
This function sets up some internal pointers and options, then initialises the
painter. Obligatory!

HAB hab - required.
HPS hps - required.
PFNWARNPROC warnproc - This is a template for a warn procedure, set warnproc
					to NULL if you don't want warnings.
PVOID warnprocData - Your warnproc will get whatever you put in here. Could be
					a HWND, for example.

ULONG useOpts - Use WINGDI_DEFAULTOPTS unless you want something special.

WINGDI_SCALEVIEWPORTSZ	//enables the painter to react to viewport scaling commands.
WINGDI_SCALEWINDOWSIZE	//enables the painter to react to window scaling commands.
WINGDI_ALLOWGDISAVEPS	//enables the painter save and restore the PS.
WINGDI_USECOLORTABLES	//enables the painter to create and select colour tables.
WINGDI_ALLOWSCALEXFORM	//enables the painter to create and select GPI transforms.

Returns a Win error code, or 0 for no error.


ULONG	APIENTRY	PaintWinMetafile(HPS hps, PCHAR metadata, ULONG metasize);
------------------------------------------------------------------------------
This function paints the windows metafile.
Returns a Win error code in the lower 16 bits, and a graphics opcode in the
upper 15 bits. The 31st bit indicates if this is a WMF or EMF opcode.


char*	APIENTRY	FormatMetafileErrorMsg(char* buffer, ULONG errcode);
------------------------------------------------------------------------
This function formats a text error message from an error code. The text error
message is written into the buffer, which should be at least 256 bytes long.
The error message is language independant, and looks something like this:-

"EMR_CREATEPEN, rc=110f"

Returns a pointer to the buffer.

