LCOV - code coverage report
Current view: top level - libreoffice/vcl/headless - svpprn.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 13 135 9.6 %
Date: 2012-12-27 Functions: 2 15 13.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include "vcl/svapp.hxx"
      22             : #include "vcl/timer.hxx"
      23             : #include "vcl/printerinfomanager.hxx"
      24             : 
      25             : #include "jobset.h"
      26             : #include "print.h"
      27             : #include "salptype.hxx"
      28             : #include "saldatabasic.hxx"
      29             : 
      30             : #include "generic/genpspgraphics.h"
      31             : 
      32             : #include "headless/svpprn.hxx"
      33             : #include "headless/svpinst.hxx"
      34             : 
      35             : using namespace psp;
      36             : 
      37             : /*
      38             :  *  static helpers
      39             :  */
      40             : 
      41           0 : static OUString getPdfDir( const PrinterInfo& rInfo )
      42             : {
      43           0 :     OUString aDir;
      44           0 :     sal_Int32 nIndex = 0;
      45           0 :     while( nIndex != -1 )
      46             :     {
      47           0 :         OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
      48           0 :         if( ! aToken.compareToAscii( "pdf=", 4 ) )
      49             :         {
      50           0 :             sal_Int32 nPos = 0;
      51           0 :             aDir = aToken.getToken( 1, '=', nPos );
      52           0 :             if( aDir.isEmpty() )
      53           0 :                 aDir = OStringToOUString( OString( getenv( "HOME" ) ), osl_getThreadTextEncoding() );
      54             :             break;
      55             :         }
      56           0 :     }
      57           0 :     return aDir;
      58             : }
      59             : 
      60           0 : inline int PtTo10Mu( int nPoints ) { return (int)((((double)nPoints)*35.27777778)+0.5); }
      61             : 
      62             : inline int TenMuToPt( int nUnits ) { return (int)((((double)nUnits)/35.27777778)+0.5); }
      63             : 
      64           0 : static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, JobData& rData )
      65             : {
      66           0 :     pJobSetup->meOrientation    = (Orientation)(rData.m_eOrientation == orientation::Landscape ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);
      67             : 
      68             :     // copy page size
      69           0 :     OUString aPaper;
      70             :     int width, height;
      71             : 
      72           0 :     rData.m_aContext.getPageSize( aPaper, width, height );
      73           0 :     pJobSetup->mePaperFormat    = PaperInfo::fromPSName(OUStringToOString( aPaper, RTL_TEXTENCODING_ISO_8859_1 ));
      74           0 :     pJobSetup->mnPaperWidth     = 0;
      75           0 :     pJobSetup->mnPaperHeight    = 0;
      76           0 :     if( pJobSetup->mePaperFormat == PAPER_USER )
      77             :     {
      78             :         // transform to 100dth mm
      79           0 :         width               = PtTo10Mu( width );
      80           0 :         height              = PtTo10Mu( height );
      81             : 
      82           0 :         if( rData.m_eOrientation == psp::orientation::Portrait )
      83             :         {
      84           0 :             pJobSetup->mnPaperWidth = width;
      85           0 :             pJobSetup->mnPaperHeight= height;
      86             :         }
      87             :         else
      88             :         {
      89           0 :             pJobSetup->mnPaperWidth = height;
      90           0 :             pJobSetup->mnPaperHeight= width;
      91             :         }
      92             :     }
      93             : 
      94             :     // copy input slot
      95           0 :     const PPDKey* pKey = NULL;
      96           0 :     const PPDValue* pValue = NULL;
      97             : 
      98           0 :     pJobSetup->mnPaperBin = 0xffff;
      99           0 :     if( rData.m_pParser )
     100           0 :         pKey                    = rData.m_pParser->getKey( String( "InputSlot"  ) );
     101           0 :     if( pKey )
     102           0 :         pValue                  = rData.m_aContext.getValue( pKey );
     103           0 :     if( pKey && pValue )
     104             :     {
     105           0 :         for( pJobSetup->mnPaperBin = 0;
     106           0 :              pValue != pKey->getValue( pJobSetup->mnPaperBin ) &&
     107           0 :                  pJobSetup->mnPaperBin < pKey->countValues();
     108             :              pJobSetup->mnPaperBin++ )
     109             :             ;
     110           0 :         if( pJobSetup->mnPaperBin >= pKey->countValues() || pValue == pKey->getDefaultValue() )
     111           0 :             pJobSetup->mnPaperBin = 0xffff;
     112             :     }
     113             : 
     114             :     // copy duplex
     115           0 :     pKey = NULL;
     116           0 :     pValue = NULL;
     117             : 
     118           0 :     pJobSetup->meDuplexMode = DUPLEX_UNKNOWN;
     119           0 :     if( rData.m_pParser )
     120           0 :         pKey = rData.m_pParser->getKey( String( "Duplex"  ) );
     121           0 :     if( pKey )
     122           0 :         pValue = rData.m_aContext.getValue( pKey );
     123           0 :     if( pKey && pValue )
     124             :     {
     125           0 :         if( pValue->m_aOption.EqualsIgnoreCaseAscii( "None" ) ||
     126           0 :             pValue->m_aOption.EqualsIgnoreCaseAscii( "Simplex", 0, 7 )
     127             :            )
     128             :         {
     129           0 :             pJobSetup->meDuplexMode = DUPLEX_OFF;
     130             :         }
     131           0 :         else if( pValue->m_aOption.EqualsIgnoreCaseAscii( "DuplexNoTumble" ) )
     132             :         {
     133           0 :             pJobSetup->meDuplexMode = DUPLEX_LONGEDGE;
     134             :         }
     135           0 :         else if( pValue->m_aOption.EqualsIgnoreCaseAscii( "DuplexTumble" ) )
     136             :         {
     137           0 :             pJobSetup->meDuplexMode = DUPLEX_SHORTEDGE;
     138             :         }
     139             :     }
     140             : 
     141             :     // copy the whole context
     142           0 :     if( pJobSetup->mpDriverData )
     143           0 :         rtl_freeMemory( pJobSetup->mpDriverData );
     144             : 
     145             :     int nBytes;
     146           0 :     void* pBuffer = NULL;
     147           0 :     if( rData.getStreamBuffer( pBuffer, nBytes ) )
     148             :     {
     149           0 :         pJobSetup->mnDriverDataLen = nBytes;
     150           0 :         pJobSetup->mpDriverData = (sal_uInt8*)pBuffer;
     151             :     }
     152             :     else
     153             :     {
     154           0 :         pJobSetup->mnDriverDataLen = 0;
     155           0 :         pJobSetup->mpDriverData = NULL;
     156           0 :     }
     157           0 : }
     158             : 
     159             : /*
     160             :  *  SalInstance
     161             :  */
     162             : 
     163           0 : SalInfoPrinter* SvpSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
     164             :                                                    ImplJobSetup*            pJobSetup )
     165             : {
     166             :     // create and initialize SalInfoPrinter
     167           0 :     SvpSalInfoPrinter* pPrinter = new SvpSalInfoPrinter();
     168             : 
     169           0 :     if( pJobSetup )
     170             :     {
     171           0 :         PrinterInfoManager& rManager( PrinterInfoManager::get() );
     172           0 :         PrinterInfo aInfo( rManager.getPrinterInfo( pQueueInfo->maPrinterName ) );
     173           0 :         pPrinter->m_aJobData = aInfo;
     174           0 :         pPrinter->m_aPrinterGfx.Init( pPrinter->m_aJobData );
     175             : 
     176           0 :         if( pJobSetup->mpDriverData )
     177           0 :             JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aInfo );
     178             : 
     179           0 :         pJobSetup->mnSystem         = JOBSETUP_SYSTEM_UNIX;
     180           0 :         pJobSetup->maPrinterName    = pQueueInfo->maPrinterName;
     181           0 :         pJobSetup->maDriver         = aInfo.m_aDriverName;
     182           0 :         copyJobDataToJobSetup( pJobSetup, aInfo );
     183             :     }
     184             : 
     185             : 
     186           0 :     return pPrinter;
     187             : }
     188             : 
     189           0 : void SvpSalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter )
     190             : {
     191           0 :     delete pPrinter;
     192           0 : }
     193             : 
     194           0 : SalPrinter* SvpSalInstance::CreatePrinter( SalInfoPrinter* pInfoPrinter )
     195             : {
     196             :     // create and initialize SalPrinter
     197           0 :     SvpSalPrinter* pPrinter = new SvpSalPrinter( pInfoPrinter );
     198           0 :     pPrinter->m_aJobData = static_cast<SvpSalInfoPrinter*>(pInfoPrinter)->m_aJobData;
     199             : 
     200           0 :     return pPrinter;
     201             : }
     202             : 
     203           0 : void SvpSalInstance::DestroyPrinter( SalPrinter* pPrinter )
     204             : {
     205           0 :     delete pPrinter;
     206           0 : }
     207             : 
     208           9 : void SvpSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
     209             : {
     210           9 :     PrinterInfoManager& rManager( PrinterInfoManager::get() );
     211           9 :     static const char* pNoSyncDetection = getenv( "SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION" );
     212           9 :     if( ! pNoSyncDetection || ! *pNoSyncDetection )
     213             :     {
     214             :         // #i62663# synchronize possible asynchronouse printer detection now
     215           9 :         rManager.checkPrintersChanged( true );
     216             :     }
     217           9 :     ::std::list< OUString > aPrinters;
     218           9 :     rManager.listPrinters( aPrinters );
     219             : 
     220           9 :     for( ::std::list< OUString >::iterator it = aPrinters.begin(); it != aPrinters.end(); ++it )
     221             :     {
     222           0 :         const PrinterInfo& rInfo( rManager.getPrinterInfo( *it ) );
     223             :         // Neuen Eintrag anlegen
     224           0 :         SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo;
     225           0 :         pInfo->maPrinterName    = *it;
     226           0 :         pInfo->maDriver         = rInfo.m_aDriverName;
     227           0 :         pInfo->maLocation       = rInfo.m_aLocation;
     228           0 :         pInfo->maComment        = rInfo.m_aComment;
     229           0 :         pInfo->mpSysData        = NULL;
     230             : 
     231           0 :         sal_Int32 nIndex = 0;
     232           0 :         while( nIndex != -1 )
     233             :         {
     234           0 :             String aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
     235           0 :             if( aToken.CompareToAscii( "pdf=", 4 ) == COMPARE_EQUAL )
     236             :             {
     237           0 :                 pInfo->maLocation = getPdfDir( rInfo );
     238             :                 break;
     239             :             }
     240           0 :         }
     241             : 
     242           0 :         pList->Add( pInfo );
     243           9 :     }
     244           9 : }
     245             : 
     246           0 : void SvpSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
     247             : {
     248           0 :     delete pInfo;
     249           0 : }
     250             : 
     251           0 : void SvpSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* )
     252             : {
     253           0 : }
     254             : 
     255          68 : OUString SvpSalInstance::GetDefaultPrinter()
     256             : {
     257          68 :     PrinterInfoManager& rManager( PrinterInfoManager::get() );
     258          68 :     return rManager.getDefaultPrinter();
     259             : }
     260             : 
     261           0 : void SvpSalInstance::PostPrintersChanged()
     262             : {
     263           0 :     const std::list< SalFrame* >& rList = SvpSalInstance::s_pDefaultInstance->getFrames();
     264           0 :     for( std::list< SalFrame* >::const_iterator it = rList.begin();
     265           0 :          it != rList.end(); ++it )
     266           0 :         SvpSalInstance::s_pDefaultInstance->PostEvent( *it, NULL, SALEVENT_PRINTERCHANGED );
     267           0 : }
     268             : 
     269           0 : GenPspGraphics *SvpSalInstance::CreatePrintGraphics()
     270             : {
     271           0 :     return new GenPspGraphics();
     272             : }
     273             : 
     274           0 : sal_Bool SvpSalInfoPrinter::Setup( SalFrame*, ImplJobSetup* )
     275             : {
     276           0 :     return sal_False;
     277             : }
     278             : 
     279           0 : SvpSalPrinter::SvpSalPrinter( SalInfoPrinter* pInfoPrinter )
     280           0 :     : PspSalPrinter( pInfoPrinter )
     281             : {
     282           0 : }
     283             : 
     284             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10