Kaydet (Commit) c76cd71f authored tarafından Michael Stahl's avatar Michael Stahl

fdo#41524: CUPS printing: use "collate" option when PDF is available

Assume that the CUPS printer is able to handle collating by itself,
don't send multiple print jobs (except if user clicks on "Create single
print jobs for collated output" of course...).

To enable collating with PDF based printers, add the "collate" option;
legacy PS based printers still get the weird stuff read from the PPD
(not sure what the risks of changing that are).

Change-Id: Ia12dc69f9083bba94f2ed633ecbd153aac7e40ab
üst 6058a238
...@@ -34,6 +34,7 @@ enum type { ...@@ -34,6 +34,7 @@ enum type {
struct VCL_DLLPUBLIC JobData struct VCL_DLLPUBLIC JobData
{ {
int m_nCopies; int m_nCopies;
bool m_bCollate;
int m_nLeftMarginAdjust; int m_nLeftMarginAdjust;
int m_nRightMarginAdjust; int m_nRightMarginAdjust;
int m_nTopMarginAdjust; int m_nTopMarginAdjust;
...@@ -50,6 +51,7 @@ struct VCL_DLLPUBLIC JobData ...@@ -50,6 +51,7 @@ struct VCL_DLLPUBLIC JobData
JobData() : JobData() :
m_nCopies( 1 ), m_nCopies( 1 ),
m_bCollate(false),
m_nLeftMarginAdjust( 0 ), m_nLeftMarginAdjust( 0 ),
m_nRightMarginAdjust( 0 ), m_nRightMarginAdjust( 0 ),
m_nTopMarginAdjust( 0 ), m_nTopMarginAdjust( 0 ),
......
...@@ -808,16 +808,9 @@ sal_uLong PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, sal ...@@ -808,16 +808,9 @@ sal_uLong PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, sal
return 0xffff; return 0xffff;
case PRINTER_CAPABILITIES_COLLATECOPIES: case PRINTER_CAPABILITIES_COLLATECOPIES:
{ {
// see if the PPD contains a value to set Collate to True
JobData aData;
JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aData );
const PPDKey* pKey = aData.m_pParser ? aData.m_pParser->getKey( OUString("Collate") ) : NULL;
const PPDValue* pVal = pKey ? pKey->getValue(OUString("True")) : NULL;
// PPDs don't mention the number of possible collated copies. // PPDs don't mention the number of possible collated copies.
// so let's guess as many as we want ? // so let's guess as many as we want ?
return pVal ? 0xffff : 0; return 0xffff;
} }
case PRINTER_CAPABILITIES_SETORIENTATION: case PRINTER_CAPABILITIES_SETORIENTATION:
return 1; return 1;
...@@ -836,7 +829,7 @@ sal_uLong PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, sal ...@@ -836,7 +829,7 @@ sal_uLong PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, sal
return 1; return 1;
else else
{ {
// see if the PPD contains a value to set Collate to True // see if the PPD contains a value to set PDF device
JobData aData = PrinterInfoManager::get().getPrinterInfo( pJobSetup->maPrinterName ); JobData aData = PrinterInfoManager::get().getPrinterInfo( pJobSetup->maPrinterName );
if( pJobSetup->mpDriverData ) if( pJobSetup->mpDriverData )
JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aData ); JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aData );
...@@ -846,7 +839,7 @@ sal_uLong PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, sal ...@@ -846,7 +839,7 @@ sal_uLong PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, sal
return PrinterInfoManager::get().checkFeatureToken( pJobSetup->maPrinterName, "external_dialog" ) ? 1 : 0; return PrinterInfoManager::get().checkFeatureToken( pJobSetup->maPrinterName, "external_dialog" ) ? 1 : 0;
case PRINTER_CAPABILITIES_USEPULLMODEL: case PRINTER_CAPABILITIES_USEPULLMODEL:
{ {
// see if the PPD contains a value to set Collate to True // see if the PPD contains a value to set PDF device
JobData aData = PrinterInfoManager::get().getPrinterInfo( pJobSetup->maPrinterName ); JobData aData = PrinterInfoManager::get().getPrinterInfo( pJobSetup->maPrinterName );
if( pJobSetup->mpDriverData ) if( pJobSetup->mpDriverData )
JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aData ); JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aData );
......
...@@ -603,6 +603,8 @@ void CUPSManager::getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner ...@@ -603,6 +603,8 @@ void CUPSManager::getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner
{ {
OString aVal( OString::number( rJob.m_nCopies ) ); OString aVal( OString::number( rJob.m_nCopies ) );
rNumOptions = cupsAddOption( "copies", aVal.getStr(), rNumOptions, (cups_option_t**)rOptions ); rNumOptions = cupsAddOption( "copies", aVal.getStr(), rNumOptions, (cups_option_t**)rOptions );
aVal = OString::boolean(rJob.m_bCollate);
rNumOptions = cupsAddOption( "collate", aVal.getStr(), rNumOptions, (cups_option_t**)rOptions );
} }
if( ! bBanner ) if( ! bBanner )
{ {
......
...@@ -31,6 +31,7 @@ using namespace psp; ...@@ -31,6 +31,7 @@ using namespace psp;
JobData& JobData::operator=(const JobData& rRight) JobData& JobData::operator=(const JobData& rRight)
{ {
m_nCopies = rRight.m_nCopies; m_nCopies = rRight.m_nCopies;
m_bCollate = rRight.m_bCollate;
m_nLeftMarginAdjust = rRight.m_nLeftMarginAdjust; m_nLeftMarginAdjust = rRight.m_nLeftMarginAdjust;
m_nRightMarginAdjust = rRight.m_nRightMarginAdjust; m_nRightMarginAdjust = rRight.m_nRightMarginAdjust;
m_nTopMarginAdjust = rRight.m_nTopMarginAdjust; m_nTopMarginAdjust = rRight.m_nTopMarginAdjust;
...@@ -54,6 +55,11 @@ JobData& JobData::operator=(const JobData& rRight) ...@@ -54,6 +55,11 @@ JobData& JobData::operator=(const JobData& rRight)
void JobData::setCollate( bool bCollate ) void JobData::setCollate( bool bCollate )
{ {
if (m_nPDFDevice > 0)
{
m_bCollate = bCollate;
return;
}
const PPDParser* pParser = m_aContext.getParser(); const PPDParser* pParser = m_aContext.getParser();
if( pParser ) if( pParser )
{ {
...@@ -133,6 +139,13 @@ bool JobData::getStreamBuffer( void*& pData, int& bytes ) ...@@ -133,6 +139,13 @@ bool JobData::getStreamBuffer( void*& pData, int& bytes )
aLine.append(static_cast<sal_Int32>(m_nCopies)); aLine.append(static_cast<sal_Int32>(m_nCopies));
aStream.WriteLine(aLine.makeStringAndClear()); aStream.WriteLine(aLine.makeStringAndClear());
if (m_nPDFDevice > 0)
{
aLine.append("collate=");
aLine.append(OString::boolean(m_bCollate));
aStream.WriteLine(aLine.makeStringAndClear());
}
aLine.append("margindajustment="); aLine.append("margindajustment=");
aLine.append(static_cast<sal_Int32>(m_nLeftMarginAdjust)); aLine.append(static_cast<sal_Int32>(m_nLeftMarginAdjust));
aLine.append(','); aLine.append(',');
...@@ -191,6 +204,7 @@ bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobDa ...@@ -191,6 +204,7 @@ bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobDa
const char printerEquals[] = "printer="; const char printerEquals[] = "printer=";
const char orientatationEquals[] = "orientation="; const char orientatationEquals[] = "orientation=";
const char copiesEquals[] = "copies="; const char copiesEquals[] = "copies=";
const char collateEquals[] = "collate=";
const char margindajustmentEquals[] = "margindajustment="; const char margindajustmentEquals[] = "margindajustment=";
const char colordepthEquals[] = "colordepth="; const char colordepthEquals[] = "colordepth=";
const char colordeviceEquals[] = "colordevice="; const char colordeviceEquals[] = "colordevice=";
...@@ -217,6 +231,10 @@ bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobDa ...@@ -217,6 +231,10 @@ bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobDa
bCopies = true; bCopies = true;
rJobData.m_nCopies = aLine.copy(RTL_CONSTASCII_LENGTH(copiesEquals)).toInt32(); rJobData.m_nCopies = aLine.copy(RTL_CONSTASCII_LENGTH(copiesEquals)).toInt32();
} }
else if (aLine.startsWith(collateEquals))
{
rJobData.m_bCollate = aLine.copy(RTL_CONSTASCII_LENGTH(collateEquals)).toInt32();
}
else if (aLine.startsWith(margindajustmentEquals)) else if (aLine.startsWith(margindajustmentEquals))
{ {
bMargin = true; bMargin = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment