summaryrefslogtreecommitdiff
path: root/vcl/unx/source
diff options
context:
space:
mode:
Diffstat (limited to 'vcl/unx/source')
-rw-r--r--vcl/unx/source/fontmanager/fontcache.cxx4
-rw-r--r--vcl/unx/source/fontmanager/fontconfig.cxx74
-rw-r--r--vcl/unx/source/gdi/salprnpsp.cxx323
-rw-r--r--vcl/unx/source/plugadapt/salplug.cxx5
-rw-r--r--vcl/unx/source/printer/cupsmgr.cxx42
-rw-r--r--vcl/unx/source/printer/jobdata.cxx41
-rw-r--r--vcl/unx/source/printer/printerinfomanager.cxx50
-rw-r--r--vcl/unx/source/printergfx/printerjob.cxx5
8 files changed, 491 insertions, 53 deletions
diff --git a/vcl/unx/source/fontmanager/fontcache.cxx b/vcl/unx/source/fontmanager/fontcache.cxx
index db4a7d05e5fc..0c43373bfa8e 100644
--- a/vcl/unx/source/fontmanager/fontcache.cxx
+++ b/vcl/unx/source/fontmanager/fontcache.cxx
@@ -373,9 +373,9 @@ void FontCache::read()
xub_StrLen nLastIndex = nIndex+1;
for( nIndex = nLastIndex ; nIndex < nLen && pLine[nIndex] != ';'; nIndex++ )
;
- if( nIndex - nLastIndex > 1 )
+ if( nIndex - nLastIndex )
{
- OUString aAlias( pLine+nLastIndex, nIndex-nLastIndex-1, RTL_TEXTENCODING_UTF8 );
+ OUString aAlias( pLine+nLastIndex, nIndex-nLastIndex, RTL_TEXTENCODING_UTF8 );
pFont->m_aAliases.push_back( pAtoms->getAtom( ATOM_FAMILYNAME, aAlias, sal_True ) );
}
}
diff --git a/vcl/unx/source/fontmanager/fontconfig.cxx b/vcl/unx/source/fontmanager/fontconfig.cxx
index 03816857f27c..ecb4aa54549b 100644
--- a/vcl/unx/source/fontmanager/fontconfig.cxx
+++ b/vcl/unx/source/fontmanager/fontconfig.cxx
@@ -121,16 +121,20 @@ class FontCfgWrapper
FcResult (*m_pFcPatternGetBool)(const FcPattern*,const char*,int,FcBool*);
void (*m_pFcDefaultSubstitute)(FcPattern *);
FcPattern* (*m_pFcFontSetMatch)(FcConfig*,FcFontSet**, int, FcPattern*,FcResult*);
+ FcPattern* (*m_pFcFontMatch)(FcConfig*,FcPattern*,FcResult*);
FcBool (*m_pFcConfigAppFontAddFile)(FcConfig*, const FcChar8*);
FcBool (*m_pFcConfigAppFontAddDir)(FcConfig*, const FcChar8*);
FcBool (*m_pFcConfigParseAndLoad)(FcConfig*,const FcChar8*,FcBool);
-
FcBool (*m_pFcConfigSubstitute)(FcConfig*,FcPattern*,FcMatchKind);
+
+ FcPattern* (*m_pFcPatternDuplicate)(const FcPattern*);
FcBool (*m_pFcPatternAddInteger)(FcPattern*,const char*,int);
FcBool (*m_pFcPatternAddDouble)(FcPattern*,const char*,double);
FcBool (*m_pFcPatternAddBool)(FcPattern*,const char*,FcBool);
FcBool (*m_pFcPatternAddCharSet)(FcPattern*,const char*,const FcCharSet*);
FcBool (*m_pFcPatternAddString)(FcPattern*,const char*,const FcChar8*);
+ FcBool (*m_pFcPatternDel)(FcPattern*,const char*);
+
FT_UInt (*m_pFcFreeTypeCharIndex)(FT_Face,FcChar32);
oslGenericFunction loadSymbol( const char* );
@@ -230,8 +234,13 @@ public:
{ m_pFcDefaultSubstitute( pPattern ); }
FcPattern* FcFontSetMatch( FcConfig* pConfig, FcFontSet **ppFontSet, int nset, FcPattern* pPattern, FcResult* pResult )
{ return m_pFcFontSetMatch ? m_pFcFontSetMatch( pConfig, ppFontSet, nset, pPattern, pResult ) : 0; }
+ FcPattern* FcFontMatch( FcConfig* pConfig, FcPattern* pPattern, FcResult* pResult )
+ { return m_pFcFontMatch( pConfig, pPattern, pResult ); }
FcBool FcConfigSubstitute( FcConfig* pConfig, FcPattern* pPattern, FcMatchKind eKind )
{ return m_pFcConfigSubstitute( pConfig, pPattern, eKind ); }
+
+ FcPattern* FcPatternDuplicate( const FcPattern* pPattern ) const
+ { return m_pFcPatternDuplicate( pPattern ); }
FcBool FcPatternAddInteger( FcPattern* pPattern, const char* pObject, int nValue )
{ return m_pFcPatternAddInteger( pPattern, pObject, nValue ); }
FcBool FcPatternAddDouble( FcPattern* pPattern, const char* pObject, double nValue )
@@ -242,6 +251,8 @@ public:
{ return m_pFcPatternAddBool( pPattern, pObject, nValue ); }
FcBool FcPatternAddCharSet(FcPattern* pPattern,const char* pObject,const FcCharSet*pCharSet)
{ return m_pFcPatternAddCharSet(pPattern,pObject,pCharSet); }
+ FcBool FcPatternDel(FcPattern* pPattern, const char* object)
+ { return m_pFcPatternDel( pPattern, object); }
FT_UInt FcFreeTypeCharIndex( FT_Face face, FcChar32 ucs4 )
{ return m_pFcFreeTypeCharIndex ? m_pFcFreeTypeCharIndex( face, ucs4 ) : 0; }
@@ -337,8 +348,13 @@ FontCfgWrapper::FontCfgWrapper()
loadSymbol( "FcDefaultSubstitute" );
m_pFcFontSetMatch = (FcPattern*(*)(FcConfig*,FcFontSet**,int,FcPattern*,FcResult*))
loadSymbol( "FcFontSetMatch" );
+ m_pFcFontMatch = (FcPattern*(*)(FcConfig*,FcPattern*,FcResult*))
+ loadSymbol( "FcFontMatch" );
m_pFcConfigSubstitute = (FcBool(*)(FcConfig*,FcPattern*,FcMatchKind))
loadSymbol( "FcConfigSubstitute" );
+
+ m_pFcPatternDuplicate = (FcPattern*(*)(const FcPattern*))
+ loadSymbol( "FcPatternDuplicate" );
m_pFcPatternAddInteger = (FcBool(*)(FcPattern*,const char*,int))
loadSymbol( "FcPatternAddInteger" );
m_pFcPatternAddDouble = (FcBool(*)(FcPattern*,const char*,double))
@@ -349,6 +365,9 @@ FontCfgWrapper::FontCfgWrapper()
loadSymbol( "FcPatternAddCharSet" );
m_pFcPatternAddString = (FcBool(*)(FcPattern*,const char*,const FcChar8*))
loadSymbol( "FcPatternAddString" );
+ m_pFcPatternDel = (FcBool(*)(FcPattern*,const char*))
+ loadSymbol( "FcPatternDel" );
+
m_pFcFreeTypeCharIndex = (FT_UInt(*)(FT_Face,FcChar32))
loadSymbol( "FcFreeTypeCharIndex" );
@@ -391,13 +410,16 @@ FontCfgWrapper::FontCfgWrapper()
m_pFcConfigAppFontAddFile &&
m_pFcConfigAppFontAddDir &&
m_pFcConfigParseAndLoad &&
+ m_pFcFontMatch &&
m_pFcDefaultSubstitute &&
m_pFcConfigSubstitute &&
+ m_pFcPatternDuplicate &&
m_pFcPatternAddInteger &&
m_pFcPatternAddDouble &&
m_pFcPatternAddCharSet &&
m_pFcPatternAddBool &&
- m_pFcPatternAddString
+ m_pFcPatternAddString &&
+ m_pFcPatternDel
) )
{
osl_unloadModule( (oslModule)m_pLib );
@@ -428,18 +450,31 @@ void FontCfgWrapper::addFontSet( FcSetName eSetName )
if( !pOrig )
return;
+ // filter the font sets to remove obsolete or duplicate faces
for( int i = 0; i < pOrig->nfont; ++i )
{
- FcBool outline = false;
- FcPattern *pOutlinePattern = pOrig->fonts[i];
- FcResult eOutRes =
- FcPatternGetBool( pOutlinePattern, FC_OUTLINE, 0, &outline );
- if( (eOutRes != FcResultMatch) || (outline != FcTrue) )
+ FcPattern* pOrigPattern = pOrig->fonts[i];
+ // create a pattern to find eventually better alternatives
+ FcPattern* pTestPattern = FcPatternDuplicate( pOrigPattern );
+ FcPatternAddBool( pTestPattern, FC_OUTLINE, FcTrue );
+ // TODO: use pattern->ImplFontAttr->pattern to filter out
+ // all attribute that are not interesting for finding dupes
+ FcPatternDel( pTestPattern, FC_FONTVERSION );
+ FcPatternDel( pTestPattern, FC_CHARSET );
+ FcPatternDel( pTestPattern, FC_FILE );
+ // find the font face for the dupe-search pattern
+ FcResult eFcResult = FcResultMatch;
+ FcPattern* pBetterPattern = FcFontMatch( FcConfigGetCurrent(), pTestPattern, &eFcResult );
+ FcPatternDestroy( pTestPattern );
+ if( eFcResult != FcResultMatch )
continue;
- FcPatternReference(pOutlinePattern);
- FcFontSetAdd(m_pOutlineSet, pOutlinePattern);
+ // insert best found pattern for the dupe-search pattern
+ // TODO: skip inserting patterns that are already known in the target fontset
+ FcPatternReference( pBetterPattern );
+ FcFontSetAdd( m_pOutlineSet, pBetterPattern );
}
- // TODO: FcFontSetDestroy( pOrig );
+
+ // TODO?: FcFontSetDestroy( pOrig );
#else
(void)eSetName; // prevent compiler warning about unused parameter
#endif
@@ -509,22 +544,29 @@ namespace
std::vector<lang_and_family>::const_iterator aEnd = families.end();
bool alreadyclosematch = false;
- for (std::vector<lang_and_family>::const_iterator aIter = families.begin(); aIter != aEnd; ++aIter)
+ for( std::vector<lang_and_family>::const_iterator aIter = families.begin(); aIter != aEnd; ++aIter )
{
const char *pLang = (const char*)aIter->first;
- //perfect
- if( rtl_str_compare(pLang,sFullMatch.getStr() ) == 0)
+ if( rtl_str_compare( pLang, sFullMatch.getStr() ) == 0)
{
+ // both language and country match
candidate = aIter->second;
break;
}
- else if( (rtl_str_compare(pLang,sLangMatch.getStr()) == 0) && (!alreadyclosematch))
+ else if( alreadyclosematch )
+ continue;
+ else if( rtl_str_compare( pLang, sLangMatch.getStr()) == 0)
{
+ // just the language matches
candidate = aIter->second;
alreadyclosematch = true;
}
+ else if( rtl_str_compare( pLang, "en") == 0)
+ {
+ // fallback to the english family name
+ candidate = aIter->second;
+ }
}
-
return candidate;
}
}
@@ -701,7 +743,7 @@ int PrintFontManager::countFontconfigFonts( std::hash_map<rtl::OString, int, rtl
);
#endif
- OSL_ASSERT(eOutRes != FcResultMatch || outline);
+// OSL_ASSERT(eOutRes != FcResultMatch || outline);
// only outline fonts are usable to psprint anyway
if( eOutRes == FcResultMatch && ! outline )
diff --git a/vcl/unx/source/gdi/salprnpsp.cxx b/vcl/unx/source/gdi/salprnpsp.cxx
index 8617bc4e5bfa..417704eb3b69 100644
--- a/vcl/unx/source/gdi/salprnpsp.cxx
+++ b/vcl/unx/source/gdi/salprnpsp.cxx
@@ -54,6 +54,8 @@
#include "vcl/svapp.hxx"
#include "vcl/jobset.h"
#include "vcl/print.h"
+#include "vcl/print.hxx"
+#include "vcl/pdfwriter.hxx"
#include "vcl/salptype.hxx"
#include "vcl/printerinfomanager.hxx"
@@ -63,6 +65,7 @@
using namespace psp;
using namespace rtl;
+using namespace com::sun::star;
/*
* static helpers
@@ -892,9 +895,26 @@ ULONG PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, USHORT
case PRINTER_CAPABILITIES_FAX:
return PrinterInfoManager::get().checkFeatureToken( pJobSetup->maPrinterName, "fax" ) ? 1 : 0;
case PRINTER_CAPABILITIES_PDF:
- return PrinterInfoManager::get().checkFeatureToken( pJobSetup->maPrinterName, "pdf" ) ? 1 : 0;
+ if( PrinterInfoManager::get().checkFeatureToken( pJobSetup->maPrinterName, "pdf" ) )
+ return 1;
+ else
+ {
+ // see if the PPD contains a value to set Collate to True
+ JobData aData = PrinterInfoManager::get().getPrinterInfo( pJobSetup->maPrinterName );
+ if( pJobSetup->mpDriverData )
+ JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aData );
+ return aData.m_nPDFDevice > 0 ? 1 : 0;
+ }
case PRINTER_CAPABILITIES_EXTERNALDIALOG:
return PrinterInfoManager::get().checkFeatureToken( pJobSetup->maPrinterName, "external_dialog" ) ? 1 : 0;
+ case PRINTER_CAPABILITIES_USEPULLMODEL:
+ {
+ // see if the PPD contains a value to set Collate to True
+ JobData aData = PrinterInfoManager::get().getPrinterInfo( pJobSetup->maPrinterName );
+ if( pJobSetup->mpDriverData )
+ JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aData );
+ return aData.m_nPDFDevice > 0 ? 1 : 0;
+ }
default: break;
};
return 0;
@@ -910,6 +930,7 @@ ULONG PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, USHORT
: m_bFax( false ),
m_bPdf( false ),
m_bSwallowFaxNo( false ),
+ m_bIsPDFWriterJob( false ),
m_pGraphics( NULL ),
m_nCopies( 1 ),
m_bCollate( false ),
@@ -1021,22 +1042,28 @@ BOOL PspSalPrinter::StartJob(
BOOL PspSalPrinter::EndJob()
{
- BOOL bSuccess = m_aPrintJob.EndJob();
-
- if( bSuccess )
+ BOOL bSuccess = FALSE;
+ if( m_bIsPDFWriterJob )
+ bSuccess = TRUE;
+ else
{
- // check for fax
- if( m_bFax )
- {
+ bSuccess = m_aPrintJob.EndJob();
- const PrinterInfo& rInfo( PrinterInfoManager::get().getPrinterInfo( m_aJobData.m_aPrinterName ) );
- // sendAFax removes the file after use
- bSuccess = sendAFax( m_aFaxNr, m_aTmpFile, rInfo.m_aCommand );
- }
- else if( m_bPdf )
+ if( bSuccess )
{
- const PrinterInfo& rInfo( PrinterInfoManager::get().getPrinterInfo( m_aJobData.m_aPrinterName ) );
- bSuccess = createPdf( m_aFileName, m_aTmpFile, rInfo.m_aCommand );
+ // check for fax
+ if( m_bFax )
+ {
+
+ const PrinterInfo& rInfo( PrinterInfoManager::get().getPrinterInfo( m_aJobData.m_aPrinterName ) );
+ // sendAFax removes the file after use
+ bSuccess = sendAFax( m_aFaxNr, m_aTmpFile, rInfo.m_aCommand );
+ }
+ else if( m_bPdf )
+ {
+ const PrinterInfo& rInfo( PrinterInfoManager::get().getPrinterInfo( m_aJobData.m_aPrinterName ) );
+ bSuccess = createPdf( m_aFileName, m_aTmpFile, rInfo.m_aCommand );
+ }
}
}
vcl_sal::PrinterUpdate::jobEnded();
@@ -1089,6 +1116,274 @@ ULONG PspSalPrinter::GetErrorCode()
return 0;
}
+// -----------------------------------------------------------------------
+
+struct PDFNewJobParameters
+{
+ Size maPageSize;
+ USHORT mnPaperBin;
+
+ PDFNewJobParameters( const Size& i_rSize = Size(),
+ USHORT i_nPaperBin = 0xffff )
+ : maPageSize( i_rSize ), mnPaperBin( i_nPaperBin ) {}
+
+ bool operator!=(const PDFNewJobParameters& rComp ) const
+ {
+ Size aCompLSSize( rComp.maPageSize.Height(), rComp.maPageSize.Width() );
+ return
+ (maPageSize != rComp.maPageSize && maPageSize != aCompLSSize)
+ || mnPaperBin != rComp.mnPaperBin
+ ;
+ }
+
+ bool operator==(const PDFNewJobParameters& rComp) const
+ {
+ return ! this->operator!=(rComp);
+ }
+};
+
+struct PDFPrintFile
+{
+ rtl::OUString maTmpURL;
+ PDFNewJobParameters maParameters;
+
+ PDFPrintFile( const rtl::OUString& i_rURL, const PDFNewJobParameters& i_rNewParameters )
+ : maTmpURL( i_rURL )
+ , maParameters( i_rNewParameters ) {}
+};
+
+BOOL PspSalPrinter::StartJob( const String* i_pFileName, const String& i_rJobName, const String& i_rAppName,
+ ImplJobSetup* i_pSetupData, vcl::PrinterController& i_rController )
+{
+ OSL_TRACE( "StartJob with controller: pFilename = %s", i_pFileName ? rtl::OUStringToOString( *i_pFileName, RTL_TEXTENCODING_UTF8 ).getStr() : "<nil>" );
+ // mark for endjob
+ m_bIsPDFWriterJob = true;
+ // reset IsLastPage
+ i_rController.setLastPage( sal_False );
+
+ // update job data
+ if( i_pSetupData )
+ JobData::constructFromStreamBuffer( i_pSetupData->mpDriverData, i_pSetupData->mnDriverDataLen, m_aJobData );
+
+ OSL_ASSERT( m_aJobData.m_nPDFDevice > 0 );
+ m_aJobData.m_nPDFDevice = 1;
+
+ // possibly create one job for collated output
+ sal_Bool bSinglePrintJobs = sal_False;
+ beans::PropertyValue* pSingleValue = i_rController.getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintCollateAsSingleJobs" ) ) );
+ if( pSingleValue )
+ {
+ pSingleValue->Value >>= bSinglePrintJobs;
+ }
+
+ int nCopies = i_rController.getPrinter()->GetCopyCount();
+ bool bCollate = i_rController.getPrinter()->IsCollateCopy();
+
+ // notify start of real print job
+ i_rController.jobStarted();
+
+ // setup PDFWriter context
+ vcl::PDFWriter::PDFWriterContext aContext;
+ aContext.Version = vcl::PDFWriter::PDF_1_4;
+ aContext.Tagged = false;
+ aContext.EmbedStandardFonts = true;
+ aContext.Encrypt = false;
+ aContext.DocumentLocale = Application::GetSettings().GetLocale();
+
+ // prepare doc info
+ vcl::PDFDocInfo aDocInfo;
+ aDocInfo.Title = i_rJobName;
+ aDocInfo.Creator = i_rAppName;
+ aDocInfo.Producer = i_rAppName;
+
+ // define how we handle metafiles in PDFWriter
+ vcl::PDFWriter::PlayMetafileContext aMtfContext;
+ aMtfContext.m_bOnlyLosslessCompression = true;
+
+ boost::shared_ptr<vcl::PDFWriter> pWriter;
+ std::vector< PDFPrintFile > aPDFFiles;
+ boost::shared_ptr<Printer> pPrinter( i_rController.getPrinter() );
+ int nAllPages = i_rController.getFilteredPageCount();
+ i_rController.createProgressDialog();
+ bool bAborted = false;
+ PDFNewJobParameters aLastParm;
+
+ aContext.DPIx = pPrinter->ImplGetDPIX();
+ aContext.DPIy = pPrinter->ImplGetDPIY();
+ for( int nPage = 0; nPage < nAllPages && ! bAborted; nPage++ )
+ {
+ if( nPage == nAllPages-1 )
+ i_rController.setLastPage( sal_True );
+
+ // get the page's metafile
+ GDIMetaFile aPageFile;
+ vcl::PrinterController::PageSize aPageSize = i_rController.getFilteredPageFile( nPage, aPageFile );
+ if( i_rController.isProgressCanceled() )
+ {
+ bAborted = true;
+ if( nPage != nAllPages-1 )
+ {
+ i_rController.createProgressDialog();
+ i_rController.setLastPage( sal_True );
+ i_rController.getFilteredPageFile( nPage, aPageFile );
+ }
+ }
+ else
+ {
+ pPrinter->SetMapMode( MapMode( MAP_100TH_MM ) );
+ pPrinter->SetPaperSizeUser( aPageSize.aSize, true );
+ PDFNewJobParameters aNewParm( pPrinter->GetPaperSize(), pPrinter->GetPaperBin() );
+
+ // create PDF writer on demand
+ // either on first page
+ // or on paper format change - cups does not support multiple paper formats per job (yet?)
+ // so we need to start a new job to get a new paper format from the printer
+ // orientation switches (that is switch of height and width) is handled transparently by CUPS
+ if( ! pWriter ||
+ (aNewParm != aLastParm && ! i_pFileName ) )
+ {
+ if( pWriter )
+ {
+ pWriter->Emit();
+ }
+ // produce PDF file
+ OUString aPDFUrl;
+ if( i_pFileName )
+ aPDFUrl = *i_pFileName;
+ else
+ osl_createTempFile( NULL, NULL, &aPDFUrl.pData );
+ // normalize to file URL
+ if( aPDFUrl.compareToAscii( "file:", 5 ) != 0 )
+ {
+ // this is not a file URL, but it should
+ // form it into a osl friendly file URL
+ rtl::OUString aTmp;
+ osl_getFileURLFromSystemPath( aPDFUrl.pData, &aTmp.pData );
+ aPDFUrl = aTmp;
+ }
+ // save current file and paper format
+ aLastParm = aNewParm;
+ aPDFFiles.push_back( PDFPrintFile( aPDFUrl, aNewParm ) );
+ // update context
+ aContext.URL = aPDFUrl;
+
+ // create and initialize PDFWriter
+ #if defined __SUNPRO_CC
+ #pragma disable_warn
+ #endif
+ pWriter.reset( new vcl::PDFWriter( aContext ) );
+ #if defined __SUNPRO_CC
+ #pragma enable_warn
+ #endif
+ pWriter->SetDocInfo( aDocInfo );
+ }
+
+ pWriter->NewPage( TenMuToPt( aNewParm.maPageSize.Width() ),
+ TenMuToPt( aNewParm.maPageSize.Height() ),
+ vcl::PDFWriter::Portrait );
+
+ pWriter->PlayMetafile( aPageFile, aMtfContext, NULL );
+ }
+ }
+
+ // emit the last file
+ if( pWriter )
+ pWriter->Emit();
+
+ // handle collate, copy count and multiple jobs correctly
+ int nOuterJobs = 1;
+ if( bSinglePrintJobs )
+ {
+ nOuterJobs = nCopies;
+ m_aJobData.m_nCopies = 1;
+ }
+ else
+ {
+ if( bCollate )
+ {
+ if( aPDFFiles.size() == 1 && pPrinter->HasSupport( SUPPORT_COLLATECOPY ) )
+ {
+ m_aJobData.setCollate( true );
+ m_aJobData.m_nCopies = nCopies;
+ }
+ else
+ {
+ nOuterJobs = nCopies;
+ m_aJobData.m_nCopies = 1;
+ }
+ }
+ else
+ {
+ m_aJobData.setCollate( false );
+ m_aJobData.m_nCopies = nCopies;
+ }
+ }
+
+ // spool files
+ if( ! i_pFileName && ! bAborted )
+ {
+ bool bFirstJob = true;
+ for( int nCurJob = 0; nCurJob < nOuterJobs; nCurJob++ )
+ {
+ for( size_t i = 0; i < aPDFFiles.size(); i++ )
+ {
+ oslFileHandle pFile = NULL;
+ osl_openFile( aPDFFiles[i].maTmpURL.pData, &pFile, osl_File_OpenFlag_Read );
+ if( pFile )
+ {
+ osl_setFilePos( pFile, osl_Pos_Absolut, 0 );
+ std::vector< char > buffer( 0x10000, 0 );
+ // update job data with current page size
+ Size aPageSize( aPDFFiles[i].maParameters.maPageSize );
+ m_aJobData.setPaper( TenMuToPt( aPageSize.Width() ), TenMuToPt( aPageSize.Height() ) );
+ // update job data with current paperbin
+ m_aJobData.setPaperBin( aPDFFiles[i].maParameters.mnPaperBin );
+
+ // spool current file
+ FILE* fp = PrinterInfoManager::get().startSpool( pPrinter->GetName(), i_rController.isDirectPrint() );
+ if( fp )
+ {
+ sal_uInt64 nBytesRead = 0;
+ do
+ {
+ osl_readFile( pFile, &buffer[0], buffer.size(), &nBytesRead );
+ if( nBytesRead > 0 )
+ fwrite( &buffer[0], 1, nBytesRead, fp );
+ } while( nBytesRead == buffer.size() );
+ rtl::OUStringBuffer aBuf( i_rJobName.Len() + 8 );
+ aBuf.append( i_rJobName );
+ if( i > 0 || nCurJob > 0 )
+ {
+ aBuf.append( sal_Unicode(' ') );
+ aBuf.append( sal_Int32( i + nCurJob * aPDFFiles.size() ) );
+ }
+ PrinterInfoManager::get().endSpool( pPrinter->GetName(), aBuf.makeStringAndClear(), fp, m_aJobData, bFirstJob );
+ bFirstJob = false;
+ }
+ }
+ osl_closeFile( pFile );
+ }
+ }
+ }
+
+ // job has been spooled
+ i_rController.setJobState( bAborted ? view::PrintableState_JOB_ABORTED : view::PrintableState_JOB_SPOOLED );
+
+ // clean up the temporary PDF files
+ if( ! i_pFileName || bAborted )
+ {
+ for( size_t i = 0; i < aPDFFiles.size(); i++ )
+ {
+ osl_removeFile( aPDFFiles[i].maTmpURL.pData );
+ OSL_TRACE( "removed print PDF file %s\n", rtl::OUStringToOString( aPDFFiles[i].maTmpURL, RTL_TEXTENCODING_UTF8 ).getStr() );
+ }
+ }
+
+ return TRUE;
+}
+
+
+
/*
* vcl::PrinterUpdate
*/
diff --git a/vcl/unx/source/plugadapt/salplug.cxx b/vcl/unx/source/plugadapt/salplug.cxx
index a438760cffba..fd49ee34f543 100644
--- a/vcl/unx/source/plugadapt/salplug.cxx
+++ b/vcl/unx/source/plugadapt/salplug.cxx
@@ -36,6 +36,7 @@
#include "vcl/salinst.hxx"
#include "saldata.hxx"
+#include "vcl/printerinfomanager.hxx"
#include <cstdio>
#include <unistd.h>
@@ -291,10 +292,12 @@ const OUString& SalGetDesktopEnvironment()
SalData::SalData() :
m_pInstance(NULL),
- m_pPlugin(NULL)
+ m_pPlugin(NULL),
+ m_pPIManager(NULL)
{
}
SalData::~SalData()
{
+ psp::PrinterInfoManager::release();
}
diff --git a/vcl/unx/source/printer/cupsmgr.cxx b/vcl/unx/source/printer/cupsmgr.cxx
index e245b2548c79..caf3249b5f46 100644
--- a/vcl/unx/source/printer/cupsmgr.cxx
+++ b/vcl/unx/source/printer/cupsmgr.cxx
@@ -524,12 +524,18 @@ void CUPSManager::initialize()
// introduced in dests with 1.2
// this is needed to check for %%IncludeFeature support
// (#i65684#, #i65491#)
+ bool bUsePDF = false;
cups_dest_t* pDest = ((cups_dest_t*)m_pDests);
const char* pOpt = m_pCUPSWrapper->cupsGetOption( "printer-info",
pDest->num_options,
pDest->options );
if( pOpt )
+ {
m_bUseIncludeFeature = true;
+ bUsePDF = true;
+ if( m_aGlobalDefaults.m_nPSLevel == 0 && m_aGlobalDefaults.m_nPDFDevice == 0 )
+ m_aGlobalDefaults.m_nPDFDevice = 1;
+ }
// do not send include JobPatch; CUPS will insert that itself
// TODO: currently unknwon which versions of CUPS insert JobPatches
// so currently it is assumed CUPS = don't insert JobPatch files
@@ -593,6 +599,8 @@ void CUPSManager::initialize()
aPrinter.m_aInfo.m_pParser = c_it->second.getParser();
aPrinter.m_aInfo.m_aContext = c_it->second;
}
+ if( bUsePDF && aPrinter.m_aInfo.m_nPSLevel == 0 && aPrinter.m_aInfo.m_nPDFDevice == 0 )
+ aPrinter.m_aInfo.m_nPDFDevice = 1;
aPrinter.m_aInfo.m_aDriverName = aBuf.makeStringAndClear();
aPrinter.m_bModified = false;
@@ -826,8 +834,15 @@ void CUPSManager::setupJobContextData(
FILE* CUPSManager::startSpool( const OUString& rPrintername, bool bQuickCommand )
{
+ OSL_TRACE( "endSpool: %s, %s",
+ rtl::OUStringToOString( rPrintername, RTL_TEXTENCODING_UTF8 ).getStr(),
+ bQuickCommand ? "true" : "false" );
+
if( m_aCUPSDestMap.find( rPrintername ) == m_aCUPSDestMap.end() )
+ {
+ OSL_TRACE( "defer to PrinterInfoManager::startSpool" );
return PrinterInfoManager::startSpool( rPrintername, bQuickCommand );
+ }
#ifdef ENABLE_CUPS
OUString aTmpURL, aTmpFile;
@@ -850,7 +865,7 @@ struct less_ppd_key : public ::std::binary_function<double, double, bool>
{ return left->getOrderDependency() < right->getOrderDependency(); }
};
-void CUPSManager::getOptionsFromDocumentSetup( const JobData& rJob, int& rNumOptions, void** rOptions ) const
+void CUPSManager::getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner, int& rNumOptions, void** rOptions ) const
{
rNumOptions = 0;
*rOptions = NULL;
@@ -880,10 +895,26 @@ void CUPSManager::getOptionsFromDocumentSetup( const JobData& rJob, int& rNumOpt
}
}
}
+
+ if( rJob.m_nPDFDevice > 0 && rJob.m_nCopies > 1 )
+ {
+ rtl::OString aVal( rtl::OString::valueOf( sal_Int32( rJob.m_nCopies ) ) );
+ rNumOptions = m_pCUPSWrapper->cupsAddOption( "copies", aVal.getStr(), rNumOptions, (cups_option_t**)rOptions );
+ }
+ if( ! bBanner )
+ {
+ rNumOptions = m_pCUPSWrapper->cupsAddOption( "job-sheets", "none", rNumOptions, (cups_option_t**)rOptions );
+ }
}
-int CUPSManager::endSpool( const OUString& rPrintername, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData )
+int CUPSManager::endSpool( const OUString& rPrintername, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner )
{
+ OSL_TRACE( "endSpool: %s, %s, copy count = %d",
+ rtl::OUStringToOString( rPrintername, RTL_TEXTENCODING_UTF8 ).getStr(),
+ rtl::OUStringToOString( rJobTitle, RTL_TEXTENCODING_UTF8 ).getStr(),
+ rDocumentJobData.m_nCopies
+ );
+
int nJobID = 0;
osl::MutexGuard aGuard( m_aCUPSMutex );
@@ -891,7 +922,10 @@ int CUPSManager::endSpool( const OUString& rPrintername, const OUString& rJobTit
std::hash_map< OUString, int, OUStringHash >::iterator dest_it =
m_aCUPSDestMap.find( rPrintername );
if( dest_it == m_aCUPSDestMap.end() )
- return PrinterInfoManager::endSpool( rPrintername, rJobTitle, pFile, rDocumentJobData );
+ {
+ OSL_TRACE( "defer to PrinterInfoManager::endSpool" );
+ return PrinterInfoManager::endSpool( rPrintername, rJobTitle, pFile, rDocumentJobData, bBanner );
+ }
#ifdef ENABLE_CUPS
std::hash_map< FILE*, OString, FPtrHash >::const_iterator it = m_aSpoolFiles.find( pFile );
@@ -903,7 +937,7 @@ int CUPSManager::endSpool( const OUString& rPrintername, const OUString& rJobTit
// setup cups options
int nNumOptions = 0;
cups_option_t* pOptions = NULL;
- getOptionsFromDocumentSetup( rDocumentJobData, nNumOptions, (void**)&pOptions );
+ getOptionsFromDocumentSetup( rDocumentJobData, bBanner, nNumOptions, (void**)&pOptions );
cups_dest_t* pDest = ((cups_dest_t*)m_pDests) + dest_it->second;
nJobID = m_pCUPSWrapper->cupsPrintFile( pDest->name,
diff --git a/vcl/unx/source/printer/jobdata.cxx b/vcl/unx/source/printer/jobdata.cxx
index a1bca9441f77..d4211eae31df 100644
--- a/vcl/unx/source/printer/jobdata.cxx
+++ b/vcl/unx/source/printer/jobdata.cxx
@@ -51,6 +51,7 @@ JobData& JobData::operator=(const JobData& rRight)
m_pParser = rRight.m_pParser;
m_aContext = rRight.m_aContext;
m_nPSLevel = rRight.m_nPSLevel;
+ m_nPDFDevice = rRight.m_nPDFDevice;
m_nColorDevice = rRight.m_nColorDevice;
if( ! m_pParser && m_aPrinterName.getLength() )
@@ -83,6 +84,34 @@ void JobData::setCollate( bool bCollate )
}
}
+bool JobData::setPaper( int i_nWidth, int i_nHeight )
+{
+ bool bSuccess = false;
+ if( m_pParser )
+ {
+ rtl::OUString aPaper( m_pParser->matchPaper( i_nWidth, i_nHeight ) );
+
+ const PPDKey* pKey = m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) ) );
+ const PPDValue* pValue = pKey ? pKey->getValueCaseInsensitive( aPaper ) : NULL;
+
+ bSuccess = pKey && pValue && m_aContext.setValue( pKey, pValue, false );
+ }
+ return bSuccess;
+}
+
+bool JobData::setPaperBin( int i_nPaperBin )
+{
+ bool bSuccess = false;
+ if( m_pParser )
+ {
+ const PPDKey* pKey = m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "InputSlot" ) ) );
+ const PPDValue* pValue = pKey ? pKey->getValue( i_nPaperBin ) : NULL;
+
+ bSuccess = pKey && pValue && m_aContext.setValue( pKey, pValue, false );
+ }
+ return bSuccess;
+}
+
bool JobData::getStreamBuffer( void*& pData, int& bytes )
{
// consistency checks
@@ -128,6 +157,10 @@ bool JobData::getStreamBuffer( void*& pData, int& bytes )
aLine += ByteString::CreateFromInt32( m_nPSLevel );
aStream.WriteLine( aLine );
+ aLine = "pdfdevice=";
+ aLine += ByteString::CreateFromInt32( m_nPDFDevice );
+ aStream.WriteLine( aLine );
+
aLine = "colordevice=";
aLine += ByteString::CreateFromInt32( m_nColorDevice );
aStream.WriteLine( aLine );
@@ -158,6 +191,7 @@ bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobDa
bool bColorDepth = false;
bool bColorDevice = false;
bool bPSLevel = false;
+ bool bPDFDevice = false;
while( ! aStream.IsEof() )
{
aStream.ReadLine( aLine );
@@ -202,6 +236,11 @@ bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobDa
bPSLevel = true;
rJobData.m_nPSLevel = aLine.Copy( 8 ).ToInt32();
}
+ else if( aLine.CompareTo( "pdfdevice=", 10 ) == COMPARE_EQUAL )
+ {
+ bPDFDevice = true;
+ rJobData.m_nPDFDevice = aLine.Copy( 10 ).ToInt32();
+ }
else if( aLine.Equals( "PPDContexData" ) )
{
if( bPrinter )
@@ -222,5 +261,5 @@ bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobDa
}
}
- return bVersion && bPrinter && bOrientation && bCopies && bContext && bMargin && bPSLevel && bColorDevice && bColorDepth;
+ return bVersion && bPrinter && bOrientation && bCopies && bContext && bMargin && bPSLevel && bPDFDevice && bColorDevice && bColorDepth;
}
diff --git a/vcl/unx/source/printer/printerinfomanager.cxx b/vcl/unx/source/printer/printerinfomanager.cxx
index e1d499c40ca5..bd6ce761e989 100644
--- a/vcl/unx/source/printer/printerinfomanager.cxx
+++ b/vcl/unx/source/printer/printerinfomanager.cxx
@@ -35,6 +35,7 @@
#include "cupsmgr.hxx"
#include "vcl/fontmanager.hxx"
#include "vcl/strhelper.hxx"
+#include "saldata.hxx"
#include "tools/urlobj.hxx"
#include "tools/stream.hxx"
@@ -92,22 +93,28 @@ namespace psp
PrinterInfoManager& PrinterInfoManager::get()
{
- static PrinterInfoManager* pManager = NULL;
+ SalData* pSalData = GetSalData();
- if( ! pManager )
+ if( ! pSalData->m_pPIManager )
{
- pManager = CUPSManager::tryLoadCUPS();
- if( ! pManager )
- pManager = new PrinterInfoManager();
+ pSalData->m_pPIManager = CUPSManager::tryLoadCUPS();
+ if( ! pSalData->m_pPIManager )
+ pSalData->m_pPIManager = new PrinterInfoManager();
- if( pManager )
- pManager->initialize();
+ pSalData->m_pPIManager->initialize();
#if OSL_DEBUG_LEVEL > 1
- fprintf( stderr, "PrinterInfoManager::get create Manager of type %d\n", pManager->getType() );
+ fprintf( stderr, "PrinterInfoManager::get create Manager of type %d\n", pSalData->m_pPIManager->getType() );
#endif
}
- return *pManager;
+ return *pSalData->m_pPIManager;
+}
+
+void PrinterInfoManager::release()
+{
+ SalData* pSalData = GetSalData();
+ delete pSalData->m_pPIManager;
+ pSalData->m_pPIManager = NULL;
}
// -----------------------------------------------------------------
@@ -130,6 +137,9 @@ PrinterInfoManager::PrinterInfoManager( Type eType ) :
PrinterInfoManager::~PrinterInfoManager()
{
delete m_pQueueInfo;
+ #if OSL_DEBUG_LEVEL > 1
+ fprintf( stderr, "PrinterInfoManager: destroyed Manager of type %d\n", getType() );
+ #endif
}
// -----------------------------------------------------------------
@@ -283,6 +293,10 @@ void PrinterInfoManager::initialize()
if( aValue.Len() )
m_aGlobalDefaults.m_nPSLevel = aValue.ToInt32();
+ aValue = aConfig.ReadKey( "PDFDevice" );
+ if( aValue.Len() )
+ m_aGlobalDefaults.m_nPDFDevice = aValue.ToInt32();
+
aValue = aConfig.ReadKey( "PerformFontSubstitution" );
if( aValue.Len() )
{
@@ -324,7 +338,7 @@ void PrinterInfoManager::initialize()
}
}
#if OSL_DEBUG_LEVEL > 1
- fprintf( stderr, "global settings: fontsubst = %s, %d substitutes\n", m_aGlobalDefaults.m_bPerformFontSubstitution ? "true" : "false", m_aGlobalDefaults.m_aFontSubstitutes.size() );
+ fprintf( stderr, "global settings: fontsubst = %s, %d substitutes\n", m_aGlobalDefaults.m_bPerformFontSubstitution ? "true" : "false", (int)m_aGlobalDefaults.m_aFontSubstitutes.size() );
#endif
}
}
@@ -494,6 +508,10 @@ void PrinterInfoManager::initialize()
if( aValue.Len() )
aPrinter.m_aInfo.m_nPSLevel = aValue.ToInt32();
+ aValue = aConfig.ReadKey( "PDFDevice" );
+ if( aValue.Len() )
+ aPrinter.m_aInfo.m_nPDFDevice = aValue.ToInt32();
+
aValue = aConfig.ReadKey( "PerformFontSubstitution" );
if( ! aValue.Equals( "0" ) && ! aValue.EqualsIgnoreCaseAscii( "false" ) )
aPrinter.m_aInfo.m_bPerformFontSubstitution = true;
@@ -758,6 +776,7 @@ bool PrinterInfoManager::writePrinterConfig()
pConfig->WriteKey( "Copies", ByteString::CreateFromInt32( it->second.m_aInfo.m_nCopies ) );
pConfig->WriteKey( "Orientation", it->second.m_aInfo.m_eOrientation == orientation::Landscape ? "Landscape" : "Portrait" );
pConfig->WriteKey( "PSLevel", ByteString::CreateFromInt32( it->second.m_aInfo.m_nPSLevel ) );
+ pConfig->WriteKey( "PDFDevice", ByteString::CreateFromInt32( it->second.m_aInfo.m_nPDFDevice ) );
pConfig->WriteKey( "ColorDevice", ByteString::CreateFromInt32( it->second.m_aInfo.m_nColorDevice ) );
pConfig->WriteKey( "ColorDepth", ByteString::CreateFromInt32( it->second.m_aInfo.m_nColorDepth ) );
aValue = ByteString::CreateFromInt32( it->second.m_aInfo.m_nLeftMarginAdjust );
@@ -845,9 +864,10 @@ bool PrinterInfoManager::addPrinter( const OUString& rPrinterName, const OUStrin
m_aPrinters[ rPrinterName ] = aPrinter;
bSuccess = true;
#if OSL_DEBUG_LEVEL > 1
- fprintf( stderr, "new printer %s, level = %d, colordevice = %d, depth = %d\n",
+ fprintf( stderr, "new printer %s, level = %d, pdfdevice = %d, colordevice = %d, depth = %d\n",
OUStringToOString( rPrinterName, osl_getThreadTextEncoding() ).getStr(),
m_aPrinters[rPrinterName].m_aInfo.m_nPSLevel,
+ m_aPrinters[rPrinterName].m_aInfo.m_nPDFDevice,
m_aPrinters[rPrinterName].m_aInfo.m_nColorDevice,
m_aPrinters[rPrinterName].m_aInfo.m_nColorDepth );
#endif
@@ -1095,7 +1115,7 @@ FILE* PrinterInfoManager::startSpool( const OUString& rPrintername, bool bQuickC
return popen (aShellCommand.getStr(), "w");
}
-int PrinterInfoManager::endSpool( const OUString& /*rPrintername*/, const OUString& /*rJobTitle*/, FILE* pFile, const JobData& /*rDocumentJobData*/ )
+int PrinterInfoManager::endSpool( const OUString& /*rPrintername*/, const OUString& /*rJobTitle*/, FILE* pFile, const JobData& /*rDocumentJobData*/, bool /*bBanner*/ )
{
return (0 == pclose( pFile ));
}
@@ -1166,7 +1186,11 @@ SystemQueueInfo::SystemQueueInfo() :
SystemQueueInfo::~SystemQueueInfo()
{
- terminate();
+ static const char* pNoSyncDetection = getenv( "SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION" );
+ if( ! pNoSyncDetection || !*pNoSyncDetection )
+ join();
+ else
+ terminate();
}
bool SystemQueueInfo::hasChanged() const
diff --git a/vcl/unx/source/printergfx/printerjob.cxx b/vcl/unx/source/printergfx/printerjob.cxx
index 5e18849b8dfe..26a1d75f68c2 100644
--- a/vcl/unx/source/printergfx/printerjob.cxx
+++ b/vcl/unx/source/printergfx/printerjob.cxx
@@ -341,7 +341,8 @@ PrinterJob::~PrinterJob ()
delete mpJobTrailer;
// XXX should really call osl::remove routines
- removeSpoolDir (maSpoolDirName);
+ if( maSpoolDirName.getLength() )
+ removeSpoolDir (maSpoolDirName);
// osl::Directory::remove (maSpoolDirName);
}
@@ -610,7 +611,7 @@ PrinterJob::EndJob ()
{
PrinterInfoManager& rPrinterInfoManager = PrinterInfoManager::get();
if (0 == rPrinterInfoManager.endSpool( m_aLastJobData.m_aPrinterName,
- maJobTitle, pDestFILE, m_aDocumentJobData ))
+ maJobTitle, pDestFILE, m_aDocumentJobData, true ))
{
bSuccess = sal_False;
}