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 .
21 #include "vcl/svapp.hxx"
22 #include "vcl/timer.hxx"
23 #include "vcl/printerinfomanager.hxx"
27 #include "salptype.hxx"
28 #include "saldatabasic.hxx"
30 #include "generic/genpspgraphics.h"
32 #include "headless/svpprn.hxx"
33 #include "headless/svpinst.hxx"
41 static OUString
getPdfDir( const PrinterInfo
& rInfo
)
47 OUString
aToken( rInfo
.m_aFeatures
.getToken( 0, ',', nIndex
) );
48 if( aToken
.startsWith( "pdf=" ) )
51 aDir
= aToken
.getToken( 1, '=', nPos
);
53 aDir
= OStringToOUString( OString( getenv( "HOME" ) ), osl_getThreadTextEncoding() );
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
);
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
;
89 pJobSetup
->mnPaperWidth
= height
;
90 pJobSetup
->mnPaperHeight
= width
;
95 const PPDKey
* pKey
= NULL
;
96 const PPDValue
* pValue
= NULL
;
98 pJobSetup
->mnPaperBin
= 0xffff;
100 pKey
= rData
.m_pParser
->getKey( OUString( "InputSlot" ) );
102 pValue
= rData
.m_aContext
.getValue( pKey
);
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;
118 pJobSetup
->meDuplexMode
= DUPLEX_UNKNOWN
;
119 if( rData
.m_pParser
)
120 pKey
= rData
.m_pParser
->getKey( OUString( "Duplex" ) );
122 pValue
= rData
.m_aContext
.getValue( pKey
);
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
);
146 void* pBuffer
= NULL
;
147 if( rData
.getStreamBuffer( pBuffer
, nBytes
) )
149 pJobSetup
->mnDriverDataLen
= nBytes
;
150 pJobSetup
->mpDriverData
= (sal_uInt8
*)pBuffer
;
154 pJobSetup
->mnDriverDataLen
= 0;
155 pJobSetup
->mpDriverData
= NULL
;
163 SalInfoPrinter
* SvpSalInstance::CreateInfoPrinter( SalPrinterQueueInfo
* pQueueInfo
,
164 ImplJobSetup
* pJobSetup
)
166 // create and initialize SalInfoPrinter
167 SvpSalInfoPrinter
* pPrinter
= new SvpSalInfoPrinter();
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
);
189 void SvpSalInstance::DestroyInfoPrinter( SalInfoPrinter
* 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
;
203 void SvpSalInstance::DestroyPrinter( SalPrinter
* 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
);
246 void SvpSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo
* 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
* )
279 SvpSalPrinter::SvpSalPrinter( SalInfoPrinter
* pInfoPrinter
)
280 : PspSalPrinter( pInfoPrinter
)
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */