[haiku-commits] haiku: hrev52187 - src/add-ons/print/drivers/lpstyl

  • From: Adrien Destugues <pulkomandy@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 7 Aug 2018 14:55:32 -0400 (EDT)

hrev52187 adds 2 changesets to branch 'master'
old head: c85dd27c9e06bf4dff8d51ab79d9570003018471
new head: 8d1f13817f33276a94a48396dbd3aa9f5634118d
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=8d1f13817f33+%5Ec85dd27c9e06

----------------------------------------------------------------------------

d9949ac911df: Initial work on Apple Stylewriter printer driver.

8d1f13817f33: libsolv: #define _GNU_SOURCE from command line
  
  On Haiku host, we need _GNU_SOURCE defined when stdio.h is included
  to use fopencookie. We did that in libsolv sources, but we now include
  stdio from BeOSBuildCompatibility.h which is included from the command
  line. So set _GNU_SOURCE from command line as well.

                                 [ Adrien Destugues <pulkomandy@xxxxxxxxx> ]

----------------------------------------------------------------------------

10 files changed, 513 insertions(+)
src/add-ons/print/drivers/Jamfile                |   1 +
src/add-ons/print/drivers/lpstyl/Jamfile         |  14 ++
src/add-ons/print/drivers/lpstyl/Lpstyl.cpp      | 178 +++++++++++++++++++
src/add-ons/print/drivers/lpstyl/Lpstyl.h        |  51 ++++++
src/add-ons/print/drivers/lpstyl/LpstylCap.cpp   | 126 +++++++++++++
src/add-ons/print/drivers/lpstyl/LpstylCap.h     |  24 +++
src/add-ons/print/drivers/lpstyl/LpstylData.cpp  |  25 +++
src/add-ons/print/drivers/lpstyl/LpstylData.h    |  31 ++++
src/add-ons/print/drivers/lpstyl/LpstylEntry.cpp |  62 +++++++
src/build/libsolv/Jamfile                        |   1 +

############################################################################

Commit:      d9949ac911df2fb1023ee4b14fa34a41633e370a
URL:         https://git.haiku-os.org/haiku/commit/?id=d9949ac911df
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Sun Jun  3 16:33:51 2018 UTC

Initial work on Apple Stylewriter printer driver.

----------------------------------------------------------------------------

diff --git a/src/add-ons/print/drivers/Jamfile 
b/src/add-ons/print/drivers/Jamfile
index 3161cd4ca9..5b6a0d465b 100644
--- a/src/add-ons/print/drivers/Jamfile
+++ b/src/add-ons/print/drivers/Jamfile
@@ -2,6 +2,7 @@ SubDir HAIKU_TOP src add-ons print drivers ;
 
 SubInclude HAIKU_TOP src add-ons print drivers canon_lips ;
 SubInclude HAIKU_TOP src add-ons print drivers gutenprint ;
+SubInclude HAIKU_TOP src add-ons print drivers lpstyl ;
 SubInclude HAIKU_TOP src add-ons print drivers pcl5 ;
 SubInclude HAIKU_TOP src add-ons print drivers pcl6 ;
 SubInclude HAIKU_TOP src add-ons print drivers postscript ;
