/*----------------------------------------------------------------------------
                     tpv2clip.c (send Metafile to clipboard)
                       This file is a part of Topaz systems
                  Copyright: Hisao Kawaura, All rights reserved
                                   1997 - 98


    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

----------------------------------------------------------------------------*/

#include <windows.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include "Parray.h"

#include <getopt.h>

//char *optarg;

HWND hWnd;
static volatile HANDLE thread;
extern Parray *xpa;
extern bool drawline(HDC dc, FILE *in, char *str, METAFILEPICT *mpict, int jobtype,
				 double printmagx, double printmagy, double printshiftx, double printshifty);
extern double margin;

bool toclip()
{
	char stemp[1000];
	HMETAFILE hmf;
	HDC hdc;
	METAFILEPICT mfp;
	HGLOBAL hgl;
	METAFILEPICT *p;

	xpa = new Parray;
	if ((hdc = CreateMetaFile(NULL)) == NULL)
		return false;
	while(fgets(stemp, sizeof(stemp), stdin) != NULL)
		drawline(hdc, stdin, stemp, &mfp, 1, 1.0, 1.0, 0.0, 0.0);
	hmf = CloseMetaFile(hdc);
	delete xpa;

	hgl = GlobalAlloc(GHND,sizeof(METAFILEPICT));
	p = (METAFILEPICT *)GlobalLock(hgl);
	p->mm=MM_ANISOTROPIC;
	p->hMF=hmf;
	p->xExt = (int)(1.76 * (double)mfp.xExt);
	p->yExt = (int)(1.76 * (double)mfp.yExt);
	GlobalUnlock(hgl);

	if (!OpenClipboard(NULL))
	{
		fprintf(stderr, "failed\n");
		return (1);
	}
	EmptyClipboard();
	SetClipboardData(CF_METAFILEPICT,hgl);
	CloseClipboard();
	return true;
}

int main(int argc, char *argv[])
{
	int c;

  // options
	while ((c = getopt(argc, argv, "vhm:")) != -1)
    {
    	switch(c)
		{
			case 'm':
			margin = atof(optarg) * 20.0;
			break;
			case 'h':
			case 'v':
			fprintf(stderr, "tpv2clip Ver. 1.00\n");;
			fprintf(stderr, "Written by Hisao Kawaura\n\n");
			fprintf(stderr, "-mx: boundingbox margin (x points)\n");
			exit(0);
		}
    }

	toclip();
	exit (0);
}


syntax highlighted by Code2HTML, v. 0.9.1