LCOV - code coverage report
Current view: top level - vcl/headless - svpprn.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 83 137 60.6 %
Date: 2014-11-03 Functions: 10 17 58.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         680 : static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, JobData& rData )
      62             : {
      63         680 :     pJobSetup->meOrientation    = (Orientation)(rData.m_eOrientation == orientation::Landscape ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);
      64             : 
      65             :     // copy page size
      66         680 :     OUString aPaper;
      67             :     int width, height;
      68             : 
      69         680 :     rData.m_aContext.getPageSize( aPaper, width, height );
      70         680 :     pJobSetup->mePaperFormat    = PaperInfo::fromPSName(OUStringToOString( aPaper, RTL_TEXTENCODING_ISO_8859_1 ));
      71         680 :     pJobSetup->mnPaperWidth     = 0;
      72         680 :     pJobSetup->mnPaperHeight    = 0;
      73         680 :     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         680 :     const PPDKey* pKey = NULL;
      93         680 :     const PPDValue* pValue = NULL;
      94             : 
      95         680 :     pJobSetup->mnPaperBin = 0xffff;
      96         680 :     if( rData.m_pParser )
      97         680 :         pKey                    = rData.m_pParser->getKey( OUString( "InputSlot"  ) );
      98         680 :     if( pKey )
      99           0 :         pValue                  = rData.m_aContext.getValue( pKey );
     100         680 :     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         680 :     pKey = NULL;
     113         680 :     pValue = NULL;
     114             : 
     115         680 :     pJobSetup->meDuplexMode = DUPLEX_UNKNOWN;
     116         680 :     if( rData.m_pParser )
     117         680 :         pKey = rData.m_pParser->getKey( OUString( "Duplex"  ) );
     118         680 :     if( pKey )
     119         680 :         pValue = rData.m_aContext.getValue( pKey );
     120         680 :     if( pKey && pValue )
     121             :     {
     122        1360 :         if( pValue->m_aOption.equalsIgnoreAsciiCase( "None" ) ||
     123         680 :             pValue->m_aOption.startsWithIgnoreAsciiCase( "Simplex" )
     124             :            )
     125             :         {
     126         680 :             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         680 :     if( pJobSetup->mpDriverData )
     140           0 :         rtl_freeMemory( pJobSetup->mpDriverData );
     141             : 
     142             :     int nBytes;
     143         680 :     void* pBuffer = NULL;
     144         680 :     if( rData.getStreamBuffer( pBuffer, nBytes ) )
     145             :     {
     146         680 :         pJobSetup->mnDriverDataLen = nBytes;
     147         680 :         pJobSetup->mpDriverData = (sal_uInt8*)pBuffer;
     148             :     }
     149             :     else
     150             :     {
     151           0 :         pJobSetup->mnDriverDataLen = 0;
     152           0 :         pJobSetup->mpDriverData = NULL;
     153         680 :     }
     154         680 : }
     155             : 
     156             : // SalInstance
     157             : 
     158         680 : SalInfoPrinter* SvpSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
     159             :                                                    ImplJobSetup*            pJobSetup )
     160             : {
     161             :     // create and initialize SalInfoPrinter
     162         680 :     SvpSalInfoPrinter* pPrinter = new SvpSalInfoPrinter();
     163             : 
     164         680 :     if( pJobSetup )
     165             :     {
     166         680 :         PrinterInfoManager& rManager( PrinterInfoManager::get() );
     167         680 :         PrinterInfo aInfo( rManager.getPrinterInfo( pQueueInfo->maPrinterName ) );
     168         680 :         pPrinter->m_aJobData = aInfo;
     169         680 :         pPrinter->m_aPrinterGfx.Init( pPrinter->m_aJobData );
     170             : 
     171         680 :         if( pJobSetup->mpDriverData )
     172           0 :             JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aInfo );
     173             : 
     174         680 :         pJobSetup->mnSystem         = JOBSETUP_SYSTEM_UNIX;
     175         680 :         pJobSetup->maPrinterName    = pQueueInfo->maPrinterName;
     176         680 :         pJobSetup->maDriver         = aInfo.m_aDriverName;
     177         680 :         copyJobDataToJobSetup( pJobSetup, aInfo );
     178             :     }
     179             : 
     180         680 :     return pPrinter;
     181             : }
     182             : 
     183         677 : void SvpSalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter )
     184             : {
     185         677 :     delete pPrinter;
     186         677 : }
     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          74 : void SvpSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
     203             : {
     204          74 :     PrinterInfoManager& rManager( PrinterInfoManager::get() );
     205          74 :     static const char* pNoSyncDetection = getenv( "SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION" );
     206          74 :     if( ! pNoSyncDetection || ! *pNoSyncDetection )
     207             :     {
     208             :         // #i62663# synchronize possible asynchronouse printer detection now
     209          74 :         rManager.checkPrintersChanged( true );
     210             :     }
     211          74 :     ::std::list< OUString > aPrinters;
     212          74 :     rManager.listPrinters( aPrinters );
     213             : 
     214         148 :     for( ::std::list< OUString >::iterator it = aPrinters.begin(); it != aPrinters.end(); ++it )
     215             :     {
     216          74 :         const PrinterInfo& rInfo( rManager.getPrinterInfo( *it ) );
     217             :         // Neuen Eintrag anlegen
     218          74 :         SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo;
     219          74 :         pInfo->maPrinterName    = *it;
     220          74 :         pInfo->maDriver         = rInfo.m_aDriverName;
     221          74 :         pInfo->maLocation       = rInfo.m_aLocation;
     222          74 :         pInfo->maComment        = rInfo.m_aComment;
     223          74 :         pInfo->mpSysData        = NULL;
     224             : 
     225          74 :         sal_Int32 nIndex = 0;
     226         222 :         while( nIndex != -1 )
     227             :         {
     228          74 :             OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
     229          74 :             if( aToken.startsWith( "pdf=" ) )
     230             :             {
     231           0 :                 pInfo->maLocation = getPdfDir( rInfo );
     232           0 :                 break;
     233             :             }
     234          74 :         }
     235             : 
     236          74 :         pList->Add( pInfo );
     237          74 :     }
     238          74 : }
     239             : 
     240          72 : void SvpSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
     241             : {
     242          72 :     delete pInfo;
     243          72 : }
     244             : 
     245         680 : void SvpSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* )
     246             : {
     247         680 : }
     248             : 
     249        2052 : OUString SvpSalInstance::GetDefaultPrinter()
     250             : {
     251        2052 :     PrinterInfoManager& rManager( PrinterInfoManager::get() );
     252        2052 :     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         780 : GenPspGraphics *SvpSalInstance::CreatePrintGraphics()
     264             : {
     265         780 :     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        1125 : }
     277             : 
     278             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10