Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 4503 → Rev 4504

/branches/Version13x/Scribus/scribus/util.cpp
1676,56 → 1676,3
}
} 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/printerutil.h
9,6 → 9,8
 
#include "scribusapi.h"
 
#include <qstring.h>
 
class QStringList;
 
class SCRIBUS_API PrinterUtil
16,7 → 18,32
public:
PrinterUtil() {};
~PrinterUtil() {};
QStringList getPrinterNames();
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 );
};
 
#endif // DRUCK_H
/branches/Version13x/Scribus/scribus/useprintermarginsdialog.cpp
14,15 → 14,10
#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"
 
40,15 → 35,14
m_pageSize=pageSize;
m_unitRatio=unitRatio;
m_suffix=suffix;
PrinterUtil pu;
QStringList printerNames=pu.getPrinterNames();
QStringList printerNames=PrinterUtil::getPrinterNames();
printerComboBox->clear();
if (printerNames.count()>0 && !pageSize.isEmpty())
{
printerComboBox->insertStringList(printerNames);
getPrinterMarginValuesFromCUPS(printerNames.first());
getPrinterMarginValues(printerNames.first());
marginsGroupBox->setTitle(tr("Minimum Margins for Page Size %1").arg(pageSize));
connect(printerComboBox, SIGNAL(activated(const QString&)), this, SLOT(getPrinterMarginValuesFromCUPS(const QString&)));
connect(printerComboBox, SIGNAL(activated(const QString&)), this, SLOT(getPrinterMarginValues(const QString&)));
}
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
66,35 → 60,11
rightMargin=m_ptsRightMargin;
}
 
void UsePrinterMarginsDialog::getPrinterMarginValuesFromCUPS(const QString& printerName)
void UsePrinterMarginsDialog::getPrinterMarginValues(const QString& printerName)
{
m_ptsTopMargin=m_ptsBottomMargin=m_ptsLeftMargin=m_ptsRightMargin=0.0;
#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
bool foundSize=PrinterUtil::getPrinterMarginValues(printerName, m_pageSize, m_ptsTopMargin, m_ptsBottomMargin, m_ptsLeftMargin, m_ptsRightMargin);
 
topLineEdit->setEnabled(foundSize);
bottomLineEdit->setEnabled(foundSize);
leftLineEdit->setEnabled(foundSize);
/branches/Version13x/Scribus/scribus/druck.cpp
29,6 → 29,7
#ifdef HAVE_CMS
extern bool CMSuse;
#endif
#include "printerutil.h"
#include "util.h"
extern bool previewDinUse;
 
64,7 → 65,7
PrintDest->setEditable(false);
QString Pcap;
QString printerName;
QStringList printerNames = getPrinterNames();
QStringList printerNames = PrinterUtil::getPrinterNames();
int numPrinters = printerNames.count();
for( int i = 0; i < numPrinters; i++)
{
294,13 → 295,14
setStoredValues(gcr);
 
if (!ToFile)
initDeviceSettings( PrintDest->currentText() );
if ( isPostscriptPrinter(PrintDest->currentText()) || ToFile )
PrinterUtil::initDeviceSettings( PrintDest->currentText() );
if ( PrinterUtil::isPostscriptPrinter(PrintDest->currentText()) || ToFile )
psLevel->setEnabled( true );
else
psLevel->setEnabled( false );
}
 
/* CB Moved to printerutil.cpp
QStringList Druck::getPrinterNames(void)
{
QString printerName;
355,7 → 357,7
#endif
return printerNames;
}
 
*/
void Druck::SetOptions()
{
#ifdef HAVE_CUPS
479,9 → 481,9
OptButton->setEnabled(!setter);
#endif
if ( !ToFile )
if( !getDefaultSettings(PrintDest->currentText()) )
if( !PrinterUtil::getDefaultSettings(PrintDest->currentText()) )
qWarning(tr("Failed to retrieve printer settings"));
if ( ToFile || isPostscriptPrinter(PrintDest->currentText()) )
if ( ToFile || PrinterUtil::isPostscriptPrinter(PrintDest->currentText()) )
{
psLevel->setEnabled( true );
PrintSep->setEnabled( true );
614,7 → 616,7
if (CMSuse)
{
bool iccInUse = prefs->getBool("ICCinUse", false);
bool psPrinter = isPostscriptPrinter(PrintDest->currentText());
bool psPrinter = PrinterUtil::isPostscriptPrinter(PrintDest->currentText());
UseICC->setChecked( psPrinter ? iccInUse : false );
UseICC->setEnabled( psPrinter );
}
711,6 → 713,7
#endif
}
 
/* CB Moved to printerutil.cpp
bool Druck::getDefaultSettings( QString printerName )
{
#ifdef _WIN32
773,3 → 776,4
return true;
#endif
}
*/
/branches/Version13x/Scribus/scribus/useprintermarginsdialog.h
34,7 → 34,7
*/
void getNewPrinterMargins(double &topMargin,double &bottomMargin,double &leftMargin,double &rightMargin);
protected slots:
void getPrinterMarginValuesFromCUPS(const QString& printerName);
void getPrinterMarginValues(const QString& printerName);
protected:
QString m_pageSize;
/branches/Version13x/Scribus/scribus/druck.h
120,9 → 120,11
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
/branches/Version13x/Scribus/scribus/util.h
167,16 → 167,4
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/printerutil.cpp
5,6 → 5,7
for which a new license (GPL+exception) is in place.
*/
#include "printerutil.h"
#include "scconfig.h"
 
#if defined( HAVE_CUPS )
#include <cups/cups.h>
14,7 → 15,6
#endif
 
#include <qstringlist.h>
 
#include "util.h"
 
QStringList PrinterUtil::getPrinterNames()
71,3 → 71,149
#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
}