/branches/Version13x/Scribus/scribus/printerutil.h |
---|
9,8 → 9,6 |
#include "scribusapi.h" |
#include <qstring.h> |
class QStringList; |
class SCRIBUS_API PrinterUtil |
18,32 → 16,7 |
public: |
PrinterUtil() {}; |
~PrinterUtil() {}; |
QStringList static SCRIBUS_API getPrinterNames(); |
bool static SCRIBUS_API getDefaultSettings( QString printerName ); |
bool static SCRIBUS_API initDeviceSettings( QString printerName ); |
/** |
* @brief Get the 4 minimum page margins for a certain paper size on the given printer |
* |
* @param printerName the printer name |
* @param pageSize the page size to get the margins for |
* @param ptsTopMargin the page's top margin in points |
* @param ptsTopMargin the page's bottom margin in points |
* @param ptsTopMargin the page's left margin in points |
* @param ptsTopMargin the page's right margin in points |
*/ |
bool static SCRIBUS_API getPrinterMarginValues(const QString& printerName, const QString& pageSize, double& ptsTopMargin, double& m_ptsBottomMargin, double& m_ptsLeftMargin, double& m_ptsRightMargin); |
/** |
* @brief Check if a specified printer supports postscript input |
* |
* On Windows, the function test postscript support for a specified printer |
* and return true if ps is supported |
* On non Windows systems, the function always return true |
* |
* @param printerName the printer name |
* @return true is printer support postscript, false otherwise. |
* |
*/ |
bool static SCRIBUS_API isPostscriptPrinter( QString printerName ); |
QStringList getPrinterNames(); |
}; |
#endif // DRUCK_H |
/branches/Version13x/Scribus/scribus/useprintermarginsdialog.cpp |
---|
14,10 → 14,15 |
#include "useprintermarginsdialog.h" |
#include "useprintermarginsdialog.moc" |
#include "scconfig.h" |
#include <qcombobox.h> |
#include <qgroupbox.h> |
#include <qlineedit.h> |
#include <qpushbutton.h> |
#ifdef HAVE_CUPS |
#include <cups/cups.h> |
#endif |
#include "printerutil.h" |
35,14 → 40,15 |
m_pageSize=pageSize; |
m_unitRatio=unitRatio; |
m_suffix=suffix; |
QStringList printerNames=PrinterUtil::getPrinterNames(); |
PrinterUtil pu; |
QStringList printerNames=pu.getPrinterNames(); |
printerComboBox->clear(); |
if (printerNames.count()>0 && !pageSize.isEmpty()) |
{ |
printerComboBox->insertStringList(printerNames); |
getPrinterMarginValues(printerNames.first()); |
getPrinterMarginValuesFromCUPS(printerNames.first()); |
marginsGroupBox->setTitle(tr("Minimum Margins for Page Size %1").arg(pageSize)); |
connect(printerComboBox, SIGNAL(activated(const QString&)), this, SLOT(getPrinterMarginValues(const QString&))); |
connect(printerComboBox, SIGNAL(activated(const QString&)), this, SLOT(getPrinterMarginValuesFromCUPS(const QString&))); |
} |
connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); |
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); |
60,11 → 66,35 |
rightMargin=m_ptsRightMargin; |
} |
void UsePrinterMarginsDialog::getPrinterMarginValues(const QString& printerName) |
void UsePrinterMarginsDialog::getPrinterMarginValuesFromCUPS(const QString& printerName) |
{ |
m_ptsTopMargin=m_ptsBottomMargin=m_ptsLeftMargin=m_ptsRightMargin=0.0; |
bool foundSize=PrinterUtil::getPrinterMarginValues(printerName, m_pageSize, m_ptsTopMargin, m_ptsBottomMargin, m_ptsLeftMargin, m_ptsRightMargin); |
#if defined(HAVE_CUPS) |
const char *filename; /* tmp PPD filename */ |
filename=cupsGetPPD(printerName); |
bool foundSize=false; |
if (filename!=NULL) |
{ |
ppd_file_t *ppd; /* PPD data */ |
ppd = ppdOpenFile(filename); |
if (ppd!=NULL) |
{ |
ppd_size_t *size; /* page size data, null if printer doesnt support selected size */ |
size = ppdPageSize(ppd, m_pageSize); |
if (size!=NULL) |
{ |
//Store in pts for returning via getNewPrinterMargins in pts |
foundSize=true; |
m_ptsTopMargin=size->length-size->top; |
m_ptsBottomMargin=size->bottom; |
m_ptsLeftMargin=size->left; |
m_ptsRightMargin=size->width-size->right; |
} |
ppdClose(ppd); |
} |
} |
#endif |
topLineEdit->setEnabled(foundSize); |
bottomLineEdit->setEnabled(foundSize); |
leftLineEdit->setEnabled(foundSize); |
/branches/Version13x/Scribus/scribus/useprintermarginsdialog.h |
---|
34,7 → 34,7 |
*/ |
void getNewPrinterMargins(double &topMargin,double &bottomMargin,double &leftMargin,double &rightMargin); |
protected slots: |
void getPrinterMarginValues(const QString& printerName); |
void getPrinterMarginValuesFromCUPS(const QString& printerName); |
protected: |
QString m_pageSize; |
/branches/Version13x/Scribus/scribus/printerutil.cpp |
---|
5,7 → 5,6 |
for which a new license (GPL+exception) is in place. |
*/ |
#include "printerutil.h" |
#include "scconfig.h" |
#if defined( HAVE_CUPS ) |
#include <cups/cups.h> |
15,6 → 14,7 |
#endif |
#include <qstringlist.h> |
#include "util.h" |
QStringList PrinterUtil::getPrinterNames() |
71,149 → 71,3 |
#endif |
return printerNames; |
} |
bool PrinterUtil::getDefaultSettings( QString printerName ) |
{ |
#ifdef _WIN32 |
bool done; |
uint size; |
QCString printer; |
LONG result = IDOK+1; |
HANDLE handle = NULL; |
printer = printerName.local8Bit(); |
// Get the printer handle |
done = OpenPrinter( printer.data(), &handle, NULL ); |
if(!done) |
return false; |
// Get size of DEVMODE structure (public + private data) |
size = DocumentProperties( winId(), handle, printer.data(), NULL, NULL, 0); |
// Allocate the memory needed by the DEVMODE structure |
DevMode.resize( size ); |
// Retrieve printer default settings |
result = DocumentProperties( winId(), handle, printer.data(), (DEVMODE*) DevMode.data(), NULL, DM_OUT_BUFFER); |
// Free the printer handle |
ClosePrinter( handle ); |
return ( result == IDOK ); |
#else |
return true; |
#endif |
} |
bool PrinterUtil::initDeviceSettings( QString printerName ) |
{ |
#ifdef _WIN32 |
bool done; |
uint size; |
QCString printer; |
LONG result = IDOK+1; |
HANDLE handle = NULL; |
printer = printerName.local8Bit(); |
// Get the printer handle |
done = OpenPrinter( printer.data(), &handle, NULL ); |
if(!done) |
return false; |
// Get size of DEVMODE structure (public + private data) |
size = DocumentProperties( winId(), handle, printer.data(), NULL, NULL, 0); |
// Compare size with DevMode structure size |
if( DevMode.size() == size ) |
{ |
// Merge printer settings |
result = DocumentProperties( winId(), handle, printer.data(), (DEVMODE*) DevMode.data(), (DEVMODE*) DevMode.data(), DM_IN_BUFFER | DM_OUT_BUFFER); |
} |
else |
{ |
// Retrieve default settings |
DevMode.resize( size ); |
result = DocumentProperties( winId(), handle, printer.data(), (DEVMODE*) DevMode.data(), NULL, DM_OUT_BUFFER); |
} |
done = ( result == IDOK); |
// Free the printer handle |
ClosePrinter( handle ); |
return done; |
#else |
return true; |
#endif |
} |
bool PrinterUtil::getPrinterMarginValues(const QString& printerName, const QString& pageSize, double& ptsTopMargin, double& ptsBottomMargin, double& ptsLeftMargin, double& ptsRightMargin) |
{ |
bool retVal=false; |
#if defined(HAVE_CUPS) |
const char *filename; // tmp PPD filename |
filename=cupsGetPPD(printerName); |
if (filename!=NULL) |
{ |
ppd_file_t *ppd; // PPD data |
ppd = ppdOpenFile(filename); |
if (ppd!=NULL) |
{ |
ppd_size_t *size; // page size data, null if printer doesnt support selected size |
size = ppdPageSize(ppd, pageSize); |
if (size!=NULL) |
{ |
//Store in pts for returning via getNewPrinterMargins in pts |
retVal=true; |
ptsTopMargin=size->length-size->top; |
ptsBottomMargin=size->bottom; |
ptsLeftMargin=size->left; |
ptsRightMargin=size->width-size->right; |
} |
ppdClose(ppd); |
} |
} |
#endif |
return retVal; |
} |
//Parameter needed on win32.. |
bool PrinterUtil::isPostscriptPrinter( QString printerName) |
{ |
#ifdef _WIN32 |
HDC dc; |
int escapeCode; |
char technology[MAX_PATH] = {0}; |
QCString printer = printerName.local8Bit(); |
// Create the default device context |
dc = CreateDC( NULL, printer.data(), NULL, NULL ); |
if ( !dc ) |
{ |
qWarning( QString("isPostscriptPrinter() failed to create device context for %1").arg(printerName) ); |
return false; |
} |
// test if printer support the POSTSCRIPT_PASSTHROUGH escape code |
escapeCode = POSTSCRIPT_PASSTHROUGH; |
if ( ExtEscape( dc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&escapeCode, 0, NULL ) > 0 ) |
{ |
DeleteDC( dc ); |
return true; |
} |
// test if printer support the POSTSCRIPT_DATA escape code |
escapeCode = POSTSCRIPT_DATA; |
if ( ExtEscape( dc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&escapeCode, 0, NULL ) > 0 ) |
{ |
DeleteDC( dc ); |
return true; |
} |
// try to get postscript support by testing the printer technology |
escapeCode = GETTECHNOLOGY; |
if ( ExtEscape( dc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&escapeCode, 0, NULL ) > 0 ) |
{ |
// if GETTECHNOLOGY is supported, then ... get technology |
if ( ExtEscape( dc, GETTECHNOLOGY, 0, NULL, MAX_PATH, (LPSTR) technology ) > 0 ) |
{ |
// check technology string for postscript word |
strupr( technology ); |
if ( strstr( technology, "POSTSCRIPT" ) ) |
{ |
DeleteDC( dc ); |
return true; |
} |
} |
} |
DeleteDC( dc ); |
return false; |
#else |
return true; |
#endif |
} |
/branches/Version13x/Scribus/scribus/util.h |
---|
167,4 → 167,16 |
const QString SCRIBUS_API arabicToRoman(uint i); |
const QString SCRIBUS_API numberToLetterSequence(uint i); |
void SCRIBUS_API parsePagesString(QString pages, std::vector<int>* pageNs, int sourcePageCount); |
/** |
* @brief Check if a specified printer support postscript input |
* |
* On Windows, the function test postscript support for a specified printer |
* and return true if ps is supported |
* On non Windows systems, the function always return true |
* |
* @param printerName the printer name |
* @return true is printer support postscript, false otherwise. |
* |
*/ |
bool SCRIBUS_API isPostscriptPrinter( QString printerName ); |
#endif |
/branches/Version13x/Scribus/scribus/util.cpp |
---|
1676,3 → 1676,56 |
} |
} while (!tmp.isEmpty()); |
} |
//Parameter needed on win32.. |
bool isPostscriptPrinter( QString printerName) |
{ |
#ifdef _WIN32 |
HDC dc; |
int escapeCode; |
char technology[MAX_PATH] = {0}; |
QCString printer = printerName.local8Bit(); |
// Create the default device context |
dc = CreateDC( NULL, printer.data(), NULL, NULL ); |
if ( !dc ) |
{ |
qWarning( QString("isPostscriptPrinter() failed to create device context for %1").arg(printerName) ); |
return false; |
} |
// test if printer support the POSTSCRIPT_PASSTHROUGH escape code |
escapeCode = POSTSCRIPT_PASSTHROUGH; |
if ( ExtEscape( dc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&escapeCode, 0, NULL ) > 0 ) |
{ |
DeleteDC( dc ); |
return true; |
} |
// test if printer support the POSTSCRIPT_DATA escape code |
escapeCode = POSTSCRIPT_DATA; |
if ( ExtEscape( dc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&escapeCode, 0, NULL ) > 0 ) |
{ |
DeleteDC( dc ); |
return true; |
} |
// try to get postscript support by testing the printer technology |
escapeCode = GETTECHNOLOGY; |
if ( ExtEscape( dc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&escapeCode, 0, NULL ) > 0 ) |
{ |
// if GETTECHNOLOGY is supported, then ... get technology |
if ( ExtEscape( dc, GETTECHNOLOGY, 0, NULL, MAX_PATH, (LPSTR) technology ) > 0 ) |
{ |
// check technology string for postscript word |
strupr( technology ); |
if ( strstr( technology, "POSTSCRIPT" ) ) |
{ |
DeleteDC( dc ); |
return true; |
} |
} |
} |
DeleteDC( dc ); |
return false; |
#else |
return true; |
#endif |
} |
/branches/Version13x/Scribus/scribus/druck.cpp |
---|
29,7 → 29,6 |
#ifdef HAVE_CMS |
extern bool CMSuse; |
#endif |
#include "printerutil.h" |
#include "util.h" |
extern bool previewDinUse; |
65,7 → 64,7 |
PrintDest->setEditable(false); |
QString Pcap; |
QString printerName; |
QStringList printerNames = PrinterUtil::getPrinterNames(); |
QStringList printerNames = getPrinterNames(); |
int numPrinters = printerNames.count(); |
for( int i = 0; i < numPrinters; i++) |
{ |
295,14 → 294,13 |
setStoredValues(gcr); |
if (!ToFile) |
PrinterUtil::initDeviceSettings( PrintDest->currentText() ); |
if ( PrinterUtil::isPostscriptPrinter(PrintDest->currentText()) || ToFile ) |
initDeviceSettings( PrintDest->currentText() ); |
if ( isPostscriptPrinter(PrintDest->currentText()) || ToFile ) |
psLevel->setEnabled( true ); |
else |
psLevel->setEnabled( false ); |
} |
/* CB Moved to printerutil.cpp |
QStringList Druck::getPrinterNames(void) |
{ |
QString printerName; |
357,7 → 355,7 |
#endif |
return printerNames; |
} |
*/ |
void Druck::SetOptions() |
{ |
#ifdef HAVE_CUPS |
481,9 → 479,9 |
OptButton->setEnabled(!setter); |
#endif |
if ( !ToFile ) |
if( !PrinterUtil::getDefaultSettings(PrintDest->currentText()) ) |
if( !getDefaultSettings(PrintDest->currentText()) ) |
qWarning(tr("Failed to retrieve printer settings")); |
if ( ToFile || PrinterUtil::isPostscriptPrinter(PrintDest->currentText()) ) |
if ( ToFile || isPostscriptPrinter(PrintDest->currentText()) ) |
{ |
psLevel->setEnabled( true ); |
PrintSep->setEnabled( true ); |
616,7 → 614,7 |
if (CMSuse) |
{ |
bool iccInUse = prefs->getBool("ICCinUse", false); |
bool psPrinter = PrinterUtil::isPostscriptPrinter(PrintDest->currentText()); |
bool psPrinter = isPostscriptPrinter(PrintDest->currentText()); |
UseICC->setChecked( psPrinter ? iccInUse : false ); |
UseICC->setEnabled( psPrinter ); |
} |
713,7 → 711,6 |
#endif |
} |
/* CB Moved to printerutil.cpp |
bool Druck::getDefaultSettings( QString printerName ) |
{ |
#ifdef _WIN32 |
776,4 → 773,3 |
return true; |
#endif |
} |
*/ |
/branches/Version13x/Scribus/scribus/druck.h |
---|
120,11 → 120,9 |
bool ToSeparation; |
PrefsContext* prefs; |
void setStoredValues(bool gcr); |
/* CB Moved to printerutil.cpp |
QStringList getPrinterNames(void); |
bool getDefaultSettings( QString printerName ); |
bool initDeviceSettings( QString printerName ); |
*/ |
}; |
#endif // DRUCK_H |