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

Generated by: LCOV version 1.10