home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0657.ZIP / CCE_0657.PD / HP.C < prev    next >
C/C++ Source or Header  |  1993-10-08  |  10KB  |  437 lines

  1. /*********************************************************************
  2. ****    Universaltreiber für HP-kompatible Drucker                ****
  3. *********************************************************************/
  4.  
  5. /* Siehe auch Datei JP350WS.C */
  6.  
  7. #include <portab.h>
  8. #include <atarierr.h>
  9.  
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. #include "mintbind.h"    /* Geht seltsamerweise nur mit der eigenen Version */
  14. #include "treiber.h"
  15.  
  16.  
  17. /********************************************************************/
  18. /* Setzt die freien Werte auf Standartwerte */
  19.  
  20. #ifndef OBEN    /* Wenn noch kein oberer Rand definiert */
  21. #define OBEN 0L
  22. #endif
  23.  
  24. #ifndef LINKS    /* Wenn noch kein linker Rand definiert */
  25. #define LINKS 0L
  26. #endif
  27.  
  28. #ifndef MAX_DPI    /* Wenn keine maximale Auflösung definiert */
  29. #define MAX_DPI 1200L
  30. #endif
  31.  
  32. #ifndef WEITE    /* druckbare Breite (in Pixel) */
  33. #define WEITE ((2336L*MAX_DPI)/300L)
  34. #endif
  35.  
  36. #ifndef HOEHE        /* druckbare Höhe (in Pixel) */
  37. #define HOEHE ((3386L*MAX_DPI)/300L)
  38. #endif
  39.  
  40.  
  41. /********************************************************************/
  42.  
  43.  
  44.  
  45. /* Findet entweder Wiederholung (TRUE) oder nichts */
  46. WORD    find_next_same( WORD *rep, UBYTE *p, LONG limit )
  47. {
  48.     WORD    i;
  49.  
  50.         /* Spezialfälle */
  51.     if(  limit<1  )
  52.     {
  53.         *rep = 1;
  54.         return FALSE;
  55.     }
  56.     if( limit<2  &&  p[0]==p[1]  )
  57.     {
  58.         *rep = 2;
  59.         return TRUE;
  60.     }
  61.  
  62.         /* Sonst getrennt */
  63.     if(  p[0]==p[1]  &&  p[1]==p[2]  )
  64.     {
  65.         /* Abstand zum nächsten Ungleichen... */
  66.         i = 3;
  67.         while(  i<128  &&  i<limit  &&  p[0]==p[i]  )
  68.             i++;
  69.         *rep = i;
  70.         return TRUE;
  71.     }
  72.     else
  73.     {
  74.         /* ... bzw. Gleichen ermitteln */
  75.         i = 0;
  76.         while(  i<128  &&  i<limit  &&  !(p[i]==p[i+1]  &&  p[i]==p[i+2])  )
  77.             i++;
  78.         *rep = i;
  79.         return FALSE;
  80.     }
  81. }
  82. /* 17.1.93 */
  83.  
  84.  
  85. static UBYTE    druckzeile[4096];
  86.  
  87. /* Wird aufgerufen, wenn Datei zu drucken */
  88. WORD    drucke_datei( UBYTE *p, LONG weite, LONG max_zeile, LONG h_dpi, LONG max_spalte, LONG zeile )
  89. {
  90.     UBYTE    tmp1[50];
  91.     LONG    lz, rechts;
  92.     LONG    i, j;
  93.     WORD    rep, modus=0/* Komprimiert oder nicht? */;
  94.     WORD    th;
  95.  
  96.     /* Ränder feststellen */
  97.     while(  ist_next_leer( p+max_spalte-1, weite, max_zeile )  &&  max_spalte>1  )
  98.         max_spalte--;
  99.  
  100.     if(  (th=(WORD)get_tempfile( "hp" ))<0  )
  101.         return -1;
  102.  
  103.     if(  max_spalte<=1  )
  104.     {
  105.         /* Seite leer */
  106.         Fwrite( th, 5L, " \33*rB\14" ); /*FF*/
  107.         return Fclose( th );
  108.     }
  109.  
  110.         /* In die obere Ecke */
  111.     Fwrite( th, 27, " \33*p0Y\33*p-300Y\33*p0X\33*p-300X" );
  112.         /* Grafikdruck Anfang */
  113.     strcpy( tmp1, "\33*rB\33*t" );
  114.         /* Grafikauflösung festlegen */
  115.     ltoa( h_dpi, tmp1+7, 10 );
  116.     strcat( tmp1, "R\33*r" );
  117.     Fwrite( th, strlen(tmp1), tmp1 );
  118.         /* Grafikweite festlegen */
  119.     ltoa( max_spalte*8, tmp1, 10 );
  120.     strcat( tmp1, "s0A" );
  121.     Fwrite( th, strlen(tmp1), tmp1 );
  122.  
  123.     while(  zeile<max_zeile  )
  124.      {
  125.              /* Leerzeilen überspringen */
  126.          for(  lz=0;  zeile<max_zeile  &&  ist_leerzeile( p, max_spalte );  lz++, zeile++  )
  127.              p += weite;
  128.          if(  lz>0  )
  129.          {
  130.             strcpy( tmp1, "\33*b" );
  131.             ltoa( lz, tmp1+3, 10 );
  132.             strcat( tmp1, "Y" );
  133.             Fwrite( th, strlen(tmp1), tmp1 );
  134.          }
  135.  
  136.             /* eine oder Druckzeilen an den Drucker! */
  137.         for(  lz=max_zeile;  zeile<lz  &&  zeile<max_zeile  &&  !ist_leerzeile( p, max_spalte );  zeile++  )
  138.         {
  139.             /* Wir komprimieren */
  140.             for(  rechts=1;  rechts<max_spalte  &&  p[max_spalte-rechts]==0;  rechts++  )
  141.                 ;
  142.             rechts--;
  143.             for(  i=0, j=0;  i<max_spalte-rechts  &&  j<max_spalte-rechts;  /*Nichts*/  )
  144.             {
  145.                 if(  find_next_same( &rep, p+i, max_spalte-i-rechts )  )
  146.                 {
  147.                     /* Gleiche */
  148.                     druckzeile[j++] = 1-rep;
  149.                     druckzeile[j++] = p[i];
  150.                     i += rep;
  151.                 }
  152.                 else
  153.                 {
  154.                     /* Ungleiche */
  155.                     druckzeile[j++] = rep-1;
  156.                     while(  rep-->0  )
  157.                         druckzeile[j++] = p[i++];
  158.                 }
  159.             }
  160.  
  161.             /* Und nun den interessanten Rest */
  162.         if(  j<max_spalte-rechts  )
  163.         {
  164.             /* Komprimieren brachte etwas */
  165.             strcpy( tmp1, "\33*b2m" );
  166.             ltoa( j, tmp1+3+2-modus, 10 );
  167.             strcat( tmp1, "W" );
  168.             Fwrite( th, strlen(tmp1), tmp1 );
  169.             Fwrite( th, j, druckzeile );
  170.             modus = 2;
  171.         }
  172.         else
  173.         {
  174.             /* Komprimieren brachte nichts */
  175.             j = max_spalte-rechts;
  176.             strcpy( tmp1, "\33*b0m" );
  177.             ltoa( j, tmp1+3+modus, 10 );
  178.             strcat( tmp1, "W" );
  179.             Fwrite( th, strlen(tmp1), tmp1 );
  180.             Fwrite( th, j, p );
  181.             modus = 0;
  182.         }
  183.  
  184.         p += weite;
  185.         }
  186.     }
  187.  
  188.     /* Ende Grafikmodus */
  189.     /* Sollte immer gut gehen! (d.h. kein File zum drucken!) */
  190.     Fwrite( th, 5L, "\33*rB\14" );
  191.     return Fclose( th );
  192. }
  193. /* 22.1.93 */
  194.  
  195.  
  196.  
  197. WORD    drucke( UBYTE *p, LONG weite, LONG max_zeile, LONG h_dpi, LONG v_dpi )
  198. {
  199.     UBYTE    tmp1[50];
  200.     LONG    max_spalte, zeile, lz, rechts;
  201.     LONG    i, j;
  202.     WORD    rep, modus=0/* Komprimiert oder nicht? */;
  203.     extern char    tmp_file[256]; /* In Datei drucken? */
  204.  
  205.     if(  h_dpi>700  )
  206.         h_dpi = 1200;
  207.     else if(  h_dpi>350  )
  208.         h_dpi = 600;
  209.     else if(  h_dpi>175  )
  210.         h_dpi = 300;
  211.     else if(  h_dpi>110  )
  212.         h_dpi = 150;
  213.     else if(  h_dpi>80  )
  214.         h_dpi = 100;
  215.     else
  216.         h_dpi = 75;
  217.  
  218.         /* Unsinnige Werte werden als Maximum angenommen */
  219.     if(  h_dpi<=0  ||  h_dpi>MAX_DPI  )
  220.         h_dpi = MAX_DPI;
  221.  
  222.     i = (OBEN*h_dpi)/MAX_DPI;
  223.     j = (LINKS*h_dpi)/MAX_DPI;
  224.     max_spalte = (weite+15)/16;
  225.     max_spalte *= 2;
  226.     p += (max_spalte*i) + j;    /* Nicht druckbare Ränder*/
  227.  
  228.     max_spalte -= j;
  229.     if(  weite>(WEITE+LINKS*8)*h_dpi/MAX_DPI  /* LINKS*8 nicht druckbar!*/  )
  230.         max_spalte = (WEITE*h_dpi)/(8*MAX_DPI);
  231.  
  232.     max_zeile -= i+1;
  233.     if(  max_zeile>(HOEHE*h_dpi)/MAX_DPI  )
  234.         max_zeile = (HOEHE*h_dpi)/MAX_DPI;
  235.     zeile = 0;
  236.     weite = (weite+15)/16;
  237.     weite *= 2;
  238.  
  239.     /* Ränder feststellen */
  240.     while(  max_spalte>0  &&  ist_next_leer( p+max_spalte-1, weite, max_zeile )  )
  241.         max_spalte--;
  242.  
  243.     if(  tmp_file[0]>0  )
  244.         return drucke_datei( p, weite, max_zeile, h_dpi, max_spalte, zeile );
  245.  
  246.     if(  open_printer()<0  )
  247.         return -1;
  248.  
  249.     if(  max_spalte<=1  )
  250.     {
  251.         /* Seite leer */
  252.         print_block( 5L, " \33*rB\14" ); /*FF*/
  253.         return 0;
  254.     }
  255.  
  256.         /* In die obere Ecke */
  257.     print_block( 27L, " \33*p0Y\33*p-300Y\33*p0X\33*p-300X" );
  258.         /* Grafikdruck Anfang */
  259.     strcpy( tmp1, "\33*rB\33*t" );
  260.         /* Grafikauflösung festlegen */
  261.     ltoa( h_dpi, tmp1+7, 10 );
  262.     strcat( tmp1, "R\33*r" );
  263.     print_block( strlen(tmp1), tmp1 );
  264.         /* Grafikweite festlegen */
  265.     ltoa( max_spalte*8, tmp1, 10 );
  266.     strcat( tmp1, "s0A" );
  267.     print_block( strlen(tmp1), tmp1 );
  268.  
  269.     while(  zeile<max_zeile  )
  270.      {
  271.              /* Leerzeilen überspringen */
  272.          for(  lz=0;  zeile<max_zeile  &&  ist_leerzeile( p, max_spalte );  lz++, zeile++  )
  273.              p += weite;
  274.          if(  lz>0  )
  275.          {
  276.             strcpy( tmp1, "\33*b" );
  277.             ltoa( lz, tmp1+3, 10 );
  278.             strcat( tmp1, "Y" );
  279.             print_block( strlen(tmp1), tmp1 );
  280.          }
  281.  
  282.             /* eine oder Druckzeilen an den Drucker! */
  283.         for(  lz=max_zeile;  zeile<lz  &&  zeile<max_zeile  &&  !ist_leerzeile( p, max_spalte );  zeile++  )
  284.         {
  285.             /* Wir komprimieren */
  286.             for(  rechts=1;  rechts<max_spalte  &&  p[max_spalte-rechts]==0;  rechts++  )
  287.                 ;
  288.             rechts--;
  289.             for(  i=0, j=0;  i<max_spalte-rechts  &&  j<max_spalte-rechts;  /*Nichts*/  )
  290.             {
  291.                 if(  find_next_same( &rep, p+i, max_spalte-i-rechts )  )
  292.                 {
  293.                     /* Gleiche */
  294.                     druckzeile[j++] = 1-rep;
  295.                     druckzeile[j++] = p[i];
  296.                     i += rep;
  297.                 }
  298.                 else
  299.                 {
  300.                     /* Ungleiche */
  301.                     druckzeile[j++] = rep-1;
  302.                     while(  rep-->0  )
  303.                         druckzeile[j++] = p[i++];
  304.                 }
  305.             }
  306.  
  307.             /* Und nun den interessanten Rest */
  308.         if(  j<max_spalte-rechts  )
  309.         {
  310.             /* Komprimieren brachte etwas */
  311.             strcpy( tmp1, "\33*b2m" );
  312.             ltoa( j, tmp1+3+2-modus, 10 );
  313.             strcat( tmp1, "W" );
  314.             print_block( strlen(tmp1), tmp1 );
  315.             print_block( j, druckzeile );
  316.             modus = 2;
  317.         }
  318.         else
  319.         {
  320.             /* Komprimieren brachte nichts */
  321.             j = max_spalte-rechts;
  322.             strcpy( tmp1, "\33*b0m" );
  323.             ltoa( j, tmp1+3+modus, 10 );
  324.             strcat( tmp1, "W" );
  325.             print_block( strlen(tmp1), tmp1 );
  326.             print_block( j, p );
  327.             modus = 0;
  328.         }
  329.  
  330.         p += weite;
  331.         }
  332.     }
  333.  
  334.     /* Ende Grafikmodus */
  335.     /* Sollte immer gut gehen! (d.h. kein File zum drucken!) */
  336.     print_block( 5L, "\33*rB\14" );
  337.     flush_block();
  338.     return 0;
  339. #if 0
  340. (864115415746648754)
  341.     if(  max_spalte<1  )
  342.     {
  343.         /* Seite leer */
  344.         print_block( 5L, " \33*rB\14" ); /*FF*/
  345.         flush_block();
  346.         return 0;
  347.     }
  348.  
  349.         /* In die obere Ecke */
  350.     print_block( 27, " \33*p0Y\33*p-300Y\33*p0X\33*p-300X" );
  351.         /* Grafikdruck Anfang */
  352.     strcpy( tmp1, "\33&100L\33*rB\33*t" );
  353.         /* Grafikauflösung festlegen */
  354.     ltoa( h_dpi, tmp1+13, 10 );
  355.     strcat( tmp1, "R\33*r" );
  356.     print_block( strlen(tmp1), tmp1 );
  357.         /* Grafikweite festlegen */
  358.     ltoa( max_spalte*8, tmp1, 10 );
  359.     strcat( tmp1, "s0A" );
  360.     print_block( strlen(tmp1), tmp1 );
  361.  
  362.     while(  zeile<max_zeile  )
  363.      {
  364.              /* Leerzeilen überspringen */
  365.          for(  lz=0;  zeile<max_zeile  &&  ist_leerzeile( p, max_spalte );  lz++, zeile++  )
  366.              p += weite;
  367.          if(  lz>0  )
  368.          {
  369.             strcpy( tmp1, "\33*b" );
  370.             ltoa( lz, tmp1+3, 10 );
  371.             strcat( tmp1, "Y" );
  372.             print_block( strlen(tmp1), tmp1 );
  373.          }
  374.  
  375.             /* 50 Zeilen (eine Druckkopfhöhe an den Drucker! */
  376.         for(  ;  zeile<max_zeile  &&  !ist_leerzeile( p, max_spalte );  zeile++  )
  377.         {
  378.             /* Wir komprimieren */
  379.             for(  rechts=1;  rechts<max_spalte  &&  p[max_spalte-rechts]==0;  rechts++  )
  380.                 ;
  381.             rechts--;
  382.             for(  i=0, j=0;  i<max_spalte-rechts  &&  j<max_spalte-rechts;  /*Nichts*/  )
  383.             {
  384.                 if(  find_next_same( &rep, p+i, max_spalte-i-rechts )  )
  385.                 {
  386.                     /* Gleiche */
  387.                     druckzeile[j++] = 1-rep;
  388.                     druckzeile[j++] = p[i];
  389.                     i += rep;
  390.                 }
  391.                 else
  392.                 {
  393.                     /* Ungleiche */
  394.                     druckzeile[j++] = rep-1;
  395.                     while(  rep-->0  )
  396.                         druckzeile[j++] = p[i++];
  397.                 }
  398.             }
  399.  
  400.                 /* Und nun den interessanten Rest */
  401.             if(  j<max_spalte-rechts  )
  402.             {
  403.                 /* Komprimieren brachte etwas */
  404.                 strcpy( tmp1, "\33*b2m" );
  405.                 ltoa( j, tmp1+5-modus, 10 );
  406.                 strcat( tmp1, "W" );
  407.                 print_block( strlen(tmp1), tmp1 );
  408.                 print_block( j, druckzeile );
  409.                 modus = 2;
  410.             }
  411.             else
  412.             {
  413.                 /* Komprimieren brachte nichts */
  414.                 j = max_spalte-rechts;
  415.                 strcpy( tmp1, "\33*b0m" );
  416.                 ltoa( j, tmp1+3+modus, 10 );
  417.                 strcat( tmp1, "W" );
  418.                 print_block( strlen(tmp1), tmp1 );
  419.                 print_block( j, p );
  420.                 modus = 0;
  421.             }
  422.     
  423.             p += weite;
  424.         }
  425.     }
  426.  
  427.     /* Ende Grafikmodus */
  428.     /* Sollte immer gut gehen! (d.h. kein File zum drucken!) */
  429.     print_block( 5L, "\33*rB\14" );
  430.     flush_block();
  431.     return 0;
  432. #endif
  433. }
  434. /* 22.1.93 */
  435.  
  436.  
  437.