Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / vcl / headless / svpprn.cxx
blobf50db9a69ec95031f0bc9d09b7d6dab629066287
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 .
21 #include "vcl/svapp.hxx"
22 #include "vcl/timer.hxx"
23 #include "vcl/printerinfomanager.hxx"
25 #include "jobset.h"
26 #include "print.h"
27 #include "salptype.hxx"
28 #include "saldatabasic.hxx"
30 #include "generic/genpspgraphics.h"
32 #include "headless/svpprn.hxx"
33 #include "headless/svpinst.hxx"
35 using namespace psp;
38 * static helpers
41 static OUString getPdfDir( const PrinterInfo& rInfo )
43 OUString aDir;
44 sal_Int32 nIndex = 0;
45 while( nIndex != -1 )
47 OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
48 if( aToken.startsWith( "pdf=" ) )
50 sal_Int32 nPos = 0;
51 aDir = aToken.getToken( 1, '=', nPos );
52 if( aDir.isEmpty() )
53 aDir = OStringToOUString( OString( getenv( "HOME" ) ), osl_getThreadTextEncoding() );
54 break;
57 return aDir;
60 inline int PtTo10Mu( int nPoints ) { return (int)((((double)nPoints)*35.27777778)+0.5); }
62 inline int TenMuToPt( int nUnits ) { return (int)((((double)nUnits)/35.27777778)+0.5); }
64 static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, JobData& rData )
66 pJobSetup->meOrientation = (Orientation)(rData.m_eOrientation == orientation::Landscape ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);
68 // copy page size
69 OUString aPaper;
70 int width, height;
72 rData.m_aContext.getPageSize( aPaper, width, height );
73 pJobSetup->mePaperFormat = PaperInfo::fromPSName(OUStringToOString( aPaper, RTL_TEXTENCODING_ISO_8859_1 ));
74 pJobSetup->mnPaperWidth = 0;
75 pJobSetup->mnPaperHeight = 0;
76 if( pJobSetup->mePaperFormat == PAPER_USER )
78 // transform to 100dth mm
79 width = PtTo10Mu( width );
80 height = PtTo10Mu( height );
82 if( rData.m_eOrientation == psp::orientation::Portrait )
84 pJobSetup->mnPaperWidth = width;
85 pJobSetup->mnPaperHeight= height;
87 else
89 pJobSetup->mnPaperWidth = height;
90 pJobSetup->mnPaperHeight= width;
94 // copy input slot
95 const PPDKey* pKey = NULL;
96 const PPDValue* pValue = NULL;
98 pJobSetup->mnPaperBin = 0xffff;
99 if( rData.m_pParser )
100 pKey = rData.m_pParser->getKey( OUString( "InputSlot" ) );
101 if( pKey )
102 pValue = rData.m_aContext.getValue( pKey );
103 if( pKey && pValue )
105 for( pJobSetup->mnPaperBin = 0;
106 pValue != pKey->getValue( pJobSetup->mnPaperBin ) &&
107 pJobSetup->mnPaperBin < pKey->countValues();
108 pJobSetup->mnPaperBin++ )
110 if( pJobSetup->mnPaperBin >= pKey->countValues() || pValue == pKey->getDefaultValue() )
111 pJobSetup->mnPaperBin = 0xffff;
114 // copy duplex
115 pKey = NULL;
116 pValue = NULL;
118 pJobSetup->meDuplexMode = DUPLEX_UNKNOWN;
119 if( rData.m_pParser )
120 pKey = rData.m_pParser->getKey( OUString( "Duplex" ) );
121 if( pKey )
122 pValue = rData.m_aContext.getValue( pKey );
123 if( pKey && pValue )
125 if( pValue->m_aOption.equalsIgnoreAsciiCase( "None" ) ||
126 pValue->m_aOption.startsWithIgnoreAsciiCase( "Simplex" )
129 pJobSetup->meDuplexMode = DUPLEX_OFF;
131 else if( pValue->m_aOption.equalsIgnoreAsciiCase( "DuplexNoTumble" ) )
133 pJobSetup->meDuplexMode = DUPLEX_LONGEDGE;
135 else if( pValue->m_aOption.equalsIgnoreAsciiCase( "DuplexTumble" ) )
137 pJobSetup->meDuplexMode = DUPLEX_SHORTEDGE;
141 // copy the whole context
142 if( pJobSetup->mpDriverData )
143 rtl_freeMemory( pJobSetup->mpDriverData );
145 int nBytes;
146 void* pBuffer = NULL;
147 if( rData.getStreamBuffer( pBuffer, nBytes ) )
149 pJobSetup->mnDriverDataLen = nBytes;
150 pJobSetup->mpDriverData = (sal_uInt8*)pBuffer;
152 else
154 pJobSetup->mnDriverDataLen = 0;
155 pJobSetup->mpDriverData = NULL;
160 * SalInstance
163 SalInfoPrinter* SvpSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
164 ImplJobSetup* pJobSetup )
166 // create and initialize SalInfoPrinter
167 SvpSalInfoPrinter* pPrinter = new SvpSalInfoPrinter();
169 if( pJobSetup )
171 PrinterInfoManager& rManager( PrinterInfoManager::get() );
172 PrinterInfo aInfo( rManager.getPrinterInfo( pQueueInfo->maPrinterName ) );
173 pPrinter->m_aJobData = aInfo;
174 pPrinter->m_aPrinterGfx.Init( pPrinter->m_aJobData );
176 if( pJobSetup->mpDriverData )
177 JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aInfo );
179 pJobSetup->mnSystem = JOBSETUP_SYSTEM_UNIX;
180 pJobSetup->maPrinterName = pQueueInfo->maPrinterName;
181 pJobSetup->maDriver = aInfo.m_aDriverName;
182 copyJobDataToJobSetup( pJobSetup, aInfo );
186 return pPrinter;
189 void SvpSalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter )
191 delete pPrinter;
194 SalPrinter* SvpSalInstance::CreatePrinter( SalInfoPrinter* pInfoPrinter )
196 // create and initialize SalPrinter
197 SvpSalPrinter* pPrinter = new SvpSalPrinter( pInfoPrinter );
198 pPrinter->m_aJobData = static_cast<SvpSalInfoPrinter*>(pInfoPrinter)->m_aJobData;
200 return pPrinter;
203 void SvpSalInstance::DestroyPrinter( SalPrinter* pPrinter )
205 delete pPrinter;
208 void SvpSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
210 PrinterInfoManager& rManager( PrinterInfoManager::get() );
211 static const char* pNoSyncDetection = getenv( "SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION" );
212 if( ! pNoSyncDetection || ! *pNoSyncDetection )
214 // #i62663# synchronize possible asynchronouse printer detection now
215 rManager.checkPrintersChanged( true );
217 ::std::list< OUString > aPrinters;
218 rManager.listPrinters( aPrinters );
220 for( ::std::list< OUString >::iterator it = aPrinters.begin(); it != aPrinters.end(); ++it )
222 const PrinterInfo& rInfo( rManager.getPrinterInfo( *it ) );
223 // Neuen Eintrag anlegen
224 SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo;
225 pInfo->maPrinterName = *it;
226 pInfo->maDriver = rInfo.m_aDriverName;
227 pInfo->maLocation = rInfo.m_aLocation;
228 pInfo->maComment = rInfo.m_aComment;
229 pInfo->mpSysData = NULL;
231 sal_Int32 nIndex = 0;
232 while( nIndex != -1 )
234 OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
235 if( aToken.startsWith( "pdf=" ) )
237 pInfo->maLocation = getPdfDir( rInfo );
238 break;
242 pList->Add( pInfo );
246 void SvpSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
248 delete pInfo;
251 void SvpSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* )
255 OUString SvpSalInstance::GetDefaultPrinter()
257 PrinterInfoManager& rManager( PrinterInfoManager::get() );
258 return rManager.getDefaultPrinter();
261 void SvpSalInstance::PostPrintersChanged()
263 const std::list< SalFrame* >& rList = SvpSalInstance::s_pDefaultInstance->getFrames();
264 for( std::list< SalFrame* >::const_iterator it = rList.begin();
265 it != rList.end(); ++it )
266 SvpSalInstance::s_pDefaultInstance->PostEvent( *it, NULL, SALEVENT_PRINTERCHANGED );
269 GenPspGraphics *SvpSalInstance::CreatePrintGraphics()
271 return new GenPspGraphics();
274 sal_Bool SvpSalInfoPrinter::Setup( SalFrame*, ImplJobSetup* )
276 return sal_False;
279 SvpSalPrinter::SvpSalPrinter( SalInfoPrinter* pInfoPrinter )
280 : PspSalPrinter( pInfoPrinter )
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */