LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vcl/headless - svpprn.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 83 137 60.6 %
Date: 2013-07-09 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             : 
      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.startsWith( "pdf=" ) )
      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           0 :             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          77 : static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, JobData& rData )
      65             : {
      66          77 :     pJobSetup->meOrientation    = (Orientation)(rData.m_eOrientation == orientation::Landscape ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);
      67             : 
      68             :     // copy page size
      69          77 :     OUString aPaper;
      70             :     int width, height;
      71             : 
      72          77 :     rData.m_aContext.getPageSize( aPaper, width, height );
      73          77 :     pJobSetup->mePaperFormat    = PaperInfo::fromPSName(OUStringToOString( aPaper, RTL_TEXTENCODING_ISO_8859_1 ));
      74          77 :     pJobSetup->mnPaperWidth     = 0;
      75          77 :     pJobSetup->mnPaperHeight    = 0;
      76          77 :     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          77 :     const PPDKey* pKey = NULL;
      96          77 :     const PPDValue* pValue = NULL;
      97             : 
      98          77 :     pJobSetup->mnPaperBin = 0xffff;
      99          77 :     if( rData.m_pParser )
     100          77 :         pKey                    = rData.m_pParser->getKey( String( "InputSlot"  ) );
     101          77 :     if( pKey )
     102           0 :         pValue                  = rData.m_aContext.getValue( pKey );
     103          77 :     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          77 :     pKey = NULL;
     116          77 :     pValue = NULL;
     117             : 
     118          77 :     pJobSetup->meDuplexMode = DUPLEX_UNKNOWN;
     119          77 :     if( rData.m_pParser )
     120          77 :         pKey = rData.m_pParser->getKey( String( "Duplex"  ) );
     121          77 :     if( pKey )
     122          77 :         pValue = rData.m_aContext.getValue( pKey );
     123          77 :     if( pKey && pValue )
     124             :     {
     125         154 :         if( pValue->m_aOption.EqualsIgnoreCaseAscii( "None" ) ||
     126          77 :             pValue->m_aOption.EqualsIgnoreCaseAscii( "Simplex", 0, 7 )
     127             :            )
     128             :         {
     129          77 :             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          77 :     if( pJobSetup->mpDriverData )
     143           0 :         rtl_freeMemory( pJobSetup->mpDriverData );
     144             : 
     145             :     int nBytes;
     146          77 :     void* pBuffer = NULL;
     147          77 :     if( rData.getStreamBuffer( pBuffer, nBytes ) )
     148             :     {
     149          77 :         pJobSetup->mnDriverDataLen = nBytes;
     150          77 :         pJobSetup->mpDriverData = (sal_uInt8*)pBuffer;
     151             :     }
     152             :     else
     153             :     {
     154           0 :         pJobSetup->mnDriverDataLen = 0;
     155           0 :         pJobSetup->mpDriverData = NULL;
     156          77 :     }
     157          77 : }
     158             : 
     159             : /*
     160             :  *  SalInstance
     161             :  */
     162             : 
     163          77 : SalInfoPrinter* SvpSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
     164             :                                                    ImplJobSetup*            pJobSetup )
     165             : {
     166             :     // create and initialize SalInfoPrinter
     167          77 :     SvpSalInfoPrinter* pPrinter = new SvpSalInfoPrinter();
     168             : 
     169          77 :     if( pJobSetup )
     170             :     {
     171          77 :         PrinterInfoManager& rManager( PrinterInfoManager::get() );
     172          77 :         PrinterInfo aInfo( rManager.getPrinterInfo( pQueueInfo->maPrinterName ) );
     173          77 :         pPrinter->m_aJobData = aInfo;
     174          77 :         pPrinter->m_aPrinterGfx.Init( pPrinter->m_aJobData );
     175             : 
     176          77 :         if( pJobSetup->mpDriverData )
     177           0 :             JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aInfo );
     178             : 
     179          77 :         pJobSetup->mnSystem         = JOBSETUP_SYSTEM_UNIX;
     180          77 :         pJobSetup->maPrinterName    = pQueueInfo->maPrinterName;
     181          77 :         pJobSetup->maDriver         = aInfo.m_aDriverName;
     182          77 :         copyJobDataToJobSetup( pJobSetup, aInfo );
     183             :     }
     184             : 
     185             : 
     186          77 :     return pPrinter;
     187             : }
     188             : 
     189          76 : void SvpSalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter )
     190             : {
     191          76 :     delete pPrinter;
     192          76 : }
     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          31 : void SvpSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
     209             : {
     210          31 :     PrinterInfoManager& rManager( PrinterInfoManager::get() );
     211          31 :     static const char* pNoSyncDetection = getenv( "SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION" );
     212          31 :     if( ! pNoSyncDetection || ! *pNoSyncDetection )
     213             :     {
     214             :         // #i62663# synchronize possible asynchronouse printer detection now
     215          31 :         rManager.checkPrintersChanged( true );
     216             :     }
     217          31 :     ::std::list< OUString > aPrinters;
     218          31 :     rManager.listPrinters( aPrinters );
     219             : 
     220          38 :     for( ::std::list< OUString >::iterator it = aPrinters.begin(); it != aPrinters.end(); ++it )
     221             :     {
     222           7 :         const PrinterInfo& rInfo( rManager.getPrinterInfo( *it ) );
     223             :         // Neuen Eintrag anlegen
     224           7 :         SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo;
     225           7 :         pInfo->maPrinterName    = *it;
     226           7 :         pInfo->maDriver         = rInfo.m_aDriverName;
     227           7 :         pInfo->maLocation       = rInfo.m_aLocation;
     228           7 :         pInfo->maComment        = rInfo.m_aComment;
     229           7 :         pInfo->mpSysData        = NULL;
     230             : 
     231           7 :         sal_Int32 nIndex = 0;
     232          21 :         while( nIndex != -1 )
     233             :         {
     234           7 :             String aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
     235           7 :             if( aToken.CompareToAscii( "pdf=", 4 ) == COMPARE_EQUAL )
     236             :             {
     237           0 :                 pInfo->maLocation = getPdfDir( rInfo );
     238           0 :                 break;
     239             :             }
     240           7 :         }
     241             : 
     242           7 :         pList->Add( pInfo );
     243          31 :     }
     244          31 : }
     245             : 
     246           6 : void SvpSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
     247             : {
     248           6 :     delete pInfo;
     249           6 : }
     250             : 
     251          77 : void SvpSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* )
     252             : {
     253          77 : }
     254             : 
     255        1648 : OUString SvpSalInstance::GetDefaultPrinter()
     256             : {
     257        1648 :     PrinterInfoManager& rManager( PrinterInfoManager::get() );
     258        1648 :     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          80 : GenPspGraphics *SvpSalInstance::CreatePrintGraphics()
     270             : {
     271          80 :     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         453 : }
     283             : 
     284             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10