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

Generated by: LCOV version 1.11