bump product version to 5.0.4.1
[LibreOffice.git] / vcl / headless / svpprn.cxx
blobcc7034930bd096f9a27e86518a9204460085431d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
24 #include "jobset.h"
25 #include "print.h"
26 #include "salptype.hxx"
27 #include "saldatabasic.hxx"
29 #include "generic/genpspgraphics.h"
31 #include "headless/svpprn.hxx"
32 #include "headless/svpinst.hxx"
34 using namespace psp;
37 * static helpers
40 static OUString getPdfDir( const PrinterInfo& rInfo )
42 OUString aDir;
43 sal_Int32 nIndex = 0;
44 while( nIndex != -1 )
46 OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
47 if( aToken.startsWith( "pdf=" ) )
49 sal_Int32 nPos = 0;
50 aDir = aToken.getToken( 1, '=', nPos );
51 if( aDir.isEmpty() )
52 aDir = OStringToOUString( OString( getenv( "HOME" ) ), osl_getThreadTextEncoding() );
53 break;
56 return aDir;
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);
65 // copy page size
66 OUString aPaper;
67 int width, height;
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;
84 else
86 pJobSetup->mnPaperWidth = height;
87 pJobSetup->mnPaperHeight= width;
91 // copy input slot
92 const PPDKey* pKey = NULL;
93 const PPDValue* pValue = NULL;
95 pJobSetup->mnPaperBin = 0xffff;
96 if( rData.m_pParser )
97 pKey = rData.m_pParser->getKey( OUString( "InputSlot" ) );
98 if( pKey )
99 pValue = rData.m_aContext.getValue( pKey );
100 if( pKey && pValue )
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;
111 // copy duplex
112 pKey = NULL;
113 pValue = NULL;
115 pJobSetup->meDuplexMode = DUPLEX_UNKNOWN;
116 if( rData.m_pParser )
117 pKey = rData.m_pParser->getKey( OUString( "Duplex" ) );
118 if( pKey )
119 pValue = rData.m_aContext.getValue( pKey );
120 if( pKey && pValue )
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 );
142 int nBytes;
143 void* pBuffer = NULL;
144 if( rData.getStreamBuffer( pBuffer, nBytes ) )
146 pJobSetup->mnDriverDataLen = nBytes;
147 pJobSetup->mpDriverData = static_cast<sal_uInt8*>(pBuffer);
149 else
151 pJobSetup->mnDriverDataLen = 0;
152 pJobSetup->mpDriverData = NULL;
156 // SalInstance
158 SalInfoPrinter* SvpSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
159 ImplJobSetup* pJobSetup )
161 // create and initialize SalInfoPrinter
162 SvpSalInfoPrinter* pPrinter = new SvpSalInfoPrinter();
164 if( pJobSetup )
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 );
180 return pPrinter;
183 void SvpSalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter )
185 delete 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;
194 return pPrinter;
197 void SvpSalInstance::DestroyPrinter( SalPrinter* pPrinter )
199 delete 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 );
232 break;
236 pList->Add( pInfo );
240 void SvpSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
242 delete 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* )
270 return false;
273 SvpSalPrinter::SvpSalPrinter( SalInfoPrinter* pInfoPrinter )
274 : PspSalPrinter( pInfoPrinter )
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */