home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / programs / amiga / pastex / pastex14-beta-6 / specialhost / source / post.c < prev    next >
C/C++ Source or Header  |  1994-07-14  |  16KB  |  630 lines

  1. /*
  2. **    SpecialHost for PasTeX
  3. **
  4. **    Copyright © by Olaf Barthel & Georg Heßmann
  5. */
  6.  
  7. #include "Global.h"
  8. #include "postlib.h"
  9.  
  10. /*#define DEBUG*/
  11.  
  12. #define INTOBP(x) ((float)(x*72.0))        /* converts 'inch' to 'big point' */
  13. #define INTOSP(x) ((float)(x*72.0*65781.76))    /* converts 'inch' to 'scaled point' */
  14. VOID __regargs PSGetSize(struct parse_result *Result, float *width, float *height, float *hoff, float *voff);
  15. VOID __regargs PSGetSizeDot(struct parse_result *Result, LONG *width, LONG *height, LONG *hoff, LONG *voff);
  16.  
  17.  
  18.  
  19. struct Library *PostBase;
  20.  
  21. STATIC struct PSparm     PSparm;
  22. STATIC struct BitMap    *BitMap;
  23. STATIC PLANEPTR         Plane;
  24. STATIC LONG         ActivationRecord,
  25.              PlaneSize;
  26. STATIC BOOL         Transferred;
  27.  
  28. #ifdef DEBUG
  29. STATIC struct Screen    *LocalScreen;
  30. STATIC struct Window    *LocalWindow;
  31. #endif    /* DEBUG */
  32.  
  33. extern void insertftrap(void);
  34. extern void deleteftrap(void);
  35.  
  36. STATIC VOID __saveds
  37. CopyPage(VOID)
  38. {
  39.     CopyMem(Plane,BitMap -> Planes[0],PlaneSize);
  40.  
  41.     Transferred = TRUE;
  42.  
  43. #ifdef DEBUG
  44.     if(LocalScreen)
  45.     {
  46.         struct IntuiMessage *IntuiMessage;
  47.  
  48.         CopyMem(Plane,LocalScreen -> RastPort . BitMap -> Planes[0],LocalScreen -> RastPort . BitMap -> BytesPerRow * LocalScreen -> RastPort . BitMap -> Rows);
  49.  
  50.         ScreenToFront(LocalScreen);
  51.  
  52.         WaitPort(LocalWindow -> UserPort);
  53.  
  54.         while(IntuiMessage = (struct IntuiMessage *)GetMsg(LocalWindow -> UserPort))
  55.             ReplyMsg(IntuiMessage);
  56.     }
  57. #endif    /* DEBUG */
  58. }
  59.  
  60. void __saveds sigfpe(void)
  61. {
  62.     PSsignalfpe(ActivationRecord);
  63. }
  64.  
  65. void __saveds sigint(void)
  66. {
  67.     PSsignalint(ActivationRecord,1);
  68. }
  69.  
  70. struct BitMap * __regargs
  71. ProcessPostscript(struct special_msg *Message,struct special_map *SpecialMap,struct parse_result *Result,LONG *Error)
  72. {
  73.     *Error = 0;
  74.     
  75.     BitMap = NULL;
  76.  
  77.     if(PostBase = OpenLibrary("post.library",15))
  78.     {
  79.         BPTR NIL;
  80.  
  81.         if(NIL = Open("NIL:",MODE_READWRITE))
  82.         {
  83.             LONG    NewWidth,
  84.                 NewHeight,
  85.                 X_DPI = Message -> hresolution,
  86.                 Y_DPI = Message -> vresolution;
  87.             STRPTR special_string = NULL, sp;
  88.  
  89.             memset(&PSparm,0,sizeof(struct PSparm));
  90.  
  91.             PSGetSizeDot(Result, &NewWidth, &NewHeight, &(SpecialMap -> hoffset), &(SpecialMap -> voffset));
  92.  
  93.             SpecialMap -> width    = NewWidth;
  94.             SpecialMap -> height    = NewHeight;
  95.             
  96.             PSparm . page . xoff = SpecialMap -> hoffset;
  97.             PSparm . page . yoff = SpecialMap -> voffset;
  98.  
  99.             SpecialMap -> voffset = - SpecialMap -> voffset;
  100.  
  101.             special_string = AllocVecPooled(1024,MEMF_ANY);
  102.             sp = special_string;
  103.  
  104.             sprintf(sp,"TeXDict begin %d %d 1000 %d %d (noname) @start\n", \
  105.                 (LONG) (INTOSP((float) NewWidth/(float)X_DPI) + 0.5),  \
  106.                 (LONG) (INTOSP((float) NewHeight/(float)Y_DPI) + 0.5), \
  107.                 X_DPI, Y_DPI);
  108.             sp += strlen(sp);
  109.             sprintf(sp,"1 0 bop\nResolution neg VResolution neg vsize -72 div 1 add mul a @beginspecial\n");
  110.             sp += strlen(sp);
  111.  
  112.             if(Result -> gotcontrol & GOT_HSIZE)
  113.             {
  114.                 sprintf(sp,"%g @hsize ", INTOBP(Result -> hsize));
  115.                 sp += strlen(sp);
  116.             }
  117.  
  118.             if(Result -> gotcontrol & GOT_VSIZE)
  119.             {
  120.                 sprintf(sp,"%g @vsize ", INTOBP(Result -> vsize));
  121.                 sp += strlen(sp);
  122.             }
  123.  
  124.             if(Result -> gotcontrol & GOT_HSCALE)
  125.             {
  126.                 sprintf(sp,"%g @hscale ", Result -> hscale * 100.0);
  127.                 sp += strlen(sp);
  128.             }
  129.  
  130.             if(Result -> gotcontrol & GOT_VSCALE)
  131.             {
  132.                 sprintf(sp,"%g @vscale ", Result -> vscale * 100.0);
  133.                 sp += strlen(sp);
  134.             }
  135.  
  136.             if(Result -> gotcontrol & GOT_SCALE)
  137.             {
  138.                 sprintf(sp,"%g @hscale %g @vscale ", Result -> scale * 100.0, Result -> scale * 100.0);
  139.                 sp += strlen(sp);
  140.             }
  141.  
  142.             if(Result -> gotcontrol & GOT_HOFFSET)
  143.             {
  144.                 sprintf(sp,"%g @hoffset ", INTOBP(Result -> hoffset));
  145.                 sp += strlen(sp);
  146.             }
  147.  
  148.             if(Result -> gotcontrol & GOT_VOFFSET)
  149.             {
  150.                 sprintf(sp,"%g @voffset ", INTOBP(Result -> voffset));
  151.                 sp += strlen(sp);
  152.             }
  153.  
  154.             if (Result -> gotcontrol & GOT_ANGLE)
  155.             {
  156.                 sprintf(sp,"%g @angle ", Result -> angle);
  157.                 sp += strlen(sp);
  158.             }
  159.  
  160.             if (Result -> gotcontrol & GOT_CLIP)
  161.             {
  162.                 sprintf(sp,"@clip ");
  163.                 sp += strlen(sp);
  164.             }
  165.  
  166.             if(Result -> gotcontrol & SUFFICIENT_PS_ARGS)
  167.             {
  168.                 sprintf(sp,"%g @llx %g @lly %g @urx %g @ury %g @rwi ", \
  169.                     INTOBP(Result -> llx), INTOBP(Result -> lly),  \
  170.                     INTOBP(Result -> urx), INTOBP(Result -> ury),  \
  171.                     INTOBP(Result -> rwi));
  172.                 sp += strlen(sp);
  173.                 if(Result -> gotcontrol & GOT_RHI)
  174.                 {
  175.                     sprintf(sp,"%g @rhi ", INTOBP(Result -> rhi));
  176.                     sp += strlen(sp);
  177.                 }
  178.             }
  179.  
  180.             sprintf(sp,"@setspecial\n");
  181.             sp += strlen(sp);
  182.     
  183.             if(NewWidth > 30000 || NewHeight > 30000)
  184.                 *Error = ERR_TOO_LARGE;
  185.             else
  186.             {
  187.                 if(NewWidth < 1 || NewHeight < 1)
  188.                     *Error = ERR_TOO_SMALL;
  189.                 else
  190.                 {
  191.                     PrintLine("Page size %ld × %ld, %ld × %ld DPI",NewWidth,NewHeight,Message -> hresolution,Message -> vresolution);
  192.  
  193.                     if(BitMap = CreateBitMap(NewWidth,NewHeight,1,NULL,NULL))
  194.                     {
  195.                         if(Plane = (PLANEPTR)AllocVecPooled(PlaneSize = BitMap -> BytesPerRow * BitMap -> Rows,MEMF_ANY))
  196.                         {
  197.                             LONG ResultCode;
  198.  
  199.                             insertftrap();
  200.  
  201.                             PSparm . page . depth    = 1;
  202.                             PSparm . page . ydir    = -1;
  203.                             PSparm . page . xden    = X_DPI;
  204.                             PSparm . page . yden    = Y_DPI;
  205.                             PSparm . page . xsize    = NewWidth;
  206.                             PSparm . page . ysize    = NewHeight;
  207.                             PSparm . page . yheight    = NewHeight;
  208.                             PSparm . page . xbytes    = BitMap -> BytesPerRow;
  209.                             PSparm . page . len    = PSparm . page . xbytes * PSparm . page . ysize;
  210.                             PSparm . page . buf[0]    = Plane;
  211.  
  212.                             PSparm . copyfunc    = (APTR)CopyPage;
  213.                             PSparm . infh        = NIL;
  214.                             PSparm . outfh        = NIL;
  215.                             PSparm . errfh        = NIL;
  216.  
  217.                             ActivationRecord = PScreateact(&PSparm);
  218.  
  219.                             if(ActivationRecord <= errmax)
  220.                             {
  221.                                 if(ActivationRecord)
  222.                                     *Error = 20000 + ActivationRecord;
  223.                                 else
  224.                                     *Error = ERR_NO_MEM;
  225.                             }
  226.                             else
  227.                             {
  228.                                 ULONG Flags = PSFLAGCLEAR | PSFLAGERASE;
  229. #ifdef DEBUG
  230.                                 if(LocalScreen = OpenScreenTags(NULL,
  231.                                     SA_Width,    NewWidth,
  232.                                     SA_Height,    NewHeight,
  233.                                     SA_Depth,    1,
  234.                                     SA_DisplayID,    HIRESLACE_KEY,
  235.                                     SA_Quiet,    TRUE,
  236.                                     SA_AutoScroll,    TRUE,
  237.                                     SA_ShowTitle,    FALSE,
  238.                                     SA_Overscan,    OSCAN_STANDARD,
  239.                                 TAG_DONE))
  240.                                 {
  241.                                     if(!(LocalWindow = OpenWindowTags(NULL,
  242.                                         WA_Left,    0,
  243.                                         WA_Top,        0,
  244.                                         WA_Width,    LocalScreen -> Width,
  245.                                         WA_Height,    LocalScreen -> Height,
  246.                                         WA_RMBTrap,    TRUE,
  247.                                         WA_Backdrop,    TRUE,
  248.                                         WA_Borderless,    TRUE,
  249.                                         WA_CustomScreen,LocalScreen,
  250.                                         WA_Activate,    TRUE,
  251.                                         WA_IDCMP,    IDCMP_VANILLAKEY,
  252.                                     TAG_DONE)))
  253.                                     {
  254.                                         CloseScreen(LocalScreen);
  255.  
  256.                                         LocalScreen = NULL;
  257.                                     }
  258.                                 }
  259. #endif    /* DEBUG */
  260.                                 Transferred = FALSE;
  261.  
  262.                                 if(Result -> psinit_file[0] && !(*Error))
  263.                                 {
  264.                                     PrintLine("Executing initialization file...");
  265.     
  266.                                     if(ResultCode = PSintstring(ActivationRecord,Result -> psinit_file,-1,PSFLAGFILE | Flags))
  267.                                         *Error = 20000 + ResultCode;
  268.                                     else
  269.                                         Flags = NULL;
  270.                                 }
  271.  
  272.                                 if(Result -> psinit_string[0] && !(*Error))
  273.                                 {
  274.                                     PrintLine("Executing initialization string...");
  275.     
  276.                                     if(ResultCode = PSintstring(ActivationRecord,Result -> psinit_string,strlen(Result -> psinit_string),PSFLAGSTRING | Flags))
  277.                                         *Error = 20000 + ResultCode;
  278.                                     else
  279.                                         Flags = NULL;
  280.                                 }
  281. /*
  282.                                 if(!(*Error))
  283.                                 {
  284.                                     PrintLine("Executing file \"%s\"...","TeX:ps/finclude.pro");
  285.     
  286.                                     if(ResultCode = PSintstring(ActivationRecord,"TeX:ps/finclude.pro",-1,PSFLAGFILE | Flags))
  287.                                         *Error = 20000 + ResultCode;
  288.                                     else
  289.                                         Flags = NULL;
  290.                                 }
  291.  
  292.                                 if(!(*Error))
  293.                                 {
  294.                                     PrintLine("Executing file \"%s\"...","TeX:ps/texps.pro");
  295.     
  296.                                     if(ResultCode = PSintstring(ActivationRecord,"TeX:ps/texps.pro",-1,PSFLAGFILE | Flags))
  297.                                         *Error = 20000 + ResultCode;
  298.                                     else
  299.                                         Flags = NULL;
  300.                                 }
  301.  
  302.                                 if(!(*Error))
  303.                                 {
  304.                                     PrintLine("Executing file \"%s\"...","TeX:ps/special..pro");
  305.     
  306.                                     if(ResultCode = PSintstring(ActivationRecord,"TeX:ps/special.pro",-1,PSFLAGFILE | Flags))
  307.                                         *Error = 20000 + ResultCode;
  308.                                     else
  309.                                         Flags = NULL;
  310.                                 }
  311.  
  312.                                 if(