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 "printerinfomanager.hxx"
26 #include "salptype.hxx"
27 #include "saldatabasic.hxx"
29 #include "unx/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
->SetOrientation( rData
.m_eOrientation
== orientation::Landscape
? Orientation::Landscape
: Orientation::Portrait
);
69 rData
.m_aContext
.getPageSize( aPaper
, width
, height
);
70 pJobSetup
->SetPaperFormat( PaperInfo::fromPSName(OUStringToOString( aPaper
, RTL_TEXTENCODING_ISO_8859_1
)) );
71 pJobSetup
->SetPaperWidth( 0 );
72 pJobSetup
->SetPaperHeight( 0 );
73 if( pJobSetup
->GetPaperFormat() == 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
->SetPaperWidth( width
);
82 pJobSetup
->SetPaperHeight( height
);
86 pJobSetup
->SetPaperWidth( height
);
87 pJobSetup
->SetPaperHeight( width
);
92 const PPDKey
* pKey
= nullptr;
93 const PPDValue
* pValue
= nullptr;
95 pJobSetup
->SetPaperBin( 0xffff );
97 pKey
= rData
.m_pParser
->getKey( OUString( "InputSlot" ) );
99 pValue
= rData
.m_aContext
.getValue( pKey
);
104 pValue
!= pKey
->getValue( nPaperBin
) &&
105 nPaperBin
< pKey
->countValues();
107 pJobSetup
->SetPaperBin(
108 (nPaperBin
== pKey
->countValues()
109 || pValue
== pKey
->getDefaultValue())
110 ? 0xffff : nPaperBin
);
117 pJobSetup
->SetDuplexMode( DuplexMode::Unknown
);
118 if( rData
.m_pParser
)
119 pKey
= rData
.m_pParser
->getKey( OUString( "Duplex" ) );
121 pValue
= rData
.m_aContext
.getValue( pKey
);
124 if( pValue
->m_aOption
.equalsIgnoreAsciiCase( "None" ) ||
125 pValue
->m_aOption
.startsWithIgnoreAsciiCase( "Simplex" )
128 pJobSetup
->SetDuplexMode( DuplexMode::Off
);
130 else if( pValue
->m_aOption
.equalsIgnoreAsciiCase( "DuplexNoTumble" ) )
132 pJobSetup
->SetDuplexMode( DuplexMode::LongEdge
);
134 else if( pValue
->m_aOption
.equalsIgnoreAsciiCase( "DuplexTumble" ) )
136 pJobSetup
->SetDuplexMode( DuplexMode::ShortEdge
);
140 // copy the whole context
141 if( pJobSetup
->GetDriverData() )
142 rtl_freeMemory( const_cast<sal_uInt8
*>(pJobSetup
->GetDriverData()) );
145 void* pBuffer
= nullptr;
146 if( rData
.getStreamBuffer( pBuffer
, nBytes
) )
148 pJobSetup
->SetDriverDataLen( nBytes
);
149 pJobSetup
->SetDriverData( static_cast<sal_uInt8
*>(pBuffer
) );
153 pJobSetup
->SetDriverDataLen( 0 );
154 pJobSetup
->SetDriverData( nullptr );
160 SalInfoPrinter
* SvpSalInstance::CreateInfoPrinter( SalPrinterQueueInfo
* pQueueInfo
,
161 ImplJobSetup
* pJobSetup
)
163 // create and initialize SalInfoPrinter
164 SvpSalInfoPrinter
* pPrinter
= new SvpSalInfoPrinter
;
168 PrinterInfoManager
& rManager( PrinterInfoManager::get() );
169 PrinterInfo
aInfo( rManager
.getPrinterInfo( pQueueInfo
->maPrinterName
) );
170 pPrinter
->m_aJobData
= aInfo
;
171 pPrinter
->m_aPrinterGfx
.Init( pPrinter
->m_aJobData
);
173 if( pJobSetup
->GetDriverData() )
174 JobData::constructFromStreamBuffer( pJobSetup
->GetDriverData(),
175 pJobSetup
->GetDriverDataLen(), aInfo
);
177 pJobSetup
->SetSystem( JOBSETUP_SYSTEM_UNIX
);
178 pJobSetup
->SetPrinterName( pQueueInfo
->maPrinterName
);
179 pJobSetup
->SetDriver( aInfo
.m_aDriverName
);
180 copyJobDataToJobSetup( pJobSetup
, aInfo
);
186 void SvpSalInstance::DestroyInfoPrinter( SalInfoPrinter
* pPrinter
)
191 SalPrinter
* SvpSalInstance::CreatePrinter( SalInfoPrinter
* pInfoPrinter
)
193 // create and initialize SalPrinter
194 SvpSalPrinter
* pPrinter
= new SvpSalPrinter( pInfoPrinter
);
195 pPrinter
->m_aJobData
= static_cast<SvpSalInfoPrinter
*>(pInfoPrinter
)->m_aJobData
;
200 void SvpSalInstance::DestroyPrinter( SalPrinter
* pPrinter
)
205 void SvpSalInstance::GetPrinterQueueInfo( ImplPrnQueueList
* pList
)
207 PrinterInfoManager
& rManager( PrinterInfoManager::get() );
208 static const char* pNoSyncDetection
= getenv( "SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION" );
209 if( ! pNoSyncDetection
|| ! *pNoSyncDetection
)
211 // #i62663# synchronize possible asynchronouse printer detection now
212 rManager
.checkPrintersChanged( true );
214 ::std::list
< OUString
> aPrinters
;
215 rManager
.listPrinters( aPrinters
);
217 for( ::std::list
< OUString
>::iterator it
= aPrinters
.begin(); it
!= aPrinters
.end(); ++it
)
219 const PrinterInfo
& rInfo( rManager
.getPrinterInfo( *it
) );
220 // Neuen Eintrag anlegen
221 SalPrinterQueueInfo
* pInfo
= new SalPrinterQueueInfo
;
222 pInfo
->maPrinterName
= *it
;
223 pInfo
->maDriver
= rInfo
.m_aDriverName
;
224 pInfo
->maLocation
= rInfo
.m_aLocation
;
225 pInfo
->maComment
= rInfo
.m_aComment
;
226 pInfo
->mpSysData
= nullptr;
228 sal_Int32 nIndex
= 0;
229 while( nIndex
!= -1 )
231 OUString
aToken( rInfo
.m_aFeatures
.getToken( 0, ',', nIndex
) );
232 if( aToken
.startsWith( "pdf=" ) )
234 pInfo
->maLocation
= getPdfDir( rInfo
);
243 void SvpSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo
* pInfo
)
248 void SvpSalInstance::GetPrinterQueueState( SalPrinterQueueInfo
* )
252 OUString
SvpSalInstance::GetDefaultPrinter()
254 PrinterInfoManager
& rManager( PrinterInfoManager::get() );
255 return rManager
.getDefaultPrinter();
258 void SvpSalInstance::PostPrintersChanged()
260 const std::list
< SalFrame
* >& rList
= SvpSalInstance::s_pDefaultInstance
->getFrames();
261 for( std::list
< SalFrame
* >::const_iterator it
= rList
.begin();
262 it
!= rList
.end(); ++it
)
263 SvpSalInstance::s_pDefaultInstance
->PostEvent( *it
, nullptr, SalEvent::PrinterChanged
);
266 GenPspGraphics
*SvpSalInstance::CreatePrintGraphics()
268 return new GenPspGraphics();
271 bool SvpSalInfoPrinter::Setup( SalFrame
*, ImplJobSetup
* )
276 SvpSalPrinter::SvpSalPrinter( SalInfoPrinter
* pInfoPrinter
)
277 : PspSalPrinter( pInfoPrinter
)
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */