/* type1interface.c

    Author - Amish S. Dave

This file contains interface functions that get called by the
shared library entry points, and calls functions in the type1
sources.

*/

#ifndef T1GST
#include "global.h"
#endif
#include <diskfont/oterrors.h>	// TetiSoft

static void FontRequest2FontScalableRec(struct T1GlyphEngine *engine);	// TetiSoft

/**
 * DEFINES
 **/
#define DECIPOINTSPERINCH 722.7
#define DEFAULTRES 75
#define DEFAULTPOINTSIZE 120


/**
 *	Create memory pool
 **/
void *OpenType1Engine(struct T1GlyphEngine *engine)
{
	return addmemory2(engine, 100000);
}

/**
 * Free memory, cleanup, etc.
 **/
void CloseType1Engine(struct T1GlyphEngine *engine)
{
	free_vm(engine);
//	engine->FontP = NULL;
	MyType1CloseFont(engine);
	delmemory2(engine);
}


static void FontRequest2FontScalableRec(struct T1GlyphEngine *engine)	// TetiSoft
{
	struct FontRequest *fontreq = &engine->fontreq;
	FontScalableRec *vals = &engine->vals;

	vals->x = fontreq->DeviceXDPI;
	vals->y = fontreq->DeviceYDPI;
	vals->point = fontreq->PointHeight * 10;
	vals->pixel = (vals->point * vals->y) / DECIPOINTSPERINCH;
#ifdef SETFACTOR						// TetiSoft: Not implemented
	vals->pixel_set = (fontreq->PointSet != 0) ? ((fontreq->PointSet * 10 * vals->x) / DECIPOINTSPERINCH) : vals->pixel;
#endif
	vals->pixel_matrix[0] = vals->pixel_matrix[3] = vals->pixel;
	vals->ShearSin = fontreq->ShearSin;
	vals->ShearCos = fontreq->ShearCos;
	vals->RotateSin = fontreq->RotateSin;
	vals->RotateCos = fontreq->RotateCos;
	vals->IsFixed = fontreq->IsFixed;			// TetiSoft
	vals->FixedWidth = fontreq->FixedWidth;			// TetiSoft
	vals->FixedWidthPixels = fontreq->FixedWidthPixels;	// TetiSoft
	vals->GlyphWidth = fontreq->GlyphWidth;			// TetiSoft
	vals->GlyphWidthPixels = fontreq->GlyphWidthPixels;	// TetiSoft
	vals->SymbolSet = fontreq->SymbolSet;			// TetiSoft
}

/* return OTERR_Success (0) on success */
int ReadType1Font(struct T1GlyphEngine *engine)
{
	FontRequest2FontScalableRec(engine);	// TetiSoft
	return MyType1OpenScalable(engine);
}


int SetTransformType1Font(struct T1GlyphEngine *engine)
{
	FontRequest2FontScalableRec(engine);	// TetiSoft
	return MyType1SetTransform(engine);
}


int MyQueryFontLib(struct T1GlyphEngine *engine, char *env, pointer dest)
{
	int rc;

	QueryFontLib(engine, engine->fontreq.FontFileName, env, dest, &rc);
	return rc;
}

void FatalError(char *line)
{
#ifdef DEBUG
	kprintf("%s\n", line);	// TetiSoft
#endif
}
