19f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 39f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 49f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 59f62ea84SAndrew Rist * distributed with this work for additional information 69f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 79f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 89f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 99f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 109f62ea84SAndrew Rist * 119f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 129f62ea84SAndrew Rist * 139f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 149f62ea84SAndrew Rist * software distributed under the License is distributed on an 159f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 179f62ea84SAndrew Rist * specific language governing permissions and limitations 189f62ea84SAndrew Rist * under the License. 199f62ea84SAndrew Rist * 209f62ea84SAndrew Rist *************************************************************/ 219f62ea84SAndrew Rist 229f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <boost/bind.hpp> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "vcl/print.hxx" 30cdf0e10cSrcweir #include "vcl/unohelp.hxx" 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include "aqua/salinst.h" 33cdf0e10cSrcweir #include "aqua/salprn.h" 34cdf0e10cSrcweir #include "aqua/aquaprintview.h" 35cdf0e10cSrcweir #include "aqua/salgdi.h" 36cdf0e10cSrcweir #include "aqua/saldata.hxx" 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include "jobset.h" 39cdf0e10cSrcweir #include "salptype.hxx" 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp" 42cdf0e10cSrcweir #include "com/sun/star/container/XNameAccess.hpp" 43cdf0e10cSrcweir #include "com/sun/star/beans/PropertyValue.hpp" 44cdf0e10cSrcweir #include "com/sun/star/awt/Size.hpp" 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include <algorithm> 47cdf0e10cSrcweir 48cdf0e10cSrcweir using namespace rtl; 49cdf0e10cSrcweir using namespace vcl; 50cdf0e10cSrcweir using namespace com::sun::star; 51cdf0e10cSrcweir using namespace com::sun::star::uno; 52cdf0e10cSrcweir using namespace com::sun::star::lang; 53cdf0e10cSrcweir using namespace com::sun::star::beans; 54cdf0e10cSrcweir using namespace com::sun::star::container; 55cdf0e10cSrcweir 56cdf0e10cSrcweir // ======================================================================= 57cdf0e10cSrcweir 58cdf0e10cSrcweir AquaSalInfoPrinter::AquaSalInfoPrinter( const SalPrinterQueueInfo& i_rQueue ) : 59cdf0e10cSrcweir mpGraphics( 0 ), 60cdf0e10cSrcweir mbGraphics( false ), 61cdf0e10cSrcweir mbJob( false ), 62cdf0e10cSrcweir mpPrinter( nil ), 63cdf0e10cSrcweir mpPrintInfo( nil ), 64cdf0e10cSrcweir mePageOrientation( ORIENTATION_PORTRAIT ), 65cdf0e10cSrcweir mnStartPageOffsetX( 0 ), 66cdf0e10cSrcweir mnStartPageOffsetY( 0 ), 67cdf0e10cSrcweir mnCurPageRangeStart( 0 ), 68cdf0e10cSrcweir mnCurPageRangeCount( 0 ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir NSString* pStr = CreateNSString( i_rQueue.maPrinterName ); 71cdf0e10cSrcweir mpPrinter = [NSPrinter printerWithName: pStr]; 72cdf0e10cSrcweir [pStr release]; 73cdf0e10cSrcweir 74cdf0e10cSrcweir NSPrintInfo* pShared = [NSPrintInfo sharedPrintInfo]; 75cdf0e10cSrcweir if( pShared ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir mpPrintInfo = [pShared copy]; 78cdf0e10cSrcweir [mpPrintInfo setPrinter: mpPrinter]; 79cdf0e10cSrcweir mePageOrientation = ([mpPrintInfo orientation] == NSLandscapeOrientation) ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT; 80cdf0e10cSrcweir [mpPrintInfo setOrientation: NSPortraitOrientation]; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir mpGraphics = new AquaSalGraphics(); 84cdf0e10cSrcweir 85cdf0e10cSrcweir const int nWidth = 100, nHeight = 100; 86cdf0e10cSrcweir maContextMemory.reset( reinterpret_cast<sal_uInt8*>( rtl_allocateMemory( nWidth * 4 * nHeight ) ), 87cdf0e10cSrcweir boost::bind( rtl_freeMemory, _1 ) ); 88cdf0e10cSrcweir 89cdf0e10cSrcweir if( maContextMemory ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir mrContext = CGBitmapContextCreate( maContextMemory.get(), nWidth, nHeight, 8, nWidth * 4, GetSalData()->mxRGBSpace, kCGImageAlphaNoneSkipFirst ); 92cdf0e10cSrcweir if( mrContext ) 93cdf0e10cSrcweir SetupPrinterGraphics( mrContext ); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir // ----------------------------------------------------------------------- 98cdf0e10cSrcweir 99cdf0e10cSrcweir AquaSalInfoPrinter::~AquaSalInfoPrinter() 100cdf0e10cSrcweir { 101cdf0e10cSrcweir delete mpGraphics; 102cdf0e10cSrcweir if( mpPrintInfo ) 103cdf0e10cSrcweir [mpPrintInfo release]; 104cdf0e10cSrcweir #if 0 105cdf0e10cSrcweir // FIXME: verify that NSPrintInfo releases the printer 106cdf0e10cSrcweir // else we have a leak here 107cdf0e10cSrcweir if( mpPrinter ) 108cdf0e10cSrcweir [mpPrinter release]; 109cdf0e10cSrcweir #endif 110cdf0e10cSrcweir if( mrContext ) 111cdf0e10cSrcweir CFRelease( mrContext ); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir // ----------------------------------------------------------------------- 115cdf0e10cSrcweir 116cdf0e10cSrcweir void AquaSalInfoPrinter::SetupPrinterGraphics( CGContextRef i_rContext ) const 117cdf0e10cSrcweir { 118cdf0e10cSrcweir if( mpGraphics ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir if( mpPrintInfo ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir // FIXME: get printer resolution 123cdf0e10cSrcweir long nDPIX = 720, nDPIY = 720; 124cdf0e10cSrcweir NSSize aPaperSize = [mpPrintInfo paperSize]; 125cdf0e10cSrcweir 126cdf0e10cSrcweir NSRect aImageRect = [mpPrintInfo imageablePageBounds]; 127cdf0e10cSrcweir if( mePageOrientation == ORIENTATION_PORTRAIT ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir // move mirrored CTM back into paper 130cdf0e10cSrcweir double dX = 0, dY = aPaperSize.height; 131cdf0e10cSrcweir // move CTM to reflect imageable area 132cdf0e10cSrcweir dX += aImageRect.origin.x; 133cdf0e10cSrcweir dY -= aPaperSize.height - aImageRect.size.height - aImageRect.origin.y; 134cdf0e10cSrcweir CGContextTranslateCTM( i_rContext, dX + mnStartPageOffsetX, dY - mnStartPageOffsetY ); 135cdf0e10cSrcweir // scale to be top/down and reflect our "virtual" DPI 136cdf0e10cSrcweir CGContextScaleCTM( i_rContext, 72.0/double(nDPIX), -(72.0/double(nDPIY)) ); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir else 139cdf0e10cSrcweir { 140cdf0e10cSrcweir // move CTM to reflect imageable area 141cdf0e10cSrcweir double dX = aImageRect.origin.x, dY = aPaperSize.height - aImageRect.size.height - aImageRect.origin.y; 142cdf0e10cSrcweir CGContextTranslateCTM( i_rContext, -dX, -dY ); 143cdf0e10cSrcweir // turn by 90 degree 144cdf0e10cSrcweir CGContextRotateCTM( i_rContext, M_PI/2 ); 145cdf0e10cSrcweir // move turned CTM back into paper 146cdf0e10cSrcweir dX = aPaperSize.height; 147cdf0e10cSrcweir dY = -aPaperSize.width; 148cdf0e10cSrcweir CGContextTranslateCTM( i_rContext, dX + mnStartPageOffsetY, dY - mnStartPageOffsetX ); 149cdf0e10cSrcweir // scale to be top/down and reflect our "virtual" DPI 150cdf0e10cSrcweir CGContextScaleCTM( i_rContext, -(72.0/double(nDPIY)), (72.0/double(nDPIX)) ); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir mpGraphics->SetPrinterGraphics( i_rContext, nDPIX, nDPIY, 1.0 ); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir else 155cdf0e10cSrcweir DBG_ERROR( "no print info in SetupPrinterGraphics" ); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir // ----------------------------------------------------------------------- 160cdf0e10cSrcweir 161cdf0e10cSrcweir SalGraphics* AquaSalInfoPrinter::GetGraphics() 162cdf0e10cSrcweir { 163cdf0e10cSrcweir SalGraphics* pGraphics = mbGraphics ? NULL : mpGraphics; 164cdf0e10cSrcweir mbGraphics = true; 165cdf0e10cSrcweir return pGraphics; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir // ----------------------------------------------------------------------- 169cdf0e10cSrcweir 170cdf0e10cSrcweir void AquaSalInfoPrinter::ReleaseGraphics( SalGraphics* ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir mbGraphics = false; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir // ----------------------------------------------------------------------- 176cdf0e10cSrcweir 177cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::Setup( SalFrame*, ImplJobSetup* ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir return sal_False; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir // ----------------------------------------------------------------------- 183cdf0e10cSrcweir 184cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::SetPrinterData( ImplJobSetup* io_pSetupData ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir // FIXME: implement driver data 187cdf0e10cSrcweir if( io_pSetupData && io_pSetupData->mpDriverData ) 188cdf0e10cSrcweir return SetData( ~0, io_pSetupData ); 189cdf0e10cSrcweir 190cdf0e10cSrcweir 191cdf0e10cSrcweir sal_Bool bSuccess = sal_True; 192cdf0e10cSrcweir 193cdf0e10cSrcweir // set system type 194cdf0e10cSrcweir io_pSetupData->mnSystem = JOBSETUP_SYSTEM_MAC; 195cdf0e10cSrcweir 196cdf0e10cSrcweir // get paper format 197cdf0e10cSrcweir if( mpPrintInfo ) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir NSSize aPaperSize = [mpPrintInfo paperSize]; 200cdf0e10cSrcweir double width = aPaperSize.width, height = aPaperSize.height; 201cdf0e10cSrcweir // set paper 20292a1bdefSEike Rathke PaperInfo aInfo( PtTo10Mu( width ), PtTo10Mu( height ) ); 20392a1bdefSEike Rathke aInfo.doSloppyFit(); 20492a1bdefSEike Rathke io_pSetupData->mePaperFormat = aInfo.getPaper(); 205cdf0e10cSrcweir if( io_pSetupData->mePaperFormat == PAPER_USER ) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir io_pSetupData->mnPaperWidth = PtTo10Mu( width ); 208cdf0e10cSrcweir io_pSetupData->mnPaperHeight = PtTo10Mu( height ); 209cdf0e10cSrcweir } 210cdf0e10cSrcweir else 211cdf0e10cSrcweir { 212cdf0e10cSrcweir io_pSetupData->mnPaperWidth = 0; 213cdf0e10cSrcweir io_pSetupData->mnPaperHeight = 0; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir // set orientation 217cdf0e10cSrcweir io_pSetupData->meOrientation = mePageOrientation; 218cdf0e10cSrcweir 219cdf0e10cSrcweir io_pSetupData->mnPaperBin = 0; 220cdf0e10cSrcweir io_pSetupData->mpDriverData = reinterpret_cast<sal_uInt8*>(rtl_allocateMemory( 4 )); 221cdf0e10cSrcweir io_pSetupData->mnDriverDataLen = 4; 222cdf0e10cSrcweir } 223cdf0e10cSrcweir else 224cdf0e10cSrcweir bSuccess = sal_False; 225cdf0e10cSrcweir 226cdf0e10cSrcweir 227cdf0e10cSrcweir return bSuccess; 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir // ----------------------------------------------------------------------- 231cdf0e10cSrcweir 232cdf0e10cSrcweir void AquaSalInfoPrinter::setPaperSize( long i_nWidth, long i_nHeight, Orientation i_eSetOrientation ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir 235cdf0e10cSrcweir Orientation ePaperOrientation = ORIENTATION_PORTRAIT; 236cdf0e10cSrcweir const PaperInfo* pPaper = matchPaper( i_nWidth, i_nHeight, ePaperOrientation ); 237cdf0e10cSrcweir 238cdf0e10cSrcweir if( pPaper ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir NSString* pPaperName = [CreateNSString( rtl::OStringToOUString(PaperInfo::toPSName(pPaper->getPaper()), RTL_TEXTENCODING_ASCII_US) ) autorelease]; 241cdf0e10cSrcweir [mpPrintInfo setPaperName: pPaperName]; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir else if( i_nWidth > 0 && i_nHeight > 0 ) 244cdf0e10cSrcweir { 245cd426cceSHerbert Dürr NSSize aPaperSize = NSMakeSize( TenMuToPt(i_nWidth), TenMuToPt(i_nHeight)); 246cdf0e10cSrcweir [mpPrintInfo setPaperSize: aPaperSize]; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir // this seems counterintuitive 249cdf0e10cSrcweir mePageOrientation = i_eSetOrientation; 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir // ----------------------------------------------------------------------- 253cdf0e10cSrcweir 254cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::SetData( sal_uLong i_nFlags, ImplJobSetup* io_pSetupData ) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir if( ! io_pSetupData || io_pSetupData->mnSystem != JOBSETUP_SYSTEM_MAC ) 257cdf0e10cSrcweir return sal_False; 258cdf0e10cSrcweir 259cdf0e10cSrcweir 260cdf0e10cSrcweir if( mpPrintInfo ) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir if( (i_nFlags & SAL_JOBSET_ORIENTATION) != 0 ) 263cdf0e10cSrcweir mePageOrientation = io_pSetupData->meOrientation; 264cdf0e10cSrcweir 265cdf0e10cSrcweir if( (i_nFlags & SAL_JOBSET_PAPERSIZE) != 0) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir // set paper format 268cdf0e10cSrcweir long width = 21000, height = 29700; 269cdf0e10cSrcweir if( io_pSetupData->mePaperFormat == PAPER_USER ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir // #i101108# sanity check 272cdf0e10cSrcweir if( io_pSetupData->mnPaperWidth && io_pSetupData->mnPaperHeight ) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir width = io_pSetupData->mnPaperWidth; 275cdf0e10cSrcweir height = io_pSetupData->mnPaperHeight; 276cdf0e10cSrcweir } 277cdf0e10cSrcweir } 278cdf0e10cSrcweir else 279cdf0e10cSrcweir { 28092a1bdefSEike Rathke PaperInfo aInfo( io_pSetupData->mePaperFormat ); 28192a1bdefSEike Rathke width = aInfo.getWidth(); 28292a1bdefSEike Rathke height = aInfo.getHeight(); 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir setPaperSize( width, height, mePageOrientation ); 286cdf0e10cSrcweir } 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir return mpPrintInfo != nil; 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir // ----------------------------------------------------------------------- 293cdf0e10cSrcweir 294cdf0e10cSrcweir sal_uLong AquaSalInfoPrinter::GetPaperBinCount( const ImplJobSetup* ) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir return 0; 297cdf0e10cSrcweir } 298cdf0e10cSrcweir 299cdf0e10cSrcweir // ----------------------------------------------------------------------- 300cdf0e10cSrcweir 301cdf0e10cSrcweir XubString AquaSalInfoPrinter::GetPaperBinName( const ImplJobSetup*, sal_uLong ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir return XubString(); 304cdf0e10cSrcweir } 305cdf0e10cSrcweir 306cdf0e10cSrcweir // ----------------------------------------------------------------------- 307cdf0e10cSrcweir 308cdf0e10cSrcweir static bool getUseNativeDialog() 309cdf0e10cSrcweir { 310cdf0e10cSrcweir bool bNative = true; 311cdf0e10cSrcweir try 312cdf0e10cSrcweir { 313cdf0e10cSrcweir // get service provider 314cdf0e10cSrcweir uno::Reference< XMultiServiceFactory > xSMgr( unohelper::GetMultiServiceFactory() ); 315*86e1cf34SPedro Giffuni // create configuration hierarchical access name 316cdf0e10cSrcweir if( xSMgr.is() ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir try 319cdf0e10cSrcweir { 320cdf0e10cSrcweir uno::Reference< XMultiServiceFactory > xConfigProvider( 321cdf0e10cSrcweir uno::Reference< XMultiServiceFactory >( 322cdf0e10cSrcweir xSMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 323cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationProvider" ))), 324cdf0e10cSrcweir UNO_QUERY ) 325cdf0e10cSrcweir ); 326cdf0e10cSrcweir if( xConfigProvider.is() ) 327cdf0e10cSrcweir { 328cdf0e10cSrcweir Sequence< Any > aArgs(1); 329cdf0e10cSrcweir PropertyValue aVal; 330cdf0e10cSrcweir aVal.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); 331cdf0e10cSrcweir aVal.Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/Misc" ) ); 332cdf0e10cSrcweir aArgs.getArray()[0] <<= aVal; 333cdf0e10cSrcweir uno::Reference< XNameAccess > xConfigAccess( 334cdf0e10cSrcweir uno::Reference< XNameAccess >( 335cdf0e10cSrcweir xConfigProvider->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 336cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationAccess" )), 337cdf0e10cSrcweir aArgs ), 338cdf0e10cSrcweir UNO_QUERY ) 339cdf0e10cSrcweir ); 340cdf0e10cSrcweir if( xConfigAccess.is() ) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir try 343cdf0e10cSrcweir { 344cdf0e10cSrcweir sal_Bool bValue = sal_False; 345cdf0e10cSrcweir Any aAny = xConfigAccess->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseSystemPrintDialog" ) ) ); 346cdf0e10cSrcweir if( aAny >>= bValue ) 347cdf0e10cSrcweir bNative = bValue; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir catch( NoSuchElementException& ) 350cdf0e10cSrcweir { 351cdf0e10cSrcweir } 352cdf0e10cSrcweir catch( WrappedTargetException& ) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir } 355cdf0e10cSrcweir } 356cdf0e10cSrcweir } 357cdf0e10cSrcweir } 358cdf0e10cSrcweir catch( Exception& ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir } 361cdf0e10cSrcweir } 362cdf0e10cSrcweir } 363cdf0e10cSrcweir catch( WrappedTargetException& ) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir } 366cdf0e10cSrcweir 367cdf0e10cSrcweir return bNative; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir sal_uLong AquaSalInfoPrinter::GetCapabilities( const ImplJobSetup*, sal_uInt16 i_nType ) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir switch( i_nType ) 373cdf0e10cSrcweir { 374cdf0e10cSrcweir case PRINTER_CAPABILITIES_SUPPORTDIALOG: 375cdf0e10cSrcweir return 0; 376cdf0e10cSrcweir case PRINTER_CAPABILITIES_COPIES: 377cdf0e10cSrcweir return 0xffff; 378cdf0e10cSrcweir case PRINTER_CAPABILITIES_COLLATECOPIES: 379cdf0e10cSrcweir return 0xffff; 380cdf0e10cSrcweir case PRINTER_CAPABILITIES_SETORIENTATION: 381cdf0e10cSrcweir return 1; 382cdf0e10cSrcweir case PRINTER_CAPABILITIES_SETDUPLEX: 383cdf0e10cSrcweir return 0; 384cdf0e10cSrcweir case PRINTER_CAPABILITIES_SETPAPERBIN: 385cdf0e10cSrcweir return 0; 386cdf0e10cSrcweir case PRINTER_CAPABILITIES_SETPAPERSIZE: 387cdf0e10cSrcweir return 1; 388cdf0e10cSrcweir case PRINTER_CAPABILITIES_SETPAPER: 389cdf0e10cSrcweir return 1; 390cdf0e10cSrcweir case PRINTER_CAPABILITIES_EXTERNALDIALOG: 391cdf0e10cSrcweir return getUseNativeDialog() ? 1 : 0; 392cdf0e10cSrcweir case PRINTER_CAPABILITIES_PDF: 393cdf0e10cSrcweir return 1; 394cdf0e10cSrcweir case PRINTER_CAPABILITIES_USEPULLMODEL: 395cdf0e10cSrcweir return 1; 396cdf0e10cSrcweir default: break; 397cdf0e10cSrcweir }; 398cdf0e10cSrcweir return 0; 399cdf0e10cSrcweir } 400cdf0e10cSrcweir 401cdf0e10cSrcweir // ----------------------------------------------------------------------- 402cdf0e10cSrcweir 403cdf0e10cSrcweir void AquaSalInfoPrinter::GetPageInfo( const ImplJobSetup*, 404cdf0e10cSrcweir long& o_rOutWidth, long& o_rOutHeight, 405cdf0e10cSrcweir long& o_rPageOffX, long& o_rPageOffY, 406cdf0e10cSrcweir long& o_rPageWidth, long& o_rPageHeight ) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir if( mpPrintInfo ) 409cdf0e10cSrcweir { 4108a718ffcSHerbert Dürr sal_Int32 nDPIX = 72, nDPIY = 72; 411cdf0e10cSrcweir mpGraphics->GetResolution( nDPIX, nDPIY ); 412cdf0e10cSrcweir const double fXScaling = static_cast<double>(nDPIX)/72.0, 413cdf0e10cSrcweir fYScaling = static_cast<double>(nDPIY)/72.0; 414cdf0e10cSrcweir 415cdf0e10cSrcweir NSSize aPaperSize = [mpPrintInfo paperSize]; 416cdf0e10cSrcweir o_rPageWidth = static_cast<long>( double(aPaperSize.width) * fXScaling ); 417cdf0e10cSrcweir o_rPageHeight = static_cast<long>( double(aPaperSize.height) * fYScaling ); 418cdf0e10cSrcweir 419cdf0e10cSrcweir NSRect aImageRect = [mpPrintInfo imageablePageBounds]; 420cdf0e10cSrcweir o_rPageOffX = static_cast<long>( aImageRect.origin.x * fXScaling ); 421cdf0e10cSrcweir o_rPageOffY = static_cast<long>( (aPaperSize.height - aImageRect.size.height - aImageRect.origin.y) * fYScaling ); 422cdf0e10cSrcweir o_rOutWidth = static_cast<long>( aImageRect.size.width * fXScaling ); 423cdf0e10cSrcweir o_rOutHeight = static_cast<long>( aImageRect.size.height * fYScaling ); 424cdf0e10cSrcweir 425cdf0e10cSrcweir if( mePageOrientation == ORIENTATION_LANDSCAPE ) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir std::swap( o_rOutWidth, o_rOutHeight ); 428cdf0e10cSrcweir std::swap( o_rPageWidth, o_rPageHeight ); 429cdf0e10cSrcweir std::swap( o_rPageOffX, o_rPageOffY ); 430cdf0e10cSrcweir } 431cdf0e10cSrcweir } 432cdf0e10cSrcweir } 433cdf0e10cSrcweir 434cdf0e10cSrcweir static Size getPageSize( vcl::PrinterController& i_rController, sal_Int32 i_nPage ) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir Size aPageSize; 437cdf0e10cSrcweir Sequence< PropertyValue > aPageParms( i_rController.getPageParameters( i_nPage ) ); 438cdf0e10cSrcweir for( sal_Int32 nProperty = 0, nPropertyCount = aPageParms.getLength(); nProperty < nPropertyCount; ++nProperty ) 439cdf0e10cSrcweir { 440cdf0e10cSrcweir if( aPageParms[ nProperty ].Name.equalsAscii( "PageSize" ) ) 441cdf0e10cSrcweir { 442cdf0e10cSrcweir awt::Size aSize; 443cdf0e10cSrcweir aPageParms[ nProperty].Value >>= aSize; 444cdf0e10cSrcweir aPageSize.Width() = aSize.Width; 445cdf0e10cSrcweir aPageSize.Height() = aSize.Height; 446cdf0e10cSrcweir break; 447cdf0e10cSrcweir } 448cdf0e10cSrcweir } 449cdf0e10cSrcweir return aPageSize; 450cdf0e10cSrcweir } 451cdf0e10cSrcweir 452cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::StartJob( const String* i_pFileName, 453cdf0e10cSrcweir const String& i_rJobName, 454cdf0e10cSrcweir const String& /*i_rAppName*/, 455cdf0e10cSrcweir ImplJobSetup* i_pSetupData, 456cdf0e10cSrcweir vcl::PrinterController& i_rController 457cdf0e10cSrcweir ) 458cdf0e10cSrcweir { 459cdf0e10cSrcweir if( mbJob ) 460cdf0e10cSrcweir return sal_False; 461cdf0e10cSrcweir 462cdf0e10cSrcweir sal_Bool bSuccess = sal_False; 463cdf0e10cSrcweir bool bWasAborted = false; 464cdf0e10cSrcweir AquaSalInstance* pInst = GetSalData()->mpFirstInstance; 465cdf0e10cSrcweir PrintAccessoryViewState aAccViewState; 466cdf0e10cSrcweir sal_Int32 nAllPages = 0; 467cdf0e10cSrcweir 468cdf0e10cSrcweir // reset IsLastPage 469cdf0e10cSrcweir i_rController.setLastPage( sal_False ); 470cdf0e10cSrcweir 471cdf0e10cSrcweir // update job data 472cdf0e10cSrcweir if( i_pSetupData ) 473cdf0e10cSrcweir SetData( ~0, i_pSetupData ); 474cdf0e10cSrcweir 475cdf0e10cSrcweir // do we want a progress panel ? 476cdf0e10cSrcweir sal_Bool bShowProgressPanel = sal_True; 477cdf0e10cSrcweir beans::PropertyValue* pMonitor = i_rController.getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MonitorVisible" ) ) ); 478cdf0e10cSrcweir if( pMonitor ) 479cdf0e10cSrcweir pMonitor->Value >>= bShowProgressPanel; 480cdf0e10cSrcweir if( ! i_rController.isShowDialogs() ) 481cdf0e10cSrcweir bShowProgressPanel = sal_False; 482cdf0e10cSrcweir 483cdf0e10cSrcweir // possibly create one job for collated output 484cdf0e10cSrcweir sal_Bool bSinglePrintJobs = sal_False; 485cdf0e10cSrcweir beans::PropertyValue* pSingleValue = i_rController.getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintCollateAsSingleJobs" ) ) ); 486cdf0e10cSrcweir if( pSingleValue ) 487cdf0e10cSrcweir { 488cdf0e10cSrcweir pSingleValue->Value >>= bSinglePrintJobs; 489cdf0e10cSrcweir } 490cdf0e10cSrcweir 491cdf0e10cSrcweir // FIXME: jobStarted() should be done after the print dialog has ended (if there is one) 492cdf0e10cSrcweir // how do I know when that might be ? 493cdf0e10cSrcweir i_rController.jobStarted(); 494cdf0e10cSrcweir 495cdf0e10cSrcweir 496cdf0e10cSrcweir int nCopies = i_rController.getPrinter()->GetCopyCount(); 497cdf0e10cSrcweir int nJobs = 1; 498cdf0e10cSrcweir if( bSinglePrintJobs ) 499cdf0e10cSrcweir { 500cdf0e10cSrcweir nJobs = nCopies; 501cdf0e10cSrcweir nCopies = 1; 502cdf0e10cSrcweir } 503cdf0e10cSrcweir 504cdf0e10cSrcweir for( int nCurJob = 0; nCurJob < nJobs; nCurJob++ ) 505cdf0e10cSrcweir { 506cdf0e10cSrcweir aAccViewState.bNeedRestart = true; 507cdf0e10cSrcweir do 508cdf0e10cSrcweir { 509cdf0e10cSrcweir if( aAccViewState.bNeedRestart ) 510cdf0e10cSrcweir { 511cdf0e10cSrcweir mnCurPageRangeStart = 0; 512cdf0e10cSrcweir mnCurPageRangeCount = 0; 513cdf0e10cSrcweir nAllPages = i_rController.getFilteredPageCount(); 514cdf0e10cSrcweir } 515cdf0e10cSrcweir 516cdf0e10cSrcweir aAccViewState.bNeedRestart = false; 517cdf0e10cSrcweir 518cdf0e10cSrcweir Size aCurSize( 21000, 29700 ); 519cdf0e10cSrcweir if( nAllPages > 0 ) 520cdf0e10cSrcweir { 521cdf0e10cSrcweir mnCurPageRangeCount = 1; 522cdf0e10cSrcweir aCurSize = getPageSize( i_rController, mnCurPageRangeStart ); 523cdf0e10cSrcweir Size aNextSize( aCurSize ); 524cdf0e10cSrcweir 525cdf0e10cSrcweir // print pages up to a different size 526cdf0e10cSrcweir while( mnCurPageRangeCount + mnCurPageRangeStart < nAllPages ) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir aNextSize = getPageSize( i_rController, mnCurPageRangeStart + mnCurPageRangeCount ); 529cdf0e10cSrcweir if( aCurSize == aNextSize // same page size 530cdf0e10cSrcweir || 531cdf0e10cSrcweir (aCurSize.Width() == aNextSize.Height() && aCurSize.Height() == aNextSize.Width()) // same size, but different orientation 532cdf0e10cSrcweir ) 533cdf0e10cSrcweir { 534cdf0e10cSrcweir mnCurPageRangeCount++; 535cdf0e10cSrcweir } 536cdf0e10cSrcweir else 537cdf0e10cSrcweir break; 538cdf0e10cSrcweir } 539cdf0e10cSrcweir } 540cdf0e10cSrcweir else 541cdf0e10cSrcweir mnCurPageRangeCount = 0; 542cdf0e10cSrcweir 543cdf0e10cSrcweir // now for the current run 544cdf0e10cSrcweir mnStartPageOffsetX = mnStartPageOffsetY = 0; 545cdf0e10cSrcweir // setup the paper size and orientation 546cdf0e10cSrcweir // do this on our associated Printer object, since that is 547cdf0e10cSrcweir // out interface to the applications which occasionally rely on the paper 548cdf0e10cSrcweir // information (e.g. brochure printing scales to the found paper size) 549cdf0e10cSrcweir // also SetPaperSizeUser has the advantage that we can share a 550cdf0e10cSrcweir // platform independent paper matching algorithm 551cdf0e10cSrcweir boost::shared_ptr<Printer> pPrinter( i_rController.getPrinter() ); 552cdf0e10cSrcweir pPrinter->SetMapMode( MapMode( MAP_100TH_MM ) ); 553cdf0e10cSrcweir pPrinter->SetPaperSizeUser( aCurSize, true ); 554cdf0e10cSrcweir 555cdf0e10cSrcweir // create view 556cdf0e10cSrcweir NSView* pPrintView = [[AquaPrintView alloc] initWithController: &i_rController withInfoPrinter: this]; 557cdf0e10cSrcweir 558cdf0e10cSrcweir NSMutableDictionary* pPrintDict = [mpPrintInfo dictionary]; 559cdf0e10cSrcweir 560cdf0e10cSrcweir // set filename 561cdf0e10cSrcweir if( i_pFileName ) 562cdf0e10cSrcweir { 563cdf0e10cSrcweir [mpPrintInfo setJobDisposition: NSPrintSaveJob]; 564cdf0e10cSrcweir NSString* pPath = CreateNSString( *i_pFileName ); 565cdf0e10cSrcweir [pPrintDict setObject: pPath forKey: NSPrintSavePath]; 566cdf0e10cSrcweir [pPath release]; 567cdf0e10cSrcweir } 568cdf0e10cSrcweir 569cdf0e10cSrcweir [pPrintDict setObject: [[NSNumber numberWithInt: nCopies] autorelease] forKey: NSPrintCopies]; 570cdf0e10cSrcweir if( nCopies > 1 ) 571cdf0e10cSrcweir [pPrintDict setObject: [[NSNumber numberWithBool: pPrinter->IsCollateCopy()] autorelease] forKey: NSPrintMustCollate]; 572cdf0e10cSrcweir [pPrintDict setObject: [[NSNumber numberWithBool: YES] autorelease] forKey: NSPrintDetailedErrorReporting]; 573cdf0e10cSrcweir [pPrintDict setObject: [[NSNumber numberWithInt: 1] autorelease] forKey: NSPrintFirstPage]; 574cdf0e10cSrcweir // #i103253# weird: for some reason, autoreleasing the value below like the others above 575cdf0e10cSrcweir // leads do a double free malloc error. Why this value should behave differently from all the others 576cdf0e10cSrcweir // is a mystery. 577cdf0e10cSrcweir [pPrintDict setObject: [NSNumber numberWithInt: mnCurPageRangeCount] forKey: NSPrintLastPage]; 578cdf0e10cSrcweir 579cdf0e10cSrcweir 580cdf0e10cSrcweir // create print operation 581cdf0e10cSrcweir NSPrintOperation* pPrintOperation = [NSPrintOperation printOperationWithView: pPrintView printInfo: mpPrintInfo]; 582cdf0e10cSrcweir 583cdf0e10cSrcweir if( pPrintOperation ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir NSObject* pReleaseAfterUse = nil; 586cdf0e10cSrcweir bool bShowPanel = (! i_rController.isDirectPrint() && getUseNativeDialog() && i_rController.isShowDialogs() ); 587cdf0e10cSrcweir [pPrintOperation setShowsPrintPanel: bShowPanel ? YES : NO ]; 588cdf0e10cSrcweir [pPrintOperation setShowsProgressPanel: bShowProgressPanel ? YES : NO]; 589cdf0e10cSrcweir 590cdf0e10cSrcweir // set job title (since MacOSX 10.5) 591cdf0e10cSrcweir if( [pPrintOperation respondsToSelector: @selector(setJobTitle:)] ) 592cdf0e10cSrcweir [pPrintOperation performSelector: @selector(setJobTitle:) withObject: [CreateNSString( i_rJobName ) autorelease]]; 593cdf0e10cSrcweir 594cdf0e10cSrcweir if( bShowPanel && mnCurPageRangeStart == 0 && nCurJob == 0) // only the first range of pages (in the first job) gets the accesory view 595cdf0e10cSrcweir pReleaseAfterUse = [AquaPrintAccessoryView setupPrinterPanel: pPrintOperation withController: &i_rController withState: &aAccViewState]; 596cdf0e10cSrcweir 597cdf0e10cSrcweir bSuccess = sal_True; 598cdf0e10cSrcweir mbJob = true; 599cdf0e10cSrcweir pInst->startedPrintJob(); 600cdf0e10cSrcweir [pPrintOperation runOperation]; 601cdf0e10cSrcweir pInst->endedPrintJob(); 602cdf0e10cSrcweir bWasAborted = [[[pPrintOperation printInfo] jobDisposition] compare: NSPrintCancelJob] == NSOrderedSame; 603cdf0e10cSrcweir mbJob = false; 604cdf0e10cSrcweir if( pReleaseAfterUse ) 605cdf0e10cSrcweir [pReleaseAfterUse release]; 606cdf0e10cSrcweir } 607cdf0e10cSrcweir 608cdf0e10cSrcweir mnCurPageRangeStart += mnCurPageRangeCount; 609cdf0e10cSrcweir mnCurPageRangeCount = 1; 610cdf0e10cSrcweir } while( aAccViewState.bNeedRestart || mnCurPageRangeStart + mnCurPageRangeCount < nAllPages ); 611cdf0e10cSrcweir } 612cdf0e10cSrcweir 613cdf0e10cSrcweir // inform application that it can release its data 614cdf0e10cSrcweir // this is awkward, but the XRenderable interface has no method for this, 615cdf0e10cSrcweir // so we need to call XRenderadble::render one last time with IsLastPage = sal_True 616cdf0e10cSrcweir i_rController.setLastPage( sal_True ); 617cdf0e10cSrcweir GDIMetaFile aPageFile; 618cdf0e10cSrcweir if( mrContext ) 619cdf0e10cSrcweir SetupPrinterGraphics( mrContext ); 620cdf0e10cSrcweir i_rController.getFilteredPageFile( 0, aPageFile ); 621cdf0e10cSrcweir 622cdf0e10cSrcweir i_rController.setJobState( bWasAborted 623cdf0e10cSrcweir ? view::PrintableState_JOB_ABORTED 624cdf0e10cSrcweir : view::PrintableState_JOB_SPOOLED ); 625cdf0e10cSrcweir 626cdf0e10cSrcweir mnCurPageRangeStart = mnCurPageRangeCount = 0; 627cdf0e10cSrcweir 628cdf0e10cSrcweir return bSuccess; 629cdf0e10cSrcweir } 630cdf0e10cSrcweir 631cdf0e10cSrcweir // ----------------------------------------------------------------------- 632cdf0e10cSrcweir 633cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::EndJob() 634cdf0e10cSrcweir { 635cdf0e10cSrcweir mnStartPageOffsetX = mnStartPageOffsetY = 0; 636cdf0e10cSrcweir mbJob = false; 637cdf0e10cSrcweir return sal_True; 638cdf0e10cSrcweir } 639cdf0e10cSrcweir 640cdf0e10cSrcweir // ----------------------------------------------------------------------- 641cdf0e10cSrcweir 642cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::AbortJob() 643cdf0e10cSrcweir { 644cdf0e10cSrcweir mbJob = false; 645cdf0e10cSrcweir 646cdf0e10cSrcweir // FIXME: implementation 647cdf0e10cSrcweir return sal_False; 648cdf0e10cSrcweir } 649cdf0e10cSrcweir 650cdf0e10cSrcweir // ----------------------------------------------------------------------- 651cdf0e10cSrcweir 652cdf0e10cSrcweir SalGraphics* AquaSalInfoPrinter::StartPage( ImplJobSetup* i_pSetupData, sal_Bool i_bNewJobData ) 653cdf0e10cSrcweir { 654cdf0e10cSrcweir if( i_bNewJobData && i_pSetupData ) 655cdf0e10cSrcweir SetPrinterData( i_pSetupData ); 656cdf0e10cSrcweir 657cdf0e10cSrcweir CGContextRef rContext = reinterpret_cast<CGContextRef>([[NSGraphicsContext currentContext] graphicsPort]); 658cdf0e10cSrcweir 659cdf0e10cSrcweir SetupPrinterGraphics( rContext ); 660cdf0e10cSrcweir 661cdf0e10cSrcweir return mpGraphics; 662cdf0e10cSrcweir } 663cdf0e10cSrcweir 664cdf0e10cSrcweir // ----------------------------------------------------------------------- 665cdf0e10cSrcweir 666cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::EndPage() 667cdf0e10cSrcweir { 668cdf0e10cSrcweir mpGraphics->InvalidateContext(); 669cdf0e10cSrcweir return sal_True; 670cdf0e10cSrcweir } 671cdf0e10cSrcweir 672cdf0e10cSrcweir // ----------------------------------------------------------------------- 673cdf0e10cSrcweir 674cdf0e10cSrcweir sal_uLong AquaSalInfoPrinter::GetErrorCode() const 675cdf0e10cSrcweir { 676cdf0e10cSrcweir return 0; 677cdf0e10cSrcweir } 678cdf0e10cSrcweir 679cdf0e10cSrcweir // ======================================================================= 680cdf0e10cSrcweir 681cdf0e10cSrcweir AquaSalPrinter::AquaSalPrinter( AquaSalInfoPrinter* i_pInfoPrinter ) : 682cdf0e10cSrcweir mpInfoPrinter( i_pInfoPrinter ) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir } 685cdf0e10cSrcweir 686cdf0e10cSrcweir // ----------------------------------------------------------------------- 687cdf0e10cSrcweir 688cdf0e10cSrcweir AquaSalPrinter::~AquaSalPrinter() 689cdf0e10cSrcweir { 690cdf0e10cSrcweir } 691cdf0e10cSrcweir 692cdf0e10cSrcweir // ----------------------------------------------------------------------- 693cdf0e10cSrcweir 694cdf0e10cSrcweir sal_Bool AquaSalPrinter::StartJob( const String* i_pFileName, 695cdf0e10cSrcweir const String& i_rJobName, 696cdf0e10cSrcweir const String& i_rAppName, 697cdf0e10cSrcweir ImplJobSetup* i_pSetupData, 698cdf0e10cSrcweir vcl::PrinterController& i_rController ) 699cdf0e10cSrcweir { 700cdf0e10cSrcweir return mpInfoPrinter->StartJob( i_pFileName, i_rJobName, i_rAppName, i_pSetupData, i_rController ); 701cdf0e10cSrcweir } 702cdf0e10cSrcweir 703cdf0e10cSrcweir // ----------------------------------------------------------------------- 704cdf0e10cSrcweir 705cdf0e10cSrcweir sal_Bool AquaSalPrinter::StartJob( const XubString* /*i_pFileName*/, 706cdf0e10cSrcweir const XubString& /*i_rJobName*/, 707cdf0e10cSrcweir const XubString& /*i_rAppName*/, 708cdf0e10cSrcweir sal_uLong /*i_nCopies*/, 709cdf0e10cSrcweir bool /*i_bCollate*/, 710cdf0e10cSrcweir bool /*i_bDirect*/, 711cdf0e10cSrcweir ImplJobSetup* ) 712cdf0e10cSrcweir { 713cdf0e10cSrcweir DBG_ERROR( "should never be called" ); 714cdf0e10cSrcweir return sal_False; 715cdf0e10cSrcweir } 716cdf0e10cSrcweir 717cdf0e10cSrcweir // ----------------------------------------------------------------------- 718cdf0e10cSrcweir 719cdf0e10cSrcweir sal_Bool AquaSalPrinter::EndJob() 720cdf0e10cSrcweir { 721cdf0e10cSrcweir return mpInfoPrinter->EndJob(); 722cdf0e10cSrcweir } 723cdf0e10cSrcweir 724cdf0e10cSrcweir // ----------------------------------------------------------------------- 725cdf0e10cSrcweir 726cdf0e10cSrcweir sal_Bool AquaSalPrinter::AbortJob() 727cdf0e10cSrcweir { 728cdf0e10cSrcweir return mpInfoPrinter->AbortJob(); 729cdf0e10cSrcweir } 730cdf0e10cSrcweir 731cdf0e10cSrcweir // ----------------------------------------------------------------------- 732cdf0e10cSrcweir 733cdf0e10cSrcweir SalGraphics* AquaSalPrinter::StartPage( ImplJobSetup* i_pSetupData, sal_Bool i_bNewJobData ) 734cdf0e10cSrcweir { 735cdf0e10cSrcweir return mpInfoPrinter->StartPage( i_pSetupData, i_bNewJobData ); 736cdf0e10cSrcweir } 737cdf0e10cSrcweir 738cdf0e10cSrcweir // ----------------------------------------------------------------------- 739cdf0e10cSrcweir 740cdf0e10cSrcweir sal_Bool AquaSalPrinter::EndPage() 741cdf0e10cSrcweir { 742cdf0e10cSrcweir return mpInfoPrinter->EndPage(); 743cdf0e10cSrcweir } 744cdf0e10cSrcweir 745cdf0e10cSrcweir // ----------------------------------------------------------------------- 746cdf0e10cSrcweir 747cdf0e10cSrcweir sal_uLong AquaSalPrinter::GetErrorCode() 748cdf0e10cSrcweir { 749cdf0e10cSrcweir return mpInfoPrinter->GetErrorCode(); 750cdf0e10cSrcweir } 751cdf0e10cSrcweir 752cdf0e10cSrcweir void AquaSalInfoPrinter::InitPaperFormats( const ImplJobSetup* ) 753cdf0e10cSrcweir { 754cdf0e10cSrcweir m_aPaperFormats.clear(); 755cdf0e10cSrcweir m_bPapersInit = true; 756cdf0e10cSrcweir 757cdf0e10cSrcweir if( mpPrinter ) 758cdf0e10cSrcweir { 759cdf0e10cSrcweir if( [mpPrinter statusForTable: @"PPD"] == NSPrinterTableOK ) 760cdf0e10cSrcweir { 761cdf0e10cSrcweir NSArray* pPaperNames = [mpPrinter stringListForKey: @"PageSize" inTable: @"PPD"]; 762cdf0e10cSrcweir if( pPaperNames ) 763cdf0e10cSrcweir { 764cdf0e10cSrcweir unsigned int nPapers = [pPaperNames count]; 765cdf0e10cSrcweir for( unsigned int i = 0; i < nPapers; i++ ) 766cdf0e10cSrcweir { 767cdf0e10cSrcweir NSString* pPaper = [pPaperNames objectAtIndex: i]; 768cdf0e10cSrcweir // first try to match the name 769cdf0e10cSrcweir rtl::OString aPaperName( [pPaper UTF8String] ); 770cdf0e10cSrcweir Paper ePaper = PaperInfo::fromPSName( aPaperName ); 771cdf0e10cSrcweir if( ePaper != PAPER_USER ) 772cdf0e10cSrcweir { 773cdf0e10cSrcweir m_aPaperFormats.push_back( PaperInfo( ePaper ) ); 774cdf0e10cSrcweir } 775cdf0e10cSrcweir else 776cdf0e10cSrcweir { 777cdf0e10cSrcweir NSSize aPaperSize = [mpPrinter pageSizeForPaper: pPaper]; 778cdf0e10cSrcweir if( aPaperSize.width > 0 && aPaperSize.height > 0 ) 779cdf0e10cSrcweir { 780cdf0e10cSrcweir PaperInfo aInfo( PtTo10Mu( aPaperSize.width ), 781cdf0e10cSrcweir PtTo10Mu( aPaperSize.height ) ); 782cdf0e10cSrcweir if( aInfo.getPaper() == PAPER_USER ) 783cdf0e10cSrcweir aInfo.doSloppyFit(); 784cdf0e10cSrcweir m_aPaperFormats.push_back( aInfo ); 785cdf0e10cSrcweir } 786cdf0e10cSrcweir } 787cdf0e10cSrcweir } 788cdf0e10cSrcweir } 789cdf0e10cSrcweir } 790cdf0e10cSrcweir } 791cdf0e10cSrcweir } 792cdf0e10cSrcweir 793cdf0e10cSrcweir const PaperInfo* AquaSalInfoPrinter::matchPaper( long i_nWidth, long i_nHeight, Orientation& o_rOrientation ) const 794cdf0e10cSrcweir { 795cdf0e10cSrcweir if( ! m_bPapersInit ) 796cdf0e10cSrcweir const_cast<AquaSalInfoPrinter*>(this)->InitPaperFormats( NULL ); 797cdf0e10cSrcweir 798cdf0e10cSrcweir const PaperInfo* pMatch = NULL; 799cdf0e10cSrcweir o_rOrientation = ORIENTATION_PORTRAIT; 800cdf0e10cSrcweir for( int n = 0; n < 2 ; n++ ) 801cdf0e10cSrcweir { 802cdf0e10cSrcweir for( size_t i = 0; i < m_aPaperFormats.size(); i++ ) 803cdf0e10cSrcweir { 804cdf0e10cSrcweir if( abs( m_aPaperFormats[i].getWidth() - i_nWidth ) < 50 && 805cdf0e10cSrcweir abs( m_aPaperFormats[i].getHeight() - i_nHeight ) < 50 ) 806cdf0e10cSrcweir { 807cdf0e10cSrcweir pMatch = &m_aPaperFormats[i]; 808cdf0e10cSrcweir return pMatch; 809cdf0e10cSrcweir } 810cdf0e10cSrcweir } 811cdf0e10cSrcweir o_rOrientation = ORIENTATION_LANDSCAPE; 812cdf0e10cSrcweir std::swap( i_nWidth, i_nHeight ); 813cdf0e10cSrcweir } 814cdf0e10cSrcweir return pMatch; 815cdf0e10cSrcweir } 816cdf0e10cSrcweir 817cdf0e10cSrcweir int AquaSalInfoPrinter::GetLandscapeAngle( const ImplJobSetup* ) 818cdf0e10cSrcweir { 819cdf0e10cSrcweir return 900; 820cdf0e10cSrcweir } 821cdf0e10cSrcweir 822cdf0e10cSrcweir 823