1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "vcl/svapp.hxx"
21 #include "vcl/timer.hxx"
22 #include "vcl/printerinfomanager.hxx"
26 #include "salptype.hxx"
27 #include "saldatabasic.hxx"
29 #include "generic/genpspgraphics.h"
31 #include "headless/svpprn.hxx"
32 #include "headless/svpinst.hxx"
40 static OUString
getPdfDir( const PrinterInfo
& rInfo
)
46 OUString
aToken( rInfo
.m_aFeatures
.getToken( 0, ',', nIndex
) );
47 if( aToken
.startsWith( "pdf=" ) )
50 aDir
= aToken
.getToken( 1, '=', nPos
);
52 aDir
= OStringToOUString( OString( getenv( "HOME" ) ), osl_getThreadTextEncoding() );
59 inline int PtTo10Mu( int nPoints
) { return (int)((((double)nPoints
)*35.27777778)+0.5); }
61 static void copyJobDataToJobSetup( ImplJobSetup
* pJobSetup
, JobData
& rData
)
63 pJobSetup
->meOrientation
= (Orientation
)(rData
.m_eOrientation
== orientation::Landscape
? ORIENTATION_LANDSCAPE
: ORIENTATION_PORTRAIT
);
69 rData
.m_aContext
.getPageSize( aPaper
, width
, height
);
70 pJobSetup
->mePaperFormat
= PaperInfo::fromPSName(OUStringToOString( aPaper
, RTL_TEXTENCODING_ISO_8859_1
));
71 pJobSetup
->mnPaperWidth
= 0;
72 pJobSetup
->mnPaperHeight
= 0;
73 if( pJobSetup
->mePaperFormat
== PAPER_USER
)
75 // transform to 100dth mm
76 width
= PtTo10Mu( width
);
77 height
= PtTo10Mu( height
);
79 if( rData
.m_eOrientation
== psp::orientation::Portrait
)
81 pJobSetup
->mnPaperWidth
= width
;
82 pJobSetup
->mnPaperHeight
= height
;
86 pJobSetup
->mnPaperWidth
= height
;
87 pJobSetup
->mnPaperHeight
= width
;
92 const PPDKey
* pKey
= NULL
;
93 const PPDValue
* pValue
= NULL
;
95 pJobSetup
->mnPaperBin
= 0xffff;
97 pKey
= rData
.m_pParser
->getKey( OUString( "InputSlot" ) );
99 pValue
= rData
.m_aContext
.getValue( pKey
);
102 for( pJobSetup
->mnPaperBin
= 0;
103 pValue
!= pKey
->getValue( pJobSetup
->mnPaperBin
) &&
104 pJobSetup
->mnPaperBin
< pKey
->countValues();
105 pJobSetup
->mnPaperBin
++ )
107 if( pJobSetup
->mnPaperBin
>= pKey
->countValues() || pValue
== pKey
->getDefaultValue() )
108 pJobSetup
->mnPaperBin
= 0xffff;
115 pJobSetup
->meDuplexMode
= DUPLEX_UNKNOWN
;
116 if( rData
.m_pParser
)
117 pKey
= rData
.m_pParser
->getKey( OUString( "Duplex" ) );
119 pValue
= rData
.m_aContext
.getValue( pKey
);
122 if( pValue
->m_aOption
.equalsIgnoreAsciiCase( "None" ) ||
123 pValue
->m_aOption
.startsWithIgnoreAsciiCase( "Simplex" )
126 pJobSetup
->meDuplexMode
= DUPLEX_OFF
;
128 else if( pValue
->m_aOption
.equalsIgnoreAsciiCase( "DuplexNoTumble" ) )
130 pJobSetup
->meDuplexMode
= DUPLEX_LONGEDGE
;
132 else if( pValue
->m_aOption
.equalsIgnoreAsciiCase( "DuplexTumble" ) )
134 pJobSetup
->meDuplexMode
= DUPLEX_SHORTEDGE
;
138 // copy the whole context
139 if( pJobSetup
->mpDriverData
)
140 rtl_freeMemory( pJobSetup
->mpDriverData
);
143 void* pBuffer
= NULL
;
144 if( rData
.getStreamBuffer( pBuffer
, nBytes
) )
146 pJobSetup
->mnDriverDataLen
= nBytes
;
147 pJobSetup
->mpDriverData
= static_cast<sal_uInt8
*>(pBuffer
);
151 pJobSetup
->mnDriverDataLen
= 0;
152 pJobSetup
->mpDriverData
= NULL
;
158 SalInfoPrinter
* SvpSalInstance::CreateInfoPrinter( SalPrinterQueueInfo
* pQueueInfo
,
159 ImplJobSetup
* pJobSetup
)
161 // create and initialize SalInfoPrinter
162 SvpSalInfoPrinter
* pPrinter
= new SvpSalInfoPrinter();
166 PrinterInfoManager
& rManager( PrinterInfoManager::get() );
167 PrinterInfo
aInfo( rManager
.getPrinterInfo( pQueueInfo
->maPrinterName
) );
168 pPrinter
->m_aJobData
= aInfo
;
169 pPrinter
->m_aPrinterGfx
.Init( pPrinter
->m_aJobData
);
171 if( pJobSetup
->mpDriverData
)
172 JobData::constructFromStreamBuffer( pJobSetup
->mpDriverData
, pJobSetup
->mnDriverDataLen
, aInfo
);
174 pJobSetup
->mnSystem
= JOBSETUP_SYSTEM_UNIX
;
175 pJobSetup
->maPrinterName
= pQueueInfo
->maPrinterName
;
176 pJobSetup
->maDriver
= aInfo
.m_aDriverName
;
177 copyJobDataToJobSetup( pJobSetup
, aInfo
);
183 void SvpSalInstance::DestroyInfoPrinter( SalInfoPrinter
* pPrinter
)
188 SalPrinter
* SvpSalInstance::CreatePrinter( SalInfoPrinter
* pInfoPrinter
)
190 // create and initialize SalPrinter
191 SvpSalPrinter
* pPrinter
= new SvpSalPrinter( pInfoPrinter
);
192 pPrinter
->m_aJobData
= static_cast<SvpSalInfoPrinter
*>(pInfoPrinter
)->m_aJobData
;
197 void SvpSalInstance::DestroyPrinter( SalPrinter
* pPrinter
)
202 void SvpSalInstance::GetPrinterQueueInfo( ImplPrnQueueList
* pList
)
204 PrinterInfoManager
& rManager( PrinterInfoManager::get() );
205 static const char* pNoSyncDetection
= getenv( "SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION" );
206 if( ! pNoSyncDetection
|| ! *pNoSyncDetection
)
208 // #i62663# synchronize possible asynchronouse printer detection now
209 rManager
.checkPrintersChanged( true );
211 ::std::list
< OUString
> aPrinters
;
212 rManager
.listPrinters( aPrinters
);
214 for( ::std::list
< OUString
>::iterator it
= aPrinters
.begin(); it
!= aPrinters
.end(); ++it
)
216 const PrinterInfo
& rInfo( rManager
.getPrinterInfo( *it
) );
217 // Neuen Eintrag anlegen
218 SalPrinterQueueInfo
* pInfo
= new SalPrinterQueueInfo
;
219 pInfo
->maPrinterName
= *it
;
220 pInfo
->maDriver
= rInfo
.m_aDriverName
;
221 pInfo
->maLocation
= rInfo
.m_aLocation
;
222 pInfo
->maComment
= rInfo
.m_aComment
;
223 pInfo
->mpSysData
= NULL
;
225 sal_Int32 nIndex
= 0;
226 while( nIndex
!= -1 )
228 OUString
aToken( rInfo
.m_aFeatures
.getToken( 0, ',', nIndex
) );
229 if( aToken
.startsWith( "pdf=" ) )
231 pInfo
->maLocation
= getPdfDir( rInfo
);
240 void SvpSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo
* pInfo
)
245 void SvpSalInstance::GetPrinterQueueState( SalPrinterQueueInfo
* )
249 OUString
SvpSalInstance::GetDefaultPrinter()
251 PrinterInfoManager
& rManager( PrinterInfoManager::get() );
252 return rManager
.getDefaultPrinter();
255 void SvpSalInstance::PostPrintersChanged()
257 const std::list
< SalFrame
* >& rList
= SvpSalInstance::s_pDefaultInstance
->getFrames();
258 for( std::list
< SalFrame
* >::const_iterator it
= rList
.begin();
259 it
!= rList
.end(); ++it
)
260 SvpSalInstance::s_pDefaultInstance
->PostEvent( *it
, NULL
, SALEVENT_PRINTERCHANGED
);
263 GenPspGraphics
*SvpSalInstance::CreatePrintGraphics()
265 return new GenPspGraphics();
268 bool SvpSalInfoPrinter::Setup( SalFrame
*, ImplJobSetup
* )
273 SvpSalPrinter::SvpSalPrinter( SalInfoPrinter
* pInfoPrinter
)
274 : PspSalPrinter( pInfoPrinter
)
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */