nss: upgrade to release 3.73
[LibreOffice.git] / vcl / headless / svpprn.cxx
blob7ecb59f8c0b2412e8e639faed7c67ad02a27e83f
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/QueueInfo.hxx>
23 #include <printerinfomanager.hxx>
25 #include <jobset.h>
26 #include <print.h>
27 #include <salptype.hxx>
28 #include <saldatabasic.hxx>
30 #include <unx/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 static int PtTo10Mu( int nPoints ) { return static_cast<int>((static_cast<double>(nPoints)*35.27777778)+0.5); }
62 static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, JobData& rData )
64 pJobSetup->SetOrientation( rData.m_eOrientation == orientation::Landscape ? Orientation::Landscape : Orientation::Portrait );
66 // copy page size
67 OUString aPaper;
68 int width, height;
70 rData.m_aContext.getPageSize( aPaper, width, height );
71 pJobSetup->SetPaperFormat( PaperInfo::fromPSName(OUStringToOString( aPaper, RTL_TEXTENCODING_ISO_8859_1 )) );
72 pJobSetup->SetPaperWidth( 0 );
73 pJobSetup->SetPaperHeight( 0 );
74 if( pJobSetup->GetPaperFormat() == PAPER_USER )
76 // transform to 100dth mm
77 width = PtTo10Mu( width );
78 height = PtTo10Mu( height );
80 if( rData.m_eOrientation == psp::orientation::Portrait )
82 pJobSetup->SetPaperWidth( width );
83 pJobSetup->SetPaperHeight( height );
85 else
87 pJobSetup->SetPaperWidth( height );
88 pJobSetup->SetPaperHeight( width );
92 // copy input slot
93 const PPDKey* pKey = nullptr;
94 const PPDValue* pValue = nullptr;
96 pJobSetup->SetPaperBin( 0xffff );
97 if( rData.m_pParser )
98 pKey = rData.m_pParser->getKey( "InputSlot" );
99 if( pKey )
100 pValue = rData.m_aContext.getValue( pKey );
101 if( pKey && pValue )
103 int nPaperBin;
104 for( nPaperBin = 0;
105 pValue != pKey->getValue( nPaperBin ) &&
106 nPaperBin < pKey->countValues();
107 nPaperBin++ );
108 pJobSetup->SetPaperBin(
109 (nPaperBin == pKey->countValues()
110 || pValue == pKey->getDefaultValue())
111 ? 0xffff : nPaperBin);
114 // copy duplex
115 pKey = nullptr;
116 pValue = nullptr;
118 pJobSetup->SetDuplexMode( DuplexMode::Unknown );
119 if( rData.m_pParser )
120 pKey = rData.m_pParser->getKey( "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->SetDuplexMode( DuplexMode::Off );
131 else if( pValue->m_aOption.equalsIgnoreAsciiCase( "DuplexNoTumble" ) )
133 pJobSetup->SetDuplexMode( DuplexMode::LongEdge );
135 else if( pValue->m_aOption.equalsIgnoreAsciiCase( "DuplexTumble" ) )
137 pJobSetup->SetDuplexMode( DuplexMode::ShortEdge );
141 // copy the whole context
142 if( pJobSetup->GetDriverData() )
143 std::free( const_cast<sal_uInt8*>(pJobSetup->GetDriverData()) );
145 sal_uInt32 nBytes;
146 void* pBuffer = nullptr;
147 if( rData.getStreamBuffer( pBuffer, nBytes ) )
149 pJobSetup->SetDriverDataLen( nBytes );
150 pJobSetup->SetDriverData( static_cast<sal_uInt8*>(pBuffer) );
152 else
154 pJobSetup->SetDriverDataLen( 0 );
155 pJobSetup->SetDriverData( nullptr );
159 // SalInstance
161 SalInfoPrinter* SvpSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
162 ImplJobSetup* pJobSetup )
164 // create and initialize SalInfoPrinter
165 SvpSalInfoPrinter* pPrinter = new SvpSalInfoPrinter;
167 if( pJobSetup )
169 PrinterInfoManager& rManager( PrinterInfoManager::get() );
170 PrinterInfo aInfo( rManager.getPrinterInfo( pQueueInfo->maPrinterName ) );
171 pPrinter->m_aJobData = aInfo;
172 pPrinter->m_aPrinterGfx.Init( pPrinter->m_aJobData );
174 if( pJobSetup->GetDriverData() )
175 JobData::constructFromStreamBuffer( pJobSetup->GetDriverData(),
176 pJobSetup->GetDriverDataLen(), aInfo );
178 pJobSetup->SetSystem( JOBSETUP_SYSTEM_UNIX );
179 pJobSetup->SetPrinterName( pQueueInfo->maPrinterName );
180 pJobSetup->SetDriver( aInfo.m_aDriverName );
181 copyJobDataToJobSetup( pJobSetup, aInfo );
184 return pPrinter;
187 void SvpSalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter )
189 delete pPrinter;
192 std::unique_ptr<SalPrinter> SvpSalInstance::CreatePrinter( SalInfoPrinter* pInfoPrinter )
194 // create and initialize SalPrinter
195 SvpSalPrinter* pPrinter = new SvpSalPrinter( pInfoPrinter );
196 pPrinter->m_aJobData = static_cast<SvpSalInfoPrinter*>(pInfoPrinter)->m_aJobData;
198 return std::unique_ptr<SalPrinter>(pPrinter);
201 void SvpSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
203 PrinterInfoManager& rManager( PrinterInfoManager::get() );
204 static const char* pNoSyncDetection = getenv( "SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION" );
205 if( ! pNoSyncDetection || ! *pNoSyncDetection )
207 // #i62663# synchronize possible asynchronouse printer detection now
208 rManager.checkPrintersChanged( true );
210 ::std::vector< OUString > aPrinters;
211 rManager.listPrinters( aPrinters );
213 for (auto const& printer : aPrinters)
215 const PrinterInfo& rInfo( rManager.getPrinterInfo(printer) );
216 // create new entry
217 std::unique_ptr<SalPrinterQueueInfo> pInfo(new SalPrinterQueueInfo);
218 pInfo->maPrinterName = printer;
219 pInfo->maDriver = rInfo.m_aDriverName;
220 pInfo->maLocation = rInfo.m_aLocation;
221 pInfo->maComment = rInfo.m_aComment;
223 sal_Int32 nIndex = 0;
224 while( nIndex != -1 )
226 OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
227 if( aToken.startsWith( "pdf=" ) )
229 pInfo->maLocation = getPdfDir( rInfo );
230 break;
234 pList->Add( std::move(pInfo) );
238 void SvpSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* )
242 OUString SvpSalInstance::GetDefaultPrinter()
244 PrinterInfoManager& rManager( PrinterInfoManager::get() );
245 return rManager.getDefaultPrinter();
248 void SvpSalInstance::PostPrintersChanged()
250 SvpSalInstance *pInst = SvpSalInstance::s_pDefaultInstance;
251 for (auto pSalFrame : pInst->getFrames() )
252 pInst->PostEvent( pSalFrame, nullptr, SalEvent::PrinterChanged );
255 std::unique_ptr<GenPspGraphics> SvpSalInstance::CreatePrintGraphics()
257 return std::make_unique<GenPspGraphics>();
260 bool SvpSalInfoPrinter::Setup( weld::Window*, ImplJobSetup* )
262 return false;
265 SvpSalPrinter::SvpSalPrinter( SalInfoPrinter* pInfoPrinter )
266 : PspSalPrinter( pInfoPrinter )
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */