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

Generated by: LCOV version 1.10