/*
SVF	- svfxampl.c
	(C) Copyright 1994 by SoftSource.  All rights reserved.
Scott Sherman 10-94...

	outputting sample SVF files
	shows how to use the different commands in SVF using svfout.c
*/

#include <stdio.h>
#include "svfcom.h"
#include "svfout.h"

/* output an SVF with a single line
	assume defaults...
		background color black
		current pen color white
		current pen position (0,0)
		pen width 0
		extents (0,0)-(255,255)
*/
int OutputSimplestSVF(char *name)
{
	FILE *fp = SVFOpen(name);	/* open a file & output header string */
	if (fp == NULL)
		return FALSE;
	SVFOutputLineTo(fp,255,255);
	SVFClose(fp);
	return TRUE;
}

/* shows how to output just about every SVF command
	note that the commands automatically handle outputting short or long form except polys */
int OutputSampleSVF(char *name)
{
	FILE *fp = SVFOpen(name);	/* open a file & output header string */
	if (fp == NULL)
		return FALSE;

		/* outputting header commands */
	SVFOutputExtents(fp,0,0,5000,5000);
	SVFOutputName(fp,"sample");	/* name gets ignored by most display code */
	SVFOutputWidth(fp,100);	/* suggest that the width of the displayed image should be 100 mm */
		/* original image had an origin @ (1,1) & was scaled relative to SVF by a factor of 2 */
	SVFOutputTransform(fp,2.0,1.0,1.0);
	SVFOutputSortByLayer(fp,0);	/* default so not completely necessary - optimization */

	SVFOutputLayerTable(fp,2);	/* layer table + number of entries */
	SVFOutputLayerEntry(fp,TRUE,"layer name");	/* these layers are ON */
	SVFOutputLayerEntry(fp,TRUE,"another layer");

	SVFOutputColorTable(fp,4);	/* color table + number of entries */
	SVFOutputColorEntry(fp,100,100,100);	/* dummy color - this will be transparent (see below) */
	SVFOutputColorEntry(fp,255,0,0);	/* red */
	SVFOutputColorEntry(fp,0,255,0);	/* green */
	SVFOutputColorEntry(fp,0,0,255);	/* blue */
	SVFOutputTransparent(fp,0);	/* make color 0 use the display's background color */
	SVFOutputBackground(fp,0);	/* the image's background will be color 0 (transparent) */

	SVFOutputNotifyTable(fp,2,2);	/* notifications */
	SVFOutputNotifyEntry(fp,"width less than or equal to 3000",3000);
	SVFOutputNotifyEntry(fp,"width less than or equal to 1000",1000);
	SVFOutputNotifyEntry(fp,"width greater than or equal to 2000",2000);
	SVFOutputNotifyEntry(fp,"width greater than or equal to 1000",1000);

		/* outputting drawing commands in the main body */
	SVFOutputSetColor(fp,1);	/* red */
	SVFOutputSetLayer(fp,0);	/* layer 0 */
	SVFOutputPoint(fp,4000,1000);
	SVFOutputPoint(fp,4000,500);
	SVFOutputMoveTo(fp,4400,750);
	SVFOutputRelLineTo(fp,0,300);
	SVFOutputMoveTo(fp,4400,750);
	SVFOutputArc(fp,500,(ushort)55000,10000);
	SVFOutputMoveTo(fp,4400,2000);
	SVFOutputCircle(fp,255);
	SVFOutputData(fp,4,"data");	/* data gets ignored by most display code */

	SVFOutputSetColor(fp,2);	/* green */
	SVFOutputMoveTo(fp,4000,3800);	/* 2-byte polyline... */
	SVFOutputPolylineStart(fp,3,2);
	SVFOutputPolyPoint(fp,4500,4300,2);
	SVFOutputPolyPoint(fp,4000,4800,2);
	SVFOutputPolyPoint(fp,3500,4300,2);
	SVFOutputSetColor(fp,3);	/* blue */
	SVFOutputRelPolylineStart(fp,4,1);	/* 1-byte relative polyline... */
	SVFOutputRelPolyPoint(fp,120,-120,1);
	SVFOutputRelPolyPoint(fp,-120,-120,1);
	SVFOutputRelPolyPoint(fp,-120,120,1);
	SVFOutputRelPolyPoint(fp,120,120,1);

	SVFOutputSetLayer(fp,1);
	SVFOutputFillMode(fp,SVF_ON);	/* display the link region filled */
	SVFOutput2dLink(fp,"http://www.softsource.com/softsource/",NULL);	/* line #2 */
	SVFOutputMoveTo(fp,1000,4000);	/* polygon link region... */
	SVFOutputPolylineStart(fp,2,2);
	SVFOutputPolyPoint(fp,2000,4000,2);
	SVFOutputPolyPoint(fp,1500,3000,2);
	SVFOutputFillMode(fp,SVF_OFF);
	SVFOutput1dLink(fp,"#anchor",NULL);	/* link #2 */
	SVFOutputMoveTo(fp,100,100);	/* bezier link... */
	SVFOutputBezierCurve(fp,400,1000,1000,900,1300,300);
	SVFOutputInvisible(fp);
	SVFOutputBezierCurve(fp,1400,1000,1500,900,1600,300);	/* invisible link #3 */
	SVFOutputEndLink(fp);

	SVFOutputSetColor(fp,2);	/* green */
	SVFOutputSetPenWidth(fp,100);	/* wide pen */
	SVFOutputMoveTo(fp,2000,1000);
	SVFOutputRectangle(fp,1000,1000);

	SVFOutputSetPenWidth(fp,0);	/* pen 1 pixel thick */
	SVFOutputMoveTo(fp,2000,3500);	/* text... */
	SVFOutputTextHeight(fp,400);
	SVFOutputText(fp,0,"link area");	/* 0 means to use fonts default width */

		/* we're done */
	SVFClose(fp);
	return TRUE;
}

void main()
{
	if (OutputSimplestSVF("simple.svf"))
		printf("output simple.svf\n");
	else
		printf("failed to output simple.svf\n");
	if (OutputSampleSVF("sample.svf"))
		printf("output sample.svf\n");
	else
		printf("failed to output sample.svf\n");
}
