/*	PF -- printer filter

Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 Ogochan .

This module is part of PF.

	PF is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves
any particular purpose or works at all, unless he says so in writing.
Refer to the GNU General Public License for full details. 

	Everyone is granted permission to copy, modify and redistribute
MACE, but only under the conditions described in the GNU General
Public License.  A copy of this license is supposed to have been given
to you along with PF so you can know your rights and
responsibilities.  It should be in a file named COPYING.  Among other
things, the copyright notice and this notice must be preserved on all
copies. 
*/
#include	<stdio.h>
#include	"types.h"
#include	"pf.h"

#include	"FMPR.h"

static	Bool	fNewPaper;

static	void
FMPR_NewPage(
	Bool	fLast)
{
	if		(  !fNewPaper  )	{
		PrintString("\x00C");
	}
	fNewPaper = FALSE;
}

static	void
FMPR_NewLine(void)
{
	PrintString("\r\n");
}

static	void
FMPR_Init(void)
{
	PrintString("\x01C\x05D");
	fNewPaper = TRUE;
}

static	void
FMPR_SetPaper(
	PrinterControl	*p)
{	char	sbuf[10];

	sprintf(sbuf,"\x01B\x05B%d\x03B%d\x020\x047",p->LinePitch,p->PitchSBCS);
	PrintString(sbuf);
	PrintString("\x01C\x024");
	PrintChar((char)(0x20 + p->PitchDBCS / 10));
	PrintChar((char)(0x70 + p->PitchDBCS % 10));
	sprintf(sbuf,"\x01B\x051%d A",(p->PageLength/p->LinePitch));
	PrintString(sbuf);
}

static	void
FMPR_Select_R(
	word	set)
{
	if		(  set  ==  SET_ASCII  ) {
		PrintString("\x01B\x028\x048\x01C\x028\x060\x071");
	} else
	if		(  set  ==  SET_JIS83  ) {
		PrintString("\x01B\x024\x042");
	} else {
		PrintString("");
	}
}

static	void
FMPR_Select_H(
	word	set)
{
	if		(  set  ==  SET_ASCII  ) {
		PrintString("\x01B\x028\x048\x01B\x051\x031\x020\x07C");
	} else
	if		(  set  ==  SET_JIS83  ) {
		PrintString("\x01B\x024\x042");
	} else {
		PrintString("");
	}
}

static	void
FMPR_Select_D(
	word	set)
{
	if		(  set  ==  SET_ASCII  ) {
		PrintString("\x01B\x028\x048\x01C\x028\x060\x070");
	} else
	if		(  set  ==  SET_JIS83  ) {
		PrintString("\x01B\x024\x042");
	} else {
		PrintString("");
	}
}

static	void
FMPR_Select_R78(
	word	set)
{
	if		(  set  ==  SET_ASCII  ) {
		PrintString("\x01B\x028\x048\x01C\x028\x060\x071");
	} else
	if		(  set  ==  SET_JIS83  ) {
		PrintString("\x01B\x024\x040");
	} else {
		PrintString("");
	}
}

static	void
FMPR_Select_H78(
	word	set)
{
	if		(  set  ==  SET_ASCII  ) {
		PrintString("\x01B\x028\x048\x01B\x051\x031\x020\x07C");
	} else
	if		(  set  ==  SET_JIS83  ) {
		PrintString("\x01B\x024\x040");
	} else {
		PrintString("");
	}
}

static	void
FMPR_Select_D78(
	word	set)
{
	if		(  set  ==  SET_ASCII  ) {
		PrintString("\x01B\x028\x048\x01C\x028\x060\x070");
	} else
	if		(  set  ==  SET_JIS83  ) {
		PrintString("\x01B\x024\x040");
	} else {
		PrintString("");
	}
}

PrinterControl	FMPR_R = {
	"FMPR-R",
	FMPR_Select_R,
	FMPR_NewPage,
	FMPR_Init,
	FMPR_NewLine,
	PrintSBCS_Direct,
	PrintDBCS_Direct,
	FMPR_SetPaper,
};

