home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_1.3 / Read-Me1.3 / Printer1.3 / Driver.Examples / src / hp / dospecial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-01  |  4.3 KB  |  233 lines

  1. /*
  2.     DoSpecial for HP_LaserJet driver.
  3.     David Berezowski - March/88.
  4. */
  5.  
  6. #include "exec/types.h"
  7. #include "../printer/printer.h"
  8. #include "../printer/prtbase.h"
  9.  
  10. #define LPI        7
  11. #define CPI        15
  12. #define QUALITY        17
  13. #define INIT_LEN    30
  14. #define LPP        7
  15. #define FORM_LEN    11
  16. #define LEFT_MARG    3
  17. #define RIGHT_MARG    7
  18. #define MARG_LEN    12
  19.  
  20. DoSpecial(command, outputBuffer, vline, currentVMI, crlfFlag, Parms)
  21. char outputBuffer[];
  22. UWORD *command;
  23. BYTE *vline;
  24. BYTE *currentVMI;
  25. BYTE *crlfFlag;
  26. UBYTE Parms[];
  27. {
  28.     extern struct PrinterData *PD;
  29.     extern struct PrinterExtendedData *PED;
  30.  
  31.     UWORD textlength, topmargin;
  32.     int x, y, j;
  33.     static char initThisPrinter[INIT_LEN] =
  34.         "\033&d@\033&l6D\033(s0b10h1q0p0s3t0u12V";
  35.     static char initForm[FORM_LEN] = "\033&l002e000F";
  36.     static char initMarg[MARG_LEN] = "\033&a000l000M\015";
  37.     static char initTMarg[] = "\033&l000e000F";
  38.  
  39.     x = y = j = 0;
  40.  
  41.     if (*command == aRIN) {
  42.         while(x < INIT_LEN) {
  43.             outputBuffer[x] = initThisPrinter[x];
  44.             x++;
  45.         }
  46.         outputBuffer[x++] = '\015';
  47.  
  48.         if (PD->pd_Preferences.PrintSpacing == EIGHT_LPI) {
  49.             outputBuffer[LPI] = '8';
  50.         }
  51.  
  52.         if (PD->pd_Preferences.PrintPitch == ELITE) {
  53.             outputBuffer[CPI] = '2';
  54.         }
  55.         else if (PD->pd_Preferences.PrintPitch == FINE) {
  56.             outputBuffer[CPI] = '5';
  57.         }
  58.  
  59.         if (PD->pd_Preferences.PrintQuality == LETTER) {
  60.             outputBuffer[QUALITY] = '2';
  61.         }
  62.  
  63.         j = x; /* set the formlength = textlength, top margin = 2 */
  64.         textlength = PD->pd_Preferences.PaperLength;
  65.         topmargin = 2;
  66.  
  67.         while (y < FORM_LEN) {
  68.             outputBuffer[x++] = initForm[y++];
  69.         }
  70.         numberString(textlength, j + LPP, outputBuffer);
  71.  
  72.         Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  73.         Parms[1] = PD->pd_Preferences.PrintRightMargin;
  74.         *command = aSLRM;
  75.     }
  76.  
  77.     if (*command == aSLRM) {
  78.         j = x;
  79.         y = 0;
  80.         while(y < MARG_LEN) {
  81.             outputBuffer[x++] = initMarg[y++];
  82.         }
  83.         numberString(Parms[0] - 1, j + LEFT_MARG, outputBuffer);
  84.         numberString(Parms[1] - 1, j + RIGHT_MARG, outputBuffer);
  85.         return(x);
  86.     }
  87.  
  88.     if ((*command == aSUS2) && (*vline == 0)) {
  89.         *command = aPLU;
  90.         *vline = 1;
  91.         return(0);
  92.     }
  93.  
  94.     if ((*command == aSUS2) && (*vline < 0)) {
  95.         *command = aRI;
  96.         *vline = 1;
  97.         return(0);
  98.     }
  99.  
  100.     if ((*command == aSUS1) && (*vline > 0)) {
  101.         *command = aPLD;
  102.         *vline = 0;
  103.         return(0);
  104.     }
  105.  
  106.     if ((*command == aSUS4) && (*vline == 0)) {
  107.         *command = aPLD;
  108.         *vline = -1;
  109.         return(0);
  110.     }
  111.  
  112.     if ((*command == aSUS4) && (*vline > 0)) {
  113.         *command = aIND;
  114.         *vline = -1;
  115.         return(0);
  116.     }
  117.  
  118.     if ((*command == aSUS3) && (*vline < 0)) {
  119.         *command = aPLU;
  120.         *vline = 0;
  121.         return(0);
  122.     }
  123.  
  124.     if(*command == aSUS0) {
  125.         if (*vline > 0) {
  126.             *command = aPLD;
  127.         }
  128.         if (*vline < 0) {
  129.             *command = aPLU;
  130.         }
  131.         *vline = 0;
  132.         return(0);
  133.     }
  134.  
  135.     if (*command == aPLU) {
  136.         (*vline)++;
  137.         return(0);
  138.     }
  139.  
  140.     if (*command == aPLD){
  141.         (*vline)--;
  142.         return(0);
  143.     }
  144.  
  145.     if (*command == aSTBM) {
  146.         if (Parms[0] == 0) {
  147.             Parms[0] = topmargin;
  148.         }
  149.         else {
  150.             topmargin = --Parms[0];
  151.         }
  152.  
  153.         if (Parms[1] == 0) {
  154.             Parms[1] = textlength;
  155.         }
  156.         else {
  157.             textlength=Parms[1];
  158.         }
  159.         while (x < 11) {
  160.             outputBuffer[x] = initTMarg[x];
  161.             x++;
  162.         }
  163.         numberString(Parms[0], 3, outputBuffer);
  164.         numberString(Parms[1] - Parms[0], 7, outputBuffer);
  165.         return(x);
  166.     }
  167.  
  168.     if (*command == aSLPP) {
  169.         while(x < 11) {
  170.             outputBuffer[x] = initForm[x];
  171.             x++;
  172.         }
  173.         /*restore textlength, margin*/
  174.         numberString(topmargin, 3, outputBuffer);
  175.         numberString(textlength, 7, outputBuffer);
  176.         return(x);    
  177.     }
  178.  
  179.     if (*command == aRIS) {
  180.         PD->pd_PWaitEnabled = 253;
  181.     }
  182.  
  183.     return(0);
  184. }
  185.  
  186. numberString(Param, x, outputBuffer)
  187. UBYTE Param;
  188. int x;
  189. char outputBuffer[];
  190. {
  191.     if (Param > 199) {
  192.         outputBuffer[x++] = '2';
  193.         Param -= 200;
  194.     }
  195.     else if (Param > 99) {
  196.         outputBuffer[x++] = '1';
  197.         Param -= 100;
  198.     }
  199.     else {
  200.         outputBuffer[x++] = '0'; /* always return 3 digits */
  201.     }
  202.  
  203.     if (Param > 9) {
  204.         outputBuffer[x++] = Param / 10 + '0';
  205.     }
  206.     else {
  207.         outputBuffer[x++] = '0';
  208.     }
  209.  
  210.     outputBuffer[x++] = Param % 10 + '0';
  211. }
  212.  
  213. ConvFunc(buf, c, flag)
  214. char *buf, c;
  215. int flag; /* expand lf into lf/cr flag (0-yes, else no ) */
  216. {
  217.     if (c == '\014') { /* if formfeed (page eject) */
  218.         PED->ped_PrintMode = 0; /* no data to print */
  219.     }
  220.     return(-1); /* pass all chars back to the printer device */
  221. }
  222.  
  223. Close(ior)
  224. struct printerIO *ior;
  225. {
  226.     if (PED->ped_PrintMode) { /* if data has been printed */
  227.         (*(PD->pd_PWrite))("\014",1); /* eject page */
  228.         (*(PD->pd_PBothReady))(); /* wait for it to finish */
  229.         PED->ped_PrintMode = 0; /* no data to print */
  230.     }
  231.     return(0);
  232. }
  233.