Style cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37376 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -6,27 +6,31 @@
|
|||||||
* Ithamar R. Adema <[email protected]>
|
* Ithamar R. Adema <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "FilterIO.h"
|
#include "FilterIO.h"
|
||||||
|
|
||||||
#include <String.h>
|
|
||||||
#include <image.h>
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <image.h>
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
FilterIO::FilterIO(const BString& cmdline)
|
FilterIO::FilterIO(const BString& cmdline)
|
||||||
: BDataIO()
|
:
|
||||||
|
BDataIO()
|
||||||
{
|
{
|
||||||
BString cmd(cmdline);
|
BString cmd(cmdline);
|
||||||
const char *argv[4];
|
const char* argv[4];
|
||||||
|
|
||||||
argv[0] = strdup("/bin/sh");
|
argv[0] = strdup("/bin/sh");
|
||||||
argv[1] = strdup("-c");
|
argv[1] = strdup("-c");
|
||||||
argv[2] = strdup(cmd.String());
|
argv[2] = strdup(cmd.String());
|
||||||
argv[3] = NULL;
|
argv[3] = NULL;
|
||||||
|
|
||||||
InitData(3,argv);
|
InitData(3, argv);
|
||||||
|
|
||||||
free((void*)argv[0]);
|
free((void*)argv[0]);
|
||||||
free((void*)argv[1]);
|
free((void*)argv[1]);
|
||||||
@@ -35,18 +39,17 @@ FilterIO::FilterIO(const BString& cmdline)
|
|||||||
|
|
||||||
|
|
||||||
FilterIO::FilterIO(int argc, const char **argv, const char **envp)
|
FilterIO::FilterIO(int argc, const char **argv, const char **envp)
|
||||||
: BDataIO()
|
:
|
||||||
|
BDataIO()
|
||||||
{
|
{
|
||||||
InitData(argc,argv,envp);
|
InitData(argc, argv, envp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
FilterIO::InitData(int argc, const char **argv, const char **envp)
|
FilterIO::InitData(int argc, const char** argv, const char** envp)
|
||||||
{
|
{
|
||||||
fStdIn =
|
fStdIn = fStdOut = fStdErr = -1;
|
||||||
fStdOut =
|
|
||||||
fStdErr = -1;
|
|
||||||
fInitErr = B_OK;
|
fInitErr = B_OK;
|
||||||
|
|
||||||
fThreadId = PipeCommand(argc, argv, fStdIn, fStdOut, fStdErr, envp);
|
fThreadId = PipeCommand(argc, argv, fStdIn, fStdOut, fStdErr, envp);
|
||||||
@@ -70,21 +73,22 @@ FilterIO::~FilterIO()
|
|||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
FilterIO::Read(void *buffer, size_t size)
|
FilterIO::Read(void* buffer, size_t size)
|
||||||
{
|
{
|
||||||
return ::read(fStdOut, buffer, size);
|
return ::read(fStdOut, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
FilterIO::Write(const void *buffer, size_t size)
|
FilterIO::Write(const void* buffer, size_t size)
|
||||||
{
|
{
|
||||||
return ::write(fStdIn, buffer, size);
|
return ::write(fStdIn, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
thread_id
|
thread_id
|
||||||
FilterIO::PipeCommand(int argc, const char **argv, int &in, int &out, int &err, const char **envp)
|
FilterIO::PipeCommand(int argc, const char** argv, int& in, int& out, int& err,
|
||||||
|
const char** envp)
|
||||||
{
|
{
|
||||||
// This function written by Peter Folk <[email protected]>
|
// This function written by Peter Folk <[email protected]>
|
||||||
// and published in the BeDevTalk FAQ
|
// and published in the BeDevTalk FAQ
|
||||||
@@ -100,7 +104,7 @@ FilterIO::PipeCommand(int argc, const char **argv, int &in, int &out, int &err,
|
|||||||
|
|
||||||
int filedes[2];
|
int filedes[2];
|
||||||
|
|
||||||
/* Create new pipe FDs as stdin, stdout, stderr */
|
// Create new pipe FDs as stdin, stdout, stderr
|
||||||
pipe(filedes); dup2(filedes[0], 0); close(filedes[0]);
|
pipe(filedes); dup2(filedes[0], 0); close(filedes[0]);
|
||||||
in = filedes[1]; // Write to in, appears on cmd's stdin
|
in = filedes[1]; // Write to in, appears on cmd's stdin
|
||||||
pipe(filedes); dup2(filedes[1], 1); close(filedes[1]);
|
pipe(filedes); dup2(filedes[1], 1); close(filedes[1]);
|
||||||
|
|||||||
@@ -5,36 +5,41 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Ithamar R. Adema <[email protected]>
|
* Ithamar R. Adema <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FILTERIO_H
|
#ifndef FILTERIO_H
|
||||||
#define FILTERIO_H
|
#define FILTERIO_H
|
||||||
|
|
||||||
|
|
||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
|
|
||||||
class BString;
|
class BString;
|
||||||
|
|
||||||
|
|
||||||
class FilterIO : public BDataIO
|
class FilterIO : public BDataIO
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FilterIO(int argc, const char **argv, const char **envp = NULL);
|
FilterIO(int argc, const char** argv,
|
||||||
FilterIO(const BString& cmdline);
|
const char** envp = NULL);
|
||||||
~FilterIO();
|
FilterIO(const BString& cmdline);
|
||||||
|
~FilterIO();
|
||||||
|
|
||||||
status_t InitCheck() const
|
status_t InitCheck() const
|
||||||
{
|
{
|
||||||
return fInitErr;
|
return fInitErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Read(void *buffer, size_t size);
|
ssize_t Read(void* buffer, size_t size);
|
||||||
ssize_t Write(const void *buffer, size_t size);
|
ssize_t Write(const void* buffer, size_t size);
|
||||||
private:
|
private:
|
||||||
int fStdIn, fStdOut, fStdErr;
|
int fStdIn, fStdOut, fStdErr;
|
||||||
thread_id fThreadId;
|
thread_id fThreadId;
|
||||||
status_t fInitErr;
|
status_t fInitErr;
|
||||||
|
|
||||||
status_t InitData(int argc, const char **argv, const char **envp = NULL);
|
status_t InitData(int argc, const char** argv,
|
||||||
thread_id PipeCommand(int argc, const char **argv, int &in, int &out, int &err, const char **envp = NULL);
|
const char** envp = NULL);
|
||||||
|
thread_id PipeCommand(int argc, const char** argv, int& in,
|
||||||
|
int& out, int& err, const char** envp = NULL);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FILTERIO_H */
|
#endif // FILTERIO_H
|
||||||
|
|||||||
@@ -6,10 +6,11 @@
|
|||||||
* Ithamar R. Adema <[email protected]>
|
* Ithamar R. Adema <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "PPDParser.h"
|
#include "PPDParser.h"
|
||||||
|
|
||||||
#include <Path.h>
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
|
#include <Path.h>
|
||||||
|
|
||||||
|
|
||||||
PPDParser::PPDParser(BFile& file)
|
PPDParser::PPDParser(BFile& file)
|
||||||
@@ -18,9 +19,9 @@ PPDParser::PPDParser(BFile& file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PPDParser::PPDParser(const BDirectory& dir, const char *fname)
|
PPDParser::PPDParser(const BDirectory& dir, const char* fname)
|
||||||
{
|
{
|
||||||
BFile file(&dir,fname, B_READ_ONLY);
|
BFile file(&dir, fname, B_READ_ONLY);
|
||||||
InitData(file);
|
InitData(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,13 +37,13 @@ status_t
|
|||||||
PPDParser::InitData(BFile& file)
|
PPDParser::InitData(BFile& file)
|
||||||
{
|
{
|
||||||
// Check if file exists...
|
// Check if file exists...
|
||||||
if ((fInitErr=file.InitCheck()) != B_OK)
|
if ((fInitErr = file.InitCheck()) != B_OK)
|
||||||
return fInitErr;
|
return fInitErr;
|
||||||
|
|
||||||
// Read entire file into BString
|
// Read entire file into BString
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
char buffer[1025];
|
char buffer[1025];
|
||||||
while ((len=file.Read(buffer,sizeof(buffer)-1)) > 0) {
|
while ((len = file.Read(buffer, sizeof(buffer)-1)) > 0) {
|
||||||
buffer[len] = '\0';
|
buffer[len] = '\0';
|
||||||
fContent << buffer;
|
fContent << buffer;
|
||||||
}
|
}
|
||||||
@@ -67,17 +68,18 @@ PPDParser::GetParameter(const BString& param)
|
|||||||
|
|
||||||
pattern << "*" << param << ":";
|
pattern << "*" << param << ":";
|
||||||
|
|
||||||
while ((next=fContent.FindFirst('\n', pos)) > 0) {
|
while ((next = fContent.FindFirst('\n', pos)) > 0) {
|
||||||
// Grab line (without newline)
|
// Grab line (without newline)
|
||||||
fContent.CopyInto(line, pos, next-pos);
|
fContent.CopyInto(line, pos, next - pos);
|
||||||
// Found our parameter?
|
// Found our parameter?
|
||||||
if (line.Compare(pattern,pattern.Length()) == 0) {
|
if (line.Compare(pattern, pattern.Length()) == 0) {
|
||||||
// Copy result
|
// Copy result
|
||||||
line.CopyInto(result, pattern.Length(), line.Length() - pattern.Length()).Trim();
|
line.CopyInto(result, pattern.Length(),
|
||||||
|
line.Length() - pattern.Length()).Trim();
|
||||||
// If result is quoted, remove quotes
|
// If result is quoted, remove quotes
|
||||||
if (result[0] == '"') {
|
if (result[0] == '"') {
|
||||||
result.Truncate(result.Length() -1);
|
result.Truncate(result.Length() -1);
|
||||||
result.Remove(0,1);
|
result.Remove(0, 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,35 @@
|
|||||||
#ifndef PPDPARSER_H
|
#ifndef PPDPARSER_H
|
||||||
#define PPDPARSER_H
|
#define PPDPARSER_H
|
||||||
|
|
||||||
|
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
class BPath;
|
class BPath;
|
||||||
class BFile;
|
class BFile;
|
||||||
class BDirectory;
|
class BDirectory;
|
||||||
|
|
||||||
|
|
||||||
class PPDParser
|
class PPDParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PPDParser(const BDirectory& dir, const char *fname);
|
PPDParser(const BDirectory& dir, const char* fname);
|
||||||
PPDParser(const BPath& path);
|
PPDParser(const BPath& path);
|
||||||
PPDParser(BFile& file);
|
PPDParser(BFile& file);
|
||||||
~PPDParser();
|
~PPDParser();
|
||||||
|
|
||||||
status_t InitCheck() const
|
status_t InitCheck() const
|
||||||
{
|
{
|
||||||
return fInitErr;
|
return fInitErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BString GetParameter(const BString& param);
|
||||||
|
|
||||||
BString GetParameter(const BString& param);
|
|
||||||
private:
|
private:
|
||||||
status_t InitData(BFile& file);
|
status_t InitData(BFile& file);
|
||||||
|
|
||||||
BString fContent;
|
BString fContent;
|
||||||
status_t fInitErr;
|
status_t fInitErr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PPDPARSER_H */
|
#endif // PPDPARSER_H
|
||||||
|
|||||||
@@ -5,26 +5,29 @@
|
|||||||
* Copyright 2010 Ithamar Adema.
|
* Copyright 2010 Ithamar Adema.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "PS.h"
|
||||||
|
|
||||||
|
#include <memory.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <memory>
|
|
||||||
#include <stdio.h>
|
#include "DbgMsg.h"
|
||||||
#include <stdlib.h>
|
#include "FilterIO.h"
|
||||||
#include "PS.h"
|
#include "Halftone.h"
|
||||||
#include "UIDriver.h"
|
|
||||||
#include "JobData.h"
|
#include "JobData.h"
|
||||||
|
#include "PackBits.h"
|
||||||
|
#include "PPDParser.h"
|
||||||
#include "PrinterData.h"
|
#include "PrinterData.h"
|
||||||
#include "PSCap.h"
|
#include "PSCap.h"
|
||||||
#include "PackBits.h"
|
|
||||||
#include "Halftone.h"
|
|
||||||
#include "ValidRect.h"
|
|
||||||
#include "DbgMsg.h"
|
|
||||||
#include "PSData.h"
|
#include "PSData.h"
|
||||||
#include "FilterIO.h"
|
#include "UIDriver.h"
|
||||||
#include "PPDParser.h"
|
#include "ValidRect.h"
|
||||||
|
|
||||||
|
|
||||||
#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE))
|
#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE))
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -33,8 +36,10 @@ using namespace std;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
PSDriver::PSDriver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap)
|
PSDriver::PSDriver(BMessage* msg, PrinterData* printer_data,
|
||||||
: GraphicsDriver(msg, printer_data, printer_cap)
|
const PrinterCap* printer_cap)
|
||||||
|
:
|
||||||
|
GraphicsDriver(msg, printer_data, printer_cap)
|
||||||
{
|
{
|
||||||
fPrintedPages = 0;
|
fPrintedPages = 0;
|
||||||
fHalftone = NULL;
|
fHalftone = NULL;
|
||||||
@@ -45,7 +50,7 @@ PSDriver::PSDriver(BMessage *msg, PrinterData *printer_data, const PrinterCap *p
|
|||||||
void
|
void
|
||||||
PSDriver::StartFilterIfNeeded()
|
PSDriver::StartFilterIfNeeded()
|
||||||
{
|
{
|
||||||
const PSData *data = dynamic_cast<const PSData*>(getPrinterData());
|
const PSData* data = dynamic_cast<const PSData*>(getPrinterData());
|
||||||
PPDParser parser(BPath(data->fPPD.String()));
|
PPDParser parser(BPath(data->fPPD.String()));
|
||||||
if (parser.InitCheck() == B_OK) {
|
if (parser.InitCheck() == B_OK) {
|
||||||
BString param = parser.GetParameter("FoomaticRIPCommandLine");
|
BString param = parser.GetParameter("FoomaticRIPCommandLine");
|
||||||
@@ -73,14 +78,14 @@ PSDriver::FlushFilterIfNeeded()
|
|||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
while ((len = fFilterIO->Read(buffer,sizeof(buffer))) > 0)
|
while ((len = fFilterIO->Read(buffer, sizeof(buffer))) > 0)
|
||||||
writeSpoolData(buffer, len);
|
writeSpoolData(buffer, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PSDriver::writePSString(const char *format, ...)
|
PSDriver::writePSString(const char* format, ...)
|
||||||
{
|
{
|
||||||
char str[256];
|
char str[256];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@@ -97,12 +102,12 @@ PSDriver::writePSString(const char *format, ...)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PSDriver::writePSData(const void *data, size_t size)
|
PSDriver::writePSData(const void* data, size_t size)
|
||||||
{
|
{
|
||||||
if (fFilterIO)
|
if (fFilterIO)
|
||||||
fFilterIO->Write(data, size);
|
fFilterIO->Write(data, size);
|
||||||
else
|
else
|
||||||
writeSpoolData(data,size);
|
writeSpoolData(data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -113,10 +118,12 @@ PSDriver::startDoc()
|
|||||||
StartFilterIfNeeded();
|
StartFilterIfNeeded();
|
||||||
|
|
||||||
jobStart();
|
jobStart();
|
||||||
fHalftone = new Halftone(getJobData()->getSurfaceType(), getJobData()->getGamma(), getJobData()->getInkDensity(), getJobData()->getDitherType());
|
fHalftone = new Halftone(getJobData()->getSurfaceType(),
|
||||||
|
getJobData()->getGamma(), getJobData()->getInkDensity(),
|
||||||
|
getJobData()->getDitherType());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (TransportException &err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,7 +152,7 @@ PSDriver::endPage(int)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (TransportException &err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,7 +166,8 @@ PSDriver::setupCTM()
|
|||||||
if (getJobData()->getOrientation() == JobData::kPortrait) {
|
if (getJobData()->getOrientation() == JobData::kPortrait) {
|
||||||
// move origin from bottom left to top left
|
// move origin from bottom left to top left
|
||||||
// and set margin
|
// and set margin
|
||||||
writePSString("%f %f translate\n", leftMargin, getJobData()->getPaperRect().Height()-topMargin);
|
writePSString("%f %f translate\n", leftMargin,
|
||||||
|
getJobData()->getPaperRect().Height()-topMargin);
|
||||||
} else {
|
} else {
|
||||||
// landscape:
|
// landscape:
|
||||||
// move origin from bottom left to margin top and left
|
// move origin from bottom left to margin top and left
|
||||||
@@ -169,7 +177,8 @@ PSDriver::setupCTM()
|
|||||||
}
|
}
|
||||||
// y values increase from top to bottom
|
// y values increase from top to bottom
|
||||||
// units of measure is dpi
|
// units of measure is dpi
|
||||||
writePSString("72 %d div 72 -%d div scale\n", getJobData()->getXres(), getJobData()->getYres());
|
writePSString("72 %d div 72 -%d div scale\n", getJobData()->getXres(),
|
||||||
|
getJobData()->getYres());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -183,7 +192,7 @@ PSDriver::endDoc(bool)
|
|||||||
jobEnd();
|
jobEnd();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (TransportException &err) {
|
catch (TransportException& err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,13 +201,13 @@ PSDriver::endDoc(bool)
|
|||||||
inline uchar
|
inline uchar
|
||||||
hex_digit(uchar value)
|
hex_digit(uchar value)
|
||||||
{
|
{
|
||||||
if (value <= 9) return '0'+value;
|
if (value <= 9) return '0' + value;
|
||||||
else return 'a'+(value-10);
|
else return 'a' + (value - 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PSDriver::nextBand(BBitmap *bitmap, BPoint *offset)
|
PSDriver::nextBand(BBitmap* bitmap, BPoint* offset)
|
||||||
{
|
{
|
||||||
DBGMSG(("> nextBand\n"));
|
DBGMSG(("> nextBand\n"));
|
||||||
|
|
||||||
@@ -206,9 +215,9 @@ PSDriver::nextBand(BBitmap *bitmap, BPoint *offset)
|
|||||||
BRect bounds = bitmap->Bounds();
|
BRect bounds = bitmap->Bounds();
|
||||||
|
|
||||||
RECT rc;
|
RECT rc;
|
||||||
rc.left = (int)bounds.left;
|
rc.left = (int)bounds.left;
|
||||||
rc.top = (int)bounds.top;
|
rc.top = (int)bounds.top;
|
||||||
rc.right = (int)bounds.right;
|
rc.right = (int)bounds.right;
|
||||||
rc.bottom = (int)bounds.bottom;
|
rc.bottom = (int)bounds.bottom;
|
||||||
|
|
||||||
int height = rc.bottom - rc.top + 1;
|
int height = rc.bottom - rc.top + 1;
|
||||||
@@ -238,36 +247,40 @@ PSDriver::nextBand(BBitmap *bitmap, BPoint *offset)
|
|||||||
|
|
||||||
bool color = getJobData()->getColor() == JobData::kColor;
|
bool color = getJobData()->getColor() == JobData::kColor;
|
||||||
int width = rc.right - rc.left + 1;
|
int width = rc.right - rc.left + 1;
|
||||||
int widthByte = (width + 7) / 8; /* byte boundary */
|
int widthByte = (width + 7) / 8;
|
||||||
int height = rc.bottom - rc.top + 1;
|
// byte boundary
|
||||||
int in_size = color ? width : widthByte;
|
int height = rc.bottom - rc.top + 1;
|
||||||
int out_size = color ? width * 6: widthByte * 2;
|
int in_size = color ? width : widthByte;
|
||||||
int delta = bitmap->BytesPerRow();
|
int out_size = color ? width * 6: widthByte * 2;
|
||||||
|
int delta = bitmap->BytesPerRow();
|
||||||
|
|
||||||
DBGMSG(("width = %d\n", width));
|
DBGMSG(("width = %d\n", width));
|
||||||
DBGMSG(("widthByte = %d\n", widthByte));
|
DBGMSG(("widthByte = %d\n", widthByte));
|
||||||
DBGMSG(("height = %d\n", height));
|
DBGMSG(("height = %d\n", height));
|
||||||
DBGMSG(("out_size = %d\n", out_size));
|
DBGMSG(("out_size = %d\n", out_size));
|
||||||
DBGMSG(("delta = %d\n", delta));
|
DBGMSG(("delta = %d\n", delta));
|
||||||
DBGMSG(("renderobj->get_pixel_depth() = %d\n", fHalftone->getPixelDepth()));
|
DBGMSG(("renderobj->get_pixel_depth() = %d\n",
|
||||||
|
fHalftone->getPixelDepth()));
|
||||||
|
|
||||||
uchar *ptr = (uchar *)bitmap->Bits()
|
uchar* ptr = static_cast<uchar*>(bitmap->Bits())
|
||||||
+ rc.top * delta
|
+ rc.top * delta
|
||||||
+ (rc.left * fHalftone->getPixelDepth()) / 8;
|
+ (rc.left * fHalftone->getPixelDepth()) / 8;
|
||||||
|
|
||||||
int compression_method;
|
int compression_method;
|
||||||
int compressed_size;
|
int compressed_size;
|
||||||
const uchar *buffer;
|
const uchar* buffer;
|
||||||
|
|
||||||
uchar *in_buffer = new uchar[in_size]; // gray values
|
uchar* in_buffer = new uchar[in_size];
|
||||||
uchar *out_buffer = new uchar[out_size]; // gray values in hexadecimal
|
// gray values
|
||||||
|
uchar* out_buffer = new uchar[out_size];
|
||||||
|
// gray values in hexadecimal
|
||||||
|
|
||||||
auto_ptr<uchar> _in_buffer(in_buffer);
|
auto_ptr<uchar> _in_buffer(in_buffer);
|
||||||
auto_ptr<uchar> _out_buffer(out_buffer);
|
auto_ptr<uchar> _out_buffer(out_buffer);
|
||||||
|
|
||||||
DBGMSG(("move\n"));
|
DBGMSG(("move\n"));
|
||||||
|
|
||||||
int size = color ? width*3 : in_size;
|
int size = color ? width * 3 : in_size;
|
||||||
startRasterGraphics(x, y, width, height, size);
|
startRasterGraphics(x, y, width, height, size);
|
||||||
|
|
||||||
for (int i = rc.top; i <= rc.bottom; i++) {
|
for (int i = rc.top; i <= rc.bottom; i++) {
|
||||||
@@ -313,23 +326,20 @@ PSDriver::nextBand(BBitmap *bitmap, BPoint *offset)
|
|||||||
|
|
||||||
endRasterGraphics();
|
endRasterGraphics();
|
||||||
|
|
||||||
} else {
|
} else
|
||||||
DBGMSG(("band bitmap is clean.\n"));
|
DBGMSG(("band bitmap is clean.\n"));
|
||||||
}
|
|
||||||
|
|
||||||
if (y >= page_height) {
|
if (y >= page_height) {
|
||||||
offset->x = -1.0;
|
offset->x = -1.0;
|
||||||
offset->y = -1.0;
|
offset->y = -1.0;
|
||||||
} else {
|
} else
|
||||||
offset->y += height;
|
offset->y += height;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DBGMSG(("< nextBand\n"));
|
DBGMSG(("< nextBand\n"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (TransportException &err) {
|
catch (TransportException& err) {
|
||||||
BAlert *alert = new BAlert("", err.what(), "OK");
|
BAlert* alert = new BAlert("", err.what(), "OK");
|
||||||
alert->Go();
|
alert->Go();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -342,10 +352,15 @@ PSDriver::jobStart()
|
|||||||
// PostScript header
|
// PostScript header
|
||||||
writePSString("%%!PS-Adobe-3.0\n");
|
writePSString("%%!PS-Adobe-3.0\n");
|
||||||
writePSString("%%%%LanguageLevel: 1\n");
|
writePSString("%%%%LanguageLevel: 1\n");
|
||||||
writePSString("%%%%Title: %s\n", getSpoolMetaData()->getDescription().c_str());
|
writePSString("%%%%Title: %s\n",
|
||||||
writePSString("%%%%Creator: %s\n", getSpoolMetaData()->getMimeType().c_str());
|
getSpoolMetaData()->getDescription().c_str());
|
||||||
writePSString("%%%%CreationDate: %s", getSpoolMetaData()->getCreationTime().c_str());
|
writePSString("%%%%Creator: %s\n",
|
||||||
writePSString("%%%%DocumentMedia: Plain %d %d white 0 ( )\n", getJobData()->getPaperRect().IntegerWidth(), getJobData()->getPaperRect().IntegerHeight());
|
getSpoolMetaData()->getMimeType().c_str());
|
||||||
|
writePSString("%%%%CreationDate: %s",
|
||||||
|
getSpoolMetaData()->getCreationTime().c_str());
|
||||||
|
writePSString("%%%%DocumentMedia: Plain %d %d white 0 ( )\n",
|
||||||
|
getJobData()->getPaperRect().IntegerWidth(),
|
||||||
|
getJobData()->getPaperRect().IntegerHeight());
|
||||||
writePSString("%%%%Pages: (atend)\n");
|
writePSString("%%%%Pages: (atend)\n");
|
||||||
writePSString("%%%%EndComments\n");
|
writePSString("%%%%EndComments\n");
|
||||||
|
|
||||||
@@ -356,7 +371,8 @@ PSDriver::jobStart()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PSDriver::startRasterGraphics(int x, int y, int width, int height, int widthByte)
|
PSDriver::startRasterGraphics(int x, int y, int width, int height,
|
||||||
|
int widthByte)
|
||||||
{
|
{
|
||||||
bool color = getJobData()->getColor() == JobData::kColor;
|
bool color = getJobData()->getColor() == JobData::kColor;
|
||||||
fCompressionMethod = -1;
|
fCompressionMethod = -1;
|
||||||
@@ -364,19 +380,17 @@ PSDriver::startRasterGraphics(int x, int y, int width, int height, int widthByte
|
|||||||
writePSString("/s %d string def\n", widthByte);
|
writePSString("/s %d string def\n", widthByte);
|
||||||
writePSString("%d %d translate\n", x, y);
|
writePSString("%d %d translate\n", x, y);
|
||||||
writePSString("%d %d scale\n", width, height);
|
writePSString("%d %d scale\n", width, height);
|
||||||
if (color) {
|
if (color)
|
||||||
writePSString("%d %d 8\n", width, height); // 8 bpp
|
writePSString("%d %d 8\n", width, height); // 8 bpp
|
||||||
} else {
|
else
|
||||||
writePSString("%d %d 1\n", width, height); // 1 bpp
|
writePSString("%d %d 1\n", width, height); // 1 bpp
|
||||||
}
|
|
||||||
writePSString("[%d 0 0 %d 0 0]\n", width, height);
|
writePSString("[%d 0 0 %d 0 0]\n", width, height);
|
||||||
writePSString("{ currentfile s readhexstring pop }\n");
|
writePSString("{ currentfile s readhexstring pop }\n");
|
||||||
if (color) {
|
if (color) {
|
||||||
writePSString("false 3\n"); // single data source, 3 color components
|
writePSString("false 3\n"); // single data source, 3 color components
|
||||||
writePSString("colorimage\n");
|
writePSString("colorimage\n");
|
||||||
} else {
|
} else
|
||||||
writePSString("image\n\n");
|
writePSString("image\n\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -390,7 +404,7 @@ PSDriver::endRasterGraphics()
|
|||||||
void
|
void
|
||||||
PSDriver::rasterGraphics(
|
PSDriver::rasterGraphics(
|
||||||
int compression_method,
|
int compression_method,
|
||||||
const uchar *buffer,
|
const uchar* buffer,
|
||||||
int size)
|
int size)
|
||||||
{
|
{
|
||||||
if (fCompressionMethod != compression_method) {
|
if (fCompressionMethod != compression_method) {
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
* PS.h
|
* PS.h
|
||||||
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
|
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __PS_H
|
#ifndef __PS_H
|
||||||
#define __PS_H
|
#define __PS_H
|
||||||
|
|
||||||
|
|
||||||
#include "GraphicsDriver.h"
|
#include "GraphicsDriver.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -15,35 +15,35 @@ class Halftone;
|
|||||||
|
|
||||||
class PSDriver : public GraphicsDriver {
|
class PSDriver : public GraphicsDriver {
|
||||||
public:
|
public:
|
||||||
PSDriver(BMessage *msg, PrinterData *printer_data, const PrinterCap *printer_cap);
|
PSDriver(BMessage* msg, PrinterData* printer_data,
|
||||||
|
const PrinterCap* printer_cap);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool startDoc();
|
virtual bool startDoc();
|
||||||
virtual bool startPage(int page);
|
virtual bool startPage(int page);
|
||||||
virtual bool nextBand(BBitmap *bitmap, BPoint *offset);
|
virtual bool nextBand(BBitmap* bitmap, BPoint* offset);
|
||||||
virtual bool endPage(int page);
|
virtual bool endPage(int page);
|
||||||
virtual bool endDoc(bool success);
|
virtual bool endDoc(bool success);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupCTM();
|
void setupCTM();
|
||||||
void jobStart();
|
void jobStart();
|
||||||
void startRasterGraphics(int x, int y, int width, int height, int widthByte);
|
void startRasterGraphics(int x, int y, int width,
|
||||||
void endRasterGraphics();
|
int height, int widthByte);
|
||||||
void rasterGraphics(
|
void endRasterGraphics();
|
||||||
int compression_method,
|
void rasterGraphics(int compression_method,
|
||||||
const uchar *buffer,
|
const uchar* buffer, int size);
|
||||||
int size);
|
void jobEnd();
|
||||||
void jobEnd();
|
|
||||||
|
|
||||||
void StartFilterIfNeeded();
|
void StartFilterIfNeeded();
|
||||||
void FlushFilterIfNeeded();
|
void FlushFilterIfNeeded();
|
||||||
void writePSString(const char *format, ...);
|
void writePSString(const char* format, ...);
|
||||||
void writePSData(const void *data, size_t size);
|
void writePSData(const void* data, size_t size);
|
||||||
|
|
||||||
int fPrintedPages;
|
int fPrintedPages;
|
||||||
int fCompressionMethod;
|
int fCompressionMethod;
|
||||||
Halftone *fHalftone;
|
Halftone* fHalftone;
|
||||||
FilterIO *fFilterIO;
|
FilterIO* fFilterIO;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __PS_H */
|
#endif // __PS_H
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
|
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PrinterData.h"
|
|
||||||
#include "PSCap.h"
|
#include "PSCap.h"
|
||||||
|
|
||||||
|
#include "PrinterData.h"
|
||||||
|
|
||||||
#define TO72DPI(a) (a * 72.0f / 600.0f)
|
#define TO72DPI(a) (a * 72.0f / 600.0f)
|
||||||
|
|
||||||
const PaperCap a3(
|
const PaperCap a3(
|
||||||
@@ -66,11 +68,11 @@ const PaperCap legal(
|
|||||||
|
|
||||||
const PaperSourceCap autobin("Auto", true, JobData::kAuto);
|
const PaperSourceCap autobin("Auto", true, JobData::kAuto);
|
||||||
|
|
||||||
const ResolutionCap dpi300("300dpi", true, 300, 300);
|
const ResolutionCap dpi300("300dpi", true, 300, 300);
|
||||||
const ResolutionCap dpi600("600dpi", false, 600, 600);
|
const ResolutionCap dpi600("600dpi", false, 600, 600);
|
||||||
const ResolutionCap dpi1200("1200dpi", false, 1200, 1200);
|
const ResolutionCap dpi1200("1200dpi", false, 1200, 1200);
|
||||||
|
|
||||||
const PaperCap *papers[] = {
|
const PaperCap* papers[] = {
|
||||||
&a4,
|
&a4,
|
||||||
&a3,
|
&a3,
|
||||||
&a5,
|
&a5,
|
||||||
@@ -80,11 +82,11 @@ const PaperCap *papers[] = {
|
|||||||
&legal
|
&legal
|
||||||
};
|
};
|
||||||
|
|
||||||
const PaperSourceCap *papersources[] = {
|
const PaperSourceCap* papersources[] = {
|
||||||
&autobin,
|
&autobin,
|
||||||
};
|
};
|
||||||
|
|
||||||
const ResolutionCap *resolutions[] = {
|
const ResolutionCap* resolutions[] = {
|
||||||
&dpi300,
|
&dpi300,
|
||||||
&dpi600,
|
&dpi600,
|
||||||
&dpi1200,
|
&dpi1200,
|
||||||
@@ -93,57 +95,64 @@ const ResolutionCap *resolutions[] = {
|
|||||||
const ColorCap color("Color", false, JobData::kColor);
|
const ColorCap color("Color", false, JobData::kColor);
|
||||||
const ColorCap monochrome("Monochrome", true, JobData::kMonochrome);
|
const ColorCap monochrome("Monochrome", true, JobData::kMonochrome);
|
||||||
|
|
||||||
const ColorCap *colors[] = {
|
const ColorCap* colors[] = {
|
||||||
&color,
|
&color,
|
||||||
&monochrome
|
&monochrome
|
||||||
};
|
};
|
||||||
|
|
||||||
PSCap::PSCap(const PrinterData *printer_data)
|
PSCap::PSCap(const PrinterData* printer_data)
|
||||||
: PrinterCap(printer_data)
|
:
|
||||||
|
PrinterCap(printer_data)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int PSCap::countCap(CapID capid) const
|
|
||||||
|
int
|
||||||
|
PSCap::countCap(CapID capid) const
|
||||||
{
|
{
|
||||||
switch (capid) {
|
switch (capid) {
|
||||||
case kPaper:
|
case kPaper:
|
||||||
return sizeof(papers) / sizeof(papers[0]);
|
return sizeof(papers) / sizeof(papers[0]);
|
||||||
case kPaperSource:
|
case kPaperSource:
|
||||||
return sizeof(papersources) / sizeof(papersources[0]);
|
return sizeof(papersources) / sizeof(papersources[0]);
|
||||||
case kResolution:
|
case kResolution:
|
||||||
return sizeof(resolutions) / sizeof(resolutions[0]);
|
return sizeof(resolutions) / sizeof(resolutions[0]);
|
||||||
case kColor:
|
case kColor:
|
||||||
return sizeof(colors) / sizeof(colors[0]);
|
return sizeof(colors) / sizeof(colors[0]);
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const BaseCap **PSCap::enumCap(CapID capid) const
|
|
||||||
|
const BaseCap**
|
||||||
|
PSCap::enumCap(CapID capid) const
|
||||||
{
|
{
|
||||||
switch (capid) {
|
switch (capid) {
|
||||||
case kPaper:
|
case kPaper:
|
||||||
return (const BaseCap **)papers;
|
return (const BaseCap **)papers;
|
||||||
case kPaperSource:
|
case kPaperSource:
|
||||||
return (const BaseCap **)papersources;
|
return (const BaseCap **)papersources;
|
||||||
case kResolution:
|
case kResolution:
|
||||||
return (const BaseCap **)resolutions;
|
return (const BaseCap **)resolutions;
|
||||||
case kColor:
|
case kColor:
|
||||||
return (const BaseCap **)colors;
|
return (const BaseCap **)colors;
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PSCap::isSupport(CapID capid) const
|
|
||||||
|
bool
|
||||||
|
PSCap::isSupport(CapID capid) const
|
||||||
{
|
{
|
||||||
switch (capid) {
|
switch (capid) {
|
||||||
case kPaper:
|
case kPaper:
|
||||||
case kPaperSource:
|
case kPaperSource:
|
||||||
case kResolution:
|
case kResolution:
|
||||||
case kColor:
|
case kColor:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,19 @@
|
|||||||
* PSCap.h
|
* PSCap.h
|
||||||
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
|
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __PSCAP_H
|
#ifndef __PSCAP_H
|
||||||
#define __PSCAP_H
|
#define __PSCAP_H
|
||||||
|
|
||||||
|
|
||||||
#include "PrinterCap.h"
|
#include "PrinterCap.h"
|
||||||
|
|
||||||
|
|
||||||
class PSCap : public PrinterCap {
|
class PSCap : public PrinterCap {
|
||||||
public:
|
public:
|
||||||
PSCap(const PrinterData *printer_data);
|
PSCap(const PrinterData* printer_data);
|
||||||
virtual int countCap(CapID) const;
|
virtual int countCap(CapID) const;
|
||||||
virtual bool isSupport(CapID) const;
|
virtual bool isSupport(CapID) const;
|
||||||
virtual const BaseCap **enumCap(CapID) const;
|
virtual const BaseCap **enumCap(CapID) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __PSCAP_H */
|
#endif // __PSCAP_H
|
||||||
|
|||||||
@@ -6,12 +6,14 @@
|
|||||||
* Ithamar R. Adema <[email protected]>
|
* Ithamar R. Adema <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "PSData.h"
|
#include "PSData.h"
|
||||||
|
|
||||||
#include <Node.h>
|
#include <Node.h>
|
||||||
|
|
||||||
#define PD_PPD_PATH "ps:ppd_path"
|
#define PD_PPD_PATH "ps:ppd_path"
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PSData::load()
|
PSData::load()
|
||||||
{
|
{
|
||||||
@@ -19,6 +21,7 @@ PSData::load()
|
|||||||
fNode->ReadAttrString(PD_PPD_PATH, &fPPD);
|
fNode->ReadAttrString(PD_PPD_PATH, &fPPD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PSData::save()
|
PSData::save()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,11 +5,12 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Ithamar R. Adema <[email protected]>
|
* Ithamar R. Adema <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PSDATA_H
|
#ifndef PSDATA_H
|
||||||
#define PSDATA_H
|
#define PSDATA_H
|
||||||
|
|
||||||
|
|
||||||
#include "PrinterData.h"
|
#include "PrinterData.h"
|
||||||
|
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -18,14 +19,17 @@ class BNode;
|
|||||||
|
|
||||||
class PSData : public PrinterData {
|
class PSData : public PrinterData {
|
||||||
public:
|
public:
|
||||||
PSData(BNode *node) : PrinterData(node) {}
|
PSData(BNode* node)
|
||||||
|
:
|
||||||
|
PrinterData(node)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// PrinterData overrides
|
// PrinterData overrides
|
||||||
virtual void load();
|
virtual void load();
|
||||||
virtual void save();
|
virtual void save();
|
||||||
|
|
||||||
BString fPPD;
|
BString fPPD;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // PSDATA_H
|
||||||
#endif /* PSDATA_H */
|
|
||||||
|
|||||||
@@ -5,72 +5,80 @@
|
|||||||
* Copyright 2010 Ithamar Adema.
|
* Copyright 2010 Ithamar Adema.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PS.h"
|
|
||||||
#include "PSCap.h"
|
|
||||||
#include "PSData.h"
|
|
||||||
#include "PrinterDriver.h"
|
|
||||||
#include "SelectPPDDlg.h"
|
|
||||||
|
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
|
||||||
|
#include "PrinterDriver.h"
|
||||||
|
#include "PS.h"
|
||||||
|
#include "PSCap.h"
|
||||||
|
#include "PSData.h"
|
||||||
|
#include "SelectPPDDlg.h"
|
||||||
|
|
||||||
|
|
||||||
class PSPrinterDriver : public PrinterDriver {
|
class PSPrinterDriver : public PrinterDriver {
|
||||||
public:
|
public:
|
||||||
PSPrinterDriver(BNode *printerFolder) : PrinterDriver(printerFolder) {}
|
PSPrinterDriver(BNode* printerFolder)
|
||||||
|
:
|
||||||
const char *GetSignature() const
|
PrinterDriver(printerFolder)
|
||||||
{
|
{
|
||||||
return "application/x-vnd.PS-compatible";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *GetDriverName() const
|
const char* GetSignature() const
|
||||||
{
|
{
|
||||||
return "PS compatible";
|
return "application/x-vnd.PS-compatible";
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *GetVersion() const
|
const char* GetDriverName() const
|
||||||
{
|
{
|
||||||
return "0.1";
|
return "PS compatible";
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *GetCopyright() const
|
const char* GetVersion() const
|
||||||
{
|
{
|
||||||
return "PS driver Copyright © 2003,04 Michael Pfeiffer.\n";
|
return "0.1";
|
||||||
}
|
}
|
||||||
|
|
||||||
char *AddPrinter(char *printerName)
|
const char* GetCopyright() const
|
||||||
{
|
{
|
||||||
BPath path;
|
return "PS driver Copyright © 2003,04 Michael Pfeiffer.\n";
|
||||||
if (find_directory(B_SYSTEM_DATA_DIRECTORY, &path) == B_OK
|
}
|
||||||
&& path.Append("ppd") == B_OK
|
|
||||||
&& BEntry(path.Path()).Exists()) {
|
|
||||||
SelectPPDDlg *dialog = new SelectPPDDlg(dynamic_cast<PSData*>(GetPrinterData()));
|
|
||||||
if (dialog->Go() != B_OK)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return printerName;
|
char* AddPrinter(char *printerName)
|
||||||
}
|
{
|
||||||
|
BPath path;
|
||||||
|
if (find_directory(B_SYSTEM_DATA_DIRECTORY, &path) == B_OK
|
||||||
|
&& path.Append("ppd") == B_OK
|
||||||
|
&& BEntry(path.Path()).Exists()) {
|
||||||
|
SelectPPDDlg* dialog =
|
||||||
|
new SelectPPDDlg(dynamic_cast<PSData*>
|
||||||
|
(GetPrinterData()));
|
||||||
|
if (dialog->Go() != B_OK)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return printerName;
|
||||||
|
}
|
||||||
|
|
||||||
PrinterData *InstantiatePrinterData(BNode *node)
|
PrinterData* InstantiatePrinterData(BNode* node)
|
||||||
{
|
{
|
||||||
return new PSData(node);
|
return new PSData(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
PrinterCap *InstantiatePrinterCap(PrinterData *printerData)
|
PrinterCap* InstantiatePrinterCap(PrinterData* printerData)
|
||||||
{
|
{
|
||||||
return new PSCap(printerData);
|
return new PSCap(printerData);
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsDriver *InstantiateGraphicsDriver(BMessage *settings, PrinterData *printerData, PrinterCap *printerCap)
|
GraphicsDriver* InstantiateGraphicsDriver(BMessage* settings,
|
||||||
{
|
PrinterData* printerData, PrinterCap* printerCap)
|
||||||
return new PSDriver(settings, printerData, printerCap);
|
{
|
||||||
}
|
return new PSDriver(settings, printerData, printerCap);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
PrinterDriver *
|
PrinterDriver *
|
||||||
instantiate_printer_driver(BNode *printerFolder)
|
instantiate_printer_driver(BNode* printerFolder)
|
||||||
{
|
{
|
||||||
return new PSPrinterDriver(printerFolder);
|
return new PSPrinterDriver(printerFolder);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,23 +6,24 @@
|
|||||||
* Ithamar R. Adema <ithamar.adema@team-embedded.nl>
|
* Ithamar R. Adema <ithamar.adema@team-embedded.nl>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "SelectPPDDlg.h"
|
#include "SelectPPDDlg.h"
|
||||||
#include "PPDParser.h"
|
|
||||||
|
|
||||||
#include <GroupLayout.h>
|
#include <GroupLayout.h>
|
||||||
#include <GroupLayoutBuilder.h>
|
#include <GroupLayoutBuilder.h>
|
||||||
|
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Message.h>
|
|
||||||
#include <ListView.h>
|
|
||||||
#include <ScrollView.h>
|
|
||||||
#include <ScrollBar.h>
|
|
||||||
#include <StringItem.h>
|
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <String.h>
|
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
|
#include <ListView.h>
|
||||||
|
#include <Message.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
#include <ScrollBar.h>
|
||||||
|
#include <ScrollView.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <StringItem.h>
|
||||||
|
|
||||||
|
#include "PPDParser.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
kMsgCancel = 'stop',
|
kMsgCancel = 'stop',
|
||||||
@@ -35,15 +36,18 @@ enum {
|
|||||||
|
|
||||||
class PPDStringItem : public BStringItem {
|
class PPDStringItem : public BStringItem {
|
||||||
public:
|
public:
|
||||||
PPDStringItem(const BString& text, const BString& path)
|
PPDStringItem(const BString& text, const BString& path)
|
||||||
: BStringItem(text.String()),
|
:
|
||||||
fPPDPath(path) {}
|
BStringItem(text.String()),
|
||||||
|
fPPDPath(path)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
BString fPPDPath;
|
BString fPPDPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
SelectPPDDlg::SelectPPDDlg(PSData *data)
|
SelectPPDDlg::SelectPPDDlg(PSData* data)
|
||||||
: DialogWindow(BRect(10, 10, 400, 400),
|
: DialogWindow(BRect(10, 10, 400, 400),
|
||||||
"Select PPD", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
|
"Select PPD", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
|
||||||
B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS),
|
B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS),
|
||||||
@@ -51,7 +55,8 @@ SelectPPDDlg::SelectPPDDlg(PSData *data)
|
|||||||
{
|
{
|
||||||
SetResult(B_ERROR);
|
SetResult(B_ERROR);
|
||||||
|
|
||||||
BButton *ok, *cancel;
|
BButton* ok;
|
||||||
|
BButton* cancel;
|
||||||
|
|
||||||
ok = new BButton("btn:ok", "OK", new BMessage(kMsgOK));
|
ok = new BButton("btn:ok", "OK", new BMessage(kMsgOK));
|
||||||
ok->MakeDefault(true);
|
ok->MakeDefault(true);
|
||||||
@@ -60,11 +65,13 @@ SelectPPDDlg::SelectPPDDlg(PSData *data)
|
|||||||
|
|
||||||
cancel = new BButton("btn:cancel", "Cancel", new BMessage(kMsgCancel));
|
cancel = new BButton("btn:cancel", "Cancel", new BMessage(kMsgCancel));
|
||||||
|
|
||||||
BScrollView *manuScroller, *printerScroller;
|
BScrollView* manuScroller, *printerScroller;
|
||||||
fManufacturersListView = new BListView("olv:manufacturers");
|
fManufacturersListView = new BListView("olv:manufacturers");
|
||||||
manuScroller=new BScrollView("scr:manufacturers", fManufacturersListView, 0, false, true);
|
manuScroller = new BScrollView("scr:manufacturers", fManufacturersListView,
|
||||||
|
0, false, true);
|
||||||
fPrintersListView = new BListView("olv:printers");
|
fPrintersListView = new BListView("olv:printers");
|
||||||
printerScroller=new BScrollView("scr:printers", fPrintersListView, 0, false, true);
|
printerScroller = new BScrollView("scr:printers", fPrintersListView, 0,
|
||||||
|
false, true);
|
||||||
|
|
||||||
fPrintersListView->SetSelectionMessage(new BMessage(kMsgPrinterSelected));
|
fPrintersListView->SetSelectionMessage(new BMessage(kMsgPrinterSelected));
|
||||||
fManufacturersListView->SetSelectionMessage(new BMessage(kMsgManuSelected));
|
fManufacturersListView->SetSelectionMessage(new BMessage(kMsgManuSelected));
|
||||||
@@ -100,13 +107,14 @@ SelectPPDDlg::PopulateManufacturers(directory_which data_dir)
|
|||||||
&& path.Append("ppd") == B_OK
|
&& path.Append("ppd") == B_OK
|
||||||
&& dir.SetTo(path.Path()) == B_OK) {
|
&& dir.SetTo(path.Path()) == B_OK) {
|
||||||
// Got the directory, now scan it
|
// Got the directory, now scan it
|
||||||
while(dir.GetNextEntry(&entry) == B_OK)
|
while (dir.GetNextEntry(&entry) == B_OK)
|
||||||
if (entry.IsDirectory()
|
if (entry.IsDirectory()
|
||||||
&& entry.GetName(name) == B_OK)
|
&& entry.GetName(name) == B_OK)
|
||||||
fManufacturersListView->AddItem(new BStringItem(name));
|
fManufacturersListView->AddItem(new BStringItem(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SelectPPDDlg::PopulatePrinters(directory_which data_dir)
|
SelectPPDDlg::PopulatePrinters(directory_which data_dir)
|
||||||
{
|
{
|
||||||
@@ -128,19 +136,21 @@ SelectPPDDlg::PopulatePrinters(directory_which data_dir)
|
|||||||
&& path.Append(manu) == B_OK
|
&& path.Append(manu) == B_OK
|
||||||
&& dir.SetTo(path.Path()) == B_OK) {
|
&& dir.SetTo(path.Path()) == B_OK) {
|
||||||
// Found manufacturer PPD directory, now fill our printer list
|
// Found manufacturer PPD directory, now fill our printer list
|
||||||
while(dir.GetNextEntry(&entry) == B_OK)
|
while (dir.GetNextEntry(&entry) == B_OK)
|
||||||
if (entry.GetName(name) == B_OK) {
|
if (entry.GetName(name) == B_OK) {
|
||||||
PPDParser parser(dir,name);
|
PPDParser parser(dir, name);
|
||||||
if (parser.InitCheck() == B_OK) {
|
if (parser.InitCheck() == B_OK) {
|
||||||
BString modelName = parser.GetParameter("ModelName");
|
BString modelName = parser.GetParameter("ModelName");
|
||||||
BPath ppdPath = path;
|
BPath ppdPath = path;
|
||||||
ppdPath.Append(name);
|
ppdPath.Append(name);
|
||||||
fPrintersListView->AddItem(new PPDStringItem(modelName, ppdPath.Path()));
|
fPrintersListView->AddItem(new PPDStringItem(modelName,
|
||||||
|
ppdPath.Path()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SelectPPDDlg::PrinterSelected()
|
SelectPPDDlg::PrinterSelected()
|
||||||
{
|
{
|
||||||
@@ -148,6 +158,7 @@ SelectPPDDlg::PrinterSelected()
|
|||||||
fOKButton->SetEnabled(idx >= 0);
|
fOKButton->SetEnabled(idx >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SelectPPDDlg::Save()
|
SelectPPDDlg::Save()
|
||||||
{
|
{
|
||||||
@@ -156,35 +167,35 @@ SelectPPDDlg::Save()
|
|||||||
|
|
||||||
idx = fPrintersListView->CurrentSelection();
|
idx = fPrintersListView->CurrentSelection();
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
ppdPath = dynamic_cast<PPDStringItem*>(fPrintersListView->ItemAt(idx))->fPPDPath;
|
ppdPath = dynamic_cast<PPDStringItem*>
|
||||||
|
(fPrintersListView->ItemAt(idx))->fPPDPath;
|
||||||
|
|
||||||
fPSData->fPPD = ppdPath;
|
fPSData->fPPD = ppdPath;
|
||||||
fPSData->save();
|
fPSData->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SelectPPDDlg::MessageReceived(BMessage *msg)
|
SelectPPDDlg::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case kMsgManuSelected:
|
case kMsgManuSelected:
|
||||||
fPrintersListView->MakeEmpty();
|
fPrintersListView->MakeEmpty();
|
||||||
PopulatePrinters(B_SYSTEM_DATA_DIRECTORY);
|
PopulatePrinters(B_SYSTEM_DATA_DIRECTORY);
|
||||||
break;
|
break;
|
||||||
case kMsgPrinterSelected:
|
case kMsgPrinterSelected:
|
||||||
PrinterSelected();
|
PrinterSelected();
|
||||||
break;
|
break;
|
||||||
case kMsgOK:
|
case kMsgOK:
|
||||||
Save();
|
Save();
|
||||||
SetResult(B_NO_ERROR);
|
SetResult(B_NO_ERROR);
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
break;
|
break;
|
||||||
|
case kMsgCancel:
|
||||||
case kMsgCancel:
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
break;
|
||||||
break;
|
default:
|
||||||
|
DialogWindow::MessageReceived(msg);
|
||||||
default:
|
break;
|
||||||
DialogWindow::MessageReceived(msg);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,33 @@
|
|||||||
#ifndef SELECTPPDDLG_H
|
#ifndef SELECTPPDDLG_H
|
||||||
#define SELECTPPDDLG_H
|
#define SELECTPPDDLG_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <storage/FindDirectory.h>
|
||||||
|
|
||||||
#include "DialogWindow.h"
|
#include "DialogWindow.h"
|
||||||
#include "PSData.h"
|
#include "PSData.h"
|
||||||
|
|
||||||
#include <storage/FindDirectory.h>
|
|
||||||
|
|
||||||
class BListView;
|
class BListView;
|
||||||
class BButton;
|
class BButton;
|
||||||
class PSData;
|
class PSData;
|
||||||
|
|
||||||
|
|
||||||
class SelectPPDDlg : public DialogWindow {
|
class SelectPPDDlg : public DialogWindow {
|
||||||
public:
|
public:
|
||||||
SelectPPDDlg(PSData *data);
|
SelectPPDDlg(PSData* data);
|
||||||
void MessageReceived(BMessage *msg);
|
void MessageReceived(BMessage* msg);
|
||||||
private:
|
private:
|
||||||
void PopulateManufacturers(directory_which data_dir);
|
void PopulateManufacturers(directory_which data_dir);
|
||||||
void PopulatePrinters(directory_which data_dir);
|
void PopulatePrinters(directory_which data_dir);
|
||||||
void PrinterSelected();
|
void PrinterSelected();
|
||||||
void Save();
|
void Save();
|
||||||
|
|
||||||
BListView *fManufacturersListView;
|
BListView* fManufacturersListView;
|
||||||
BListView *fPrintersListView;
|
BListView* fPrintersListView;
|
||||||
BButton *fOKButton;
|
BButton* fOKButton;
|
||||||
|
|
||||||
PSData *fPSData;
|
PSData* fPSData;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SELECTPPDDLG_H */
|
#endif // SELECTPPDDLG_H
|
||||||
|
|||||||
Reference in New Issue
Block a user