PrinterControl	FMPR_H = {
	"FMPR-H",
	FMPR_Select_H,
	FMPR_NewPage,
	FMPR_Init,
	FMPR_NewLine,
	PrintSBCS_Direct,
	PrintDBCS_Direct,
	FMPR_SetPaper
};

PrinterControl	FMPR_D = {
	"FMPR-D",
	FMPR_Select_D,
	FMPR_NewPage,
	FMPR_Init,
	FMPR_NewLine,
	PrintSBCS_Direct,
	PrintDBCS_Direct,
	FMPR_SetPaper,
};

PrinterControl	FMPR_R78 = {
	"FMPR-R78",
	FMPR_Select_R78,
	FMPR_NewPage,
	FMPR_Init,
	FMPR_NewLine,
	PrintSBCS_Direct,
	PrintDBCS_Direct,
	FMPR_SetPaper,
};

PrinterControl	FMPR_H78 = {
	"FMPR-H78",
	FMPR_Select_H78,
	FMPR_NewPage,
	FMPR_Init,
	FMPR_NewLine,
	PrintSBCS_Direct,
	PrintDBCS_Direct,
	FMPR_SetPaper,
};

PrinterControl	FMPR_D78 = {
	"FMPR-D78",
	FMPR_Select_D78,
	FMPR_NewPage,
	FMPR_Init,
	FMPR_NewLine,
	PrintSBCS_Direct,
	PrintDBCS_Direct,
	FMPR_SetPaper,
};

static	void
Help(void)
{
	fprintf(stderr,"\tR\tpretty ANK font\n");
	fprintf(stderr,"\tH\tNIHONGO like ANK font\n");
	fprintf(stderr,"\tD\tdraft ANK font\n");
	fprintf(stderr,"\tR78\tpretty ANK font, NIHONGO set is JIS78\n");
	fprintf(stderr,"\tH78\tNIHONGO like ANK font, NIHONGO set is JIS78\n");
	fprintf(stderr,"\tD78\tdraft ANK font, NIHONGO set is JIS78\n");
}

static	PrinterControl	*
Select(char *parameter,
	int		LinePitch,
	int		PitchSBCS,
	int		PitchDBCS,
	int		PageLength,
	int		PageWidth,
	int		PageLines,
	int		LineLength,
	int		TopMargineInLines,
	int		LeftMargine,
	int		TabWidth,
	Bool	fPrintPageHeader)
{
	PrinterControl	*ret;

	if		(  !strcmp(parameter,"R")  ) {
		ret = &FMPR_R;
	} else
	if		(  !strcmp(parameter,"H")  ) {
		ret = &FMPR_H;
	} else
	if		(  !strcmp(parameter,"D")  ) {
		ret = &FMPR_D;
	} else
	if		(  !strcmp(parameter,"R78")  ) {
		ret = &FMPR_R78;
	} else
	if		(  !strcmp(parameter,"H78")  ) {
		ret = &FMPR_H78;
	} else
	if		(  !strcmp(parameter,"D78")  ) {
		ret = &FMPR_D78;
	} else {
		ret = NULL;
	}
	if		(  ret  !=  NULL  ) {
		ret->LinePitch = LinePitch;
		ret->PitchSBCS = PitchSBCS;
		ret->PitchDBCS = PitchDBCS;
		ret->PageLength = PageLength;
		ret->PageWidth = PageWidth;
		ret->PageLines = PageLines;
		ret->LineLength = LineLength;
		ret->LineColumns = LineLength / PitchSBCS;
		ret->TopMargineInLines = TopMargineInLines;
		ret->LeftMargine = LeftMargine;
		ret->TabWidth = TabWidth;
		ret->fPrintPageHeader = fPrintPageHeader;
	}
	return	(ret);
}

PrinterClass	FMPR = {
	"FMPR",
	Help,
	Select
};

