LCOV - code coverage report
Current view: top level - vcl/headless - svpprn.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 83 135 61.5 %
Date: 2012-08-25 Functions: 8 15 53.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 60 174 34.5 %

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

Generated by: LCOV version 1.10