home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fonts 1
/
freshfonts1.bin
/
programs
/
amiga
/
pastex
/
pastex14-beta-6
/
specialhost
/
source
/
post.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-14
|
16KB
|
630 lines
/*
** SpecialHost for PasTeX
**
** Copyright © by Olaf Barthel & Georg Heßmann
*/
#include "Global.h"
#include "postlib.h"
/*#define DEBUG*/
#define INTOBP(x) ((float)(x*72.0)) /* converts 'inch' to 'big point' */
#define INTOSP(x) ((float)(x*72.0*65781.76)) /* converts 'inch' to 'scaled point' */
VOID __regargs PSGetSize(struct parse_result *Result, float *width, float *height, float *hoff, float *voff);
VOID __regargs PSGetSizeDot(struct parse_result *Result, LONG *width, LONG *height, LONG *hoff, LONG *voff);
struct Library *PostBase;
STATIC struct PSparm PSparm;
STATIC struct BitMap *BitMap;
STATIC PLANEPTR Plane;
STATIC LONG ActivationRecord,
PlaneSize;
STATIC BOOL Transferred;
#ifdef DEBUG
STATIC struct Screen *LocalScreen;
STATIC struct Window *LocalWindow;
#endif /* DEBUG */
extern void insertftrap(void);
extern void deleteftrap(void);
STATIC VOID __saveds
CopyPage(VOID)
{
CopyMem(Plane,BitMap -> Planes[0],PlaneSize);
Transferred = TRUE;
#ifdef DEBUG
if(LocalScreen)
{
struct IntuiMessage *IntuiMessage;
CopyMem(Plane,LocalScreen -> RastPort . BitMap -> Planes[0],LocalScreen -> RastPort . BitMap -> BytesPerRow * LocalScreen -> RastPort . BitMap -> Rows);
ScreenToFront(LocalScreen);
WaitPort(LocalWindow -> UserPort);
while(IntuiMessage = (struct IntuiMessage *)GetMsg(LocalWindow -> UserPort))
ReplyMsg(IntuiMessage);
}
#endif /* DEBUG */
}
void __saveds sigfpe(void)
{
PSsignalfpe(ActivationRecord);
}
void __saveds sigint(void)
{
PSsignalint(ActivationRecord,1);
}
struct BitMap * __regargs
ProcessPostscript(struct special_msg *Message,struct special_map *SpecialMap,struct parse_result *Result,LONG *Error)
{
*Error = 0;
BitMap = NULL;
if(PostBase = OpenLibrary("post.library",15))
{
BPTR NIL;
if(NIL = Open("NIL:",MODE_READWRITE))
{
LONG NewWidth,
NewHeight,
X_DPI = Message -> hresolution,
Y_DPI = Message -> vresolution;
STRPTR special_string = NULL, sp;
memset(&PSparm,0,sizeof(struct PSparm));
PSGetSizeDot(Result, &NewWidth, &NewHeight, &(SpecialMap -> hoffset), &(SpecialMap -> voffset));
SpecialMap -> width = NewWidth;
SpecialMap -> height = NewHeight;
PSparm . page . xoff = SpecialMap -> hoffset;
PSparm . page . yoff = SpecialMap -> voffset;
SpecialMap -> voffset = - SpecialMap -> voffset;
special_string = AllocVecPooled(1024,MEMF_ANY);
sp = special_string;
sprintf(sp,"TeXDict begin %d %d 1000 %d %d (noname) @start\n", \
(LONG) (INTOSP((float) NewWidth/(float)X_DPI) + 0.5), \
(LONG) (INTOSP((float) NewHeight/(float)Y_DPI) + 0.5), \
X_DPI, Y_DPI);
sp += strlen(sp);
sprintf(sp,"1 0 bop\nResolution neg VResolution neg vsize -72 div 1 add mul a @beginspecial\n");
sp += strlen(sp);
if(Result -> gotcontrol & GOT_HSIZE)
{
sprintf(sp,"%g @hsize ", INTOBP(Result -> hsize));
sp += strlen(sp);
}
if(Result -> gotcontrol & GOT_VSIZE)
{
sprintf(sp,"%g @vsize ", INTOBP(Result -> vsize));
sp += strlen(sp);
}
if(Result -> gotcontrol & GOT_HSCALE)
{
sprintf(sp,"%g @hscale ", Result -> hscale * 100.0);
sp += strlen(sp);
}
if(Result -> gotcontrol & GOT_VSCALE)
{
sprintf(sp,"%g @vscale ", Result -> vscale * 100.0);
sp += strlen(sp);
}
if(Result -> gotcontrol & GOT_SCALE)
{
sprintf(sp,"%g @hscale %g @vscale ", Result -> scale * 100.0, Result -> scale * 100.0);
sp += strlen(sp);
}
if(Result -> gotcontrol & GOT_HOFFSET)
{
sprintf(sp,"%g @hoffset ", INTOBP(Result -> hoffset));
sp += strlen(sp);
}
if(Result -> gotcontrol & GOT_VOFFSET)
{
sprintf(sp,"%g @voffset ", INTOBP(Result -> voffset));
sp += strlen(sp);
}
if (Result -> gotcontrol & GOT_ANGLE)
{
sprintf(sp,"%g @angle ", Result -> angle);
sp += strlen(sp);
}
if (Result -> gotcontrol & GOT_CLIP)
{
sprintf(sp,"@clip ");
sp += strlen(sp);
}
if(Result -> gotcontrol & SUFFICIENT_PS_ARGS)
{
sprintf(sp,"%g @llx %g @lly %g @urx %g @ury %g @rwi ", \
INTOBP(Result -> llx), INTOBP(Result -> lly), \
INTOBP(Result -> urx), INTOBP(Result -> ury), \
INTOBP(Result -> rwi));
sp += strlen(sp);
if(Result -> gotcontrol & GOT_RHI)
{
sprintf(sp,"%g @rhi ", INTOBP(Result -> rhi));
sp += strlen(sp);
}
}
sprintf(sp,"@setspecial\n");
sp += strlen(sp);
if(NewWidth > 30000 || NewHeight > 30000)
*Error = ERR_TOO_LARGE;
else
{
if(NewWidth < 1 || NewHeight < 1)
*Error = ERR_TOO_SMALL;
else
{
PrintLine("Page size %ld × %ld, %ld × %ld DPI",NewWidth,NewHeight,Message -> hresolution,Message -> vresolution);
if(BitMap = CreateBitMap(NewWidth,NewHeight,1,NULL,NULL))
{
if(Plane = (PLANEPTR)AllocVecPooled(PlaneSize = BitMap -> BytesPerRow * BitMap -> Rows,MEMF_ANY))
{
LONG ResultCode;
insertftrap();
PSparm . page . depth = 1;
PSparm . page . ydir = -1;
PSparm . page . xden = X_DPI;
PSparm . page . yden = Y_DPI;
PSparm . page . xsize = NewWidth;
PSparm . page . ysize = NewHeight;
PSparm . page . yheight = NewHeight;
PSparm . page . xbytes = BitMap -> BytesPerRow;
PSparm . page . len = PSparm . page . xbytes * PSparm . page . ysize;
PSparm . page . buf[0] = Plane;
PSparm . copyfunc = (APTR)CopyPage;
PSparm . infh = NIL;
PSparm . outfh = NIL;
PSparm . errfh = NIL;
ActivationRecord = PScreateact(&PSparm);
if(ActivationRecord <= errmax)
{
if(ActivationRecord)
*Error = 20000 + ActivationRecord;
else
*Error = ERR_NO_MEM;
}
else
{
ULONG Flags = PSFLAGCLEAR | PSFLAGERASE;
#ifdef DEBUG
if(LocalScreen = OpenScreenTags(NULL,
SA_Width, NewWidth,
SA_Height, NewHeight,
SA_Depth, 1,
SA_DisplayID, HIRESLACE_KEY,
SA_Quiet, TRUE,
SA_AutoScroll, TRUE,
SA_ShowTitle, FALSE,
SA_Overscan, OSCAN_STANDARD,
TAG_DONE))
{
if(!(LocalWindow = OpenWindowTags(NULL,
WA_Left, 0,
WA_Top, 0,
WA_Width, LocalScreen -> Width,
WA_Height, LocalScreen -> Height,
WA_RMBTrap, TRUE,
WA_Backdrop, TRUE,
WA_Borderless, TRUE,
WA_CustomScreen,LocalScreen,
WA_Activate, TRUE,
WA_IDCMP, IDCMP_VANILLAKEY,
TAG_DONE)))
{
CloseScreen(LocalScreen);
LocalScreen = NULL;
}
}
#endif /* DEBUG */
Transferred = FALSE;
if(Result -> psinit_file[0] && !(*Error))
{
PrintLine("Executing initialization file...");
if(ResultCode = PSintstring(ActivationRecord,Result -> psinit_file,-1,PSFLAGFILE | Flags))
*Error = 20000 + ResultCode;
else
Flags = NULL;
}
if(Result -> psinit_string[0] && !(*Error))
{
PrintLine("Executing initialization string...");
if(ResultCode = PSintstring(ActivationRecord,Result -> psinit_string,strlen(Result -> psinit_string),PSFLAGSTRING | Flags))
*Error = 20000 + ResultCode;
else
Flags = NULL;
}
/*
if(!(*Error))
{
PrintLine("Executing file \"%s\"...","TeX:ps/finclude.pro");
if(ResultCode = PSintstring(ActivationRecord,"TeX:ps/finclude.pro",-1,PSFLAGFILE | Flags))
*Error = 20000 + ResultCode;
else
Flags = NULL;
}
if(!(*Error))
{
PrintLine("Executing file \"%s\"...","TeX:ps/texps.pro");
if(ResultCode = PSintstring(ActivationRecord,"TeX:ps/texps.pro",-1,PSFLAGFILE | Flags))
*Error = 20000 + ResultCode;
else
Flags = NULL;
}
if(!(*Error))
{
PrintLine("Executing file \"%s\"...","TeX:ps/special..pro");
if(ResultCode = PSintstring(ActivationRecord,"TeX:ps/special.pro",-1,PSFLAGFILE | Flags))
*Error = 20000 + ResultCode;
else
Flags = NULL;
}
if(