diff --git a/src/add-ons/print/drivers/lpstyl/Jamfile 
b/src/add-ons/print/drivers/lpstyl/Jamfile
new file mode 100644
index 0000000000..16e72091b0
--- /dev/null
+++ b/src/add-ons/print/drivers/lpstyl/Jamfile
@@ -0,0 +1,14 @@
+SubDir HAIKU_TOP src add-ons print drivers lpstyl ;
+
+SubDirHdrs [ FDirName $(HAIKU_TOP) headers libs print libprint ] ;
+
+AddResources Lpstyl : Lpstyl.rdef ;
+
+Addon Lpstyl :
+       Lpstyl.cpp
+       LpstylCap.cpp
+       LpstylData.cpp
+       LpstylEntry.cpp
+       : be libprint.a [ TargetLibstdc++ ]
+;
+
diff --git a/src/add-ons/print/drivers/lpstyl/Lpstyl.cpp 
b/src/add-ons/print/drivers/lpstyl/Lpstyl.cpp
new file mode 100644
index 0000000000..11ee6b82a3
--- /dev/null
+++ b/src/add-ons/print/drivers/lpstyl/Lpstyl.cpp
@@ -0,0 +1,178 @@
+/*
+* Copyright 2017, Haiku. All rights reserved.
+* Distributed under the terms of the MIT License.
+*
+* Authors:
+*              Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
+*/
+#include "Lpstyl.h"
+
+
+LpstylDriver::LpstylDriver(BMessage* message, PrinterData* printerData,
+       const PrinterCap* printerCap)
+       : GraphicsDriver(message, printerData, printerCap)
+{
+}
+
+
+bool
+LpstylDriver::StartDocument()
+{
+       _EjectAndReset();
+       _IdentifyPrinter();
+       _ColorCartridge();
+       return true;
+}
+
+
+bool
+LpstylDriver::StartPage()
+{
+       if (fPrinterType < kStyleWriter2400)
+               WriteSpoolData("nuA", 3);
+       else
+               WriteSpoolChar('L');
+       return true;
+}
+
+
+bool
+LpstylDriver::NextBand(BBitmap* bitmap, BPoint* offset)
+{
+       fprintf(stderr, "Next band at %f %f\n", offset->x, offset->y);
+
+       int page_height = GetPageHeight();
+
+       // Advance the cursor
+       offset->y += bitmap->Bounds().Height();
+
+       // Have we reached the end of the page yet?
+       if (offset->y >= page_height)
+       {
+               offset->y = -1;
+               offset->x = -1;
+       }
+
+       return true;
+}
+
+
+bool
+LpstylDriver::EndPage(int page)
+{
+       fprintf(stderr, "end page %d\n", page);
+       return true;
+}
+
+
+bool
+LpstylDriver::EndDocument(bool success)
+{
+       return true;
+}
+
+
+/** Eject the current page (if any) and reset the printer.
+ */
+void
+LpstylDriver::_EjectAndReset(void)
+{
+       _WriteFFFx('I');
+
+       int s1;
+
+       do {
+               for (;;) {
+                       try {
+                               s1 = _GetStatus('1');
+                               break;
+                       } catch(const TransportException&) {
+                               continue;
+                       }
+               }
+
+               if (s1 == 1) {
+                       // Check for stylewriter1, where status 1 doesn't g to 
0 on init.
+                       if (_GetStatus('2') == 0 && _GetStatus('B') == 0xa0)
+                               break;
+               }
+       } while (s1 == 1);
+}
+
+
+void
+LpstylDriver::_IdentifyPrinter(void)
+{
+       WriteSpoolChar('?');
+
+       char smallBuf[32];
+       int i = 0;
+       for (i = 0; i < 31; i++) {
+               smallBuf[i] = ReadSpoolChar();
+               if (smallBuf[i] == 0x0D)
+                       break;
+       }
+       smallBuf[i] = 0;
+
+       if (strcmp(smallBuf, "IJ10\x0D") == 0)
+               fPrinterType = kStyleWriter;
+       else if (strcmp(smallBuf, "SW\x0D") == 0)
+               fPrinterType = kStyleWriter2;
+       else if (strcmp(smallBuf, "SW3\x0D") == 0)
+               fPrinterType = kStyleWriter3;
+       else if (strcmp(smallBuf, "CS\x0D") == 0) {
+               switch (_GetStatus('p'))
+               {
+                       default:
+                       case 1:
+                               fPrinterType = kStyleWriter2400;
+                               break;
+                       case 2:
+                               fPrinterType = kStyleWriter2200;
+                               break;
+                       case 4:
+                               fPrinterType = kStyleWriter1500;
+                               break;
+                       case 5:
+                               fPrinterType = kStyleWriter2500;
+                               break;
+               }
+       }
+}
+
+
+bool
+LpstylDriver::_ColorCartridge()
+{
+       WriteSpoolChar('D');
+       unsigned char i = _GetStatus('H');
+       return i & 0x80;
+}
+
+
+/** Send a 4-byte command to the printer.
+ *
+ * These commands can be sent at any time, because their prefix is FFFFFF, a
+ * sequence which can't be generated by the data compression algorithm
+ */
+void
+LpstylDriver::_WriteFFFx(char x)
+{
+       unsigned char str[4];
+       str[0] = str[1] = str[2] = 0xFF;
+       str[3] = x;
+       WriteSpoolData(str, 4);
+}
+
+
+/** Get one of the printer status bytes.
+ *
+ * There are 3 status registers, 1, 2, and B. Each returns some different
+ * information about the printer state.
+ */
+int
+LpstylDriver::_GetStatus(char reg)
+{
+       _WriteFFFx(reg);
+       return ReadSpoolChar();
+}
diff --git a/src/add-ons/print/drivers/lpstyl/Lpstyl.h 
b/src/add-ons/print/drivers/lpstyl/Lpstyl.h
new file mode 100644
index 0000000000..1fecec7e07
--- /dev/null
+++ b/src/add-ons/print/drivers/lpstyl/Lpstyl.h
@@ -0,0 +1,51 @@
+/*
+* Copyright 2017, Haiku. All rights reserved.
+* Distributed under the terms of the MIT License.
+*
+* Authors:
+*              Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
+*/
+#ifndef LPSTYL_H
+#define LPSTYL_H
+
+
+#include "GraphicsDriver.h"
+
+
+enum PrinterType {
+       kStyleWriter,
+       kStyleWriter2,
+       kStyleWriter3,
+       kStyleWriter2400,
+       kStyleWriter2200,
+       kStyleWriter1500,
+       kStyleWriter2500
+};
+
+
+class LpstylDriver: public GraphicsDriver {
+       public:
+                                               LpstylDriver(BMessage* message, 
PrinterData* printerData,
+                                                       const PrinterCap* 
printerCap);
+
+       protected:
+               bool                    StartDocument();
+               bool                    StartPage();
+               bool                    NextBand(BBitmap* bitmap, BPoint* 
offset);
+               bool                    EndPage(int page);
+               bool                    EndDocument(bool success);
+
+       private:
+               void                    _EjectAndReset(void);
+               void                    _IdentifyPrinter(void);
+               bool                    _ColorCartridge(void);
+
+               void                    _WriteFFFx(char x);
+               int                             _GetStatus(char reg);
+
+       private:
+               PrinterType             fPrinterType;
+};
+
+
+#endif
diff --git a/src/add-ons/print/drivers/lpstyl/LpstylCap.cpp 
b/src/add-ons/print/drivers/lpstyl/LpstylCap.cpp
new file mode 100644
index 0000000000..fb177f6fec
--- /dev/null
+++ b/src/add-ons/print/drivers/lpstyl/LpstylCap.cpp
@@ -0,0 +1,126 @@
+/*
+* Copyright 2017, Haiku. All rights reserved.
+* Distributed under the terms of the MIT License.
+*
+* Authors:
+*              Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
+*/
+#include "LpstylCap.h"
+
+
+#define TO72DPI(a)     (a * 72.0f / 360.0f)
+
+
+static const PaperCap a4(
+       "A4",
+       true,
+       JobData::kA4,
+       BRect(0.0f,           0.0f,           TO72DPI(2975.0f), 
TO72DPI(4210.0f)),
+       BRect(TO72DPI(72.0f), TO72DPI(72.0f), TO72DPI(2903.0f), 
TO72DPI(4138.0f)));
+
+static const PaperCap letter(
+       "Letter",
+       true,
+       JobData::kLetter,
+       BRect(0.0f,           0.0f,           TO72DPI(3060.0f), 
TO72DPI(3960.0f)),
+       BRect(TO72DPI(72.0f), TO72DPI(72.0f), TO72DPI(2988.0f), 
TO72DPI(3888.0f)));
+
+
+static const ResolutionCap dpi360("360dpi",   true,  1, 360,  360);
+
+
+static const PaperCap* papers[] = {
+       &a4,
+       &letter,
+};
+
+static const ResolutionCap* resolutions[] = {
+       &dpi360,
+};
+
+static const ColorCap color("Color", false, JobData::kColor);
+static const ColorCap monochrome("Shades of Gray", true, JobData::kMonochrome);
+
+static const ColorCap* colors[] = {
+       &color,
+       &monochrome
+};
+
+// This is required so libprint saves PrinterData in the printer spool dir.
+static const ProtocolClassCap proto("Serial", true, 1, "Serial port");
+
+static const ProtocolClassCap* protocols[] = {
+       &proto
+};
+
+
+int
+LpstylCap::CountCap(CapID capid) const
+{
+       switch (capid) {
+               case kPaper:
+                       return sizeof(papers) / sizeof(papers[0]);
+               case kResolution:
+                       return sizeof(resolutions) / sizeof(resolutions[0]);
+#if 0
+               case kPaperSource:
+                       return sizeof(papersources) / sizeof(papersources[0]);
+               case kPrintStyle:
+                       return sizeof(printstyles) / sizeof(printstyles[0]);
+               case kBindingLocation:
+                       return sizeof(bindinglocations) / 
sizeof(bindinglocations[0]);
+#endif
+               case kColor:
+                       return sizeof(colors) / sizeof(colors[0]);
+               case kProtocolClass:
+                       return sizeof(protocols) / sizeof(protocols[0]);
+               default:
+                       return 0;
+               }
+}
+
+
+const BaseCap**
+LpstylCap::GetCaps(CapID capid) const
+{
+       switch (capid) {
+               case kPaper:
+                       return (const BaseCap **)papers;
+               case kResolution:
+                       return (const BaseCap **)resolutions;
+#if 0
+               case kPaperSource:
+                       return (const BaseCap **)papersources;
+               case kPrintStyle:
+                       return (const BaseCap **)printstyles;
+               case kBindingLocation:
+                       return (const BaseCap **)bindinglocations;
+#endif
+               case kProtocolClass:
+                       return (const BaseCap **)protocols;
+               case kColor:
+                       return (const BaseCap **)colors;
+               default:
+                       return NULL;
+       }
+}
+
+
+bool
+LpstylCap::Supports(CapID capid) const
+{
+       switch (capid) {
+               case kPaper:
+               case kResolution:
+               case kColor:
+               case kProtocolClass:
+                       return true;
+               case kPaperSource:
+               case kPrintStyle:
+               case kBindingLocation:
+               case kCopyCommand:
+               case kHalftone:
+               default:
+                       return false;
+       }
+}
diff --git a/src/add-ons/print/drivers/lpstyl/LpstylCap.h 
b/src/add-ons/print/drivers/lpstyl/LpstylCap.h
new file mode 100644
index 0000000000..4bcce700d7
--- /dev/null
+++ b/src/add-ons/print/drivers/lpstyl/LpstylCap.h
@@ -0,0 +1,24 @@
+/*
+* Copyright 2017, Haiku. All rights reserved.
+* Distributed under the terms of the MIT License.
+*
+* Authors:
+*              Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
+*/
+#ifndef LPSTYLCAP_H
+#define LPSTYLCAP_H
+
+
+#include "PrinterCap.h"
+
+
+class LpstylCap : public PrinterCap {
+public:
+                                       LpstylCap(const PrinterData* 
printer_data)
+                                               : PrinterCap(printer_data) {}
+       virtual int             CountCap(CapID) const;
+       virtual bool    Supports(CapID) const;
+       virtual const   BaseCap** GetCaps(CapID) const;
+};
+
+#endif // __LIPS4CAP_H
diff --git a/src/add-ons/print/drivers/lpstyl/LpstylData.cpp 
b/src/add-ons/print/drivers/lpstyl/LpstylData.cpp
new file mode 100644
index 0000000000..12cd77b9ef
--- /dev/null
+++ b/src/add-ons/print/drivers/lpstyl/LpstylData.cpp
@@ -0,0 +1,25 @@
+/*
+* Copyright 2017, Haiku. All rights reserved.
+* Distributed under the terms of the MIT License.
+*
+* Authors:
+*              Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
+*/
+
+
+#include "LpstylData.h"
+
+#include <termios.h>
+
+#include <Node.h>
+#include <SupportKit.h>
+
+
+void
+LpstylData::Save()
+{
+       PrinterData::Save();
+       // force baudrate for the serial transport
+       int32 rate = B57600;
+       fNode->WriteAttr("transport_baudrate", B_INT32_TYPE, 0, &rate, 
sizeof(int32));
+}
diff --git a/src/add-ons/print/drivers/lpstyl/LpstylData.h 
b/src/add-ons/print/drivers/lpstyl/LpstylData.h
new file mode 100644
index 0000000000..0c15647de1
--- /dev/null
+++ b/src/add-ons/print/drivers/lpstyl/LpstylData.h
@@ -0,0 +1,31 @@
+/*
+* Copyright 2017, Haiku. All rights reserved.
+* Distributed under the terms of the MIT License.
+*
+* Authors:
+*              Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
+*/
+#ifndef LPSTYLDATA_H
+#define LPSTYLDATA_H
+
+
+#include "PrinterData.h"
+
+
+class BNode;
+
+
+class LpstylData : public PrinterData {
+public:
+                                       LpstylData(BNode* node)
+                                       :
+                                       PrinterData(node)
+                                       {
+                                       }
+
+       // PrinterData overrides
+       virtual void    Save();
+};
+
+#endif // LPSTYLDATA_H
+
diff --git a/src/add-ons/print/drivers/lpstyl/LpstylEntry.cpp 
b/src/add-ons/print/drivers/lpstyl/LpstylEntry.cpp
new file mode 100644
index 0000000000..4e1acb904f
--- /dev/null
+++ b/src/add-ons/print/drivers/lpstyl/LpstylEntry.cpp
@@ -0,0 +1,62 @@
+/*
+* Copyright 2017, Haiku. All rights reserved.
+* Distributed under the terms of the MIT License.
+*
+* Authors:
+*              Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
+*/
+#include "Lpstyl.h"
+#include "LpstylCap.h"
+#include "LpstylData.h"
+#include "PrinterDriver.h"
+
+
+class LpstylPrinterDriver : public PrinterDriver
+{
+       public:
+               LpstylPrinterDriver(BNode* printerFolder)
+                       : PrinterDriver(printerFolder)
+               {}
+
+               const char* GetSignature() const
+               {
+                       return "application/x-vnd.lpstyl";
+               }
+
+               const char* GetDriverName() const
+               {
+                       return "Apple StyleWriter";
+               }
+
+               const char* GetVersion() const
+               {
+                       return "1.0.0";
+               }
+
+               const char* GetCopyright() const
+               {
+                       return "Copyright 1996-2000 Monroe Williams, 2017 
Adrien Destugues.\n";
+               }
+
+               PrinterData* InstantiatePrinterData(BNode* node)
+               {
+                       return new LpstylData(node);
+               }
+
+               PrinterCap* InstantiatePrinterCap(PrinterData* printerData)
+               {
+                       return new LpstylCap(printerData);
+               }
+
+               GraphicsDriver* InstantiateGraphicsDriver(BMessage* settings,
+                       PrinterData* printerData, PrinterCap* printerCap)
+               {
+                       return new LpstylDriver(settings, printerData, 
printerCap);
+               }
+};
+
+PrinterDriver*
+instantiate_printer_driver(BNode* printerFolder)
+{
+       return new LpstylPrinterDriver(printerFolder);
+}

############################################################################

Revision:    hrev52187
Commit:      8d1f13817f33276a94a48396dbd3aa9f5634118d
URL:         https://git.haiku-os.org/haiku/commit/?id=8d1f13817f33
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Tue Aug  7 18:50:56 2018 UTC

libsolv: #define _GNU_SOURCE from command line

On Haiku host, we need _GNU_SOURCE defined when stdio.h is included
to use fopencookie. We did that in libsolv sources, but we now include
stdio from BeOSBuildCompatibility.h which is included from the command
line. So set _GNU_SOURCE from command line as well.

----------------------------------------------------------------------------

diff --git a/src/build/libsolv/Jamfile b/src/build/libsolv/Jamfile
index e09b82cc4d..c7e7888780 100644
--- a/src/build/libsolv/Jamfile
+++ b/src/build/libsolv/Jamfile
@@ -16,6 +16,7 @@ DEFINES =
        HAIKU
        ENABLE_HAIKU
        VERSION=\\\"$(libsolvVersion)\\\"
+       _GNU_SOURCE
        ;
 
 # One of the following must be defined:


Other related posts:

  • » [haiku-commits] haiku: hrev52187 - src/add-ons/print/drivers/lpstyl - Adrien Destugues