Index: source/helper/helper.cxx =================================================================== RCS file: /cvs/gsl/psprint/source/helper/helper.cxx,v retrieving revision 1.3.6.1.2.1 diff -u -r1.3.6.1.2.1 helper.cxx --- source/helper/helper.cxx 5 Jun 2003 04:30:04 -0000 1.3.6.1.2.1 +++ source/helper/helper.cxx 11 Jun 2003 18:52:33 -0000 @@ -233,7 +233,7 @@ if( rOutFile.write( pWriteBuffer, nBytesToWrite, nRead ) || nRead != nBytesToWrite ) bSuccess = false; - delete pWriteBuffer; + delete [] pWriteBuffer; } else { @@ -262,7 +262,7 @@ else bSuccess = false; - delete pBuffer; + delete [] pBuffer; } else if( nType == 3 ) bEof = true; Index: source/helper/ppdparser.cxx =================================================================== RCS file: /cvs/gsl/psprint/source/helper/ppdparser.cxx,v retrieving revision 1.3.6.2 diff -u -r1.3.6.2 ppdparser.cxx --- source/helper/ppdparser.cxx 5 Jun 2003 04:30:04 -0000 1.3.6.2 +++ source/helper/ppdparser.cxx 11 Jun 2003 18:52:54 -0000 @@ -385,8 +385,6 @@ ByteString aCupsFilterString( pKey->getValue( 0 )->m_aValue, RTL_TEXTENCODING_ISO_8859_1 ); if ( strstr(aCupsFilterString.GetBuffer(), "application/pdf") > 0 ) m_bType42Capable = true; - -fprintf( stderr, "##### PPDParser::PPDParser() got 'cupsFilter' key, app/pdf %s found. %d Value: %s\n", m_bType42Capable ? "WAS" : "NOT", aCupsFilterString.Search("application/pdf"), aCupsFilterString.GetBuffer() ); } } #endif @@ -730,7 +728,7 @@ if( ! aConstraint.m_pKey1 || ! aConstraint.m_pKey2 || bFailed ) { #ifdef __DEBUG - fprintf( stderr, "Warning: constraint \"%s\" is invalid\n", rLine.GetStr() ); + fprintf( stderr, "Warning: constraint \"%s\" is invalid\n", rLine.GetBuffer() ); #endif } else @@ -1249,10 +1247,10 @@ { #ifdef __DEBUG fprintf( stderr, "PPDContext::setValue: option %s (%s) is constrained after setting %s to %s\n", - it->first->getKey().GetStr(), - it->second->m_aOption.GetStr(), - pKey->getKey().GetStr(), - pValue->m_aOption.GetStr() ); + it->first->getKey().GetBuffer(), + it->second->m_aOption.GetBuffer(), + pKey->getKey().GetBuffer(), + pValue->m_aOption.GetBuffer() ); #endif resetValue( it->first, true ); it = m_aCurrentValues.begin(); @@ -1300,7 +1298,7 @@ return false; #ifdef __DEBUG - fprintf( stderr, "resetValue( %s, %s ) ", pKey->getKey().GetStr(), + fprintf( stderr, "resetValue( %s, %s ) ", pKey->getKey().GetBuffer(), bDefaultable ? "true" : "false" ); #endif Index: source/helper/strhelper.cxx =================================================================== RCS file: /cvs/gsl/psprint/source/helper/strhelper.cxx,v retrieving revision 1.2 diff -u -r1.2 strhelper.cxx --- source/helper/strhelper.cxx 12 Dec 2001 14:39:50 -0000 1.2 +++ source/helper/strhelper.cxx 11 Jun 2003 18:53:04 -0000 @@ -61,7 +61,9 @@ #include #ifdef SOLARIS #include // finite +#include #endif +#include #include // for isnan #include // strcpy @@ -162,7 +164,7 @@ return String(); int nActualToken = 0; - sal_Unicode* pBuffer = new sal_Unicode[ nLen + 1 ]; + sal_Unicode* pBuffer = (sal_Unicode*)alloca( sizeof(sal_Unicode)*( nLen + 1 ) ); const sal_Unicode* pRun = rLine.GetBuffer(); sal_Unicode* pLeap; @@ -203,7 +205,6 @@ *pLeap = 0; String aRet( pBuffer ); - delete pBuffer; return aRet; } @@ -214,7 +215,7 @@ return ByteString(); int nActualToken = 0; - char* pBuffer = new char[ nLen + 1 ]; + char* pBuffer = (char*)alloca( nLen + 1 ); const char* pRun = rLine.GetBuffer(); char* pLeap; @@ -255,7 +256,6 @@ *pLeap = 0; ByteString aRet( pBuffer ); - delete pBuffer; return aRet; } @@ -367,7 +367,7 @@ if( ! nLen ) return String(); - sal_Unicode *pBuffer = new sal_Unicode[ nLen + 1 ]; + sal_Unicode *pBuffer = (sal_Unicode*)alloca( sizeof(sal_Unicode)*(nLen + 1) ); const sal_Unicode *pRun = rLine.GetBuffer(); sal_Unicode *pLeap = pBuffer; @@ -415,7 +415,6 @@ *pLeap = 0; String aRet( *pBuffer == ' ' ? pBuffer+1 : pBuffer ); - delete pBuffer; return aRet; } @@ -425,7 +424,7 @@ if( ! nLen ) return ByteString(); - char *pBuffer = new char[ nLen + 1 ]; + char *pBuffer = (char*)alloca( nLen + 1 ); const char *pRun = rLine.GetBuffer(); char *pLeap = pBuffer; @@ -473,7 +472,6 @@ *pLeap = 0; ByteString aRet( *pBuffer == ' ' ? pBuffer+1 : pBuffer ); - delete pBuffer; return aRet; } Index: source/printer/jobdata.cxx =================================================================== RCS file: /cvs/gsl/psprint/source/printer/jobdata.cxx,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 jobdata.cxx --- source/printer/jobdata.cxx 8 May 2001 11:46:03 -0000 1.1.1.1 +++ source/printer/jobdata.cxx 11 Jun 2003 18:53:04 -0000 @@ -63,6 +63,12 @@ #include #include +#ifdef SOLARIS +#include +#else +#include +#endif + using namespace psp; using namespace rtl; @@ -127,7 +133,7 @@ aStream.Write( pContextBuffer, nBytes ); // success - pData = new char[ bytes = aStream.GetSize() ]; + pData = rtl_allocateMemory( bytes = aStream.GetSize() ); memcpy( pData, aStream.GetData(), bytes ); return true; } @@ -206,10 +212,9 @@ { rJobData.m_aContext.setParser( rJobData.m_pParser ); int nBytes = bytes - aStream.Tell(); - void* pRemain = new char[ bytes - aStream.Tell() ]; + void* pRemain = alloca( bytes - aStream.Tell() ); aStream.Read( pRemain, nBytes ); rJobData.m_aContext.rebuildFromStreamBuffer( pRemain, nBytes ); - delete pRemain; bContext = true; } } Index: source/printer/printerinfomanager.cxx =================================================================== RCS file: /cvs/gsl/psprint/source/printer/printerinfomanager.cxx,v retrieving revision 1.11.8.1.2.3 diff -u -r1.11.8.1.2.3 printerinfomanager.cxx --- source/printer/printerinfomanager.cxx 5 Jun 2003 04:30:05 -0000 1.11.8.1.2.3 +++ source/printer/printerinfomanager.cxx 11 Jun 2003 18:53:20 -0000 @@ -598,18 +598,18 @@ if( aPrinter.m_aInfo.m_pParser ) { // merge the ppd context keys if the printer has the same keys and values - // this is a bit tricky, since it involves mixing two PPDs - // without constraints which might end up badly - // this feature should be use with caution // it is mainly to select default paper sizes for new printers for( int nPPDValueModified = 0; nPPDValueModified < m_aGlobalDefaults.m_aContext.countValuesModified(); nPPDValueModified++ ) { const PPDKey* pDefKey = m_aGlobalDefaults.m_aContext.getModifiedKey( nPPDValueModified ); const PPDValue* pDefValue = m_aGlobalDefaults.m_aContext.getValue( pDefKey ); + // If the default PPD has a certain key, attempt to get that same key in the Printer's PPD const PPDKey* pPrinterKey = pDefKey ? aPrinter.m_aInfo.m_pParser->getKey( pDefKey->getKey() ) : NULL; + + // The key usually merged is PageSize if( pDefKey && pPrinterKey ) { - // at least the options exist in both PPDs + // Key exists in both the Default PPD and the printer's specific PPD. if( pDefValue ) { const PPDValue* pPrinterValue = pPrinterKey->getValue( pDefValue->m_aOption ); @@ -621,6 +621,61 @@ aPrinter.m_aInfo.m_aContext.setValue( pPrinterKey, NULL ); } } + + // Some CUPS PPDs on Mac OS X (Epson, HP) don't include the requisite + // PageSize information for the value. We have to fudge it from the + // margin information. Others (Canon BJC 8200) have the coordinates + // but not the "setpagedevice" stuff + const PPDKey* pPSizeKey = aPrinter.m_aInfo.m_pParser->getKey( String(RTL_CONSTASCII_USTRINGPARAM("PageSize")) ); + if ( pPSizeKey ) + { + int psIndex = 0; + int nNumValues = pPSizeKey->countValues(); + + for ( psIndex = 0; psIndex < nNumValues; psIndex++ ) + { + const PPDValue* pPSizeValue = pPSizeKey->getValue( psIndex ); + + // Only take care of PPD values that are not formatted correctly. + if ( pPSizeValue && + ( !(pPSizeValue->m_aValue.Len()) || + (pPSizeValue->m_aValue.Len() && (pPSizeValue->m_aValue.SearchAscii("setpagedevice")==STRING_NOTFOUND)) ) + ) + { + // Deal with the two cases: 1) where there is a blank PageSize value and + // 2) where there are simply the dimensions as the PageSize value + if ( !pPSizeValue->m_aValue.Len() ) + { + int paperWidth; + int paperHeight; + char aWidth[ 32 ]; + char aHeight[ 32 ]; + + // Grab dimensions for this paper size from the "PaperDimension" key of the PPD + aPrinter.m_aInfo.m_pParser->getPaperDimension( pPSizeValue->m_aOption, paperWidth, paperHeight ); + snprintf( aWidth, 32, "%d", paperWidth ); + snprintf( aHeight, 32, "%d", paperHeight ); + + // Construct a suitable PageSize key value from the PaperDimension values for this paper size + pPSizeValue->m_aValue.AppendAscii( "<m_aValue.AppendAscii( aWidth ); + pPSizeValue->m_aValue.AppendAscii( " " ); + pPSizeValue->m_aValue.AppendAscii( aHeight ); + pPSizeValue->m_aValue.AppendAscii( "] /ImagingBBox null>> setpagedevice" ); + } + else + { + String aBox( pPSizeValue->m_aValue ); + + // The PageSize value was just the bounding box, add in the correct postscript + pPSizeValue->m_aValue.AssignAscii( "" ); + pPSizeValue->m_aValue.AppendAscii( "<m_aValue.Append( aBox ); + pPSizeValue->m_aValue.AppendAscii( "] /ImagingBBox null>> setpagedevice" ); + } + } + } + } } else { @@ -629,11 +684,16 @@ // Some printers don't have the PPDs in /etc/cups/ppd (like Rendezvous-shared ones) // so we have to simply use a stripped down shared printer PPD for them - aPrinter.m_aInfo.m_aDriverName = String( RTL_CONSTASCII_USTRINGPARAM( "MacShared" ) ); + aPrinter.m_aInfo.m_aDriverName = String( RTL_CONSTASCII_USTRINGPARAM("MacShared") ); aPrinter.m_aInfo.m_pParser = PPDParser::getParser( aPrinter.m_aInfo.m_aDriverName ); aPrinter.m_aInfo.m_aContext.setParser( aPrinter.m_aInfo.m_pParser ); if( !(aPrinter.m_aInfo.m_pParser) ) - fprintf( stderr, "Warning: still couldn't load the PPD, MacShared.ppd may be missing.\n" ); + { + fprintf( stderr, "Warning: still couldn't load the PPD, MacShared.ppd may be missing. Will use generic printer PPD.\n" ); + aPrinter.m_aInfo.m_aDriverName = String( RTL_CONSTASCII_USTRINGPARAM("SGENPRT") ); + aPrinter.m_aInfo.m_pParser = PPDParser::getParser( aPrinter.m_aInfo.m_aDriverName ); + aPrinter.m_aInfo.m_aContext.setParser( aPrinter.m_aInfo.m_pParser ); + } } } #endif Index: source/printergfx/printerjob.cxx =================================================================== RCS file: /cvs/gsl/psprint/source/printergfx/printerjob.cxx,v retrieving revision 1.15.4.3.2.3 diff -u -r1.15.4.3.2.3 printerjob.cxx --- source/printergfx/printerjob.cxx 5 Jun 2003 04:30:06 -0000 1.15.4.3.2.3 +++ source/printergfx/printerjob.cxx 11 Jun 2003 18:53:45 -0000 @@ -740,7 +740,7 @@ const PPDValue *pCupsFilterValue; pCupsFilterKey = pJobData.m_pParser->getKey( String(RTL_CONSTASCII_USTRINGPARAM("cupsFilter")) ); - pCupsFilterValue = pJobData.m_aContext.getValue( pCupsFilterKey ); + pCupsFilterValue = pCupsFilterKey != NULL ? pJobData.m_aContext.getValue( pCupsFilterKey ) : NULL; if ( pCupsFilterValue ) { ByteString aCupsFilterString( pCupsFilterValue->m_aOption, RTL_TEXTENCODING_ISO_8859_1 ); @@ -815,16 +815,6 @@ { #define kJobOptionsStringSize 500 char jobOptions[ kJobOptionsStringSize ]; - /* Determine which printing system we are using, either 'lp' or 'lpr'. They - * each have a different switch for number of copies. - * Note that neither of these two actually honors these arguments on 10.2 right now. - */ - /* - if ( (strstr(psprintPrintCmd.getStr(), "lp ") != NULL) || (psprintPrintCmd=="lp") ) - strncpy( numCopiesSwitch, "-n", 4 ); - else if ( (strstr(psprintPrintCmd.getStr(), "lpr ") != NULL) || (psprintPrintCmd=="lpr") ) - strncpy( numCopiesSwitch, "-#", 4 ); - */ jobOptions[ 0 ] = NULL; /* Based on job options, find out what parameters to pass to the printer. */ @@ -834,23 +824,41 @@ const PPDValue *pSizeValue; const PPDKey *pSlotKey; const PPDValue *pSlotValue; + BOOL needComma = FALSE; - pSizeKey = pJobData.m_pParser->getKey( String(RTL_CONSTASCII_USTRINGPARAM("PageSize")) ); - pSizeValue = pJobData.m_aContext.getValue( pSizeKey ); - if ( pSizeValue ) + // Only CUPS PS->PDF printers require the page size options + if ( printFormat == kApplePrintingUsePDF ) { - ByteString aSizeString( pSizeValue->m_aOption, RTL_TEXTENCODING_ISO_8859_1 ); - snprintf( jobOptions, kJobOptionsStringSize, "-o media=%s", aSizeString.GetBuffer() ); - - pSlotKey = pJobData.m_pParser->getKey( String(RTL_CONSTASCII_USTRINGPARAM("InputSlot")) ); - pSlotValue = pJobData.m_aContext.getValue( pSlotKey ); - if ( pSlotValue ) + // Add page size option if necessary + pSizeKey = pJobData.m_pParser->getKey( String(RTL_CONSTASCII_USTRINGPARAM("PageSize")) ); + pSizeValue = pSizeKey != NULL ? pJobData.m_aContext.getValue( pSizeKey ) : NULL; + if ( pSizeValue ) { - ByteString aSlotString( pSlotValue->m_aOption, RTL_TEXTENCODING_ISO_8859_1 ); - strncat( jobOptions, ",", kJobOptionsStringSize - strlen(jobOptions) ); - strncat( jobOptions, aSlotString.GetBuffer(), kJobOptionsStringSize - strlen(jobOptions) ); + ByteString aSizeString( pSizeValue->m_aOption, RTL_TEXTENCODING_ISO_8859_1 ); + snprintf( jobOptions, kJobOptionsStringSize, "-o \"media=" ); + strncat( jobOptions, aSizeString.GetBuffer(), kJobOptionsStringSize-strlen(jobOptions) ); + needComma = TRUE; } } + + // Add paper tray option if necessary + pSlotKey = pJobData.m_pParser->getKey( String(RTL_CONSTASCII_USTRINGPARAM("InputSlot")) ); + pSlotValue = pSlotKey != NULL ? pJobData.m_aContext.getValue( pSlotKey ) : NULL; + if ( pSlotValue ) + { + ByteString aSlotString( pSlotValue->m_aOption, RTL_TEXTENCODING_ISO_8859_1 ); + // If the string wasn't created from PageSize, create it now + if ( strlen(jobOptions) == 0 ) + snprintf( jobOptions, kJobOptionsStringSize, "-o \"media=" ); + if ( TRUE == needComma ) + strncat( jobOptions, ",", kJobOptionsStringSize - strlen(jobOptions) ); + + strncat( jobOptions, aSlotString.GetBuffer(), kJobOptionsStringSize - strlen(jobOptions) ); + } + + // Add on the ending " to the media= part + if ( strlen(jobOptions) > 0 ) + strncat( jobOptions, "\"", kJobOptionsStringSize - strlen(jobOptions) ); /* Deal with landscape orientation */ // Disable for the moment since testers say it has undesired effects @@ -869,9 +877,12 @@ #endif /* Stupid lp and lpr on 10.2 don't actually honor their respective # copies arguments. - * So we have to just keep printing the job over and over for multiple copies. + * So we have to just keep printing the job over and over for multiple copies for PS->PDF + * printers. Direct-to-PostScript printers can handle the # copies _inside_ the PostScript + * document we are sending to them. */ - for( index = 1; index <= pJobData.m_nCopies; index++ ) + int numCopies = (printFormat == kApplePrintingUsePDF ) ? pJobData.m_nCopies : 1; + for( index = 1; index <= numCopies; index++ ) printCmdErr = system( sysCommandBuffer ); } unlink( pdfFileName ); @@ -1252,8 +1263,6 @@ aKeys[i] = rJob.m_aContext.getModifiedKey( i ); ::std::sort( aKeys.begin(), aKeys.end(), less_ppd_key() ); -fprintf( stderr, "----- FEATURE: %d keys in feature section\n", nKeys ); - for( i = 0; i < nKeys && bSuccess; i++ ) { const PPDKey* pKey = aKeys[i]; @@ -1262,22 +1271,9 @@ pKey->getSetupType() == PPDKey::AnySetup ) { const PPDValue* pValue = rJob.m_aContext.getValue( pKey ); -{ -ByteString bsOption( pValue->m_aOption, RTL_TEXTENCODING_UTF8 ); -ByteString bsValue( pValue->m_aValue, RTL_TEXTENCODING_UTF8 ); -fprintf( stderr," Trying Key, Option: %s, Value: %s\n", bsOption.GetBuffer(), bsValue.GetBuffer() ); -fflush(stderr); -} if(pValue && pValue->m_eType == eInvocation - #ifdef MACOSX - // Some CUPS PPDs on OS X do not have values for PageSize. So we have - // to let the key through anyway and fudge the values. - && (pValue->m_aValue.Len() - || (pKey->getKey().EqualsIgnoreCaseAscii("PageSize"))) - #else && pValue->m_aValue.Len() - #endif && ( m_aLastJobData.m_pParser == NULL || m_aLastJobData.m_aContext.getValue( pKey ) != pValue ) ) @@ -1291,43 +1287,10 @@ if( bHavePS2 ) continue; } - #ifdef MACOSX - // Some CUPS PPDs on Mac OS X (Epson, HP) don't include the requisite - // PageSize information for the value. We have to fudge it from the - // margin information. Others (Canon BJC 8200) have the coordinates - // but not the "setpagedevice" stuff - if ( !(pValue->m_aValue.Len()) && pKey->getKey().EqualsIgnoreCaseAscii("PageSize") ) - { - char aWidth[ 32 ]; - char aHeight[ 32 ]; - - snprintf( aWidth, 32, "%d", mnWidthPt ); - snprintf( aHeight, 32, "%d", mnHeightPt ); - - // bounding box was blank, construct from margin info - pValue->m_aValue.AppendAscii( "<m_aValue.AppendAscii( aWidth ); - pValue->m_aValue.AppendAscii( " " ); - pValue->m_aValue.AppendAscii( aHeight ); - pValue->m_aValue.AppendAscii( "] /ImagingBBox null>> setpagedevice" ); - } - else if ( pValue->m_aValue.Len() && (pValue->m_aValue.SearchAscii("setpagedevice")==STRING_NOTFOUND) ) - { - String aBox( pValue->m_aValue ); - - // The value was just the bounding box, add in the correct postscript - pValue->m_aValue.AssignAscii( "" ); - pValue->m_aValue.AppendAscii( "<m_aValue.Append( aBox ); - pValue->m_aValue.AppendAscii( "] /ImagingBBox null>> setpagedevice" ); - } - #endif bSuccess = writeFeature( pFile, pKey, pValue ); -fprintf( stderr," Attempted to write key, success = %s\n", bSuccess ? "good" : "bad" ); } } } -fprintf( stderr, "----- END FEATURE\n" ); } else bSuccess = false;